Use Qubes DB instead of Xenstore

This commit is contained in:
Marek Marczykowski 2013-06-07 05:21:41 +02:00 committed by Marek Marczykowski-Górecki
parent a91a8c8312
commit dc41fbad79
6 changed files with 22 additions and 23 deletions

View File

@ -5,11 +5,12 @@ NAME=${DEVNAME#/dev/}
DESC="`echo "${ID_MODEL} (${ID_FS_LABEL})" | iconv -f utf8 -t ascii//TRANSLIT`" DESC="`echo "${ID_MODEL} (${ID_FS_LABEL})" | iconv -f utf8 -t ascii//TRANSLIT`"
SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ] SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
MODE=w MODE=w
XS_KEY="qubes-block-devices/$NAME" QDB_KEY="/qubes-block-devices/$NAME"
xs_remove() { xs_remove() {
if [ "$QUBES_EXPOSED" == "1" ]; then if [ "$QUBES_EXPOSED" == "1" ]; then
xenstore-rm "$XS_KEY" qubesdb-rm "$QDB_KEY"
qubesdb-write /qubes-block-devices ''
fi fi
echo QUBES_EXPOSED=0 echo QUBES_EXPOSED=0
} }
@ -59,17 +60,12 @@ if [ -n "$DM_NAME" ]; then
DESC="$DM_NAME" DESC="$DM_NAME"
fi fi
# Get lock only in dom0 - there are so many block devices so it causes xenstore # The last one is meant to trigger watches
# deadlocks sometimes. qubesdb-write \
if [ -f /etc/qubes-release ]; then "$QDB_KEY/desc" "$DESC" \
# Skip xenstore-write if cannot obtain lock. This can mean very early system startup "$XS_KEY/size" "$SIZE" \
# stage without /run mounted (or populated). Devices will be rediscovered later "$XS_KEY/mode" "$MODE" \
# by qubes-core startup script. /qubes-block-devices ''
exec 9>>/var/run/qubes/block-xenstore.lock || exit 0
flock 9
fi
xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
echo QUBES_EXPOSED=1 echo QUBES_EXPOSED=1
# Make sure that block backend is loaded # Make sure that block backend is loaded

View File

@ -1,8 +1,9 @@
#!/bin/sh #!/bin/sh
NAME=${DEVNAME#/dev/} NAME=${DEVNAME#/dev/}
XS_KEY="qubes-block-devices/$NAME" QDB_KEY="/qubes-block-devices/$NAME"
xenstore-rm "$XS_KEY" qubesdb-rm "$XS_KEY"
qubesdb-write /qubes-block-devices ''
# If device was connected to some VM - detach it # If device was connected to some VM - detach it
# Notice: this can be run also in VM, so we cannot use xl... # Notice: this can be run also in VM, so we cannot use xl...

View File

@ -1,4 +1,4 @@
# Expose all (except xen-frontend) block devices via xenstore # Expose all (except xen-frontend) block devices via Qubes DB
# Only block devices are interesting # Only block devices are interesting
SUBSYSTEM!="block", GOTO="qubes_block_end" SUBSYSTEM!="block", GOTO="qubes_block_end"

View File

@ -1,4 +1,4 @@
# Expose all USB devices (except block) via xenstore # Expose all USB devices (except block) via Qubes DB
# Handle only USB devices # Handle only USB devices
SUBSYSTEM!="usb", GOTO="qubes_usb_end" SUBSYSTEM!="usb", GOTO="qubes_usb_end"

View File

@ -12,7 +12,7 @@
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0 [ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
[ "$DEVTYPE" != "usb_device" ] && exit 0 [ "$DEVTYPE" != "usb_device" ] && exit 0
# xenstore doesn't allow dot in key name # qubesdb doesn't allow dot in key name
XSNAME=`basename ${DEVPATH} | tr . _` XSNAME=`basename ${DEVPATH} | tr . _`
# FIXME: For some devices (my Cherry keyboard) ID_SERIAL does not # FIXME: For some devices (my Cherry keyboard) ID_SERIAL does not
@ -31,10 +31,11 @@ else
exit 0 exit 0
fi fi
XS_KEY="qubes-usb-devices/$XSNAME" QDB_KEY="/qubes-usb-devices/$XSNAME"
xenstore-write "$XS_KEY/desc" "$DESC" qubesdb-write "$QDB_KEY/desc" "$DESC"
xenstore-write "$XS_KEY/usb-ver" "$VERSION" qubesdb-write "$QDB_KEY/usb-ver" "$VERSION"
qubesdb-write /qubes-usb-devices ''
# Make sure PVUSB backend driver is loaded. # Make sure PVUSB backend driver is loaded.
/sbin/modprobe xen-usbback 2> /dev/null || /sbin/modprobe usbbk /sbin/modprobe xen-usbback 2> /dev/null || /sbin/modprobe usbbk

View File

@ -4,6 +4,7 @@
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0 [ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
NAME=`basename ${DEVPATH} | tr . _` NAME=`basename ${DEVPATH} | tr . _`
XS_KEY="qubes-usb-devices/$NAME" QDB_KEY="/qubes-usb-devices/$NAME"
xenstore-rm "$XS_KEY" qubesdb-rm "$QDB_KEY"
qubesdb-write /qubes-usb-devices ''