master - tools: allow -S|--select for vgremove and lvremove
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=00744b053f395b...
Commit: 00744b053f395be79ab1cb80fdf7342548aa79e2
Parent: f784c60cd65d14d107e957338af041c3a507ef8d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Dec 12 09:34:50 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:08:42 2015 +0100
tools: allow -S|--select for vgremove and lvremove
---
WHATS_NEW | 1 +
tools/commands.h | 10 ++++++----
tools/lvremove.c | 5 +++--
tools/reporter.c | 2 +-
tools/vgremove.c | 5 +++--
5 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f02ac8b..7fa7d3c 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.117 -
====================================
+ Add support for -S/--select to vgremove and lvremove.
Add support for -S/--select to vgchange,lvchange and pvchange.
Add infrastructure to support selection for non-reporting tools.
Add LVM_COMMAND_PROFILE env var to set default command profile name to use.
diff --git a/tools/commands.h b/tools/commands.h
index 6df7f7d..63dbb2a 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -512,7 +512,7 @@ xx(lvreduce,
xx(lvremove,
"Remove logical volume(s) from the system",
- 0,
+ ALL_VGS_IS_DEFAULT, /* all VGs only with --select */
"lvremove\n"
"\t[-A|--autobackup y|n]\n"
"\t[--commandprofile ProfileName]\n"
@@ -520,12 +520,13 @@ xx(lvremove,
"\t[-f|--force]\n"
"\t[-h|--help]\n"
"\t[--noudevsync]\n"
+ "\t[-S|--select Selection]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
- autobackup_ARG, force_ARG, noudevsync_ARG, test_ARG)
+ autobackup_ARG, force_ARG, noudevsync_ARG, select_ARG, test_ARG)
xx(lvrename,
"Rename a logical volume",
@@ -1186,19 +1187,20 @@ xx(vgreduce,
xx(vgremove,
"Remove volume group(s)",
- 0,
+ ALL_VGS_IS_DEFAULT, /* all VGs only with select */
"vgremove\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
"\t[-f|--force]\n"
"\t[-h|--help]\n"
"\t[--noudevsync]\n"
+ "\t[-S|--select Selection]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]\n"
"\tVolumeGroupName [VolumeGroupName...]\n",
- force_ARG, noudevsync_ARG, test_ARG)
+ force_ARG, noudevsync_ARG, select_ARG, test_ARG)
xx(vgrename,
"Rename a volume group",
diff --git a/tools/lvremove.c b/tools/lvremove.c
index 1005218..df920fb 100644
--- a/tools/lvremove.c
+++ b/tools/lvremove.c
@@ -17,8 +17,9 @@
int lvremove(struct cmd_context *cmd, int argc, char **argv)
{
- if (!argc) {
- log_error("Please enter one or more logical volume paths");
+ if (!argc && !arg_is_set(cmd, select_ARG)) {
+ log_error("Please enter one or more logical volume paths "
+ "or use -S for selection.");
return EINVALID_CMD_LINE;
}
diff --git a/tools/reporter.c b/tools/reporter.c
index dba97be..0bfed51 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -455,7 +455,7 @@ int report_for_selection(struct selection_handle *sh,
static const char *incorrect_report_type_msg = "report_for_selection: incorrect report type";
int args_are_pvs = sh->orig_report_type == PVS;
int do_lv_info, do_lv_seg_status;
- struct processing_handle handle = { .internal_report = 0,
+ struct processing_handle handle = { .internal_report_for_select = 0,
.selection_handle = sh,
.custom_handle = NULL };
int r = 0;
diff --git a/tools/vgremove.c b/tools/vgremove.c
index 315e1dc..3ce0763 100644
--- a/tools/vgremove.c
+++ b/tools/vgremove.c
@@ -69,8 +69,9 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
{
int ret;
- if (!argc) {
- log_error("Please enter one or more volume group paths");
+ if (!argc && !arg_is_set(cmd, select_ARG)) {
+ log_error("Please enter one or more volume group paths "
+ "or use -S for selection.");
return EINVALID_CMD_LINE;
}
9 years, 3 months
master - tools: allow -S|--select for vgchange, lvchange and pvchange
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f784c60cd65d14...
Commit: f784c60cd65d14d107e957338af041c3a507ef8d
Parent: d6c8f0de280653d0d15f491f776046b09d7dc635
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 3 10:03:48 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:08:04 2015 +0100
tools: allow -S|--select for vgchange, lvchange and pvchange
---
WHATS_NEW | 1 +
tools/commands.h | 20 +++++++++++---------
tools/lvchange.c | 4 ++--
tools/pvchange.c | 3 ++-
4 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 860f92d..f02ac8b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.117 -
====================================
+ Add support for -S/--select to vgchange,lvchange and pvchange.
Add infrastructure to support selection for non-reporting tools.
Add LVM_COMMAND_PROFILE env var to set default command profile name to use.
set CLOEXEC flag on file descriptors originating in libdaemon
diff --git a/tools/commands.h b/tools/commands.h
index 7bfc800..6df7f7d 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -135,6 +135,7 @@ xx(lvchange,
"\t[-r|--readahead ReadAheadSectors|auto|none]\n"
"\t[--refresh]\n"
"\t[--resync]\n"
+ "\t[-S|--select Selection]\n"
"\t[--sysinit]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
@@ -144,17 +145,16 @@ xx(lvchange,
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
activationmode_ARG, addtag_ARG, alloc_ARG, autobackup_ARG, activate_ARG,
- available_ARG,
- cachepolicy_ARG, cachesettings_ARG, contiguous_ARG, deltag_ARG, discards_ARG,
- detachprofile_ARG, errorwhenfull_ARG, force_ARG,
+ available_ARG, cachepolicy_ARG, cachesettings_ARG, contiguous_ARG, deltag_ARG,
+ discards_ARG, detachprofile_ARG, errorwhenfull_ARG, force_ARG,
ignorelockingfailure_ARG, ignoremonitoring_ARG, ignoreactivationskip_ARG,
ignoreskippedcluster_ARG, major_ARG, metadataprofile_ARG, minor_ARG,
monitor_ARG, minrecoveryrate_ARG, maxrecoveryrate_ARG, noudevsync_ARG,
partial_ARG, permission_ARG, persistent_ARG, poll_ARG,
raidminrecoveryrate_ARG, raidmaxrecoveryrate_ARG, raidsyncaction_ARG,
raidwritebehind_ARG, raidwritemostly_ARG, readahead_ARG, resync_ARG,
- refresh_ARG, setactivationskip_ARG, syncaction_ARG, sysinit_ARG, test_ARG,
- writebehind_ARG, writemostly_ARG, zero_ARG)
+ refresh_ARG, select_ARG, setactivationskip_ARG, syncaction_ARG, sysinit_ARG,
+ test_ARG, writebehind_ARG, writemostly_ARG, zero_ARG)
#define COMMON_OPTS \
"\t[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]\n" \
@@ -638,6 +638,7 @@ xx(pvchange,
"\t[-d|--debug]\n"
"\t[-f|--force]\n"
"\t[-h|--help]\n"
+ "\t[-S|--select Selection]\n"
"\t[-t|--test]\n"
"\t[-u|--uuid]\n"
"\t[-x|--allocatable y|n]\n"
@@ -649,7 +650,7 @@ xx(pvchange,
"\t[PhysicalVolumePath...]\n",
all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, deltag_ARG,
- addtag_ARG, force_ARG, metadataignore_ARG, test_ARG, uuid_ARG)
+ addtag_ARG, force_ARG, metadataignore_ARG, select_ARG, test_ARG, uuid_ARG)
xx(pvresize,
"Resize physical volume(s)",
@@ -945,6 +946,7 @@ xx(vgchange,
"\t[--poll {y|n}]\n"
"\t[--noudevsync]\n"
"\t[--refresh]\n"
+ "\t[-S|--select Selection]\n"
"\t[--sysinit]\n"
"\t[-t|--test]\n"
"\t[-u|--uuid]\n"
@@ -962,13 +964,13 @@ xx(vgchange,
"\t[VolumeGroupName...]\n",
activationmode_ARG, addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG,
- activate_ARG,
- available_ARG, clustered_ARG, deltag_ARG, detachprofile_ARG,
+ activate_ARG, available_ARG, clustered_ARG, deltag_ARG, detachprofile_ARG,
ignoreactivationskip_ARG, ignorelockingfailure_ARG, ignoremonitoring_ARG,
ignoreskippedcluster_ARG, logicalvolume_ARG, maxphysicalvolumes_ARG,
metadataprofile_ARG, monitor_ARG, noudevsync_ARG, metadatacopies_ARG,
vgmetadatacopies_ARG, partial_ARG, physicalextentsize_ARG, poll_ARG,
- refresh_ARG, resizeable_ARG, resizable_ARG, sysinit_ARG, test_ARG, uuid_ARG)
+ refresh_ARG, resizeable_ARG, resizable_ARG, select_ARG, sysinit_ARG,
+ test_ARG, uuid_ARG)
xx(vgck,
"Check the consistency of volume group(s)",
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 17e977f..f45469e 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -1152,8 +1152,8 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
if (!update || !update_partial_unsafe)
cmd->handles_missing_pvs = 1;
- if (!argc) {
- log_error("Please give logical volume path(s)");
+ if (!argc && !arg_is_set(cmd, select_ARG)) {
+ log_error("Please give logical volume path(s) or provide selection criteria.");
return EINVALID_CMD_LINE;
}
diff --git a/tools/pvchange.c b/tools/pvchange.c
index f0342a6..b164509 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -177,7 +177,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
}
if (!(arg_count(cmd, all_ARG)) && !argc && !handle->internal_report_for_select) {
- log_error("Please give a physical volume path");
+ log_error("Please give a physical volume path "
+ "or use -S for selection.");
r = EINVALID_CMD_LINE;
goto out;
}
9 years, 3 months
master - pvchange: use processing_handle when processing items for pvchange
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d6c8f0de280653...
Commit: d6c8f0de280653d0d15f491f776046b09d7dc635
Parent: 56846d787381e5dc90f3a3adbcc3de58154a4ed3
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 3 10:02:13 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:07:01 2015 +0100
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.
---
tools/pvchange.c | 45 +++++++++++++++++++++++++++++++++++----------
1 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/tools/pvchange.c b/tools/pvchange.c
index 76db917..f0342a6 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;
}
9 years, 3 months
master - report: implement report_for_selection
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=56846d787381e5...
Commit: 56846d787381e5dc90f3a3adbcc3de58154a4ed3
Parent: 984ae7f72dee4f119eafc4e236a276a6c8a3fc95
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Dec 1 15:40:03 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:06:53 2015 +0100
report: implement report_for_selection
We have 3 input report types:
- LVS (representing "_select_match_lv")
- VGS (representing "_select_match_vg")
- PVS (representing "_select_match_pv")
The input report type is saved in struct selection_handle's "orig_report_type"
variable.
However, users can use any combination of fields of different report types in
selection criteria - the resulting report type can thus differ. The struct
selection_handle's "report_type" variable stores this resulting report type.
The resulting report_type can end up as one of:
- LVS
- VGS
- PVS
- SEGS
- PVSEGS
This patch adds logic to report_for_selection based on (sensible) combination
of orig_report_type and report_type and calls appropriate reporting functions
or iterates over multiple items that need reporting to determine the selection
result.
---
WHATS_NEW | 1 +
tools/reporter.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 96 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6488f44..860f92d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.117 -
====================================
+ Add infrastructure to support selection for non-reporting tools.
Add LVM_COMMAND_PROFILE env var to set default command profile name to use.
set CLOEXEC flag on file descriptors originating in libdaemon
diff --git a/tools/reporter.c b/tools/reporter.c
index 7301956..dba97be 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -452,7 +452,101 @@ int report_for_selection(struct selection_handle *sh,
struct volume_group *vg,
struct logical_volume *lv)
{
- return 1;
+ static const char *incorrect_report_type_msg = "report_for_selection: incorrect report type";
+ int args_are_pvs = sh->orig_report_type == PVS;
+ int do_lv_info, do_lv_seg_status;
+ struct processing_handle handle = { .internal_report = 0,
+ .selection_handle = sh,
+ .custom_handle = NULL };
+ int r = 0;
+
+ if (!_get_final_report_type(args_are_pvs,
+ sh->orig_report_type | sh->report_type,
+ &do_lv_info,
+ &do_lv_seg_status,
+ &sh->report_type))
+ return_0;
+
+ /*
+ * Remember:
+ * sh->orig_report_type is the original report type requested
+ * sh->report_type is the report type actually used (it counts with all types of fields used in selection)
+ */
+ switch (sh->orig_report_type) {
+ case LVS:
+ switch (sh->report_type) {
+ case LVS:
+ r = _do_lvs_with_info_and_status_single(vg->cmd, lv, do_lv_info, do_lv_seg_status, &handle);
+ break;
+ case SEGS:
+ r = process_each_segment_in_lv(vg->cmd, lv, &handle,
+ do_lv_info && !do_lv_seg_status ? &_segs_with_info_single :
+ !do_lv_info && do_lv_seg_status ? &_segs_with_status_single :
+ do_lv_info && do_lv_seg_status ? &_segs_with_info_and_status_single :
+ &_segs_single);
+ break;
+ default:
+ log_error(INTERNAL_ERROR "%s for LVS", incorrect_report_type_msg);
+ break;
+ }
+ break;
+ case VGS:
+ switch (sh->report_type) {
+ case VGS:
+ r = _vgs_single(vg->cmd, vg->name, vg, &handle);
+ break;
+ case LVS:
+ r = process_each_lv_in_vg(vg->cmd, vg, NULL, NULL, 0, &handle,
+ do_lv_info && !do_lv_seg_status ? &_lvs_with_info_single :
+ !do_lv_info && do_lv_seg_status ? &_lvs_with_status_single :
+ do_lv_info && do_lv_seg_status ? &_lvs_with_info_and_status_single :
+ &_lvs_single);
+ break;
+ case SEGS:
+ r = process_each_lv_in_vg(vg->cmd, vg, NULL, NULL, 0, &handle,
+ do_lv_info && !do_lv_seg_status ? &_lvsegs_with_info_single :
+ !do_lv_info && do_lv_seg_status ? &_lvsegs_with_status_single :
+ do_lv_info && do_lv_seg_status ? &_lvsegs_with_info_and_status_single :
+ &_lvsegs_single);
+ break;
+ case PVS:
+ r = process_each_pv_in_vg(vg->cmd, vg, &handle, &_pvs_single);
+ break;
+ case PVSEGS:
+ r = process_each_pv_in_vg(vg->cmd, vg, &handle,
+ do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_single :
+ !do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_single :
+ do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_single :
+ &_pvsegs_single);
+ break;
+ default:
+ log_error(INTERNAL_ERROR "%s for VGS", incorrect_report_type_msg);
+ break;
+ }
+ break;
+ case PVS:
+ switch (sh->report_type) {
+ case PVS:
+ r = _pvs_single(vg->cmd, vg, pv, &handle);
+ break;
+ case PVSEGS:
+ r = process_each_segment_in_pv(vg->cmd, vg, pv, &handle,
+ do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_sub_single :
+ !do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_sub_single :
+ do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_sub_single :
+ &_pvsegs_sub_single);
+ break;
+ default:
+ log_error(INTERNAL_ERROR "%s for PVS", incorrect_report_type_msg);
+ break;
+ }
+ break;
+ default:
+ log_error(INTERNAL_ERROR "%s", incorrect_report_type_msg);
+ break;
+ }
+
+ return r;
}
static int _report(struct cmd_context *cmd, int argc, char **argv,
9 years, 3 months
master - report: add report_for_selection and use it in select_match_{pv, vg, lv}
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=984ae7f72dee4f...
Commit: 984ae7f72dee4f119eafc4e236a276a6c8a3fc95
Parent: e5b345aff389af24bde7986b236a92e166435f38
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Dec 1 14:19:30 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:36 2015 +0100
report: add report_for_selection and use it in select_match_{pv,vg,lv}
The report_for_selection does the actual "reporting for selection only".
The selection status will be saved in struct selection_handle's "selected"
variable.
---
lib/report/report.h | 4 ++++
tools/reporter.c | 8 ++++++++
tools/toollib.c | 33 ++++++++++++++++++++++++++++++---
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/lib/report/report.h b/lib/report/report.h
index 80a75fd..5bd8b79 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -71,6 +71,10 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
int quoted, int columns_as_rows, const char *selection);
void *report_init_for_selection(struct cmd_context *cmd, report_type_t *report_type,
const char *selection);
+int report_for_selection(struct selection_handle *sh,
+ struct physical_volume *pv,
+ struct volume_group *vg,
+ struct logical_volume *lv);
void report_free(void *handle);
int report_object(void *handle, int selection_only, const struct volume_group *vg,
const struct logical_volume *lv, const struct physical_volume *pv,
diff --git a/tools/reporter.c b/tools/reporter.c
index 4e41e90..7301956 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -447,6 +447,14 @@ static int _get_final_report_type(int args_are_pvs,
return 1;
}
+int report_for_selection(struct selection_handle *sh,
+ struct physical_volume *pv,
+ struct volume_group *vg,
+ struct logical_volume *lv)
+{
+ return 1;
+}
+
static int _report(struct cmd_context *cmd, int argc, char **argv,
report_type_t report_type)
{
diff --git a/tools/toollib.c b/tools/toollib.c
index 7d406ba..34286e3 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1628,36 +1628,63 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, int *selected)
{
+ struct selection_handle *sh = handle->selection_handle;
+
if (!handle->internal_report_for_select) {
*selected = 1;
return 1;
}
- *selected = 1;
+ sh->orig_report_type = VGS;
+
+ if (!report_for_selection(sh, NULL, vg, NULL))
+ return_0;
+
+ sh->orig_report_type = 0;
+ *selected = sh->selected;
+
return 1;
}
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, struct logical_volume *lv, int *selected)
{
+ struct selection_handle *sh = handle->selection_handle;
+
if (!handle->internal_report_for_select) {
*selected = 1;
return 1;
}
- *selected = 1;
+ sh->orig_report_type = LVS;
+
+ if (!report_for_selection(sh, NULL, vg, lv))
+ return_0;
+
+ sh->orig_report_type = 0;
+ *selected = sh->selected;
+
return 1;
}
int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, struct physical_volume *pv, int *selected)
{
+ struct selection_handle *sh = handle->selection_handle;
+
if (!handle->internal_report_for_select) {
*selected = 1;
return 1;
}
- *selected = 1;
+ sh->orig_report_type = PVS;
+
+ if (!report_for_selection(sh, pv, vg, NULL))
+ return_0;
+
+ sh->orig_report_type = 0;
+ *selected = sh->selected;
+
return 1;
}
9 years, 3 months
master - refactor: report: factor out code to determine final report type
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e5b345aff389af...
Commit: e5b345aff389af24bde7986b236a92e166435f38
Parent: de273247118a9183eb8ba6a4615699edcb49dc2d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Dec 1 14:04:29 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:35 2015 +0100
refactor: report: factor out code to determine final report type
The code to determine final report type based on combination of input
report type (determined from fields used for reporting to output and selection)
can be reused for pure reporting for selection - factor out this code into
_get_final_report_type function.
---
tools/reporter.c | 71 ++++++++++++++++++++++++++++++++++-------------------
1 files changed, 45 insertions(+), 26 deletions(-)
diff --git a/tools/reporter.c b/tools/reporter.c
index 3cba020..4e41e90 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -408,6 +408,45 @@ static int _pvsegs_in_vg(struct cmd_context *cmd, const char *vg_name,
return process_each_pv_in_vg(cmd, vg, handle, &_pvsegs_single);
}
+static int _get_final_report_type(int args_are_pvs,
+ report_type_t report_type,
+ int *lv_info_needed,
+ int *lv_segment_status_needed,
+ report_type_t *final_report_type)
+{
+ /* Do we need to acquire LV device info in addition? */
+ *lv_info_needed = (report_type & (LVSINFO | LVSINFOSTATUS)) ? 1 : 0;
+
+ /* Do we need to acquire LV device status in addition? */
+ *lv_segment_status_needed = (report_type & (SEGSSTATUS | LVSSTATUS | LVSINFOSTATUS)) ? 1 : 0;
+
+ /* Ensure options selected are compatible */
+ if (report_type & (SEGS | SEGSSTATUS))
+ report_type |= LVS;
+ if (report_type & PVSEGS)
+ report_type |= PVS;
+ if ((report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS)) &&
+ (report_type & (PVS | LABEL)) && !args_are_pvs) {
+ log_error("Can't report LV and PV fields at the same time");
+ return 0;
+ }
+
+ /* Change report type if fields specified makes this necessary */
+ if ((report_type & PVSEGS) ||
+ ((report_type & (PVS | LABEL)) && (report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS))))
+ report_type = PVSEGS;
+ else if ((report_type & PVS) ||
+ ((report_type & LABEL) && (report_type & VGS)))
+ report_type = PVS;
+ else if (report_type & (SEGS | SEGSSTATUS))
+ report_type = SEGS;
+ else if (report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS))
+ report_type = LVS;
+
+ *final_report_type = report_type;
+ return 1;
+}
+
static int _report(struct cmd_context *cmd, int argc, char **argv,
report_type_t report_type)
{
@@ -419,7 +458,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
int r = ECMD_PROCESSED;
int aligned, buffered, headings, field_prefixes, quoted;
int columns_as_rows;
- unsigned args_are_pvs, lv_info_needed, lv_segment_status_needed;
+ unsigned args_are_pvs;
+ int lv_info_needed, lv_segment_status_needed;
int lock_global = 0;
aligned = find_config_tree_bool(cmd, report_aligned_CFG, NULL);
@@ -538,35 +578,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
columns_as_rows, selection)))
return_ECMD_FAILED;
- /* Do we need to acquire LV device info in addition? */
- lv_info_needed = (report_type & (LVSINFO | LVSINFOSTATUS)) ? 1 : 0;
-
- /* Do we need to acquire LV device status in addition? */
- lv_segment_status_needed = (report_type & (SEGSSTATUS | LVSSTATUS | LVSINFOSTATUS)) ? 1 : 0;
-
- /* Ensure options selected are compatible */
- if (report_type & (SEGS | SEGSSTATUS))
- report_type |= LVS;
- if (report_type & PVSEGS)
- report_type |= PVS;
- if ((report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS)) && (report_type & (PVS | LABEL)) && !args_are_pvs) {
- log_error("Can't report LV and PV fields at the same time");
+ if (!_get_final_report_type(args_are_pvs,
+ report_type, &lv_info_needed,
+ &lv_segment_status_needed,
+ &report_type)) {
dm_report_free(report_handle);
return ECMD_FAILED;
}
- /* Change report type if fields specified makes this necessary */
- if ((report_type & PVSEGS) ||
- ((report_type & (PVS | LABEL)) && (report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS))))
- report_type = PVSEGS;
- else if ((report_type & PVS) ||
- ((report_type & LABEL) && (report_type & VGS)))
- report_type = PVS;
- else if (report_type & (SEGS | SEGSSTATUS))
- report_type = SEGS;
- else if (report_type & (LVS | LVSINFO | LVSSTATUS | LVSINFOSTATUS))
- report_type = LVS;
-
/*
* We lock VG_GLOBAL to enable use of metadata cache.
* This can pause alongide pvscan or vgscan process for a while.
9 years, 3 months
master - toollib: select the whole structure if at least one of its items is selected
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=de273247118a91...
Commit: de273247118a9183eb8ba6a4615699edcb49dc2d
Parent: 56011918e66adf1f639436fd6781a89ad61eb8f4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 3 14:20:00 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:32 2015 +0100
toollib: select the whole structure if at least one of its items is selected
This applies to:
- process_each_lv_in_vg - the VG is selected only if at least one of its LVs is selected
- process_each_segment_in_lv - the LV is selected only if at least one of its LV segments is selected
- process_each_pv_in_vg - the VG is selected only if at least one of its PVs is selected
- process_each_segment_in_pv - the PV is selected only if at least one of its PV segments is selected
So this patch causes the selection result to be properly propagated up to callers.
---
tools/toollib.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index e38aab1..7d406ba 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -198,6 +198,28 @@ int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsiste
}
/*
+ * This functiona updates the "selected" arg only if last item processed
+ * is selected so this implements the "whole structure is selected if
+ * at least one of its items is selected".
+ */
+static void _update_selection_result(struct processing_handle *handle, int *selected)
+{
+ if (!handle || !handle->selection_handle)
+ return;
+
+ if (handle->selection_handle->selected)
+ *selected = 1;
+}
+
+static void _set_final_selection_result(struct processing_handle *handle, int selected)
+{
+ if (!handle || !handle->selection_handle)
+ return;
+
+ handle->selection_handle->selected = selected;
+}
+
+/*
* Metadata iteration functions
*/
int process_each_segment_in_pv(struct cmd_context *cmd,
@@ -207,6 +229,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
process_single_pvseg_fn_t process_single_pvseg)
{
struct pv_segment *pvseg;
+ int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
struct pv_segment _free_pv_segment = { .pv = pv };
@@ -223,6 +246,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
return_ECMD_FAILED;
ret = process_single_pvseg(cmd, vg, pvseg, handle);
+ _update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
@@ -230,6 +254,8 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
}
}
+ /* the PV is selected if at least one PV segment is selected */
+ _set_final_selection_result(handle, whole_selected);
return ret_max;
}
@@ -239,6 +265,7 @@ int process_each_segment_in_lv(struct cmd_context *cmd,
process_single_seg_fn_t process_single_seg)
{
struct lv_segment *seg;
+ int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
@@ -247,12 +274,15 @@ int process_each_segment_in_lv(struct cmd_context *cmd,
return_ECMD_FAILED;
ret = process_single_seg(cmd, seg, handle);
+ _update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
ret_max = ret;
}
+ /* the LV is selected if at least one LV segment is selected */
+ _set_final_selection_result(handle, whole_selected);
return ret_max;
}
@@ -1643,6 +1673,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
const char *vg_name;
const char *vg_uuid;
int selected;
+ int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
int skip;
@@ -1680,6 +1711,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
(!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) &&
select_match_vg(cmd, handle, vg, &selected) && selected) {
ret = process_single_vg(cmd, vg_name, vg, handle);
+ _update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
@@ -1692,6 +1724,8 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
unlock_and_release_vg(cmd, vg, vg_name);
}
+ /* the VG is selected if at least one LV is selected */
+ _set_final_selection_result(handle, whole_selected);
return ret_max;
}
@@ -1800,6 +1834,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int ret_max = ECMD_PROCESSED;
int ret = 0;
int selected;
+ int whole_selected = 0;
int handle_supplied = handle != NULL;
unsigned process_lv;
unsigned process_all = 0;
@@ -1902,6 +1937,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
log_very_verbose("Processing LV %s in VG %s.", lvl->lv->name, vg->name);
ret = process_single_lv(cmd, lvl->lv, handle);
+ if (handle_supplied)
+ _update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
@@ -1926,6 +1963,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle, 1);
+ else
+ _set_final_selection_result(handle, whole_selected);
return ret_max;
}
@@ -2697,6 +2736,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
struct processing_handle *handle,
process_single_pv_fn_t process_single_pv)
{
+ int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
struct pv_list *pvl;
@@ -2706,12 +2746,14 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
return_ECMD_FAILED;
ret = process_single_pv(cmd, vg, pvl->pv, handle);
+ _update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
ret_max = ret;
}
+ _set_final_selection_result(handle, whole_selected);
return ret_max;
}
9 years, 3 months
master - toollib: initialize handles (including reporting for selection) for _select_match_* used in process_each_* fns
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=56011918e66adf...
Commit: 56011918e66adf1f639436fd6781a89ad61eb8f4
Parent: a91bc7a19b8f439fa1d21101ad5c11d72413d4c0
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 28 15:04:25 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:29 2015 +0100
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.
---
tools/lvconvert.c | 16 ++++--
tools/polldaemon.c | 2 +
tools/pvresize.c | 11 +++--
tools/toollib.c | 135 +++++++++++++++++++++++++++++++++++----------------
tools/vgcfgbackup.c | 1 +
5 files changed, 113 insertions(+), 52 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index f9f666d..2df2483 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -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 ret = ECMD_PROCESSED;
struct lvconvert_params lp = {
.target_attr = ~0,
};
@@ -3547,13 +3548,16 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
.custom_handle = &lp };
if (!_read_params(cmd, argc, argv, &lp)) {
- stack;
- return EINVALID_CMD_LINE;
+ ret = EINVALID_CMD_LINE;
+ goto_out;
}
if (lp.merge)
- return process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &handle,
- &_lvconvert_merge_single);
-
- return lvconvert_single(cmd, &lp);
+ ret = process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &handle,
+ &_lvconvert_merge_single);
+ else
+ ret = lvconvert_single(cmd, &lp);
+out:
+ destroy_processing_handle(cmd, &handle, 0);
+ return ret;
}
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index 3eb9b17..204c495 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -240,6 +240,8 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
break;
sleep(parms->interval);
}
+
+ destroy_processing_handle(cmd, &handle, 0);
}
/*
diff --git a/tools/pvresize.c b/tools/pvresize.c
index a2f6b8b..f6253d9 100644
--- a/tools/pvresize.c
+++ b/tools/pvresize.c
@@ -50,16 +50,18 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
struct processing_handle handle = { .internal_report_for_select = 1,
.selection_handle = NULL,
.custom_handle = ¶ms };
- int ret;
+ int ret = ECMD_PROCESSED;
if (!argc) {
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) {
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,
@@ -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) "
"not resized", params.done, params.total - params.done);
-
+out:
+ destroy_processing_handle(cmd, &handle, 0);
return ret;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index 0ce3c50..e38aab1 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1731,6 +1731,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
uint32_t flags, struct processing_handle *handle,
process_single_vg_fn_t process_single_vg)
{
+ int handle_supplied = handle != NULL;
struct dm_list arg_tags; /* str_list */
struct dm_list arg_vgnames; /* str_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.
*/
- if ((ret = _get_arg_vgnames(cmd, argc, argv, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
- stack;
- return ret;
- }
+ if ((ret = _get_arg_vgnames(cmd, argc, argv, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED)
+ goto_out;
/*
* 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.
*/
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)) {
- stack;
- return ret;
- }
+ ((ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0)) != ECMD_PROCESSED))
+ goto_out;
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
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))
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) {
- stack;
- return ret;
- }
+ else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
+ goto_out;
+
+ if (!handle && !(handle = init_processing_handle(cmd)))
+ goto_out;
- return _process_vgnameid_list(cmd, flags, &vgnameids_to_process,
- &arg_vgnames, &arg_tags, handle, process_single_vg);
+ 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,
@@ -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 = 0;
int selected;
+ int handle_supplied = handle != NULL;
unsigned process_lv;
unsigned process_all = 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 dm_str_list *sl;
- if (!vg_check_status(vg, EXPORTED_VG))
- return_ECMD_FAILED;
+ if (!vg_check_status(vg, EXPORTED_VG)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
if (tags_in && !dm_list_empty(tags_in))
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))
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
* or if VG tags match. */
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.
*/
dm_list_iterate_items(lvl, &vg->lvs) {
- if (sigint_caught())
- return_ECMD_FAILED;
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
if (lvl->lv->status & SNAPSHOT)
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;
- if (sigint_caught())
- return_ECMD_FAILED;
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
if (!process_lv)
continue;
@@ -1883,7 +1908,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
ret_max = ret;
if (stop_on_error && ret != ECMD_PROCESSED)
- return ret_max;
+ goto_out;
}
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;
}
}
-
+out:
+ if (!handle_supplied)
+ destroy_processing_handle(cmd, handle, 1);
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,
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_vgnames; /* 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.
*/
- if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED)) {
- stack;
- return ret;
- }
+ if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED))
+ goto_out;
+
+ 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:
* any tags were supplied and need resolving; or
* 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)) &&
- (ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0) != ECMD_PROCESSED)) {
- stack;
- return ret;
- }
+ if (((dm_list_empty(&arg_vgnames) && (enable_all_vgs ||
+ handle->internal_report_for_select)) || !dm_list_empty(&arg_tags)) &&
+ (ret = _get_vgnameids_on_system(cmd, &vgnameids_on_system, NULL, 0) != ECMD_PROCESSED))
+ goto_out;
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
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))
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) {
- stack;
- return ret;
- }
+ else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
+ goto_out;
- return _process_lv_vgnameid_list(cmd, flags, &vgnameids_to_process, &arg_vgnames, &arg_lvnames,
- &arg_tags, handle, process_single_lv);
+ ret = _process_lv_vgnameid_list(cmd, flags, &vgnameids_to_process, &arg_vgnames, &arg_lvnames,
+ &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,
@@ -2336,6 +2371,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct processing_handle *handle,
process_single_pv_fn_t process_single_pv)
{
+ int handle_supplied = handle != NULL;
struct physical_volume *pv;
struct pv_list *pvl;
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 = 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) {
- if (sigint_caught())
- return_ECMD_FAILED;
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
pv = pvl->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))
break;
}
-
+out:
+ if (!handle_supplied)
+ destroy_processing_handle(cmd, handle, 1);
return ret_max;
}
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index ee65f18..0a6c5f2 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -96,5 +96,6 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
init_pvmove(0);
+ destroy_processing_handle(cmd, &handle, 0);
return ret;
}
9 years, 3 months
master - toollib: add init_processing_handle, init_selection_handle and destroy_processing_handle helper functions
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a91bc7a19b8f43...
Commit: a91bc7a19b8f439fa1d21101ad5c11d72413d4c0
Parent: c3180c4a05ea947b379e9e9bc51e50d0ca329980
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 28 14:46:18 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:27 2015 +0100
toollib: add init_processing_handle, init_selection_handle and destroy_processing_handle helper functions
The init_processing_handle, init_selection_handle and
destroy_processing_handle are helper functions that allocate and
initialize the handles used when processing items in process_each_*
and related functions.
---
tools/toollib.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/toollib.h | 5 +++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 13cb034..0ce3c50 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1542,6 +1542,59 @@ static int _get_vgnameids_on_system(struct cmd_context *cmd,
return ECMD_PROCESSED;
}
+struct processing_handle *init_processing_handle(struct cmd_context *cmd)
+{
+ struct processing_handle *handle;
+
+ if (!(handle = dm_pool_zalloc(cmd->mem, sizeof(struct processing_handle)))) {
+ log_error("_init_processing_handle: failed to allocate memory for processing handle");
+ return NULL;
+ }
+
+ /*
+ * For any reporting tool, the internal_report_for_select is reset to 0
+ * automatically because the internal reporting/selection is simply not
+ * needed - the reporting/selection is already a part of the code path
+ * used there.
+ *
+ * *The internal report for select is only needed for non-reporting tools!*
+ */
+ handle->internal_report_for_select = arg_is_set(cmd, select_ARG);
+
+ return handle;
+}
+
+int init_selection_handle(struct cmd_context *cmd, struct processing_handle *handle)
+{
+ struct selection_handle *sh;
+
+ if (!(sh = dm_pool_zalloc(cmd->mem, sizeof(struct selection_handle)))) {
+ log_error("_init_selection_handle: failed to allocate memory for selection handle");
+ return 0;
+ }
+
+ if (!(sh->selection_rh = report_init_for_selection(cmd, &sh->report_type,
+ arg_str_value(cmd, select_ARG, NULL)))) {
+ dm_pool_free(cmd->mem, sh);
+ return_0;
+ }
+
+ handle->selection_handle = sh;
+ return 1;
+}
+
+void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle *handle,
+ int deallocate_handle_root)
+{
+ if (handle) {
+ if (handle->selection_handle && handle->selection_handle->selection_rh)
+ dm_report_free(handle->selection_handle->selection_rh);
+ if (deallocate_handle_root)
+ dm_pool_free(cmd->mem, handle);
+ }
+}
+
+
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, int *selected)
{
diff --git a/tools/toollib.h b/tools/toollib.h
index ead36d3..4050117 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -137,6 +137,11 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int stop_on_error, struct processing_handle *handle,
process_single_lv_fn_t process_single_lv);
+struct processing_handle *init_processing_handle(struct cmd_context *cmd);
+int init_selection_handle(struct cmd_context *cmd, struct processing_handle *handle);
+void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle *handle,
+ int deallocate_handle_root);
+
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, int *selected);
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
9 years, 3 months
master - toollib: pass struct processing_handle to _select_match_* functions
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c3180c4a05ea94...
Commit: c3180c4a05ea947b379e9e9bc51e50d0ca329980
Parent: a64b39aef80d790dd4afe4ce8fdaa0ed1b0e2c48
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 28 14:34:56 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 10 16:05:26 2015 +0100
toollib: pass struct processing_handle to _select_match_* functions
The "struct processing_handle" contains handles to drive the selection/matching
so pass it to the _select_match_* functions which are entry points to the
selection mechanism used in process_each_* and related functions.
This is revised and edited version of former Dave Teigland's patch which
provided starting point for all the select support in process_each_* fns.
---
tools/toollib.c | 32 ++++++++++++++++++++++++--------
tools/toollib.h | 12 ++++++------
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 759769e..13cb034 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1542,22 +1542,38 @@ 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)
+int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
+ struct volume_group *vg, int *selected)
{
+ if (!handle->internal_report_for_select) {
+ *selected = 1;
+ return 1;
+ }
+
*selected = 1;
return 1;
}
-int select_match_lv(struct cmd_context *cmd, struct volume_group *vg,
- struct logical_volume *lv, int *selected)
+int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
+ struct volume_group *vg, struct logical_volume *lv, int *selected)
{
+ if (!handle->internal_report_for_select) {
+ *selected = 1;
+ return 1;
+ }
+
*selected = 1;
return 1;
}
-int select_match_pv(struct cmd_context *cmd, struct volume_group *vg,
- struct physical_volume *pv, int *selected)
+int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
+ struct volume_group *vg, struct physical_volume *pv, int *selected)
{
+ if (!handle->internal_report_for_select) {
+ *selected = 1;
+ return 1;
+ }
+
*selected = 1;
return 1;
}
@@ -1609,7 +1625,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
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))) &&
- select_match_vg(cmd, vg, &selected) && selected) {
+ select_match_vg(cmd, handle, vg, &selected) && selected) {
ret = process_single_vg(cmd, vg_name, vg, handle);
if (ret != ECMD_PROCESSED)
stack;
@@ -1797,7 +1813,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
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;
+ process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv, &selected) && selected;
if (sigint_caught())
return_ECMD_FAILED;
@@ -2307,7 +2323,7 @@ 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;
+ process_pv = process_pv && select_match_pv(cmd, handle, vg, pv, &selected) && selected;
if (process_pv) {
if (skip)
diff --git a/tools/toollib.h b/tools/toollib.h
index cc86227..ead36d3 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -137,12 +137,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int stop_on_error, struct processing_handle *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);
+int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
+ struct volume_group *vg, int *selected);
+int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
+ struct volume_group *vg, struct logical_volume *lv, int *selected);
+int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
+ 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,
9 years, 3 months