X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Flvm.c;h=216c9c44ab5d6bc7938947cf5e85dad9e1c7b6fc;hb=37366ede50b78ff9159e080ebae08a822795452a;hp=0df27e2f0fe6ccf100d056017287c8d79c2364ce;hpb=6280ac9b987c14f89749b4b4fdfec5a647567432;p=libguestfs.git diff --git a/daemon/lvm.c b/daemon/lvm.c index 0df27e2..216c9c4 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -664,7 +664,8 @@ do_vgscan (void) return 0; } -/* Test if a device is a logical volume (RHBZ#619793). +/* Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0 + * to a canonical one. * * This is harder than it should be. A LV device like /dev/VG/LV is * really a symlink to a device-mapper device like /dev/dm-0. However @@ -675,9 +676,16 @@ do_vgscan (void) * * Note use of 'stat' instead of 'lstat' so that symlinks are fully * resolved. + * + * Returns: + * 1 = conversion was successful, path is an LV + * '*ret' is set to the updated path if 'ret' is non-NULL. + * 0 = path is not an LV + * -1 = error, reply_with_* has been called + * */ int -do_is_lv (const char *device) +lv_canonical (const char *device, char **ret) { struct stat stat1, stat2; @@ -700,6 +708,14 @@ do_is_lv (const char *device) return -1; } if (stat1.st_rdev == stat2.st_rdev) { /* found it */ + if (ret) { + *ret = strdup (lvs[i]); + if (*ret == NULL) { + reply_with_perror ("strdup"); + free_strings (lvs); + return -1; + } + } free_strings (lvs); return 1; } @@ -709,3 +725,27 @@ do_is_lv (const char *device) free_strings (lvs); return 0; } + +/* Test if a device is a logical volume (RHBZ#619793). */ +int +do_is_lv (const char *device) +{ + return lv_canonical (device, NULL); +} + +/* Return canonical name of LV to caller (RHBZ#638899). */ +char * +do_lvm_canonical_lv_name (const char *device) +{ + char *canonical; + int r = lv_canonical (device, &canonical); + if (r == -1) + return NULL; + + if (r == 0) { + reply_with_error ("%s: not a logical volume", device); + return NULL; + } + + return canonical; /* caller frees */ +}