Files
xen/tools/examples/block-enbd
T
cl349@firebug.cl.cam.ac.uk eccd1bf398 Move block device bind/unbind into hotplug scripts.
Fixes file: devices since unbind now runs after the backend driver
closes the loopback device.
Also moves name -> node translation into the backend domain.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
2005-09-12 19:49:03 +00:00

34 lines
744 B
Bash
Executable File

#!/bin/sh
# Usage: block-enbd [bind server ctl_port |unbind node]
#
# The file argument to the bind command is the file we are to bind to a
# loop device.
#
# The node argument to unbind is the name of the device node we are to
# unbind.
#
# This assumes you're running a correctly configured server at the other end!
set -e
case $1 in
bind)
for dev in /dev/nd*; do
if nbd-client $2:$3 $dev; then
major=$(stat -L -c %t "$dev")
minor=$(stat -L -c %T "$dev")
pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
xenstore-write "$XENBUS_PATH"/physical-device $pdev \
"$XENBUS_PATH"/node $dev
exit 0
fi
done
exit 1
;;
unbind)
nbd-client -d $2
exit 0
;;
esac