From: Matthew Booth Date: Tue, 18 Oct 2011 12:42:16 +0000 (+0100) Subject: inspect: Handle cciss devices in /etc/fstab X-Git-Tag: 1.13.22~3 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=6aa3ece129d04a588ceb161c4b203a20664ddcd8;p=libguestfs.git inspect: Handle cciss devices in /etc/fstab --- diff --git a/regressions/test-inspect-fstab.sh b/regressions/test-inspect-fstab.sh index bb79a81..26ea10f 100755 --- a/regressions/test-inspect-fstab.sh +++ b/regressions/test-inspect-fstab.sh @@ -93,6 +93,38 @@ 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' > test.output + add-drive-opts test1.img readonly:true name:cciss/c1d3 + run + inspect-os + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/dev/VG/Root +/: /dev/VG/Root +/boot: /dev/vda1 +/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 77834a1..6b1a05b 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; static pcre *re_netbsd; @@ -108,6 +109,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); COMPILE (re_netbsd, "^NetBSD (\\d+)\\.(\\d+)", 0); } @@ -128,6 +130,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); pcre_free (re_netbsd); } @@ -880,6 +883,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