Is there a way to force a Samba process to close a given file without killing it?
Samba opens a process for each client connection, and sometimes I see it holds open files far longer than needed. Usually i just kill the process, and the (windows) client will reopen it the next time it access the share; but sometimes it's actively reading other file for a long time, and i'd like to just 'kill' one file, and not the whole connection.
edit: I've tried the 'net rpc file close ', but doesn't seem to work. Anybody knows why?
edit: this is the best mention i've found of something similar. It seems to be a problem on the win32 client, something that microsoft servers have a workaround for; but Samba doesn't. I wish the net rpc file close <fileid>
command worked, I'll keep trying to find out why. I'm accepting LuckyLindy's answer, even if it didn't solve the problem, because it's the only useful procedure in this case.
-
If there isn't an explicit option in samba, that would be impossible to externally close an open file descriptor with standard unix interfaces.
-
This is probably answered here: http://stackoverflow.com/questions/323146/how-to-close-a-file-descriptor-from-another-process-in-unix-systems
At a guess, 'net rpc file close' probably doesn't work because the interprocess communication telling Samba to close the file winds up not being looked at until the file you want to close is done being read.
-
Generally speaking, you can't meddle with a process file descriptors from the outside. Yet as root you can of course do that as you seen in that phrack article from 1997: http://www.phrack.org/issues.html?issue=51&id=5#article - I wouldn't recommend doing that on a production system though...
-
The better question in this case would be why? Why do you want to close a file early? What purpose does it ultimately have to close the file? What are you attempting to accomplish?
Javier : it's very frequent that a windows client opens a file, and seems to have closed it; but the samba process keeps it open and other users can't erase it. the only way to release it is killing the process.Javier : IOW, it's not 'early' closing the file. it should be already closed long ago.X-Istence : My suggestion would be to file a bug report with the samba developers. Then go from there, there is no good way to close a file from outside of a process without possibly putting the process in an unstable state. You can always restart Samba periodically as a work around!Jess : X-Istence - this has been a "bug" with Samba for over 5 years, and it hasn't been addressed by them. We do the same thing as Javier and just kill the process.X-Istence : LuckyLindy: If this has been a bug in Samba for over 5 years, could you please link to me a bug report?Stefan Thyberg : Easier to write questions like this as comments. -
This happens all the time on our systems, particularly when connecting to Samba from a Win98 machine. We follow these steps to solve it (which are probably similar to yours):
- See which computer is using the file (i.e.
lsof|grep -i <file_name>
) - Try to open that file from the offending computer, or see if a process is hiding in task manager that we can close
- If no luck, have the user exit any important network programs
- Kill the user's Samba process from linux (i.e.
kill -9 <pid>
)
I wish there was a better way!
Javier : yep, that's exactly what i'm doing. - See which computer is using the file (i.e.
-
I am creating a new answer, since my first answer really just contained more questions, and really was not a whole lot of help.
After doing a bit of searching, I have not been able to find any current open bugs for the latest version of Samba, please check out the Samba Bug Report website, and create a new bug. This is the simplest way to get someone to suggest ideas as to how to possibly fix it, and have developers look at the issue. LuckyLindy left a comment in my previous answer saying that this is the way it has been for 5 years now, well the project is Open Source the best way to fix something that is wrong by reporting it, and or providing patches.
I have also found one mailing list entry: Samba Open files, they suggest adding
posix locking=no
to the configuration file, as long as you don't also have the files handed out over NFS not locking the file should be okay, that is if the file is being held is locked.If you wanted too, you could write a program that uses ptrace and attaches to the program, and it goes through and unlocks and closes all the files. However, be aware that this might possibly leave Samba in an unknown state, which can be more dangerous.
The work around that I have already mentioned is to periodically restart samba as a work around. I know it is not a solution but it might work temporarily.
Javier : the mailthread was interesting; unfortunately it seems that the problem isn't about using posix locks or not, it's about samba believing the file should be open, so other samba clients can't delete it.
0 comments:
Post a Comment