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, subtype=None, 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)
51 mnttype = 'fuse.' + subtype
56 if m.path == path or m.path.startswith(path+"/"):
58 if not (m.is_fuse and (mnttype is None or
59 mnttype == m.mnttype)):
61 "cannot unmount {}: mount type is {}".format(
63 for path in sorted(paths, key=len, reverse=True):
64 unmount(path, timeout=timeout, recursive=False)
72 deadline = time.time() + timeout
77 if m.is_fuse and (mnttype is None or mnttype == m.mnttype):
79 if os.path.realpath(m.path) == path:
91 delay = min(delay, deadline - time.time())
93 raise Exception("timed out")
97 with open('/sys/fs/fuse/connections/{}/abort'.format(m.minor),
101 if e.errno != errno.ENOENT:
106 subprocess.check_call(["fusermount", "-u", "-z", path])
107 except subprocess.CalledProcessError: