Allow to attach disk image from different VM as block device. File attached with qvm-block -A will be visible as loopX device and as such can be detached. File path will be in device description.
43 строки
1.0 KiB
Bash
Исполняемый файл
43 строки
1.0 KiB
Bash
Исполняемый файл
#!/bin/bash
|
|
|
|
NAME=${DEVNAME#/dev/}
|
|
DESC="${ID_MODEL} (${ID_FS_LABEL})"
|
|
SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
|
|
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
|
|
# ... and "empty" loop devices
|
|
if [ "$MAJOR" -eq 7 -a ! -d /sys/$DEVPATH/loop ]; then
|
|
xenstore-rm "$XS_KEY"
|
|
exit 0
|
|
fi
|
|
|
|
# Special case for CD
|
|
if [ "$ID_TYPE" = "cd" ]; then
|
|
if [ "$ID_CDROM_MEDIA" != "1" ]; then
|
|
# Hide empty cdrom drive
|
|
xenstore-rm "$XS_KEY"
|
|
exit 0
|
|
fi
|
|
MODE=r
|
|
fi
|
|
|
|
# Special description for loop devices
|
|
if [ -d /sys/$DEVPATH/loop ]; then
|
|
DESC=$(cat /sys/$DEVPATH/loop/backing_file)
|
|
fi
|
|
xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
|
|
|
|
# Make sure that block backend is loaded
|
|
/sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk
|