11209: Try unmounting at least once even if timeout=0.
authorTom Clegg <tom@curoverse.com>
Thu, 23 Mar 2017 22:06:01 +0000 (18:06 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 23 Mar 2017 22:09:56 +0000 (18:09 -0400)
services/fuse/arvados_fuse/command.py
services/fuse/arvados_fuse/unmount.py

index 883af3652b096a062d16c95120f9f0965a693f7d..fff0c99a8e9cd10fa0684db99081a1d6477fc8ab 100644 (file)
@@ -11,7 +11,6 @@ import sys
 import time
 
 import arvados.commands._util as arv_cmd
-from arvados_fuse import crunchstat
 from arvados_fuse import *
 from arvados_fuse._version import __version__
 
index ab5ce4f6ab24833cf2a31c0e4072e85f6b85e774..7a7464d4da8a0fbe513eadf4ff8e26b9cd04dc07 100644 (file)
@@ -62,12 +62,13 @@ def unmount(path, timeout=10):
     path = os.path.realpath(path)
 
     was_mounted = False
-    t0 = time.time()
-    delay = 0
-    while True:
-        if timeout and t0 + timeout < time.time():
-            raise Exception("timed out")
+    attempted = False
+    if timeout is None:
+        deadline = None
+    else:
+        deadline = time.time() + timeout
 
+    while True:
         mounted = False
         for m in mountinfo():
             if m.is_fuse:
@@ -81,6 +82,14 @@ def unmount(path, timeout=10):
         if not mounted:
             return was_mounted
 
+        if attempted:
+            delay = 1
+            if deadline:
+                delay = min(delay, deadline - time.time())
+                if delay <= 0:
+                    raise Exception("timed out")
+            time.sleep(delay)
+
         try:
             with open('/sys/fs/fuse/connections/{}/abort'.format(m.minor),
                       'w') as f:
@@ -88,11 +97,9 @@ def unmount(path, timeout=10):
         except OSError as e:
             if e.errno != errno.ENOENT:
                 raise
+
+        attempted = True
         try:
             subprocess.check_call(["fusermount", "-u", "-z", path])
         except subprocess.CalledProcessError:
             pass
-
-        time.sleep(delay)
-        if delay == 0:
-            delay = 1