systemd/rules.d
Martin Wilck c072860593 99-systemd.rules: rework SYSTEMD_READY logic for device mapper
Device mapper devices are set up in multiple steps. The first step, which
generates the initial "add" event, only creates an empty container, which is
useless for higher layers. SYSTEMD_READY should be set to 0 on this event to
avoid premature device activation.

The event that matters is the "activation" event: the first "change" event on
which DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 is not set. When this event arrives,
the device is ready for being scanned by blkid and similar tools, and for being
activated by systemd.

Intermittent events with DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 should be ignored
as far as systemd or higher-level block layers are concerned. Previous device
properties and symlinks should be preserved: the device shouldn't be scanned or
activated, but shouldn't be deactivated, either.  In particular, SYSTEM_READY
shouldn't be set to 0 if it wasn't set before, because that might cause mounted
file systems to be unmounted. Such intermittent events may occur any time,
before or after the "activation" event.

DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 can have multiple reasons. One possible reason
is that the device is suspended. There are other reasons that depend on the
device-mapper subsystem (LVM, multipath, dm-crypt, etc.).

The current systemd rule set

1) sets SYSTEMD_READY=0 if DM_UDEV_DISABLE_OTHER_RULES_FLAG is set in "add"
events;
2) imports SYSTEMD_READY from the udev db if DM_SUSPENDED is set, and jumps to systemd_end;
3) sets SYSTEMD_READY=1, otherwise.

This logic has several flaws:

* 1) can cause file systems to be unmounted if an coldplug event arrives while
a file system is suspended. This rule shouldn't be applied for coldplug events
or in general, "synthetic" add events;
* 2) evaluates DM_SUSPENDED=1, which is a device-mapper internal property.
It's wrong to infer that a device is accessible if DM_SUSPENDED=0.
The jump to systemd_end may cause properties and/or symlinks to be lost;
* 3) is superfluous, because SYSTEMD_READY=1 is equivalent with SYSTEMD_READY
being unset, and can create the wrong impression that the device was explicitly
activated.

This patch fixes the logic as follows:

- apply 1) only if DM_NAME is empty, which is only the case for the first
"genuine add" event;
- change 2) to use DM_UDEV_DISABLE_OTHER_RULES_FLAG instead of DM_SUSPENDED,
and remove the GOTO directive;
- remove 3).

Fixes: b7cf1b6 ("udev: use SYSTEMD_READY to mask uninitialized DM devices")
Fixes: 35a6750 ("rules: set SYSTEMD_READY=0 on DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 only with ADD event (#2747)")

Signed-off-by: Martin Wilck <mwilck@suse.com>
2024-04-03 12:48:14 +01:00
..
50-udev-default.rules.in udev: add hwdb execution for hidraw subsystem devices 2023-12-25 02:16:44 +09:00
60-autosuspend.rules Add support to set autosuspend delay via hwdb 2022-05-09 21:14:12 -05:00
60-block.rules
60-cdrom_id.rules
60-dmi-id.rules rules: split out DMI related rules from udev-default.rules 2023-06-20 14:44:36 +02:00
60-drm.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
60-evdev.rules rules: add missing line continuation 2022-12-21 09:52:07 +01:00
60-fido-id.rules
60-infiniband.rules udev/rules: add by-path and by-ibdev links to infiniband verbs 2022-10-14 12:18:08 +09:00
60-input-id.rules
60-persistent-alsa.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
60-persistent-input.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
60-persistent-media-controller.rules udev: Add /dev/media/by-path symlinks for media controllers 2024-02-22 19:27:29 +00:00
60-persistent-storage-mtd.rules rules: add mtd/by-name symlinks 2023-10-17 11:43:30 +02:00
60-persistent-storage-tape.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
60-persistent-storage.rules.in udev: even if a device is a zac device, scsi-$ID_SERIAL will be reserved for it (#30459) 2024-01-16 14:57:07 +09:00
60-persistent-v4l.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
60-sensor.rules udev: hwdb: Add rules to match cros-ec-accel by 'location' sysfs file 2022-08-18 21:17:19 +03:00
60-serial.rules udev: add USB revision in ID_PATH 2023-05-20 14:27:10 +09:00
64-btrfs.rules.in Drop split-usr and unmerged-usr support 2023-07-28 19:34:03 +01:00
70-camera.rules rules: remove stray whitespace before comma between tokens 2023-03-27 10:00:30 +00:00
70-joystick.rules
70-memory.rules
70-mouse.rules
70-power-switch.rules meson: move udev rules to rules.d/ 2022-05-05 11:51:44 +02:00
70-touchpad.rules
70-uaccess.rules.in hwdb: Allow users access to USB serial for analysers 2022-08-09 18:12:19 +02:00
71-seat.rules.in Drop split-usr and unmerged-usr support 2023-07-28 19:34:03 +01:00
73-seat-late.rules.in meson: move udev rules to rules.d/ 2022-05-05 11:51:44 +02:00
75-net-description.rules udev: allow/denylist for reading sysfs attributes when composing a NIC name 2023-12-19 19:15:52 +09:00
75-probe_mtd.rules
78-sound-card.rules
80-drivers.rules udev-builtin-kmod: support to run without arguments 2022-10-14 21:32:24 +09:00
80-net-setup-link.rules
81-net-dhcp.rules
82-net-auto-link-local.rules hwdb,rules: mark host-to-host network devices as only requiring link local addressing 2023-10-30 18:57:41 +01:00
90-iocost.rules udev/iocost: invert DEVTYPE match 2023-04-26 14:50:25 +09:00
90-vconsole.rules.in rules: start systemd-vconsole-setup via unit 2023-05-19 17:46:47 +02:00
99-systemd.rules.in 99-systemd.rules: rework SYSTEMD_READY logic for device mapper 2024-04-03 12:48:14 +01:00
meson.build rules: add mtd/by-name symlinks 2023-10-17 11:43:30 +02:00
README docs: Fixing typo in systemd.device man page and README. 2021-09-29 22:18:38 +01:00

Files in this directory contain configuration for systemd-udevd.service, a
daemon that manages symlinks to device nodes, permissions of devices nodes,
emits device events for userspace, and renames network interfaces.

See man:udev(7) for an overview of the configuration file format, and
man:systemd-udevd.service(8) for a description of service itself.

Use 'systemd-analyze cat-config udev/rules.d' to display the effective config.