master - report: add --logonly arg to report only log for a command
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=92caebab95353e...
Commit: 92caebab95353e13b37fc724a6f31c23c8fd2cac
Parent: 3e8e8ddb4619bbc16e28ba0d84d43868271516e5
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Jun 15 13:35:27 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
report: add --logonly arg to report only log for a command
---
WHATS_NEW | 1 +
lib/report/report.h | 2 +-
tools/args.h | 1 +
tools/commands.h | 52 +++++++++++++++++++++++++++++---------------------
tools/reporter.c | 28 +++++++++++++++++---------
tools/toollib.c | 3 +-
tools/toollib.h | 1 +
7 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 8a4f7d5..86a53ce 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Add --logonly option to report only cmd log for a command, not other reports.
Add log/command_log_selection to configure default selection used on cmd log.
Use 'orphan' object type in cmd log for groups to collect PVs not yet in VGs.
Add lvm lastlog command for query and display of last cmd's log in lvm shell.
diff --git a/lib/report/report.h b/lib/report/report.h
index 9d9d01f..b9028fe 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -83,7 +83,7 @@ typedef int (*field_report_fn) (struct report_handle * dh, struct field * field,
int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_group_type,
struct dm_report_group **report_group, struct dm_report **log_rh,
- log_report_t *saved_log_report_state);
+ int *log_only, log_report_t *saved_log_report_state);
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
diff --git a/tools/args.h b/tools/args.h
index b7b2262..670d6a0 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -55,6 +55,7 @@ arg(lockopt_ARG, '\0', "lockopt", string_arg, 0, 0)
arg(lockstart_ARG, '\0', "lockstart", NULL, 0, 0)
arg(lockstop_ARG, '\0', "lockstop", NULL, 0, 0)
arg(locktype_ARG, '\0', "locktype", locktype_arg, 0, 0)
+arg(logonly_ARG, '\0', "logonly", NULL, 0, 0)
arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", size_kb_arg, 0, 0)
arg(merge_ARG, '\0', "merge", NULL, 0, 0)
arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0, 0)
diff --git a/tools/commands.h b/tools/commands.h
index d54a50c..4bebcd4 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -149,6 +149,7 @@ xx(fullreport,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--nameprefixes]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
@@ -169,10 +170,10 @@ xx(fullreport,
"\t[VolumeGroupName [VolumeGroupName...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
- ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG,
- rows_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, trustcache_ARG,
- unbuffered_ARG, units_ARG, unquoted_ARG)
+ ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
+ reportformat_ARG, rows_ARG, select_ARG, separator_ARG, shared_ARG,
+ sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(lastlog,
"Display last command's log report",
@@ -486,6 +487,7 @@ xx(lvdisplay,
"\t[-H|--history]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\n"
@@ -504,7 +506,7 @@ xx(lvdisplay,
aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG,
history_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
- maps_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG,
+ logonly_ARG, maps_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG,
partial_ARG, readonly_ARG, reportformat_ARG, segments_ARG, select_ARG,
separator_ARG, shared_ARG, unbuffered_ARG, units_ARG)
@@ -730,6 +732,7 @@ xx(lvs,
"\t[-H|--history]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--nameprefixes]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
@@ -751,11 +754,11 @@ xx(lvs,
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
aligned_ARG, all_ARG, binary_ARG, configreport_ARG, foreign_ARG, history_ARG,
- ignorelockingfailure_ARG, ignoreskippedcluster_ARG, nameprefixes_ARG,
- noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
- readonly_ARG, reportformat_ARG, rows_ARG, segments_ARG, select_ARG,
- separator_ARG, shared_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG,
- units_ARG, unquoted_ARG)
+ ignorelockingfailure_ARG, ignoreskippedcluster_ARG, logonly_ARG,
+ nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG,
+ options_ARG, partial_ARG, readonly_ARG, reportformat_ARG, rows_ARG,
+ segments_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG,
+ trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(lvscan,
"List all logical volumes in all volume groups",
@@ -918,6 +921,7 @@ xx(pvdisplay,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\n"
@@ -933,7 +937,7 @@ xx(pvdisplay,
"\t[PhysicalVolumePath [PhysicalVolumePath...]]\n",
aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG,
- ignorelockingfailure_ARG, ignoreskippedcluster_ARG, maps_ARG,
+ ignorelockingfailure_ARG, ignoreskippedcluster_ARG, logonly_ARG, maps_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG, readonly_ARG, reportformat_ARG,
select_ARG, separator_ARG, shared_ARG, short_ARG, sort_ARG, unbuffered_ARG,
units_ARG)
@@ -1014,6 +1018,7 @@ xx(pvs,
"\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--nameprefixes]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
@@ -1035,10 +1040,11 @@ xx(pvs,
"\t[PhysicalVolume [PhysicalVolume...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
- ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG,
- rows_ARG, segments_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG,
- trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
+ ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
+ reportformat_ARG, rows_ARG, segments_ARG, select_ARG, separator_ARG,
+ shared_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG,
+ unquoted_ARG)
xx(pvscan,
"List all physical volumes",
@@ -1265,6 +1271,7 @@ xx(vgdisplay,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\n"
@@ -1282,9 +1289,9 @@ xx(vgdisplay,
activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG,
foreign_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
- noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
- reportformat_ARG, select_ARG, shared_ARG, short_ARG, separator_ARG,
- sort_ARG, unbuffered_ARG, units_ARG)
+ logonly_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG,
+ readonly_ARG, reportformat_ARG, select_ARG, shared_ARG, short_ARG,
+ separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
xx(vgexport,
"Unregister volume group(s) from the system",
@@ -1446,6 +1453,7 @@ xx(vgs,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
+ "\t[--logonly]\n"
"\t[--nameprefixes]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
@@ -1466,10 +1474,10 @@ xx(vgs,
"\t[VolumeGroupName [VolumeGroupName...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
- ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG,
- rows_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, trustcache_ARG,
- unbuffered_ARG, units_ARG, unquoted_ARG)
+ ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
+ reportformat_ARG, rows_ARG, select_ARG, separator_ARG, shared_ARG,
+ sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(vgscan,
"Search for all volume groups",
diff --git a/tools/reporter.c b/tools/reporter.c
index f65676e..c7dee20 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -54,6 +54,7 @@ struct report_args {
int columns_as_rows;
const char *separator;
struct volume_group *full_report_vg;
+ int log_only;
struct single_report_args single_args[REPORT_IDX_COUNT];
};
@@ -1047,7 +1048,7 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
&lv_segment_status_needed, &report_type))
goto_out;
- if (handle->report_group) {
+ if (!(args->log_only && (single_args->report_type != CMDLOG))) {
if (!dm_report_group_push(handle->report_group, report_handle, (void *) single_args->report_name))
goto_out;
report_in_group = 1;
@@ -1160,7 +1161,8 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
log_error("Failed to compact given columns in report output.");
}
- dm_report_output(report_handle);
+ if (!(args->log_only && (single_args->report_type != CMDLOG)))
+ dm_report_output(report_handle);
if (lock_global)
unlock_vg(cmd, VG_GLOBAL);
@@ -1189,7 +1191,7 @@ static int _full_report_single(struct cmd_context *cmd,
args->full_report_vg = vg;
- if (!dm_report_group_push(handle->report_group, NULL, NULL))
+ if (!args->log_only && !dm_report_group_push(handle->report_group, NULL, NULL))
goto out;
if (orphan) {
@@ -1205,7 +1207,7 @@ static int _full_report_single(struct cmd_context *cmd,
stack;
}
- if (!dm_report_group_pop(handle->report_group))
+ if (!args->log_only && !dm_report_group_pop(handle->report_group))
goto_out;
out:
args->full_report_vg = NULL;
@@ -1360,13 +1362,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, report_type_t
handle->include_historical_lvs = cmd->include_historical_lvs;
args.report_group_type = handle->report_group_type;
+ args.log_only = handle->log_only;
if (!_config_report(cmd, &args, single_args)) {
destroy_processing_handle(cmd, handle);
return_ECMD_FAILED;
}
- if (!dm_report_group_push(handle->report_group, NULL, report_name)) {
+ if (!args.log_only && !dm_report_group_push(handle->report_group, NULL, report_name)) {
log_error("Failed to add main report section to report group.");
destroy_processing_handle(cmd, handle);
return ECMD_FAILED;
@@ -1426,20 +1429,23 @@ int devtypes(struct cmd_context *cmd, int argc, char **argv)
int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_group_type,
struct dm_report_group **report_group, struct dm_report **log_rh,
- log_report_t *saved_log_report_state)
+ int *log_only, log_report_t *saved_log_report_state)
{
int config_set = find_config_tree_node(cmd, report_output_format_CFG, NULL) != NULL;
const char *config_format_str = find_config_tree_str(cmd, report_output_format_CFG, NULL);
const char *format_str = arg_str_value(cmd, reportformat_ARG, config_set ? config_format_str : NULL);
- int report_command_log = find_config_tree_bool(cmd, log_report_command_log_CFG, NULL);
+ int report_command_log;
struct report_args args = {0};
struct single_report_args *single_args;
struct dm_report_group *new_report_group;
struct dm_report *tmp_log_rh = NULL;
+ args.log_only = arg_is_set(cmd, logonly_ARG) || *log_rh;
+ report_command_log = args.log_only || find_config_tree_bool(cmd, log_report_command_log_CFG, NULL);
+
if (!format_str || !strcmp(format_str, REPORT_FORMAT_NAME_BASIC)) {
- args.report_group_type = report_command_log ? DM_REPORT_GROUP_BASIC
- : DM_REPORT_GROUP_SINGLE;
+ args.report_group_type = (report_command_log && !args.log_only) ? DM_REPORT_GROUP_BASIC
+ : DM_REPORT_GROUP_SINGLE;
} else if (!strcmp(format_str, REPORT_FORMAT_NAME_JSON)) {
args.report_group_type = DM_REPORT_GROUP_JSON;
} else {
@@ -1452,6 +1458,8 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
if (report_group_type)
*report_group_type = args.report_group_type;
+ if (log_only)
+ *log_only = args.log_only;
if (!(new_report_group = dm_report_group_create(args.report_group_type, NULL))) {
log_error("Failed to create report group.");
@@ -1517,7 +1525,7 @@ int lastlog(struct cmd_context *cmd, int argc, char **argv)
goto out;
}
- if (!report_format_init(cmd, NULL, &report_group, &cmd->log_rh, NULL))
+ if (!report_format_init(cmd, NULL, &report_group, &cmd->log_rh, NULL, NULL))
goto_out;
if (arg_count(cmd, select_ARG) &&
diff --git a/tools/toollib.c b/tools/toollib.c
index 0eb2887..fe9f9c0 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1733,7 +1733,8 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct
if (!parent_handle) {
if (!report_format_init(cmd, &handle->report_group_type, &handle->report_group,
- &handle->log_rh, &handle->saved_log_report_state)) {
+ &handle->log_rh, &handle->log_only,
+ &handle->saved_log_report_state)) {
dm_pool_free(cmd->mem, handle);
return NULL;
}
diff --git a/tools/toollib.h b/tools/toollib.h
index 1144793..42e7f7a 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -76,6 +76,7 @@ struct processing_handle {
dm_report_group_type_t report_group_type;
struct dm_report_group *report_group;
struct dm_report *log_rh;
+ int log_only;
log_report_t saved_log_report_state;
void *custom_handle;
};
7 years, 11 months
master - report: use report type description for report's name if using DM_REPORT_GROUP_BASIC output format
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3e8e8ddb4619bb...
Commit: 3e8e8ddb4619bbc16e28ba0d84d43868271516e5
Parent: 5b93db65660c5dbb5b68d458ffa4c034a4c37211
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 14 16:44:52 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
report: use report type description for report's name if using DM_REPORT_GROUP_BASIC output format
---
lib/report/report.c | 14 ++++++++++----
lib/report/report.h | 4 +++-
tools/reporter.c | 20 +++++++++++++-------
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 3b9693d..512986e 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3769,7 +3769,9 @@ void *report_init_for_selection(struct cmd_context *cmd,
cmd);
}
-const char *report_get_field_prefix(report_type_t report_type_id)
+int report_get_prefix_and_desc(report_type_t report_type_id,
+ const char **report_prefix,
+ const char **report_desc)
{
const struct dm_report_object_type *report_types, *report_type;
@@ -3781,11 +3783,15 @@ const char *report_get_field_prefix(report_type_t report_type_id)
report_types = _report_types;
for (report_type = report_types; report_type->id; report_type++) {
- if (report_type_id & report_type->id)
- return report_type->prefix;
+ if (report_type_id & report_type->id) {
+ *report_prefix = report_type->prefix;
+ *report_desc = report_type->desc;
+ return 1;
+ }
}
- return "";
+ *report_prefix = *report_desc = "";
+ return 0;
}
/*
diff --git a/lib/report/report.h b/lib/report/report.h
index e6fbc8d..9d9d01f 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -93,7 +93,9 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
int report_get_single_selection(struct cmd_context *cmd, const char **selection);
void *report_init_for_selection(struct cmd_context *cmd, report_type_t *report_type,
const char *selection);
-const char *report_get_field_prefix(report_type_t report_type);
+int report_get_prefix_and_desc(report_type_t report_type_id,
+ const char **report_prefix,
+ const char **report_desc);
int report_for_selection(struct cmd_context *cmd,
struct processing_handle *parent_handle,
struct physical_volume *pv,
diff --git a/tools/reporter.c b/tools/reporter.c
index 8564133..f65676e 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -985,9 +985,10 @@ int report_get_single_selection(struct cmd_context *cmd, const char **selection)
return _do_report_get_selection(cmd, NULL, NULL, expected_idxs, selection);
}
-static int _set_report_prefix_and_name(struct single_report_args *single_args)
+static int _set_report_prefix_and_name(struct report_args *args,
+ struct single_report_args *single_args)
{
- const char *report_prefix;
+ const char *report_prefix, *report_desc;
size_t len;
if (single_args->report_type == FULL) {
@@ -996,7 +997,8 @@ static int _set_report_prefix_and_name(struct single_report_args *single_args)
return 1;
}
- report_prefix = report_get_field_prefix(single_args->report_type);
+ (void) report_get_prefix_and_desc(single_args->report_type,
+ &report_prefix, &report_desc);
len = strlen(report_prefix);
if (report_prefix[len - 1] == '_')
len--;
@@ -1012,7 +1014,11 @@ static int _set_report_prefix_and_name(struct single_report_args *single_args)
return 0;
}
single_args->report_prefix[len] = '\0';
- single_args->report_name = single_args->report_prefix;
+
+ if (args->report_group_type != DM_REPORT_GROUP_BASIC)
+ single_args->report_name = single_args->report_prefix;
+ else
+ single_args->report_name = report_desc;
return 1;
}
@@ -1211,7 +1217,7 @@ out:
args->single_args[REPORT_IDX_FULL_ ## type].report_type = type; \
args->single_args[REPORT_IDX_FULL_ ## type].keys = find_config_tree_str(cmd, report_ ## name ## _sort_full_CFG, NULL); \
args->single_args[REPORT_IDX_FULL_ ## type].options = find_config_tree_str(cmd, report_ ## name ## _cols_full_CFG, NULL); \
- if (!_set_report_prefix_and_name(&args->single_args[REPORT_IDX_FULL_ ## type])) \
+ if (!_set_report_prefix_and_name(args, &args->single_args[REPORT_IDX_FULL_ ## type])) \
return_0; \
} while (0)
@@ -1228,7 +1234,7 @@ static int _config_report(struct cmd_context *cmd, struct report_args *args, str
/* Check PV specifics and do extra changes/actions if needed. */
_check_pv_list(cmd, args, single_args);
- if (!_set_report_prefix_and_name(single_args))
+ if (!_set_report_prefix_and_name(args, single_args))
return_0;
switch (single_args->report_type) {
@@ -1472,7 +1478,7 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
* We reusing existing log report handle.
* Just get report's name and prefix now.
*/
- if (!_set_report_prefix_and_name(single_args))
+ if (!_set_report_prefix_and_name(&args, single_args))
goto_bad;
}
7 years, 11 months
master - libdm: select: recognize special selection string 'all' as an alias for blank selection string
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5b93db65660c5d...
Commit: 5b93db65660c5dbb5b68d458ffa4c034a4c37211
Parent: 1127b090bd07065a6a5046881ba1692bd507b9da
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Jun 13 15:23:44 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
libdm: select: recognize special selection string 'all' as an alias for blank selection string
---
WHATS_NEW_DM | 1 +
libdm/libdm-report.c | 4 +++-
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 1772e18..8911e36 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.128 -
=================================
+ Recognize 'all' keyword used in selection as synonym for "" (no selection).
Add dm_report_set_selection to set selection for multiple output of report.
Add DM_REPORT_OUTPUT_MULTIPLE_TIMES flag for multiple output of same report.
Move field width handling/sort init from dm_report_object to dm_report_output.
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index cae9c66..1326fdf 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -3984,6 +3984,8 @@ static int _alloc_rh_selection(struct dm_report *rh)
return 1;
}
+#define SPECIAL_SELECTION_ALL "all"
+
static int _report_set_selection(struct dm_report *rh, const char *selection, int add_new_fields)
{
struct selection_node *root = NULL;
@@ -3999,7 +4001,7 @@ static int _report_set_selection(struct dm_report *rh, const char *selection, in
goto_bad;
}
- if (!selection)
+ if (!selection || !strcasecmp(selection, SPECIAL_SELECTION_ALL))
return 1;
rh->selection->add_new_fields = add_new_fields;
7 years, 11 months
master - conf: add log/command_log_selection config setting
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1127b090bd0706...
Commit: 1127b090bd07065a6a5046881ba1692bd507b9da
Parent: cee1aedf12310866157b2112071850a59e6386b1
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 14 13:25:03 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
conf: add log/command_log_selection config setting
---
WHATS_NEW | 1 +
conf/example.conf.in | 5 +++++
lib/config/config_settings.h | 3 +++
lib/config/defaults.h | 2 ++
tools/reporter.c | 1 +
5 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 25494cb..8a4f7d5 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Add log/command_log_selection to configure default selection used on cmd log.
Use 'orphan' object type in cmd log for groups to collect PVs not yet in VGs.
Add lvm lastlog command for query and display of last cmd's log in lvm shell.
Report per-object return codes via cmd log while processing multiple objects.
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 1918a3d..bf8f177 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -501,6 +501,11 @@ log {
# This configuration option has an automatic default value.
# command_log_cols = "log_seq_num,log_type,log_context,log_object_type,log_object_name,log_object_id,log_object_group,log_object_group_id,log_message,log_errno,log_ret_code"
+ # Configuration option log/command_log_selection.
+ # Selection criteria used when reporting command log.
+ # This configuration option has an automatic default value.
+ # command_log_selection = "!(log_type=status && message=success)"
+
# Configuration option log/verbose.
# Controls the messages sent to stdout or stderr.
verbose = 0
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 89e0771..64859e4 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -564,6 +564,9 @@ cfg(log_command_log_cols_CFG, "command_log_cols", log_CFG_SECTION, CFG_PROFILABL
"log_object_name, log_object_id, log_object_group, log_object_group_id,\n"
"log_message, log_errno, log_ret_code.\n")
+cfg(log_command_log_selection_CFG, "command_log_selection", log_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_COMMAND_LOG_SELECTION, vsn(2, 2, 158), NULL, 0, NULL,
+ "Selection criteria used when reporting command log.\n")
+
cfg(log_verbose_CFG, "verbose", log_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_VERBOSE, vsn(1, 0, 0), NULL, 0, NULL,
"Controls the messages sent to stdout or stderr.\n")
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 6c7769a..3d449ff 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -211,6 +211,8 @@
#define DEFAULT_REP_OUTPUT_FORMAT "basic"
#define DEFAULT_COMPACT_OUTPUT_COLS ""
+#define DEFAULT_COMMAND_LOG_SELECTION "!(log_type=status && message=success)"
+
#define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,pool_lv,origin,data_percent,metadata_percent,move_pv,mirror_log,copy_percent,convert_lv"
#define DEFAULT_VGS_COLS "vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free"
#define DEFAULT_PVS_COLS "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free"
diff --git a/tools/reporter.c b/tools/reporter.c
index c732d0e..8564133 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -1285,6 +1285,7 @@ static int _config_report(struct cmd_context *cmd, struct report_args *args, str
case CMDLOG:
single_args->keys = find_config_tree_str(cmd, log_command_log_sort_CFG, NULL);
single_args->options = find_config_tree_str(cmd, log_command_log_cols_CFG, NULL);
+ single_args->selection = find_config_tree_str(cmd, log_command_log_selection_CFG, NULL);
break;
default:
log_error(INTERNAL_ERROR "_report: unknown report type.");
7 years, 11 months
master - log: use separate 'orphan' report object type for orphan VGs
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cee1aedf123108...
Commit: cee1aedf12310866157b2112071850a59e6386b1
Parent: 89e2aef63a9a2b29b1f83a589d108c25236b4ae1
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jun 14 13:21:53 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
log: use separate 'orphan' report object type for orphan VGs
---
WHATS_NEW | 1 +
lib/log/log.c | 1 +
lib/log/lvm-logging.h | 1 +
tools/toollib.c | 32 ++++++++++++++++++++------------
4 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6f6e9e8..25494cb 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Use 'orphan' object type in cmd log for groups to collect PVs not yet in VGs.
Add lvm lastlog command for query and display of last cmd's log in lvm shell.
Report per-object return codes via cmd log while processing multiple objects.
Annotate processing code with log report hooks for per-object command log.
diff --git a/lib/log/log.c b/lib/log/log.c
index 0bd2de9..e8793c6 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -298,6 +298,7 @@ const char *log_get_report_context_name(log_report_context_t context)
const char *log_get_report_object_type_name(log_report_object_type_t object_type)
{
static const char *log_object_type_names[LOG_REPORT_OBJECT_TYPE_COUNT] = {[LOG_REPORT_OBJECT_TYPE_NULL] = "",
+ [LOG_REPORT_OBJECT_TYPE_ORPHAN] = "orphan",
[LOG_REPORT_OBJECT_TYPE_PV] = "pv",
[LOG_REPORT_OBJECT_TYPE_VG] = "vg",
[LOG_REPORT_OBJECT_TYPE_LV] = "lv"};
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 5789c0b..e5b8b63 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -74,6 +74,7 @@ typedef enum {
typedef enum {
LOG_REPORT_OBJECT_TYPE_NULL,
+ LOG_REPORT_OBJECT_TYPE_ORPHAN,
LOG_REPORT_OBJECT_TYPE_PV,
LOG_REPORT_OBJECT_TYPE_VG,
LOG_REPORT_OBJECT_TYPE_LV,
diff --git a/tools/toollib.c b/tools/toollib.c
index 41ef549..0eb2887 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1894,11 +1894,14 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
notfound = 0;
uuid[0] = '\0';
- if (vg_uuid && !is_orphan_vg(vg_name) &&
- !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
- stack;
-
- log_set_report_object_name_and_id(vg_name, uuid);
+ if (is_orphan_vg(vg_name)) {
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_ORPHAN);
+ log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), uuid);
+ } else {
+ if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
+ log_set_report_object_name_and_id(vg_name, uuid);
+ }
if (sigint_caught()) {
ret_max = ECMD_FAILED;
@@ -3306,7 +3309,8 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
goto_out;
}
- log_set_report_object_group_and_group_id(vg->name, vg_uuid);
+ if (!is_orphan_vg(vg->name))
+ log_set_report_object_group_and_group_id(vg->name, vg_uuid);
dm_list_iterate_items(pvl, &vg->pvs) {
pv = pvl->pv;
@@ -3430,11 +3434,14 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
notfound = 0;
uuid[0] = '\0';
- if (vg_uuid && !is_orphan_vg(vg_name) &&
- !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
- stack;
-
- log_set_report_object_name_and_id(vg_name, uuid);
+ if (is_orphan_vg(vg_name)) {
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_ORPHAN);
+ log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), uuid);
+ } else {
+ if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
+ log_set_report_object_name_and_id(vg_name, uuid);
+ }
if (sigint_caught()) {
ret_max = ECMD_FAILED;
@@ -3750,7 +3757,8 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
stack;
- log_set_report_object_group_and_group_id(vg->name, vg_uuid);
+ if (!is_orphan_vg(vg->name))
+ log_set_report_object_group_and_group_id(vg->name, vg_uuid);
dm_list_iterate_items(pvl, &vg->pvs) {
pv_uuid[0] = '\0';
7 years, 11 months
master - tools: add 'lvm lastlog' command for interactive query and display of last command's log
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=89e2aef63a9a2b...
Commit: 89e2aef63a9a2b29b1f83a589d108c25236b4ae1
Parent: c33c0545aff1d531972682c8777e5db5e8da5676
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri May 20 15:30:58 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
tools: add 'lvm lastlog' command for interactive query and display of last command's log
If we're running in lvm shell, we can keep last command's log report
for further query with possible different selection criteria for easy
log lookup.
---
WHATS_NEW | 1 +
lib/commands/toolcontext.c | 3 +++
lib/commands/toolcontext.h | 5 +++++
tools/Makefile.in | 2 +-
tools/commands.h | 9 +++++++++
tools/lvm.c | 6 ++++++
tools/reporter.c | 35 +++++++++++++++++++++++++++++++++++
tools/toollib.c | 12 ++++++++++--
8 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f800eca..6f6e9e8 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Add lvm lastlog command for query and display of last cmd's log in lvm shell.
Report per-object return codes via cmd log while processing multiple objects.
Annotate processing code with log report hooks for per-object command log.
Also pass common printed messages (besides warnings and errors) to log report.
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 076f48d..75f19c9 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -2247,6 +2247,9 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->cft_def_hash)
dm_hash_destroy(cmd->cft_def_hash);
+ if (cmd->log_rh)
+ dm_report_free(cmd->log_rh);
+
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index c04455c..ee849b5 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -186,6 +186,11 @@ struct cmd_context {
char proc_dir[PATH_MAX];
/*
+ * Command log reporting.
+ */
+ struct dm_report *log_rh; /* keep log report of last cmd for further queries if cmd line is interactive (e.g. lvm shell) */
+
+ /*
* Buffers.
*/
char display_buffer[NAME_LEN * 10]; /* ring buffer for upto 10 longest vg/lv names */
diff --git a/tools/Makefile.in b/tools/Makefile.in
index bb29176..8dfac7f 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -168,7 +168,7 @@ liblvm2cmd.$(LIB_SUFFIX).$(LIB_VERSION): liblvm2cmd.$(LIB_SUFFIX)
.commands: $(srcdir)/commands.h $(srcdir)/cmdnames.h Makefile
$(CC) -E -P $(srcdir)/cmdnames.h 2> /dev/null | \
- egrep -v '^ *(|#.*|config|devtypes|dumpconfig|formats|fullreport|help|lvpoll|pvdata|segtypes|systemid|tags|version) *$$' > .commands
+ egrep -v '^ *(|#.*|config|devtypes|dumpconfig|formats|fullreport|help|lastlog|lvpoll|pvdata|segtypes|systemid|tags|version) *$$' > .commands
ifneq ("$(CFLOW_CMD)", "")
CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES))
diff --git a/tools/commands.h b/tools/commands.h
index 3f0fff5..d54a50c 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -174,6 +174,15 @@ xx(fullreport,
rows_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, trustcache_ARG,
unbuffered_ARG, units_ARG, unquoted_ARG)
+xx(lastlog,
+ "Display last command's log report",
+ PERMITTED_READ_ONLY | NO_METADATA_PROCESSING,
+ "log\n"
+ "\t[--reportformat {json}]\n"
+ "\t[-S|--select Selection]\n",
+
+ reportformat_ARG, select_ARG)
+
xx(lvchange,
"Change the attributes of logical volume(s)",
CACHE_VGMETADATA | PERMITTED_READ_ONLY,
diff --git a/tools/lvm.c b/tools/lvm.c
index 18e3490..62cc141 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -235,6 +235,12 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
break;
}
+ if (cmd->log_rh && strcmp(argv[0], "lastlog")) {
+ /* drop old log report */
+ dm_report_free(cmd->log_rh);
+ cmd->log_rh = NULL;
+ }
+
ret = lvm_run_command(cmd, argc, argv);
if (ret == ENO_SUCH_CMD)
log_error("No such command '%s'. Try 'help'.",
diff --git a/tools/reporter.c b/tools/reporter.c
index 3df4bac..c732d0e 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -1497,3 +1497,38 @@ bad:
dm_report_free(tmp_log_rh);
return 0;
}
+
+int lastlog(struct cmd_context *cmd, int argc, char **argv)
+{
+ static report_idx_t expected_idxs[] = {REPORT_IDX_SINGLE, REPORT_IDX_LOG, REPORT_IDX_NULL};
+ struct dm_report_group *report_group = NULL;
+ const char *selection = NULL;
+ int r = ECMD_FAILED;
+
+ if (!cmd->log_rh) {
+ log_error("No log report stored.");
+ goto out;
+ }
+
+ if (!report_format_init(cmd, NULL, &report_group, &cmd->log_rh, NULL))
+ goto_out;
+
+ if (arg_count(cmd, select_ARG) &&
+ !_do_report_get_selection(cmd, NULL, NULL, expected_idxs, &selection))
+ goto_out;
+
+ if (!dm_report_set_selection(cmd->log_rh, selection)) {
+ log_error("Failed to set selection for log report.");
+ goto out;
+ }
+
+ if (!dm_report_output(cmd->log_rh) ||
+ !dm_report_group_pop(report_group))
+ goto_out;
+
+ r = ECMD_PROCESSED;
+out:
+ if (!dm_report_group_destroy(report_group))
+ stack;
+ return r;
+}
diff --git a/tools/toollib.c b/tools/toollib.c
index e044cb4..41ef549 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1778,8 +1778,16 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
if (!dm_report_group_destroy(handle->report_group))
stack;
- if (handle->log_rh)
- dm_report_free(handle->log_rh);
+ if (handle->log_rh) {
+ if (cmd->is_interactive) {
+ /*
+ * Keep log report if we're interactive so
+ * we can do further queries on this report.
+ */
+ cmd->log_rh = handle->log_rh;
+ } else
+ dm_report_free(handle->log_rh);
+ }
/*
* TODO: think about better alternatives:
* handle mempool, dm_alloc for handle memory...
7 years, 11 months
master - refactor: move 'interactive' field from struct command_line to struct cmd_context as 'is_interactive' switch
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c33c0545aff1d5...
Commit: c33c0545aff1d531972682c8777e5db5e8da5676
Parent: 0ab118774029cc955512c4a41930956ccd96a138
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri May 20 14:23:43 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
refactor: move 'interactive' field from struct command_line to struct cmd_context as 'is_interactive' switch
---
lib/commands/toolcontext.h | 1 +
tools/lvm.c | 3 ++-
tools/lvm2cmdline.h | 1 -
tools/lvmcmdline.c | 2 +-
4 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index f4beae1..c04455c 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -113,6 +113,7 @@ struct cmd_context {
* Switches.
*/
unsigned is_long_lived:1; /* optimises persistent_filter handling */
+ unsigned is_interactive:1;
unsigned check_pv_dev_sizes:1;
unsigned handles_missing_pvs:1;
unsigned handles_unknown_segments:1;
diff --git a/tools/lvm.c b/tools/lvm.c
index b7cec81..18e3490 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -193,7 +193,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
_cmdline = cmdline;
- _cmdline->interactive = 1;
+ cmd->is_interactive = 1;
while (1) {
free(input);
input = readline("lvm> ");
@@ -246,6 +246,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
}
_write_history();
}
+ cmd->is_interactive = 0;
free(input);
return 0;
diff --git a/tools/lvm2cmdline.h b/tools/lvm2cmdline.h
index 3b68af7..80bd03e 100644
--- a/tools/lvm2cmdline.h
+++ b/tools/lvm2cmdline.h
@@ -23,7 +23,6 @@ struct cmdline_context {
struct command *commands;
int num_commands;
int commands_size;
- int interactive;
};
int lvm2_main(int argc, char **argv);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 5533cb1..870a8c3 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1739,7 +1739,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
stack;
}
- if (ret == EINVALID_CMD_LINE && !_cmdline.interactive)
+ if (ret == EINVALID_CMD_LINE && !cmd->is_interactive)
_short_usage(cmd->command->name);
log_debug("Completed: %s", cmd->cmd_line);
7 years, 11 months
master - log: annotate processing code with report_current_object_cmdlog
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0ab118774029cc...
Commit: 0ab118774029cc955512c4a41930956ccd96a138
Parent: 6ca28ca4c69b66b07ebcc19cea02b8317c6df0bf
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon May 23 15:27:09 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
log: annotate processing code with report_current_object_cmdlog
---
WHATS_NEW | 1 +
lib/report/report.h | 3 +++
tools/toollib.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index fedc1e8..f800eca 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Report per-object return codes via cmd log while processing multiple objects.
Annotate processing code with log report hooks for per-object command log.
Also pass common printed messages (besides warnings and errors) to log report.
Log warnings and errors via report during cmd processing if this is enabled.
diff --git a/lib/report/report.h b/lib/report/report.h
index f2880ec..e6fbc8d 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -111,6 +111,9 @@ int report_cmdlog(void *handle, const char *type, const char *context,
const char *object_id, const char *object_group,
const char *object_group_id, const char *msg,
int current_errno, int ret_code);
+#define REPORT_OBJECT_CMDLOG_NAME "status"
+#define REPORT_OBJECT_CMDLOG_SUCCESS "success"
+#define REPORT_OBJECT_CMDLOG_FAILURE "failure"
int report_current_object_cmdlog(const char *type, const char *msg, int32_t ret_code);
int report_output(void *handle);
diff --git a/tools/toollib.c b/tools/toollib.c
index 08178f6..e044cb4 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -22,6 +22,10 @@
#include <sys/wait.h>
#include <sys/utsname.h>
+#define report_log_ret_code(ret_code) report_current_object_cmdlog(REPORT_OBJECT_CMDLOG_NAME, \
+ ret_code == ECMD_PROCESSED ? REPORT_OBJECT_CMDLOG_SUCCESS \
+ : REPORT_OBJECT_CMDLOG_FAILURE, ret_code)
+
struct device_id_list {
struct dm_list list;
struct device *dev;
@@ -1862,6 +1866,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
int notfound;
int process_all = 0;
int already_locked;
+ int do_report_ret_code = 1;
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
@@ -1896,6 +1901,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
continue;
}
@@ -1905,6 +1911,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
if (_ignore_vg(vg, vg_name, arg_vgnames, read_flags, &skip, ¬found)) {
stack;
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
goto endvg;
}
if (skip || notfound)
@@ -1922,6 +1929,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
_update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
}
@@ -1935,10 +1943,12 @@ endvg:
log_set_report_object_name_and_id(NULL, NULL);
}
-
/* the VG is selected if at least one LV is selected */
_set_final_selection_result(handle, whole_selected);
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -2304,6 +2314,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
struct dm_list final_lvs;
struct lv_list *final_lvl;
struct glv_list *glvl, *tglvl;
+ int do_report_ret_code = 1;
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV);
@@ -2459,11 +2470,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
_update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
if (stop_on_error && ret != ECMD_PROCESSED) {
- log_set_report_object_name_and_id(NULL, NULL);
+ do_report_ret_code = 0;
goto_out;
}
}
@@ -2509,11 +2521,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
_update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
if (stop_on_error && ret != ECMD_PROCESSED) {
- log_set_report_object_name_and_id(NULL, NULL);
+ do_report_ret_code = 0;
goto_out;
}
}
@@ -2531,9 +2544,13 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
vg->name, sl->str);
if (ret_max < ECMD_FAILED)
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
}
}
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_set_report_object_name_and_id(NULL, NULL);
log_set_report_object_group_and_group_id(NULL, NULL);
if (!handle_supplied)
@@ -2701,6 +2718,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
int skip;
int notfound;
int already_locked;
+ int do_report_ret_code = 1;
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
@@ -2756,6 +2774,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
continue;
}
@@ -2765,6 +2784,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
if (_ignore_vg(vg, vg_name, arg_vgnames, read_flags, &skip, ¬found)) {
stack;
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
goto endvg;
}
if (skip || notfound)
@@ -2774,6 +2794,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
handle, process_single_lv);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
@@ -2785,7 +2806,10 @@ endvg:
stack;
log_set_report_object_name_and_id(NULL, NULL);
}
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -3253,6 +3277,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct device_id_list *dil;
const char *pv_name;
int process_pv;
+ int do_report_ret_code = 1;
int ret_max = ECMD_PROCESSED;
int ret = 0;
@@ -3327,6 +3352,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
ret = process_single_pv(cmd, vg, pv, handle);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
}
@@ -3339,7 +3365,10 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
break;
log_set_report_object_name_and_id(NULL, NULL);
}
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_set_report_object_name_and_id(NULL, NULL);
log_set_report_object_group_and_group_id(NULL, NULL);
if (!handle_supplied)
@@ -3382,6 +3411,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
int skip;
int notfound;
int already_locked;
+ int do_report_ret_code;
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
@@ -3405,6 +3435,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
continue;
}
@@ -3416,6 +3447,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
if (_ignore_vg(vg, vg_name, NULL, read_flags, &skip, ¬found)) {
stack;
ret_max = ECMD_FAILED;
+ report_log_ret_code(ret_max);
if (!skip)
goto endvg;
/* Drop through to eliminate a clustered VG's PVs from the devices list */
@@ -3433,6 +3465,7 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
handle, process_single_pv);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
@@ -3444,12 +3477,17 @@ endvg:
stack;
/* Quit early when possible. */
- 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)) {
+ do_report_ret_code = 0;
goto_out;
+ }
log_set_report_object_name_and_id(NULL, NULL);
}
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -3695,6 +3733,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
+ int do_report_ret_code = 1;
struct pv_list *pvl;
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV);
@@ -3721,6 +3760,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
_update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
stack;
+ report_log_ret_code(ret);
if (ret > ret_max)
ret_max = ret;
@@ -3728,7 +3768,10 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
}
_set_final_selection_result(handle, whole_selected);
+ do_report_ret_code = 0;
out:
+ if (do_report_ret_code)
+ report_log_ret_code(ret_max);
log_restore_report_state(saved_log_report_state);
return ret_max;
}
7 years, 11 months
master - log: annotate processing code with log_set_report_{context, object_type, id_and_name}
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6ca28ca4c69b66...
Commit: 6ca28ca4c69b66b07ebcc19cea02b8317c6df0bf
Parent: 1b107adc1da26efe6e328e969c69d619436b0366
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri May 20 13:26:02 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
log: annotate processing code with log_set_report_{context,object_type,id_and_name}
---
WHATS_NEW | 1 +
tools/toollib.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 170 insertions(+), 32 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 823eeaf..fedc1e8 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.158 -
=================================
+ Annotate processing code with log report hooks for per-object command log.
Also pass common printed messages (besides warnings and errors) to log report.
Log warnings and errors via report during cmd processing if this is enabled.
Make it possible to iterate over internal 'orphan' VGs in process_each_vg fn.
diff --git a/tools/toollib.c b/tools/toollib.c
index fe162d1..08178f6 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1736,6 +1736,7 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct
} else
handle->saved_log_report_state = log_get_report_state();
+ log_set_report_context(LOG_REPORT_CONTEXT_PROCESSING);
return handle;
}
@@ -1847,6 +1848,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
struct processing_handle *handle,
process_single_vg_fn_t process_single_vg)
{
+ log_report_t saved_log_report_state = log_get_report_state();
char uuid[64] __attribute__((aligned(8)));
struct volume_group *vg;
struct vgnameid_list *vgnl;
@@ -1861,6 +1863,8 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
int process_all = 0;
int already_locked;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
+
/*
* If no VG names or tags were supplied, then process all VGs.
*/
@@ -1871,19 +1875,24 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
* FIXME If one_vgname, only proceed if exactly one VG matches tags or selection.
*/
dm_list_iterate_items(vgnl, vgnameids_to_process) {
- if (sigint_caught())
- return_ECMD_FAILED;
-
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
skip = 0;
notfound = 0;
+ uuid[0] = '\0';
if (vg_uuid && !is_orphan_vg(vg_name) &&
!id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
stack;
- log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
+ log_set_report_object_name_and_id(vg_name, uuid);
+
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
+
+ log_very_verbose("Processing VG %s %s", vg_name, uuid);
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
@@ -1923,10 +1932,14 @@ endvg:
release_vg(vg);
if (!lockd_vg(cmd, vg_name, "un", 0, &lockd_state))
stack;
+
+ log_set_report_object_name_and_id(NULL, NULL);
}
/* the VG is selected if at least one LV is selected */
_set_final_selection_result(handle, whole_selected);
+out:
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -2100,6 +2113,7 @@ int process_each_vg(struct cmd_context *cmd,
struct processing_handle *handle,
process_single_vg_fn_t process_single_vg)
{
+ log_report_t saved_log_report_state = log_get_report_state();
int handle_supplied = handle != NULL;
struct dm_list arg_tags; /* str_list */
struct dm_list arg_vgnames; /* str_list */
@@ -2110,6 +2124,7 @@ int process_each_vg(struct cmd_context *cmd,
int ret_max = ECMD_PROCESSED;
int ret;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
log_debug("Processing each VG");
/* Disable error in vg_read so we can print it from ignore_vg. */
@@ -2221,6 +2236,7 @@ out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -2272,6 +2288,9 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
struct processing_handle *handle,
process_single_lv_fn_t process_single_lv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
+ char lv_uuid[64] __attribute__((aligned(8)));
+ char vg_uuid[64] __attribute__((aligned(8)));
int ret_max = ECMD_PROCESSED;
int ret = 0;
int whole_selected = 0;
@@ -2286,6 +2305,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
struct lv_list *final_lvl;
struct glv_list *glvl, *tglvl;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV);
+
+ vg_uuid[0] = '\0';
+ if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
+ stack;
+
dm_list_init(&final_lvs);
if (!vg_check_status(vg, EXPORTED_VG)) {
@@ -2316,7 +2341,15 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
(tags_supplied && str_list_match_list(tags_in, &vg->tags, NULL)))
process_all = 1;
+ log_set_report_object_group_and_group_id(vg->name, vg_uuid);
+
dm_list_iterate_items(lvl, &vg->lvs) {
+ lv_uuid[0] = '\0';
+ if (!id_write_format(&lvl->lv->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(lvl->lv->name, lv_uuid);
+
if (sigint_caught()) {
ret_max = ECMD_FAILED;
goto_out;
@@ -2398,8 +2431,15 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
final_lvl->lv = lvl->lv;
dm_list_add(&final_lvs, &final_lvl->list);
}
+ log_set_report_object_name_and_id(NULL, NULL);
dm_list_iterate_items(lvl, &final_lvs) {
+ lv_uuid[0] = '\0';
+ if (!id_write_format(&lvl->lv->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(lvl->lv->name, lv_uuid);
+
if (sigint_caught()) {
ret_max = ECMD_FAILED;
goto_out;
@@ -2422,9 +2462,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (ret > ret_max)
ret_max = ret;
- if (stop_on_error && ret != ECMD_PROCESSED)
+ if (stop_on_error && ret != ECMD_PROCESSED) {
+ log_set_report_object_name_and_id(NULL, NULL);
goto_out;
+ }
}
+ log_set_report_object_name_and_id(NULL, NULL);
if (handle->include_historical_lvs && !tags_supplied) {
if (!dm_list_size(&_historical_lv.segments))
@@ -2432,6 +2475,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
_historical_lv.vg = vg;
dm_list_iterate_items_safe(glvl, tglvl, &vg->historical_lvs) {
+ lv_uuid[0] = '\0';
+ if (!id_write_format(&glvl->glv->historical->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(glvl->glv->historical->name, lv_uuid);
+
process_lv = process_all;
if (lvargs_supplied &&
@@ -2463,9 +2512,12 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (ret > ret_max)
ret_max = ret;
- if (stop_on_error && ret != ECMD_PROCESSED)
+ if (stop_on_error && ret != ECMD_PROCESSED) {
+ log_set_report_object_name_and_id(NULL, NULL);
goto_out;
+ }
}
+ log_set_report_object_name_and_id(NULL, NULL);
}
if (lvargs_supplied) {
@@ -2474,6 +2526,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
* this leads to miscalculation that depends on the order of args.
*/
dm_list_iterate_items(sl, arg_lvnames) {
+ log_set_report_object_name_and_id(sl->str, NULL);
log_error("Failed to find logical volume \"%s/%s\"",
vg->name, sl->str);
if (ret_max < ECMD_FAILED)
@@ -2481,10 +2534,14 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
}
}
out:
+ log_set_report_object_name_and_id(NULL, NULL);
+ log_set_report_object_group_and_group_id(NULL, NULL);
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
else
_set_final_selection_result(handle, whole_selected);
+ log_restore_report_state(saved_log_report_state);
+
return ret_max;
}
@@ -2627,6 +2684,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
struct processing_handle *handle,
process_single_lv_fn_t process_single_lv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
char uuid[64] __attribute__((aligned(8)));
struct volume_group *vg;
struct vgnameid_list *vgnl;
@@ -2644,15 +2702,25 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
int notfound;
int already_locked;
- dm_list_iterate_items(vgnl, vgnameids_to_process) {
- if (sigint_caught())
- return_ECMD_FAILED;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
+ dm_list_iterate_items(vgnl, vgnameids_to_process) {
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
skip = 0;
notfound = 0;
+ uuid[0] = '\0';
+ if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(vg_name, uuid);
+
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
+
/*
* arg_lvnames contains some elements that are just "vgname"
* which means process all lvs in the vg. Other elements
@@ -2678,14 +2746,12 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
if (!str_list_add(cmd->mem, &lvnames,
dm_pool_strdup(cmd->mem, lvn + 1))) {
log_error("strlist allocation failed.");
- return ECMD_FAILED;
+ ret_max = ECMD_FAILED;
+ goto out;
}
}
}
- if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
- stack;
-
log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
@@ -2717,8 +2783,10 @@ endvg:
release_vg(vg);
if (!lockd_vg(cmd, vg_name, "un", 0, &lockd_state))
stack;
+ log_set_report_object_name_and_id(NULL, NULL);
}
-
+out:
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -2732,6 +2800,7 @@ int process_each_lv(struct cmd_context *cmd,
struct processing_handle *handle,
process_single_lv_fn_t process_single_lv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
int handle_supplied = handle != NULL;
struct dm_list arg_tags; /* str_list */
struct dm_list arg_vgnames; /* str_list */
@@ -2743,6 +2812,8 @@ int process_each_lv(struct cmd_context *cmd,
int ret_max = ECMD_PROCESSED;
int ret;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV);
+
/* Disable error in vg_read so we can print it from ignore_vg. */
cmd->vg_read_print_access_error = 0;
@@ -2850,6 +2921,7 @@ out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -3172,6 +3244,9 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct processing_handle *handle,
process_single_pv_fn_t process_single_pv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
+ char pv_uuid[64] __attribute__((aligned(8)));
+ char vg_uuid[64] __attribute__((aligned(8)));
int handle_supplied = handle != NULL;
struct physical_volume *pv;
struct pv_list *pvl;
@@ -3181,6 +3256,12 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
int ret_max = ECMD_PROCESSED;
int ret = 0;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV);
+
+ vg_uuid[0] = '\0';
+ if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
+ stack;
+
if (!handle && (!(handle = init_processing_handle(cmd, NULL)))) {
ret_max = ECMD_FAILED;
goto_out;
@@ -3192,15 +3273,22 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
goto_out;
}
+ log_set_report_object_group_and_group_id(vg->name, vg_uuid);
+
dm_list_iterate_items(pvl, &vg->pvs) {
+ pv = pvl->pv;
+ pv_name = pv_dev_name(pv);
+ pv_uuid[0]='\0';
+ if (!id_write_format(&pv->id, pv_uuid, sizeof(pv_uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(pv_name, pv_uuid);
+
if (sigint_caught()) {
ret_max = ECMD_FAILED;
goto_out;
}
- pv = pvl->pv;
- pv_name = pv_dev_name(pv);
-
process_pv = process_all_pvs;
/* Remove each arg_devices entry as it is processed. */
@@ -3249,10 +3337,15 @@ 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;
+ log_set_report_object_name_and_id(NULL, NULL);
}
out:
+ log_set_report_object_name_and_id(NULL, NULL);
+ log_set_report_object_group_and_group_id(NULL, NULL);
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
+ log_restore_report_state(saved_log_report_state);
+
return ret_max;
}
@@ -3277,6 +3370,8 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
struct processing_handle *handle,
process_single_pv_fn_t process_single_pv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
+ char uuid[64] __attribute__((aligned(8)));
struct volume_group *vg;
struct vgnameid_list *vgnl;
const char *vg_name;
@@ -3288,15 +3383,26 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
int notfound;
int already_locked;
- dm_list_iterate_items(vgnl, all_vgnameids) {
- if (sigint_caught())
- return_ECMD_FAILED;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
+ dm_list_iterate_items(vgnl, all_vgnameids) {
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
skip = 0;
notfound = 0;
+ uuid[0] = '\0';
+ if (vg_uuid && !is_orphan_vg(vg_name) &&
+ !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(vg_name, uuid);
+
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
+
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
continue;
@@ -3339,9 +3445,12 @@ endvg:
/* Quit early when possible. */
if (!process_all_pvs && dm_list_empty(arg_tags) && dm_list_empty(arg_devices))
- return ret_max;
- }
+ goto_out;
+ log_set_report_object_name_and_id(NULL, NULL);
+ }
+out:
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -3351,6 +3460,7 @@ int process_each_pv(struct cmd_context *cmd,
struct processing_handle *handle,
process_single_pv_fn_t process_single_pv)
{
+ log_report_t saved_log_report_state = log_get_report_state();
struct dm_list arg_tags; /* str_list */
struct dm_list arg_pvnames; /* str_list */
struct dm_list arg_devices; /* device_id_list */
@@ -3364,6 +3474,7 @@ int process_each_pv(struct cmd_context *cmd,
int ret_max = ECMD_PROCESSED;
int ret;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV);
log_debug("Processing each PV");
/*
@@ -3398,8 +3509,8 @@ int process_each_pv(struct cmd_context *cmd,
* names/paths into arg_devices which can be used to match below.
*/
if ((ret = _get_arg_pvnames(cmd, argc, argv, &arg_pvnames, &arg_tags)) != ECMD_PROCESSED) {
- stack;
- return ret;
+ ret_max = ret;
+ goto_out;
}
if ((cmd->command->flags & DISALLOW_TAG_ARGS) && !dm_list_empty(&arg_tags)) {
@@ -3414,8 +3525,10 @@ int process_each_pv(struct cmd_context *cmd,
process_all_devices = process_all_pvs && (cmd->command->flags & ENABLE_ALL_DEVS) && all_is_set;
/* Needed for a current listing of the global VG namespace. */
- if (!only_this_vgname && !lockd_gl(cmd, "sh", 0))
- return_ECMD_FAILED;
+ if (!only_this_vgname && !lockd_gl(cmd, "sh", 0)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
/*
* This full scan would be done by _get_all_devices() if
@@ -3431,8 +3544,8 @@ int process_each_pv(struct cmd_context *cmd,
}
if (!get_vgnameids(cmd, &all_vgnameids, only_this_vgname, 1)) {
- stack;
- return ret;
+ ret_max = ret;
+ goto_out;
}
/*
@@ -3441,8 +3554,8 @@ int process_each_pv(struct cmd_context *cmd,
* any devs remaining in all_devices are processed.
*/
if ((ret = _get_all_devices(cmd, &all_devices) != ECMD_PROCESSED)) {
- stack;
- return ret;
+ ret_max = ret;
+ goto_out;
}
if ((ret = _get_arg_devices(cmd, &arg_pvnames, &arg_devices)) != ECMD_PROCESSED)
@@ -3568,6 +3681,7 @@ skip_missed:
if (ret > ret_max)
ret_max = ret;
out:
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
@@ -3575,14 +3689,33 @@ 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)
{
+ log_report_t saved_log_report_state = log_get_report_state();
+ char pv_uuid[64] __attribute__((aligned(8)));
+ char vg_uuid[64] __attribute__((aligned(8)));
int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
struct pv_list *pvl;
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV);
+
+ vg_uuid[0] = '\0';
+ if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
+ stack;
+
+ log_set_report_object_group_and_group_id(vg->name, vg_uuid);
+
dm_list_iterate_items(pvl, &vg->pvs) {
- if (sigint_caught())
- return_ECMD_FAILED;
+ pv_uuid[0] = '\0';
+ if (!id_write_format(&pvl->pv->id, pv_uuid, sizeof(pv_uuid)))
+ stack;
+
+ log_set_report_object_name_and_id(pv_dev_name(pvl->pv), pv_uuid);
+
+ if (sigint_caught()) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
ret = process_single_pv(cmd, vg, pvl->pv, handle);
_update_selection_result(handle, &whole_selected);
@@ -3590,9 +3723,13 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
stack;
if (ret > ret_max)
ret_max = ret;
+
+ log_set_report_object_name_and_id(NULL, NULL);
}
_set_final_selection_result(handle, whole_selected);
+out:
+ log_restore_report_state(saved_log_report_state);
return ret_max;
}
7 years, 11 months
master - report: add 'multiple_output' arg to report_init
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1b107adc1da26e...
Commit: 1b107adc1da26efe6e328e969c69d619436b0366
Parent: 2078b842fb50d73f886fb93ff9e06c08977bf8a3
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu May 12 14:37:38 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200
report: add 'multiple_output' arg to report_init
Some reports may be reported several times with possible different
selection criteria, just like command log report.
---
lib/report/report.c | 6 +++++-
lib/report/report.h | 3 ++-
tools/reporter.c | 4 ++--
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 1436cfe..3b9693d 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3703,7 +3703,8 @@ static const struct dm_report_field_type _log_fields[] = {
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
int aligned, int buffered, int headings, int field_prefixes,
- int quoted, int columns_as_rows, const char *selection)
+ int quoted, int columns_as_rows, const char *selection,
+ int multiple_output)
{
uint32_t report_flags = 0;
const struct dm_report_object_type *types;
@@ -3729,6 +3730,9 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
if (columns_as_rows)
report_flags |= DM_REPORT_OUTPUT_COLUMNS_AS_ROWS;
+ if (multiple_output)
+ report_flags |= DM_REPORT_OUTPUT_MULTIPLE_TIMES;
+
if (*report_type & CMDLOG) {
types = _log_report_types;
fields = _log_fields;
diff --git a/lib/report/report.h b/lib/report/report.h
index a6f17cd..f2880ec 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -88,7 +88,8 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
int aligned, int buffered, int headings, int field_prefixes,
- int quoted, int columns_as_rows, const char *selection);
+ int quoted, int columns_as_rows, const char *selection,
+ int multiple_output);
int report_get_single_selection(struct cmd_context *cmd, const char **selection);
void *report_init_for_selection(struct cmd_context *cmd, report_type_t *report_type,
const char *selection);
diff --git a/tools/reporter.c b/tools/reporter.c
index d376947..3df4bac 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -1032,7 +1032,7 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
if (!(report_handle = report_init(cmd, single_args->options, single_args->keys, &report_type,
args->separator, args->aligned, args->buffered,
args->headings, args->field_prefixes, args->quoted,
- args->columns_as_rows, single_args->selection)))
+ args->columns_as_rows, single_args->selection, 0)))
goto_out;
handle->custom_handle = report_handle;
@@ -1462,7 +1462,7 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
if (!(tmp_log_rh = report_init(NULL, single_args->options, single_args->keys, &single_args->report_type,
args.separator, args.aligned, args.buffered, args.headings,
args.field_prefixes, args.quoted, args.columns_as_rows,
- single_args->selection))) {
+ single_args->selection, 1))) {
log_error("Failed to create log report.");
goto bad;
}
7 years, 11 months