Certain udev rules for block devices are problematic for osbuild.
One prominent example is LVM2 related rules that would trigger
a scan and auto-activation of logical volumes. This rules are
triggered for new block devices or when the backing file of an
loop devices changes. The rules will lead to a `lvm pvscan
--cache --activate ay` via the `lvm2-pvscan@.service` systemd
service. This will auto-activate all LVM2 logical volumes and
thus interfering with our own device handling in `devices/
org.osbuild.lvm2.lv`, where we only want to activate a single
logical volume.
Also, if the lvm2 devices get activated after the manual metadata
change done in `org.osbuild.lvm2.metadata` the volume group names
might conflict which results in all lvm2 based tooling to be very,
ver sad and also said stage to hang since the loopback device can
not be detached since the activate logical volumes keep it open.
To work-around this we therefore implement a udev rule inhibition
mechanism: on the osbuild side a lock file is created via the new
class called `UdevInhibitor` in `utils/udev.py`. A custom set of
udev rules in `10-osbuild-inhibitor.rules` is then acting on the
existence of that lock file and if present will opt-out of certain
further processing. See the udev rules file for more details.
In fact, we want this custom inhibition mechanism, for all block
devices that are under osbuild's control, since these rules are
there to provide automatisms and integrations with the host,
something we never want.
NB: this should not affect the detection of devices, since lvm2
does do a scan of devices when we call `lvdisplay` in `lvm2.lv`.
The call chain as of lvm2 git rev f773040:
_lvdisplay_single [tools/lvdisplay.c
process_each_lv [tools/toollib.c
lvmcache_label_scan [lib/cache/lvmcache.c
label_scan [ibidem, here is the device detection!
lvdisplay_full [lib/display/display.c
39 lines
1.8 KiB
Text
39 lines
1.8 KiB
Text
# This file is part of osbuild
|
|
#
|
|
# A set of rules that implements an inhibition mechanism that allows
|
|
# osbuild to suppress the execution of certain udev rules for block
|
|
# devices that are known to cause problems for its use case.
|
|
#
|
|
# osbuild indicates that it wants to inhibit a device by creating a
|
|
# lock file in a special lock folder which is then in turn detected
|
|
# by this set of rules. As a result various environment variables
|
|
# are set that should inhibit the other udev rules.
|
|
#
|
|
# A udev property called 'OSBUILD_INHIBIT' will be set for devices
|
|
# that are inhibited via this set of rules.
|
|
|
|
SUBSYSTEM!="block", GOTO="osbuild_end"
|
|
ACTION=="remove", GOTO="osbuild_end"
|
|
|
|
# Support locking via device major and minor numbers
|
|
TEST=="/run/osbuild/locks/udev/device-$major:$minor", ENV{OSBUILD_INHIBIT}="1"
|
|
|
|
# Support locking via the "device mapper" device name
|
|
ENV{DM_NAME}=="?*", TEST=="/run/osbuild/locks/udev/dm-$env{DM_NAME}", ENV{OSBUILD_INHIBIT}="1"
|
|
|
|
# Setting `DM_UDEV_DISABLE_OTHER_RULES_FLAG` should prevent the processing
|
|
# of the device by device mapper related rules; specifically it should
|
|
# prevent lvm2 from scanning the device and activating its volume groups
|
|
# and logival volumes.
|
|
# On Fedora/RHEL these rules are in '69-dm-lvm-metad.rules'
|
|
ENV{OSBUILD_INHIBIT}=="1", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
|
|
|
|
# Setting `UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG` should opt-out of
|
|
# the creation of various links in udev that are useful for host devices
|
|
# but are not needed by osbuild and might even conflict if multiple
|
|
# concurrent builds are ongoing which use the same device labels, like
|
|
# like "disk/by-label".
|
|
# On Fedora/RHEL these rules are in '60-persistent-storage.rules'
|
|
ENV{OSBUILD_INHIBIT}=="1", ENV{UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG}="1"
|
|
|
|
LABEL="osbuild_end"
|