From 012dc63c53e90afb19da4c1751dc9a32b8777713 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Thu, 29 Sep 2011 13:49:52 +0200 Subject: [PATCH] dom0+vm: expose block devices info in xenstore (#226) --- common/block_add_change | 29 +++++++++++++++++++++++++++++ common/block_remove | 5 +++++ common/qubes_block.rules | 19 +++++++++++++++++++ rpm_spec/core-commonvm.spec | 6 ++++++ 4 files changed, 59 insertions(+) create mode 100755 common/block_add_change create mode 100755 common/block_remove create mode 100644 common/qubes_block.rules diff --git a/common/block_add_change b/common/block_add_change new file mode 100755 index 0000000..f2f3a48 --- /dev/null +++ b/common/block_add_change @@ -0,0 +1,29 @@ +#!/bin/bash + +NAME=${DEVNAME#/dev/} +DESC="${ID_MODEL} (${ID_FS_LABEL})" +SIZE=$(cat /sys/$DEVPATH/size) +MODE=w +XS_KEY="qubes-block-devices/$NAME" + +# Ignore mounted... +if fgrep -q $DEVNAME /proc/mounts; then + xenstore-rm "$XS_KEY" + exit 0 +fi +# ... and used by device-mapper +if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then + xenstore-rm "$XS_KEY" + exit 0 +fi + +# Special case for CD +if [ "$ID_TYPE" = "cd" ]; then + if [ "$ID_MEDIA_CDROM" != "1" ]; then + # Hide empty cdrom drive + xenstore-rm "$XS_KEY" + exit 0 + fi + MODE=r +fi +xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE" diff --git a/common/block_remove b/common/block_remove new file mode 100755 index 0000000..4825dea --- /dev/null +++ b/common/block_remove @@ -0,0 +1,5 @@ +#!/bin/sh + +NAME=${DEVNAME#/dev/} +XS_KEY="qubes-block-devices/$NAME" +xenstore-rm "$XS_KEY" diff --git a/common/qubes_block.rules b/common/qubes_block.rules new file mode 100644 index 0000000..644834f --- /dev/null +++ b/common/qubes_block.rules @@ -0,0 +1,19 @@ +# Expose all (except xen-frontend) block devices via xenstore + +# Only block devices are interesting +SUBSYSTEM!="block", GOTO="qubes_block_end" + +# Skip xen-blkfront devices +ENV{MAJOR}=="202", GOTO="qubes_block_end" + +# Skip loop devices +ENV{MAJOR}=="7", 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=="remove", RUN+="/usr/lib/qubes/block_remove" + +LABEL="qubes_block_end" diff --git a/rpm_spec/core-commonvm.spec b/rpm_spec/core-commonvm.spec index 634d1b9..fdf2bb3 100644 --- a/rpm_spec/core-commonvm.spec +++ b/rpm_spec/core-commonvm.spec @@ -78,9 +78,12 @@ cp serial.conf $RPM_BUILD_ROOT/var/lib/qubes/ mkdir -p $RPM_BUILD_ROOT/etc/udev/rules.d cp qubes_network.rules $RPM_BUILD_ROOT/etc/udev/rules.d/99-qubes_network.rules cp qubes_memory.rules $RPM_BUILD_ROOT/etc/udev/rules.d/50-qubes_memory.rules +cp qubes_block.rules $RPM_BUILD_ROOT/etc/udev/rules.d/99-qubes_block.rules mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes/ cp setup_ip $RPM_BUILD_ROOT/usr/lib/qubes/ cp qubes_download_dom0_updates.sh $RPM_BUILD_ROOT/usr/lib/qubes/ +cp block_add_change $RPM_BUILD_ROOT/usr/lib/qubes/ +cp block_remove $RPM_BUILD_ROOT/usr/lib/qubes/ mkdir -p $RPM_BUILD_ROOT/etc/yum/post-actions cp qubes_trigger_sync_appmenus.action $RPM_BUILD_ROOT/etc/yum/post-actions/ mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes @@ -243,9 +246,12 @@ rm -rf $RPM_BUILD_ROOT /usr/bin/xenstore-watch-qubes /etc/udev/rules.d/99-qubes_network.rules /etc/udev/rules.d/50-qubes_memory.rules +/etc/udev/rules.d/99-qubes_block.rules /etc/sysconfig/modules/qubes_core.modules /usr/lib/qubes/setup_ip /etc/yum/post-actions/qubes_trigger_sync_appmenus.action /usr/lib/qubes/qubes_trigger_sync_appmenus.sh /usr/lib/qubes/qubes_download_dom0_updates.sh +/usr/lib/qubes/block_add_change +/usr/lib/qubes/block_remove /lib/firmware/updates