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

361 Commits

Author SHA1 Message Date
Zdenek Kabelac
60b61f2db3 libdm-stats: correct checking of dm_snprintf error
Function dm_snprintf returns -1 on error, while 0 is still
considered valid result code so correcting error path testing.
2018-02-12 22:13:57 +01:00
Ondrej Kozina
32e747dd31 dmsetup: hide integrity encryption keys on table output 2017-11-10 15:23:00 +01:00
Zdenek Kabelac
e2fce429cf cleanup: gcc const warning 2017-11-07 21:26:11 +01:00
Alasdair G Kergon
4b0f6829f6 dmsetup: Add unknown device error to dmsetup status.
Treat status the same way as info if provided device name doesn't exist.
2017-10-26 17:47:13 +01:00
Alasdair G Kergon
f1cc5b12fd tidy: Add missing underscores to statics. 2017-10-18 15:58:13 +01:00
Alasdair G Kergon
d73eddcdc0 dmsetup: Process -S to filter input device lists.
The following commands now pass the device list through a
--select|-S filter before processing:

suspend resume clear wipe_table remove deps status table
2017-09-14 23:41:17 +01:00
Zdenek Kabelac
962874bfe2 dmsetup: validate strtol reading
Better validation for --mode option.
2017-08-25 14:20:59 +02:00
Zdenek Kabelac
47b7d4a733 dmsetup: add missing -- for option 2017-08-25 14:20:59 +02:00
Alasdair G Kergon
827be01758 dmsetup: Add --concise to dmsetup create.
Add the new concise format to dmsetup create, either as a single
command-line parameter or from stdin.

Based on patches submitted by
Enric Balletbo i Serra <enric.balletbo@collabora.com>.
2017-08-04 19:38:34 +01:00
Alasdair G Kergon
f9f75de3da dmsetup: Add minor number to concise table output format.
When using this new format for input, it'll sometimes help to
be able to specify the minor number.
2017-07-25 12:22:46 +01:00
Alasdair G Kergon
5fd7c0aa33 dmsetup: Add concise table output format.
Create a new table output format that concisely shows multiple devices
on one line.

dmsetup table --concise [device...]

<dev_name>,<uuid>,<flags>[,<table>]*[;<dev_name>,<uuid>,<flags>[,<table>]*]*

Table lines are separated by commas.
Devices are separated by semi-colons.
Flags is currently 'ro' or 'rw' (and might be extended in a
yet-to-be-defined way in future).
Any comma, semi-colon or backslash within a field is quoted by a
preceding backslash.

The format can later be supplied as input to dmsetup or even to the
booting kernel as an alternative way to set up devices.

Based on patches submitted by
Enric Balletbo i Serra <enric.balletbo@collabora.com>.
2017-07-25 01:13:14 +01:00
Zdenek Kabelac
0bf836aa14 tidy: prefer not using else after return
clang-tidy: avoid using  'else' after return - give more readable code,
and also saves indention level.
2017-07-20 11:18:29 +02:00
Zdenek Kabelac
0d0a3397c2 cleanup: add braces in macro 2017-07-20 11:18:29 +02:00
Zdenek Kabelac
e769e3d3bf dmsetup: simplify check of parsed cookie value
Improving parsing error detection for strtoul.
2017-07-20 11:18:16 +02:00
Zdenek Kabelac
ba9820b142 numbers: strtod or strtoul need reset of errno
API for strtod() or strtoul() needs reset of errno, before it's being
called. So add missing resets in missing places and some also some
errno validation for out-of-range numbers.
2017-07-17 12:32:18 +02:00
Bryn M. Reeves
2b46fe5843 dmsetup: replace (f)printf("\n") with putchar/putc 2017-03-30 16:30:50 +01:00
Nir Soffer
b8b2b1efd8 dmsetup: Flush ouptut when using --interval 2017-03-30 10:17:32 +01:00
Bryn M. Reeves
fe0922b8a6 dmsetup: simplify branching in _stats_update_file()
The fallback branch in _stats_update_file() is redundant (since the
branch taken when the daemon starts successfully must jump to the
'out' label anyway): remove it and re-order the conditions to
improve readability.
2017-03-30 09:57:58 +01:00
Bryn M. Reeves
5994ed9df2 dmsetup: always close fd when leaving _stats_update_file() (coverity) 2017-03-29 18:34:57 +01:00
Bryn M. Reeves
11749e7adb dmsetup: do not start dmfilemapd if region creation fails (coverity) 2017-03-29 18:34:51 +01:00
Zdenek Kabelac
e3a3cf01eb cleanup: use more common FMTd64 type
We use 'd' for plain singed integers.
2017-03-27 20:50:19 +02:00
Bryn M. Reeves
c713745314 dmsetup: always initialise 'dms' in _stats_update_file() 2017-03-10 16:44:08 +00:00
Bryn M. Reeves
6a0f597727 dmsetup: always initialise 'mode' in filemap create functions
Older compilers cannot tell that the 'mode' variable is only
used in branches in which it is assigned:

