From 95eaa683097af6ea28b2dda1c5048df386180af5 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 28 Sep 2009 16:23:44 +0000 Subject: [PATCH] Add global/si_unit_consistency to enable cleaned-up use of units in output. Add configure --enable-units-compat to set si_unit_consistency off by default. Use standard output units for 'PE Size' and 'Stripe size' in pv/lvdisplay. --- WHATS_NEW | 3 +++ configure | 20 ++++++++++++++++++++ configure.in | 11 +++++++++++ doc/example.conf | 7 +++++++ lib/commands/toolcontext.c | 4 ++++ lib/commands/toolcontext.h | 1 + lib/config/defaults.h | 4 ++++ lib/display/display.c | 9 +++++++-- lib/misc/configure.h.in | 3 +++ lib/striped/striped.c | 9 ++++++++- 10 files changed, 68 insertions(+), 3 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 7d27545b3..f91c06d0c 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,8 @@ Version 2.02.54 - ===================================== + Use standard output units for 'PE Size' and 'Stripe size' in pv/lvdisplay. + Add configure --enable-units-compat to set si_unit_consistency off by default. + Add global/si_unit_consistency to enable cleaned-up use of units in output. Version 2.02.53 - 25th September 2009 ===================================== diff --git a/configure b/configure index 970a10356..db06bd64e 100755 --- a/configure +++ b/configure @@ -825,6 +825,7 @@ enable_devmapper enable_udev_sync enable_udev_rules enable_compat +enable_units_compat enable_ioctl enable_o_direct enable_applib @@ -1514,6 +1515,8 @@ Optional Features: --enable-udev_sync Enable synchronisation with udev processing --enable-udev_rules Install rule files needed for udev synchronisation --enable-compat Enable support for old device-mapper versions + --enable-units-compat Enable output compatibility with old versions that + that don't use KiB-style unit suffixes --disable-driver Disable calls to device-mapper in the kernel --disable-o_direct Disable O_DIRECT --enable-applib Build application library @@ -12215,6 +12218,23 @@ else fi +################################################################################ +# Check whether --enable-units-compat was given. +if test "${enable_units_compat+set}" = set; then + enableval=$enable_units_compat; UNITS_COMPAT=$enableval +else + UNITS_COMPAT=no +fi + + +if test x$UNITS_COMPAT = xyes; then + +cat >>confdefs.h <<\_ACEOF +#define DEFAULT_SI_UNIT_CONSISTENCY 0 +_ACEOF + +fi + ################################################################################ # Check whether --enable-ioctl was given. if test "${enable_ioctl+set}" = set; then diff --git a/configure.in b/configure.in index 8a63e7365..6a3f53a1d 100644 --- a/configure.in +++ b/configure.in @@ -678,6 +678,17 @@ dnl -- Compatibility mode AC_ARG_ENABLE(compat, [ --enable-compat Enable support for old device-mapper versions], DM_COMPAT=$enableval, DM_COMPAT=no) +################################################################################ +dnl -- Compatible units suffix mode +AC_ARG_ENABLE(units-compat, + [ --enable-units-compat Enable output compatibility with old versions that + that don't use KiB-style unit suffixes], + UNITS_COMPAT=$enableval, UNITS_COMPAT=no) + +if test x$UNITS_COMPAT = xyes; then + AC_DEFINE([DEFAULT_SI_UNIT_CONSISTENCY], 0, [Define to 0 to reinstate the pre-2.02.54 handling of unit suffixes.]) +fi + ################################################################################ dnl -- Disable ioctl AC_ARG_ENABLE(ioctl, [ --disable-driver Disable calls to device-mapper in the kernel], diff --git a/doc/example.conf b/doc/example.conf index 4f57b59e9..f254325f0 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -236,6 +236,13 @@ global { # Default value for --units argument units = "h" + # Since version 2.02.54, the tools distinguish between powers of + # 1024 bytes (e.g. KiB, MiB, GiB) and powers of 1000 bytes (e.g. + # KB, MB, GB). + # If you have scripts that depend on the old behaviour, set this to 0 + # temporarily until you update them. + si_unit_consistency = 1 + # Whether or not to communicate with the kernel device-mapper. # Set to 0 if you want to use the tools to manipulate LVM metadata # without activating any logical volumes. diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index 4c2592609..2a561004d 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -293,6 +293,10 @@ static int _process_config(struct cmd_context *cmd) } } + cmd->si_unit_consistency = find_config_tree_int(cmd, + "global/si_unit_consistency", + DEFAULT_SI_UNIT_CONSISTENCY); + return 1; } diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index 24f924a15..e4341a703 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -70,6 +70,7 @@ struct cmd_context { unsigned is_long_lived:1; /* Optimises persistent_filter handling */ unsigned handles_missing_pvs:1; unsigned partial_activation:1; + unsigned si_unit_consistency:1; struct dev_filter *filter; int dump_filter; /* Dump filter when exiting? */ diff --git a/lib/config/defaults.h b/lib/config/defaults.h index d483492b9..7ce96abc4 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -92,6 +92,10 @@ #define DEFAULT_SUFFIX 1 #define DEFAULT_HOSTTAGS 0 +#ifndef DEFAULT_SI_UNIT_CONSISTENCY +# define DEFAULT_SI_UNIT_CONSISTENCY 1 +#endif + #ifdef DEVMAPPER_SUPPORT # define DEFAULT_ACTIVATION 1 # define DEFAULT_RESERVED_MEMORY 8192 diff --git a/lib/display/display.c b/lib/display/display.c index 62f30f648..6e8534a7b 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -344,7 +344,12 @@ void pvdisplay_full(const struct cmd_context *cmd, /* LV count is no longer available when displaying PV log_print("Cur LV %u", vg->lv_count); */ - log_print("PE Size (KByte) %" PRIu32, pv->pe_size / 2); + + if (cmd->si_unit_consistency) + log_print("PE Size %s", display_size(cmd, (uint64_t) pv->pe_size)); + else + log_print("PE Size (KByte) %" PRIu32, pv->pe_size / 2); + log_print("Total PE %u", pv->pe_count); log_print("Free PE %" PRIu32, pe_free); log_print("Allocated PE %u", pv->pe_alloc_count); @@ -489,7 +494,7 @@ int lvdisplay_full(struct cmd_context *cmd, log_print("Segments %u", dm_list_size(&lv->segments)); /********* FIXME Stripes & stripesize for each segment - log_print("Stripe size (KByte) %u", lv->stripesize / 2); + log_print("Stripe size %s", display_size(cmd, (uint64_t) lv->stripesize)); ***********/ log_print("Allocation %s", get_alloc_string(lv->alloc)); diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in index 6e4043cae..e5c2e6754 100644 --- a/lib/misc/configure.h.in +++ b/lib/misc/configure.h.in @@ -17,6 +17,9 @@ /* Define to 1 if using `alloca.c'. */ #undef C_ALLOCA +/* Define to 0 to reinstate the pre-2.02.54 handling of unit suffixes. */ +#undef DEFAULT_SI_UNIT_CONSISTENCY + /* Define to 1 to enable LVM2 device-mapper interaction. */ #undef DEVMAPPER_SUPPORT diff --git a/lib/striped/striped.c b/lib/striped/striped.c index 0e1ca2d35..f187da542 100644 --- a/lib/striped/striped.c +++ b/lib/striped/striped.c @@ -40,7 +40,14 @@ static void _striped_display(const struct lv_segment *seg) display_stripe(seg, 0, " "); else { log_print(" Stripes\t\t%u", seg->area_count); - log_print(" Stripe size\t\t%u KB", seg->stripe_size / 2); + + if (seg->lv->vg->cmd->si_unit_consistency) + log_print(" Stripe size\t\t%s", + display_size(seg->lv->vg->cmd, + (uint64_t) seg->stripe_size)); + else + log_print(" Stripe size\t\t%u KB", + seg->stripe_size / 2); for (s = 0; s < seg->area_count; s++) { log_print(" Stripe %d:", s);