debuggers.hg

view tools/hotplug/Linux/blktap @ 20993:4a4caf3c052d

hotplug: ignore xenstore-read error

The failure to read "backend/tap/<domid>/*" in the xenstore is a usual
case since the domain is gone after xenstore-ls command is executed.
The error should be ignored.

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 16 09:28:39 2010 +0000 (2010-02-16)
parents 534d3716bbbe
children 3ffdb094c2c0
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_default "$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_default "$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 }
58 t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
59 if [ -n "$t" ]
60 then
61 p=$(xenstore_read "$XENBUS_PATH/params")
62 # if we have a ':', chew from head including :
63 if echo $p | grep -q \:
64 then
65 p=${p#*:}
66 fi
67 fi
68 # some versions of readlink cannot be passed a regular file
69 if [ -L "$p" ]; then
70 file=$(readlink -f "$p") || fatal "$p link does not exist."
71 else
72 file="$p"
73 fi
75 if [ "$command" = 'add' ]
76 then
77 [ -e "$file" ] || { fatal $file does not exist; }
79 FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
80 FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
81 mode=$(xenstore_read "$XENBUS_PATH/mode")
82 mode=$(canonicalise_mode "$mode")
84 if [ "$mode" != '!' ]
85 then
86 result=$(check_blktap_sharing "$file" "$mode")
87 [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
88 fi
90 success
91 fi
93 exit 0