dom0+vm/qvm-block: automatically detach device when physical dev removed (#226)
This will work when device is unmounted. On mounted device backend will be removed (after 3s timeout), but frontend will left in "closing" state - manual 'xl block-detach' will be needed.
This commit is contained in:
parent
111d807ae0
commit
8d855aa958
8
common/block_cleanup
Executable file
8
common/block_cleanup
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DEVID=$[ $MAJOR * 256 + $MINOR ]
|
||||||
|
|
||||||
|
XS_PATH="device/vbd/$DEVID"
|
||||||
|
|
||||||
|
# Double check that DEVID is not empty
|
||||||
|
[ -n "$DEVID" ] && xenstore-rm $XS_PATH
|
@ -3,3 +3,30 @@
|
|||||||
NAME=${DEVNAME#/dev/}
|
NAME=${DEVNAME#/dev/}
|
||||||
XS_KEY="qubes-block-devices/$NAME"
|
XS_KEY="qubes-block-devices/$NAME"
|
||||||
xenstore-rm "$XS_KEY"
|
xenstore-rm "$XS_KEY"
|
||||||
|
|
||||||
|
# If device was connected to some VM - detach it
|
||||||
|
# Notice: this can be run also in VM, so we cannot use xl...
|
||||||
|
|
||||||
|
device_detach() {
|
||||||
|
xs_path=$1
|
||||||
|
|
||||||
|
xenstore-write $xs_path/online 0 $xs_path/state 5
|
||||||
|
|
||||||
|
# Wait for backend to finish dev shutdown
|
||||||
|
try=30
|
||||||
|
# -lt will break loop also when 'state' will be empty
|
||||||
|
while [ "`xenstore-read $xs_path/state 2> /dev/null`" -lt 6 ]; do
|
||||||
|
try=$[ $try - 1 ]
|
||||||
|
[ "$try" -le 0 ] && break
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
xenstore-rm $xs_path
|
||||||
|
}
|
||||||
|
|
||||||
|
for XS_DEV_PATH in `xenstore-ls -f backend/vbd | grep 'backend/vbd/[0-9]*/[0-9]* ' | cut -f 1 -d ' '`; do
|
||||||
|
CUR_DEVICE=`xenstore-read "$XS_DEV_PATH/params"`
|
||||||
|
if [ "$CUR_DEVICE" == "$DEVNAME" ]; then
|
||||||
|
device_detach "$XS_DEV_PATH"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
@ -17,3 +17,6 @@ ACTION=="change", RUN+="/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"
|
||||||
|
|
||||||
|
# Cleanup disconnected frontend from xenstore
|
||||||
|
ACTION=="remove", SUBSYSTEM=="block", ENV{MAJOR}=="202", RUN+="/usr/lib/qubes/block_cleanup"
|
||||||
|
@ -84,6 +84,7 @@ cp setup_ip $RPM_BUILD_ROOT/usr/lib/qubes/
|
|||||||
cp qubes_download_dom0_updates.sh $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_add_change $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
cp block_remove $RPM_BUILD_ROOT/usr/lib/qubes/
|
cp block_remove $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
|
cp block_cleanup $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/yum/post-actions
|
mkdir -p $RPM_BUILD_ROOT/etc/yum/post-actions
|
||||||
cp qubes_trigger_sync_appmenus.action $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
|
mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
@ -254,4 +255,5 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
/usr/lib/qubes/qubes_download_dom0_updates.sh
|
/usr/lib/qubes/qubes_download_dom0_updates.sh
|
||||||
/usr/lib/qubes/block_add_change
|
/usr/lib/qubes/block_add_change
|
||||||
/usr/lib/qubes/block_remove
|
/usr/lib/qubes/block_remove
|
||||||
|
/usr/lib/qubes/block_cleanup
|
||||||
/lib/firmware/updates
|
/lib/firmware/updates
|
||||||
|
@ -106,6 +106,7 @@ cp aux-tools/qubes-receive-updates $RPM_BUILD_ROOT/usr/lib/qubes/
|
|||||||
cp aux-tools/keep-dom0-clock-synced $RPM_BUILD_ROOT/usr/lib/qubes/
|
cp aux-tools/keep-dom0-clock-synced $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
cp ../common/block_add_change $RPM_BUILD_ROOT/usr/lib/qubes/
|
cp ../common/block_add_change $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
cp ../common/block_remove $RPM_BUILD_ROOT/usr/lib/qubes/
|
cp ../common/block_remove $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
|
cp ../common/block_cleanup $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc/policy
|
mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc/policy
|
||||||
cp ../appvm/qubes.Filecopy.policy $RPM_BUILD_ROOT/etc/qubes_rpc/policy/qubes.Filecopy
|
cp ../appvm/qubes.Filecopy.policy $RPM_BUILD_ROOT/etc/qubes_rpc/policy/qubes.Filecopy
|
||||||
@ -317,6 +318,7 @@ fi
|
|||||||
/usr/lib/qubes/qubes-receive-updates
|
/usr/lib/qubes/qubes-receive-updates
|
||||||
/usr/lib/qubes/block_add_change
|
/usr/lib/qubes/block_add_change
|
||||||
/usr/lib/qubes/block_remove
|
/usr/lib/qubes/block_remove
|
||||||
|
/usr/lib/qubes/block_cleanup
|
||||||
%attr(4750,root,qubes) /usr/lib/qubes/qfile-dom0-unpacker
|
%attr(4750,root,qubes) /usr/lib/qubes/qfile-dom0-unpacker
|
||||||
/usr/lib/qubes/keep-dom0-clock-synced
|
/usr/lib/qubes/keep-dom0-clock-synced
|
||||||
%attr(770,root,qubes) %dir /var/lib/qubes
|
%attr(770,root,qubes) %dir /var/lib/qubes
|
||||||
|
Loading…
Reference in New Issue
Block a user