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.
This commit is contained in:
parent
3e89b33209
commit
871d4485b9
@ -6,19 +6,26 @@ SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
|
|||||||
MODE=w
|
MODE=w
|
||||||
XS_KEY="qubes-block-devices/$NAME"
|
XS_KEY="qubes-block-devices/$NAME"
|
||||||
|
|
||||||
|
xs_remove() {
|
||||||
|
if [ "$QUBES_EXPOSED" == "1" ]; then
|
||||||
|
xenstore-rm "$XS_KEY"
|
||||||
|
fi
|
||||||
|
echo QUBES_EXPOSED=0
|
||||||
|
}
|
||||||
|
|
||||||
# Ignore mounted...
|
# Ignore mounted...
|
||||||
if fgrep -q $DEVNAME /proc/mounts; then
|
if fgrep -q $DEVNAME /proc/mounts; then
|
||||||
xenstore-rm "$XS_KEY"
|
xs_remove
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
# ... and used by device-mapper
|
# ... and used by device-mapper
|
||||||
if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then
|
if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then
|
||||||
xenstore-rm "$XS_KEY"
|
xs_remove
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
# ... and "empty" loop devices
|
# ... and "empty" loop devices
|
||||||
if [ "$MAJOR" -eq 7 -a ! -d /sys/$DEVPATH/loop ]; then
|
if [ "$MAJOR" -eq 7 -a ! -d /sys/$DEVPATH/loop ]; then
|
||||||
xenstore-rm "$XS_KEY"
|
xs_remove
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -26,7 +33,7 @@ fi
|
|||||||
if [ "$ID_TYPE" = "cd" ]; then
|
if [ "$ID_TYPE" = "cd" ]; then
|
||||||
if [ "$ID_CDROM_MEDIA" != "1" ]; then
|
if [ "$ID_CDROM_MEDIA" != "1" ]; then
|
||||||
# Hide empty cdrom drive
|
# Hide empty cdrom drive
|
||||||
xenstore-rm "$XS_KEY"
|
xs_remove
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
MODE=r
|
MODE=r
|
||||||
@ -37,6 +44,7 @@ if [ -d /sys/$DEVPATH/loop ]; then
|
|||||||
DESC=$(cat /sys/$DEVPATH/loop/backing_file)
|
DESC=$(cat /sys/$DEVPATH/loop/backing_file)
|
||||||
fi
|
fi
|
||||||
xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
|
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
|
# Make sure that block backend is loaded
|
||||||
/sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk
|
/sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk
|
||||||
|
@ -9,8 +9,8 @@ ENV{MAJOR}=="202", GOTO="qubes_block_end"
|
|||||||
# Skip device-mapper devices
|
# Skip device-mapper devices
|
||||||
ENV{MAJOR}=="253", GOTO="qubes_block_end"
|
ENV{MAJOR}=="253", GOTO="qubes_block_end"
|
||||||
|
|
||||||
ACTION=="add", RUN+="/usr/lib/qubes/block_add_change"
|
ACTION=="add", IMPORT{program}="/usr/lib/qubes/block_add_change"
|
||||||
ACTION=="change", RUN+="/usr/lib/qubes/block_add_change"
|
ACTION=="change", IMPORT{program}="/usr/lib/qubes/block_add_change"
|
||||||
ACTION=="remove", RUN+="/usr/lib/qubes/block_remove"
|
ACTION=="remove", RUN+="/usr/lib/qubes/block_remove"
|
||||||
|
|
||||||
LABEL="qubes_block_end"
|
LABEL="qubes_block_end"
|
||||||
|
Loading…
Reference in New Issue
Block a user