From 5f43553aef21045b3bfe57a6c7065d6f3635a295 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 24 Oct 2014 12:29:43 -0500 Subject: toollib: command should fail if ignoring named arg If a foreign VG is ignored when it's included by "all vgs", then the command shouldn't fail. If a foreign VG is ignored when it's named explicitly as a command arg, then the command should fail. Also, remove ignore_vg from reporter functions because it repeats what has been done in process_each given the recent new version of process_each. --- tools/reporter.c | 14 -------------- tools/toollib.c | 25 ++++++++++++++++++++----- tools/toollib.h | 2 -- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/reporter.c b/tools/reporter.c index d7859a83b..44dc4309e 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -218,13 +218,6 @@ static int _pvs_in_vg(struct cmd_context *cmd, const char *vg_name, struct volume_group *vg, void *handle) { - int ret = ECMD_PROCESSED; - - if (ignore_vg(vg, vg_name, 0, &ret)) { - stack; - return ret; - } - return process_each_pv_in_vg(cmd, vg, handle, &_pvs_single); } @@ -232,13 +225,6 @@ static int _pvsegs_in_vg(struct cmd_context *cmd, const char *vg_name, struct volume_group *vg, void *handle) { - int ret = ECMD_PROCESSED; - - if (ignore_vg(vg, vg_name, 0, &ret)) { - stack; - return ret; - } - return process_each_pv_in_vg(cmd, vg, handle, &_pvsegs_single); } diff --git a/tools/toollib.c b/tools/toollib.c index 18c7e65ce..59b886ba4 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -160,7 +160,8 @@ const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name, /* * Returns 1 if VG should be ignored. */ -int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsistent, int *ret) +static int ignore_vg(struct cmd_context *cmd, struct volume_group *vg, const char *vg_name, + struct dm_list *arg_vgnames, int allow_inconsistent, int *ret) { uint32_t read_error = vg_read_error(vg); @@ -170,8 +171,21 @@ int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsiste if ((read_error == FAILED_INCONSISTENT) && allow_inconsistent) return 0; - if (read_error == FAILED_SYSTEMID) + /* + * Commands that operate on "all vgs" shouldn't be bothered by + * skipping a foreign VG, and the command shouldn't fail when + * one is skipped. But, if the command explicitly asked to + * operate on a foreign VG and it's skipped, then the command + * would expect to fail. + */ + if (read_error == FAILED_SYSTEMID) { + if (arg_vgnames && str_list_match_item(arg_vgnames, vg->name)) { + log_error("Skipping volume group %s with system id %s", + vg->name, vg->system_id); + *ret = ECMD_FAILED; + } return 1; + } if (read_error == FAILED_NOTFOUND) *ret = ECMD_FAILED; @@ -1488,9 +1502,10 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags, ret = 0; vg = vg_read(cmd, vg_name, vg_uuid, flags); - if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &ret)) { + if (ignore_vg(cmd, vg, vg_name, arg_vgnames, flags & READ_ALLOW_INCONSISTENT, &ret)) { if (ret > ret_max) ret_max = ret; + release_vg(vg); stack; continue; @@ -1862,7 +1877,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags, } vg = vg_read(cmd, vg_name, vg_uuid, flags); - if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &ret)) { + if (ignore_vg(cmd, vg, vg_name, arg_vgnames, flags & READ_ALLOW_INCONSISTENT, &ret)) { if (ret > ret_max) ret_max = ret; release_vg(vg); @@ -2178,7 +2193,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags, skip = 0; vg = vg_read(cmd, vg_name, vg_uuid, flags | READ_WARN_INCONSISTENT); - if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &ret)) { + if (ignore_vg(cmd, vg, vg_name, NULL, flags & READ_ALLOW_INCONSISTENT, &ret)) { if (ret > ret_max) ret_max = ret; skip = 1; diff --git a/tools/toollib.h b/tools/toollib.h index dbf24b3f2..d3d2140b6 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -20,8 +20,6 @@ int become_daemon(struct cmd_context *cmd, int skip_lvm); -int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsistent, int *ret); - typedef int (*process_single_vg_fn_t) (struct cmd_context * cmd, const char *vg_name, struct volume_group * vg, -- cgit v1.2.1