From e7d7111f13ad60703a652e83be094d1565360a54 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 15 Jul 2016 16:15:41 +0000 Subject: [PATCH 1/3] udev-block-add-change: better mount status check The canonical device name is not necessarily used in /proc/mounts or /proc/self/mountinfo, see /dev/dm-0 vs. /dev/mapper/dmroot. (And only checking by major:minor is not possible in the case of btrfs.) Also fixes another bug where e.g. dm-10 would match when really only dm-1 was mounted, or when the mountpoint path included the device name, etc. Also catches enabled swap. --- udev/udev-block-add-change | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index b9f970b..e0eaadd 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -20,8 +20,8 @@ xs_remove() { is_used() { local sys_devpath=$1 - # mounted - if fgrep -q $(basename $sys_devpath) /proc/mounts; then + # mounted; or enabled swap + if lsblk -dnr -o MOUNTPOINT "$DEVNAME" | grep -q .; then return 0 fi # part of other device-mapper From 6b32378158e7606869ff4d38fc622704373bbdf1 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 15 Jul 2016 16:15:41 +0000 Subject: [PATCH 2/3] udev-block-add-change: don't exclude already attached devs For example, attaching a device-mapper device to another VM increases its "dmsetup info" open count in is_used(), which triggered its removal from qvm-block. --- udev/udev-block-add-change | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index e0eaadd..27ccef4 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -11,6 +11,10 @@ MODE=w QDB_KEY="/qubes-block-devices/$NAME" xs_remove() { + if is_attached /sys$DEVPATH; then + return 0 + fi + if [ "$QUBES_EXPOSED" == "1" ]; then qubesdb-rm "$QDB_KEY/" qubesdb-write /qubes-block-devices '' From a032129b80a24dfae171a2a3ed3954ca54769624 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 15 Jul 2016 16:15:42 +0000 Subject: [PATCH 3/3] udev-block-add-change: simplify a check --- udev/udev-block-add-change | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index 27ccef4..53c8006 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -86,11 +86,7 @@ fi # the same time) for part in /sys$DEVPATH/$NAME*; do if [ -d $part ]; then - if is_used $part; then - xs_remove - exit 0 - fi - if is_attached $part; then + if is_used $part || is_attached $part; then xs_remove exit 0 fi