X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Flvm.c;h=01b6435e0f12b9d7d7f1522bec0a1bb9ac979176;hp=6946d58454abd9b05abdd427debe24d0210f9456;hb=6279c4bbf9cbbe66917ce9ffa4b98eca9040bcd9;hpb=58caa9e5f1dca3916178894876b938a6a45771b0 diff --git a/daemon/lvm.c b/daemon/lvm.c index 6946d58..01b6435 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -152,30 +152,32 @@ do_lvs (void) * the code. That code is in stubs.c, and it is generated as usual * by generator.ml. */ -guestfs_lvm_int_pv_list * +guestfs_int_lvm_pv_list * do_pvs_full (void) { return parse_command_line_pvs (); } -guestfs_lvm_int_vg_list * +guestfs_int_lvm_vg_list * do_vgs_full (void) { return parse_command_line_vgs (); } -guestfs_lvm_int_lv_list * +guestfs_int_lvm_lv_list * do_lvs_full (void) { return parse_command_line_lvs (); } 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) { @@ -185,18 +187,29 @@ do_pvcreate (const char *device) } free (err); + + udev_settle (); + return 0; } 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; @@ -211,11 +224,14 @@ do_vgcreate (const char *volgroup, char * const* const physvols) } free (err); + + udev_settle (); + return 0; } int -do_lvcreate (const char *logvol, const char *volgroup, int mbytes) +do_lvcreate (char *logvol, char *volgroup, int mbytes) { char *err; int r; @@ -233,6 +249,33 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes) } free (err); + + udev_settle (); + + 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; } @@ -297,16 +340,20 @@ do_lvm_remove_all (void) } free_strings (xs); + udev_settle (); + /* There, that was easy, sorry about your data. */ return 0; } 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) { @@ -316,11 +363,14 @@ do_lvremove (const char *device) } free (err); + + udev_settle (); + return 0; } int -do_vgremove (const char *device) +do_vgremove (char *device) { char *err; int r; @@ -334,15 +384,20 @@ do_vgremove (const char *device) } free (err); + + udev_settle (); + return 0; } 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) { @@ -352,5 +407,70 @@ do_pvremove (const char *device) } free (err); + + udev_settle (); + + 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); + + udev_settle (); + return 0; } + +int +do_vg_activate_all (int activate) +{ + char *empty[] = { NULL }; + return do_vg_activate (activate, empty); +}