-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy path1005-hotplug-trigger-udev-event-on-block-attach-detach.patch
59 lines (52 loc) · 1.94 KB
/
1005-hotplug-trigger-udev-event-on-block-attach-detach.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 060a68175d9650285a55471f6a2f0e82480962fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Wed, 16 Nov 2022 01:43:37 +0100
Subject: [PATCH] hotplug: trigger udev event on block attach/detach
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Update QubesDB entries of given device (and its partitions) when it's attached
or detached to other VM. This is used to prevent accidential attachment of
whole device and its partitions at the same time.
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
---
tools/hotplug/Linux/block | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/hotplug/Linux/block b/tools/hotplug/Linux/block
index dc4466906e70..c0d509ef8ccd 100644
--- a/tools/hotplug/Linux/block
+++ b/tools/hotplug/Linux/block
@@ -281,6 +281,12 @@ case "$command" in
check_device_sharing "$dev" "$mode"
write_dev "$dev"
release_lock "block"
+ # update QubesDB entries
+ if [ -f "/sys/class/block/$(basename $dev)/partition" ]; then
+ udevadm trigger --property-match=DEVNAME=$dev
+ else
+ udevadm trigger --parent-match=/sys/class/block/$(basename $dev)
+ fi
exit 0
;;
@@ -353,8 +359,20 @@ mount it read-write in a guest domain."
remove)
truetype=$(cat $HOTPLUG_STORE-type || echo $truetype)
+ p=$(cat $HOTPLUG_STORE-params || echo $p)
case $truetype in
phy)
+ dev=$(expand_dev $p)
+ if [ -L "$dev" ]
+ then
+ dev=$(readlink -f "$dev") || fatal "$dev link does not exist."
+ fi
+ # update QubesDB entries
+ if [ -f "/sys/class/block/$(basename $dev)/partition" ]; then
+ udevadm trigger --property-match=DEVNAME=$dev
+ else
+ udevadm trigger --parent-match=/sys/class/block/$(basename $dev)
+ fi
exit 0
;;
--
2.44.0