1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
Commit Graph

151 Commits

Author SHA1 Message Date
Bryn M. Reeves
ac41deeeac Rename _stats_set_aux() argument
The aux_data argument of _stats_set_aux() is the user-defined data
to be stored with the stats region. Rename the argument to better
reflect this.
2023-10-12 11:31:14 +00:00
Bryn M. Reeves
eda99fc383 Clean up group struct in _stats_create_group() error path
Fix a double free in the error path from _stats_create_group() by
clearing the group struct embedded in the dm_stats handle before
returning:

    device-mapper: message ioctl on  (253:0) failed: Invalid argument
    Could not create regions from file /var/tmp/File With Spaces.
    free(): double free detected in tcache 2
    Aborted (core dumped)
2023-10-12 11:31:14 +00:00
Zdenek Kabelac
2e990d1fec gcc: avoid warns on missing braces with older version 2021-09-20 16:11:49 +02:00
Zdenek Kabelac
63930f576a cov: add some initializers 2021-09-13 12:34:41 +02:00
Zdenek Kabelac
a8480f0f6e libdm: symbol versioning with -flto
Gcc10 introduced different strategy how to build
shared libraries with their new LTO optimizer.

Insired by:

https://akkadia.org/drepper/symbol-versioning
https://sourceware.org/pipermail/elfutils-devel/attachments/20200414/1c0c2903/attachment.bin
https://github.com/InBetweenNames/gentooLTO/issues/459
https://github.com/linux-rdma/rdma-core/blob/master/util/symver.h
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48200
2021-04-06 21:26:57 +02:00
Zdenek Kabelac
1cedbaf137 configure: support builds without versioning
Not all libc (like musl, uclibc dietlibc) libraries support full symbol
version resolution in runtime like glibc.
Add support to not generate symbol versions when compiling against them.

Additionally libdevmapper.so was broken when compiled against
uclibc. Runtime linker loader caused calling dm_task_get_info_base()
function recursively, leading to segmentation fault.

Introduce --with-symvers=STYLE option, which allows to choose
between gnu and disabled symbol versioning. By default gnu symbol
versioning is used.
__GNUC__ check is replaced now with GNU_SYMVER.
Additionally ld version script is included only in
case of gnu option, which slightly reduces output size.

Providing --without-symvers to configure script when building against
uclibc library fixes segmentation fault error described above, due to
lack of several versions of the same symbol in libdevmapper.so
library.

Based on:
https://patchwork.kernel.org/project/dm-devel/patch/20180831144817.31207-1-m.niestroj@grinn-global.com/

Suggested-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-03-30 13:06:19 +02:00
Zdenek Kabelac
fd96f1014b gcc: zero-sized array to fexlible array C99
Switch remaining zero sized struct to flexible arrays to be C99
complient.

These simple rules should apply:

- The incomplete array type must be the last element within the structure.
- There cannot be an array of structures that contain a flexible array member.
- Structures that contain a flexible array member cannot be used as a member of another structure.
- The structure must contain at least one named member in addition to the flexible array member.

