1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 11:55:55 +03:00
Commit Graph

260 Commits

Author SHA1 Message Date
Bryn M. Reeves
69fa16048a dmstats: check for zero in _nr_areas_from_step() (Coverity) 2015-08-17 18:37:16 +01:00
Bryn M. Reeves
b01e9651b0 dmsetup: make sure subcommand is initialised (Coverity) 2015-08-17 18:37:16 +01:00
Zdenek Kabelac
94c56559ca dmsetup: fix usage of ifdefs 2015-08-17 15:52:06 +02:00
Bryn M. Reeves
4a6d5e2012 dmstats: fix --length argument
Commit f10ad95 introduced a regression causing the size of regions
passed in on the command line to be truncated to zero. Initialise
the 'this_len' variable to the supplied length to correct this.
2015-08-15 18:35:10 +01:00
Bryn M. Reeves
9d5cd4ca14 dmstats: fix new area count for 'create --areasize'
Commit f10ad95 introduced a regression in the calculation of the
number of areas in a region created with the --areasize switch:

vg_hex-lv_home: Created new region with 0 area(s) as region ID 1
vg_hex-lv_swap: Created new region with 0 area(s) as region ID 1

Fis this by using the correct region size when calculating the
value.
2015-08-15 00:42:51 +01:00
Bryn M. Reeves
0b487802a0 dmstats: change region fields prefix to 'region_' 2015-08-14 23:53:42 +01:00
Bryn M. Reeves
f3891e90e3 dmstats: make -v enable per area reports for 'stats list'
When dmstats is run with -v or higher enable a per-area reporting
mode for statistics regions. This will output one row per area
(rather than one row per region) and adds additional fields of use
when viewing areas:

 area_id    - index within the region assigned by libdm-stats
 area_start - the start location of the area in the containing
              device.
2015-08-14 22:03:37 +01:00
Bryn M. Reeves
0f3b81bb2e dmstats: add 'area_offset' field to stats reports 2015-08-14 22:03:37 +01:00
Bryn M. Reeves
16ff2d927f dmsetup: add support for 'stats report --raw'
Add a '--raw' switch to stats reports that causes us to report the
basic counter values rather than derived metrics for each visible
statistics region.
2015-08-14 22:03:37 +01:00
Bryn M. Reeves
fc7a27bc3d dmsetup: add prefixes for all report types
Add prefixes to all dmsetup report types to allow the 'group_all'
option to be effective:

  DR_NAME       name_
  DR_INFO       info_
  DR_DEPS       deps_
  DR_TREE       tree_
  DR_NAME       splitname_
2015-08-14 22:03:37 +01:00
Bryn M. Reeves
666722324f dmstats: add 'stat_' prefix to stats report columns 2015-08-14 22:03:37 +01:00
Bryn M. Reeves
8852b25fc7 dmsetup: do not track moving average for interval estimate
When run with full verbosity dmsetup or dmstats reports will
output a figure that tracks a moving average over a window of the
last two intervals:

Interval     #3        time delta:    999991087ns
Interval     #3     mean duration:    999907064ns, current err: -8913ns
End interval #3          duration:    999991087ns
Adjusted sample interval duration:    999991087ns

Due to the narrow window this is a very crude estimate and is only
of use to someone debugging or modifying the stats clock: remove
the value and the global variables used to track it.

Anyone with a particular use for this information can construct a
better mean by calculating the value of a greater number of
intervals.
2015-08-14 13:55:26 +01:00
Bryn M. Reeves
e6724f0303 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.
2015-08-14 13:43:12 +01:00
Bryn M. Reeves
37dd26e322 dmstats: separate stats meta fields into their own report type
Although statistics and meta fields (region and area properties) share
the same object type the state of the handle they expect differs: meta
only expects a dm_stats_list() operation to have been performed whereas
statistics require a fully populated handle.

Distinguish between these requirements by separating the fields into
two distinct report types:

  DR_STATS = 32,
  DR_STATS_META = 64

The new category is described as "Mapped Device Statistics Region
Information" in the help text.
2015-08-14 13:43:03 +01:00
Bryn M. Reeves
f10ad95c36 dmstats: cleanup _do_stats_create_regions()
Make the use of the this_start and this_len variables easier to
follow and clarify the use of zero start and len arguments to
request a whole-device region.
2015-08-14 13:36:52 +01:00
Bryn M. Reeves
9b3dc72506 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.
2015-08-14 13:36:50 +01:00
Alasdair G Kergon
6a93206882 dmsetup: Fix dmsetup return code. 2015-08-14 00:09:40 +01:00
Alasdair G Kergon
043fb32c4b dmsetup: Restructure arg handling.
Introduce enums and global variables to record cleanly which command we
are processing and eliminate the historically inconsistent use of the
shifted argv[0] and fix assorted bugs discovered along the way.

