From 3d33abbb8c93d76e27143c5f8e36816742116ea1 Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Tue, 21 Aug 2007 16:40:33 +0000 Subject: [PATCH] Prepare to move guts of vgremove into lvm library. Fixup force_t. --- lib/metadata/lv_manip.c | 2 +- lib/metadata/metadata-exported.h | 6 +++--- tools/vgremove.c | 34 +++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 5e2e3e360..98b955576 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -1850,7 +1850,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, return 0; } - if (info.exists && (force == DONT_FORCE)) { + if (info.exists && (force == PROMPT)) { if (yes_no_prompt("Do you really want to remove active " "logical volume \"%s\"? [y/n]: ", lv->name) == 'n') { diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 493636d62..5b8030c08 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -107,9 +107,9 @@ typedef enum { * Whether or not to force an operation. */ typedef enum { - DONT_FORCE = 0, - FORCE_NO_CONFIRM = 1, /* skip yes/no confirmation of operation */ - FORCE_OVERRIDE = 2 /* skip confirmation and bypass a second condition */ + PROMPT = 0, /* Issue yes/no prompt to confirm operation */ + DONT_PROMPT = 1, /* Skip yes/no prompt */ + DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */ } force_t; struct cmd_context; diff --git a/tools/vgremove.c b/tools/vgremove.c index 2b4484478..8076ae5ed 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -15,37 +15,37 @@ #include "tools.h" -static int vgremove_single(struct cmd_context *cmd, const char *vg_name, - struct volume_group *vg, int consistent, - void *handle __attribute((unused))) +static int vg_remove_single(struct cmd_context *cmd, const char *vg_name, + struct volume_group *vg, int consistent, + force_t force) { struct physical_volume *pv; struct pv_list *pvl; - int ret = ECMD_PROCESSED; + int ret = 1; if (!vg || !consistent || (vg_status(vg) & PARTIAL_VG)) { log_error("Volume group \"%s\" not found or inconsistent.", vg_name); log_error("Consider vgreduce --removemissing if metadata " "is inconsistent."); - return ECMD_FAILED; + return 0; } if (!vg_check_status(vg, EXPORTED_VG)) - return ECMD_FAILED; + return 0; if (vg->lv_count) { log_error("Volume group \"%s\" still contains %d " "logical volume(s)", vg_name, vg->lv_count); - return ECMD_FAILED; + return 0; } if (!archive(vg)) - return ECMD_FAILED; + return 0; if (!vg_remove(vg)) { log_error("vg_remove %s failed", vg_name); - return ECMD_FAILED; + return 0; } /* init physical volumes */ @@ -58,7 +58,7 @@ static int vgremove_single(struct cmd_context *cmd, const char *vg_name, if (!dev_get_size(pv_dev(pv), &pv->size)) { log_error("%s: Couldn't get size.", dev_name(pv_dev(pv))); - ret = ECMD_FAILED; + ret = 0; continue; } @@ -67,19 +67,29 @@ static int vgremove_single(struct cmd_context *cmd, const char *vg_name, log_error("Failed to remove physical volume \"%s\"" " from volume group \"%s\"", dev_name(pv_dev(pv)), vg_name); - ret = ECMD_FAILED; + ret = 0; } } backup_remove(cmd, vg_name); - if (ret == ECMD_PROCESSED) + if (ret) log_print("Volume group \"%s\" successfully removed", vg_name); else log_error("Volume group \"%s\" not properly removed", vg_name); return ret; } +static int vgremove_single(struct cmd_context *cmd, const char *vg_name, + struct volume_group *vg, int consistent, + void *handle __attribute((unused))) +{ + if (!vg_remove_single(cmd, vg_name, vg, consistent, + arg_count(cmd, force_ARG))) + return ECMD_FAILED; + + return ECMD_PROCESSED; +} int vgremove(struct cmd_context *cmd, int argc, char **argv) {