debian-forge/osbuild/util
Christian Kellner 7e2bb524a4 devices: add custom udev rule inhibitor mechanism
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
2021-12-09 00:44:21 +00:00
..
__init__.py util: mark as module 2020-04-21 17:00:04 +02:00
checksum.py util: add new checksum related utilities 2021-05-12 14:26:16 +02:00
ctx.py util/ctx: extract suppress_oserror() 2020-05-11 18:05:12 +02:00
jsoncomm.py util/jsoncomm: add send_and_recv helper 2021-06-09 18:37:47 +01:00
linux.py util/linux: add helper for BLK_IOC_FLSBUF ioctl 2021-08-13 17:35:32 +02:00
lorax.py utils/lorax: add lorax template related helpers 2021-02-19 14:42:32 +00:00
lvm2.py utils: add lvm2 utility module 2021-08-13 12:20:54 +02:00
osrelease.py util/osrelease: add default os-release paths 2020-10-21 11:13:28 +02:00
ostree.py stages: add org.osbuild.ostree.passwd 2021-08-17 13:53:00 +02:00
path.py util/path: add path checker helper function 2021-06-28 19:07:42 +02:00
rhsm.py util/rhsm: Check if repositories is None before iterating 2021-09-03 20:52:17 +02:00
rmrf.py util/rmrf: handle broken symlinks 2021-12-02 11:38:30 +01:00
selinux.py util/selinux: add gefilecon helper 2020-06-15 20:36:48 +02:00
types.py util: add types module defining PathLike type 2020-07-27 12:50:38 +01:00
udev.py devices: add custom udev rule inhibitor mechanism 2021-12-09 00:44:21 +00:00