35 lines
673 B
Bash
35 lines
673 B
Bash
#!/bin/sh
|
|
|
|
# Usage: block-nbd [bind server ctl_port |unbind node]
|
|
#
|
|
# 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!
|
|
|
|
dir=$(dirname "$0")
|
|
. "$dir/block-common.sh"
|
|
|
|
#set -x
|
|
par=`xenstore-read $XENBUS_PATH/params` || true
|
|
#echo $par
|
|
|
|
case "$command" in
|
|
add)
|
|
modprobe nbd
|
|
for dev in /dev/nbd*; do
|
|
if nbd-client $par $dev; then
|
|
xenstore-write $XENBUS_PATH/node $dev
|
|
write_dev $dev
|
|
exit 0
|
|
fi
|
|
done
|
|
exit 1
|
|
;;
|
|
remove)
|
|
node=`xenstore-read $XENBUS_PATH/node` || true
|
|
nbd-client -d $node
|
|
exit 0
|
|
;;
|
|
esac
|