summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Wysochanski <dwysocha@redhat.com>2007-08-28 16:14:49 +0000
committerDave Wysochanski <dwysocha@redhat.com>2007-08-28 16:14:49 +0000
commitf603fe64bd656af8679a9e8cae0cdeda87d556dc (patch)
treefa3e0ba17496b94d87ee1c5c824d706d9d0fb5c1
parente4e02000babdc71815f710c1547123256658394a (diff)
downloadlvm2-f603fe64bd656af8679a9e8cae0cdeda87d556dc.tar.gz
Modify lvremove to prompt for removal if LV active on other cluster nodes.
Add '-f' to vgremove to force removal of VG even if LVs exist. Update vgremove man page for '-f'.
-rw-r--r--WHATS_NEW4
-rw-r--r--lib/metadata/lv_manip.c58
-rw-r--r--lib/metadata/metadata.c27
-rw-r--r--man/vgremove.817
-rw-r--r--tools/commands.h3
5 files changed, 79 insertions, 30 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index eee9169a5..bd4c9fa81 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,6 +1,8 @@
Version 2.02.29 -
==================================
-
+ Modify lvremove to prompt for removal if LV active on other cluster nodes.
+ Add '-f' to vgremove to force removal of VG even if LVs exist.
+
Version 2.02.28 - 24th August 2007
==================================
Fix clvmd logging so you can get lvm-level debugging out of it.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index c761533e2..5f544fd99 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -1839,37 +1839,49 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
/* FIXME Ensure not referred to by another existing LVs */
- if (lv_info(cmd, lv, &info, 1)) {
- if (info.open_count) {
- log_error("Can't remove open logical volume \"%s\"",
- lv->name);
- return 0;
- }
-
- if (info.exists && (force == PROMPT)) {
- if (yes_no_prompt("Do you really want to remove active "
- "logical volume \"%s\"? [y/n]: ",
- lv->name) == 'n') {
- log_print("Logical volume \"%s\" not removed",
- lv->name);
- return 0;
- }
- }
+ /*
+ * If we can't get information about the LV from the kernel, or
+ * someone has the LV device open, fail.
+ */
+ if (!lv_info(cmd, lv, &info, 1)) {
+ log_error("Unable to obtain status for logical volume \"%s\"",
+ lv->name);
+ return 0;
}
-
- if (!archive(vg))
+ if (info.open_count) {
+ log_error("Can't remove open logical volume \"%s\"",
+ lv->name);
return 0;
+ }
- /* If the VG is clustered then make sure no-one else is using the LV
- we are about to remove */
- if (vg_status(vg) & CLUSTERED) {
- if (!activate_lv_excl(cmd, lv)) {
- log_error("Can't get exclusive access to volume \"%s\"",
+ /*
+ * Check for confirmation prompts in the following cases:
+ * 1) Clustered VG, and some remote nodes have the LV active
+ * 2) Non-clustered VG, but LV active locally
+ */
+ if ((vg_status(vg) & CLUSTERED) && !activate_lv_excl(cmd, lv) &&
+ (force == PROMPT)) {
+ if (yes_no_prompt("Logical volume \"%s\" is active on other "
+ "cluster nodes. Really remove? [y/n]: ",
+ lv->name) == 'n') {
+ log_print("Logical volume \"%s\" not removed",
lv->name);
return 0;
}
+ } else if (info.exists && (force == PROMPT)) {
+ if (yes_no_prompt("Do you really want to remove active "
+ "logical volume \"%s\"? [y/n]: ",
+ lv->name) == 'n') {
+ log_print("Logical volume \"%s\" not removed",
+ lv->name);
+ return 0;
+ }
}
+
+ if (!archive(vg))
+ return 0;
+
/* FIXME Snapshot commit out of sequence if it fails after here? */
if (!deactivate_lv(cmd, lv)) {
log_error("Unable to deactivate logical volume \"%s\"",
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 80efbb00a..25dee4659 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -249,6 +249,20 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
return 1;
}
+static int remove_lvs_in_vg(struct cmd_context *cmd,
+ struct volume_group *vg,
+ force_t force)
+{
+ struct lv_list *lvl;
+
+ list_iterate_items(lvl, &vg->lvs)
+ if (!lv_remove_single(cmd, lvl->lv, force))
+ return 0;
+
+ return 1;
+}
+
+/* FIXME: remove redundant vg_name */
int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg, int consistent,
force_t force __attribute((unused)))
@@ -269,6 +283,19 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
return 0;
if (vg->lv_count) {
+ if ((force == PROMPT) &&
+ (yes_no_prompt("Do you really want to remove volume "
+ "group \"%s\" containing %d "
+ "logical volumes? [y/n]: ",
+ vg_name, vg->lv_count) == 'n')) {
+ log_print("Volume group \"%s\" not removed", vg_name);
+ return 0;
+ }
+ if (!remove_lvs_in_vg(cmd, vg, force))
+ return 0;
+ }
+
+ if (vg->lv_count) {
log_error("Volume group \"%s\" still contains %d "
"logical volume(s)", vg_name, vg->lv_count);
return 0;
diff --git a/man/vgremove.8 b/man/vgremove.8
index 0f2d9e9fe..7a51ed68b 100644
--- a/man/vgremove.8
+++ b/man/vgremove.8
@@ -3,17 +3,24 @@
vgremove \- remove a volume group
.SH SYNOPSIS
.B vgremove
-[\-d/\-\-debug] [\-h/\-?/\-\-help] [\-t/\-\-test] [\-v/\-\-verbose]
+[\-d/\-\-debug] [\-f/\-\-force] [\-h/\-?/\-\-help]
+[\-t/\-\-test] [\-v/\-\-verbose]
VolumeGroupName [VolumeGroupName...]
.SH DESCRIPTION
vgremove allows you to remove one or more volume groups.
-The volume group(s) must not have any logical volumes allocated:
-Remove them first with \fBlvremove\fP. If one or more physical
-volumes in the volume group are lost, consider
-\fBvgreduce --removemissing\fP to make the volume group
+If one or more physical volumes in the volume group are lost,
+consider \fBvgreduce --removemissing\fP to make the volume group
metadata consistent again.
+.sp
+If there are logical volumes that exist in the volume group,
+a prompt will be given to confirm removal. You can override
+the prompt with \fB-f\fP.
.SH OPTIONS
See \fBlvm\fP for common options.
+.TP
+.BR \-f ", " \-\-force
+Force the removal of any logical volumes on the volume group
+without confirmation.
.SH SEE ALSO
.BR lvm (8),
.BR lvremove (8),
diff --git a/tools/commands.h b/tools/commands.h
index 10d283e66..1ab5e3809 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -807,13 +807,14 @@ xx(vgremove,
"Remove volume group(s)",
"vgremove\n"
"\t[-d|--debug]\n"
+ "\t[-f|--force]\n"
"\t[-h|--help]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tVolumeGroupName [VolumeGroupName...]\n",
- test_ARG)
+ force_ARG, test_ARG)
xx(vgrename,
"Rename a volume group",