Although some of the code pieces should be still improved.
2020-09-01 17:57:50 +02:00
Zdenek Kabelac
19e9c88faf gcc: do not use return with void function
Follow C norm and do not use 'return' in void function to call other
functions.
2020-08-28 21:43:03 +02:00
Zdenek Kabelac
ee0cb17608 gcc: use apropriate type for reading and printing values 2020-08-28 21:43:03 +02:00
Zdenek Kabelac
88faf5a53b debug: drop some unneeded backtraces 2018-12-22 23:55:48 +01:00
Zdenek Kabelac
83c6f7e7e6 stats: initilize regions to NULL
Commit 3750b0cff5 used bad: error
path in more occasions thus it now needs regions defined as NULL.
2018-12-21 22:42:36 +01:00
Zdenek Kabelac
3750b0cff5 stats: fix error path when region is NULL
We should not call _stats_cleanup_region_ids() when regions
are NULL.
Also add backtracing for  goto.
2018-12-21 21:42:30 +01:00
Bryn M. Reeves
19f2105b87 libdm-stats: move no regions warning after dm_stats_list()
It doesn't make sense to test or warn about the region count until
the stats handle has been listed: at this point it may or may not
contain valid information (but is guaranteed to be correct after
the list).
2018-11-01 16:59:56 +00:00
Zdenek Kabelac
05b5774827 cov: shutdown warning
Since previous patch reverted coverity patch as this case is intentional,
provide override this coverity warning.
2018-10-16 21:55:19 +02:00
Zdenek Kabelac
6179cab877 revert "cov: dm stats missed terminating null"
This reverts commit 20971f7034
as the parsing of 'dmstatus' started to fail on present \0 char.
2018-10-16 21:34:23 +02:00
Zdenek Kabelac
20971f7034 cov: dm stats missed terminating null
Coverity noticed allocating insufficient memory
for the terminating null of the string.
2018-10-15 17:49:44 +02:00
Joe Thornber
7f97c7ea9a build: Don't generate symlinks in include/ dir
As we start refactoring the code to break dependencies (see doc/refactoring.txt),
I want us to use full paths in the includes (eg, #include "base/data-struct/list.h").
This makes it more obvious when we're breaking abstraction boundaries, eg, including a file in
metadata/ from base/
2018-05-14 10:30:20 +01:00
Zdenek Kabelac
043f58452a libdm-stats: fix error messages
When function dm_stats_populate() returns 0 it's an error and needs
log_error() message -  function can't have 'success' returning 0 or
error without reasons.
2018-03-15 10:56:31 +01:00
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
Zdenek Kabelac
f7e62bc55c cleanup: drop extra compare
dm_free() already validates for NULL itself.
2017-07-17 12:32:18 +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
Zdenek Kabelac
5ff6260071 coverity: move initilization of count variable
Make code more understandble for Coverity, so it sees connection
between 'extents' and 'count' and in fact code is more readable.
2017-06-27 12:16:33 +02:00
Bryn M. Reeves
744f2920db libdm: allow truncated files in dm_stats_update_regions_from_fd()
It's not an error to attempt to update regions from an fd that has
been truncated (or otherwise no longer has any allocated extents):
in this case, the call should remove all regions corresponding to
the group, and return an empty region table.
2017-06-13 19:45:50 +01:00
Bryn M. Reeves
febda60f3d libdm: use correct FMTu32 format specifier for uint32_t 2017-03-30 16:17:19 +01:00
Bryn M. Reeves
e8d5e05ff5 libdm: fix incorrect format specifier in _stats_resize_group()
The bitmap size in dm_bitset_t[0] is a uint32_t, not uint64_t: use
%u instead of FMTu64.
2017-03-30 10:31:36 +01:00
Bryn M. Reeves
c7e4b97abc libdm: use uint64_t where possible in filemap routines
Use uint64_t where possible and explicit casts elsewhere to avoid
compiler warnings when converting between int, int64_t and
uint64_t.
2017-03-30 10:02:54 +01:00
Bryn M. Reeves
b823646ace libdm: use size_t for buflen in _stats_group_file_regions() 2017-03-30 10:02:45 +01:00
Bryn M. Reeves
833b02106d libdm: make _stats_resize_group() num_regions argument uint64_t 2017-03-30 10:02:39 +01:00
Bryn M. Reeves
722542fabb libdm: make _find_extent() nr_extents argument uint64_t 2017-03-30 10:02:35 +01:00
Bryn M. Reeves
ac6089ee8d libdm: use DM_STATS_GROUP_* constants in dm_stats_create_regions_from_fd 2017-03-30 09:57:58 +01:00
Bryn M. Reeves
4b3d71212f libdm: use log_sys_error if dmfilemapd exec fails
Use log_sys_error rather than log_error if execvp() fails:

  /mnt/redhat/xdoio.13752.XIORQ: Created new group with 2 region(s) as group ID 0.
  # execvp() failed.

vs:

  /var/lib/libvirt/images/rhel7-vm1.qcow2: Created new group with 884 region(s) as group ID 0.
  dmfilemapd: execvp failed: No such file or directory
2017-03-29 21:38:15 +01:00
Bryn M. Reeves
6740eb1c2b libdm: do not attempt filemap cleanup if dm_stats_list() fails (coverity) 2017-03-29 18:34:43 +01:00
Bryn M. Reeves
f86c1f5d0a libdm: abort filemap update if pool allocation fails (coverity) 2017-03-29 18:34:38 +01:00
Bryn M. Reeves
bc5d67884f libdm: do not leak FIEMAP extent buffer if pool allocation fails (coverity) 2017-03-29 18:34:30 +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
Zdenek Kabelac
42b970d4f3 libdm: fix endless loop
Coverity noticed endless loop (i not being changed).

TODO: test coverage
2017-03-16 01:02:10 +01:00
Bryn M. Reeves
77a7ed065f dmfilemapd: ensure path argument is absolute
Require that the path argument to dmfilemapd be an absolute path
and document this in tool output, libdevmapper.h and dmfilemapd.8.

The check is also enforced by dm_stats_start_filemapd() to avoid
forking a new process with an invalid path argument.
2017-03-13 11:44:05 +00:00
Bryn M. Reeves
8c6b8e90e3 libdm: use correct value for NR_FILEMAPD_ARGS
The argument count for the file mapping daemon needs to account
for the program's name in argv[0] to avoid indexing off the end
of the argument array.
2017-03-10 16:52:27 +00:00
Bryn M. Reeves
d28a50ec76 libdm: make dm_stats_destroy(NULL) a no-op
Test for NULL in dm_stats_destroy() and return immediately if
the struct dm_stats pointer is NULL (similar to free(NULL)).

This simplifies cleanup code which otherwise needs to:

  out:
    if (dms)
        dm_stats_destroy(dms);
    return;
2017-03-10 16:41:28 +00:00
Bryn M. Reeves
93644be44b libdm: dm_stats_start_filemapd() mode can never be < 0 2017-03-10 14:42:23 +00:00
Bryn M. Reeves
146b2582b0 libdm: move initialisation of group_id in _aggregate_histogram()
Older compilers are not able to determine that although group_id
is only assigned in one branch of a conditional, it is never used
used when the other branch is taken:

  libdm-stats.c:3319: warning: "group_id" may be used uninitialized in this function

Avoid this by always initialising the variable when it is
declared.
2017-03-10 11:45:08 +00:00
Bryn M. Reeves
0104fd6c66 libdm: don't nest FIEMAP and DMFILEMAPD ifdefs 2017-03-09 21:20:27 +00:00
Bryn M. Reeves
8b78982297 daemons: add dmfilemapd
Add a daemon that can be launched to monitor a group of regions
corresponding to the extents of a file, and to update the regions as the
file's allocation changes.

The daemon is intended to be started from a library interface, but can
also be run from the command line:

  dmfilemapd <fd> <group_id> <path> <mode> [<foreground>[<log_level>]]

Where fd is a file descriptor open on the mapped file, group_id is the
group identifier of the mapped group and mode is either "inode" or
"path". E.g.:

  # dmfilemapd 3 0 vm.img inode 1 3 3<vm.img
  ...

If foreground is non-zero, the daemon will not fork to run in the
background. If verbose is non-zero, libdm and daemon log messages will
be printed.

It is possible for the group identifier to change when regions are
re-mapped: this occurs when the group leader is deleted (regroup=1 in
dm_stats_update_regions_from_fd()), and another region is created before
the daemon has a chance to recreate the leader region.

The operation is inherently racey since there is currently no way to
atomically move or resize a dm_stats region while retaining its
region_id.

Detect this condition and update the group_id value stored in the
filemap monitor.

A function is also provided in the the stats API to launch the filemap
monitoring daemon:

  int dm_stats_start_filemapd(int fd, uint64_t group_id, const char *path,
                              dm_filemapd_mode_t mode, unsigned foreground,
                              unsigned verbose);

This carries out the first fork and execs dmfilemapd with the arguments
specified.

A dm_filemapd_mode_t value is specified by the mode argument: either
DM_FILEMAPD_FOLLOW_INODE, or DM_FILEMAPD_FOLLOW_PATH. A helper function,
dm_filemapd_mode_from_string(), is provided to parse a string containing
a valid mode name into the appropriate dm_filemapd_mode_t value.
2017-03-09 18:50:15 +00:00
Bryn M. Reeves
c98868181f libdm: remove unnecessary backtrace in _stats_group_id_present()
It's not an error to call dm_stats_group_present() on a handle
that contains no regions.

This causes dmfilemap to log a false backtrace during shutdown
if all regions are removed from the corresponding device:

  exiting _filemap_monitor_get_events() with deleted=0, check=0
  waiting for FILEMAPD_WAIT
  dm message   (253:1) [ opencount flush ]  @stats_list dmstats [32768] (*1)
  <backtrace>
  Filemap group removed: exiting.

Change this to only emit a backtrace if the handle is NULL.
2017-03-09 17:53:15 +00:00
Zdenek Kabelac
3350eb67cc libdm: move code for _stats_resize_group
Code is only needed when "fiemap.h" so keep it under single #ifdef.
2017-02-14 10:24:56 +01:00
Zdenek Kabelac
a3579aafc5 cleanup: use matching signed number comparation 2017-02-13 10:06:19 +01:00
Zdenek Kabelac
7cbee8f31a cleanup: use matching const type 2017-02-13 10:06:18 +01:00
Zdenek Kabelac
717d0c6b94 cleanup: use proper printf specifier 2017-02-13 10:06:18 +01:00
Zdenek Kabelac
416f951283 coverity: fix double free
Do not try to free hist_arg twice.
2017-02-12 17:28:44 +01:00
Zdenek Kabelac
a7d2ee4bc2 coverity: fix mem leak on error path in dm stats
Free allocated resouces on error path.
2017-02-12 17:28:13 +01:00