mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-24 17:57:48 +03:00
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.
This commit is contained in:
parent
56846d7873
commit
d6c8f0de28
@ -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;
|
||||
}
|
||||
|
||||
if (!(arg_count(cmd, all_ARG)) && !argc) {
|
||||
/* 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 && !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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user