dmsetup.c:5651: warning: "mode" may be used uninitialized in this function
dmsetup.c:5023: warning: "mode" may be used uninitialized in this function

Avoid this by always assigning the variable a value.
2017-03-10 12:17:25 +00:00
Bryn M. Reeves
baa8a9be4a dmstats: start dmfilemapd when creating or updating file maps
Launch an instance of the filemap monitoring daemon when creating,
or updating, a file mapped group, unless the --nomonitor switch is
given.

Unless --foreground is given the daemon will detach from the
terminal and run in the background until it is signaled or the
daemon termination conditions are met.

The --follow={inode|path} switch is added to control the daemon
behaviour when files are moved, unlinked, or renamed while they
are being monitored.

The daemon runs with the same verbosity as the dmstats command
that starts it.
2017-03-09 18:50:15 +00:00
Alasdair G Kergon
d2dbe71fb3 dmsetup: Indicate device repetition in usage summaries. 2017-02-21 11:25:18 +00:00
Ondrej Kozina
035c614c19 dmsetup: do not suppress kernel key descriptions in tables
Kernel 4.10 (dm-crypt v1.15.0) and later supports loading device
tables with crypt segment having key in kernel keyring retention
service.

dmsetup hid key section of tables output. With this patch dmsetup
no longer hides key section if it detects kernel key description
instead of hex byte representation of key itself.
2017-02-10 19:18:49 +01:00
Bryn M. Reeves
b999d5f501 dmstats: allow --filemap groups to be updated
Add a new update_filemap command to dmstats that allows a filemap
group to be updated:

  # dmstats update_filemap --groupid 0 vm.img
  /var/lib/libvirt/images/vm.img: Updated group ID 0 with 137 region(s).

This will update the set of regions mapped to the file to reflect
the current file system allocation.

Currently this needs to be run manually - a future update will add
support for monitoring file maps via a daemon, allowing them to be
automatically updated when the underlying file is modified.
2017-01-25 16:15:21 +00:00
Bryn M. Reeves
c90e9392e4 libdm: add dm_stats_bind_from_fd()
dmsetup already has a version of this function, and dmfilemapd will
need it too: move it to libdevmapper to avoid copying it around.
2016-12-18 20:47:17 +00:00
Bryn M. Reeves
a15f0d181c dmstats: don't declare _start_timestamp if HAVE_SYS_TIMERFD_H
The _start_timestamp is not used by the TIMERFD clock.
2016-12-18 14:08:11 +00:00
Bryn M. Reeves
3e53adf7c0 dmstats: fix TIMERFD _timer_running() test 2016-12-18 14:07:25 +00:00
Bryn M. Reeves
5a4750d76c dmstats: fix interval number reporting with --count=0
When --count=0 interval numbers are miscalculated:

Interval     #18446744069414584325     time delta:    999920887ns
Interval     #18446744069414584325   current err:       -79113ns
End interval #18446744069414584325  duration:    999920887ns

This is because the command line argument is cast through the
uint32_t type, and fixed to UINT32_MAX:

  _count = ((uint32_t)_int_args[COUNT_ARG]) ? : UINT32_MAX;

We also need to handle --count=0 specially when calculating the
interval number: since intervals count from #1, this must account
for the implicit "minus one" when converting from zero to the
UINT64_MAX value used (which is too large to store in _int_args).
2016-12-18 13:03:45 +00:00
Bryn M. Reeves
5635cd3b03 dmstats: separate TIMERFD and useleep() exit conditions
The time management code mixes tests of the _timer_fd value with
code that should be timer agnostic: this causes problems for users
of the usleep() timer, since it cannot properly detect the start
of a new interval:

Beginning first interval
Interval     #18446744069414584348     time delta:   1000000000ns
Interval     #18446744069414584348   current err:            0ns
End interval #18446744069414584348  duration:   1000000000ns
Adjusted sample interval duration:   1000000000ns
[...]
Beginning first interval
Interval     #18446744069414584349     time delta:   1000000000ns
Interval     #18446744069414584349   current err:            0ns
End interval #18446744069414584349  duration:   1000000000ns
Adjusted sample interval duration:   1000000000ns

Separate these out, by defining a _timer_running() call that each
timer implements, and only define _timer_fd if we are compiling
with TIMERFD enabled.
2016-12-18 13:03:44 +00:00
Bryn M. Reeves
886b4f755d dmstats: use better interval estimate for usleep() timer
Although the usleep() interval timer is not used if the Linux
TIMERFD interface is available it should still provide reasonably
good timing.

Instead of trying to estimate the error from the duration of the
last sleep, peg it to the start time of the program, and use the
value of  ((start_time - now) % interval) to correct the current
interval duration.

This always pulls us back into sync at the end of each interval,
rather than relying on trying to incrementally adjust the time
duration at each interval start.

