Proper way to unmount fuse programatically

983 views
Skip to first unread message

an...@codelathe.com

unread,
Nov 17, 2016, 11:44:36 AM11/17/16
to OSXFUSE
Hi all, 
I am developing a cloud network drive using osxfuse 3.5.2 and it uses a UI framework and mounts fuse . I need to exit (and remount) cleanly without leaving mount points.

Originally I was using the helper method fuse_main define to mount fuse but there is no way to unmount and clean up the fuse. During development I was just using system ("umount -f mountpoint")  to exit out and it will hang occasionally and leave stale mount points. I have also seen occasionally fuse going brain dead (the listing will go empty and the user side callbacks will not receive anything) which I am hoping is due to previous unclean shutdowns.

I have now changed it to use the fuse_mount, fuse_new, fuse_loop_mt methods to setup fuse. When I try to exit out by calling fuse_exit , nothing happens and looking at the fuse source it looks like it is waiting on read and only when it breaks out, it can check that the exit is requested. So I have tried calling fuse_exit followed by fuse_unmount and then followed by fuse_destroy. The fuse_unmount causes the fuse_loop_mt to breakout but the fuse_unmount call itself takes a long time (probably 30 seconds) to return. 

I would be grateful if someone can point me to some documentation or sample that shows how to properly unmount and clean up.

Best Regards
Anis

Sam Moffatt

unread,
Nov 18, 2016, 11:38:53 AM11/18/16
to osxfus...@googlegroups.com
Hi Anis,

You need to think that you’re writing a file system, it’s generally not the role of the file system to terminate itself and instead the kernel should handle that. In general “umount" is the right sort of API for this as it should take into account if it’s “safe” for the filesystem to be unmounted in terms of what the kernel perceives. I actually prefer to use “diskutil unmount” (or “diskutil eject” at times) to unmount the filesystem as it then ensures nobody is using it though it will pop up a dialog if there are open file handles. If these fail and you’re doing unclean unmounts right now which could explain some of the issues you’re seeing.

Cheers,

--
You received this message because you are subscribed to the Google Groups "OSXFUSE" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osxfuse-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alejandro Exojo

unread,
Nov 25, 2016, 5:04:44 AM11/25/16
to osxfus...@googlegroups.com
On 17 November 2016 at 17:44, <an...@codelathe.com> wrote:
Hi all, 
I am developing a cloud network drive using osxfuse 3.5.2 and it uses a UI framework and mounts fuse . I need to exit (and remount) cleanly without leaving mount points.


Be prepared for some pain, since the system is not 100% well prepared for this. Maybe recent versions of OSXFUSE have improved, but the 2.x series were certainly not.
 
Originally I was using the helper method fuse_main define to mount fuse but there is no way to unmount and clean up the fuse. During development I was just using system ("umount -f mountpoint")  to exit out and it will hang occasionally and leave stale mount points. I have also seen occasionally fuse going brain dead (the listing will go empty and the user side callbacks will not receive anything) which I am hoping is due to previous unclean shutdowns.

I have now changed it to use the fuse_mount, fuse_new, fuse_loop_mt methods to setup fuse. When I try to exit out by calling fuse_exit , nothing happens and looking at the fuse source it looks like it is waiting on read and only when it breaks out, it can check that the exit is requested. So I have tried calling fuse_exit followed by fuse_unmount and then followed by fuse_destroy. The fuse_unmount causes the fuse_loop_mt to breakout but the fuse_unmount call itself takes a long time (probably 30 seconds) to return. 

I would be grateful if someone can point me to some documentation or sample that shows how to properly unmount and clean up.


There is no documentation that I know of. Search the archives of this mailing list, and you'll see that it's been asked several times. I digged in the sources, and I saw how it's done in the library for the implementation of fuse_main. The UNIX signal handlers have an implementation of this. And, surprise, it's done (again, when I checked, that was latest 2.x and/or early 3.x) by accessing a private struct that you don't have access to, and by calling system() or fork+execve to call umount. I decided to do something awkward, but the best I can think of: install those handlers (even if I did want/need to, it's not a console application) and send SIGHUP to myself.
Reply all
Reply to author
Forward
0 new messages