[Libguestfs] [PATCH] daemon: umount-all: Give a "second chance" for temporary umount failures (RHBZ#1246032).

Richard W.M. Jones rjones at redhat.com
Thu Jul 23 16:30:29 UTC 2015


When unmounting all filesystems, it appears that large amounts of
writes in flight + very slow storage may cause the umount command to
fail temporarily.  Even the briefest of pauses appears to let the
umount succeed.

In this patch, call umount as normal, but if it fails, wait a few
seconds then call it again (if it fails a second time, we report the
error and fail the operation).

I considered using 'umount -l' instead, but that is unsafe since when
using umount-all we usually want the filesystem to be unmounted and
synchronized properly by the time umount-all returns.
---
 daemon/mount.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/daemon/mount.c b/daemon/mount.c
index c5b7d89..a076305 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -419,13 +419,20 @@ do_umount_all (void)
 
   /* Unmount them. */
   for (i = 0; i < mounts.size; ++i) {
-    CLEANUP_FREE char *err = NULL;
-
-    r = command (NULL, &err, str_umount, mounts.argv[i], NULL);
+    /* To avoid problems caused by temporary failures, such as a udev
+     * operation still completing, allow a second chance for each umount.
+     */
+    r = command (NULL, NULL, str_umount, mounts.argv[i], NULL);
     if (r == -1) {
-      reply_with_error ("umount: %s: %s", mounts.argv[i], err);
-      free_stringslen (mounts.argv, mounts.size);
-      return -1;
+      CLEANUP_FREE char *err = NULL;
+
+      sleep (5);
+      r = command (NULL, &err, str_umount, mounts.argv[i], NULL);
+      if (r == -1) {
+        reply_with_error ("umount: %s: %s", mounts.argv[i], err);
+        free_stringslen (mounts.argv, mounts.size);
+        return -1;
+      }
     }
   }
 
-- 
2.4.3




More information about the Libguestfs mailing list