summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/xen/files/xen.examples/scripts/block-nbd
blob: d45711523f1973d9ed7e15614db70f22ac4efe4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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