ia64/xen-unstable

view tools/hotplug/NetBSD/block-nbsd @ 18770:4bfc67b09e9c

tools/hotplug: Separate OS-specific scripts.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Nov 04 12:13:42 2008 +0000 (2008-11-04)
parents
children 415505139333
line source
1 #!/bin/sh -e
3 # $NetBSD: block-nbsd,v 1.1.1.1 2008/08/07 20:26:57 cegger Exp $
4 # Called by xenbackendd
5 # Usage: block xsdir_backend_path state
7 PATH=/bin:/usr/bin:/sbin:/usr/sbin
8 export PATH
10 error() {
11 echo "$@" >&2
12 xenstore_write $xpath/hotplug-status error
13 exit 1
14 }
17 xpath=$1
18 xstatus=$2
19 xtype=$(xenstore-read "$xpath/type")
20 xparams=$(xenstore-read "$xpath/params")
22 case $xstatus in
23 6)
24 # device removed
25 case $xtype in
26 file)
27 vnd=$(xenstore-read "$xpath/vnd" || echo none)
28 if [ $vnd != none ]; then
29 vnconfig -u $vnd
30 fi
31 ;;
32 phy)
33 ;;
34 *)
35 echo "unknown type $xtype" >&2
36 ;;
37 esac
38 xenstore-rm $xpath
39 exit 0
40 ;;
41 2)
42 case $xtype in
43 file)
44 # Store the list of available vnd(4) devices in
45 #``available_disks'', and mark them as ``free''.
46 list=`ls -1 /dev/vnd[0-9]*d | sed "s,/dev/vnd,,;s,d,," | sort -n`
47 for i in $list; do
48 disk="vnd$i"
49 available_disks="$available_disks $disk"
50 eval $disk=free
51 done
52 # Mark the used vnd(4) devices as ``used''.
53 for disk in `sysctl hw.disknames`; do
54 case $disk in
55 vnd[0-9]*) eval $disk=used ;;
56 esac
57 done
58 # Configure the first free vnd(4) device.
59 for disk in $available_disks; do
60 eval status=\$$disk
61 if [ "$status" = "free" ] && \
62 vnconfig /dev/${disk}d $xparams >/dev/null; then
63 device=/dev/${disk}d
64 echo vnconfig /dev/${disk}d $xparams
65 break
66 fi
67 done
68 if [ x$device = x ] ; then
69 error "no available vnd device"
70 fi
71 echo xenstore-write $xpath/vnd $device
72 xenstore-write $xpath/vnd $device
73 ;;
74 phy)
75 device=$xparams
76 ;;
77 esac
78 physical_device=$(stat -f '%r' "$device")
79 echo xenstore-write $xpath/physical-device $physical_device
80 xenstore-write $xpath/physical-device $physical_device
81 echo xenstore-write $xpath/hotplug-status connected
82 xenstore-write $xpath/hotplug-status connected
83 exit 0
84 ;;
85 *)
86 exit 0
87 ;;
88 esac