File locks

Status
Not open for further replies.

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
How can I find out the name of the process that has locked a certain file?
The problem is: I have a qBittorrent client running from a jail, set up as described here.
After stopping download and removing it from the download queue I'm unable to move some of the downloaded files to another location - they stay locked.
 

willnx

Dabbler
Joined
Aug 11, 2013
Messages
49
The command fuser will give you a list of PIDs that are using a file.

You can use ps -p PID to get the name of the process.

This bash line should do all of that for you (remember, FreeNAS by default doesn't use bash. If the system complains about syntax, switch to the bash shell; /bin/bash).
Just replace MyFile

# for PID in $(fuser MyFile | egrep -o "[0-9]+"); do ps -p $PID ; done
 

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
The command fuser will give you a list of PIDs that are using a file.

You can use ps -p PID to get the name of the process.

This bash line should do all of that for you (remember, FreeNAS by default doesn't use bash. If the system complains about syntax, switch to the bash shell; /bin/bash).
Just replace MyFile

# for PID in $(fuser MyFile | egrep -o "[0-9]+"); do ps -p $PID ; done

Hmm... Maybe you could help me to enterpret the result of fuser command?
The script didn't work though SHELL=/usr/local/bin/bash, so I did some manual job.
mostly fuser returns just the filename...
# fuser VIDEO_TS.BUP
VIDEO_TS.BUP:
I managed to get PID 40478 for one locked directory with fuser, then executed
root@GATE /mnt/GATE_RAID/DISK_F/_На разборку]# ps -p 40478
PID TT STAT TIME COMMAND
40478 ?? I 6:34.18 /usr/local/sbin/smbd --daemon --configfile=/usr/local/etc/smb4.conf
As far as I can understand, the file is locked by SMB server. But why?
 
Last edited:

willnx

Dabbler
Joined
Aug 11, 2013
Messages
49
If an application on the (I'm assuming Windows computer) is locking a file in the share, then the SMB daemon on the NAS would handle that for the client;
I would google for info about NTFS file locking.

If there's no share, and that's something in your qBittorrent jail, then I'm out of my league; I don't know enough about how jails work within ZFS to provide any useful info.
 

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
If an application on the (I'm assuming Windows computer) is locking a file in the share, then the SMB daemon on the NAS would handle that for the client;
I would google for info about NTFS file locking.

If there's no share, and that's something in your qBittorrent jail, then I'm out of my league; I don't know enough about how jails work within ZFS to provide any useful info.

Call me stupid, but i don't understand this (we assume, I have a shared HDD directory, in which a folder VIDEO_TS is located):
1. When I enter this folder from the network, I expectingly get "VIDEO_TS: 40478" from fuser. When I close the application that has been accessing it, I expectingly get "VIDEO_TS:" from fuser. Great.
2. I enter the folder from console: cd VIDEO_TS
3. I type fuser VIDEO_TS.BUP - the file is accessible, i get "VIDEO_TS.BUP:" in reply in the console.
4. I start a file manager again on a network computer and enter VIDEO_TS folder . Still get "VIDEO_TS.BUP:" from fsutil
5. I try to move the file to another folder by the filemanager on the remote computer and voila - the file is not writable, though I still get "VIDEO_TS.BUP:" from fsutil, which, I assume, means the file isn't locked.
 

willnx

Dabbler
Joined
Aug 11, 2013
Messages
49
Hmm... your logic sounds right; it doesn't seem like the file is locked.

Is it a permission problem?:
Can you move other files into/outof that both the directory where VIDEO_TS.BUP lives, and the directory where you're trying to move the fail to?
Can you do it while the file manager is both on and off?

(if you're trying to leech torrents, I wouldn't be surprised if qBittorrent had a mechanism to reduce that. Have you tried waiting an hour* or so after the download completes to move it?)
*An hour is a super-mega high figure I'd expected to exceed any limit imposed by such a mechanism.
 

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
Hmm... your logic sounds right; it doesn't seem like the file is locked.

Is it a permission problem?:
Can you move other files into/outof that both the directory where VIDEO_TS.BUP lives, and the directory where you're trying to move the fail to?
Can you do it while the file manager is both on and off?

(if you're trying to leech torrents, I wouldn't be surprised if qBittorrent had a mechanism to reduce that. Have you tried waiting an hour* or so after the download completes to move it?)
*An hour is a super-mega high figure I'd expected to exceed any limit imposed by such a mechanism.

I would recognise it as a permission problem if the situation occured with every subfolder in the folder, where the torrent contents are located. But I get access problems with only some of them. Becides, I surely stopped downloads for the files I'm trying to move, so there shouldn't be any access restrictions from qbittorrent....

Added later: and becides, we've already found out with fuser and ps that the lock belongs to "smbd" process, which AFAIK stands for Samba server, so I don't think that qbittorent has to deal with this.

As this is a home network, I didn't set any access restrictions and password protection for the shared folders. I know, this isn't quite right, but all restrictions make the system inconvinient in use. The system is behind a firewall, I have no users I don't know, so I assumed that password protection for the network is excessive.

I'll try writing something into the folder tonight, will reply about the results. Maybe even I should trying removing the jail with qbittorrent from the system to regain access to the files
 
Last edited:

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
Hmm... your logic sounds right; it doesn't seem like the file is locked.

Is it a permission problem?:
Can you move other files into/outof that both the directory where VIDEO_TS.BUP lives, and the directory where you're trying to move the fail to?
Can you do it while the file manager is both on and off?

(if you're trying to leech torrents, I wouldn't be surprised if qBittorrent had a mechanism to reduce that. Have you tried waiting an hour* or so after the download completes to move it?)
*An hour is a super-mega high figure I'd expected to exceed any limit imposed by such a mechanism.

Yep. Have just run "cp tmp.txt VIDEO_TS" as root from FreeNAS console in the web interface. Worked fine. Then I tried to remove the file with a file manager via the network and expectingly got access rejection.
I even run rm tmp.txt and it worked in the console, ls returns just the files, that existed previously. Did the same from the console within the qbittorrent jail - worked as well...

I am oppressed by the pettiness of my intellect.
 

DrBob

Dabbler
Joined
Jan 6, 2015
Messages
46
Update: I found a per rectal solution for the problem: I installed Midnight Commander into the jail and now I'm able to copy and move files directly from the console within the jail...
And it damn works on the files, that are not accessible for writing over the network. Though I still can not change anything in these folders over the network, neither copy files to them, neither delete, nothing.
 
Last edited:
Status
Not open for further replies.
Top