From f419a871500e36e5c9c38fb89946e2090bfa39f6 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Sun, 20 Apr 2008 00:15:08 +0000 Subject: [PATCH] Add --prefixes to reporting tools for field name prefix output format. E.g. lvs --prefixes --noheadings --unbuffered --units m --nosuffix (Used '--prefixes' for now, but I'm looking for a better name.) --- WHATS_NEW | 1 + lib/config/defaults.h | 1 + lib/report/report.c | 17 +++++++++++++---- lib/report/report.h | 2 +- tools/args.h | 1 + tools/commands.h | 17 +++++++++++------ tools/reporter.c | 10 ++++++++-- 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 4b2d630b3..e9c702a20 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.36 - ================================= + Add --prefixes to reporting tools for field name prefix output format. Fix lvconvert -m0 allocatable space check. Version 2.02.35 - 15th April 2008 diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 3e26c4b8b..4be02f909 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -102,6 +102,7 @@ #define DEFAULT_REP_ALIGNED 1 #define DEFAULT_REP_BUFFERED 1 #define DEFAULT_REP_HEADINGS 1 +#define DEFAULT_REP_PREFIXES 0 #define DEFAULT_REP_SEPARATOR " " #define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,origin,snap_percent,move_pv,mirror_log,copy_percent,convert_lv" diff --git a/lib/report/report.c b/lib/report/report.c index 922a84cff..f2ffd9827 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -386,7 +386,7 @@ static int _pvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_ const uint32_t status = *(const uint32_t *) data; char *repstr; - if (!(repstr = dm_pool_zalloc(mem, 4))) { + if (!(repstr = dm_pool_zalloc(mem, 3))) { log_error("dm_pool_alloc failed"); return 0; } @@ -1077,9 +1077,10 @@ 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 aligned, int buffered, int headings, int field_prefixes) { uint32_t report_flags = 0; + void *rh; if (aligned) report_flags |= DM_REPORT_OUTPUT_ALIGNED; @@ -1090,8 +1091,16 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys, if (headings) report_flags |= DM_REPORT_OUTPUT_HEADINGS; - return dm_report_init(report_type, _report_types, _fields, format, - separator, report_flags, keys, cmd); + if (field_prefixes) + report_flags |= DM_REPORT_OUTPUT_FIELD_NAME_PREFIX; + + rh = dm_report_init(report_type, _report_types, _fields, format, + separator, report_flags, keys, cmd); + + if (field_prefixes) + dm_report_set_output_field_name_prefix(rh, "lvm2_"); + + return rh; } /* diff --git a/lib/report/report.h b/lib/report/report.h index 71cb06a6f..40eac504b 100644 --- a/lib/report/report.h +++ b/lib/report/report.h @@ -28,7 +28,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 aligned, int buffered, int headings, int field_prefixes); 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 5a0309c59..07178008e 100644 --- a/tools/args.h +++ b/tools/args.h @@ -53,6 +53,7 @@ arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0) arg(config_ARG, '\0', "config", string_arg, 0) arg(trustcache_ARG, '\0', "trustcache", NULL, 0) arg(ignoremonitoring_ARG, '\0', "ignoremonitoring", NULL, 0) +arg(prefixes_ARG, '\0', "prefixes", 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 9e9d6f15c..efac7594c 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -368,6 +368,7 @@ xx(lvs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--prefixes]\n" "\t[--segments]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" @@ -378,8 +379,9 @@ xx(lvs, "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n", aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG, - nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG, - separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG) + nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, prefixes_ARG, + segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, + units_ARG) xx(lvscan, "List all logical volumes in all volume groups", @@ -575,6 +577,7 @@ xx(pvs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--prefixes]\n" "\t[--segments]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" @@ -585,8 +588,9 @@ xx(pvs, "\t[PhysicalVolume [PhysicalVolume...]]\n", aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG, - nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG, - separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG) + nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, prefixes_ARG, + segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, + units_ARG) xx(pvscan, "List all physical volumes", @@ -890,6 +894,7 @@ xx(vgs, "\t[-o|--options [+]Field[,Field]]\n" "\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n" "\t[-P|--partial] " "\n" + "\t[--prefixes]\n" "\t[--separator Separator]\n" "\t[--trustcache]\n" "\t[--unbuffered]\n" @@ -899,8 +904,8 @@ xx(vgs, "\t[VolumeGroupName [VolumeGroupName...]]\n", aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG, - nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, separator_ARG, - sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG) + nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, prefixes_ARG, + separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG) xx(vgscan, "Search for all volume groups", diff --git a/tools/reporter.c b/tools/reporter.c index 2504f206d..5e13ed411 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -158,7 +158,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, char *str; const char *keys = NULL, *options = NULL, *separator; int r = ECMD_PROCESSED; - int aligned, buffered, headings; + int aligned, buffered, headings, field_prefixes; unsigned args_are_pvs; aligned = find_config_tree_int(cmd, "report/aligned", @@ -169,6 +169,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, DEFAULT_REP_HEADINGS); separator = find_config_tree_str(cmd, "report/separator", DEFAULT_REP_SEPARATOR); + field_prefixes = find_config_tree_int(cmd, "report/prefixes", + DEFAULT_REP_PREFIXES); args_are_pvs = (report_type == PVS || report_type == PVSEGS) ? 1 : 0; @@ -270,10 +272,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, buffered = 0; if (arg_count(cmd, noheadings_ARG)) headings = 0; + if (arg_count(cmd, prefixes_ARG)) { + aligned = 0; + field_prefixes = 1; + } if (!(report_handle = report_init(cmd, options, keys, &report_type, separator, aligned, buffered, - headings))) { + headings, field_prefixes))) { stack; return ECMD_FAILED; }