1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-08-03 08:22:00 +03:00

toollib: initialize handles (including reporting for selection) for _select_match_* used in process_each_* fns

Call _init_processing_handle, _init_selection_handle and
_destroy_processing_handle in process_each_* and related functions to
set up and destroy handles used while processing items.
This commit is contained in:
Peter Rajnoha
2014-11-28 15:04:25 +01:00
parent a91bc7a19b
commit 56011918e6
5 changed files with 113 additions and 52 deletions

View File

@ -3538,6 +3538,7 @@ static int _lvconvert_merge_single(struct cmd_context *cmd, struct logical_volum
int lvconvert(struct cmd_context * cmd, int argc, char **argv) int lvconvert(struct cmd_context * cmd, int argc, char **argv)
{ {
int ret = ECMD_PROCESSED;
struct lvconvert_params lp = { struct lvconvert_params lp = {
.target_attr = ~0, .target_attr = ~0,
}; };
@ -3547,13 +3548,16 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
.custom_handle = &lp }; .custom_handle = &lp };
if (!_read_params(cmd, argc, argv, &lp)) { if (!_read_params(cmd, argc, argv, &lp)) {
stack; ret = EINVALID_CMD_LINE;
return EINVALID_CMD_LINE; goto_out;
} }
if (lp.merge) if (lp.merge)
return process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &handle, ret = process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &handle,
&_lvconvert_merge_single); &_lvconvert_merge_single);
else
return lvconvert_single(cmd, &lp); ret = lvconvert_single(cmd, &lp);
out:
destroy_processing_handle(cmd, &handle, 0);
return ret;
} }

View File

