fuse action on umount

1.9k views Asked by At

I've written some simple filesystems with Python-fuse, but now I'm wanting to do something that I can't find in the pydoc nor in the sample scripts I've found: when the filesystem is unmounted with fusermount -u, I want to trap that action, perform the umount, and then rmdir the mount directory created by my program's initialization script. If it is even possible, what's the magic incantation to trap the umount action?

I can see how that could easily turn into an endless loop, but I can hopefully figure out how to disable the umount trap the first time it's hit.


Update: I found destroy at http://omake.metaprl.org/prerelease/omake-dll-fuse.html#htoc582 and added the method, but it doesn't seem to be called.

2

There are 2 answers

1
jcomeau_ictx On BEST ANSWER

found it! it's fsdestroy() in Python-fuse. located it by:

jcomeau@intrepid:/usr/src/google-desktop/api$ cat /usr/lib/python2.6/dist-packages/fuseparts/* | strings | grep destroy
fsdestroy

What I used was:

def fsdestroy(self, data = None):
  syslog.syslog(syslog.LOG_INFO, 'destroy %s: %s' % (self.mountpoint, data))
  os.rmdir(self.mountpoint)

Don't know if the data parameter is necessary or not, but doesn't hurt. And apparently, it's called after the umount, so I didn't have to worry about handling that.

0
Kevin On

Another solution, though not specific and not tested under Python, is prevent FUSE from "daemonizing" with the -f switch.

In this case, the fuse_main method will block until the filesystem in unmounted, and you will get the control back afterwards.

If you do need the deamon behavior, you can reimplement it yourself before mounting.