[Libguestfs] [PATCH v2 1/2] inspect: fix existance check of /dev/mapper devices

Pino Toscano ptoscano at redhat.com
Wed Dec 7 12:27:55 UTC 2016


When checking for the existance of /dev/mapper devices found in the
fstab of a filesystem, using guestfs_exists means they are checked as
files in the guest, while they really appear as devices on the
appliance. Instead, try the lvm name resolution anyway, and ignore them
when they are reported as missing.

Thanks to: Richard W.M. Jones.

Fixes commit 96b6504b09461aeb6850bb2e7b870a0a4c2f5edf.
---
 src/inspect-fs-unix.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index c833304..1e1cf5d 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <libintl.h>
+#include <errno.h>
 
 #ifdef HAVE_ENDIAN_H
 #include <endian.h>
@@ -1820,7 +1821,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
   char *type, *slice, *disk, *part;
   int r;
 
-  if (STRPREFIX (spec, "/dev/mapper/") && guestfs_exists (g, spec) > 0) {
+  if (STRPREFIX (spec, "/dev/mapper/")) {
     /* LVM2 does some strange munging on /dev/mapper paths for VGs and
      * LVs which contain '-' character:
      *
@@ -1831,7 +1832,17 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
      * This makes it impossible to reverse those paths directly, so
      * we have implemented lvm_canonical_lv_name in the daemon.
      */
+    guestfs_push_error_handler (g, NULL, NULL);
     device = guestfs_lvm_canonical_lv_name (g, spec);
+    guestfs_pop_error_handler (g);
+    if (device == NULL) {
+      if (guestfs_last_errno (g) == ENOENT) {
+        /* Ignore devices that don't exist. (RHBZ#811872) */
+      } else {
+        guestfs_int_error_errno (g, guestfs_last_errno (g), "%s", guestfs_last_error (g));
+        return NULL;
+      }
+    }
   }
   else if (match3 (g, spec, re_xdev, &type, &disk, &part)) {
     r = resolve_fstab_device_xdev (g, type, disk, part, &device);
-- 
2.7.4




More information about the Libguestfs mailing list