1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 01:55:10 +03:00

udev+systemd: refine lvm2-pvscan@.service to better track device existence

When using ENV{SYSTEMD_WANTS}=lvm2-pvscan@... to instantiate a service
for lvmetad scan when the new PV appears in the system, the service
is started and executed. However, to track device removal, we need
to bind it (the "BindsTo" systemd directive) to a certain .device
systemd unit.

In default systemd setup, the device is tracked by it's name and
sysfs path (there's normally a sysfs path .device systemd unit for
a device and then the device name .device unit as an alias for it).
Neither of these two is useful for lvmetad update as we need to bind
it to device's <major>:<minor> pair.

The /dev/block/<major>:<minor> is the essential symlink under /dev
that exists for each block device (created by default udev rules
provided by udev directly). So let's use this as an alias for
the device's .device unit as well by means of "ENV{SYSTEMD_ALIAS}"
declaration within udev rules which systemd understands (this will
create a new alias "dev-block-<major>:<minor>.device".

Then we can easily bind the "dev-block-<major>:<minor>" device
systemd unit with instantiated lvm2-pvscan@<major>:<minor>.service.
So once the device is removed from the systemd, the
lvm-pvscan@<major>:<minor>.service executes it's ExecStop action
(which in turn notifies lvmetad about the device being gone).

This completes the udev-systemd-lvmetad interaction then.
This commit is contained in:
Peter Rajnoha 2013-10-22 14:03:53 +02:00
parent 0a48137d39
commit 3fee661028
3 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.104
===================================
Add dev-block-<major>:<minor>.device systemd alias for complete PV tracking.
Use major:minor as short form of --major and --minor arg for pvscan --cache.
Remove 2>/dev/null from three lvm commands executed by vgimportclone.
Add configure --enable-udev-systemd-background-jobs.

View File

@ -1,11 +1,14 @@
[Unit]
Description=LVM2 PV scan on %I
Description=LVM2 PV scan on device %i
Documentation=man:pvscan(8)
DefaultDependencies=no
After=lvm2-lvmetad.socket %i.device
BindsTo=dev-block-%i.device
After=lvm2-lvmetad.socket
Before=shutdown.target
Conflicts=shutdown.target
[Service]
Type=simple
ExecStart=@sbindir@/pvscan --cache --activate ay %I
Type=oneshot
RemainAfterExit=yes
ExecStart=@sbindir@/pvscan --cache --activate ay /dev/block/%i
ExecStop=/usr/sbin/pvscan --cache %i

View File

@ -47,7 +47,9 @@ BLKID_RULE=IMPORT{program}=\"${SBIN}\/blkid -o udev -p \$$tempnode\"
endif
ifeq ("@UDEV_SYSTEMD_BACKGROUND_JOBS@", "yes")
PVSCAN_RULE=ENV{SYSTEMD_WANTS}=\"lvm2-pvscan@\$$devnode.service\"
PVSCAN_RULE="ENV{SYSTEMD_ALIAS}=\"/dev/block/$$major:$$minor\" \
ENV{ID_MODEL}=\"LVM PV $$env{ID_FS_UUID_ENC} on /dev/$$name\" \
ENV{SYSTEMD_WANTS}=\"lvm2-pvscan@\$$devnode.service\""
else
PVSCAN_RULE=RUN\+\=\"$(LVM_EXEC)/lvm pvscan --background --cache --activate ay --major \$$major --minor \$$minor\", ENV{LVM_SCANNED}=\"1\"
endif