2013-03-20 05:27:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
NAME=${DEVNAME#/dev/}
|
2013-06-07 03:21:41 +00:00
|
|
|
QDB_KEY="/qubes-block-devices/$NAME"
|
2014-12-11 05:06:57 +00:00
|
|
|
# Trailing slash is intentional - it will remove whole directory, instead of
|
|
|
|
# single base entry
|
|
|
|
qubesdb-rm "$QDB_KEY/"
|
2013-06-07 03:21:41 +00:00
|
|
|
qubesdb-write /qubes-block-devices ''
|
2013-03-20 05:27:32 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2016-05-16 02:36:17 +00:00
|
|
|
# update info about underlying devices of device-mapper (if any)
|
|
|
|
# at this stage device-mapper is already removed, so can't check what devices
|
|
|
|
# were used there
|
|
|
|
udevadm trigger --subsystem-match=block
|
|
|
|
|
2013-03-20 05:27:32 +00:00
|
|
|
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
|