1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

toollib: prepare select_match_{pv,vg,lv} hooks

These hooks will check currently processed PV/VG/LV with current selection
criteria and the processing continues only if there's a match.
This commit is contained in:
David Teigland 2014-11-24 11:08:41 +01:00 committed by Peter Rajnoha
parent 123a3383a0
commit 455ef6f2f5
2 changed files with 59 additions and 6 deletions

View File

@ -1541,6 +1541,26 @@ static int _get_vgnameids_on_system(struct cmd_context *cmd,
return ECMD_PROCESSED;
}
int select_match_vg(struct cmd_context *cmd, struct volume_group *vg, int *selected)
{
*selected = 1;
return 1;
}
int select_match_lv(struct cmd_context *cmd, struct volume_group *vg,
struct logical_volume *lv, int *selected)
{
*selected = 1;
return 1;
}
int select_match_pv(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv, int *selected)
{
*selected = 1;
return 1;
}
static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
struct dm_list *vgnameids_to_process,
struct dm_list *arg_vgnames,
@ -1551,6 +1571,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
struct vgnameid_list *vgnl;
const char *vg_name;
const char *vg_uuid;
int selected;
int ret_max = ECMD_PROCESSED;
int ret;
int skip;
@ -1583,9 +1604,10 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
}
/* Process this VG? */
if (process_all ||
if ((process_all ||
(!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
(!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) {
(!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) &&
select_match_vg(cmd, vg, &selected) && selected) {
ret = process_single_vg(cmd, vg_name, vg, handle);
if (ret != ECMD_PROCESSED)
stack;
@ -1698,6 +1720,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
{
int ret_max = ECMD_PROCESSED;
int ret = 0;
int selected;
unsigned process_lv;
unsigned process_all = 0;
unsigned tags_supplied = 0;
unsigned lvargs_supplied = 0;
@ -1751,12 +1775,31 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (!lvargs_supplied && !lv_is_visible(lvl->lv) && !arg_count(cmd, all_ARG))
continue;
/* Only process the LV if the name matches or process_all is set or if an LV tag matches */
if (lvargs_supplied && str_list_match_item(arg_lvnames, lvl->lv->name))
/*
* process the LV if one of the following:
* - process_all is set
* - LV name matches a supplied LV name
* - LV tag matches a supplied LV tag
* - LV matches the selection
*/
process_lv = process_all;
if (lvargs_supplied && str_list_match_item(arg_lvnames, lvl->lv->name)) {
/* Remove LV from list of unprocessed LV names */
str_list_del(arg_lvnames, lvl->lv->name);
else if (!process_all &&
(!tags_supplied || !str_list_match_list(tags_in, &lvl->lv->tags, NULL)))
process_lv = 1;
}
if (!process_lv && tags_supplied && str_list_match_list(tags_in, &lvl->lv->tags, NULL))
process_lv = 1;
process_lv = process_lv && select_match_lv(cmd, vg, lvl->lv, &selected) && selected;
if (sigint_caught())
return_ECMD_FAILED;
if (!process_lv)
continue;
log_very_verbose("Processing LV %s in VG %s.", lvl->lv->name, vg->name);
@ -2225,6 +2268,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct device_id_list *dil;
struct device *dev_orig;
const char *pv_name;
int selected;
int process_pv;
int dev_found;
int ret_max = ECMD_PROCESSED;
@ -2259,6 +2303,8 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
str_list_match_list(arg_tags, &pv->tags, NULL))
process_pv = 1;
process_pv = process_pv && select_match_pv(cmd, vg, pv, &selected) && selected;
if (process_pv) {
if (skip)
log_verbose("Skipping PV %s in VG %s.", pv_name, vg->name);

View File

@ -79,6 +79,13 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int stop_on_error, void *handle,
process_single_lv_fn_t process_single_lv);
int select_match_vg(struct cmd_context *cmd, struct volume_group *vg,
int *selected);
int select_match_lv(struct cmd_context *cmd, struct volume_group *vg,
struct logical_volume *lv, int *selected);
int select_match_pv(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv, int *selected);
const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
unsigned *dev_dir_found);