mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0043-fuse-In-mount-local-run-test-if-root-filesystem-has-.patch

cd6068
From bcd31e216bdefd61dbc8eafebcfa36953928597c Mon Sep 17 00:00:00 2001
cd6068
From: "Richard W.M. Jones" <rjones@redhat.com>
cd6068
Date: Fri, 24 Jan 2014 10:20:14 +0000
cd6068
Subject: [PATCH] fuse: In mount-local-run, test if root filesystem has been
cd6068
 mounted (RHBZ#1057504).
cd6068
cd6068
It is never normally valid to use the mount-local* APIs when you
cd6068
haven't mounted some filesystems in the libguestfs namespace.
cd6068
cd6068
If you try it, it results in some odd errors.  The mount-local-run
cd6068
call is successful, but subsequent operations fail:
cd6068
cd6068
$ mkdir -p /tmp/mnt
cd6068
$ guestfish -x -N fs mount-local /tmp/mnt : mount-local-run
cd6068
libguestfs: error: lstat: lstat_stub: you must call 'mount' first to mount the root filesystem
cd6068
libguestfs: error: lstat: lstat_stub: you must call 'mount' first to mount the root filesystem
cd6068
cd6068
With this commit, the mount-local-run call gives an error:
cd6068
cd6068
libguestfs: error: you must call 'guestfs_mount' first to mount a filesystem on '/'.
cd6068
Note: '/tmp/mnt' is still mounted.  Use 'guestunmount /tmp/mnt' to clean up.
cd6068
cd6068
The error is implemented by calling guestfs_exists (g, "/") which has
cd6068
the side effect of running the NEED_ROOT macro in the daemon.  (There
cd6068
is no simple equivalent of NEED_ROOT on the library side.)
cd6068
cd6068
(cherry picked from commit 0e2489974b91e4728d544fe2aa08c2a1c9deb365)
cd6068
---
cd6068
 src/fuse.c | 12 ++++++++++++
cd6068
 1 file changed, 12 insertions(+)
cd6068
cd6068
diff --git a/src/fuse.c b/src/fuse.c
cd6068
index 967a744..e84ea84 100644
cd6068
--- a/src/fuse.c
cd6068
+++ b/src/fuse.c
cd6068
@@ -1011,6 +1011,18 @@ guestfs__mount_local_run (guestfs_h *g)
cd6068
     return -1;
cd6068
   }
cd6068
 
cd6068
+  /* Test if root is mounted.  We do this by using a side-effect of
cd6068
+   * guestfs_exists (which is that it calls NEED_ROOT).
cd6068
+   */
cd6068
+  guestfs_push_error_handler (g, NULL, NULL);
cd6068
+  r = guestfs_exists (g, "/");
cd6068
+  guestfs_pop_error_handler (g);
cd6068
+  if (r == -1) {
cd6068
+    error (g, _("you must call 'guestfs_mount' first to mount a filesystem on '/'.\nNote: '%s' is still mounted.  Use 'guestunmount %s' to clean up."),
cd6068
+           g->localmountpoint, g->localmountpoint);
cd6068
+    return -1;
cd6068
+  }
cd6068
+
cd6068
   debug (g, "%s: entering fuse_loop", __func__);
cd6068
 
cd6068
   /* Enter the main loop. */
cd6068
-- 
cd6068
1.8.3.1
cd6068