dev-prajnoha-pv-ext-flag-used - WHATS_NEW_DM: recent commits (stats field split and timestamp headers)
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4d5b618d52f9f2...
Commit: 4d5b618d52f9f26537f8044bd4e6b139032c46c1
Parent: e6724f0303b8dee0806ac799f0035d9f928441fc
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Fri Aug 14 13:20:20 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Fri Aug 14 13:43:12 2015 +0100
WHATS_NEW_DM: recent commits (stats field split and timestamp headers)
---
WHATS_NEW_DM | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index f3b62b1..8e816a0 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,9 @@
Version 1.02.105 -
===================================
+ Fix 'stats list -o all' segfault
+ Separate statistics fields from region information fields
+ Add interval and interval_ns fields to DR_STATS reports.
+ Do not include internal glibc headers in libdm-timestamp.c (1.02.104)
Exit immediately if no device is supplied to dmsetup wipe_table.
Suppress dmsetup report headings when no data is output. (1.02.104)
Adjust dmsetup usage/help output selection to match command invoked.
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: make 'dmstats list' use common report infrastructure
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e6724f0303b8de...
Commit: e6724f0303b8dee0806ac799f0035d9f928441fc
Parent: 37dd26e322bc2fc3fa0fd7dd85d1972b08fca36c
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Thu Aug 13 23:03:46 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Fri Aug 14 13:43:12 2015 +0100
dmstats: make 'dmstats list' use common report infrastructure
Unlike 'info -c' and 'stats report' the 'dmstats list' subcommand
does its own report processing. This complicates the handling of
the DR_STATS and DR_STATS_META fields and leads to inconsistent
behaviour between the different commands. In particular it causes
'stats list' to segfault when using 'all' field options:
Segmentation fault (core dumped)
Delete _stats_list() entirely and adapt _stats_report so that it
can correctly format a DR_STATS_META-only report request.
This requires passing the subcommand into _report_init() where it
is used in addition to the command name to select the default set
of report fields for the 'list' and 'report' stats subcommands.
With this change both 'list' and 'report' dmstats report will use
the correct report object type and ensure that it is initialised
appropriately for the field selection in use.
---
tools/dmsetup.c | 147 ++++++++++++++++--------------------------------------
1 files changed, 44 insertions(+), 103 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index db2c3e4..5472985 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -252,9 +252,9 @@ static report_type_t _report_type;
static dev_name_t _dev_name_type;
static uint32_t _count = 1; /* count of repeating reports */
static struct dm_timestamp *_initial_timestamp = NULL;
-static int _stats_report_init = 0;
static uint64_t _disp_factor = 512; /* display sizes in sectors */
static char _disp_units = 's';
+const char *_program_id = DM_STATS_PROGRAM_ID; /* program_id used for reports. */
/* report timekeeping */
static struct dm_timestamp *_cycle_timestamp = NULL;
@@ -830,7 +830,7 @@ static int _display_info_cols(struct dm_task *dmt, struct dm_info *info)
dm_stats_bind_devno(obj.stats, info->major, info->minor);
- if (!(dm_stats_populate(obj.stats, DM_STATS_PROGRAM_ID, DM_STATS_REGIONS_ALL)))
+ if (!dm_stats_populate(obj.stats, _program_id, DM_STATS_REGIONS_ALL))
goto out;
/* Update timestamps and handle end-of-interval accounting. */
@@ -841,6 +841,21 @@ static int _display_info_cols(struct dm_task *dmt, struct dm_info *info)
dm_stats_set_sampling_interval_ns(obj.stats, _last_interval);
}
+ /* Only a dm_stats_list is needed for DR_STATS_META reports. */
+ if (!obj.stats && (_report_type & DR_STATS_META)) {
+ if (!(obj.stats = dm_stats_create(DM_STATS_PROGRAM_ID)))
+ goto_out;
+
+ dm_stats_bind_devno(obj.stats, info->major, info->minor);
+
+ if (!dm_stats_list(obj.stats, _program_id))
+ goto out;
+
+ /* No regions to report */
+ if (!dm_stats_get_nr_regions(obj.stats))
+ goto out;
+ }
+
/*
* Walk any statistics regions contained in the current
* reporting object: for objects with a NULL stats handle,
@@ -3995,7 +4010,7 @@ static const char *splitname_report_options = "vg_name,lv_name,lv_layer";
static const char *_stats_default_report_options = DEV_INFO_STATS ",area_id," METRICS;
static const char *_stats_list_options = "name,region_id,region_start,region_len,area_len,area_count,program_id";
-static int _report_init(const struct command *cmd)
+static int _report_init(const struct command *cmd, const char *subcommand)
{
char *options = (char *) default_report_options;
char *opt_fields = NULL; /* optional fields from command line */
@@ -4014,8 +4029,13 @@ static int _report_init(const struct command *cmd)
}
if (cmd && !strcmp(cmd->name, "stats")) {
- options = (char *) _stats_default_report_options;
- _report_type |= (DR_STATS | DR_STATS_META);
+ _report_type |= DR_STATS_META;
+ if (!strcmp(subcommand, "list"))
+ options = (char *) _stats_list_options;
+ else {
+ options = (char *) _stats_default_report_options;
+ _report_type |= DR_STATS;
+ }
}
if (cmd && !strcmp(cmd->name, "list")) {
@@ -4642,91 +4662,6 @@ out:
return 0;
}
-static int _stats_list(CMD_ARGS)
-{
- struct dm_stats *dms;
- const char *name, *program_id = DM_STATS_PROGRAM_ID;
- struct dm_task *dmt = NULL;
- struct dm_info info;
- struct dmsetup_report_obj obj;
-
- if (names)
- name = names->name;
- else {
- if (!argc && !_switches[UUID_ARG] && !_switches[MAJOR_ARG])
- return _process_all(cmd, subcommand, argc, argv, 0, _stats_list);
- name = argv[0];
- }
-
- if (_switches[PROGRAM_ID_ARG])
- program_id = _string_args[PROGRAM_ID_ARG];
-
- if (_switches[ALL_PROGRAMS_ARG])
- program_id = "";
-
- if (_switches[OPTIONS_ARG] && !strcmp(_string_args[OPTIONS_ARG], "help"))
- /* field help already output from _report_init(). */
- return 1;
-
- if (!(dms = dm_stats_create(DM_STATS_PROGRAM_ID)))
- return_0;
-
- if (!_bind_stats_device(dms, name))
- goto_out;
-
- if (!dm_stats_list(dms, program_id)) {
- log_error("Could not list statistics regions.");
- goto out;
- }
-
- if (_report && !_stats_report_init) {
- dm_report_free(_report);
- _report_init(cmd);
- _stats_report_init = 1;
- }
-
- if (!dm_stats_get_nr_regions(dms)) {
- log_info("No statistics regions present.");
- goto none;
- }
-
- if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
- return 0;
-
- if (!_set_task_device(dmt, name, 0))
- goto out;
-
- if (_switches[CHECKS_ARG] && !dm_task_enable_checks(dmt))
- goto out;
-
- if (!_task_run(dmt))
- goto out;
-
- if (!dm_task_get_info(dmt, &info))
- goto out;
-
- obj.task = dmt;
- obj.stats = dms;
- obj.info = &info;
-
- dm_stats_walk_do(obj.stats) {
- dm_report_object(_report, &obj);
- dm_stats_walk_next_region(obj.stats);
- } dm_stats_walk_while(obj.stats);
-
- dm_task_destroy(dmt);
-
-none:
- dm_stats_destroy(dms);
- return 1;
-
-out:
- if (dmt)
- dm_task_destroy(dmt);
- dm_stats_destroy(dms);
- return 0;
-}
-
static int _stats_print(CMD_ARGS)
{
struct dm_stats *dms;
@@ -4805,6 +4740,12 @@ static int _stats_report(CMD_ARGS)
struct dm_task *dmt;
char *name = NULL;
+ if (_switches[PROGRAM_ID_ARG])
+ _program_id = _string_args[PROGRAM_ID_ARG];
+
+ if (_switches[ALL_PROGRAMS_ARG])
+ _program_id = "";
+
if (names)
name = names->name;
else {
@@ -4869,7 +4810,7 @@ static struct command _stats_subcommands[] = {
{"clear", "--regionid <id> [<device>]", 0, -1, 1, 0, _stats_clear},
{"create", CREATE_OPTS "\n\t\t" ID_OPTS "[<device>]", 0, -1, 1, 0, _stats_create},
{"delete", "--regionid <id> <device>", 1, -1, 1, 0, _stats_delete},
- {"list", "[--programid <id>] [<device>]", 0, -1, 1, 0, _stats_list},
+ {"list", "[--programid <id>] [<device>]", 0, -1, 1, 0, _stats_report},
{"print", PRINT_OPTS "[<device>]", 0, -1, 1, 0, _stats_print},
{"report", REPORT_OPTS "[<device>]", 0, -1, 1, 0, _stats_report},
{"version", "", 0, -1, 1, 0, _version},
@@ -5025,7 +4966,7 @@ static int _stats_help(CMD_ARGS)
_report = NULL;
}
- (void) _report_init(cmd);
+ (void) _report_init(cmd, "help");
if (_report) {
dm_report_free(_report);
_report = NULL;
@@ -5048,7 +4989,7 @@ static int _dmsetup_help(CMD_ARGS)
dm_report_free(_report);
_report = NULL;
}
- (void) _report_init(cmd);
+ (void) _report_init(cmd, "");
if (_report) {
dm_report_free(_report);
_report = NULL;
@@ -5964,7 +5905,16 @@ unknown:
goto out;
#endif
- if (_switches[COLS_ARG] && !_report_init(cmd))
+ /*
+ * Extract subcommand?
+ * dmsetup <command> <subcommand> [args...]
+ */
+ if (cmd->has_subcommands) {
+ subcommand = argv[0];
+ argc--, argv++;
+ }
+
+ if (_switches[COLS_ARG] && !_report_init(cmd, subcommand))
goto out;
if (_switches[COUNT_ARG])
@@ -5981,15 +5931,6 @@ unknown:
}
}
- /*
- * Extract subcommand?
- * dmsetup <command> <subcommand> [args...]
- */
- if (cmd->has_subcommands) {
- subcommand = argv[0];
- argc--, argv++;
- }
-
/* Start interval timer. */
if (_count > 1)
if (!_start_timer())
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: add 'interval' and 'interval_ns' report fields
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9b3dc725060a24...
Commit: 9b3dc725060a243b7b6d849de9bafbdf3e9f5140
Parent: 4534f0fbcf6b83d29baf4af78f9027ff76fe0a7a
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Thu Aug 13 17:29:15 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Fri Aug 14 13:36:50 2015 +0100
dmstats: add 'interval' and 'interval_ns' report fields
Add a pair of fields to expose the current per-interval duation
estimate. The 'interval' field provides a real value in units of
seconds and the 'interval_ns' field provides the same quantity
expressed as a whole number of nanoseconds.
---
man/dmstats.8.in | 14 ++++++++++++++
tools/dmsetup.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/man/dmstats.8.in b/man/dmstats.8.in
index 3b9f032..f8d2949 100644
--- a/man/dmstats.8.in
+++ b/man/dmstats.8.in
@@ -501,6 +501,20 @@ The program ID value associated with this region.
.br
The auxiliary data value associated with this region.
.br
+.HP
+.B interval_ns
+.br
+The estimated interval over which the current counter values have
+accumulated. The vaulue is reported as an interger expressed in units
+of nanoseconds.
+.br
+.HP
+.B interval
+.br
+The estimated interval over which the current counter values have
+accumulated. The value is reported as a real number in units of
+seconds.
+.br
.SS Basic counters
Basic counters provide access to the raw counter data from the kernel,
allowing further processing to be carried out by another program.
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index c5be193..6e75e28 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -3376,6 +3376,39 @@ static int _dm_stats_aux_data_disp(struct dm_report *rh,
return dm_report_field_string(rh, field, (const char * const*) &aux_data);
}
+static int _dm_stats_sample_interval_ns_disp(struct dm_report *rh,
+ struct dm_pool *mem __attribute__((unused)),
+ struct dm_report_field *field, const void *data,
+ void *private __attribute__((unused)))
+{
+ /* FIXME: use internal interval estimate when supported by libdm */
+ return dm_report_field_uint64(rh, field, &_last_interval);
+}
+
+static int _dm_stats_sample_interval_disp(struct dm_report *rh,
+ struct dm_pool *mem __attribute__((unused)),
+ struct dm_report_field *field, const void *data,
+ void *private __attribute__((unused)))
+{
+ char buf[64];
+ char *repstr;
+ double *sortval;
+
+ if (!(sortval = dm_pool_alloc(mem, sizeof(*sortval))))
+ return_0;
+
+ *sortval = (double)_last_interval / (double) NSEC_PER_SEC;
+
+ if (!dm_snprintf(buf, sizeof(buf), "%2.6f", *sortval))
+ return_0;
+
+ if (!(repstr = dm_pool_strdup(mem, buf)))
+ return_0;
+
+ dm_report_field_set_value(field, repstr, sortval);
+ return 1;
+}
+
static int _dm_stats_rrqm_disp(struct dm_report *rh,
struct dm_pool *mem __attribute__((unused)),
struct dm_report_field *field, const void *data,
@@ -3917,6 +3950,8 @@ FIELD_F(STATS, SIZ, "ASize", 5, dm_stats_area_len, "area_len", "Area length.")
FIELD_F(STATS, NUM, "#Areas", 6, dm_stats_area_count, "area_count", "Area count.")
FIELD_F(STATS, STR, "ProgID", 6, dm_stats_program_id, "program_id", "Program ID.")
FIELD_F(STATS, STR, "AuxDat", 6, dm_stats_aux_data, "aux_data", "Auxiliary data.")
+FIELD_F(STATS, NUM, "IntervalNSec", 10, dm_stats_sample_interval_ns, "interval_ns", "Sampling interval in nanoseconds.")
+FIELD_F(STATS, NUM, "Interval", 8, dm_stats_sample_interval, "interval", "Sampling interval.")
/* Stats derived metrics */
FIELD_F(STATS, NUM, "RRqM/s", 8, dm_stats_rrqm, "rrqm", "Read requests merged per second.")
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - libdm: do not in include internal bits/time.h header
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4534f0fbcf6b83...
Commit: 4534f0fbcf6b83d29baf4af78f9027ff76fe0a7a
Parent: 6a93206882cb628a88dbd372d36dc8fc8cc5053a
Author: Natanael Copa <ncopa(a)alpinelinux.org>
AuthorDate: Fri Aug 14 11:32:36 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Fri Aug 14 11:33:12 2015 +0100
libdm: do not in include internal bits/time.h header
Do not include bits/time.h as it is an internal libc header file.
A comment at the top of the glibc specific bits/time.h says:
"Never include this file directly; use <time.h> instead."
This fixes the following build error with musl libc:
libdm-timestamp.c:37:23: fatal error: bits/time.h: No such file or directory
---
Compile tested with Alpine Linx (musl libc) and ubuntu 15.04
libdm/libdm-timestamp.c | 1 -
1 file changed, 1 deletion(-)
---
libdm/libdm-timestamp.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-timestamp.c b/libdm/libdm-timestamp.c
index 3e01442..9be93a4 100644
--- a/libdm/libdm-timestamp.c
+++ b/libdm/libdm-timestamp.c
@@ -34,7 +34,6 @@
#ifdef HAVE_REALTIME
#include <time.h>
-#include <bits/time.h>
struct dm_timestamp {
struct timespec t;
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: replace --force with new stats-specific --alldevices
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b81ac5807bdbf...
Commit: 6b81ac5807bdbfdd0063db4f53cc6d310c2fe4fc
Parent: 988ca743519839b283ebdbaaf06243cb0541b935
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Thu Aug 13 14:42:55 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Thu Aug 13 19:05:46 2015 +0100
dmstats: replace --force with new stats-specific --alldevices
The '--force' switch is only used by dmstats to allow either
creation or deletion of one or more regions on all devices.
These operations do not carry any risk: just a possible mess of
region IDs to be cleaned up.
Remove the use of '--force' for stats commands and change current
uses to a new '--alldevices' switch.
---
WHATS_NEW_DM | 1 +
man/dmstats.8.in | 16 +++++++++++-----
tools/dmsetup.c | 16 ++++++++++------
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index a72d3e0..45db0e4 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,6 +1,7 @@
Version 1.02.105 -
===================================
Add more arg validation for dm_tree_node_add_cache_target().
+ Add --alldevices switch to replace use of --force for stats create / delete.
Version 1.02.104 - 10th August 2015
===================================
diff --git a/man/dmstats.8.in b/man/dmstats.8.in
index c5ef47f..3b9f032 100644
--- a/man/dmstats.8.in
+++ b/man/dmstats.8.in
@@ -27,6 +27,7 @@ dmstats \(em device-mapper statistics management
.br
.B dmstats create
.I device_name
+.RB [ \-\-alldevices ]
.RB [[ \-\-areas
.IR nr_areas ]
.RB |[ \-\-areasize
@@ -43,7 +44,7 @@ dmstats \(em device-mapper statistics management
.br
.B dmstats delete
.I device_name
-.RB [ \-\-force ]
+.RB [ \-\-alldevices ]
.RB [ \-\-allregions
.RB | \-\-regionid
.IR id ]
@@ -115,10 +116,14 @@ when run as 'dmsetup stats'.
When no device argument is given dmstats will by default operate on all
device-mapper devices present. The \fBcreate\fP and \fBdelete\fP
-commands require the use of \fB--force\fP when used in this way.
+commands require the use of \fB--alldevices\fP when used in this way.
.SH OPTIONS
.TP
+.B \-\-alldevices
+If no device arguments are given allow operation on all devices when
+creating or deleting regions.
+.TP
.B \-\-allprograms
Include regions from all program IDs for list and report operations.
.TP
@@ -267,7 +272,7 @@ stdout.
.TP
.B delete
.I [ device_name ]
-.RB [ \-\-force ]
+.RB [ \-\-alldevices ]
.RB [ \-\-allregions
.RB | \-\-regionid
.IR id ]
@@ -282,7 +287,8 @@ of subsequent list, print, or report operations.
All regions registered on a device may be removed using
\fB\-\-allregions\fP.
-To remove all regions on all devices \fB\-\-force\fP must be used.
+To remove all regions on all devices both \fB--allregions\fP and
+\fB\-\-alldevices\fP must be used.
.br
.TP
.B help
@@ -601,7 +607,7 @@ Created region: 0
Delete all regions on all devices
.br
.br
-# dmstats delete --allregions --force
+# dmstats delete --alldevices --allregions
.br
.br
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 420e263..20ab3a0 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -120,6 +120,7 @@ enum {
READ_ONLY = 0,
ADD_NODE_ON_CREATE_ARG,
ADD_NODE_ON_RESUME_ARG,
+ ALL_DEVICES_ARG,
ALL_PROGRAMS_ARG,
ALL_REGIONS_ARG,
AREAS_ARG,
@@ -4418,9 +4419,9 @@ static int _stats_create(CMD_ARGS)
name = names->name;
else {
if (argc == 1 && !_switches[UUID_ARG] && !_switches[MAJOR_ARG]) {
- if (!_switches[FORCE_ARG]) {
- log_error("Creating regions on all devices "
- "requires --force.");
+ if (!_switches[ALL_DEVICES_ARG]) {
+ log_error("Please specify device(s) or use "
+ "--alldevices.");
return 0;
}
return _process_all(cmd, subcommand, argc, argv, 0, _stats_create);
@@ -4506,9 +4507,9 @@ static int _stats_delete(CMD_ARGS)
name = names->name;
else {
if (argc == 1 && !_switches[UUID_ARG] && !_switches[MAJOR_ARG]) {
- if (!_switches[FORCE_ARG]) {
- log_error("Deleting regions from all devices "
- "requires --force.");
+ if (!_switches[ALL_DEVICES_ARG]) {
+ log_error("Please specify device(s) or use "
+ "--alldevices.");
return 0;
}
return _process_all(cmd, subcommand, argc, argv, 0, _stats_delete);
@@ -5355,6 +5356,7 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
#ifdef HAVE_GETOPTLONG
static struct option long_options[] = {
{"readonly", 0, &ind, READ_ONLY},
+ {"alldevices", 0, &ind, ALL_DEVICES_ARG},
{"allprograms", 0, &ind, ALL_PROGRAMS_ARG},
{"allregions", 0, &ind, ALL_REGIONS_ARG},
{"areas", 1, &ind, AREAS_ARG},
@@ -5479,6 +5481,8 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
optind = OPTIND_INIT;
while ((ind = -1, c = GETOPTLONG_FN(*argcp, *argvp, "cCfG:hj:m:M:no:O:rS:u:U:vy",
long_options, NULL)) != -1) {
+ if (ind == ALL_DEVICES_ARG)
+ _switches[ALL_DEVICES_ARG]++;
if (ind == ALL_PROGRAMS_ARG)
_switches[ALL_PROGRAMS_ARG]++;
if (ind == ALL_REGIONS_ARG)
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: improve region creation messages
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=988ca743519839...
Commit: 988ca743519839b283ebdbaaf06243cb0541b935
Parent: 86adb6ca63358ca09d3a886915f30fcec997787f
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Thu Aug 13 12:42:35 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Thu Aug 13 19:05:45 2015 +0100
dmstats: improve region creation messages
The region creation message just outputs the new region_id, e.g.:
Created region: 0
This is fine when the device is unambigous (as above) but produces
unhelpful output when creating multiple regions, or regions on
multiple devices:
Created region: 0
Created region: 0
Created region: 1
Created region: 2
Created region: 0
To address this refactor _stats_create_segments() (previously only
used when creating one-region-per-target for --segments) into a
more general _do_stats_create_regions() that can create regions
for each segment, or a single region spanning either the entire
device or a specied start/len range.
This allows us to output all region creation messages from a
single point where both the device name and all information needed
to derive the number of areas is available.
This allows us to log all these facts in the resulting messages:
vg_hex-lv_home: Created new region with 13 area(s) as region ID 0
vg_hex-lv_home: Created new region with 4 area(s) as region ID 1
vg_hex-lv_home: Created new region with 1 area(s) as region ID 2
vg_hex-lv_swap: Created new region with 1 area(s) as region ID 0
vg_hex-lv_root: Created new region with 10 area(s) as region ID 0
luks-79733921-3f68-4c92-9eb7-d0aca4c6ba3e: Created new region with 17 area(s) as region ID 0
vg_hex-lv_images: Created new region with 20 area(s) as region ID 0
vg_hex-lv_images: Created new region with 4 area(s) as region ID 1
---
tools/dmsetup.c | 97 +++++++++++++++++++++++++++++++++++++------------------
1 files changed, 65 insertions(+), 32 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 3473244..420e263 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -4282,19 +4282,43 @@ static int _size_from_string(char *argptr, uint64_t *size, const char *name)
return 1;
}
-static int _stats_create_segments(struct dm_stats *dms,
- const char *name, int64_t step,
- const char *program_id, const char *aux_data)
+/*
+ * FIXME: expose this from libdm-stats
+ */
+static uint64_t _nr_areas_from_step(uint64_t len, int64_t step)
{
- uint64_t start, length, region_id = UINT64_C(0);
+ /* --areas */
+ if (step < 0)
+ return (uint64_t)(-step);
+
+ /* --areasize - cast step to unsigned as it cannot be -ve here. */
+ return (len / (step ? : len)) + !!(len % (uint64_t) step);
+}
+
+/*
+ * Create a single region starting at start and spanning len sectors,
+ * or, if the segments argument is no-zero create one region for each
+ * segment present in the mapped device.
+ */
+static int _do_stats_create_regions(struct dm_stats *dms,
+ const char *name, uint64_t start,
+ uint64_t len, int64_t step,
+ int segments,
+ const char *program_id,
+ const char *aux_data)
+{
+ uint64_t this_start = start, this_len = len, region_id = UINT64_C(0);
char *target_type, *params; /* unused */
struct dm_task *dmt;
struct dm_info info;
void *next = NULL;
const char *devname = NULL;
+ int r = 0;
- if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
+ if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) {
+ dm_stats_destroy(dms);
return 0;
+ }
if (!_set_task_device(dmt, name, 0))
goto out;
@@ -4315,30 +4339,50 @@ static int _stats_create_segments(struct dm_stats *dms,
goto out;
do {
- next = dm_get_next_target(dmt, next, &start, &length,
+ uint64_t segment_start, segment_len;
+ next = dm_get_next_target(dmt, next, &segment_start, &segment_len,
&target_type, ¶ms);
- if (!dm_stats_create_region(dms, ®ion_id, start, length,
- step, program_id, aux_data)) {
- log_error("Could not create statistics region.");
+
+ /* Accumulate whole-device size for nr_areas calculation. */
+ if (!segments && !len)
+ this_len += segment_len;
+
+ /* Segments or whole-device. */
+ if (segments || !next) {
+ /*
+ * this_start and this_len hold the start and length in
+ * sectors of the to-be-created region: this is either the
+ * segment start/len (for --segments), the value of the
+ * --start/--length arguments, or 0/0 for a default
+ * whole-device region).
+ */
+ this_start = (segments) ? segment_start : this_start;
+ this_len = (segments) ? segment_len : this_len;
+ if (!dm_stats_create_region(dms, ®ion_id,
+ this_start, this_len, step,
+ program_id, aux_data)) {
+ log_error("%s: Could not create statistics region.",
+ devname);
+ goto out;
+ }
+
+ printf("%s: Created new region with "FMTu64" area(s) as "
+ "region ID "FMTu64"\n", devname,
+ _nr_areas_from_step(this_len, step), region_id);
}
- printf("Created region %"PRIu64" on %s\n",
- region_id, devname);
} while (next);
-
- dm_stats_destroy(dms);
- dm_task_destroy(dmt);
- return 1;
+ r = 1;
out:
dm_task_destroy(dmt);
- return 0;
+ dm_stats_destroy(dms);
+ return r;
}
static int _stats_create(CMD_ARGS)
{
struct dm_stats *dms;
const char *name, *aux_data = "", *program_id = DM_STATS_PROGRAM_ID;
- uint64_t region_id;
uint64_t start = 0, len = 0, areas = 0, area_size = 0;
int64_t step = 0;
@@ -4393,7 +4437,7 @@ static int _stats_create(CMD_ARGS)
return 0;
areas = (areas) ? areas : 1;
- /* bytes to sectors or area count - promote to int before conversion */
+ /* bytes to sectors or -(areas): promote to signed before conversion */
step = (area_size) ? ((int64_t) area_size / 512) : -((int64_t) areas);
if (_switches[START_ARG]) {
@@ -4430,20 +4474,9 @@ static int _stats_create(CMD_ARGS)
/* force creation of a region with no id */
dm_stats_set_program_id(dms, 1, NULL);
- if (_switches[SEGMENTS_ARG])
- return _stats_create_segments(dms, name, step,
- program_id, aux_data);
-
- if (!dm_stats_create_region(dms, ®ion_id, start, len,
- step, program_id, aux_data)) {
- log_error("Could not create statistics region.");
- goto out;
- }
-
- /* FIXME: support --quiet and --export output modes */
- printf("Created region: %"PRIu64"\n", region_id);
- dm_stats_destroy(dms);
- return 1;
+ return _do_stats_create_regions(dms, name, start, len, step,
+ _switches[SEGMENTS_ARG],
+ program_id, aux_data);
out:
dm_stats_destroy(dms);
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmsetup: make timekeeping debug messages more readable
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=86adb6ca63358c...
Commit: 86adb6ca63358ca09d3a886915f30fcec997787f
Parent: b22b7d7ba9208c5ead5ea6d7353cd903ebb3c075
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Wed Aug 12 19:46:11 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Thu Aug 13 19:05:45 2015 +0100
dmsetup: make timekeeping debug messages more readable
Don't use cryptic abbreviations and make sure that all values can
be understood by someone not familiar with the clock internals.
Include the current interval number (inverse of the _count) in all
interval update messages and attempt to align interval timestamp
logs for interval counts < 99,999.
---
tools/dmsetup.c | 30 ++++++++++++++++++++----------
1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 4a1a396..3473244 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -482,6 +482,14 @@ static void _destroy_split_name(struct dm_split_name *split_name)
* _update_interval_times() - Update timestamps and interval estimate.
*/
+/*
+ * Return the current interval number counting upwards from one.
+ */
+static uint64_t _interval_num(void)
+{
+ return 1 + (uint64_t) _int_args[COUNT_ARG] - _count;
+}
+
#if HAVE_SYS_TIMERFD_H
static int _start_timerfd_timer(void)
{
@@ -639,7 +647,7 @@ static int _do_timer_wait(void)
static int _update_interval_times(void)
{
static struct dm_timestamp *this_timestamp = NULL;
- uint64_t delta_t;
+ uint64_t delta_t, interval_num = _interval_num();
int r = 0;
/*
@@ -697,7 +705,9 @@ static int _update_interval_times(void)
_new_interval = 1;
}
- log_debug("Checking for interval end, dt="FMTu64, delta_t);
+ log_debug("Interval #%-4"PRIu64" time delta: %12"
+ PRIu64"ns", interval_num, delta_t);
+
if (_new_interval) {
/* Update timestamp and interval and clear _new_interval */
dm_timestamp_copy(_cycle_timestamp, this_timestamp);
@@ -708,14 +718,14 @@ static int _update_interval_times(void)
_mean_interval = ((double) delta_t + _mean_interval) / 2.0;
/*
- * Log interval duration, mean interval, the last interval
- * error and the difference between the mean and configured
- * intervals.
+ * Log interval duration, mean duration and interval error.
*/
- log_debug("Ending interval, I="FMTu64" Imean=%f, Ierr="FMTi64
- ", Emean=%.2f", _last_interval, _mean_interval,
- ((int64_t)_last_interval - (int64_t)_interval),
- _mean_interval - (double) _interval);
+ log_debug("Interval #%-5"PRIu64" mean duration: %12.0fns, "
+ "current err: "FMTi64"ns", interval_num,
+ _mean_interval, ((int64_t)_last_interval
+ - (int64_t)_interval));
+ log_debug("End interval #%-9"PRIu64" duration: %12"PRIu64"ns",
+ interval_num, _last_interval);
}
r = 1;
@@ -785,7 +795,7 @@ static int _display_info_cols(struct dm_task *dmt, struct dm_info *info)
/* Update timestamps and handle end-of-interval accounting. */
_update_interval_times();
- log_debug("Setting interval, I="FMTu64, _last_interval);
+ log_debug("Adjusted sample interval duration: %12"PRIu64"ns", _last_interval);
/* use measured approximation for calculations */
dm_stats_set_sampling_interval_ns(obj.stats, _last_interval);
}
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmsetup: Use #define for command names.
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b22b7d7ba9208c...
Commit: b22b7d7ba9208c5ead5ea6d7353cd903ebb3c075
Parent: 7995eedd3581407b030b0864202068b51dd1ef45
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Aug 13 13:10:23 2015 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Thu Aug 13 13:10:23 2015 +0100
dmsetup: Use #define for command names.
---
tools/dmsetup.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index dd2f153..4a1a396 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -108,6 +108,11 @@ extern char *optarg;
/* program_id used for dmstats-managed statistics regions */
#define DM_STATS_PROGRAM_ID "dmstats"
+#define DMSETUP_CMD_NAME "dmsetup"
+#define LOSETUP_CMD_NAME "losetup"
+#define DMLOSETUP_CMD_NAME "dmlosetup"
+#define DMSTATS_CMD_NAME "dmstats"
+
/*
* We have only very simple switches ATM.
*/
@@ -4818,7 +4823,7 @@ static void _dmsetup_usage(FILE *out)
int i;
fprintf(out, "Usage:\n\n");
- fprintf(out, "dmsetup [--version] [-h|--help [-c|-C|--columns]]\n"
+ fprintf(out, DMSETUP_CMD_NAME " [--version] [-h|--help [-c|-C|--columns]]\n"
" [-v|--verbose [-v|--verbose ...]]\n"
" [--checks] [--manglename <mangling_mode>]\n"
" [-r|--readonly] [--noopencount] [--nolockfs] [--inactive]\n"
@@ -4843,7 +4848,7 @@ static void _dmsetup_usage(FILE *out)
static void _losetup_usage(FILE *out)
{
fprintf(out, "Usage:\n\n");
- fprintf(out, "losetup [-d|-a] [-e encryption] "
+ fprintf(out, LOSETUP_CMD_NAME " [-d|-a] [-e encryption] "
"[-o offset] [-f|loop_device] [file]\n\n");
}
@@ -5110,7 +5115,7 @@ static int _loop_table(char *table, size_t tlen, char *file,
sectors = size >> SECTOR_SHIFT;
if (_switches[VERBOSE_ARG])
- fprintf(stderr, "losetup: set loop size to %llukB "
+ fprintf(stderr, LOSETUP_CMD_NAME ": set loop size to %llukB "
"(%llu sectors)\n", (long long unsigned) sectors >> 1,
(long long unsigned) sectors);
@@ -5413,13 +5418,13 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
return 1;
}
- if (!strcmp(base, "losetup") || !strcmp(base, "dmlosetup")){
+ if (!strcmp(base, LOSETUP_CMD_NAME) || !strcmp(base, DMLOSETUP_CMD_NAME)){
r = _process_losetup_switches(base, argcp, argvp, dev_dir);
free(namebase);
return r;
}
- if (!strcmp(base, "dmstats")) {
+ if (!strcmp(base, DMSTATS_CMD_NAME)) {
/* save the offset to the 'stats' in 'dmstats' */
stats_p = (*argvp)[0] + strlen(namebase) - strlen(base) + 2;
stats_c = (*argvp)[1]; /* stats command */
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: don't output column headings if report fails
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7995eedd358140...
Commit: 7995eedd3581407b030b0864202068b51dd1ef45
Parent: 098528513f8c00d12f4ca5b5e87e4a932a6ef4f6
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Wed Aug 12 22:02:23 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Wed Aug 12 22:02:23 2015 +0100
dmstats: don't output column headings if report fails
If _stats_report fails (e.g. due to an invalid device on the
command line) destroy the _report to prevent stats columns headings
from being displayed.
This also requires a change in main to test the return from
_perform_command_for_all_repeatable_args inside the interval loop
and exit immediately in case of error.
---
tools/dmsetup.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index e913a7e..dd2f153 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -4692,6 +4692,10 @@ static int _stats_report(CMD_ARGS)
out:
dm_task_destroy(dmt);
+ if (!r && _report) {
+ dm_report_free(_report);
+ _report = NULL;
+ }
return r;
}
@@ -5838,6 +5842,9 @@ doit:
goto_out;
}
}
+
+ if (r)
+ break;
} while (--_count);
out:
8 years, 9 months
dev-prajnoha-pv-ext-flag-used - dmstats: don't output column headings when args checks fail
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=098528513f8c00...
Commit: 098528513f8c00d12f4ca5b5e87e4a932a6ef4f6
Parent: 829384f46dedee8646cc6b098ef98463658c51d6
Author: Bryn M. Reeves <bmr(a)redhat.com>
AuthorDate: Wed Aug 12 21:14:00 2015 +0100
Committer: Bryn M. Reeves <bmr(a)redhat.com>
CommitterDate: Wed Aug 12 21:40:43 2015 +0100
dmstats: don't output column headings when args checks fail
The clear, create, delete, and print commands do not use _report:
make sure it is freed and set to NULL before checking arguments.
---
tools/dmsetup.c | 48 ++++++++++++++++++++++++------------------------
1 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 459639b..e913a7e 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -4193,6 +4193,12 @@ static int _stats_clear(CMD_ARGS)
char *name = NULL;
int allregions = _switches[ALL_REGIONS_ARG];
+ /* clear does not use a report */
+ if (_report) {
+ dm_report_free(_report);
+ _report = NULL;
+ }
+
if (!_switches[REGION_ID_ARG] && !_switches[ALL_REGIONS_ARG]) {
err("Please specify a region_id.");
return 0;
@@ -4206,12 +4212,6 @@ static int _stats_clear(CMD_ARGS)
name = argv[1];
}
- /* create does not use a report */
- if (_report) {
- dm_report_free(_report);
- _report = NULL;
- }
-
region_id = (allregions) ? DM_STATS_REGIONS_ALL
: (uint64_t) _int_args[REGION_ID_ARG];
@@ -4327,6 +4327,12 @@ static int _stats_create(CMD_ARGS)
uint64_t start = 0, len = 0, areas = 0, area_size = 0;
int64_t step = 0;
+ /* create does not use a report */
+ if (_report) {
+ dm_report_free(_report);
+ _report = NULL;
+ }
+
if (_switches[ALL_REGIONS_ARG]) {
log_error("Cannot use --allregions with create.");
return 0;
@@ -4363,12 +4369,6 @@ static int _stats_create(CMD_ARGS)
name = argv[1];
}
- /* create does not use a report */
- if (_report) {
- dm_report_free(_report);
- _report = NULL;
- }
-
if (_switches[AREAS_ARG])
areas = (uint64_t) _int_args[AREAS_ARG];
@@ -4443,6 +4443,12 @@ static int _stats_delete(CMD_ARGS)
const char *program_id = DM_STATS_PROGRAM_ID;
int allregions = _switches[ALL_REGIONS_ARG];
+ /* delete does not use a report */
+ if (_report) {
+ dm_report_free(_report);
+ _report = NULL;
+ }
+
if (!_switches[REGION_ID_ARG] && !allregions) {
err("Please specify a region_id.");
return 0;
@@ -4462,12 +4468,6 @@ static int _stats_delete(CMD_ARGS)
name = argv[1];
}
- /* delete does not use a report */
- if (_report) {
- dm_report_free(_report);
- _report = NULL;
- }
-
if (_switches[ALL_PROGRAMS_ARG])
program_id = DM_STATS_ALL_PROGRAMS;
@@ -4598,6 +4598,12 @@ static int _stats_print(CMD_ARGS)
unsigned clear = (unsigned) _switches[CLEAR_ARG];
int allregions = _switches[ALL_REGIONS_ARG];
+ /* print does not use a report */
+ if (_report) {
+ dm_report_free(_report);
+ _report = NULL;
+ }
+
if (!_switches[REGION_ID_ARG] && !allregions) {
err("Please specify a region_id.");
return 0;
@@ -4611,12 +4617,6 @@ static int _stats_print(CMD_ARGS)
name = argv[1];
}
- /* print does not use a report */
- if (_report) {
- dm_report_free(_report);
- _report = NULL;
- }
-
region_id = (uint64_t) _int_args[REGION_ID_ARG];
dms = dm_stats_create(DM_STATS_PROGRAM_ID);
8 years, 9 months