[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 5/5] inspect: Handle cciss devices in /etc/fstab



---
 regressions/test-inspect-fstab.sh |   36 ++++++++++++++++++++++++++++++++++++
 src/inspect_fs_unix.c             |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/regressions/test-inspect-fstab.sh b/regressions/test-inspect-fstab.sh
index 0f4dbc2..eabcda6 100755
--- a/regressions/test-inspect-fstab.sh
+++ b/regressions/test-inspect-fstab.sh
@@ -97,6 +97,42 @@ if [ "$(cat test.output)" != "/: /dev/VG/Root
     exit 1
 fi
 
+cat <<'EOF' > test.fstab
+/dev/VG/Root / ext2 default 0 0
+
+# cciss device which requires a hint
+/dev/cciss/c1d3p1 /boot ext2 default 0 0
+
+# cciss device, whole disk
+/dev/cciss/c1d3 /var ext2 default 0 0
+EOF
+
+$guestfish -a test1.img <<'EOF'
+  run
+  mount-options "" /dev/VG/Root /
+  upload test.fstab /etc/fstab
+EOF
+
+$guestfish <<'EOF' | sort > test.output
+  add-drive-opts test1.img readonly:true name:cciss/c1d3
+  run
+  inspect-os
+  inspect-get-mountpoints /dev/VG/Root
+EOF
+
+# Note that the test output below isn't exactly what I expect. This is even
+# weirder than the case above, because here the output of inspect-os is
+# interlaced with the output of inspect-get-mountpoints. Again, it has no
+# bearing on the test.
+if [ "$(cat test.output)" != "/: /dev/VG/Root
+/boot: /dev/vda1
+/dev/VG/Root
+/var: /dev/vda" ]; then
+    echo "$0: error: unexpected output from inspect-get-mountpoints command"
+    cat test.output
+    exit 1
+fi
+
 rm test.fstab
 rm test1.img
 rm test.output
diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c
index 0410cf9..acbf21d 100644
--- a/src/inspect_fs_unix.c
+++ b/src/inspect_fs_unix.c
@@ -64,6 +64,7 @@ static pcre *re_scientific_linux_no_minor;
 static pcre *re_major_minor;
 static pcre *re_aug_seq;
 static pcre *re_xdev;
+static pcre *re_cciss;
 static pcre *re_first_partition;
 static pcre *re_freebsd;
 
@@ -107,6 +108,7 @@ compile_regexps (void)
   COMPILE (re_major_minor, "(\\d+)\\.(\\d+)", 0);
   COMPILE (re_aug_seq, "/\\d+$", 0);
   COMPILE (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0);
+  COMPILE (re_cciss, "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$", 0);
   COMPILE (re_freebsd, "^/dev/ad(\\d+)s(\\d+)([a-z])$", 0);
 }
 
@@ -126,6 +128,7 @@ free_regexps (void)
   pcre_free (re_major_minor);
   pcre_free (re_aug_seq);
   pcre_free (re_xdev);
+  pcre_free (re_cciss);
   pcre_free (re_freebsd);
 }
 
@@ -819,6 +822,35 @@ resolve_fstab_device (guestfs_h *g, const char *spec)
     free (part);
     guestfs___free_string_list (devices);
   }
+  else if (match2 (g, spec, re_cciss, &disk, &part)) {
+    /* disk: (cciss/c\d+d\d+)
+     * part: (\d+)? */
+    char **devices = guestfs_list_devices (g);
+    if (devices == NULL)
+      return NULL;
+
+    /* Check any hints we were passed for a non-heuristic mapping */
+    size_t i = 0;
+    struct drive *drive = g->drives;
+    while (drive) {
+      if (drive->name && STREQ(drive->name, disk)) {
+        if (part) {
+          device = safe_asprintf (g, "%s%s", devices[i], part);
+        } else {
+          device = safe_strdup (g, devices[i]);
+        }
+        break;
+      }
+
+      i++; drive = drive->next;
+    }
+
+    /* We don't try to guess mappings for cciss devices */
+
+    free (disk);
+    free (part);
+    guestfs___free_string_list (devices);
+  }
   else if (match3 (g, spec, re_freebsd, &disk, &slice, &part)) {
     /* FreeBSD disks are organized quite differently.  See:
      * http://www.freebsd.org/doc/handbook/disk-organization.html

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]