From d5a3559a2fb15a1c9ceeb44b917e168ba439e99b Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 21 Dec 2005 21:21:45 +0000 Subject: [PATCH] Add --mirrorsonly arg to vgreduce. (Doesn't handle mirrors yet.) --- WHATS_NEW | 1 + tools/args.h | 1 + tools/commands.h | 3 ++- tools/vgreduce.c | 22 ++++++++++++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index bc2bfb107..f95f4f2b0 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.02 - ==================================== + Add --mirrorsonly to vgreduce. vgreduce replaces active LVs with error segment before removing them. Set block_on_error parameter if available. Add target_version. diff --git a/tools/args.h b/tools/args.h index 17dc59fb5..64867eaed 100644 --- a/tools/args.h +++ b/tools/args.h @@ -44,6 +44,7 @@ arg(minor_ARG, '\0', "minor", minor_arg) arg(type_ARG, '\0', "type", segtype_arg) arg(alloc_ARG, '\0', "alloc", alloc_arg) arg(separator_ARG, '\0', "separator", string_arg) +arg(mirrorsonly_ARG, '\0', "mirrorsonly", NULL) /* Allow some variations */ arg(resizable_ARG, '\0', "resizable", yes_no_arg) diff --git a/tools/commands.h b/tools/commands.h index 65af40613..7ca6d15b3 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -770,6 +770,7 @@ xx(vgreduce, "\t[-A|--autobackup y|n]\n" "\t[-d|--debug]\n" "\t[-h|--help]\n" + "\t[--mirrorsonly]\n" "\t[--removemissing]\n" "\t[-t|--test]\n" "\t[-v|--verbose]\n" @@ -777,7 +778,7 @@ xx(vgreduce, "\tVolumeGroupName\n" "\t[PhysicalVolumePath...]\n", - all_ARG, autobackup_ARG, removemissing_ARG, test_ARG) + all_ARG, autobackup_ARG, mirrorsonly_ARG, removemissing_ARG, test_ARG) xx(vgremove, "Remove volume group(s)", diff --git a/tools/vgreduce.c b/tools/vgreduce.c index c27ac250e..1954e553b 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -152,8 +152,9 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg) struct physical_volume *pv; struct lv_segment *seg; unsigned int s; - int list_unsafe; + int list_unsafe, only_mirror_images_found; LIST_INIT(lvs_changed); + only_mirror_images_found = 1; /* Deactivate & remove necessary LVs */ restart_loop: @@ -172,6 +173,12 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg) pv = seg_pv(seg, s); if (!pv || !pv->dev) { + if (arg_count(cmd, mirrorsonly_ARG) && + !(lv->status & MIRROR_IMAGE)) { + log_error("Non-mirror-image LV %s found: can't remove.", lv->name); + only_mirror_images_found = 0; + continue; + } if (!_remove_lv(cmd, lv, &list_unsafe, &lvs_changed)) { stack; return 0; @@ -183,6 +190,11 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg) } } + if (!only_mirror_images_found) { + log_error("Aborting because --mirrorsonly was specified."); + return 0; + } + /* Remove missing PVs */ list_iterate_safe(pvh, pvht, &vg->pvs) { pvl = list_item(pvh, struct pv_list); @@ -235,7 +247,7 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg) /* FIXME If any lvs_changed belong to mirrors, reduce those mirrors */ /* Deactivate error LVs */ - if (!test_mode) { + if (!test_mode()) { list_iterate_items(lvl, &lvs_changed) { log_verbose("Deactivating (if active) logical volume %s", lvl->lv->name); @@ -340,6 +352,12 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } + if (arg_count(cmd, mirrorsonly_ARG) && + !arg_count(cmd, removemissing_ARG)) { + log_error("--mirrorsonly requires --removemissing"); + return EINVALID_CMD_LINE; + } + if (argc == 1 && !arg_count(cmd, all_ARG) && !arg_count(cmd, removemissing_ARG)) { log_error("Please enter physical volume paths or option -a");