mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
Blob Blame History Raw
From 60e21f49f1da66af4531b4472670e075d83cd0c1 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Tue, 6 Dec 2016 15:18:34 +0100
Subject: [PATCH] inspect: fix existance check of /dev/mapper devices

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.

(cherry picked from commit dad35e55fac526dbcd50964500f2d5047ae011af)
---
 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 8e27ade..8b7a7ee 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>
@@ -1850,7 +1851,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:
      *
@@ -1861,7 +1862,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);
-- 
1.8.3.1