Fix cutting away 1 character via incorrect usage of dm_strncpy
introduced in last batch of commits and use sizeof(buffer) to
get proper sizes.
In case of use strcpy_name_len() the replacement was invalid,
so we need to restore this case since sanlock uses buffer without
nul ending, so we would strip one more character from the buffer.
Also start to use dm_strncpy() without (void) for unchecked usage.
Add internal inline function wrapper for dm_strncpy().
Use it for calls where we test the result.
Avoids emitting warnings in Coverity for unchecked usage.
Zdenek Kabelac [Thu, 28 Mar 2024 21:43:16 +0000 (22:43 +0100)]
cov: remove unnecessary sanity check
This sanity check actually confused in some way Coverity
giving it some assumption about array access.
Since these two checks basically validated compiler's capability
to add and then substract the number from char pointer we likely
don't really need them - as if this base math would not work,
compiler would be having far more troubles...
So drop them - and get rid of report:
Event overrun-call: Overrunning callee's array of size 513 by...
Tony Asleson [Wed, 27 Mar 2024 17:26:19 +0000 (12:26 -0500)]
tests: lvmdbusest.py faster test_z_sigint
Reduce #lv and intervals.
We are trying to ensure that the daemon stops while it's busy processing
its internal queues. Decrease the number of LVs and intervals to allow
this test to complete in less time.
Tony Asleson [Wed, 27 Mar 2024 16:49:05 +0000 (11:49 -0500)]
lvmdbusd: Exit faster
Add a global timeout value to be used for the threads to end waiting for
whatever it is they are blocked on. The values varied from 2-5 seconds,
which is way longer than needed. Value of 0.5 shows no CPU load when
service is running and is idle.
Zdenek Kabelac [Tue, 26 Mar 2024 23:28:14 +0000 (00:28 +0100)]
device_id: use dm_basename
Avoid problems for other libc like muslc and use dm_basename.
Prototype for basename has been removed from string.h from latest musl [1]
compilers e.g. clang-18 flags the absense of prototype as error. therefore
include libgen.h for providing it.
Zdenek Kabelac [Mon, 25 Mar 2024 18:20:55 +0000 (19:20 +0100)]
dmsetup: refactor getopt_long usage
Shuffle code to avoid using static variable to pass parsed option.
Code is now easier to follow and also number of coverity reports
will go away.
There should be no functional change.
Zdenek Kabelac [Mon, 25 Mar 2024 12:17:42 +0000 (13:17 +0100)]
devices_id: add some syscall checks
Add debug tracing for syscall failures.
Also switch some log_error to log_warn when command does not exit
with 'error' result and only warns user.
Easier error path handling.
Initialize some vars at declaration time.
Zdenek Kabelac [Sat, 23 Mar 2024 23:06:32 +0000 (00:06 +0100)]
tests: update extend of raid
Here we actually need to slowdown only $dev2 - since repair operation
is only reading data from this device and compares it with origin $dev1,
and if they match there is no write...
Zdenek Kabelac [Sat, 23 Mar 2024 23:06:45 +0000 (00:06 +0100)]
commands: use nul for EOL for compiled-in buffer
Use \0 as EOL in compiled-in syntax description to avoid
unnecessary line copy that just replaced \n with \0.
Also use already splitted lines when possible.
Zdenek Kabelac [Sun, 24 Mar 2024 21:42:16 +0000 (22:42 +0100)]
raid: update dm_get_status_raid
Handle mismatch of reported 'dm raid' status, where the active
raid LV can be actually showing higher numebr of raid leg devices,
that the number of shown status characters.
This can happen if the raid leg is dropped during initial
resynchronization.
Peter Rajnoha [Mon, 25 Mar 2024 09:16:04 +0000 (10:16 +0100)]
udev: create /dev/disk/by-label symlinks for DM devs that have crypto as next layer
We already create /dev/disk/by-uuid symlinks for DM devices which
contain crypto-type as next layer (as identified by blkid).
Also create /dev/disk/by-label symlinks as the labels can be
defined for crypto-type devices too.
Reported and fix suggested by: Patrick Plenefisch <simonpatp@gmail.com>
See also:
https://lore.kernel.org/lvm-devel/CAOCpoWfYjOVNJNt+cnOVXDHiDq2wRogTqBijcUoa7chqOLRa5Q@mail.gmail.com/
Daan De Meyer [Wed, 29 Nov 2023 08:09:57 +0000 (09:09 +0100)]
Upstream db_persist udev rule from dracut
Setting db_persist is required for dm devices so that their properties
are carried over on switch-root from the initrd to the rootfs. This
logic has always lived in dracut
(https://github.com/dracutdevs/dracut/blob/master/modules.d/90dm/11-dm.rules).
However, this means that other initramfs generators each have to
implement and maintain the same rule which leads to unnecessary
duplication.
Instead, let's make the rule part of the upstream lvm rules, which
will ensure that generated initramfses will just work if they make
sure the lvm udev rules are installed, without having to figure out
that they have to add an extra rule themselves on top.
Identical rule in Arch Linux's lvm2 package: https://gitlab.archlinux.org/archlinux/packaging/packages/lvm2/-/blob/main/11-dm-initramfs.rules?ref_type=heads
Peter Rajnoha [Thu, 7 Mar 2024 08:48:49 +0000 (09:48 +0100)]
udev: change action check from ACTION!="add|change" to ACTION=="remove"
For DM devices, the add/change/remove can appear as action for genuine
udev events.
However, there are more action types (bind, unbind, move, online, offline)
which never appear as actions for genuine DM udev events, but they can
still be synthesized (e.g. by writing "<action>" to "/sys/.../uevent" file
or by calling "udevadm trigger --action=<action>").
Let's also process these extra action types so that the udev-related content
is not lost completely, keeping all the symlinks and udev db entries just like
this was a synthetic udev event with "change" action.
Related to https://gitlab.com/lvmteam/lvm2/-/issues/4.
Martin Wilck [Fri, 1 Mar 2024 14:26:59 +0000 (15:26 +0100)]
10-dm.rules: bump DM_UDEV_RULES_VSN to 3
Bump the rules version in order to indicate that upper level rules
should consume DM_UDEV_DISABLE_OTHER_RULES_FLAG rather than DM_NOSCAN
and DM_SUSPENDED.
Also update the comments at the top of the file that describe the
exported properties, and add a note about internal device-mapper
properties.
Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Peter Rajnoha <prajnoha@redhat.com>
Martin Wilck [Fri, 1 Mar 2024 14:16:33 +0000 (15:16 +0100)]
dm udev rules: don't export and save DM_SUSPENDED
DM_SUSPENDED is a device-mapper internal flag, which is not intended to be
used by other rules, and which is determined by 10-dm.rules from sysfs for
every uevent. Rename it to ".DM_SUSPENDED", so that it won't be saved in the
udev database.
Known consumers of DM_SUSPENDED are 66-kpartx.rules (from multipath-tools) and
99-systemd.rules (from systemd). These will have to be adapted.
11-dm-mpath.rules will be changed to use .DM_SUSPENDED.
Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Peter Rajnoha <prajnoha@redhat.com>
Martin Wilck [Fri, 1 Mar 2024 13:45:32 +0000 (14:45 +0100)]
11-dm-lvm.rules: don't restore DM_UDEV_DISABLE_OTHER_RULES_FLAG from db
DM_UDEV_DISABLE_OTHER_RULES_FLAG is used as the "output" flag of the
device-mapper rules, to be consumed by non-dm rules. It is a logical OR of
several conditions that might make dm devices inaccessible. 10-dm.rules
calculates it for every uevent, whether it's genuine or spurious.
DM_SUBSYSTEM_UDEV_FLAG0 is just another flag that needs to be or'd in. We
don't need to restore the previous state of DM_UDEV_DISABLE_OTHER_RULES_FLAG.
Actually, doing so is wrong if the flag has previously been set because the
device was suspended, and the device isn't suspended anymore.
Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Peter Rajnoha <prajnoha@redhat.com>
Martin Wilck [Fri, 1 Mar 2024 11:43:36 +0000 (12:43 +0100)]
10-dm-rules: don't restore DM_UDEV_DISABLE_OTHER_RULES_FLAG from db
We use DM_UDEV_DISABLE_OTHER_RULES_FLAG to tell upper non-DM layers
to keep their hands off the device in question, for any reason.
One possible reason is that the device is supended; another is that
the cookie carries the flag of the same name.
DM_SUSPENDED is not restored from the db, but evaluated anew for every
uevent. Therefore DM_UDEV_DISABLE_OTHER_RULES_FLAG shouldn't be
restored, either. Use a new variable DM_COOKIE_DISABLE_OTHER_RULES_FLAG
to save and restore the original value from the cookie.
Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Peter Rajnoha <prajnoha@redhat.com>
Martin Wilck [Tue, 5 Mar 2024 11:22:40 +0000 (12:22 +0100)]
10-dm.rules: test DISK_RO after importing properties
DISK_RO is set in the environment of a block-device uevent if and only if
the read-only (ro) attribute of the device just changed (the kernel
function set_disk_ro() was called). It is not synoymous with the "ro" sysfs
attribute; the device could very well be write-protected if DISK_RO is not
set. Device mapper-level probing is possible for DISK_RO events, but it makes
little sense, because the device propreties haven't changed as far as dm is
concerned. But we should import possible previously set device properties
to avoid confusing follow-up rules. We should do this for both DISK_RO=1
and DISK_RO=0 events.
Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Peter Rajnoha <prajnoha@redhat.com>
Zdenek Kabelac [Thu, 21 Mar 2024 20:03:44 +0000 (21:03 +0100)]
dev_manager: fix table for cache with cachevol
When using cached LV with cachevols (so not with cachepool),
the loaded table could have been using more then one mapping line
for sub devices - resulting into data corruption in some cases
when i.e. taking snapshot of such cached LV with and instead of
single line - 2 lines were generated into DM table as the code
skipped protection again repeated addition.
vg-fast_cvol-cdata: 0 16384 linear 253:2 16384
vg-fast_cvol-cdata: 16384 16384 linear 253:2 16384
New code is also refactoring to use _add_new_cvol_subdev_to_dtree
(similar _add_cvol_subdev.. ) and also the addition of subdev has
been moved after check for already processed node.
Also the cachevol sub devices are now added with the insertion
of cachevol with cached LV.
Zdenek Kabelac [Tue, 27 Feb 2024 16:16:55 +0000 (17:16 +0100)]
man: lvmthin update for external origin usage
Document usage of chaining external origins as it is now possibly to
create thinA LV in poolA which use thinB LV in poolB as it external
origin and user could create chain of such LV.