inspect: Handle cciss devices in /etc/fstab

This commit is contained in:
Matthew Booth
2011-10-18 13:42:16 +01:00
committed by Richard W.M. Jones
parent f5c9f0e9ee
commit 6aa3ece129
2 changed files with 64 additions and 0 deletions

View File

@@ -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

View File

@@ -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