Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3fee6610286f8373…
Commit: 3fee6610286f83737d193c9047e24e8d7c85d1ce
Parent: 0a48137d39c51163ee29608c8c7ccbeecb4a7815
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Oct 22 14:03:53 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Oct 22 14:22:40 2013 +0200
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.
---
WHATS_NEW | 1 +
scripts/lvm2_pvscan_systemd_red_hat@.service.in | 11 +++++++----
udev/Makefile.in | 4 +++-
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index df81923..2d7792b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -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.
diff --git a/scripts/lvm2_pvscan_systemd_red_hat@.service.in b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
index 9d91b5e..07ea5ca 100644
--- a/scripts/lvm2_pvscan_systemd_red_hat@.service.in
+++ b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
@@ -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
diff --git a/udev/Makefile.in b/udev/Makefile.in
index fdf43df..8f0dc8a 100644
--- a/udev/Makefile.in
+++ b/udev/Makefile.in
@@ -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(a)\$$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(a)\$$devnode.service\""
else
PVSCAN_RULE=RUN\+\=\"$(LVM_EXEC)/lvm pvscan --background --cache --activate ay --major \$$major --minor \$$minor\", ENV{LVM_SCANNED}=\"1\"
endif
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0a48137d39c51163…
Commit: 0a48137d39c51163ee29608c8c7ccbeecb4a7815
Parent: 65456a4a29d8f25ab75af2145b8a6b2a9ff391e5
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Oct 22 13:52:18 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Oct 22 13:52:18 2013 +0200
pvscan: use major:minor as short form of --major and --minor arg for pvscan --cache
Before, pvscan recognized either:
pvscan --cache --major <major> --minor <minor>
or
pvscan --cache <DevicePath>
When the device is gone and we need to notify lvmetad about device
removal, only --major/--minor works as we can't translate DevicePath
into major/minor pair anymore. The device does not exist in the system
and we don't keep DevicePath index in lvmetad cache to make the
translation internally into original major/minor pair. It would be
useless to keep this index just for this one exact case.
There's nothing bad about using "--major <major> --minor <minor>",
but it makes our life a bit harder when trying to make an
interconnection with systemd units, mainly with instantiated services
where only one and only one arg can be passed (which is encoded in the
service name).
This patch tries to make this easier by adding support for recognizing
the "<major>:<minor>" as a shortcut for the longer form
"--major <major> --minor <minor>". The rule here is simple: if the argument
starts with "/", it's a DevicePath, otherwise it's a <major>:<minor> pair.
---
WHATS_NEW | 1 +
man/pvscan.8.in | 4 ++-
tools/pvscan.c | 61 +++++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 61aeb72..df81923 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104
===================================
+ 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.
Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
diff --git a/man/pvscan.8.in b/man/pvscan.8.in
index 211c82b..37ecaaf 100644
--- a/man/pvscan.8.in
+++ b/man/pvscan.8.in
@@ -25,7 +25,9 @@ pvscan \- scan all disks for physical volumes
.B \-\-minor
.I minor
|
-.IR DevicePath ]...
+.IR DevicePath
+|
+.IR major:minor ]...
.SH DESCRIPTION
pvscan scans all supported LVM block devices in the system for
physical volumes.
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 3f16b05..b6a07bd 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -132,6 +132,27 @@ out:
return r;
}
+static int _clear_dev_from_lvmetad_cache(dev_t devno, int32_t major, int32_t minor,
+ activation_handler handler)
+{
+ char *buf;
+
+ if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor))
+ stack;
+ if (!lvmetad_pv_gone(devno, buf ? : "", handler)) {
+ if (buf)
+ dm_free(buf);
+ return 0;
+ }
+
+ log_print_unless_silent("Device %s not found. "
+ "Cleared from lvmetad cache.", buf ? : "");
+ if (buf)
+ dm_free(buf);
+
+ return 1;
+}
+
static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
{
int ret = ECMD_PROCESSED;
@@ -142,7 +163,6 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
int devno_args = 0;
struct arg_value_group_list *current_group;
dev_t devno;
- char *buf;
activation_handler handler = NULL;
/*
@@ -193,11 +213,30 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
/* Process any command line PVs first. */
while (argc--) {
pv_name = *argv++;
- dev = dev_cache_get(pv_name, cmd->lvmetad_filter);
- if (!dev) {
- log_error("Physical Volume %s not found.", pv_name);
- ret = ECMD_FAILED;
- continue;
+ if (pv_name[0] == '/') {
+ /* device path */
+ if (!(dev = dev_cache_get(pv_name, cmd->lvmetad_filter))) {
+ log_error("Physical Volume %s not found.", pv_name);
+ ret = ECMD_FAILED;
+ continue;
+ }
+ }
+ else {
+ /* device major:minor */
+ if (sscanf(pv_name, "%d:%d", &major, &minor) != 2) {
+ log_error("Failed to parse major:minor from %s", pv_name);
+ ret = ECMD_FAILED;
+ continue;
+ }
+ devno = MKDEV((dev_t)major, minor);
+ if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
+ if (!(_clear_dev_from_lvmetad_cache(devno, major, minor, handler))) {
+ stack;
+ ret = ECMD_FAILED;
+ break;
+ }
+ continue;
+ }
}
if (sigint_caught()) {
ret = ECMD_FAILED;
@@ -225,19 +264,11 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
devno = MKDEV((dev_t)major, minor);
if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
- if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor))
+ if (!(_clear_dev_from_lvmetad_cache(devno, major, minor, handler))) {
stack;
- if (!lvmetad_pv_gone(devno, buf ? : "", handler)) {
ret = ECMD_FAILED;
- if (buf)
- dm_free(buf);
break;
}
-
- log_print_unless_silent("Device %s not found. "
- "Cleared from lvmetad cache.", buf ? : "");
- if (buf)
- dm_free(buf);
continue;
}
if (sigint_caught()) {
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=65456a4a29d8f25a…
Commit: 65456a4a29d8f25ab75af2145b8a6b2a9ff391e5
Parent: 7763607f3617188906dae9e9ae218e9099f5e6e9
Author: Mike Snitzer <snitzer(a)redhat.com>
AuthorDate: Mon Oct 21 18:04:14 2013 -0400
Committer: Mike Snitzer <snitzer(a)redhat.com>
CommitterDate: Mon Oct 21 18:04:14 2013 -0400
vgimportclone: remove 2>/dev/null from three lvm commands
There is no point eating stderr for these commands. In fact the
redirect causes confusion and hurts dubugging.
Also reword an error message if the pvs command fails so as not be
certain that a device is not a PV. Coupled with removing the stderr
redirect this will improve the user experience in the face of errors.
---
WHATS_NEW | 1 +
scripts/vgimportclone.sh | 8 ++++----
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 96e6775..61aeb72 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104
===================================
+ Remove 2>/dev/null from three lvm commands executed by vgimportclone.
Add configure --enable-udev-systemd-background-jobs.
Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
Fix lvconvert swap of poolmetadata volume for active thin pool.
diff --git a/scripts/vgimportclone.sh b/scripts/vgimportclone.sh
index d6ad75d..7087557 100755
--- a/scripts/vgimportclone.sh
+++ b/scripts/vgimportclone.sh
@@ -204,8 +204,8 @@ for ARG
do
if [ -b "$ARG" ]
then
- PVS_OUT=`"${LVM}" pvs ${LVM_OPTS} --noheadings -o vg_name "$ARG" 2>/dev/null`
- checkvalue $? "$ARG is not a PV."
+ PVS_OUT=`"${LVM}" pvs ${LVM_OPTS} --noheadings -o vg_name "$ARG"`
+ checkvalue $? "$ARG could not be verified to be a PV without errors."
PV_VGNAME=$(echo $PVS_OUT | $GREP -v '[[:space:]]+$')
[ -z "$PV_VGNAME" ] && die 3 "$ARG is not in a VG."
@@ -227,7 +227,7 @@ fi
### Get the existing state so we can use it later
#####################################################################
-OLDVGS=`"${LVM}" vgs ${LVM_OPTS} -o name --noheadings 2>/dev/null`
+OLDVGS=`"${LVM}" vgs ${LVM_OPTS} -o name --noheadings`
checkvalue $? "Current VG names could not be collected without errors"
#####################################################################
@@ -280,7 +280,7 @@ export LVM_SYSTEM_DIR=${TMP_LVM_SYSTEM_DIR}
### Rename the VG(s) and change the VG and PV UUIDs.
#####################################################################
-PVINFO=`"${LVM}" pvs ${LVM_OPTS} -o pv_name,vg_name,vg_attr --noheadings --separator : 2>/dev/null`
+PVINFO=`"${LVM}" pvs ${LVM_OPTS} -o pv_name,vg_name,vg_attr --noheadings --separator :`
checkvalue $? "PV info could not be collected without errors"
# output VG info so each line looks like: name:exported?:disk1,disk2,...
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9f406ce252c40a29…
Commit: 9f406ce252c40a29c06dba4bebe92b570207df93
Parent: 7f4452a41e55a60678cadda99ae1a383a367a9e5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 17 22:54:12 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 22:54:12 2013 +0200
tests: drop settle for old systems
Reverts previously added udevsettle call.
Seems to be unrelated, while udev on old system may take over 10
minutes, to finish it's very slow and CPU intensive work, it doesn't
interact directly with created device, only access /dev/mapper/control
node via dmsetup, so the device is ocasionaly blocked by something else.
---
test/lib/utils.sh | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/test/lib/utils.sh b/test/lib/utils.sh
index c3bd533..0f58b25 100644
--- a/test/lib/utils.sh
+++ b/test/lib/utils.sh
@@ -214,5 +214,3 @@ case "$PATH" in
esac
test -z "$PREFIX" || prepare_test_vars
-
-test ! -e /sbin/udevsettle || if pidof udevd >/dev/null; then /sbin/udevsettle ; fi
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d9e44112c53cad29…
Commit: d9e44112c53cad296858f5f796add99441a4b2ae
Parent: 66f4698a93c6cc7d0fb027c5e4209b1de6a880ef
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 17 16:59:30 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 16:59:30 2013 +0200
tests: fix last commit
It must not fail here during execution, so always check in a way
that '||' is used for call of settle.
---
test/lib/utils.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/utils.sh b/test/lib/utils.sh
index 8311c4c..c3bd533 100644
--- a/test/lib/utils.sh
+++ b/test/lib/utils.sh
@@ -215,4 +215,4 @@ esac
test -z "$PREFIX" || prepare_test_vars
-test -e /sbin/udevsettle && pidof udevd >/dev/null && /sbin/udevsettle
+test ! -e /sbin/udevsettle || if pidof udevd >/dev/null; then /sbin/udevsettle ; fi
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=66f4698a93c6cc7d…
Commit: 66f4698a93c6cc7d0fb027c5e4209b1de6a880ef
Parent: 93a07a1b841628bb4c8caaa7f0470fc77f656ff2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 17 16:19:06 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 16:19:06 2013 +0200
tests: workaround udevd compromising tests
Patch helps a bit when lvm2 is build with disabled udev_sync support,
but udevd runs in the system - so it randomly influences unrelated tests
even - so before every test wait at least till udevd is settled.
---
test/lib/utils.sh | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/test/lib/utils.sh b/test/lib/utils.sh
index 0f58b25..8311c4c 100644
--- a/test/lib/utils.sh
+++ b/test/lib/utils.sh
@@ -214,3 +214,5 @@ case "$PATH" in
esac
test -z "$PREFIX" || prepare_test_vars
+
+test -e /sbin/udevsettle && pidof udevd >/dev/null && /sbin/udevsettle