@ -240,6 +240,8 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
break; break;
sleep(parms->interval); sleep(parms->interval);
} }
destroy_processing_handle(cmd, &handle, 0);
} }
/* /*

View File

@ -50,16 +50,18 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
struct processing_handle handle = { .internal_report_for_select = 1, struct processing_handle handle = { .internal_report_for_select = 1,
.selection_handle = NULL, .selection_handle = NULL,
.custom_handle = &params }; .custom_handle = &params };
int ret; int ret = ECMD_PROCESSED;
if (!argc) { if (!argc) {
log_error("Please supply physical volume(s)"); log_error("Please supply physical volume(s)");
return EINVALID_CMD_LINE; ret = EINVALID_CMD_LINE;
goto out;
} }
if (arg_sign_value(cmd, physicalvolumesize_ARG, SIGN_NONE) == SIGN_MINUS) { if (arg_sign_value(cmd, physicalvolumesize_ARG, SIGN_NONE) == SIGN_MINUS) {
log_error("Physical volume size may not be negative"); log_error("Physical volume size may not be negative");
return EINVALID_CMD_LINE; ret = EINVALID_CMD_LINE;
goto out;
} }
params.new_size = arg_uint64_value(cmd, physicalvolumesize_ARG, params.new_size = arg_uint64_value(cmd, physicalvolumesize_ARG,
@ -73,6 +75,7 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) " log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) "
"not resized", params.done, params.total - params.done); "not resized", params.done, params.total - params.done);
out:
destroy_processing_handle(cmd, &handle, 0);
return ret; return ret;
} }

View File

@ -1731,6 +1731,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
uint32_t flags, struct processing_handle *handle, uint32_t flags, struct processing_handle *handle,
process_single_vg_fn_t process_single_vg) process_single_vg_fn_t process_single_vg)
{ {
int handle_supplied = handle != NULL;
struct dm_list arg_tags; /* str_list */ struct dm_list arg_tags; /* str_list */
struct dm_list arg_vgnames; /* str_list */ struct dm_list arg_vgnames; /* str_list */
struct dm_list vgnameids_on_system; /* vgnameid_list */ struct dm_list vgnameids_on_system; /* vgnameid_list */
@ -1747,10 +1748,8 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
/* /*
* Find any VGs or tags explicitly provided on the command line. * Find any VGs or tags explicitly provided on the command line.
*/ */
if ((ret = _get_arg_vgnames(cmd, argc, argv, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) { if ((ret = _get_arg_vgnames(cmd, argc, argv, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED)
stack; goto_out;
return ret;
}
/* /*
* Obtain the complete list of VGs present on the system if it is needed because: * Obtain the complete list of VGs present on the system if it is needed because:
@ -1758,15 +1757,14 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
* no VG names were given and the command defaults to processing all VGs. * no VG names were given and the command defaults to processing all VGs.
*/ */
if (((dm_list_empty(&arg_vgnames) && enable_all_vgs) || !dm_list_empty(&arg_tags)) && if (((dm_list_empty(&arg_vgnames) && enable_all_vgs) || !dm_list_empty(&arg_tags)) &&
((ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0)) != ECMD_PROCESSED)) { ((ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0)) != ECMD_PROCESSED))
stack; goto_out;
return ret;
}
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) { if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */ /* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found."); log_verbose("No volume groups found.");
return ECMD_PROCESSED; ret = ECMD_PROCESSED;
goto out;
} }
/* /*
@ -1775,13 +1773,22 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
*/ */
if (!dm_list_empty(&vgnameids_on_system)) if (!dm_list_empty(&vgnameids_on_system))
dm_list_splice(&vgnameids_to_process, &vgnameids_on_system); dm_list_splice(&vgnameids_to_process, &vgnameids_on_system);
else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED) { else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
stack; goto_out;
return ret;
}
return _process_vgnameid_list(cmd, flags, &vgnameids_to_process, if (!handle && !(handle = init_processing_handle(cmd)))
&arg_vgnames, &arg_tags, handle, process_single_vg); goto_out;
if (handle->internal_report_for_select && !handle->selection_handle &&
!init_selection_handle(cmd, handle))
goto_out;
ret = _process_vgnameid_list(cmd, flags, &vgnameids_to_process,
&arg_vgnames, &arg_tags, handle, process_single_vg);
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle, 1);
return ret;
} }
int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
@ -1793,6 +1800,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int ret_max = ECMD_PROCESSED; int ret_max = ECMD_PROCESSED;
int ret = 0; int ret = 0;
int selected; int selected;
int handle_supplied = handle != NULL;
unsigned process_lv; unsigned process_lv;
unsigned process_all = 0; unsigned process_all = 0;
unsigned tags_supplied = 0; unsigned tags_supplied = 0;
@ -1800,8 +1808,10 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
struct lv_list *lvl; struct lv_list *lvl;
struct dm_str_list *sl; struct dm_str_list *sl;
if (!vg_check_status(vg, EXPORTED_VG)) if (!vg_check_status(vg, EXPORTED_VG)) {
return_ECMD_FAILED; ret_max = ECMD_FAILED;
goto_out;
}
if (tags_in && !dm_list_empty(tags_in)) if (tags_in && !dm_list_empty(tags_in))
tags_supplied = 1; tags_supplied = 1;
@ -1809,6 +1819,17 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (arg_lvnames && !dm_list_empty(arg_lvnames)) if (arg_lvnames && !dm_list_empty(arg_lvnames))
lvargs_supplied = 1; lvargs_supplied = 1;
if (!handle && !(handle = init_processing_handle(cmd))) {
ret_max = ECMD_FAILED;
goto_out;
}
if (handle->internal_report_for_select && !handle->selection_handle &&
!init_selection_handle(cmd, handle)) {
ret_max = ECMD_FAILED;
goto_out;
}
/* Process all LVs in this VG if no restrictions given /* Process all LVs in this VG if no restrictions given
* or if VG tags match. */ * or if VG tags match. */
if ((!tags_supplied && !lvargs_supplied) || if ((!tags_supplied && !lvargs_supplied) ||
@ -1820,8 +1841,10 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
* but it works since entries are allocated from vg mem pool. * but it works since entries are allocated from vg mem pool.
*/ */
dm_list_iterate_items(lvl, &vg->lvs) { dm_list_iterate_items(lvl, &vg->lvs) {
if (sigint_caught()) if (sigint_caught()) {
return_ECMD_FAILED; ret_max = ECMD_FAILED;
goto_out;
}
if (lvl->lv->status & SNAPSHOT) if (lvl->lv->status & SNAPSHOT)
continue; continue;
@ -1868,8 +1891,10 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv, &selected) && selected; process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv, &selected) && selected;
if (sigint_caught()) if (sigint_caught()) {
return_ECMD_FAILED; ret_max = ECMD_FAILED;
goto_out;
}
if (!process_lv) if (!process_lv)
continue; continue;
@ -1883,7 +1908,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
ret_max = ret; ret_max = ret;
if (stop_on_error && ret != ECMD_PROCESSED) if (stop_on_error && ret != ECMD_PROCESSED)
return ret_max; goto_out;
} }
if (lvargs_supplied) { if (lvargs_supplied) {
@ -1898,7 +1923,9 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
ret_max = ECMD_FAILED; ret_max = ECMD_FAILED;
} }
} }
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle, 1);
return ret_max; return ret_max;
} }
@ -2097,6 +2124,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t flags, int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t flags,
struct processing_handle *handle, process_single_lv_fn_t process_single_lv) struct processing_handle *handle, process_single_lv_fn_t process_single_lv)
{ {
int handle_supplied = handle != NULL;
struct dm_list arg_tags; /* str_list */ struct dm_list arg_tags; /* str_list */
struct dm_list arg_vgnames; /* str_list */ struct dm_list arg_vgnames; /* str_list */
struct dm_list arg_lvnames; /* str_list */ struct dm_list arg_lvnames; /* str_list */
@ -2115,26 +2143,31 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t fla
/* /*
* Find any LVs, VGs or tags explicitly provided on the command line. * Find any LVs, VGs or tags explicitly provided on the command line.
*/ */
if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED)) { if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED))
stack; goto_out;
return ret;
} if (!handle && !(handle = init_processing_handle(cmd)))
goto_out;
if (handle->internal_report_for_select && !handle->selection_handle &&
!init_selection_handle(cmd, handle))
goto_out;
/* /*
* Obtain the complete list of VGs present on the system if it is needed because: * Obtain the complete list of VGs present on the system if it is needed because:
* any tags were supplied and need resolving; or * any tags were supplied and need resolving; or
* no VG names were given and the command defaults to processing all VGs. * no VG names were given and the command defaults to processing all VGs.
*/ */
if (((dm_list_empty(&arg_vgnames) && enable_all_vgs) || !dm_list_empty(&arg_tags)) && if (((dm_list_empty(&arg_vgnames) && (enable_all_vgs ||
(ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0) != ECMD_PROCESSED)) { handle->internal_report_for_select)) || !dm_list_empty(&arg_tags)) &&
stack; (ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0) != ECMD_PROCESSED))
return ret; goto_out;
}
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) { if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */ /* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found."); log_verbose("No volume groups found.");
return ECMD_PROCESSED; ret = ECMD_PROCESSED;
goto out;
} }
/* /*
@ -2143,13 +2176,15 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t fla
*/ */
if (!dm_list_empty(&vgnameids_on_system)) if (!dm_list_empty(&vgnameids_on_system))
dm_list_splice(&vgnameids_to_process, &vgnameids_on_system); dm_list_splice(&vgnameids_to_process, &vgnameids_on_system);
else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED) { else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
stack; goto_out;
return ret;
}
return _process_lv_vgnameid_list(cmd, flags, &vgnameids_to_process, &arg_vgnames, &arg_lvnames, ret = _process_lv_vgnameid_list(cmd, flags, &vgnameids_to_process, &arg_vgnames, &arg_lvnames,
&arg_tags, handle, process_single_lv); &arg_tags, handle, process_single_lv);
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle, 1);
return ret;
} }
static int _get_arg_pvnames(struct cmd_context *cmd, static int _get_arg_pvnames(struct cmd_context *cmd,
@ -2336,6 +2371,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct processing_handle *handle, struct processing_handle *handle,
process_single_pv_fn_t process_single_pv) process_single_pv_fn_t process_single_pv)
{ {
int handle_supplied = handle != NULL;
struct physical_volume *pv; struct physical_volume *pv;
struct pv_list *pvl; struct pv_list *pvl;
struct device_id_list *dil; struct device_id_list *dil;
@ -2347,9 +2383,22 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
int ret_max = ECMD_PROCESSED; int ret_max = ECMD_PROCESSED;
int ret = 0; int ret = 0;
if (!handle && (!(handle = init_processing_handle(cmd)))) {
ret_max = ECMD_FAILED;
goto_out;
}
if (handle->internal_report_for_select && !handle->selection_handle &&
!init_selection_handle(cmd, handle)) {
ret_max = ECMD_FAILED;
goto_out;
}
dm_list_iterate_items(pvl, &vg->pvs) { dm_list_iterate_items(pvl, &vg->pvs) {
if (sigint_caught()) if (sigint_caught()) {
return_ECMD_FAILED; ret_max = ECMD_FAILED;
goto_out;
}
pv = pvl->pv; pv = pvl->pv;
pv_name = pv_dev_name(pv); pv_name = pv_dev_name(pv);
@ -2474,7 +2523,9 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
if (!process_all_pvs && dm_list_empty(arg_tags) && dm_list_empty(arg_devices)) if (!process_all_pvs && dm_list_empty(arg_tags) && dm_list_empty(arg_devices))
break; break;
} }
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle, 1);
return ret_max; return ret_max;
} }

View File

@ -96,5 +96,6 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
init_pvmove(0); init_pvmove(0);
destroy_processing_handle(cmd, &handle, 0);
return ret; return ret;
} }