Merge branch '16602-wb-acr-version' refs #16602
[arvados.git] / services / fuse / arvados_fuse / unmount.py
index 4a647c3ccefbb90a4db15e45d80078e2d2e4ab3c..dbfea1f90449cb14f3c12df15e6b37001b131bcc 100644 (file)
@@ -6,6 +6,7 @@ import collections
 import errno
 import os
 import subprocess
+import sys
 import time
 
 
@@ -116,6 +117,7 @@ def unmount(path, subtype=None, timeout=10, recursive=False):
 
     was_mounted = False
     attempted = False
+    fusermount_output = b''
     if timeout is None:
         deadline = None
     else:
@@ -155,6 +157,10 @@ def unmount(path, subtype=None, timeout=10, recursive=False):
             return was_mounted
 
         if attempted:
+            # Report buffered stderr from previous call to fusermount,
+            # now that we know it didn't succeed.
+            sys.stderr.write(fusermount_output)
+
             delay = 1
             if deadline:
                 delay = min(delay, deadline - time.time())
@@ -166,12 +172,16 @@ def unmount(path, subtype=None, timeout=10, recursive=False):
             with open('/sys/fs/fuse/connections/{}/abort'.format(m.minor),
                       'w') as f:
                 f.write("1")
-        except OSError as e:
+        except IOError as e:
             if e.errno != errno.ENOENT:
                 raise
 
         attempted = True
         try:
-            subprocess.check_call(["fusermount", "-u", "-z", path])
-        except subprocess.CalledProcessError:
-            pass
+            subprocess.check_output(
+                ["fusermount", "-u", "-z", path],
+                stderr=subprocess.STDOUT)
+        except subprocess.CalledProcessError as e:
+            fusermount_output = e.output
+        else:
+            fusermount_output = b''