X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Flvm.c;h=143c5a810447fe5e468ee655b6a1f5c76137ef30;hp=6946d58454abd9b05abdd427debe24d0210f9456;hb=56bef498f46ac3dd580f4bde3c8f3ed2fe688826;hpb=58caa9e5f1dca3916178894876b938a6a45771b0 diff --git a/daemon/lvm.c b/daemon/lvm.c index 6946d58..143c5a8 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -171,11 +171,13 @@ do_lvs_full (void) } int -do_pvcreate (const char *device) +do_pvcreate (char *device) { char *err; int r; + IS_DEVICE (device, -1); + r = command (NULL, &err, "/sbin/lvm", "pvcreate", device, NULL); if (r == -1) { @@ -189,14 +191,22 @@ do_pvcreate (const char *device) } int -do_vgcreate (const char *volgroup, char * const* const physvols) +do_vgcreate (char *volgroup, char **physvols) { char *err; int r, argc, i; const char **argv; + /* Check they are devices and also do device name translation. */ + for (i = 0; physvols[i] != NULL; ++i) + IS_DEVICE (physvols[i], -1); + argc = count_strings (physvols) + 3; argv = malloc (sizeof (char *) * (argc + 1)); + if (argv == NULL) { + reply_with_perror ("malloc"); + return -1; + } argv[0] = "/sbin/lvm"; argv[1] = "vgcreate"; argv[2] = volgroup; @@ -215,7 +225,7 @@ do_vgcreate (const char *volgroup, char * const* const physvols) } int -do_lvcreate (const char *logvol, const char *volgroup, int mbytes) +do_lvcreate (char *logvol, char *volgroup, int mbytes) { char *err; int r; @@ -236,6 +246,30 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes) return 0; } +int +do_lvresize (char *logvol, int mbytes) +{ + char *err; + int r; + char size[64]; + + IS_DEVICE (logvol, -1); + + snprintf (size, sizeof size, "%d", mbytes); + + r = command (NULL, &err, + "/sbin/lvm", "lvresize", + "-L", size, logvol, NULL); + if (r == -1) { + reply_with_error ("lvresize: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + /* Super-dangerous command used for testing. It removes all * LVs, VGs and PVs permanently. */ @@ -302,11 +336,13 @@ do_lvm_remove_all (void) } int -do_lvremove (const char *device) +do_lvremove (char *device) { char *err; int r; + IS_DEVICE (device, -1); + r = command (NULL, &err, "/sbin/lvm", "lvremove", "-f", device, NULL); if (r == -1) { @@ -320,7 +356,7 @@ do_lvremove (const char *device) } int -do_vgremove (const char *device) +do_vgremove (char *device) { char *err; int r; @@ -338,11 +374,13 @@ do_vgremove (const char *device) } int -do_pvremove (const char *device) +do_pvremove (char *device) { char *err; int r; + IS_DEVICE (device, -1); + r = command (NULL, &err, "/sbin/lvm", "pvremove", "-ff", device, NULL); if (r == -1) { @@ -354,3 +392,62 @@ do_pvremove (const char *device) free (err); return 0; } + +int +do_pvresize (char *device) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + r = command (NULL, &err, + "/sbin/lvm", "pvresize", device, NULL); + if (r == -1) { + reply_with_error ("pvresize: %s: %s", device, err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_vg_activate (int activate, char **volgroups) +{ + char *err; + int r, i, argc; + const char **argv; + + argc = count_strings (volgroups) + 4; + argv = malloc (sizeof (char *) * (argc+1)); + if (argv == NULL) { + reply_with_perror ("malloc"); + return -1; + } + + argv[0] = "/sbin/lvm"; + argv[1] = "vgchange"; + argv[2] = "-a"; + argv[3] = activate ? "y" : "n"; + for (i = 4; i <= argc; ++i) + argv[i] = volgroups[i-4]; + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("vgchange: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_vg_activate_all (int activate) +{ + char *empty[] = { NULL }; + return do_vg_activate (activate, empty); +}