go-fuse icon indicating copy to clipboard operation
go-fuse copied to clipboard

How to clean-up abandoned mounts

Open enocom opened this issue 2 years ago • 3 comments

Let's say a previous run of a program using this library mounted a FUSE instance with fs.Mount but was shutdown with SIGKILL before it could unmount the mount.

Is there a way to unmount abandoned mounts without requiring a user do so manually?

I see that fuse.NewServer attempts to mount and will fail if there is an abandoned mount. Meanwhile, the unmount function is not exported, so a client cannot call it directly.

enocom avatar Nov 08 '21 18:11 enocom

I have this script to clean up my connections:

$ cat ~/bin/kill-all-fuse.sh
#!/bin/sh
set -eux

cd /sys/fs/fuse/connections
for f in *; do
  echo $f
  echo hoi > $f/abort
done


for f in $(mount|grep fuse|grep tmp| awk '{print $3;}'); do
  fusermount -u $f
done

I wish I could automate this better, but I don't know how to get connection number from the fuse mount.

hanwen avatar Nov 08 '21 19:11 hanwen

Thanks! That's a handy script. Also, glad I didn't miss anything obvious in the documentation.

How would you feel about exporting unmount (and its Darwin equivalent) in one form or another? Alternatively, perhaps MountOptions could allow a user to request a mount to be cleaned up before attempting to mount again?

enocom avatar Nov 08 '21 19:11 enocom

but I don't know how to get connection number from the fuse mount

@hanwen, FYI this number is st_dev of corresponding FUSE mountpoint:

https://lab.nexedi.com/nexedi/wendelin.core/blob/63153845/wcfs/init.py#L339-343

https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/fs/fuse/control.c#L252-L269

navytux avatar Jun 14 '23 14:06 navytux