summaryrefslogtreecommitdiffstats
path: root/src/inspect.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-10-25 12:59:50 +0100
committerRichard W.M. Jones <rjones@redhat.com>2010-10-27 10:59:45 +0100
commit9160dee922ad0866a3f6245fb1e0ad0b2e90170c (patch)
tree204f002ce91145385a6bf6928cbed7fb4356a8b3 /src/inspect.c
parentb01ef8eae1acc5105e623a25c8988bcc3326ea1c (diff)
downloadlibguestfs-9160dee922ad0866a3f6245fb1e0ad0b2e90170c.tar.gz
libguestfs-9160dee922ad0866a3f6245fb1e0ad0b2e90170c.tar.xz
libguestfs-9160dee922ad0866a3f6245fb1e0ad0b2e90170c.zip
/dev/mapper paths should not be returned from C inspection APIs (RHBZ#638899).
With this patch, /dev/mapper paths do not appear in the output of guestfs_inspect_os, as you can see from this example: Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for a list of commands 'man' to read the manual 'quit' to quit the shell Operating system: Fedora release 13 (Goddard) /dev/vg_f13x64/lv_root mounted on / <--- NB /dev/vda1 mounted on /boot
Diffstat (limited to 'src/inspect.c')
-rw-r--r--src/inspect.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/inspect.c b/src/inspect.c
index 1f4096d1..3ffb2bd0 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -878,39 +878,54 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
}
/* Resolve block device name to the libguestfs device name, eg.
- * /dev/xvdb1 => /dev/vdb1. This assumes that disks were added in the
- * same order as they appear to the real VM, which is a reasonable
- * assumption to make. Return things like LV names unchanged (or
- * anything we don't recognize).
+ * /dev/xvdb1 => /dev/vdb1; and /dev/mapper/VG-LV => /dev/VG/LV. This
+ * assumes that disks were added in the same order as they appear to
+ * the real VM, which is a reasonable assumption to make. Return
+ * anything we don't recognize unchanged.
*/
static char *
resolve_fstab_device (guestfs_h *g, const char *spec)
{
- char **devices = guestfs_list_devices (g);
- if (devices == NULL)
- return NULL;
+ char *a1;
+ char *device = NULL;
- size_t count;
- for (count = 0; devices[count] != NULL; count++)
- ;
+ if (STRPREFIX (spec, "/dev/mapper/")) {
+ /* LVM2 does some strange munging on /dev/mapper paths for VGs and
+ * LVs which contain '-' character:
+ *
+ * ><fs> lvcreate LV--test VG--test 32
+ * ><fs> debug ls /dev/mapper
+ * VG----test-LV----test
+ *
+ * This makes it impossible to reverse those paths directly, so
+ * we have implemented lvm_canonical_lv_name in the daemon.
+ */
+ device = guestfs_lvm_canonical_lv_name (g, spec);
+ }
+ else if ((a1 = match1 (g, spec, re_xdev)) != NULL) {
+ char **devices = guestfs_list_devices (g);
+ if (devices == NULL)
+ return NULL;
+
+ size_t count;
+ for (count = 0; devices[count] != NULL; count++)
+ ;
- char *device = NULL;
- char *a1 = match1 (g, spec, re_xdev);
- if (a1) {
size_t i = a1[0] - 'a'; /* a1[0] is always [a-z] because of regex. */
if (i < count) {
size_t len = strlen (devices[i]) + strlen (a1) + 16;
device = safe_malloc (g, len);
snprintf (device, len, "%s%s", devices[i], &a1[1]);
}
- } else {
+
+ free (a1);
+ free_string_list (devices);
+ }
+ else {
/* Didn't match device pattern, return original spec unchanged. */
device = safe_strdup (g, spec);
}
- free (a1);
- free_string_list (devices);
-
return device;
}