From 1f787aca2839ebef864d87ee9c89b69a618441d2 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 24 Jun 2008 22:48:53 +0000 Subject: [PATCH] Add --rows to reports. --- WHATS_NEW | 2 +- lib/config/defaults.h | 1 + lib/report/report.c | 5 ++++- lib/report/report.h | 2 +- tools/args.h | 1 + tools/commands.h | 13 ++++++++----- tools/reporter.c | 8 +++++++- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 4c59c07d2..30d533ed4 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,6 +1,6 @@ Version 2.02.39 - ================================ - Add --unquoted to reporting tools. + Add --unquoted and --rows to reporting tools. Add and use uninitialized_var() macro to suppress invalid compiler warnings. Introduce enum for md minor sb version to suppress compiler warning. Avoid undefined return value after _memlock manipulation in lvm2_run. diff --git a/lib/config/defaults.h b/lib/config/defaults.h index b55fa71dc..645cfddfb 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -101,6 +101,7 @@ #define DEFAULT_REP_ALIGNED 1 #define DEFAULT_REP_BUFFERED 1 +#define DEFAULT_REP_COLUMNS_AS_ROWS 0 #define DEFAULT_REP_HEADINGS 1 #define DEFAULT_REP_PREFIXES 0 #define DEFAULT_REP_QUOTED 1 diff --git a/lib/report/report.c b/lib/report/report.c index 46e268328..8177a2ff5 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -1078,7 +1078,7 @@ static struct dm_report_field_type _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 quoted, int columns_as_rows) { uint32_t report_flags = 0; void *rh; @@ -1098,6 +1098,9 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys, if (!quoted) report_flags |= DM_REPORT_OUTPUT_FIELD_UNQUOTED; + if (columns_as_rows) + report_flags |= DM_REPORT_OUTPUT_COLUMNS_AS_ROWS; + rh = dm_report_init(report_type, _report_types, _fields, format, separator, report_flags, keys, cmd); diff --git a/lib/report/report.h b/lib/report/report.h index d2bf89218..5d8d569be 100644 --- a/lib/report/report.h +++ b/lib/report/report.h @@ -29,7 +29,7 @@ typedef int (*field_report_fn) (struct report_handle * dh, struct field * field, 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 quoted, int columns_as_rows); void report_free(void *handle); int report_object(void *handle, struct volume_group *vg, struct logical_volume *lv, struct physical_volume *pv, diff --git a/tools/args.h b/tools/args.h index ff6b886f7..8f026fc6a 100644 --- a/tools/args.h +++ b/tools/args.h @@ -55,6 +55,7 @@ arg(trustcache_ARG, '\0', "trustcache", NULL, 0) arg(ignoremonitoring_ARG, '\0', "ignoremonitoring", NULL, 0) arg(nameprefixes_ARG, '\0', "nameprefixes", NULL, 0) arg(unquoted_ARG, '\0', "unquoted", NULL, 0) +arg(rows_ARG, '\0', "rows", NULL, 0) /* Allow some variations */ arg(resizable_ARG, '\0', "resizable", yes_no_arg, 0) diff --git a/tools/commands.h b/tools/commands.h index 12e771126..fddc6a33e 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -372,6 +372,7 @@ xx(lvs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--rows]\n" "\t[--segments]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" @@ -384,8 +385,8 @@ xx(lvs, aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, - segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, - units_ARG, unquoted_ARG) + rows_ARG, segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, + unbuffered_ARG, units_ARG, unquoted_ARG) xx(lvscan, "List all logical volumes in all volume groups", @@ -582,6 +583,7 @@ xx(pvs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--rows]\n" "\t[--segments]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" @@ -594,8 +596,8 @@ xx(pvs, aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, - segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, - units_ARG, unquoted_ARG) + rows_ARG, segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, + unbuffered_ARG, units_ARG, unquoted_ARG) xx(pvscan, "List all physical volumes", @@ -900,6 +902,7 @@ xx(vgs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--rows]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" "\t[--unbuffered]\n" @@ -911,7 +914,7 @@ xx(vgs, aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, - separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, + rows_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG) xx(vgscan, diff --git a/tools/reporter.c b/tools/reporter.c index 5f8d822a3..02b51e381 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -159,6 +159,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, const char *keys = NULL, *options = NULL, *separator; int r = ECMD_PROCESSED; int aligned, buffered, headings, field_prefixes, quoted; + int columns_as_rows; unsigned args_are_pvs; aligned = find_config_tree_int(cmd, "report/aligned", @@ -173,6 +174,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, DEFAULT_REP_PREFIXES); quoted = find_config_tree_int(cmd, "report/quoted", DEFAULT_REP_QUOTED); + columns_as_rows = find_config_tree_int(cmd, "report/columns_as_rows", + DEFAULT_REP_COLUMNS_AS_ROWS); args_are_pvs = (report_type == PVS || report_type == PVSEGS) ? 1 : 0; @@ -280,10 +283,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, } if (arg_count(cmd, unquoted_ARG)) quoted = 0; + if (arg_count(cmd, rows_ARG)) + columns_as_rows = 1; if (!(report_handle = report_init(cmd, options, keys, &report_type, separator, aligned, buffered, - headings, field_prefixes, quoted))) { + headings, field_prefixes, quoted, + columns_as_rows))) { stack; return ECMD_FAILED; }