Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a Samba process to close a file

Tags:

sysadmin

samba

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.

like image 214
Javier Avatar asked Sep 26 '08 21:09

Javier


People also ask

How do you force close a file in Linux?

Simply click the X button in the top corner (left or right, depending on your Linux operating system). This should stop the program dead in its tracks. You might see a dialog box, asking you to Wait or Force Quit to end it now. If all goes to plan, some distros will prompt you to send an error report.

How do you force close a file someone else has open?

Click on Shared Folders”, and after that, on Open Files. That should open the screen with a list of files that are detected as open, the user that opened it, possible locks, and mode that is opened in. By right click on the wanted file, choose an option, “Close open file”, and that will close it.

How do I close an open file on a server?

Click to highlight desired items. Then right-click and select Close Open Files.

What does force user do in Samba?

The documentation for Samba specifies that the force user parameter "specifies a UNIX user name that will be assigned as the default user" (emphasis mine).


3 Answers

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!

like image 197
Beep beep Avatar answered Sep 30 '22 15:09

Beep beep


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.

like image 38
X-Istence Avatar answered Sep 30 '22 13:09

X-Istence


This is probably answered here: 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.

like image 36
chaos Avatar answered Sep 30 '22 15:09

chaos