8 MountInfo = collections.namedtuple(
9 'MountInfo', ['is_fuse', 'major', 'minor', 'mnttype', 'path'])
14 with open('/proc/self/mountinfo') as f:
15 for m in f.readlines():
16 mntid, pmntid, dev, root, path, extra = m.split(" ", 5)
17 mnttype = extra.split(" - ")[1].split(" ", 1)[0]
18 major, minor = dev.split(":")
20 is_fuse=(mnttype == "fuse" or mnttype.startswith("fuse.")),
29 def unmount(path, timeout=10, recursive=False):
30 """Unmount the fuse mount at path.
32 Unmounting is done by writing 1 to the "abort" control file in
33 sysfs to kill the fuse driver process, then executing "fusermount
34 -u -z" to detach the mount point, and repeating these steps until
35 the mount is no longer listed in /proc/self/mountinfo.
37 This procedure should enable a non-root user to reliably unmount
38 their own fuse filesystem without risk of deadlock.
40 Returns True if unmounting was successful, False if it wasn't a
41 fuse mount at all. Raises an exception if it cannot be unmounted.
44 path = os.path.realpath(path)
49 if m.path == path or m.path.startswith(path+"/"):
53 "cannot unmount {}: non-fuse mountpoint {}".format(
55 for path in sorted(paths, key=len, reverse=True):
56 unmount(path, timeout=timeout, recursive=False)
64 deadline = time.time() + timeout
71 if os.path.realpath(m.path) == path:
83 delay = min(delay, deadline - time.time())
85 raise Exception("timed out")
89 with open('/sys/fs/fuse/connections/{}/abort'.format(m.minor),
93 if e.errno != errno.ENOENT:
98 subprocess.check_call(["fusermount", "-u", "-z", path])
99 except subprocess.CalledProcessError: