ia64/xen-unstable

view tools/examples/blktap @ 16877:31adb5c972d0

block scripts: use fatal() in xen-hotplug-common.sh if the file does not exist.
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 24 14:41:26 2008 +0000 (2008-01-24)
parents be5f27ff147b
children 5e3baace443f
line source
1 #!/bin/bash
3 # Copyright (c) 2005, XenSource Ltd.
5 dir=$(dirname "$0")
6 . "$dir/xen-hotplug-common.sh"
7 . "$dir/block-common.sh"
9 findCommand "$@"
11 ##
12 # check_blktap_sharing file mode
13 #
14 # Perform the sharing check for the given blktap and mode.
15 #
16 check_blktap_sharing()
17 {
18 local file="$1"
19 local mode="$2"
21 local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
22 for dom in $(xenstore-list "$base_path")
23 do
24 for dev in $(xenstore-list "$base_path/$dom")
25 do
26 params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2)
27 if [ "$file" = "$params" ]
28 then
30 if [ "$mode" = 'w' ]
31 then
32 if ! same_vm "$dom"
33 then
34 echo 'guest'
35 return
36 fi
37 else
38 local m=$(xenstore_read "$base_path/$dom/$dev/mode")
39 m=$(canonicalise_mode "$m")
41 if [ "$m" = 'w' ]
42 then
43 if ! same_vm "$dom"
44 then
45 echo 'guest'
46 return
47 fi
48 fi
49 fi
50 fi
51 done
52 done
54 echo 'ok'
55 }
57 FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
58 FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
59 mode=$(xenstore_read "$XENBUS_PATH/mode")
60 mode=$(canonicalise_mode "$mode")
62 t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
63 if [ -n "$t" ]
64 then
65 p=$(xenstore_read "$XENBUS_PATH/params")
66 # if we have a ':', chew from head including :
67 if echo $p | grep -q \:
68 then
69 p=${p#*:}
70 fi
71 fi
72 # some versions of readlink cannot be passed a regular file
73 if [ -L "$p" ]; then
74 file=$(readlink -f "$p") || fatal "$p link does not exist."
75 else
76 [ -f "$p" ] || { fatal "$p file does not exist."; }
77 file="$p"
78 fi
80 if [ "$mode" != '!' ]
81 then
82 result=$(check_blktap_sharing "$file" "$mode")
83 [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
84 fi
86 if [ "$command" = 'add' ]
87 then
88 [ -e "$file" ] || { fatal $file does not exist; }
89 success
90 fi
92 exit 0