Add dm_report_is_empty() to indicate there is no data awaiting output
and use this to suppress dmsetup report headings when no data is output
so we don't get a stray line saying 'Help' at the end of reporting help.

Define a report type (as the interface requires) so -o all selects
the right fields in splitname.  (A fix for stats list will follow.)

Exit immediately if no device is supplied to dmsetup wipe_table instead
of hitting errors later and failing.

Adjust the command name printed in usage/help output to match command
invoked (most of the time).
2015-08-13 22:30:39 +01:00
Bryn M. Reeves
b3cd5d2945 dmstats: do not use "region_id" in error messages
Refer to either '--regionid' or '--allregions' when the user fails
to specify either a single region ID or the --allregions switch.
2015-08-13 19:05:48 +01:00
Bryn M. Reeves
6b81ac5807 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.
2015-08-13 19:05:46 +01:00
Bryn M. Reeves
988ca74351 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
2015-08-13 19:05:45 +01:00
Bryn M. Reeves
86adb6ca63 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.
2015-08-13 19:05:45 +01:00
Alasdair G Kergon
b22b7d7ba9 dmsetup: Use #define for command names. 2015-08-13 13:10:23 +01:00
Bryn M. Reeves
7995eedd35 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.
2015-08-12 22:02:23 +01:00
Bryn M. Reeves
098528513f 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.
2015-08-12 21:40:43 +01:00
Bryn M. Reeves
e96041e18f dmsetup: only free resources once in the final interval
The _update_interval_times() function is called once per reported
object: when shutting down at the end of a run only the first call
should free timestamps. Clear the timestamp pointers after free
and use this to signal to other callers that the clock is already
shut down.
2015-08-12 19:16:05 +01:00
Bryn M. Reeves
a8b9e2eccd dmsetup: use timerfd for interval timing if available
If the Linux timerfd interface to POSIX timers is available at compile
time use it for all report interval timekeeping. This gives more
accurate interval timing when the per-interval processing time is less
than the configured interval and simplifies the timestamp bookkeeping
required to keep accurate time.

For systems without timerfd support fall back to the simple usleep based
timer.
2015-08-12 15:09:57 +01:00
Bryn M. Reeves
ec87e88c52 dmsetup: don't free handle if dm_stats_create fails (Coverity)
The error path of _stats_list frees the task and stats objects:
don't try to branch to it before they have been allocated.

tools/dmsetup.c: 4589 in _stats_help() - Null pointer dereferences  (FORWARD_NULL)
2015-08-10 20:25:59 +01:00
Bryn M. Reeves
3b74824985 dmsetup: remove bogus !_report test in _stats_report (Coverity)
There's no point testing _report here in _stats_report: it's always
initialised before the function is called and if the check did fail
we'd end up freeing an uninitialized dm_task in the error path.

tools/dmsetup.c: 4389 in _stats_report() - Declaring variable "dmt" without initializer.
2015-08-10 20:12:53 +01:00
Bryn M. Reeves
d62a8d2f15 dmstats: add libdm-stats library and 'dmsetup stats' command
Add the libdm-stats module to libdm: this implements a simple interface
for creating, managing and interrogating I/O statistics regions and
areas on device-mapper devices.

The library interface is documented in libdevmapper.h and provides a
'dm_stats' handle that is used to perform statistics operations and
obtain data.

Public methods are provided to create and destroy handles and to list,
create, and destroy statistics regions as well as to obtain and parse
counter data and calculate rate-based metrics.

This commit also adds a 'dmsetup stats' (aka 'dmstats') command with
'clear', 'create', 'delete', 'list', 'print', and 'report' sub-commands.

See the library documentation and the dmstats.8 manual page for detailed
API and command descriptions.
2015-08-09 14:37:58 +01:00
Bryn M. Reeves
54815fff06 libdm: remove report interval support
Don't do interval management and external timekeeping for stats in
dm_report: let applications handle this on their own.

