1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

report: add --logonly arg to report only log for a command

This commit is contained in:
Peter Rajnoha 2016-06-15 13:35:27 +02:00
parent 3e8e8ddb46
commit 92caebab95
7 changed files with 54 additions and 34 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.158 - 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. 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. 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. Add lvm lastlog command for query and display of last cmd's log in lvm shell.

View File

@ -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, 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, 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, void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator, report_type_t *report_type, const char *separator,

View File

@ -55,6 +55,7 @@ arg(lockopt_ARG, '\0', "lockopt", string_arg, 0, 0)
arg(lockstart_ARG, '\0', "lockstart", NULL, 0, 0) arg(lockstart_ARG, '\0', "lockstart", NULL, 0, 0)
arg(lockstop_ARG, '\0', "lockstop", NULL, 0, 0) arg(lockstop_ARG, '\0', "lockstop", NULL, 0, 0)
arg(locktype_ARG, '\0', "locktype", locktype_arg, 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(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", size_kb_arg, 0, 0)
arg(merge_ARG, '\0', "merge", NULL, 0, 0) arg(merge_ARG, '\0', "merge", NULL, 0, 0)
arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0, 0) arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0, 0)

View File

@ -149,6 +149,7 @@ xx(fullreport,
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--nameprefixes]\n" "\t[--nameprefixes]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
@ -169,10 +170,10 @@ xx(fullreport,
"\t[VolumeGroupName [VolumeGroupName...]]\n", "\t[VolumeGroupName [VolumeGroupName...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
rows_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, trustcache_ARG, reportformat_ARG, rows_ARG, select_ARG, separator_ARG, shared_ARG,
unbuffered_ARG, units_ARG, unquoted_ARG) sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(lastlog, xx(lastlog,
"Display last command's log report", "Display last command's log report",
@ -486,6 +487,7 @@ xx(lvdisplay,
"\t[-H|--history]\n" "\t[-H|--history]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\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, aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG,
history_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_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, partial_ARG, readonly_ARG, reportformat_ARG, segments_ARG, select_ARG,
separator_ARG, shared_ARG, unbuffered_ARG, units_ARG) separator_ARG, shared_ARG, unbuffered_ARG, units_ARG)
@ -730,6 +732,7 @@ xx(lvs,
"\t[-H|--history]\n" "\t[-H|--history]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--nameprefixes]\n" "\t[--nameprefixes]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
@ -751,11 +754,11 @@ xx(lvs,
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n", "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
aligned_ARG, all_ARG, binary_ARG, configreport_ARG, foreign_ARG, history_ARG, aligned_ARG, all_ARG, binary_ARG, configreport_ARG, foreign_ARG, history_ARG,
ignorelockingfailure_ARG, ignoreskippedcluster_ARG, nameprefixes_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG, logonly_ARG,
noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG,
readonly_ARG, reportformat_ARG, rows_ARG, segments_ARG, select_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG, rows_ARG,
separator_ARG, shared_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, segments_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG,
units_ARG, unquoted_ARG) trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(lvscan, xx(lvscan,
"List all logical volumes in all volume groups", "List all logical volumes in all volume groups",
@ -918,6 +921,7 @@ xx(pvdisplay,
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\n" "\t[-o|--options [+|-|#]Field[,Field]]\n"
@ -933,7 +937,7 @@ xx(pvdisplay,
"\t[PhysicalVolumePath [PhysicalVolumePath...]]\n", "\t[PhysicalVolumePath [PhysicalVolumePath...]]\n",
aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG, 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, noheadings_ARG, nosuffix_ARG, options_ARG, readonly_ARG, reportformat_ARG,
select_ARG, separator_ARG, shared_ARG, short_ARG, sort_ARG, unbuffered_ARG, select_ARG, separator_ARG, shared_ARG, short_ARG, sort_ARG, unbuffered_ARG,
units_ARG) units_ARG)
@ -1014,6 +1018,7 @@ xx(pvs,
"\t[-h|-?|--help]\n" "\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--nameprefixes]\n" "\t[--nameprefixes]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
@ -1035,10 +1040,11 @@ xx(pvs,
"\t[PhysicalVolume [PhysicalVolume...]]\n", "\t[PhysicalVolume [PhysicalVolume...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
rows_ARG, segments_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, reportformat_ARG, rows_ARG, segments_ARG, select_ARG, separator_ARG,
trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG) shared_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG,
unquoted_ARG)
xx(pvscan, xx(pvscan,
"List all physical volumes", "List all physical volumes",
@ -1265,6 +1271,7 @@ xx(vgdisplay,
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
"\t[-o|--options [+|-|#]Field[,Field]]\n" "\t[-o|--options [+|-|#]Field[,Field]]\n"
@ -1282,9 +1289,9 @@ xx(vgdisplay,
activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG, activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG,
foreign_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG, foreign_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, logonly_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG,
reportformat_ARG, select_ARG, shared_ARG, short_ARG, separator_ARG, readonly_ARG, reportformat_ARG, select_ARG, shared_ARG, short_ARG,
sort_ARG, unbuffered_ARG, units_ARG) separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
xx(vgexport, xx(vgexport,
"Unregister volume group(s) from the system", "Unregister volume group(s) from the system",
@ -1446,6 +1453,7 @@ xx(vgs,
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
"\t[--logonly]\n"
"\t[--nameprefixes]\n" "\t[--nameprefixes]\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
"\t[--nosuffix]\n" "\t[--nosuffix]\n"
@ -1466,10 +1474,10 @@ xx(vgs,
"\t[VolumeGroupName [VolumeGroupName...]]\n", "\t[VolumeGroupName [VolumeGroupName...]]\n",
aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, ignoreskippedcluster_ARG, logonly_ARG, nameprefixes_ARG, noheadings_ARG,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, reportformat_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
rows_ARG, select_ARG, separator_ARG, shared_ARG, sort_ARG, trustcache_ARG, reportformat_ARG, rows_ARG, select_ARG, separator_ARG, shared_ARG,
unbuffered_ARG, units_ARG, unquoted_ARG) sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(vgscan, xx(vgscan,
"Search for all volume groups", "Search for all volume groups",

View File

@ -54,6 +54,7 @@ struct report_args {
int columns_as_rows; int columns_as_rows;
const char *separator; const char *separator;
struct volume_group *full_report_vg; struct volume_group *full_report_vg;
int log_only;
struct single_report_args single_args[REPORT_IDX_COUNT]; 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)) &lv_segment_status_needed, &report_type))
goto_out; 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)) if (!dm_report_group_push(handle->report_group, report_handle, (void *) single_args->report_name))
goto_out; goto_out;
report_in_group = 1; report_in_group = 1;
@ -1160,6 +1161,7 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
log_error("Failed to compact given columns in report output."); log_error("Failed to compact given columns in report output.");
} }
if (!(args->log_only && (single_args->report_type != CMDLOG)))
dm_report_output(report_handle); dm_report_output(report_handle);
if (lock_global) if (lock_global)
@ -1189,7 +1191,7 @@ static int _full_report_single(struct cmd_context *cmd,
args->full_report_vg = vg; 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; goto out;
if (orphan) { if (orphan) {
@ -1205,7 +1207,7 @@ static int _full_report_single(struct cmd_context *cmd,
stack; stack;
} }
if (!dm_report_group_pop(handle->report_group)) if (!args->log_only && !dm_report_group_pop(handle->report_group))
goto_out; goto_out;
out: out:
args->full_report_vg = NULL; 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; handle->include_historical_lvs = cmd->include_historical_lvs;
args.report_group_type = handle->report_group_type; args.report_group_type = handle->report_group_type;
args.log_only = handle->log_only;
if (!_config_report(cmd, &args, single_args)) { if (!_config_report(cmd, &args, single_args)) {
destroy_processing_handle(cmd, handle); destroy_processing_handle(cmd, handle);
return_ECMD_FAILED; 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."); log_error("Failed to add main report section to report group.");
destroy_processing_handle(cmd, handle); destroy_processing_handle(cmd, handle);
return ECMD_FAILED; return ECMD_FAILED;
@ -1426,19 +1429,22 @@ 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, 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, 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; 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 *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); 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 report_args args = {0};
struct single_report_args *single_args; struct single_report_args *single_args;
struct dm_report_group *new_report_group; struct dm_report_group *new_report_group;
struct dm_report *tmp_log_rh = NULL; 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)) { if (!format_str || !strcmp(format_str, REPORT_FORMAT_NAME_BASIC)) {
args.report_group_type = report_command_log ? DM_REPORT_GROUP_BASIC args.report_group_type = (report_command_log && !args.log_only) ? DM_REPORT_GROUP_BASIC
: DM_REPORT_GROUP_SINGLE; : DM_REPORT_GROUP_SINGLE;
} else if (!strcmp(format_str, REPORT_FORMAT_NAME_JSON)) { } else if (!strcmp(format_str, REPORT_FORMAT_NAME_JSON)) {
args.report_group_type = DM_REPORT_GROUP_JSON; args.report_group_type = DM_REPORT_GROUP_JSON;
@ -1452,6 +1458,8 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
if (report_group_type) if (report_group_type)
*report_group_type = args.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))) { if (!(new_report_group = dm_report_group_create(args.report_group_type, NULL))) {
log_error("Failed to create report group."); log_error("Failed to create report group.");
@ -1517,7 +1525,7 @@ int lastlog(struct cmd_context *cmd, int argc, char **argv)
goto out; 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; goto_out;
if (arg_count(cmd, select_ARG) && if (arg_count(cmd, select_ARG) &&

View File

@ -1733,7 +1733,8 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct
if (!parent_handle) { if (!parent_handle) {
if (!report_format_init(cmd, &handle->report_group_type, &handle->report_group, 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); dm_pool_free(cmd->mem, handle);
return NULL; return NULL;
} }

View File

@ -76,6 +76,7 @@ struct processing_handle {
dm_report_group_type_t report_group_type; dm_report_group_type_t report_group_type;
struct dm_report_group *report_group; struct dm_report_group *report_group;
struct dm_report *log_rh; struct dm_report *log_rh;
int log_only;
log_report_t saved_log_report_state; log_report_t saved_log_report_state;
void *custom_handle; void *custom_handle;
}; };