From 098bfb634dcb0b0e472a874fe0620da470cbaf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 16 May 2016 04:39:19 +0200 Subject: [PATCH] udev/qvm-block: exclude device if its partition is already attached This prevents simultaneous attachment of the same device (in practice) to multiple VMs. This change to be effective requires udev action being called when such device is attached/detached to some domain. Script /etc/xen/scripts/block will take care of it. Fixes QubesOS/qubes-issues#1081 --- udev/udev-block-add-change | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index e4b7152..90eac10 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -36,11 +36,21 @@ is_used() { return 1 } +is_attached() { + dev_hex=$(stat -c %t:%T /dev/$(basename $1)) + xenstore-ls backend/vbd | grep -q "physical-device = \"$dev_hex\"" +} + # update info about parent devices, if any: if [ -f /sys$DEVPATH/partition ]; then parent=$(dirname $(readlink -f /sys$DEVPATH)) udevadm trigger \ --property-match=DEVPATH=/$(realpath --relative-to=/sys $parent) + # if parent device is already attached, skip its partitions + if is_attached $parent; then + xs_remove + exit 0 + fi fi # and underlying devices of device-mapper (if any) @@ -58,12 +68,18 @@ if is_used /sys$DEVPATH; then fi # or one of its partitions is used +# or already attached (prevent attaching both device and its partition(s) at +# 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 + xs_remove + exit 0 + fi fi done