diff options
-rw-r--r-- | tools/pvchange.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/tools/pvchange.c b/tools/pvchange.c index 76db91727..f0342a62d 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -145,7 +145,9 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) int opt = 0; int done = 0; int total = 0; + int selected; + struct processing_handle *handle = NULL; struct volume_group *vg; const char *vg_name; char *pv_name; @@ -154,22 +156,36 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) struct dm_list *vgnames; struct dm_str_list *sll; + int r = ECMD_PROCESSED; + if (!(arg_count(cmd, allocatable_ARG) + arg_is_set(cmd, addtag_ARG) + arg_is_set(cmd, deltag_ARG) + arg_count(cmd, uuid_ARG) + arg_count(cmd, metadataignore_ARG))) { log_error("Please give one or more of -x, -uuid, " "--addtag, --deltag or --metadataignore"); - return EINVALID_CMD_LINE; + r = EINVALID_CMD_LINE; + goto out; + } + + /* FIXME: use process_each_pv for pvchange. */ + + if (!(handle = init_processing_handle(cmd)) || + (handle->internal_report_for_select && !init_selection_handle(cmd, handle))) { + log_error("Failed to initialize processing handle."); + r = ECMD_FAILED; + goto out; } - if (!(arg_count(cmd, all_ARG)) && !argc) { + if (!(arg_count(cmd, all_ARG)) && !argc && !handle->internal_report_for_select) { log_error("Please give a physical volume path"); - return EINVALID_CMD_LINE; + r = EINVALID_CMD_LINE; + goto out; } if (arg_count(cmd, all_ARG) && argc) { log_error("Option --all and PhysicalVolumePath are exclusive."); - return EINVALID_CMD_LINE; + r = EINVALID_CMD_LINE; + goto out; } if (argc) { @@ -213,7 +229,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) */ if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE, NULL)) { log_error("Unable to obtain global lock."); - return ECMD_FAILED; + r = ECMD_FAILED; + goto out; } /* populate lvmcache */ @@ -230,10 +247,13 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) continue; } dm_list_iterate_items(pvl, &vg->pvs) { - total++; - done += _pvchange_single(cmd, vg, - pvl->pv, - NULL); + if (select_match_pv(cmd, handle, vg, pvl->pv, + &selected) && selected) { + total++; + done += _pvchange_single(cmd, vg, + pvl->pv, + NULL); + } } unlock_and_release_vg(cmd, vg, sll->str); } @@ -246,5 +266,10 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) done, done == 1 ? "" : "s", total - done, (total - done) == 1 ? "" : "s"); - return (total == done) ? ECMD_PROCESSED : ECMD_FAILED; +out: + destroy_processing_handle(cmd, handle, 1); + if (r == ECMD_PROCESSED) + return (total == done) ? ECMD_PROCESSED : ECMD_FAILED; + else + return r; } |