X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Flvm.c;h=0df27e2f0fe6ccf100d056017287c8d79c2364ce;hp=18d6519fa45678f083b6e076e97912109771f6d8;hb=04d8209077d2227eb1d42695ba71147f78987050;hpb=c24de46d06cc3ecccf00bfaaffb06172659cdd0a diff --git a/daemon/lvm.c b/daemon/lvm.c index 18d6519..0df27e2 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -20,8 +20,10 @@ #include #include +#include #include #include +#include #include "daemon.h" #include "c-ctype.h" @@ -453,6 +455,29 @@ do_pvresize (const char *device) } int +do_pvresize_size (const char *device, int64_t size) +{ + char *err; + int r; + + char buf[32]; + snprintf (buf, sizeof buf, "%" PRIi64 "b", size); + + r = command (NULL, &err, + "lvm", "pvresize", + "--setphysicalvolumesize", buf, + device, NULL); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int do_vg_activate (int activate, char *const *volgroups) { char *err; @@ -638,3 +663,49 @@ do_vgscan (void) free (err); return 0; } + +/* Test if a device is a logical volume (RHBZ#619793). + * + * 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 + * at the device-mapper (kernel) level, nothing is really known about + * LVM (a userspace concept). Therefore we use a convoluted method to + * determine this, by listing out known LVs and checking whether the + * rdev (major/minor) of the device we are passed matches any of them. + * + * Note use of 'stat' instead of 'lstat' so that symlinks are fully + * resolved. + */ +int +do_is_lv (const char *device) +{ + struct stat stat1, stat2; + + int r = stat (device, &stat1); + if (r == -1) { + reply_with_perror ("stat: %s", device); + return -1; + } + + char **lvs = do_lvs (); + if (lvs == NULL) + return -1; + + size_t i; + for (i = 0; lvs[i] != NULL; ++i) { + r = stat (lvs[i], &stat2); + if (r == -1) { + reply_with_perror ("stat: %s", lvs[i]); + free_strings (lvs); + return -1; + } + if (stat1.st_rdev == stat2.st_rdev) { /* found it */ + free_strings (lvs); + return 1; + } + } + + /* not found */ + free_strings (lvs); + return 0; +}