From 871d4485b94e9503dc9fbf67c374b2f015931dbb Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 6 Jun 2012 02:12:10 +0200 Subject: [PATCH] dom0+vm/qvm-block: speed up udev block handler (#560) xenstore is very slow, so don't bother it when unneeded. Namely do not try to remove entries, which haven't even created. --- misc/block_add_change | 16 ++++++++++++---- misc/qubes_block.rules | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/misc/block_add_change b/misc/block_add_change index e1b25ca..b366f9d 100755 --- a/misc/block_add_change +++ b/misc/block_add_change @@ -6,19 +6,26 @@ SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ] MODE=w XS_KEY="qubes-block-devices/$NAME" +xs_remove() { + if [ "$QUBES_EXPOSED" == "1" ]; then + xenstore-rm "$XS_KEY" + fi + echo QUBES_EXPOSED=0 +} + # Ignore mounted... if fgrep -q $DEVNAME /proc/mounts; then - xenstore-rm "$XS_KEY" + xs_remove exit 0 fi # ... and used by device-mapper if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then - xenstore-rm "$XS_KEY" + xs_remove exit 0 fi # ... and "empty" loop devices if [ "$MAJOR" -eq 7 -a ! -d /sys/$DEVPATH/loop ]; then - xenstore-rm "$XS_KEY" + xs_remove exit 0 fi @@ -26,7 +33,7 @@ fi if [ "$ID_TYPE" = "cd" ]; then if [ "$ID_CDROM_MEDIA" != "1" ]; then # Hide empty cdrom drive - xenstore-rm "$XS_KEY" + xs_remove exit 0 fi MODE=r @@ -37,6 +44,7 @@ if [ -d /sys/$DEVPATH/loop ]; then DESC=$(cat /sys/$DEVPATH/loop/backing_file) fi xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE" +echo QUBES_EXPOSED=1 # Make sure that block backend is loaded /sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk diff --git a/misc/qubes_block.rules b/misc/qubes_block.rules index 343553f..14503ee 100644 --- a/misc/qubes_block.rules +++ b/misc/qubes_block.rules @@ -9,8 +9,8 @@ ENV{MAJOR}=="202", GOTO="qubes_block_end" # Skip device-mapper devices ENV{MAJOR}=="253", GOTO="qubes_block_end" -ACTION=="add", RUN+="/usr/lib/qubes/block_add_change" -ACTION=="change", RUN+="/usr/lib/qubes/block_add_change" +ACTION=="add", IMPORT{program}="/usr/lib/qubes/block_add_change" +ACTION=="change", IMPORT{program}="/usr/lib/qubes/block_add_change" ACTION=="remove", RUN+="/usr/lib/qubes/block_remove" LABEL="qubes_block_end"