This greatly reduces drift when the usleep() clock is used.
2016-12-18 13:03:44 +00:00
Bryn M. Reeves
68ec42ebaf dmstats: improve tool help output and option coverage 2016-12-18 11:51:13 +00:00
Zdenek Kabelac
1d58074d9f debug: more stacktrace corrections
Continue previous patch dropping some unneeded stack traces
after printed log_error/warn messages.
2016-11-25 14:58:28 +01:00
Heinz Mauelshagen
b11f4f93d7 dmsetup: [v2] return 0 for [--]{version,help}
Leverage 0b1c796420 to cope with "dmsetup SubCommand --{help,version}"
and bail out directly when _report_init() fails.

Related: rhbz1393692
2016-11-10 18:09:37 +01:00
Heinz Mauelshagen
0b1c796420 dmsetup: return 0 for [--]{version,help}
dmsetup regressed returning 1 when properly processing
version or help subcommands.

Resolves: rhbz1393692
2016-11-10 17:03:04 +01:00
Zdenek Kabelac
4e26024add cleanup: use WARNING prefix for log_warn
Use capital WARNING prefix for log_warn() messages.
2016-11-03 17:49:07 +01:00
Bryn M. Reeves
021715e897 dmsetup: remove stray '\n' in delete log message 2016-10-24 17:21:35 +01:00
Bryn M. Reeves
5eda393488 dmsetup: obey --programid when deleting regions 2016-10-24 17:21:18 +01:00
Alasdair G Kergon
34da83d729 dmsetup: Produce partial output if dev disappears.
If a device disappears after obtaining the list of devices but before
processing it as a member of that list, dmsetup exits with a failure code.

Most commands still produce what output they can in these circumstances,
but 'ls --tree' and 'info -c' with fields depending on device dependencies
didn't.  Change this.
2016-10-18 18:01:52 +01:00
Peter Rajnoha
926a565781 coverity: dmsetup: fix possible use of uninitialized value 2016-09-21 15:52:23 +02:00
Bryn M. Reeves
7ea5758c91 dmsetup: ensure --filemap histogram bounds are freed
Make sure that the temporary dm_histogram used for the bounds
argument is freed in the case that the user provided a --bounds
argument on the command line.
2016-09-21 10:09:20 +01:00
Bryn M. Reeves
da49d4d54e dmstats: fix bounds leak in _do_stats_create_regions() (Coverity) 2016-07-18 18:48:34 +01:00
Bryn M. Reeves
d2bf6742f8 dmstats: check uuid, major, and alldevices before argc (Coverity)
The --uuid, --major and --alldevices arguments were incorrectly tested
after confirming argc is > 0, in a branch that only executes if argc
== 0 (i.e. they were unreachable).

Move all device checks before the test for argc and log an appropriate
error before returning.
2016-07-18 18:48:34 +01:00
Bryn M. Reeves
da146ae9b9 dmstats: free bounds string in _stats_create_file() (Coverity) 2016-07-18 18:48:34 +01:00
Bryn M. Reeves
6a77a40501 dmstats: accept multiple arguments to --filemap
Make the --filemap switch take no arguments and instead accept one
or more files on the command line to be mapped and placed into
groups.

This allows --filemap to be used with a glob:

  # dmstats create --filemap *
  rhel5.10-1.qcow2: Created new group with 87 region(s) as group ID 1564.
  rhel5.10.qcow2: Created new group with 8 region(s) as group ID 1651.
  rhel7.0-1.qcow2: Created new group with 11 region(s) as group ID 1659.
  rhel7.0.qcow2: Created new group with 1454 region(s) as group ID 1670.
  vm.img: Created new group with 2 region(s) as group ID 3124.
2016-07-08 22:05:36 +01:00
Bryn M. Reeves
5cd39f1dc4 dmstats: use canonical path when reporting errors
When a 'dmstats create --filemap' operation fails (e.g. during
open(2), close(2), or dm_stats_create_regions_from_fd()), use the
canonical version of the path. This avoids cryptic/confusing error
messages when symbolic links exist in the path argument given:

  # findmnt /var/lib/libvirt/images -otarget,source
  TARGET                  SOURCE
  /var/lib/libvirt/images /dev/mapper/vg_hex-lv_images

  # readlink /var/lib/libvirt/images/my.img
  /boot/my.img

  # dmstats create --filemap /var/lib/libvirt/images/my.img
  Cannot map file: not a device-mapper device.
  Could not create regions from file /var/lib/libvirt/images/my.img
  Command failed

Using the canonical path the error is immediately obvious:

  # dmstats create --filemap /var/lib/libvirt/images/my.img
  Cannot map file: not a device-mapper device.
  Could not create regions from file /boot/my.img
  Command failed
2016-07-08 17:27:52 +01:00
Bryn M. Reeves
bd1f4987eb dmstats: group regions by default with --segments
Grouping is also useful in combination with --segments: creating a
group allows both individual segment data and data for the device
as a whole to be presented in the same report.

Support grouping for 'create --segments' in the same manner as for
'create --filemap'; group regions by default, applying an optional
alias specified with --alias, unless the user specifies --nogroup.
2016-07-08 17:27:52 +01:00
Bryn M. Reeves
bce1bc4ca3 dmstats: allow --bounds with 'create --filemap' 2016-07-08 17:27:52 +01:00