Since this has not been included in a release remove it from the
library entirely and handle report timing directly inside dmsetup.
2015-08-08 11:48:12 +01:00
Bryn M. Reeves
666c77c0f2 libdm: add dm_report_column_headings
Add a function to print column headings regardless of whether they
have already been output. This will be used by dmstats to issue
periodic reminders of the column headings.

This patch removes a check for RH_HEADINGS_PRINTED from
_report_headings that prevents headings being displayed if the flag
is already set; this check is redundant since the only existing
caller (_output_as_columns()) already tests the flag before
calling the function.
2015-08-08 11:43:52 +01:00
Alasdair G Kergon
559ca8bc65 dmsetup: Report timestamps of ioctls with -vvv.
If enabled, record timestamp immediately after the ioctl() returns.
2015-08-05 08:28:35 +01:00
Alasdair G Kergon
362a1a5a82 dmsetup: Tidy whitespace. 2015-08-05 05:03:33 +01:00
Bryn M. Reeves
519c309952 dmsetup: Use argcp and argvp. 2015-07-31 22:53:38 +01:00
Bryn M. Reeves
a161e29c59 dmsetup: Add --count and --interval to reports.
For example, to monitor active devices every second you can now run
dmsetup info -c --count 0.
2015-07-31 21:59:34 +01:00
Alasdair G Kergon
649c9d4719 dmsetup: Allow commands to have subcommands.
No commands set has_subcommands yet.

Move multiple device loop to separate function because we'll
soon want to call it repeatedly.

(Based on patch from bmr.)
2015-07-31 19:09:31 +01:00
Alasdair G Kergon
51f89f2fbd dmsetup: Add subcommand parameter.
Not yet used.
Allows for dmsetup stats <subcommand> dev1 dev2...
2015-07-31 17:47:03 +01:00
Alasdair G Kergon
e06d188f0d dmsetup: _find_command returns const 2015-07-31 16:58:14 +01:00
Alasdair G Kergon
fef3cb3f21 dmsetup: Add _dmsetup to help and usage fns.
Prepare for dmstats.
Adjust some text to avoid 80-char wrap.
2015-07-31 16:26:38 +01:00
Alasdair G Kergon
027fe112ec dmsetup: Rename _commands to _dmsetup_commands.
We'll need to accommodate sub-commands for dmstats.
2015-07-31 16:13:45 +01:00
Peter Rajnoha
ca0d9a70d1 dmsetup: remove dead code that covered "info -c -o help" case once
The "-o help" is now handled as implicit field and it gets processed
just like any other field - all handled by libdevmapper now.
2015-07-29 13:16:09 +02:00
Alasdair G Kergon
dfe3eb12d0 include: Standardise around new tool.h. 2015-07-06 17:30:18 +01:00
Alasdair G Kergon
810ab095e6 macros: Wrap PRI with FMT.
Create a set of wrappers with embedded % such as
  #define FMTu64 "%" PRIu64
2015-07-06 15:09:17 +01:00
Ondrej Kozina
8af5f54824 dmsetup: zero errno in before strtoul call
Testing errno value without explicitly setting to
zero in before the strtoul call may lead to
unexpected failures.
2015-05-26 16:27:10 +02:00
Zdenek Kabelac
428b9fcd87 cleanup: validate pointers
Mostly on almost impossible to happen paths - but stay safe.
2014-11-13 17:49:42 +01:00
Zdenek Kabelac
c5f2c541f6 cleanup: simplier struct init
Use simplier struct initilizer.
2014-08-19 14:33:07 +02:00
Zdenek Kabelac
24df01f735 cleanup: avoid double assign
Skip setting a value to a variable which is never
used and overwritten/set afterwards.
2014-08-19 14:33:06 +02:00
Alasdair G Kergon
42e07d2bce dmsetup: Support remove --deferred.
This patch adds a new flag --deferred to dmsetup remove. If this flag is
specified and the device is open, it is scheduled to be deleted on
close.

struct dm_info is extended.

The existing dm_task_get_info() is converted into a wrapper around the
new version dm_task_get_info_with_deferred_remove() so existing binaries
can still use the old smaller structure.

Recompiled code will pick up the new larger structure.

From: Mikulas Patocka <mpatocka@redhat.com>
2014-08-16 00:34:48 +01:00
Peter Rajnoha
59ed4d3bf6 dmsetup: no need to check for "help" field name after report init
The "help" field (as well as "?") is implicit now - libdevmapper
takes care of it completely.
2014-06-19 18:22:51 +02:00