File: block

package info (click to toggle)
xen-common 4.0.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 876 kB
  • ctags: 362
  • sloc: sh: 3,061; makefile: 403; perl: 186; python: 174; xml: 2
file content (91 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh -e

# $NetBSD: block-nbsd,v 1.1.1.1 2008/08/07 20:26:57 cegger Exp $
# Called by xenbackendd
# Usage: block xsdir_backend_path state

DIR=$(dirname "$0")
. "${DIR}/hotplugpath.sh"

PATH=${BINDIR}:${SBINDIR}:${LIBEXEC}:${PRIVATE_BINDIR}:/bin:/usr/bin:/sbin:/usr/sbin
export PATH

error() {
	echo "$@" >&2
	xenstore_write $xpath/hotplug-status error
	exit 1
}
	

xpath=$1
xstatus=$2
xtype=$(xenstore-read "$xpath/type")
xparams=$(xenstore-read "$xpath/params")

case $xstatus in
6)
	# device removed
	case $xtype in
	file)
		vnd=$(xenstore-read "$xpath/vnd" || echo none)
		if [ $vnd != none ]; then
			vnconfig -u $vnd
		fi
		;;
	phy)
		;;
	*)
		echo "unknown type $xtype" >&2
		;;
	esac
	xenstore-rm $xpath
	exit 0
	;;
2)
	case $xtype in
	file)
		# Store the list of available vnd(4) devices in
		#``available_disks'', and mark them as ``free''.
		list=`ls -1 /dev/vnd[0-9]*d | sed "s,/dev/vnd,,;s,d,," | sort -n`
		for i in $list; do
			disk="vnd$i"
			available_disks="$available_disks $disk"
			eval $disk=free
		done
		# Mark the used vnd(4) devices as ``used''.
		for disk in `sysctl hw.disknames`; do
			case $disk in
			vnd[0-9]*) eval $disk=used ;;
			esac
		done
		# Configure the first free vnd(4) device.
		for disk in $available_disks; do
			eval status=\$$disk
			if [ "$status" = "free" ] && \
			    vnconfig /dev/${disk}d $xparams >/dev/null; then
				device=/dev/${disk}d
				echo vnconfig /dev/${disk}d $xparams
				break	
			fi
		done
		if [ x$device = x ] ; then
			error "no available vnd device"
		fi
		echo xenstore-write $xpath/vnd $device
		xenstore-write $xpath/vnd $device
		;;
	phy)
		device=$xparams
		;;
	esac
	physical_device=$(stat -f '%r' "$device")
	echo xenstore-write $xpath/physical-device $physical_device
	xenstore-write $xpath/physical-device $physical_device
	echo xenstore-write $xpath/hotplug-status connected
	xenstore-write $xpath/hotplug-status connected
	exit 0
	;;
*)
	exit 0
	;;
esac