/* Super-dangerous command used for testing. It removes all * LVs, VGs and PVs permanently. */ int do_lvm_remove_all (void) { size_t i; int r; { /* Remove LVs. */ CLEANUP_FREE_STRING_LIST char **xs = do_lvs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { CLEANUP_FREE char *err = NULL; /* Deactivate the LV first. On Ubuntu, lvremove '-f' option * does not remove active LVs reliably. */ (void) command (NULL, NULL, str_lvm, "lvchange", "-an", xs[i], NULL); udev_settle (); r = command (NULL, &err, str_lvm, "lvremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("lvremove: %s: %s", xs[i], err); return -1; } } } { /* Remove VGs. */ CLEANUP_FREE_STRING_LIST char **xs = do_vgs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { CLEANUP_FREE char *err = NULL; /* Deactivate the VG first, see note above. */ (void) command (NULL, NULL, str_lvm, "vgchange", "-an", xs[i], NULL); udev_settle (); r = command (NULL, &err, str_lvm, "vgremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("vgremove: %s: %s", xs[i], err); return -1; } } } { /* Remove PVs. */ CLEANUP_FREE_STRING_LIST char **xs = do_pvs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { CLEANUP_FREE char *err = NULL; r = command (NULL, &err, str_lvm, "pvremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("pvremove: %s: %s", xs[i], err); return -1; } } } udev_settle (); /* There, that was easy, sorry about your data. */ return 0; }
/* Super-dangerous command used for testing. It removes all * LVs, VGs and PVs permanently. */ int do_lvm_remove_all (void) { char **xs; int i, r; char *err; /* Remove LVs. */ xs = do_lvs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { /* Deactivate the LV first. On Ubuntu, lvremove '-f' option * does not remove active LVs reliably. */ (void) command (NULL, NULL, "lvm", "lvchange", "-an", xs[i], NULL); udev_settle (); r = command (NULL, &err, "lvm", "lvremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("lvremove: %s: %s", xs[i], err); free (err); free_strings (xs); return -1; } free (err); } free_strings (xs); /* Remove VGs. */ xs = do_vgs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { /* Deactivate the VG first, see note above. */ (void) command (NULL, NULL, "lvm", "vgchange", "-an", xs[i], NULL); udev_settle (); r = command (NULL, &err, "lvm", "vgremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("vgremove: %s: %s", xs[i], err); free (err); free_strings (xs); return -1; } free (err); } free_strings (xs); /* Remove PVs. */ xs = do_pvs (); if (xs == NULL) return -1; for (i = 0; xs[i] != NULL; ++i) { r = command (NULL, &err, "lvm", "pvremove", "-f", xs[i], NULL); if (r == -1) { reply_with_error ("pvremove: %s: %s", xs[i], err); free (err); free_strings (xs); return -1; } free (err); } free_strings (xs); udev_settle (); /* There, that was easy, sorry about your data. */ return 0; }