summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2014-12-03 10:02:13 +0100
committerPeter Rajnoha <prajnoha@redhat.com>2015-02-09 14:20:28 +0100
commit5bbc5f379d2078312ec387b411dffee1707aedcd (patch)
tree97848e0e3dc5967691d69defff331e39444865ca
parent0be9005dc34fafde9eaeddfa5e09760d0b8d5d45 (diff)
downloadlvm2-5bbc5f379d2078312ec387b411dffee1707aedcd.tar.gz
pvchange: use processing_handle when processing items for pvchange
pvchange is an exception that does not use toollib yet for iterating over the list of PVs (process_each_pv) so intialize the processing_handle and use just like it's used in toollib.
-rw-r--r--tools/pvchange.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/tools/pvchange.c b/tools/pvchange.c
index 76db91727..d5496d935 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -146,6 +146,7 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
int done = 0;
int total = 0;
+ struct processing_handle *handle = NULL;
struct volume_group *vg;
const char *vg_name;
char *pv_name;
@@ -154,22 +155,34 @@ 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;
+ }
+
+ if (!(handle = init_processing_handle(cmd)) ||
+ (!handle->direct_reporting && !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->direct_reporting) {
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 +226,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 +244,12 @@ 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)) {
+ total++;
+ done += _pvchange_single(cmd, vg,
+ pvl->pv,
+ NULL);
+ }
}
unlock_and_release_vg(cmd, vg, sll->str);
}
@@ -246,5 +262,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;
}