ia64/xen-unstable

view tools/examples/block-enbd @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children 98fd1359eecd
line source
1 #!/bin/sh
3 # Usage: block-enbd [bind server ctl_port |unbind node]
4 #
5 # The file argument to the bind command is the file we are to bind to a
6 # loop device.
7 #
8 # The node argument to unbind is the name of the device node we are to
9 # unbind.
10 #
11 # This assumes you're running a correctly configured server at the other end!
13 set -e
15 case $1 in
16 bind)
17 for dev in /dev/nd*; do
18 if nbd-client $2:$3 $dev; then
19 major=$(stat -L -c %t "$dev")
20 minor=$(stat -L -c %T "$dev")
21 pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
22 xenstore-write "$XENBUS_PATH"/physical-device $pdev \
23 "$XENBUS_PATH"/node $dev
24 exit 0
25 fi
26 done
27 exit 1
28 ;;
29 unbind)
30 nbd-client -d $2
31 exit 0
32 ;;
33 esac