ia64/xen-unstable

view tools/examples/xen-hotplug-common.sh @ 7595:286946489e5d

From Murillo Fernandes Bernardes <mfb@br.ibm.com>:

The problem is: There is no mechanism to detect block device setup failure

Network devices have the same problem, and are fixed with this too.

I handling this problem in the way suggested by aliguori:
- hotplug scripts write a "hotplug-status" node on store
- Xend DevController.createDevice() check verify this node and return success
or throw an exception on failure.
- If no changes in "hotplug-status" node after DEVICE_CREATE_TIMEOUT seconds
Xend throw an exception showing the problem with hotplug scripts.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Oct 31 17:10:57 2005 +0100 (2005-10-31)
parents 4722eae11abb
children 28331cd6d43a
line source
1 #
2 # Copyright (c) 2005 XenSource Ltd.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
6 # License as published by the Free Software Foundation.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
19 dir=$(dirname "$0")
20 . "$dir/xen-script-common.sh"
22 export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
23 export LANG="POSIX"
24 unset $(set | grep ^LC_ | cut -d= -f1)
26 log() {
27 local level="$1"
28 shift
29 logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2
30 }
32 fatal() {
33 xenstore_write "$XENBUS_PATH"/hotplug-status error
34 log err "$@"
35 exit 1
36 }
38 success() {
39 # Tell DevController that backend is "connected"
40 xenstore_write "$XENBUS_PATH"/hotplug-status connected
41 }
43 ##
44 # xenstore_read <path>+
45 #
46 # Read each of the given paths, returning each result on a separate line, or
47 # exit this script if any of the paths is missing.
48 #
49 xenstore_read() {
50 local v=$(xenstore-read "$@" || true)
51 [ "$v" != "" ] || fatal "xenstore-read $@ failed."
52 echo "$v"
53 }
56 ##
57 # xenstore_read_default <path> <default>
58 #
59 # Read the given path, returning the value there or the given default if the
60 # path is not present.
61 #
62 xenstore_read_default() {
63 xenstore-read "$1" || echo "$2"
64 }
67 ##
68 # xenstore_write (<path> <value>)+
69 #
70 # Write each of the key/value pairs to the store, and exit this script if any
71 # such writing fails.
72 #
73 xenstore_write() {
74 log debug "Writing $@ to xenstore."
75 xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
76 }
78 log debug "$@" "XENBUS_PATH=$XENBUS_PATH"