ia64/xen-unstable
changeset 18829:436816898c87
merge with xen-unstable.hg
author | Isaku Yamahata <yamahata@valinux.co.jp> |
---|---|
date | Tue Nov 25 14:21:24 2008 +0900 (2008-11-25) |
parents | 7ef733b961c8 e7c421510be9 |
children | b3265ff6c613 |
files | tools/examples/blktap tools/examples/block tools/examples/block-common.sh tools/examples/block-enbd tools/examples/block-nbd tools/examples/external-device-migrate tools/examples/init.d/sysconfig.xendomains tools/examples/init.d/xend tools/examples/init.d/xendomains tools/examples/locking.sh tools/examples/logging.sh tools/examples/network-bridge tools/examples/network-nat tools/examples/network-route tools/examples/vif-bridge tools/examples/vif-common.sh tools/examples/vif-nat tools/examples/vif-route tools/examples/vscsi tools/examples/vtpm tools/examples/vtpm-common.sh tools/examples/vtpm-delete tools/examples/vtpm-hotplug-common.sh tools/examples/vtpm-impl tools/examples/vtpm-migration.sh tools/examples/xen-backend.agent tools/examples/xen-backend.rules tools/examples/xen-hotplug-cleanup tools/examples/xen-hotplug-common.sh tools/examples/xen-network-common.sh tools/examples/xen-script-common.sh xen/arch/x86/mm/page-guest32.h xen/include/asm-x86/pirq.h |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extras/mini-os/include/posix/net/if.h Tue Nov 25 14:21:24 2008 +0900 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + * This code is mostly taken from NetBSD net/if.h 1.6 + * Changes: Stefano Stabellini <stefano.stabellini@eu.citrix.com> 1.7 + * 1.8 + ****************************************************************************** 1.9 + * 1.10 + * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. 1.11 + * All rights reserved. 1.12 + * 1.13 + * This code is derived from software contributed to The NetBSD Foundation 1.14 + * by William Studenmund and Jason R. Thorpe. 1.15 + * 1.16 + * Redistribution and use in source and binary forms, with or without 1.17 + * modification, are permitted provided that the following conditions 1.18 + * are met: 1.19 + * 1. Redistributions of source code must retain the above copyright 1.20 + * notice, this list of conditions and the following disclaimer. 1.21 + * 2. Redistributions in binary form must reproduce the above copyright 1.22 + * notice, this list of conditions and the following disclaimer in the 1.23 + * documentation and/or other materials provided with the distribution. 1.24 + * 1.25 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1.26 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1.27 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.28 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1.29 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.30 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.31 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.32 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.33 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.34 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.35 + * POSSIBILITY OF SUCH DAMAGE. 1.36 + */ 1.37 + 1.38 +/* 1.39 + * Copyright (c) 1982, 1986, 1989, 1993 1.40 + * The Regents of the University of California. All rights reserved. 1.41 + * 1.42 + * Redistribution and use in source and binary forms, with or without 1.43 + * modification, are permitted provided that the following conditions 1.44 + * are met: 1.45 + * 1. Redistributions of source code must retain the above copyright 1.46 + * notice, this list of conditions and the following disclaimer. 1.47 + * 2. Redistributions in binary form must reproduce the above copyright 1.48 + * notice, this list of conditions and the following disclaimer in the 1.49 + * documentation and/or other materials provided with the distribution. 1.50 + * 3. Neither the name of the University nor the names of its contributors 1.51 + * may be used to endorse or promote products derived from this software 1.52 + * without specific prior written permission. 1.53 + * 1.54 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1.55 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.56 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.57 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1.58 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.59 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.60 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.61 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1.62 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1.63 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.64 + * SUCH DAMAGE. 1.65 + * 1.66 + */ 1.67 + 1.68 +#ifndef _NET_IF_H_ 1.69 +#define _NET_IF_H_ 1.70 + 1.71 +/* 1.72 + * Length of interface external name, including terminating '\0'. 1.73 + * Note: this is the same size as a generic device's external name. 1.74 + */ 1.75 +#define IF_NAMESIZE 16 1.76 + 1.77 +struct if_nameindex { 1.78 + unsigned int if_index; /* 1, 2, ... */ 1.79 + char *if_name; /* null terminated name: "le0", ... */ 1.80 +}; 1.81 + 1.82 +unsigned int if_nametoindex(const char *); 1.83 +char * if_indextoname(unsigned int, char *); 1.84 +struct if_nameindex * if_nameindex(void); 1.85 +void if_freenameindex(struct if_nameindex *); 1.86 + 1.87 +#endif /* !_NET_IF_H_ */ 1.88 +
2.1 --- a/extras/mini-os/lib/sys.c Tue Nov 18 10:55:51 2008 +0100 2.2 +++ b/extras/mini-os/lib/sys.c Tue Nov 25 14:21:24 2008 +0900 2.3 @@ -34,6 +34,7 @@ 2.4 #include <sys/unistd.h> 2.5 #include <sys/stat.h> 2.6 #include <sys/mman.h> 2.7 +#include <net/if.h> 2.8 #include <time.h> 2.9 #include <errno.h> 2.10 #include <fcntl.h> 2.11 @@ -1324,6 +1325,12 @@ unsupported_function(int, tcsetattr, -1) 2.12 unsupported_function(int, tcgetattr, 0); 2.13 unsupported_function(int, poll, -1); 2.14 2.15 +/* net/if.h */ 2.16 +unsupported_function_log(unsigned int, if_nametoindex, -1); 2.17 +unsupported_function_log(char *, if_indextoname, (char *) NULL); 2.18 +unsupported_function_log(struct if_nameindex *, if_nameindex, (struct if_nameindex *) NULL); 2.19 +unsupported_function_crash(if_freenameindex); 2.20 + 2.21 /* Linuxish abi for the Caml runtime, don't support */ 2.22 unsupported_function_log(struct dirent *, readdir64, NULL); 2.23 unsupported_function_log(int, getrusage, -1);
3.1 --- a/tools/Makefile Tue Nov 18 10:55:51 2008 +0100 3.2 +++ b/tools/Makefile Tue Nov 25 14:21:24 2008 +0900 3.3 @@ -9,6 +9,7 @@ SUBDIRS-y += flask 3.4 SUBDIRS-y += xenstore 3.5 SUBDIRS-y += misc 3.6 SUBDIRS-y += examples 3.7 +SUBDIRS-y += hotplug 3.8 SUBDIRS-y += xentrace 3.9 SUBDIRS-$(CONFIG_XCUTILS) += xcutils 3.10 SUBDIRS-$(CONFIG_X86) += firmware
4.1 --- a/tools/examples/Makefile Tue Nov 18 10:55:51 2008 +0100 4.2 +++ b/tools/examples/Makefile Tue Nov 25 14:21:24 2008 +0900 4.3 @@ -24,41 +24,6 @@ XEN_CONFIGS += xmexample.vti 4.4 XEN_CONFIGS += xend-pci-quirks.sxp 4.5 XEN_CONFIGS += xend-pci-permissive.sxp 4.6 4.7 -# Xen script dir and scripts to go there. 4.8 -XEN_SCRIPT_DIR = /etc/xen/scripts 4.9 -XEN_SCRIPTS = network-bridge vif-bridge 4.10 -XEN_SCRIPTS += network-route vif-route 4.11 -XEN_SCRIPTS += network-nat vif-nat 4.12 -XEN_SCRIPTS += block 4.13 -XEN_SCRIPTS += block-enbd block-nbd 4.14 -XEN_SCRIPTS += blktap 4.15 -XEN_SCRIPTS += vtpm vtpm-delete 4.16 -XEN_SCRIPTS += xen-hotplug-cleanup 4.17 -XEN_SCRIPTS += external-device-migrate 4.18 -XEN_SCRIPTS += vscsi 4.19 -XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh 4.20 -XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh 4.21 -XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh 4.22 -XEN_SCRIPT_DATA += vtpm-migration.sh vtpm-impl 4.23 - 4.24 -XEN_HOTPLUG_DIR = /etc/hotplug 4.25 -XEN_HOTPLUG_SCRIPTS = xen-backend.agent 4.26 - 4.27 -UDEV_RULES_DIR = /etc/udev 4.28 -UDEV_RULES = xen-backend.rules 4.29 - 4.30 -DI = $(if $(DISTDIR),$(shell readlink -f $(DISTDIR)),) 4.31 -DE = $(if $(DESTDIR),$(shell readlink -f $(DESTDIR)),) 4.32 -ifeq ($(findstring $(DI),$(DE)),$(DI)) 4.33 -HOTPLUGS=install-hotplug install-udev 4.34 -else 4.35 -ifeq ($(shell [ -x /usr/bin/udevinfo ] && [ `/usr/bin/udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/'` -ge 059 ] && echo 1),1) 4.36 -HOTPLUGS=install-udev 4.37 -else 4.38 -HOTPLUGS=install-hotplug 4.39 -endif 4.40 -endif 4.41 - 4.42 .PHONY: all 4.43 all: 4.44 4.45 @@ -66,7 +31,7 @@ all: 4.46 build: 4.47 4.48 .PHONY: install 4.49 -install: all install-readmes install-initd install-configs install-scripts $(HOTPLUGS) 4.50 +install: all install-readmes install-configs $(HOTPLUGS) 4.51 4.52 .PHONY: install-readmes 4.53 install-readmes: 4.54 @@ -77,14 +42,6 @@ install-readmes: 4.55 $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_CONFIG_DIR); \ 4.56 done 4.57 4.58 -.PHONY: install-initd 4.59 -install-initd: 4.60 - [ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d 4.61 - [ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig 4.62 - $(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d 4.63 - $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d 4.64 - $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains 4.65 - 4.66 .PHONY: install-configs 4.67 install-configs: $(XEN_CONFIGS) 4.68 [ -d $(DESTDIR)$(XEN_CONFIG_DIR) ] || \ 4.69 @@ -96,19 +53,6 @@ install-configs: $(XEN_CONFIGS) 4.70 $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_CONFIG_DIR); \ 4.71 done 4.72 4.73 -.PHONY: install-scripts 4.74 -install-scripts: 4.75 - [ -d $(DESTDIR)$(XEN_SCRIPT_DIR) ] || \ 4.76 - $(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR) 4.77 - set -e; for i in $(XEN_SCRIPTS); \ 4.78 - do \ 4.79 - $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 4.80 - done 4.81 - set -e; for i in $(XEN_SCRIPT_DATA); \ 4.82 - do \ 4.83 - $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 4.84 - done 4.85 - 4.86 .PHONY: install-hotplug 4.87 install-hotplug: 4.88 [ -d $(DESTDIR)$(XEN_HOTPLUG_DIR) ] || \
5.1 --- a/tools/examples/blktap Tue Nov 18 10:55:51 2008 +0100 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,93 +0,0 @@ 5.4 -#!/bin/bash 5.5 - 5.6 -# Copyright (c) 2005, XenSource Ltd. 5.7 - 5.8 -dir=$(dirname "$0") 5.9 -. "$dir/xen-hotplug-common.sh" 5.10 -. "$dir/block-common.sh" 5.11 - 5.12 -findCommand "$@" 5.13 - 5.14 -## 5.15 -# check_blktap_sharing file mode 5.16 -# 5.17 -# Perform the sharing check for the given blktap and mode. 5.18 -# 5.19 -check_blktap_sharing() 5.20 -{ 5.21 - local file="$1" 5.22 - local mode="$2" 5.23 - 5.24 - local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE" 5.25 - for dom in $(xenstore-list "$base_path") 5.26 - do 5.27 - for dev in $(xenstore-list "$base_path/$dom") 5.28 - do 5.29 - params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2) 5.30 - if [ "$file" = "$params" ] 5.31 - then 5.32 - 5.33 - if [ "$mode" = 'w' ] 5.34 - then 5.35 - if ! same_vm "$dom" 5.36 - then 5.37 - echo 'guest' 5.38 - return 5.39 - fi 5.40 - else 5.41 - local m=$(xenstore_read "$base_path/$dom/$dev/mode") 5.42 - m=$(canonicalise_mode "$m") 5.43 - 5.44 - if [ "$m" = 'w' ] 5.45 - then 5.46 - if ! same_vm "$dom" 5.47 - then 5.48 - echo 'guest' 5.49 - return 5.50 - fi 5.51 - fi 5.52 - fi 5.53 - fi 5.54 - done 5.55 - done 5.56 - 5.57 - echo 'ok' 5.58 -} 5.59 - 5.60 - 5.61 -t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') 5.62 -if [ -n "$t" ] 5.63 -then 5.64 - p=$(xenstore_read "$XENBUS_PATH/params") 5.65 - # if we have a ':', chew from head including : 5.66 - if echo $p | grep -q \: 5.67 - then 5.68 - p=${p#*:} 5.69 - fi 5.70 -fi 5.71 -# some versions of readlink cannot be passed a regular file 5.72 -if [ -L "$p" ]; then 5.73 - file=$(readlink -f "$p") || fatal "$p link does not exist." 5.74 -else 5.75 - file="$p" 5.76 -fi 5.77 - 5.78 -if [ "$command" = 'add' ] 5.79 -then 5.80 - [ -e "$file" ] || { fatal $file does not exist; } 5.81 - 5.82 - FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id") 5.83 - FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm") 5.84 - mode=$(xenstore_read "$XENBUS_PATH/mode") 5.85 - mode=$(canonicalise_mode "$mode") 5.86 - 5.87 - if [ "$mode" != '!' ] 5.88 - then 5.89 - result=$(check_blktap_sharing "$file" "$mode") 5.90 - [ "$result" = 'ok' ] || ebusy "$file already in use by other domain" 5.91 - fi 5.92 - 5.93 - success 5.94 -fi 5.95 - 5.96 -exit 0
6.1 --- a/tools/examples/block Tue Nov 18 10:55:51 2008 +0100 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,381 +0,0 @@ 6.4 -#!/bin/bash 6.5 - 6.6 -dir=$(dirname "$0") 6.7 -. "$dir/block-common.sh" 6.8 - 6.9 -expand_dev() { 6.10 - local dev 6.11 - case $1 in 6.12 - /*) 6.13 - dev=$1 6.14 - ;; 6.15 - *) 6.16 - dev=/dev/$1 6.17 - ;; 6.18 - esac 6.19 - echo -n $dev 6.20 -} 6.21 - 6.22 - 6.23 -## 6.24 -# check_sharing device mode 6.25 -# 6.26 -# Check whether the device requested is already in use. To use the device in 6.27 -# read-only mode, it may be in use in read-only mode, but may not be in use in 6.28 -# read-write anywhere at all. To use the device in read-write mode, it must 6.29 -# not be in use anywhere at all. 6.30 -# 6.31 -# Prints one of 6.32 -# 6.33 -# 'local': the device may not be used because it is mounted in the current 6.34 -# (i.e. the privileged domain) in a way incompatible with the 6.35 -# requested mode; 6.36 -# 'guest': the device may not be used because it already mounted by a guest 6.37 -# in a way incompatible with the requested mode; or 6.38 -# 'ok': the device may be used. 6.39 -# 6.40 -check_sharing() 6.41 -{ 6.42 - local dev="$1" 6.43 - local mode="$2" 6.44 - 6.45 - local devmm=$(device_major_minor "$dev") 6.46 - local file 6.47 - 6.48 - if [ "$mode" = 'w' ] 6.49 - then 6.50 - toskip="^$" 6.51 - else 6.52 - toskip="^[^ ]* [^ ]* [^ ]* ro[, ]" 6.53 - fi 6.54 - 6.55 - for file in $(cat /proc/mounts | grep -v "$toskip" | cut -f 1 -d ' ') 6.56 - do 6.57 - if [ -e "$file" ] 6.58 - then 6.59 - local d=$(device_major_minor "$file") 6.60 - 6.61 - if [ "$d" = "$devmm" ] 6.62 - then 6.63 - echo 'local' 6.64 - return 6.65 - fi 6.66 - fi 6.67 - done 6.68 - 6.69 - local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE" 6.70 - for dom in $(xenstore-list "$base_path") 6.71 - do 6.72 - for dev in $(xenstore-list "$base_path/$dom") 6.73 - do 6.74 - d=$(xenstore_read_default "$base_path/$dom/$dev/physical-device" "") 6.75 - 6.76 - if [ "$d" = "$devmm" ] 6.77 - then 6.78 - if [ "$mode" = 'w' ] 6.79 - then 6.80 - if ! same_vm $dom 6.81 - then 6.82 - echo 'guest' 6.83 - return 6.84 - fi 6.85 - else 6.86 - local m=$(xenstore_read "$base_path/$dom/$dev/mode") 6.87 - m=$(canonicalise_mode "$m") 6.88 - 6.89 - if [ "$m" = 'w' ] 6.90 - then 6.91 - if ! same_vm $dom 6.92 - then 6.93 - echo 'guest' 6.94 - return 6.95 - fi 6.96 - fi 6.97 - fi 6.98 - fi 6.99 - done 6.100 - done 6.101 - 6.102 - echo 'ok' 6.103 -} 6.104 - 6.105 - 6.106 -## 6.107 -# check_device_sharing dev mode 6.108 -# 6.109 -# Perform the sharing check for the given physical device and mode. 6.110 -# 6.111 -check_device_sharing() 6.112 -{ 6.113 - local dev="$1" 6.114 - local mode=$(canonicalise_mode "$2") 6.115 - local result 6.116 - 6.117 - if [ "x$mode" = 'x!' ] 6.118 - then 6.119 - return 0 6.120 - fi 6.121 - 6.122 - result=$(check_sharing "$dev" "$mode") 6.123 - 6.124 - if [ "$result" != 'ok' ] 6.125 - then 6.126 - do_ebusy "Device $dev is mounted " "$mode" "$result" 6.127 - fi 6.128 -} 6.129 - 6.130 - 6.131 -## 6.132 -# check_device_sharing file dev mode 6.133 -# 6.134 -# Perform the sharing check for the given file mounted through the given 6.135 -# loopback interface, in the given mode. 6.136 -# 6.137 -check_file_sharing() 6.138 -{ 6.139 - local file="$1" 6.140 - local dev="$2" 6.141 - local mode="$3" 6.142 - 6.143 - result=$(check_sharing "$dev" "$mode") 6.144 - 6.145 - if [ "$result" != 'ok' ] 6.146 - then 6.147 - do_ebusy "File $file is loopback-mounted through $dev, 6.148 -which is mounted " "$mode" "$result" 6.149 - fi 6.150 -} 6.151 - 6.152 - 6.153 -## 6.154 -# do_ebusy prefix mode result 6.155 -# 6.156 -# Helper function for check_device_sharing check_file_sharing, calling ebusy 6.157 -# with an error message constructed from the given prefix, mode, and result 6.158 -# from a call to check_sharing. 6.159 -# 6.160 -do_ebusy() 6.161 -{ 6.162 - local prefix="$1" 6.163 - local mode="$2" 6.164 - local result="$3" 6.165 - 6.166 - if [ "$result" = 'guest' ] 6.167 - then 6.168 - dom='a guest ' 6.169 - when='now' 6.170 - else 6.171 - dom='the privileged ' 6.172 - when='by a guest' 6.173 - fi 6.174 - 6.175 - if [ "$mode" = 'w' ] 6.176 - then 6.177 - m1='' 6.178 - m2='' 6.179 - else 6.180 - m1='read-write ' 6.181 - m2='read-only ' 6.182 - fi 6.183 - 6.184 - release_lock "block" 6.185 - ebusy \ 6.186 -"${prefix}${m1}in ${dom}domain, 6.187 -and so cannot be mounted ${m2}${when}." 6.188 -} 6.189 - 6.190 - 6.191 -t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') 6.192 - 6.193 -case "$command" in 6.194 - add) 6.195 - phys=$(xenstore_read_default "$XENBUS_PATH/physical-device" 'MISSING') 6.196 - if [ "$phys" != 'MISSING' ] 6.197 - then 6.198 - # Depending upon the hotplug configuration, it is possible for this 6.199 - # script to be called twice, so just bail. 6.200 - exit 0 6.201 - fi 6.202 - 6.203 - if [ -n "$t" ] 6.204 - then 6.205 - p=$(xenstore_read "$XENBUS_PATH/params") 6.206 - mode=$(xenstore_read "$XENBUS_PATH/mode") 6.207 - fi 6.208 - 6.209 - case $t in 6.210 - phy) 6.211 - dev=$(expand_dev $p) 6.212 - FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id") 6.213 - FRONTEND_UUID=$(xenstore_read_default \ 6.214 - "/local/domain/$FRONTEND_ID/vm" 'unknown') 6.215 - 6.216 - if [ -L "$dev" ] 6.217 - then 6.218 - dev=$(readlink -f "$dev") || fatal "$dev link does not exist." 6.219 - fi 6.220 - test -e "$dev" || fatal "$dev does not exist." 6.221 - test -b "$dev" || fatal "$dev is not a block device." 6.222 - 6.223 - claim_lock "block" 6.224 - check_device_sharing "$dev" "$mode" 6.225 - write_dev "$dev" 6.226 - release_lock "block" 6.227 - exit 0 6.228 - ;; 6.229 - 6.230 - file) 6.231 - # Canonicalise the file, for sharing check comparison, and the mode 6.232 - # for ease of use here. 6.233 - file=$(readlink -f "$p") || fatal "$p does not exist." 6.234 - test -f "$file" || fatal "$file does not exist." 6.235 - mode=$(canonicalise_mode "$mode") 6.236 - 6.237 - claim_lock "block" 6.238 - 6.239 - if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w 6.240 - then 6.241 - release_lock "block" 6.242 - ebusy \ 6.243 -"File $file is read-only, and so I will not 6.244 -mount it read-write in a guest domain." 6.245 - fi 6.246 - 6.247 - loopdev='' 6.248 - for dev in /dev/loop* 6.249 - do 6.250 - if [ ! -b "$dev" ] 6.251 - then 6.252 - continue 6.253 - fi 6.254 - 6.255 - f=$(losetup "$dev" 2>/dev/null) || f='' 6.256 - 6.257 - if [ "$f" ] 6.258 - then 6.259 - # $dev is in use. Check sharing. 6.260 - if [ "x$mode" = 'x!' ] 6.261 - then 6.262 - continue 6.263 - fi 6.264 - 6.265 - f=$(echo "$f" | sed -e 's/.*(\(.*\)).*/\1/g') 6.266 - 6.267 - # $f is the filename, as read from losetup, but the loopback 6.268 - # driver truncates filenames at 64 characters, so we need to go 6.269 - # trawling through the store if it's longer than that. Truncation 6.270 - # is indicated by an asterisk at the end of the filename. 6.271 - if expr index "$f" '*' >/dev/null 6.272 - then 6.273 - found="" 6.274 - for dom in $(xenstore-list "$XENBUS_BASE_PATH") 6.275 - do 6.276 - for domdev in $(xenstore-list "$XENBUS_BASE_PATH/$dom") 6.277 - do 6.278 - d=$(xenstore_read_default \ 6.279 - "$XENBUS_BASE_PATH/$dom/$domdev/node" "") 6.280 - if [ "$d" = "$dev" ] 6.281 - then 6.282 - f=$(xenstore_read "$XENBUS_BASE_PATH/$dom/$domdev/params") 6.283 - found=1 6.284 - break 2 6.285 - fi 6.286 - done 6.287 - done 6.288 - 6.289 - if [ ! "$found" ] 6.290 - then 6.291 - # This loopback device is in use by someone else, so skip it. 6.292 - log debug "Loopback sharing check skips device $dev." 6.293 - continue 6.294 - fi 6.295 - fi 6.296 - 6.297 - # Canonicalise the filename for the comparison. 6.298 - 6.299 - # I have seen this readlink fails because the filename given by 6.300 - # losetup is only the basename. This cannot happen when the loop 6.301 - # device is set up through this script, because file is 6.302 - # canonicalised above, but it may happen when loop devices are set 6.303 - # up some other way. This readlink may also conceivably fail if 6.304 - # the file backing this loop device has been removed. 6.305 - 6.306 - # For maximum safety, in the case that $f does not resolve, we 6.307 - # assume that $file and $f are in the same directory. 6.308 - 6.309 - # If you create a loopback filesystem, remove it and continue to 6.310 - # run on it, and then create another file with the same name, then 6.311 - # this check will block that -- don't do that. 6.312 - 6.313 - # If you create loop devices through some other mechanism, use 6.314 - # relative filenames, and then use the same filename through this 6.315 - # script, then this check will block that -- don't do that either. 6.316 - 6.317 - f=$(readlink -f "$f" || echo $(dirname "$file")/$(basename "$f")) 6.318 - 6.319 - 6.320 - if [ "$f" = "$file" ] 6.321 - then 6.322 - check_file_sharing "$file" "$dev" "$mode" 6.323 - fi 6.324 - else 6.325 - # $dev is not in use, so we'll remember it for use later; we want 6.326 - # to finish the sharing check first. 6.327 - 6.328 - if [ "$loopdev" = '' ] 6.329 - then 6.330 - loopdev="$dev" 6.331 - fi 6.332 - fi 6.333 - done 6.334 - 6.335 - if [ "$loopdev" = '' ] 6.336 - then 6.337 - release_lock "block" 6.338 - fatal 'Failed to find an unused loop device' 6.339 - fi 6.340 - 6.341 - if LANG=C losetup -h 2>&1 | grep read-only >/dev/null 6.342 - then 6.343 - roflag="-$mode"; roflag="${roflag#-w}"; roflag="${roflag#-!}" 6.344 - else 6.345 - roflag='' 6.346 - fi 6.347 - do_or_die losetup $roflag "$loopdev" "$file" 6.348 - xenstore_write "$XENBUS_PATH/node" "$loopdev" 6.349 - write_dev "$loopdev" 6.350 - release_lock "block" 6.351 - exit 0 6.352 - ;; 6.353 - 6.354 - "") 6.355 - claim_lock "block" 6.356 - success 6.357 - release_lock "block" 6.358 - ;; 6.359 - esac 6.360 - ;; 6.361 - 6.362 - remove) 6.363 - case $t in 6.364 - phy) 6.365 - exit 0 6.366 - ;; 6.367 - 6.368 - file) 6.369 - node=$(xenstore_read "$XENBUS_PATH/node") 6.370 - losetup -d "$node" 6.371 - exit 0 6.372 - ;; 6.373 - 6.374 - "") 6.375 - exit 0 6.376 - ;; 6.377 - esac 6.378 - ;; 6.379 - 6.380 -esac 6.381 - 6.382 -# If we've reached here, $t is neither phy nor file, so fire a helper script. 6.383 -[ -x /etc/xen/scripts/block-"$t" ] && \ 6.384 - /etc/xen/scripts/block-"$t" "$command" $node
7.1 --- a/tools/examples/block-common.sh Tue Nov 18 10:55:51 2008 +0100 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,116 +0,0 @@ 7.4 -# 7.5 -# Copyright (c) 2005 XenSource Ltd. 7.6 -# 7.7 -# This library is free software; you can redistribute it and/or 7.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 7.9 -# License as published by the Free Software Foundation. 7.10 -# 7.11 -# This library is distributed in the hope that it will be useful, 7.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 7.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 7.14 -# Lesser General Public License for more details. 7.15 -# 7.16 -# You should have received a copy of the GNU Lesser General Public 7.17 -# License along with this library; if not, write to the Free Software 7.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 7.19 -# 7.20 - 7.21 - 7.22 -dir=$(dirname "$0") 7.23 -. "$dir/xen-hotplug-common.sh" 7.24 - 7.25 -findCommand "$@" 7.26 - 7.27 -if [ "$command" != "add" ] && 7.28 - [ "$command" != "remove" ] 7.29 -then 7.30 - log err "Invalid command: $command" 7.31 - exit 1 7.32 -fi 7.33 - 7.34 - 7.35 -XENBUS_PATH="${XENBUS_PATH:?}" 7.36 - 7.37 - 7.38 -ebusy() 7.39 -{ 7.40 - xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \ 7.41 - "$XENBUS_PATH/hotplug-status" busy 7.42 - log err "$@" 7.43 - exit 1 7.44 -} 7.45 - 7.46 - 7.47 -## 7.48 -# Print the given device's major and minor numbers, written in hex and 7.49 -# separated by a colon. 7.50 -device_major_minor() 7.51 -{ 7.52 - stat -L -c %t:%T "$1" 7.53 -} 7.54 - 7.55 - 7.56 -## 7.57 -# Write physical-device = MM,mm to the store, where MM and mm are the major 7.58 -# and minor numbers of device respectively. 7.59 -# 7.60 -# @param device The device from which major and minor numbers are read, which 7.61 -# will be written into the store. 7.62 -# 7.63 -write_dev() { 7.64 - local mm 7.65 - 7.66 - mm=$(device_major_minor "$1") 7.67 - 7.68 - if [ -z $mm ] 7.69 - then 7.70 - fatal "Backend device does not exist" 7.71 - fi 7.72 - 7.73 - xenstore_write "$XENBUS_PATH/physical-device" "$mm" 7.74 - 7.75 - success 7.76 -} 7.77 - 7.78 - 7.79 -## 7.80 -# canonicalise_mode mode 7.81 -# 7.82 -# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations 7.83 -# thereof, and canonicalises them to one of 7.84 -# 7.85 -# 'r': perform checks for a new read-only mount; 7.86 -# 'w': perform checks for a read-write mount; or 7.87 -# '!': perform no checks at all. 7.88 -# 7.89 -canonicalise_mode() 7.90 -{ 7.91 - local mode="$1" 7.92 - 7.93 - if ! expr index "$mode" 'w' >/dev/null 7.94 - then 7.95 - echo 'r' 7.96 - elif ! expr index "$mode" '!' >/dev/null 7.97 - then 7.98 - echo 'w' 7.99 - else 7.100 - echo '!' 7.101 - fi 7.102 -} 7.103 - 7.104 - 7.105 -same_vm() 7.106 -{ 7.107 - local otherdom="$1" 7.108 - # Note that othervm can be MISSING here, because Xend will be racing with 7.109 - # the hotplug scripts -- the entries in /local/domain can be removed by 7.110 - # Xend before the hotplug scripts have removed the entry in 7.111 - # /local/domain/0/backend/. In this case, we want to pretend that the 7.112 - # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be 7.113 - # allowed. 7.114 - local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \ 7.115 - "$FRONTEND_UUID") 7.116 - 7.117 - [ "$FRONTEND_UUID" = "$othervm" ] 7.118 -} 7.119 -
8.1 --- a/tools/examples/block-enbd Tue Nov 18 10:55:51 2008 +0100 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,27 +0,0 @@ 8.4 -#!/bin/bash 8.5 - 8.6 -# Usage: block-enbd [bind server ctl_port |unbind node] 8.7 -# 8.8 -# The node argument to unbind is the name of the device node we are to 8.9 -# unbind. 8.10 -# 8.11 -# This assumes you're running a correctly configured server at the other end! 8.12 - 8.13 -dir=$(dirname "$0") 8.14 -. "$dir/block-common.sh" 8.15 - 8.16 -case "$command" in 8.17 - add) 8.18 - for dev in /dev/nd*; do 8.19 - if nbd-client $2:$3 $dev; then 8.20 - write_dev $dev 8.21 - exit 0 8.22 - fi 8.23 - done 8.24 - exit 1 8.25 - ;; 8.26 - remove) 8.27 - nbd-client -d $2 8.28 - exit 0 8.29 - ;; 8.30 -esac
9.1 --- a/tools/examples/block-nbd Tue Nov 18 10:55:51 2008 +0100 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,27 +0,0 @@ 9.4 -#!/bin/bash 9.5 - 9.6 -# Usage: block-nbd [bind server ctl_port |unbind node] 9.7 -# 9.8 -# The node argument to unbind is the name of the device node we are to 9.9 -# unbind. 9.10 -# 9.11 -# This assumes you're running a correctly configured server at the other end! 9.12 - 9.13 -dir=$(dirname "$0") 9.14 -. "$dir/block-common.sh" 9.15 - 9.16 -case "$command" in 9.17 - add) 9.18 - for dev in /dev/nbd*; do 9.19 - if nbd-client $2 $3 $dev; then 9.20 - write_dev $dev 9.21 - exit 0 9.22 - fi 9.23 - done 9.24 - exit 1 9.25 - ;; 9.26 - remove) 9.27 - nbd-client -d $2 9.28 - exit 0 9.29 - ;; 9.30 -esac
10.1 --- a/tools/examples/external-device-migrate Tue Nov 18 10:55:51 2008 +0100 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,98 +0,0 @@ 10.4 -#!/bin/bash 10.5 - 10.6 -# Copyright (c) 2005 IBM Corporation 10.7 -# 10.8 -# This library is free software; you can redistribute it and/or 10.9 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 10.10 -# License as published by the Free Software Foundation. 10.11 -# 10.12 -# This library is distributed in the hope that it will be useful, 10.13 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 10.14 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10.15 -# Lesser General Public License for more details. 10.16 -# 10.17 -# You should have received a copy of the GNU Lesser General Public 10.18 -# License along with this library; if not, write to the Free Software 10.19 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 10.20 -# 10.21 - 10.22 -set -x 10.23 - 10.24 -# This script is called by XenD for migration of external devices 10.25 -# It does not handle the migration of those devices itself, but 10.26 -# passes the requests on to further applications 10.27 -# It handles the low-level command line parsing and some of the 10.28 -# synchronization 10.29 - 10.30 -dir=$(dirname "$0") 10.31 -. "$dir/logging.sh" 10.32 - 10.33 - 10.34 -function ext_dev_migrate_usage() { 10.35 -cat <<EOF 10.36 -Pass the following command line parameters to the script: 10.37 - 10.38 --step <n> : n-th migration step 10.39 --host <host> : the destination host 10.40 --domname <domain name> : name of the domain that is migrating 10.41 --type <device type> : the type of device that is migrating 10.42 --subtype <dev. subtype>: the subtype of the device 10.43 --recover : indicates recovery request; an error 10.44 - occurred during migration 10.45 --help : display this help screen 10.46 -EOF 10.47 -} 10.48 - 10.49 -# Parse the command line paramters. The following parameters must be 10.50 -# passed as the first ones in the sequence: 10.51 -# -step [required] 10.52 -# -host [required] 10.53 -# -domname [required] 10.54 -# -type [required] 10.55 -# -subtype [optional] 10.56 -# -recover [optional] 10.57 -# The remaining ones will be passed to the called function. 10.58 -function evaluate_params() 10.59 -{ 10.60 - local step host domname typ recover filename func stype 10.61 - stype="" 10.62 - while [ $# -ge 1 ]; do 10.63 - case "$1" in 10.64 - -step) step=$2; shift; shift;; 10.65 - -host) host=$2; shift; shift;; 10.66 - -domname) domname=$2; shift; shift;; 10.67 - -type) typ=$2; shift; shift;; 10.68 - -subtype) stype=$2; shift; shift;; 10.69 - -recover) recover=1; shift;; 10.70 - -help) ext_dev_migrate_usage; exit 0;; 10.71 - *) break;; 10.72 - esac 10.73 - done 10.74 - 10.75 - if [ "$step" = "" -o \ 10.76 - "$host" = "" -o \ 10.77 - "$typ" = "" -o \ 10.78 - "$domname" = "" ]; then 10.79 - echo "Error: Parameter(s) missing (-step/-host/-type/-domname)" 1>&2 10.80 - echo "" 1>&2 10.81 - echo "$0 -help for usage." 1>&2 10.82 - exit 1 10.83 - fi 10.84 - 10.85 - filename="$dir/$typ$stype-migration.sh" 10.86 - if [ ! -r $filename ]; then 10.87 - echo "Error: Could not find script '$filename'" 10.88 - return 10.89 - fi 10.90 - . "$filename" 10.91 - 10.92 - if [ "$recover" = "1" ]; then 10.93 - func="$typ"_recover 10.94 - eval $func $host $domname $step $* 10.95 - else 10.96 - func="$typ"_migration_step 10.97 - eval $func $host $domname $step $* 10.98 - fi 10.99 -} 10.100 - 10.101 -evaluate_params "$@"
11.1 --- a/tools/examples/init.d/sysconfig.xendomains Tue Nov 18 10:55:51 2008 +0100 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,137 +0,0 @@ 11.4 -## Path: System/xen 11.5 -## Description: xen domain start/stop on boot 11.6 -## Type: string 11.7 -## Default: 11.8 -# 11.9 -# The xendomains script can send SysRq requests to domains on shutdown. 11.10 -# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility 11.11 -# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks 11.12 -# of the domains ("s"). 11.13 -# 11.14 -XENDOMAINS_SYSRQ="" 11.15 - 11.16 -## Type: integer 11.17 -## Default: 100000 11.18 -# 11.19 -# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait 11.20 -# (in microseconds) after each SysRq, so the domain has a chance to react. 11.21 -# If you want to a quick'n'dirty shutdown via SysRq, you may want to set 11.22 -# it to a relatively high value (1200000). 11.23 -# 11.24 -XENDOMAINS_USLEEP=100000 11.25 - 11.26 -## Type: integer 11.27 -## Default: 5000000 11.28 -# 11.29 -# When creating a guest domain, it is sensible to allow a little time for it 11.30 -# to get started before creating another domain or proceeding through the 11.31 -# boot process. Without this, the booting guests will thrash the disk as they 11.32 -# start up. This timeout (in microseconds) specifies the delay after guest 11.33 -# domain creation. 11.34 -# 11.35 -XENDOMAINS_CREATE_USLEEP=5000000 11.36 - 11.37 -## Type: string 11.38 -## Default: "" 11.39 -# 11.40 -# Set this to a non-empty string if you want to migrate virtual machines 11.41 -# on shutdown. The string will be passed to the xm migrate DOMID command 11.42 -# as is: It should contain the target IP address of the physical machine 11.43 -# to migrate to and optionally parameters like --live. Leave empty if 11.44 -# you don't want to try virtual machine relocation on shutdown. 11.45 -# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for 11.46 -# that domain. 11.47 -# 11.48 -XENDOMAINS_MIGRATE="" 11.49 - 11.50 -## Type: string 11.51 -## Default: /var/lib/xen/save 11.52 -# 11.53 -# Directory to save running domains to when the system (dom0) is 11.54 -# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE 11.55 -# is set (see below). Leave empty to disable domain saving on shutdown 11.56 -# (e.g. because you rather shut domains down). 11.57 -# If domain saving does succeed, SHUTDOWN will not be executed. 11.58 -# 11.59 -XENDOMAINS_SAVE=/var/lib/xen/save 11.60 - 11.61 -## Type: string 11.62 -## Default: "--halt --wait" 11.63 -# 11.64 -# If neither MIGRATE nor SAVE were enabled or if they failed, you can 11.65 -# try to shut down a domain by sending it a shutdown request. To do this, 11.66 -# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting 11.67 -# for the domain to be really down. Leave empty to skip domain shutdown. 11.68 -# 11.69 -XENDOMAINS_SHUTDOWN="--halt --wait" 11.70 - 11.71 -## Type: string 11.72 -## Default: "--all --halt --wait" 11.73 -# 11.74 -# After we have gone over all virtual machines (resp. all automatically 11.75 -# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, 11.76 -# migrated, saved and/or shutdown according to the settings above, we 11.77 -# might want to shutdown the virtual machines that are still running 11.78 -# for some reason or another. To do this, set this variable to 11.79 -# "--all --halt --wait", it will be passed to xm shutdown. 11.80 -# Leave it empty not to do anything special here. 11.81 -# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY 11.82 -# is set.) 11.83 -# 11.84 -XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" 11.85 - 11.86 -## Type: boolean 11.87 -## Default: true 11.88 -# 11.89 -# This variable determines whether saved domains from XENDOMAINS_SAVE 11.90 -# will be restored on system startup. 11.91 -# 11.92 -XENDOMAINS_RESTORE=true 11.93 - 11.94 -## Type: string 11.95 -## Default: /etc/xen/auto 11.96 -# 11.97 -# This variable sets the directory where domains configurations 11.98 -# are stored that should be started on system startup automatically. 11.99 -# Leave empty if you don't want to start domains automatically 11.100 -# (or just don't place any xen domain config files in that dir). 11.101 -# Note that the script tries to be clever if both RESTORE and AUTO are 11.102 -# set: It will first restore saved domains and then only start domains 11.103 -# in AUTO which are not running yet. 11.104 -# Note that the name matching is somewhat fuzzy. 11.105 -# 11.106 -XENDOMAINS_AUTO=/etc/xen/auto 11.107 - 11.108 -## Type: boolean 11.109 -## Default: false 11.110 -# 11.111 -# If this variable is set to "true", only the domains started via config 11.112 -# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, 11.113 -# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise 11.114 -# all running domains will be. 11.115 -# Note that the name matching is somewhat fuzzy. 11.116 -# 11.117 -XENDOMAINS_AUTO_ONLY=false 11.118 - 11.119 -## Type: integer 11.120 -## Default: 300 11.121 -# 11.122 -# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, 11.123 -# shutdown --all) may be executed. In the worst case, these commands may 11.124 -# stall forever, which will prevent a successful shutdown of the machine. 11.125 -# If this variable is non-zero, the script will set up a watchdog timer 11.126 -# for every of these xm commands and time it out after the number of seconds 11.127 -# specified by this variable. 11.128 -# Note that SHUTDOWN_ALL will not be called if no virtual machines or only 11.129 -# zombies are still running, so you don't need to enable this timeout just 11.130 -# for the zombie case. 11.131 -# The setting should be large enough to make sure that migrate/save/shutdown 11.132 -# can succeed. If you do live migrations, keep in mind that live migration 11.133 -# of a 1GB machine over Gigabit ethernet may actually take something like 11.134 -# 100s (assuming that live migration uses 10% of the network # bandwidth). 11.135 -# Depending on the virtual machine, a shutdown may also require a significant 11.136 -# amount of time. So better setup this variable to a huge number and hope the 11.137 -# watchdog never fires. 11.138 -# 11.139 -XENDOMAINS_STOP_MAXWAIT=300 11.140 -
12.1 --- a/tools/examples/init.d/xend Tue Nov 18 10:55:51 2008 +0100 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,66 +0,0 @@ 12.4 -#!/bin/bash 12.5 -# 12.6 -# xend Script to start and stop the Xen control daemon. 12.7 -# 12.8 -# Author: Keir Fraser <keir.fraser@cl.cam.ac.uk> 12.9 -# 12.10 -# chkconfig: 2345 98 01 12.11 -# description: Starts and stops the Xen control daemon. 12.12 -### BEGIN INIT INFO 12.13 -# Provides: xend 12.14 -# Required-Start: $syslog $remote_fs 12.15 -# Should-Start: 12.16 -# Required-Stop: $syslog $remote_fs 12.17 -# Should-Stop: 12.18 -# Default-Start: 3 4 5 12.19 -# Default-Stop: 0 1 2 6 12.20 -# Default-Enabled: yes 12.21 -# Short-Description: Start/stop xend 12.22 -# Description: Starts and stops the Xen control daemon. 12.23 -### END INIT INFO 12.24 - 12.25 -if ! grep -q "control_d" /proc/xen/capabilities ; then 12.26 - exit 0 12.27 -fi 12.28 - 12.29 -# Wait for Xend to be up 12.30 -function await_daemons_up 12.31 -{ 12.32 - i=1 12.33 - rets=10 12.34 - xend status 12.35 - while [ $? -ne 0 -a $i -lt $rets ]; do 12.36 - sleep 1 12.37 - echo -n . 12.38 - i=$(($i + 1)) 12.39 - xend status 12.40 - done 12.41 -} 12.42 - 12.43 -case "$1" in 12.44 - start) 12.45 - xend start 12.46 - await_daemons_up 12.47 - ;; 12.48 - stop) 12.49 - xend stop 12.50 - ;; 12.51 - status) 12.52 - xend status 12.53 - ;; 12.54 - reload) 12.55 - xend reload 12.56 - ;; 12.57 - restart|force-reload) 12.58 - xend restart 12.59 - await_daemons_up 12.60 - ;; 12.61 - *) 12.62 - # do not advertise unreasonable commands that there is no reason 12.63 - # to use with this device 12.64 - echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" 12.65 - exit 1 12.66 -esac 12.67 - 12.68 -exit $? 12.69 -
13.1 --- a/tools/examples/init.d/xendomains Tue Nov 18 10:55:51 2008 +0100 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,531 +0,0 @@ 13.4 -#!/bin/bash 13.5 -# 13.6 -# /etc/init.d/xendomains 13.7 -# Start / stop domains automatically when domain 0 boots / shuts down. 13.8 -# 13.9 -# chkconfig: 345 99 00 13.10 -# description: Start / stop Xen domains. 13.11 -# 13.12 -# This script offers fairly basic functionality. It should work on Redhat 13.13 -# but also on LSB-compliant SuSE releases and on Debian with the LSB package 13.14 -# installed. (LSB is the Linux Standard Base) 13.15 -# 13.16 -# Based on the example in the "Designing High Quality Integrated Linux 13.17 -# Applications HOWTO" by Avi Alkalay 13.18 -# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/> 13.19 -# 13.20 -### BEGIN INIT INFO 13.21 -# Provides: xendomains 13.22 -# Required-Start: $syslog $remote_fs xend 13.23 -# Should-Start: 13.24 -# Required-Stop: $syslog $remote_fs xend 13.25 -# Should-Stop: 13.26 -# Default-Start: 3 4 5 13.27 -# Default-Stop: 0 1 2 6 13.28 -# Default-Enabled: yes 13.29 -# Short-Description: Start/stop secondary xen domains 13.30 -# Description: Start / stop domains automatically when domain 0 13.31 -# boots / shuts down. 13.32 -### END INIT INFO 13.33 - 13.34 -# Correct exit code would probably be 5, but it's enough 13.35 -# if xend complains if we're not running as privileged domain 13.36 -if ! [ -e /proc/xen/privcmd ]; then 13.37 - exit 0 13.38 -fi 13.39 - 13.40 -LOCKFILE=/var/lock/subsys/xendomains 13.41 -XENDOM_CONFIG=/etc/sysconfig/xendomains 13.42 - 13.43 -test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing"; 13.44 - if [ "$1" = "stop" ]; then exit 0; 13.45 - else exit 6; fi; } 13.46 - 13.47 -. $XENDOM_CONFIG 13.48 - 13.49 -# Use the SUSE rc_ init script functions; 13.50 -# emulate them on LSB, RH and other systems 13.51 -if test -e /etc/rc.status; then 13.52 - # SUSE rc script library 13.53 - . /etc/rc.status 13.54 -else 13.55 - _cmd=$1 13.56 - declare -a _SMSG 13.57 - if test "${_cmd}" = "status"; then 13.58 - _SMSG=(running dead dead unused unknown) 13.59 - _RC_UNUSED=3 13.60 - else 13.61 - _SMSG=(done failed failed missed failed skipped unused failed failed) 13.62 - _RC_UNUSED=6 13.63 - fi 13.64 - if test -e /etc/init.d/functions; then 13.65 - # REDHAT 13.66 - . /etc/init.d/functions 13.67 - echo_rc() 13.68 - { 13.69 - #echo -n " [${_SMSG[${_RC_RV}]}] " 13.70 - if test ${_RC_RV} = 0; then 13.71 - success " [${_SMSG[${_RC_RV}]}] " 13.72 - else 13.73 - failure " [${_SMSG[${_RC_RV}]}] " 13.74 - fi 13.75 - } 13.76 - elif test -e /lib/lsb/init-functions; then 13.77 - # LSB 13.78 - . /lib/lsb/init-functions 13.79 - if alias log_success_msg >/dev/null 2>/dev/null; then 13.80 - echo_rc() 13.81 - { 13.82 - echo " [${_SMSG[${_RC_RV}]}] " 13.83 - } 13.84 - else 13.85 - echo_rc() 13.86 - { 13.87 - if test ${_RC_RV} = 0; then 13.88 - log_success_msg " [${_SMSG[${_RC_RV}]}] " 13.89 - else 13.90 - log_failure_msg " [${_SMSG[${_RC_RV}]}] " 13.91 - fi 13.92 - } 13.93 - fi 13.94 - else 13.95 - # emulate it 13.96 - echo_rc() 13.97 - { 13.98 - echo " [${_SMSG[${_RC_RV}]}] " 13.99 - } 13.100 - fi 13.101 - rc_reset() { _RC_RV=0; } 13.102 - rc_failed() 13.103 - { 13.104 - if test -z "$1"; then 13.105 - _RC_RV=1; 13.106 - elif test "$1" != "0"; then 13.107 - _RC_RV=$1; 13.108 - fi 13.109 - return ${_RC_RV} 13.110 - } 13.111 - rc_check() 13.112 - { 13.113 - return rc_failed $? 13.114 - } 13.115 - rc_status() 13.116 - { 13.117 - rc_failed $? 13.118 - if test "$1" = "-r"; then _RC_RV=0; shift; fi 13.119 - if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi 13.120 - if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi 13.121 - if test "$1" = "-v"; then echo_rc; shift; fi 13.122 - if test "$1" = "-r"; then _RC_RV=0; shift; fi 13.123 - return ${_RC_RV} 13.124 - } 13.125 - rc_exit() { exit ${_RC_RV}; } 13.126 - rc_active() 13.127 - { 13.128 - if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi 13.129 - if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi 13.130 - return 1 13.131 - } 13.132 -fi 13.133 - 13.134 -if ! which usleep >&/dev/null 13.135 -then 13.136 - usleep() 13.137 - { 13.138 - if [ -n "$1" ] 13.139 - then 13.140 - sleep $(( $1 / 1000000 )) 13.141 - fi 13.142 - } 13.143 -fi 13.144 - 13.145 -# Reset status of this service 13.146 -rc_reset 13.147 - 13.148 -## 13.149 -# Returns 0 (success) if the given parameter names a directory, and that 13.150 -# directory is not empty. 13.151 -# 13.152 -contains_something() 13.153 -{ 13.154 - if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ] 13.155 - then 13.156 - return 0 13.157 - else 13.158 - return 1 13.159 - fi 13.160 -} 13.161 - 13.162 -# read name from xen config file 13.163 -rdname() 13.164 -{ 13.165 - NM=$(xm create --quiet --dryrun --defconfig "$1" | 13.166 - sed -n 's/^.*(name \(.*\))$/\1/p') 13.167 -} 13.168 - 13.169 -rdnames() 13.170 -{ 13.171 - NAMES= 13.172 - if ! contains_something "$XENDOMAINS_AUTO" 13.173 - then 13.174 - return 13.175 - fi 13.176 - for dom in $XENDOMAINS_AUTO/*; do 13.177 - rdname $dom 13.178 - if test -z $NAMES; then 13.179 - NAMES=$NM; 13.180 - else 13.181 - NAMES="$NAMES|$NM" 13.182 - fi 13.183 - done 13.184 -} 13.185 - 13.186 -parseln() 13.187 -{ 13.188 - if [[ "$1" =~ "\(domain" ]]; then 13.189 - name=;id= 13.190 - else if [[ "$1" =~ "\(name" ]]; then 13.191 - name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/') 13.192 - else if [[ "$1" =~ "\(domid" ]]; then 13.193 - id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/') 13.194 - fi; fi; fi 13.195 - 13.196 - [ -n "$name" -a -n "$id" ] && return 0 || return 1 13.197 -} 13.198 - 13.199 -is_running() 13.200 -{ 13.201 - rdname $1 13.202 - RC=1 13.203 - name=;id= 13.204 - while read LN; do 13.205 - parseln "$LN" || continue 13.206 - if test $id = 0; then continue; fi 13.207 - case $name in 13.208 - ($NM) 13.209 - RC=0 13.210 - ;; 13.211 - esac 13.212 - done < <(xm list -l | grep '(\(domain\|domid\|name\)') 13.213 - return $RC 13.214 -} 13.215 - 13.216 -start() 13.217 -{ 13.218 - if [ -f $LOCKFILE ]; then 13.219 - echo -n "xendomains already running (lockfile exists)" 13.220 - return; 13.221 - fi 13.222 - 13.223 - saved_domains=" " 13.224 - if [ "$XENDOMAINS_RESTORE" = "true" ] && 13.225 - contains_something "$XENDOMAINS_SAVE" 13.226 - then 13.227 - mkdir -p $(dirname "$LOCKFILE") 13.228 - touch $LOCKFILE 13.229 - echo -n "Restoring Xen domains:" 13.230 - saved_domains=`ls $XENDOMAINS_SAVE` 13.231 - for dom in $XENDOMAINS_SAVE/*; do 13.232 - if [ -f $dom ] ; then 13.233 - HEADER=`head -c 16 $dom | head -n 1 2> /dev/null` 13.234 - if [ $HEADER = "LinuxGuestRecord" ]; then 13.235 - echo -n " ${dom##*/}" 13.236 - xm restore $dom 13.237 - if [ $? -ne 0 ]; then 13.238 - rc_failed $? 13.239 - echo -n '!' 13.240 - else 13.241 - # mv $dom ${dom%/*}/.${dom##*/} 13.242 - rm $dom 13.243 - fi 13.244 - fi 13.245 - fi 13.246 - done 13.247 - echo . 13.248 - fi 13.249 - 13.250 - if contains_something "$XENDOMAINS_AUTO" 13.251 - then 13.252 - touch $LOCKFILE 13.253 - echo -n "Starting auto Xen domains:" 13.254 - # We expect config scripts for auto starting domains to be in 13.255 - # XENDOMAINS_AUTO - they could just be symlinks to files elsewhere 13.256 - 13.257 - # Create all domains with config files in XENDOMAINS_AUTO. 13.258 - # TODO: We should record which domain name belongs 13.259 - # so we have the option to selectively shut down / migrate later 13.260 - # If a domain statefile from $XENDOMAINS_SAVE matches a domain name 13.261 - # in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't 13.262 - # restore correctly it requires administrative attention. 13.263 - for dom in $XENDOMAINS_AUTO/*; do 13.264 - echo -n " ${dom##*/}" 13.265 - shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p') 13.266 - echo $saved_domains | grep -w $shortdom > /dev/null 13.267 - if [ $? -eq 0 ] || is_running $dom; then 13.268 - echo -n "(skip)" 13.269 - else 13.270 - xm create --quiet --defconfig $dom 13.271 - if [ $? -ne 0 ]; then 13.272 - rc_failed $? 13.273 - echo -n '!' 13.274 - else 13.275 - usleep $XENDOMAINS_CREATE_USLEEP 13.276 - fi 13.277 - fi 13.278 - done 13.279 - fi 13.280 -} 13.281 - 13.282 -all_zombies() 13.283 -{ 13.284 - name=;id= 13.285 - while read LN; do 13.286 - parseln "$LN" || continue 13.287 - if test $id = 0; then continue; fi 13.288 - if test "$state" != "-b---d" -a "$state" != "-----d"; then 13.289 - return 1; 13.290 - fi 13.291 - done < <(xm list -l | grep '(\(domain\|domid\|name\)') 13.292 - return 0 13.293 -} 13.294 - 13.295 -# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish; 13.296 -# if it has not exited by that time kill it, so the init script will 13.297 -# succeed within a finite amount of time; if $2 is nonnull, it will 13.298 -# kill the command as well as soon as no domain (except for zombies) 13.299 -# are left (used for shutdown --all). 13.300 -watchdog_xm() 13.301 -{ 13.302 - if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then 13.303 - exit 13.304 - fi 13.305 - usleep 20000 13.306 - for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do 13.307 - # exit if xm save/migrate/shutdown is finished 13.308 - PSAX=`ps axlw | grep "xm $1" | grep -v grep` 13.309 - if test -z "$PSAX"; then exit; fi 13.310 - echo -n "."; sleep 1 13.311 - # go to kill immediately if there's only zombies left 13.312 - if all_zombies && test -n "$2"; then break; fi 13.313 - done 13.314 - sleep 1 13.315 - read PSF PSUID PSPID PSPPID < <(echo "$PSAX") 13.316 - # kill xm $1 13.317 - kill $PSPID >/dev/null 2>&1 13.318 -} 13.319 - 13.320 -stop() 13.321 -{ 13.322 - # Collect list of domains to shut down 13.323 - if test "$XENDOMAINS_AUTO_ONLY" = "true"; then 13.324 - rdnames 13.325 - fi 13.326 - echo -n "Shutting down Xen domains:" 13.327 - name=;id= 13.328 - while read LN; do 13.329 - parseln "$LN" || continue 13.330 - if test $id = 0; then continue; fi 13.331 - echo -n " $name" 13.332 - if test "$XENDOMAINS_AUTO_ONLY" = "true"; then 13.333 - eval " 13.334 - case \"\$name\" in 13.335 - ($NAMES) 13.336 - # nothing 13.337 - ;; 13.338 - (*) 13.339 - echo -n '(skip)' 13.340 - continue 13.341 - ;; 13.342 - esac 13.343 - " 13.344 - fi 13.345 - # XENDOMAINS_SYSRQ chould be something like just "s" 13.346 - # or "s e i u" or even "s e s i u o" 13.347 - # for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so 13.348 - if test -n "$XENDOMAINS_SYSRQ"; then 13.349 - for sysrq in $XENDOMAINS_SYSRQ; do 13.350 - echo -n "(SR-$sysrq)" 13.351 - xm sysrq $id $sysrq 13.352 - if test $? -ne 0; then 13.353 - rc_failed $? 13.354 - echo -n '!' 13.355 - fi 13.356 - # usleep just ignores empty arg 13.357 - usleep $XENDOMAINS_USLEEP 13.358 - done 13.359 - fi 13.360 - if test "$state" = "-b---d" -o "$state" = "-----d"; then 13.361 - echo -n "(zomb)" 13.362 - continue 13.363 - fi 13.364 - if test -n "$XENDOMAINS_MIGRATE"; then 13.365 - echo -n "(migr)" 13.366 - watchdog_xm migrate & 13.367 - WDOG_PID=$! 13.368 - xm migrate $id $XENDOMAINS_MIGRATE 13.369 - if test $? -ne 0; then 13.370 - rc_failed $? 13.371 - echo -n '!' 13.372 - kill $WDOG_PID >/dev/null 2>&1 13.373 - else 13.374 - kill $WDOG_PID >/dev/null 2>&1 13.375 - continue 13.376 - fi 13.377 - fi 13.378 - if test -n "$XENDOMAINS_SAVE"; then 13.379 - echo -n "(save)" 13.380 - watchdog_xm save & 13.381 - WDOG_PID=$! 13.382 - mkdir -p "$XENDOMAINS_SAVE" 13.383 - xm save $id $XENDOMAINS_SAVE/$name 13.384 - if test $? -ne 0; then 13.385 - rc_failed $? 13.386 - echo -n '!' 13.387 - kill $WDOG_PID >/dev/null 2>&1 13.388 - else 13.389 - kill $WDOG_PID >/dev/null 2>&1 13.390 - continue 13.391 - fi 13.392 - fi 13.393 - if test -n "$XENDOMAINS_SHUTDOWN"; then 13.394 - # XENDOMAINS_SHUTDOWN should be "--halt --wait" 13.395 - echo -n "(shut)" 13.396 - watchdog_xm shutdown & 13.397 - WDOG_PID=$! 13.398 - xm shutdown $id $XENDOMAINS_SHUTDOWN 13.399 - if test $? -ne 0; then 13.400 - rc_failed $? 13.401 - echo -n '!' 13.402 - fi 13.403 - kill $WDOG_PID >/dev/null 2>&1 13.404 - fi 13.405 - done < <(xm list -l | grep '(\(domain\|domid\|name\)') 13.406 - 13.407 - # NB. this shuts down ALL Xen domains (politely), not just the ones in 13.408 - # AUTODIR/* 13.409 - # This is because it's easier to do ;-) but arguably if this script is run 13.410 - # on system shutdown then it's also the right thing to do. 13.411 - if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then 13.412 - # XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait" 13.413 - echo -n " SHUTDOWN_ALL " 13.414 - watchdog_xm shutdown 1 & 13.415 - WDOG_PID=$! 13.416 - xm shutdown $XENDOMAINS_SHUTDOWN_ALL 13.417 - if test $? -ne 0; then 13.418 - rc_failed $? 13.419 - echo -n '!' 13.420 - fi 13.421 - kill $WDOG_PID >/dev/null 2>&1 13.422 - fi 13.423 - 13.424 - # Unconditionally delete lock file 13.425 - rm -f $LOCKFILE 13.426 -} 13.427 - 13.428 -check_domain_up() 13.429 -{ 13.430 - name=;id= 13.431 - while read LN; do 13.432 - parseln "$LN" || continue 13.433 - if test $id = 0; then continue; fi 13.434 - case $name in 13.435 - ($1) 13.436 - return 0 13.437 - ;; 13.438 - esac 13.439 - done < <(xm list -l | grep '(\(domain\|domid\|name\)') 13.440 - return 1 13.441 -} 13.442 - 13.443 -check_all_auto_domains_up() 13.444 -{ 13.445 - if ! contains_something "$XENDOMAINS_AUTO" 13.446 - then 13.447 - return 0 13.448 - fi 13.449 - missing= 13.450 - for nm in $XENDOMAINS_AUTO/*; do 13.451 - rdname $nm 13.452 - found=0 13.453 - if check_domain_up "$NM"; then 13.454 - echo -n " $name" 13.455 - else 13.456 - missing="$missing $NM" 13.457 - fi 13.458 - done 13.459 - if test -n "$missing"; then 13.460 - echo -n " MISS AUTO:$missing" 13.461 - return 1 13.462 - fi 13.463 - return 0 13.464 -} 13.465 - 13.466 -check_all_saved_domains_up() 13.467 -{ 13.468 - if ! contains_something "$XENDOMAINS_SAVE" 13.469 - then 13.470 - return 0 13.471 - fi 13.472 - missing=`/bin/ls $XENDOMAINS_SAVE` 13.473 - echo -n " MISS SAVED: " $missing 13.474 - return 1 13.475 -} 13.476 - 13.477 -# This does NOT necessarily restart all running domains: instead it 13.478 -# stops all running domains and then boots all the domains specified in 13.479 -# AUTODIR. If other domains have been started manually then they will 13.480 -# not get restarted. 13.481 -# Commented out to avoid confusion! 13.482 - 13.483 -restart() 13.484 -{ 13.485 - stop 13.486 - start 13.487 -} 13.488 - 13.489 -reload() 13.490 -{ 13.491 - restart 13.492 -} 13.493 - 13.494 - 13.495 -case "$1" in 13.496 - start) 13.497 - start 13.498 - rc_status 13.499 - if test -f $LOCKFILE; then rc_status -v; fi 13.500 - ;; 13.501 - 13.502 - stop) 13.503 - stop 13.504 - rc_status -v 13.505 - ;; 13.506 - 13.507 - restart) 13.508 - restart 13.509 - ;; 13.510 - reload) 13.511 - reload 13.512 - ;; 13.513 - 13.514 - status) 13.515 - echo -n "Checking for xendomains:" 13.516 - if test ! -f $LOCKFILE; then 13.517 - rc_failed 3 13.518 - else 13.519 - check_all_auto_domains_up 13.520 - rc_status 13.521 - check_all_saved_domains_up 13.522 - rc_status 13.523 - fi 13.524 - rc_status -v 13.525 - ;; 13.526 - 13.527 - *) 13.528 - echo "Usage: $0 {start|stop|restart|reload|status}" 13.529 - rc_failed 3 13.530 - rc_status -v 13.531 - ;; 13.532 -esac 13.533 - 13.534 -rc_exit
14.1 --- a/tools/examples/locking.sh Tue Nov 18 10:55:51 2008 +0100 14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 14.3 @@ -1,98 +0,0 @@ 14.4 -# 14.5 -# Copyright (c) 2005 XenSource Ltd. 14.6 -# 14.7 -# This library is free software; you can redistribute it and/or 14.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 14.9 -# License as published by the Free Software Foundation. 14.10 -# 14.11 -# This library is distributed in the hope that it will be useful, 14.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 14.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14.14 -# Lesser General Public License for more details. 14.15 -# 14.16 -# You should have received a copy of the GNU Lesser General Public 14.17 -# License along with this library; if not, write to the Free Software 14.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14.19 -# 14.20 - 14.21 -# 14.22 -# Serialisation 14.23 -# 14.24 - 14.25 -LOCK_SLEEPTIME=1 14.26 -LOCK_SPINNING_RETRIES=5 14.27 -LOCK_RETRIES=100 14.28 -LOCK_BASEDIR=/var/run/xen-hotplug 14.29 - 14.30 - 14.31 -claim_lock() 14.32 -{ 14.33 - local lockdir="$LOCK_BASEDIR/$1" 14.34 - mkdir -p "$LOCK_BASEDIR" 14.35 - _claim_lock "$lockdir" 14.36 -} 14.37 - 14.38 - 14.39 -release_lock() 14.40 -{ 14.41 - _release_lock "$LOCK_BASEDIR/$1" 14.42 -} 14.43 - 14.44 - 14.45 -_claim_lock() 14.46 -{ 14.47 - local lockdir="$1" 14.48 - local owner=$(_lock_owner "$lockdir") 14.49 - local retries=0 14.50 - 14.51 - while [ $retries -lt $LOCK_RETRIES ] 14.52 - do 14.53 - mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR && 14.54 - _update_lock_info "$lockdir" && return 14.55 - 14.56 - local new_owner=$(_lock_owner "$lockdir") 14.57 - if [ "$new_owner" != "$owner" ] 14.58 - then 14.59 - owner="$new_owner" 14.60 - retries=0 14.61 - fi 14.62 - 14.63 - if [ $retries -gt $LOCK_SPINNING_RETRIES ] 14.64 - then 14.65 - sleep $LOCK_SLEEPTIME 14.66 - else 14.67 - sleep 0 14.68 - fi 14.69 - retries=$(($retries + 1)) 14.70 - done 14.71 - _steal_lock "$lockdir" 14.72 -} 14.73 - 14.74 - 14.75 -_release_lock() 14.76 -{ 14.77 - trap sigerr ERR 14.78 - rm -rf "$1" 2>/dev/null || true 14.79 -} 14.80 - 14.81 - 14.82 -_steal_lock() 14.83 -{ 14.84 - local lockdir="$1" 14.85 - local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown") 14.86 - log err "Forced to steal lock on $lockdir from $owner!" 14.87 - _release_lock "$lockdir" 14.88 - _claim_lock "$lockdir" 14.89 -} 14.90 - 14.91 - 14.92 -_lock_owner() 14.93 -{ 14.94 - cat "$1/owner" 2>/dev/null || echo "unknown" 14.95 -} 14.96 - 14.97 - 14.98 -_update_lock_info() 14.99 -{ 14.100 - echo "$$: $0" >"$1/owner" 14.101 -}
15.1 --- a/tools/examples/logging.sh Tue Nov 18 10:55:51 2008 +0100 15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 15.3 @@ -1,22 +0,0 @@ 15.4 -# 15.5 -# Copyright (c) 2005 XenSource Ltd. 15.6 -# 15.7 -# This library is free software; you can redistribute it and/or 15.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 15.9 -# License as published by the Free Software Foundation. 15.10 -# 15.11 -# This library is distributed in the hope that it will be useful, 15.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 15.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15.14 -# Lesser General Public License for more details. 15.15 -# 15.16 -# You should have received a copy of the GNU Lesser General Public 15.17 -# License along with this library; if not, write to the Free Software 15.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15.19 -# 15.20 - 15.21 -log() { 15.22 - local level="$1" 15.23 - shift 15.24 - logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2 15.25 -}
16.1 --- a/tools/examples/network-bridge Tue Nov 18 10:55:51 2008 +0100 16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 16.3 @@ -1,310 +0,0 @@ 16.4 -#!/bin/bash 16.5 -#============================================================================ 16.6 -# Default Xen network start/stop script. 16.7 -# Xend calls a network script when it starts. 16.8 -# The script name to use is defined in /etc/xen/xend-config.sxp 16.9 -# in the network-script field. 16.10 -# 16.11 -# This script creates a bridge (default ${netdev}), adds a device 16.12 -# (defaults to the device on the default gateway route) to it, copies 16.13 -# the IP addresses from the device to the bridge and adjusts the routes 16.14 -# accordingly. 16.15 -# 16.16 -# If all goes well, this should ensure that networking stays up. 16.17 -# However, some configurations are upset by this, especially 16.18 -# NFS roots. If the bridged setup does not meet your needs, 16.19 -# configure a different script, for example using routing instead. 16.20 -# 16.21 -# Usage: 16.22 -# 16.23 -# network-bridge (start|stop|status) {VAR=VAL}* 16.24 -# 16.25 -# Vars: 16.26 -# 16.27 -# bridge The bridge to use (default ${netdev}). 16.28 -# netdev The interface to add to the bridge (default gateway device). 16.29 -# antispoof Whether to use iptables to prevent spoofing (default no). 16.30 -# 16.31 -# Internal Vars: 16.32 -# pdev="p${netdev}" 16.33 -# tdev=tmpbridge 16.34 -# 16.35 -# start: 16.36 -# Creates the bridge as tdev 16.37 -# Copies the IP and MAC addresses from pdev to bridge 16.38 -# Renames netdev to be pdev 16.39 -# Renames tdev to bridge 16.40 -# Enslaves pdev to bridge 16.41 -# 16.42 -# stop: 16.43 -# Removes pdev from the bridge 16.44 -# Transfers addresses, routes from bridge to pdev 16.45 -# Renames bridge to tdev 16.46 -# Renames pdev to netdev 16.47 -# Deletes tdev 16.48 -# 16.49 -# status: 16.50 -# Print addresses, interfaces, routes 16.51 -# 16.52 -#============================================================================ 16.53 - 16.54 - 16.55 -dir=$(dirname "$0") 16.56 -. "$dir/xen-script-common.sh" 16.57 -. "$dir/xen-network-common.sh" 16.58 - 16.59 -findCommand "$@" 16.60 -evalVariables "$@" 16.61 - 16.62 -is_network_root () { 16.63 - local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab) 16.64 - local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab) 16.65 - 16.66 - [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && has_nfsroot=1 || has_nfsroot=0 16.67 - if [ $has_nfsroot -eq 1 ]; then 16.68 - local bparms=$(cat /proc/cmdline) 16.69 - for p in $bparms; do 16.70 - local ipaddr=$(echo $p | awk /nfsroot=/'{ print substr($1,9,index($1,":")-9) }') 16.71 - if [ "$ipaddr" != "" ]; then 16.72 - local nfsdev=$(ip route get $ipaddr | awk /$ipaddr/'{ print $3 }') 16.73 - [[ "$nfsdev" == "$netdev" ]] && return 0 || return 1 16.74 - fi 16.75 - done 16.76 - fi 16.77 - return 1 16.78 -} 16.79 - 16.80 -find_alt_device () { 16.81 - local interf=$1 16.82 - local prefix=${interf%[[:digit:]]} 16.83 - local ifs=$(ip link show | grep " $prefix" |\ 16.84 - gawk '{ printf ("%s",substr($2,1,length($2)-1)) }' |\ 16.85 - sed s/$interf//) 16.86 - echo "$ifs" 16.87 -} 16.88 - 16.89 -netdev=${netdev:-$(ip route list 0.0.0.0/0 | \ 16.90 - sed 's/.*dev \([a-z]\+[0-9]\+\).*$/\1/')} 16.91 -if is_network_root ; then 16.92 - altdevs=$(find_alt_device $netdev) 16.93 - for netdev in $altdevs; do break; done 16.94 - if [ -z "$netdev" ]; then 16.95 - [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting" 16.96 - exit 16.97 - fi 16.98 -fi 16.99 -netdev=${netdev:-eth0} 16.100 -bridge=${bridge:-${netdev}} 16.101 -antispoof=${antispoof:-no} 16.102 - 16.103 -pdev="p${netdev}" 16.104 -tdev=tmpbridge 16.105 - 16.106 -get_ip_info() { 16.107 - addr_pfx=`ip addr show dev $1 | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'` 16.108 - gateway=`ip route show dev $1 | fgrep default | sed 's/default via //'` 16.109 -} 16.110 - 16.111 -do_ifup() { 16.112 - if ! ifup $1 ; then 16.113 - if [ -n "$addr_pfx" ] ; then 16.114 - # use the info from get_ip_info() 16.115 - ip addr flush $1 16.116 - ip addr add ${addr_pfx} dev $1 16.117 - ip link set dev $1 up 16.118 - [ -n "$gateway" ] && ip route add default via ${gateway} 16.119 - fi 16.120 - fi 16.121 -} 16.122 - 16.123 -# Usage: transfer_addrs src dst 16.124 -# Copy all IP addresses (including aliases) from device $src to device $dst. 16.125 -transfer_addrs () { 16.126 - local src=$1 16.127 - local dst=$2 16.128 - # Don't bother if $dst already has IP addresses. 16.129 - if ip addr show dev ${dst} | egrep -q '^ *inet ' ; then 16.130 - return 16.131 - fi 16.132 - # Address lines start with 'inet' and have the device in them. 16.133 - # Replace 'inet' with 'ip addr add' and change the device name $src 16.134 - # to 'dev $src'. 16.135 - ip addr show dev ${src} | egrep '^ *inet ' | sed -e " 16.136 -s/inet/ip addr add/ 16.137 -s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@ 16.138 -s/${src}/dev ${dst} label ${dst}/ 16.139 -s/secondary// 16.140 -" | sh -e 16.141 - # Remove automatic routes on destination device 16.142 - ip route list | sed -ne " 16.143 -/dev ${dst}\( \|$\)/ { 16.144 - s/^/ip route del / 16.145 - p 16.146 -}" | sh -e 16.147 -} 16.148 - 16.149 -# Usage: transfer_routes src dst 16.150 -# Get all IP routes to device $src, delete them, and 16.151 -# add the same routes to device $dst. 16.152 -# The original routes have to be deleted, otherwise adding them 16.153 -# for $dst fails (duplicate routes). 16.154 -transfer_routes () { 16.155 - local src=$1 16.156 - local dst=$2 16.157 - # List all routes and grep the ones with $src in. 16.158 - # Stick 'ip route del' on the front to delete. 16.159 - # Change $src to $dst and use 'ip route add' to add. 16.160 - ip route list | sed -ne " 16.161 -/dev ${src}\( \|$\)/ { 16.162 - h 16.163 - s/^/ip route del / 16.164 - P 16.165 - g 16.166 - s/${src}/${dst}/ 16.167 - s/^/ip route add / 16.168 - P 16.169 - d 16.170 -}" | sh -e 16.171 -} 16.172 - 16.173 - 16.174 -## 16.175 -# link_exists interface 16.176 -# 16.177 -# Returns 0 if the interface named exists (whether up or down), 1 otherwise. 16.178 -# 16.179 -link_exists() 16.180 -{ 16.181 - if ip link show "$1" >/dev/null 2>/dev/null 16.182 - then 16.183 - return 0 16.184 - else 16.185 - return 1 16.186 - fi 16.187 -} 16.188 - 16.189 -# Set the default forwarding policy for $dev to drop. 16.190 -# Allow forwarding to the bridge. 16.191 -antispoofing () { 16.192 - iptables -P FORWARD DROP 16.193 - iptables -F FORWARD 16.194 - iptables -A FORWARD -m physdev --physdev-in ${pdev} -j ACCEPT 16.195 -} 16.196 - 16.197 -# Usage: show_status dev bridge 16.198 -# Print ifconfig and routes. 16.199 -show_status () { 16.200 - local dev=$1 16.201 - local bridge=$2 16.202 - 16.203 - echo '============================================================' 16.204 - ip addr show ${dev} 16.205 - ip addr show ${bridge} 16.206 - echo ' ' 16.207 - brctl show ${bridge} 16.208 - echo ' ' 16.209 - ip route list 16.210 - echo ' ' 16.211 - route -n 16.212 - echo '============================================================' 16.213 -} 16.214 - 16.215 -op_start () { 16.216 - if [ "${bridge}" = "null" ] ; then 16.217 - return 16.218 - fi 16.219 - 16.220 - if link_exists "$pdev"; then 16.221 - # The device is already up. 16.222 - return 16.223 - fi 16.224 - 16.225 - create_bridge ${tdev} 16.226 - 16.227 - preiftransfer ${netdev} 16.228 - transfer_addrs ${netdev} ${tdev} 16.229 - if ! ifdown ${netdev}; then 16.230 - # If ifdown fails, remember the IP details. 16.231 - get_ip_info ${netdev} 16.232 - ip link set ${netdev} down 16.233 - ip addr flush ${netdev} 16.234 - fi 16.235 - ip link set ${netdev} name ${pdev} 16.236 - ip link set ${tdev} name ${bridge} 16.237 - 16.238 - setup_bridge_port ${pdev} 16.239 - 16.240 - add_to_bridge2 ${bridge} ${pdev} 16.241 - do_ifup ${bridge} 16.242 - 16.243 - if [ ${antispoof} = 'yes' ] ; then 16.244 - antispoofing 16.245 - fi 16.246 -} 16.247 - 16.248 -op_stop () { 16.249 - if [ "${bridge}" = "null" ]; then 16.250 - return 16.251 - fi 16.252 - if ! link_exists "$bridge"; then 16.253 - return 16.254 - fi 16.255 - 16.256 - transfer_addrs ${bridge} ${pdev} 16.257 - if ! ifdown ${bridge}; then 16.258 - get_ip_info ${bridge} 16.259 - fi 16.260 - ip link set ${pdev} down 16.261 - ip addr flush ${bridge} 16.262 - 16.263 - brctl delif ${bridge} ${pdev} 16.264 - ip link set ${bridge} down 16.265 - 16.266 - ip link set ${bridge} name ${tdev} 16.267 - ip link set ${pdev} name ${netdev} 16.268 - do_ifup ${netdev} 16.269 - 16.270 - brctl delbr ${tdev} 16.271 -} 16.272 - 16.273 -# adds $dev to $bridge but waits for $dev to be in running state first 16.274 -add_to_bridge2() { 16.275 - local bridge=$1 16.276 - local dev=$2 16.277 - local maxtries=10 16.278 - 16.279 - echo -n "Waiting for ${dev} to negotiate link." 16.280 - ip link set ${dev} up 16.281 - for i in `seq ${maxtries}` ; do 16.282 - if ifconfig ${dev} | grep -q RUNNING ; then 16.283 - break 16.284 - else 16.285 - echo -n '.' 16.286 - sleep 1 16.287 - fi 16.288 - done 16.289 - 16.290 - if [ ${i} -eq ${maxtries} ] ; then echo -n '(link isnt in running state)' ; fi 16.291 - echo 16.292 - 16.293 - add_to_bridge ${bridge} ${dev} 16.294 -} 16.295 - 16.296 -case "$command" in 16.297 - start) 16.298 - op_start 16.299 - ;; 16.300 - 16.301 - stop) 16.302 - op_stop 16.303 - ;; 16.304 - 16.305 - status) 16.306 - show_status ${netdev} ${bridge} 16.307 - ;; 16.308 - 16.309 - *) 16.310 - echo "Unknown command: $command" >&2 16.311 - echo 'Valid commands are: start, stop, status' >&2 16.312 - exit 1 16.313 -esac
17.1 --- a/tools/examples/network-nat Tue Nov 18 10:55:51 2008 +0100 17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 17.3 @@ -1,119 +0,0 @@ 17.4 -#!/bin/bash -x 17.5 -#============================================================================ 17.6 -# Default Xen network start/stop script when using NAT. 17.7 -# Xend calls a network script when it starts. 17.8 -# The script name to use is defined in /etc/xen/xend-config.sxp 17.9 -# in the network-script field. 17.10 -# 17.11 -# Usage: 17.12 -# 17.13 -# network-nat (start|stop|status) {VAR=VAL}* 17.14 -# 17.15 -# Vars: 17.16 -# 17.17 -# netdev The gateway interface (default eth0). 17.18 -# antispoof Whether to use iptables to prevent spoofing (default no). 17.19 -# dhcp Whether to alter the local DHCP configuration (default no). 17.20 -# 17.21 -#============================================================================ 17.22 - 17.23 -dir=$(dirname "$0") 17.24 -. "$dir/xen-script-common.sh" 17.25 -. "$dir/xen-network-common.sh" 17.26 - 17.27 -findCommand "$@" 17.28 -evalVariables "$@" 17.29 - 17.30 -netdev=${netdev:-eth0} 17.31 -# antispoofing not yet implemented 17.32 -antispoof=${antispoof:-no} 17.33 - 17.34 -# turn on dhcp feature by default if dhcpd is installed 17.35 -if [ -f /etc/dhcpd.conf ] 17.36 -then 17.37 - dhcp=${dhcp:-yes} 17.38 -else 17.39 - dhcp=${dhcp:-no} 17.40 -fi 17.41 - 17.42 - 17.43 -if [ "$dhcp" != 'no' ] 17.44 -then 17.45 - dhcpd_conf_file=$(find_dhcpd_conf_file) 17.46 - dhcpd_init_file=$(find_dhcpd_init_file) 17.47 - if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] 17.48 - then 17.49 - echo 'Failed to find dhcpd configuration or init file.' >&2 17.50 - exit 1 17.51 - fi 17.52 -fi 17.53 - 17.54 - 17.55 -function dhcp_start() 17.56 -{ 17.57 - if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file" 17.58 - then 17.59 - echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {}" 17.60 - fi 17.61 - 17.62 - "$dhcpd_init_file" restart 17.63 -} 17.64 - 17.65 - 17.66 -function dhcp_stop() 17.67 -{ 17.68 - local tmpfile=$(mktemp) 17.69 - grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile" 17.70 - if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null 17.71 - then 17.72 - rm "$tmpfile" 17.73 - else 17.74 - mv "$tmpfile" "$dhcpd_conf_file" 17.75 - fi 17.76 - 17.77 - "$dhcpd_init_file" restart 17.78 -} 17.79 - 17.80 - 17.81 -op_start() { 17.82 - echo 1 >/proc/sys/net/ipv4/ip_forward 17.83 - iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE 17.84 - [ "$dhcp" != 'no' ] && dhcp_start 17.85 -} 17.86 - 17.87 - 17.88 -op_stop() { 17.89 - [ "$dhcp" != 'no' ] && dhcp_stop 17.90 - iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE 17.91 -} 17.92 - 17.93 - 17.94 -show_status() { 17.95 - echo '============================================================' 17.96 - ifconfig 17.97 - echo ' ' 17.98 - ip route list 17.99 - echo ' ' 17.100 - route -n 17.101 - echo '============================================================' 17.102 - 17.103 -} 17.104 - 17.105 -case "$command" in 17.106 - start) 17.107 - op_start 17.108 - ;; 17.109 - 17.110 - stop) 17.111 - op_stop 17.112 - ;; 17.113 - 17.114 - status) 17.115 - show_status 17.116 - ;; 17.117 - 17.118 - *) 17.119 - echo "Unknown command: $command" >&2 17.120 - echo 'Valid commands are: start, stop, status' >&2 17.121 - exit 1 17.122 -esac
18.1 --- a/tools/examples/network-route Tue Nov 18 10:55:51 2008 +0100 18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 18.3 @@ -1,27 +0,0 @@ 18.4 -#!/bin/bash 18.5 -#============================================================================ 18.6 -# Default Xen network start/stop script. 18.7 -# Xend calls a network script when it starts. 18.8 -# The script name to use is defined in /etc/xen/xend-config.sxp 18.9 -# in the network-script field. 18.10 -# 18.11 -# Usage: 18.12 -# 18.13 -# network-route (start|stop|status) {VAR=VAL}* 18.14 -# 18.15 -# Vars: 18.16 -# 18.17 -# netdev The gateway interface (default eth0). 18.18 -# antispoof Whether to use iptables to prevent spoofing (default yes). 18.19 -# 18.20 -#============================================================================ 18.21 - 18.22 -dir=$(dirname "$0") 18.23 -. "$dir/xen-script-common.sh" 18.24 - 18.25 -evalVariables "$@" 18.26 - 18.27 -netdev=${netdev:-eth${vifnum}} 18.28 - 18.29 -echo 1 >/proc/sys/net/ipv4/ip_forward 18.30 -echo 1 >/proc/sys/net/ipv4/conf/${netdev}/proxy_arp
19.1 --- a/tools/examples/vif-bridge Tue Nov 18 10:55:51 2008 +0100 19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 19.3 @@ -1,100 +0,0 @@ 19.4 -#!/bin/bash 19.5 -#============================================================================ 19.6 -# /etc/xen/vif-bridge 19.7 -# 19.8 -# Script for configuring a vif in bridged mode. 19.9 -# The hotplugging system will call this script if it is specified either in 19.10 -# the device configuration given to Xend, or the default Xend configuration 19.11 -# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 19.12 -# places, then this script is the default. 19.13 -# 19.14 -# Usage: 19.15 -# vif-bridge (add|remove|online|offline) 19.16 -# 19.17 -# Environment vars: 19.18 -# vif vif interface name (required). 19.19 -# XENBUS_PATH path to this device's details in the XenStore (required). 19.20 -# 19.21 -# Read from the store: 19.22 -# bridge bridge to add the vif to (optional). Defaults to searching for the 19.23 -# bridge itself. 19.24 -# ip list of IP networks for the vif, space-separated (optional). 19.25 -# 19.26 -# up: 19.27 -# Enslaves the vif interface to the bridge and adds iptables rules 19.28 -# for its ip addresses (if any). 19.29 -# 19.30 -# down: 19.31 -# Removes the vif interface from the bridge and removes the iptables 19.32 -# rules for its ip addresses (if any). 19.33 -#============================================================================ 19.34 - 19.35 -dir=$(dirname "$0") 19.36 -. "$dir/vif-common.sh" 19.37 - 19.38 -bridge=${bridge:-} 19.39 -bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge") 19.40 - 19.41 -if [ -z "$bridge" ] 19.42 -then 19.43 - bridge=$(brctl show | cut -d " 19.44 -" -f 2 | cut -f 1) 19.45 - 19.46 - if [ -z "$bridge" ] 19.47 - then 19.48 - fatal "Could not find bridge, and none was specified" 19.49 - fi 19.50 -else 19.51 - # 19.52 - # Old style bridge setup with netloop, used to have a bridge name 19.53 - # of xenbrX, enslaving pethX and vif0.X, and then configuring 19.54 - # eth0. 19.55 - # 19.56 - # New style bridge setup does not use netloop, so the bridge name 19.57 - # is ethX and the physical device is enslaved pethX 19.58 - # 19.59 - # So if... 19.60 - # 19.61 - # - User asks for xenbrX 19.62 - # - AND xenbrX doesn't exist 19.63 - # - AND there is a ethX device which is a bridge 19.64 - # 19.65 - # ..then we translate xenbrX to ethX 19.66 - # 19.67 - # This lets old config files work without modification 19.68 - # 19.69 - if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ] 19.70 - then 19.71 - if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ] 19.72 - then 19.73 - bridge="eth${bridge#xenbr}" 19.74 - fi 19.75 - fi 19.76 -fi 19.77 - 19.78 -RET=0 19.79 -ip link show $bridge 1>/dev/null 2>&1 || RET=1 19.80 -if [ "$RET" -eq 1 ] 19.81 -then 19.82 - fatal "Could not find bridge device $bridge" 19.83 -fi 19.84 - 19.85 -case "$command" in 19.86 - online) 19.87 - setup_bridge_port "$vif" 19.88 - add_to_bridge "$bridge" "$vif" 19.89 - ;; 19.90 - 19.91 - offline) 19.92 - do_without_error brctl delif "$bridge" "$vif" 19.93 - do_without_error ifconfig "$vif" down 19.94 - ;; 19.95 -esac 19.96 - 19.97 -handle_iptable 19.98 - 19.99 -log debug "Successful vif-bridge $command for $vif, bridge $bridge." 19.100 -if [ "$command" == "online" ] 19.101 -then 19.102 - success 19.103 -fi
20.1 --- a/tools/examples/vif-common.sh Tue Nov 18 10:55:51 2008 +0100 20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 20.3 @@ -1,151 +0,0 @@ 20.4 -# 20.5 -# Copyright (c) 2005 XenSource Ltd. 20.6 -# 20.7 -# This library is free software; you can redistribute it and/or 20.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 20.9 -# License as published by the Free Software Foundation. 20.10 -# 20.11 -# This library is distributed in the hope that it will be useful, 20.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 20.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20.14 -# Lesser General Public License for more details. 20.15 -# 20.16 -# You should have received a copy of the GNU Lesser General Public 20.17 -# License along with this library; if not, write to the Free Software 20.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20.19 -# 20.20 - 20.21 - 20.22 -dir=$(dirname "$0") 20.23 -. "$dir/xen-hotplug-common.sh" 20.24 -. "$dir/xen-network-common.sh" 20.25 - 20.26 -findCommand "$@" 20.27 - 20.28 -if [ "$command" != "online" ] && 20.29 - [ "$command" != "offline" ] && 20.30 - [ "$command" != "add" ] && 20.31 - [ "$command" != "remove" ] 20.32 -then 20.33 - log err "Invalid command: $command" 20.34 - exit 1 20.35 -fi 20.36 - 20.37 -case "$command" in 20.38 - add | remove) 20.39 - exit 0 20.40 - ;; 20.41 -esac 20.42 - 20.43 - 20.44 -# Parameters may be read from the environment, the command line arguments, and 20.45 -# the store, with overriding in that order. The environment is given by the 20.46 -# driver, the command line is given by the Xend global configuration, and 20.47 -# store details are given by the per-domain or per-device configuration. 20.48 - 20.49 -evalVariables "$@" 20.50 - 20.51 -ip=${ip:-} 20.52 -ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") 20.53 - 20.54 -# Check presence of compulsory args. 20.55 -XENBUS_PATH="${XENBUS_PATH:?}" 20.56 -vif="${vif:?}" 20.57 - 20.58 - 20.59 -vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "") 20.60 -if [ "$vifname" ] 20.61 -then 20.62 - if [ "$command" == "online" ] && ! ip link show "$vifname" >&/dev/null 20.63 - then 20.64 - do_or_die ip link set "$vif" name "$vifname" 20.65 - fi 20.66 - vif="$vifname" 20.67 -fi 20.68 - 20.69 - 20.70 -frob_iptable() 20.71 -{ 20.72 - if [ "$command" == "online" ] 20.73 - then 20.74 - local c="-A" 20.75 - else 20.76 - local c="-D" 20.77 - fi 20.78 - 20.79 - iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \ 20.80 - 2>/dev/null || 20.81 - [ "$c" == "-D" ] || 20.82 - log err \ 20.83 - "iptables $c FORWARD -m physdev --physdev-in $vif $@ -j ACCEPT failed. 20.84 -If you are using iptables, this may affect networking for guest domains." 20.85 -} 20.86 - 20.87 - 20.88 -## 20.89 -# Add or remove the appropriate entries in the iptables. With antispoofing 20.90 -# turned on, we have to explicitly allow packets to the interface, regardless 20.91 -# of the ip setting. If ip is set, then we additionally restrict the packets 20.92 -# to those coming from the specified networks, though we allow DHCP requests 20.93 -# as well. 20.94 -# 20.95 -handle_iptable() 20.96 -{ 20.97 - # Check for a working iptables installation. Checking for the iptables 20.98 - # binary is not sufficient, because the user may not have the appropriate 20.99 - # modules installed. If iptables is not working, then there's no need to do 20.100 - # anything with it, so we can just return. 20.101 - if ! iptables -L -n >&/dev/null 20.102 - then 20.103 - return 20.104 - fi 20.105 - 20.106 - if [ "$ip" != "" ] 20.107 - then 20.108 - local addr 20.109 - for addr in $ip 20.110 - do 20.111 - frob_iptable -s "$addr" 20.112 - done 20.113 - 20.114 - # Always allow the domain to talk to a DHCP server. 20.115 - frob_iptable -p udp --sport 68 --dport 67 20.116 - else 20.117 - # No IP addresses have been specified, so allow anything. 20.118 - frob_iptable 20.119 - fi 20.120 -} 20.121 - 20.122 - 20.123 -## 20.124 -# ip_of interface 20.125 -# 20.126 -# Print the IP address currently in use at the given interface, or nothing if 20.127 -# the interface is not up. 20.128 -# 20.129 -ip_of() 20.130 -{ 20.131 - ip addr show "$1" | awk "/^.*inet.*$1\$/{print \$2}" | sed -n '1 s,/.*,,p' 20.132 -} 20.133 - 20.134 - 20.135 -## 20.136 -# dom0_ip 20.137 -# 20.138 -# Print the IP address of the interface in dom0 through which we are routing. 20.139 -# This is the IP address on the interface specified as "netdev" as a parameter 20.140 -# to these scripts, or eth0 by default. This function will call fatal if no 20.141 -# such interface could be found. 20.142 -# 20.143 -dom0_ip() 20.144 -{ 20.145 - local nd=${netdev:-eth0} 20.146 - local result=$(ip_of "$nd") 20.147 - if [ -z "$result" ] 20.148 - then 20.149 - fatal 20.150 -"$netdev is not up. Bring it up or specify another interface with " \ 20.151 -"netdev=<if> as a parameter to $0." 20.152 - fi 20.153 - echo "$result" 20.154 -}
21.1 --- a/tools/examples/vif-nat Tue Nov 18 10:55:51 2008 +0100 21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 21.3 @@ -1,192 +0,0 @@ 21.4 -#!/bin/bash 21.5 -#============================================================================ 21.6 -# /etc/xen/vif-nat 21.7 -# 21.8 -# Script for configuring a vif in routed-nat mode. 21.9 -# The hotplugging system will call this script if it is specified either in 21.10 -# the device configuration given to Xend, or the default Xend configuration 21.11 -# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 21.12 -# places, then vif-bridge is the default. 21.13 -# 21.14 -# Usage: 21.15 -# vif-nat (add|remove|online|offline) 21.16 -# 21.17 -# Environment vars: 21.18 -# vif vif interface name (required). 21.19 -# XENBUS_PATH path to this device's details in the XenStore (required). 21.20 -# 21.21 -# Parameters: 21.22 -# dhcp Whether to alter the local DHCP configuration to include this 21.23 -# new host (default no). 21.24 -# 21.25 -# Read from the store: 21.26 -# ip list of IP networks for the vif, space-separated (default given in 21.27 -# this script). 21.28 -#============================================================================ 21.29 - 21.30 - 21.31 -dir=$(dirname "$0") 21.32 -. "$dir/vif-common.sh" 21.33 - 21.34 -# turn on dhcp feature by default if dhcpd is installed 21.35 -if [ -f /etc/dhcpd.conf ] 21.36 -then 21.37 - dhcp=${dhcp:-yes} 21.38 -else 21.39 - dhcp=${dhcp:-no} 21.40 -fi 21.41 - 21.42 -if [ "$dhcp" != 'no' ] 21.43 -then 21.44 - dhcpd_conf_file=$(find_dhcpd_conf_file) 21.45 - dhcpd_init_file=$(find_dhcpd_init_file) 21.46 - dhcpd_arg_file=$(find_dhcpd_arg_file) 21.47 - if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] || [ -z "$dhcpd_arg_file" ] 21.48 - then 21.49 - echo 'Failed to find dhcpd configuration or init or args file.' >&2 21.50 - exit 1 21.51 - fi 21.52 -fi 21.53 - 21.54 - 21.55 -domid=$(xenstore_read "$XENBUS_PATH/frontend-id") 21.56 -vifid=$(xenstore_read "$XENBUS_PATH/handle") 21.57 -vifid=$(( $vifid + 1 )) 21.58 - 21.59 - 21.60 -ip_from_dom() 21.61 -{ 21.62 - local domid1=$(( $domid / 256 )) 21.63 - local domid2=$(( $domid % 256 )) 21.64 - 21.65 - echo "10.$domid1.$domid2.$vifid/16" 21.66 -} 21.67 - 21.68 - 21.69 -routing_ip() 21.70 -{ 21.71 - echo $(echo $1 | awk -F. '{print $1"."$2"."$3"."$4 + 127}') 21.72 -} 21.73 - 21.74 - 21.75 -dotted_quad() 21.76 -{ 21.77 - echo\ 21.78 - $(( ($1 & 0xFF000000) >> 24))\ 21.79 -.$(( ($1 & 0x00FF0000) >> 16))\ 21.80 -.$(( ($1 & 0x0000FF00) >> 8 ))\ 21.81 -.$(( $1 & 0x000000FF )) 21.82 -} 21.83 - 21.84 - 21.85 -if [ "$ip" = "" ] 21.86 -then 21.87 - ip=$(ip_from_dom) 21.88 -fi 21.89 - 21.90 -router_ip=$(routing_ip "$ip") 21.91 - 21.92 -# Split the given IP/bits pair. 21.93 -vif_ip=`echo ${ip} | awk -F/ '{print $1}'` 21.94 - 21.95 -hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----') 21.96 -if [ "$vifid" != "1" ] 21.97 -then 21.98 - hostname="$hostname-$vifid" 21.99 -fi 21.100 - 21.101 -dhcparg_remove_entry() 21.102 -{ 21.103 - local tmpfile=$(mktemp) 21.104 - sed -e "s/$vif //" "$dhcpd_arg_file" >"$tmpfile" 21.105 - if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null 21.106 - then 21.107 - rm "$tmpfile" 21.108 - else 21.109 - mv "$tmpfile" "$dhcpd_arg_file" 21.110 - fi 21.111 -} 21.112 - 21.113 -dhcparg_add_entry() 21.114 -{ 21.115 - dhcparg_remove_entry 21.116 - local tmpfile=$(mktemp) 21.117 - # handle Red Hat, SUSE, and Debian styles, with or without quotes 21.118 - sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"$vif "'"/' \ 21.119 - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 21.120 - sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"$vif "'"/' \ 21.121 - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 21.122 - sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"$vif "'"/' \ 21.123 - "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 21.124 - rm -f "$tmpfile" 21.125 -} 21.126 - 21.127 -dhcp_remove_entry() 21.128 -{ 21.129 - local tmpfile=$(mktemp) 21.130 - grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile" 21.131 - if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null 21.132 - then 21.133 - rm "$tmpfile" 21.134 - else 21.135 - mv "$tmpfile" "$dhcpd_conf_file" 21.136 - fi 21.137 - dhcparg_remove_entry 21.138 -} 21.139 - 21.140 - 21.141 -dhcp_up() 21.142 -{ 21.143 - claim_lock "vif-nat-dhcp" 21.144 - dhcp_remove_entry 21.145 - mac=$(xenstore_read "$XENBUS_PATH/mac") 21.146 - echo >>"$dhcpd_conf_file" \ 21.147 -"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }" 21.148 - dhcparg_add_entry 21.149 - release_lock "vif-nat-dhcp" 21.150 - "$dhcpd_init_file" restart || true 21.151 -} 21.152 - 21.153 - 21.154 -dhcp_down() 21.155 -{ 21.156 - claim_lock "vif-nat-dhcp" 21.157 - dhcp_remove_entry 21.158 - release_lock "vif-nat-dhcp" 21.159 - "$dhcpd_init_file" restart || true # We need to ignore failure because 21.160 - # ISC dhcpd 3 borks if there is nothing 21.161 - # for it to do, which is the case if 21.162 - # the outgoing interface is not 21.163 - # configured to offer leases and there 21.164 - # are no vifs. 21.165 -} 21.166 - 21.167 - 21.168 -case "$command" in 21.169 - online) 21.170 - if ip route | grep -q "dev $vif" 21.171 - then 21.172 - log debug "$vif already up" 21.173 - exit 0 21.174 - fi 21.175 - 21.176 - do_or_die ip link set "$vif" up arp on 21.177 - do_or_die ip addr add "$router_ip" dev "$vif" 21.178 - do_or_die ip route add "$vif_ip" dev "$vif" src "$router_ip" 21.179 - echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp 21.180 - [ "$dhcp" != 'no' ] && dhcp_up 21.181 - ;; 21.182 - offline) 21.183 - [ "$dhcp" != 'no' ] && dhcp_down 21.184 - do_without_error ifconfig "$vif" down 21.185 - ;; 21.186 -esac 21.187 - 21.188 - 21.189 -handle_iptable 21.190 - 21.191 -log debug "Successful vif-nat $command for $vif." 21.192 -if [ "$command" = "online" ] 21.193 -then 21.194 - success 21.195 -fi
22.1 --- a/tools/examples/vif-route Tue Nov 18 10:55:51 2008 +0100 22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 22.3 @@ -1,56 +0,0 @@ 22.4 -#!/bin/bash 22.5 -#============================================================================ 22.6 -# /etc/xen/vif-route 22.7 -# 22.8 -# Script for configuring a vif in routed mode. 22.9 -# The hotplugging system will call this script if it is specified either in 22.10 -# the device configuration given to Xend, or the default Xend configuration 22.11 -# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 22.12 -# places, then vif-bridge is the default. 22.13 -# 22.14 -# Usage: 22.15 -# vif-route (add|remove|online|offline) 22.16 -# 22.17 -# Environment vars: 22.18 -# vif vif interface name (required). 22.19 -# XENBUS_PATH path to this device's details in the XenStore (required). 22.20 -# 22.21 -# Read from the store: 22.22 -# ip list of IP networks for the vif, space-separated (default given in 22.23 -# this script). 22.24 -#============================================================================ 22.25 - 22.26 -dir=$(dirname "$0") 22.27 -. "$dir/vif-common.sh" 22.28 - 22.29 -main_ip=$(dom0_ip) 22.30 - 22.31 -case "$command" in 22.32 - online) 22.33 - ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up 22.34 - echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp 22.35 - ipcmd='add' 22.36 - cmdprefix='' 22.37 - ;; 22.38 - offline) 22.39 - do_without_error ifdown ${vif} 22.40 - ipcmd='del' 22.41 - cmdprefix='do_without_error' 22.42 - ;; 22.43 -esac 22.44 - 22.45 -if [ "${ip}" ] ; then 22.46 - # If we've been given a list of IP addresses, then add routes from dom0 to 22.47 - # the guest using those addresses. 22.48 - for addr in ${ip} ; do 22.49 - ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip} 22.50 - done 22.51 -fi 22.52 - 22.53 -handle_iptable 22.54 - 22.55 -log debug "Successful vif-route $command for $vif." 22.56 -if [ "$command" = "online" ] 22.57 -then 22.58 - success 22.59 -fi
23.1 --- a/tools/examples/vscsi Tue Nov 18 10:55:51 2008 +0100 23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 23.3 @@ -1,22 +0,0 @@ 23.4 -#!/bin/sh 23.5 -# 23.6 -# Copyright (c) 2007, FUJITSU Limited 23.7 -# Based on the block scripts code. 23.8 -# 23.9 - 23.10 -dir=$(dirname "$0") 23.11 -. "$dir/xen-hotplug-common.sh" 23.12 - 23.13 -findCommand "$@" 23.14 - 23.15 -case "$command" in 23.16 - add) 23.17 - success 23.18 - ;; 23.19 - remove) 23.20 - # TODO 23.21 - exit 0 23.22 - ;; 23.23 -esac 23.24 - 23.25 -exit 0
24.1 --- a/tools/examples/vtpm Tue Nov 18 10:55:51 2008 +0100 24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 24.3 @@ -1,22 +0,0 @@ 24.4 -#!/bin/bash 24.5 - 24.6 -dir=$(dirname "$0") 24.7 -. "$dir/vtpm-hotplug-common.sh" 24.8 - 24.9 -vtpm_fatal_error=0 24.10 - 24.11 -case "$command" in 24.12 - add) 24.13 - vtpm_create_instance 24.14 - ;; 24.15 - remove) 24.16 - vtpm_remove_instance 24.17 - ;; 24.18 -esac 24.19 - 24.20 -if [ $vtpm_fatal_error -eq 0 ]; then 24.21 - log debug "Successful vTPM operation '$command'." 24.22 - success 24.23 -else 24.24 - fatal "Error while executing vTPM operation '$command'." 24.25 -fi
25.1 --- a/tools/examples/vtpm-common.sh Tue Nov 18 10:55:51 2008 +0100 25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 25.3 @@ -1,448 +0,0 @@ 25.4 -# 25.5 -# Copyright (c) 2005 IBM Corporation 25.6 -# Copyright (c) 2005 XenSource Ltd. 25.7 -# 25.8 -# This library is free software; you can redistribute it and/or 25.9 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 25.10 -# License as published by the Free Software Foundation. 25.11 -# 25.12 -# This library is distributed in the hope that it will be useful, 25.13 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 25.14 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25.15 -# Lesser General Public License for more details. 25.16 -# 25.17 -# You should have received a copy of the GNU Lesser General Public 25.18 -# License along with this library; if not, write to the Free Software 25.19 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25.20 -# 25.21 - 25.22 -dir=$(dirname "$0") 25.23 -. "$dir/logging.sh" 25.24 -. "$dir/locking.sh" 25.25 - 25.26 -VTPMDB="/var/vtpm/vtpm.db" 25.27 - 25.28 -#In the vtpm-impl file some commands should be defined: 25.29 -# vtpm_create, vtpm_setup, vtpm_start, etc. (see below) 25.30 -if [ -r "$dir/vtpm-impl.alt" ]; then 25.31 - . "$dir/vtpm-impl.alt" 25.32 -elif [ -r "$dir/vtpm-impl" ]; then 25.33 - . "$dir/vtpm-impl" 25.34 -else 25.35 - function vtpm_create () { 25.36 - true 25.37 - } 25.38 - function vtpm_setup() { 25.39 - true 25.40 - } 25.41 - function vtpm_start() { 25.42 - true 25.43 - } 25.44 - function vtpm_suspend() { 25.45 - true 25.46 - } 25.47 - function vtpm_resume() { 25.48 - true 25.49 - } 25.50 - function vtpm_delete() { 25.51 - true 25.52 - } 25.53 - function vtpm_migrate() { 25.54 - echo "Error: vTPM migration accross machines not implemented." 25.55 - } 25.56 - function vtpm_migrate_local() { 25.57 - echo "Error: local vTPM migration not supported" 25.58 - } 25.59 - function vtpm_migrate_recover() { 25.60 - true 25.61 - } 25.62 -fi 25.63 - 25.64 - 25.65 -#Find the instance number for the vtpm given the name of the domain 25.66 -# Parameters 25.67 -# - vmname : the name of the vm 25.68 -# Return value 25.69 -# Returns '0' if instance number could not be found, otherwise 25.70 -# it returns the instance number in the variable 'instance' 25.71 -function vtpmdb_find_instance () { 25.72 - local vmname ret instance 25.73 - vmname=$1 25.74 - ret=0 25.75 - 25.76 - instance=$(cat $VTPMDB | \ 25.77 - awk -vvmname=$vmname \ 25.78 - '{ \ 25.79 - if ( 1 != index($1,"#")) { \ 25.80 - if ( $1 == vmname ) { \ 25.81 - print $2; \ 25.82 - exit; \ 25.83 - } \ 25.84 - } \ 25.85 - }') 25.86 - if [ "$instance" != "" ]; then 25.87 - ret=$instance 25.88 - fi 25.89 - echo "$ret" 25.90 -} 25.91 - 25.92 - 25.93 -# Check whether a particular instance number is still available 25.94 -# returns "0" if it is not available, "1" otherwise. 25.95 -function vtpmdb_is_free_instancenum () { 25.96 - local instance instances avail i 25.97 - instance=$1 25.98 - avail=1 25.99 - #Allowed instance number range: 1-255 25.100 - if [ $instance -eq 0 -o $instance -gt 255 ]; then 25.101 - avail=0 25.102 - else 25.103 - instances=$(cat $VTPMDB | \ 25.104 - gawk \ 25.105 - '{ \ 25.106 - if (1 != index($1,"#")) { \ 25.107 - printf("%s ",$2); \ 25.108 - } \ 25.109 - }') 25.110 - for i in $instances; do 25.111 - if [ $i -eq $instance ]; then 25.112 - avail=0 25.113 - break 25.114 - fi 25.115 - done 25.116 - fi 25.117 - echo "$avail" 25.118 -} 25.119 - 25.120 - 25.121 -# Get an available instance number given the database 25.122 -# Returns an unused instance number 25.123 -function vtpmdb_get_free_instancenum () { 25.124 - local ctr instances don found 25.125 - instances=$(cat $VTPMDB | \ 25.126 - gawk \ 25.127 - '{ \ 25.128 - if (1 != index($1,"#")) { \ 25.129 - printf("%s ",$2); \ 25.130 - } \ 25.131 - }') 25.132 - ctr=1 25.133 - don=0 25.134 - while [ $don -eq 0 ]; do 25.135 - found=0 25.136 - for i in $instances; do 25.137 - if [ $i -eq $ctr ]; then 25.138 - found=1; 25.139 - break; 25.140 - fi 25.141 - done 25.142 - 25.143 - if [ $found -eq 0 ]; then 25.144 - don=1 25.145 - break 25.146 - fi 25.147 - let ctr=ctr+1 25.148 - done 25.149 - echo "$ctr" 25.150 -} 25.151 - 25.152 - 25.153 -# Add a domain name and instance number to the DB file 25.154 -function vtpmdb_add_instance () { 25.155 - local res vmname inst 25.156 - vmname=$1 25.157 - inst=$2 25.158 - 25.159 - if [ ! -f $VTPMDB ]; then 25.160 - echo "#Database for VM to vTPM association" > $VTPMDB 25.161 - echo "#1st column: domain name" >> $VTPMDB 25.162 - echo "#2nd column: TPM instance number" >> $VTPMDB 25.163 - fi 25.164 - res=$(vtpmdb_validate_entry $vmname $inst) 25.165 - if [ $res -eq 0 ]; then 25.166 - echo "$vmname $inst" >> $VTPMDB 25.167 - fi 25.168 -} 25.169 - 25.170 - 25.171 -#Validate whether an entry is the same as passed to this 25.172 -#function 25.173 -function vtpmdb_validate_entry () { 25.174 - local res rc vmname inst 25.175 - rc=0 25.176 - vmname=$1 25.177 - inst=$2 25.178 - 25.179 - res=$(cat $VTPMDB | \ 25.180 - gawk -vvmname=$vmname \ 25.181 - -vinst=$inst \ 25.182 - '{ \ 25.183 - if ( 1 == index($1,"#")) {\ 25.184 - } else \ 25.185 - if ( $1 == vmname && \ 25.186 - $2 == inst) { \ 25.187 - printf("1"); \ 25.188 - exit; \ 25.189 - } else \ 25.190 - if ( $1 == vmname || \ 25.191 - $2 == inst) { \ 25.192 - printf("2"); \ 25.193 - exit; \ 25.194 - } \ 25.195 - }') 25.196 - 25.197 - if [ "$res" == "1" ]; then 25.198 - rc=1 25.199 - elif [ "$res" == "2" ]; then 25.200 - rc=2 25.201 - fi 25.202 - echo "$rc" 25.203 -} 25.204 - 25.205 - 25.206 -#Remove an entry from the vTPM database given its domain name 25.207 -#and instance number 25.208 -function vtpmdb_remove_entry () { 25.209 - local vmname instance VTPMDB_TMP 25.210 - vmname=$1 25.211 - instance=$2 25.212 - VTPMDB_TMP="$VTPMDB".tmp 25.213 - 25.214 - $(cat $VTPMDB | \ 25.215 - gawk -vvmname=$vmname \ 25.216 - '{ \ 25.217 - if ( $1 != vmname ) { \ 25.218 - print $0; \ 25.219 - } \ 25.220 - '} > $VTPMDB_TMP) 25.221 - if [ -e $VTPMDB_TMP ]; then 25.222 - mv -f $VTPMDB_TMP $VTPMDB 25.223 - vtpm_delete $instance 25.224 - else 25.225 - log err "Error creating temporary file '$VTPMDB_TMP'." 25.226 - fi 25.227 -} 25.228 - 25.229 - 25.230 -# Find the reason for the creation of this device: 25.231 -# Returns 'resume' or 'create' 25.232 -function vtpm_get_create_reason () { 25.233 - local resume 25.234 - resume=$(xenstore_read $XENBUS_PATH/resume) 25.235 - if [ "$resume" == "True" ]; then 25.236 - echo "resume" 25.237 - else 25.238 - echo "create" 25.239 - fi 25.240 -} 25.241 - 25.242 - 25.243 -#Create a vTPM instance 25.244 -# If no entry in the TPM database is found, the instance is 25.245 -# created and an entry added to the database. 25.246 -function vtpm_create_instance () { 25.247 - local res instance domname reason uuid 25.248 - uuid=$(xenstore_read "$XENBUS_PATH"/uuid) 25.249 - reason=$(vtpm_get_create_reason) 25.250 - 25.251 - claim_lock vtpmdb 25.252 - 25.253 - instance="0" 25.254 - 25.255 - if [ "$uuid" != "" ]; then 25.256 - instance=$(vtpmdb_find_instance $uuid) 25.257 - fi 25.258 - if [ "$instance" == "0" ]; then 25.259 - domname=$(xenstore_read "$XENBUS_PATH"/domain) 25.260 - instance=$(vtpmdb_find_instance $domname) 25.261 - fi 25.262 - 25.263 - if [ "$instance" == "0" -a "$reason" != "create" ]; then 25.264 - release_lock vtpmdb 25.265 - return 25.266 - fi 25.267 - 25.268 - if [ "$instance" == "0" ]; then 25.269 - #Try to give the preferred instance to the domain 25.270 - instance=$(xenstore_read "$XENBUS_PATH"/pref_instance) 25.271 - if [ "$instance" != "" ]; then 25.272 - res=$(vtpmdb_is_free_instancenum $instance) 25.273 - if [ $res -eq 0 ]; then 25.274 - instance=$(vtpmdb_get_free_instancenum) 25.275 - fi 25.276 - else 25.277 - instance=$(vtpmdb_get_free_instancenum) 25.278 - fi 25.279 - 25.280 - vtpm_create $instance 25.281 - 25.282 - if [ $vtpm_fatal_error -eq 0 ]; then 25.283 - if [ "$uuid" != "" ]; then 25.284 - vtpmdb_add_instance $uuid $instance 25.285 - else 25.286 - vtpmdb_add_instance $domname $instance 25.287 - fi 25.288 - fi 25.289 - else 25.290 - if [ "$reason" == "resume" ]; then 25.291 - vtpm_resume $instance 25.292 - else 25.293 - vtpm_start $instance 25.294 - fi 25.295 - fi 25.296 - 25.297 - release_lock vtpmdb 25.298 - 25.299 - xenstore_write $XENBUS_PATH/instance $instance 25.300 -} 25.301 - 25.302 - 25.303 -#Remove an instance when a VM is terminating or suspending. 25.304 -#Since it is assumed that the VM will appear again, the 25.305 -#entry is kept in the VTPMDB file. 25.306 -function vtpm_remove_instance () { 25.307 - local instance reason domname uuid 25.308 - #Stop script execution quietly if path does not exist (anymore) 25.309 - xenstore-exists "$XENBUS_PATH"/domain 25.310 - uuid=$(xenstore_read "$XENBUS_PATH"/uuid) 25.311 - 25.312 - claim_lock vtpmdb 25.313 - 25.314 - instance="0" 25.315 - 25.316 - if [ "$uuid" != "" ]; then 25.317 - instance=$(vtpmdb_find_instance $uuid) 25.318 - fi 25.319 - 25.320 - if [ "$instance" == "0" ]; then 25.321 - domname=$(xenstore_read "$XENBUS_PATH"/domain) 25.322 - instance=$(vtpmdb_find_instance $domname) 25.323 - fi 25.324 - 25.325 - if [ "$instance" != "0" ]; then 25.326 - vtpm_suspend $instance 25.327 - fi 25.328 - 25.329 - release_lock vtpmdb 25.330 -} 25.331 - 25.332 - 25.333 -#Remove an entry in the VTPMDB file given the domain's name 25.334 -#1st parameter: The name of the domain 25.335 -function vtpm_delete_instance () { 25.336 - local instance 25.337 - 25.338 - claim_lock vtpmdb 25.339 - 25.340 - instance=$(vtpmdb_find_instance $1) 25.341 - if [ "$instance" != "0" ]; then 25.342 - vtpmdb_remove_entry $1 $instance 25.343 - fi 25.344 - 25.345 - release_lock vtpmdb 25.346 -} 25.347 - 25.348 -# Determine whether the given address is local to this machine 25.349 -# Return values: 25.350 -# "-1" : the given machine name is invalid 25.351 -# "0" : this is not an address of this machine 25.352 -# "1" : this is an address local to this machine 25.353 -function vtpm_isLocalAddress() { 25.354 - local addr res 25.355 - addr=$(ping $1 -c 1 | \ 25.356 - gawk '{ print substr($3,2,length($3)-2); exit }') 25.357 - if [ "$addr" == "" ]; then 25.358 - echo "-1" 25.359 - return 25.360 - fi 25.361 - res=$(ifconfig | grep "inet addr" | \ 25.362 - gawk -vaddr=$addr \ 25.363 - '{ \ 25.364 - if ( addr == substr($2, 6)) {\ 25.365 - print "1"; \ 25.366 - } \ 25.367 - }' \ 25.368 - ) 25.369 - if [ "$res" == "" ]; then 25.370 - echo "0" 25.371 - return 25.372 - fi 25.373 - echo "1" 25.374 -} 25.375 - 25.376 -# Perform a migration step. This function differentiates between migration 25.377 -# to the local host or to a remote machine. 25.378 -# Parameters: 25.379 -# 1st: destination host to migrate to 25.380 -# 2nd: name of the domain to migrate 25.381 -# 3rd: the migration step to perform 25.382 -function vtpm_migration_step() { 25.383 - local res=$(vtpm_isLocalAddress $1) 25.384 - if [ "$res" == "0" ]; then 25.385 - vtpm_migrate $1 $2 $3 25.386 - else 25.387 - vtpm_migrate_local 25.388 - fi 25.389 -} 25.390 - 25.391 -# Recover from migration due to an error. This function differentiates 25.392 -# between migration to the local host or to a remote machine. 25.393 -# Parameters: 25.394 -# 1st: destination host the migration was going to 25.395 -# 2nd: name of the domain that was to be migrated 25.396 -# 3rd: the last successful migration step that was done 25.397 -function vtpm_recover() { 25.398 - local res 25.399 - res=$(vtpm_isLocalAddress $1) 25.400 - if [ "$res" == "0" ]; then 25.401 - vtpm_migrate_recover $1 $2 $3 25.402 - fi 25.403 -} 25.404 - 25.405 - 25.406 -#Determine the domain id given a domain's name. 25.407 -#1st parameter: name of the domain 25.408 -#return value: domain id or -1 if domain id could not be determined 25.409 -function vtpm_domid_from_name () { 25.410 - local id name ids 25.411 - ids=$(xenstore-list /local/domain) 25.412 - for id in $ids; do 25.413 - name=$(xenstore-read /local/domain/$id/name) 25.414 - if [ "$name" == "$1" ]; then 25.415 - echo "$id" 25.416 - return 25.417 - fi 25.418 - done 25.419 - echo "-1" 25.420 -} 25.421 - 25.422 -#Determine the virtual TPM's instance number using the domain ID. 25.423 -#1st parm: domain ID 25.424 -function vtpm_uuid_by_domid() { 25.425 - echo $(xenstore-read /local/domain/0/backend/vtpm/$1/0/uuid) 25.426 -} 25.427 - 25.428 - 25.429 -# Determine the vTPM's UUID by the name of the VM 25.430 -function vtpm_uuid_from_vmname() { 25.431 - local domid=$(vtpm_domid_from_name $1) 25.432 - if [ "$domid" != "-1" ]; then 25.433 - echo $(vtpm_uuid_by_domid $domid) 25.434 - return 25.435 - fi 25.436 - echo "" 25.437 -} 25.438 - 25.439 -#Add a virtual TPM instance number and its associated domain name 25.440 -#to the VTPMDB file and activate usage of this virtual TPM instance 25.441 -#by writing the instance number into the xenstore 25.442 -#1st parm: name of virtual machine 25.443 -#2nd parm: instance of associated virtual TPM 25.444 -function vtpm_add_and_activate() { 25.445 - local domid=$(vtpm_domid_from_name $1) 25.446 - local vtpm_uuid=$(vtpm_uuid_from_vmname $1) 25.447 - if [ "$vtpm_uuid" != "" -a "$domid" != "-1" ]; then 25.448 - vtpmdb_add_instance $vtpm_uuid $2 25.449 - xenstore-write backend/vtpm/$domid/0/instance $2 25.450 - fi 25.451 -}
26.1 --- a/tools/examples/vtpm-delete Tue Nov 18 10:55:51 2008 +0100 26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 26.3 @@ -1,18 +0,0 @@ 26.4 -#!/bin/bash 26.5 - 26.6 -# This scripts must be called the following way: 26.7 -# vtpm-delete <vtpm uuid> 26.8 -# or 26.9 -# vtpm-delete --vmname <vm name> 26.10 - 26.11 -dir=$(dirname "$0") 26.12 -. "$dir/vtpm-common.sh" 26.13 - 26.14 -if [ "$1" == "--vmname" ]; then 26.15 - vtpm_uuid=$(vtpm_uuid_from_vmname $2) 26.16 - if [ "$vtpm_uuid" != "" ];then 26.17 - vtpm_delete_instance $vtpm_uuid 26.18 - fi 26.19 -else 26.20 - vtpm_delete_instance $1 26.21 -fi
27.1 --- a/tools/examples/vtpm-hotplug-common.sh Tue Nov 18 10:55:51 2008 +0100 27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 27.3 @@ -1,35 +0,0 @@ 27.4 -# 27.5 -# Copyright (c) 2005 IBM Corporation 27.6 -# Copyright (c) 2005 XenSource Ltd. 27.7 -# 27.8 -# This library is free software; you can redistribute it and/or 27.9 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 27.10 -# License as published by the Free Software Foundation. 27.11 -# 27.12 -# This library is distributed in the hope that it will be useful, 27.13 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 27.14 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27.15 -# Lesser General Public License for more details. 27.16 -# 27.17 -# You should have received a copy of the GNU Lesser General Public 27.18 -# License along with this library; if not, write to the Free Software 27.19 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27.20 -# 27.21 - 27.22 -dir=$(dirname "$0") 27.23 -. "$dir/xen-hotplug-common.sh" 27.24 - 27.25 -findCommand "$@" 27.26 -if [ "$command" != "online" ] && 27.27 - [ "$command" != "offline" ] && 27.28 - [ "$command" != "add" ] && 27.29 - [ "$command" != "remove" ] 27.30 -then 27.31 - log err "Invalid command: $command" 27.32 - exit 1 27.33 -fi 27.34 - 27.35 - 27.36 -XENBUS_PATH="${XENBUS_PATH:?}" 27.37 - 27.38 -. "$dir/vtpm-common.sh"
28.1 --- a/tools/examples/vtpm-impl Tue Nov 18 10:55:51 2008 +0100 28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 28.3 @@ -1,208 +0,0 @@ 28.4 -#!/bin/bash 28.5 -# =================================================================== 28.6 -# 28.7 -# Copyright (c) 2005, Intel Corp. 28.8 -# All rights reserved. 28.9 -# 28.10 -# Redistribution and use in source and binary forms, with or without 28.11 -# modification, are permitted provided that the following conditions 28.12 -# are met: 28.13 -# 28.14 -# * Redistributions of source code must retain the above copyright 28.15 -# notice, this list of conditions and the following disclaimer. 28.16 -# * Redistributions in binary form must reproduce the above 28.17 -# copyright notice, this list of conditions and the following 28.18 -# disclaimer in the documentation and/or other materials provided 28.19 -# with the distribution. 28.20 -# * Neither the name of Intel Corporation nor the names of its 28.21 -# contributors may be used to endorse or promote products derived 28.22 -# from this software without specific prior written permission. 28.23 -# 28.24 -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28.25 -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28.26 -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28.27 -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28.28 -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28.29 -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28.30 -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28.31 -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.32 -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28.33 -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.34 -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 28.35 -# OF THE POSSIBILITY OF SUCH DAMAGE. 28.36 -# =================================================================== 28.37 - 28.38 -# | SRC | TAG | CMD SIZE | ORD |mtype|strt 28.39 -TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x01 28.40 -TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x02 28.41 -TPM_CMD_CLOS=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x02 28.42 -TPM_CMD_DELE=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x03 28.43 - 28.44 -TPM_TYPE_PVM=\\x01 28.45 -TPM_TYPE_HVM=\\x02 28.46 - 28.47 -TPM_SUCCESS=00000000 28.48 - 28.49 -TX_VTPM_MANAGER=/var/vtpm/fifos/from_console.fifo 28.50 -RX_VTPM_MANAGER=/var/vtpm/fifos/to_console.fifo 28.51 - 28.52 -VTPM_MIG=/usr/bin/vtpm_migrator 28.53 - 28.54 -# -------------------- Helpers for binary streams ----------- 28.55 - 28.56 -function str_to_hex32() { 28.57 - printf "%0.8x" $1 28.58 -} 28.59 - 28.60 -function hex32_to_bin() { 28.61 - local inst=$(str_to_hex32 $1); 28.62 - 28.63 - local n1=`echo $inst | sed 's/\(..\)....../\\\\x\1/'` 28.64 - local n2=`echo $inst | sed 's/..\(..\)..../\\\\x\1/'` 28.65 - local n3=`echo $inst | sed 's/....\(..\)../\\\\x\1/'` 28.66 - local n4=`echo $inst | sed 's/......\(..\)/\\\\x\1/'` 28.67 - 28.68 - echo "$n1$n2$n3$n4" 28.69 -} 28.70 - 28.71 -function vtpm_manager_cmd() { 28.72 - local cmd=$1; 28.73 - local inst=$2; 28.74 - local inst_bin=$(hex32_to_bin $inst); 28.75 - 28.76 - claim_lock vtpm_mgr 28.77 - 28.78 - #send cmd to vtpm_manager 28.79 - printf "$cmd$inst_bin" > $TX_VTPM_MANAGER 28.80 - 28.81 - #recv response 28.82 - set +e 28.83 - local resp_hex=`dd skip=10 bs=1 count=4 if=$RX_VTPM_MANAGER 2> /dev/null | xxd -ps` 28.84 - set -e 28.85 - 28.86 - release_lock vtpm_mgr 28.87 - 28.88 - #return whether the command was successful 28.89 - if [ $resp_hex -ne $TPM_SUCCESS ]; then 28.90 - vtpm_fatal_error=1 28.91 - false 28.92 - else 28.93 - true 28.94 - fi 28.95 -} 28.96 - 28.97 -# Helper to get vm type to pass to vtpm_manager open/resume 28.98 -function vtpm_get_type() { 28.99 - local inst=$(xenstore_read $XENBUS_PATH/frontend-id) 28.100 - local vm=$(xenstore_read /local/domain/$inst/vm) 28.101 - if [ "$vm" != "" ]; then 28.102 - local ostype=$(xenstore-read $vm/image/ostype) 28.103 - if [ "$ostype" == "hvm" ]; then 28.104 - echo $TPM_TYPE_HVM; 28.105 - else 28.106 - echo $TPM_TYPE_PVM; 28.107 - fi 28.108 - fi 28.109 -} 28.110 - 28.111 -# ------------------ Command handlers ----------------- 28.112 - 28.113 -# Create new vtpm instance & set it up for use 28.114 -function vtpm_create () { 28.115 - # Creation is handled implicitly by the manager on first setup 28.116 - # so just set it up for use 28.117 - $(vtpm_start $1) 28.118 -} 28.119 - 28.120 -# Setup vtpm instance for use. 28.121 -function vtpm_start() { 28.122 - local vmtype=$(vtpm_get_type); 28.123 - $(vtpm_manager_cmd $TPM_CMD_OPEN$vmtype $1) 28.124 -} 28.125 - 28.126 -function vtpm_resume() { 28.127 - local vmtype=$(vtpm_get_type); 28.128 - $(vtpm_manager_cmd $TPM_CMD_RESM$vmtype $1) 28.129 -} 28.130 - 28.131 -# Reset the vtpm AKA clear PCRs 28.132 -function vtpm_reset() { 28.133 - #not used by current implemenation 28.134 - true 28.135 -} 28.136 - 28.137 -# Shutdown the vtpm while the vm is down 28.138 -# This could be a suspend of shutdown 28.139 -# we cannot distinquish, so save the state 28.140 -# and decide on startup if we should keep is 28.141 -function vtpm_suspend() { 28.142 - $(vtpm_manager_cmd $TPM_CMD_CLOS $1) 28.143 -} 28.144 - 28.145 - 28.146 -function vtpm_delete() { 28.147 - local inst=$1 28.148 - if $(vtpm_manager_cmd $TPM_CMD_DELE $inst); then 28.149 - rm -f /var/vtpm/vtpm_dm_$1.data 28.150 - true 28.151 - else 28.152 - vtpm_fatal_error=1 28.153 - false 28.154 - fi 28.155 -} 28.156 - 28.157 -# Perform a migration step. This function differentiates between migration 28.158 -# to the local host or to a remote machine. 28.159 -# Parameters: 28.160 -# 1st: destination host to migrate to 28.161 -# 2nd: name of the domain to migrate 28.162 -# 3rd: the migration step to perform 28.163 -function vtpm_migrate() { 28.164 - local instance res 28.165 - 28.166 - instance=$(vtpmdb_find_instance $2) 28.167 - if [ "$instance" == "" ]; then 28.168 - log err "VTPM Migratoin failed. Unable to translation of domain name" 28.169 - echo "Error: VTPM Migration failed while looking up instance number" 28.170 - fi 28.171 - 28.172 - case "$3" in 28.173 - 0) 28.174 - #Incicate migration supported 28.175 - echo "0" 28.176 - ;; 28.177 - 28.178 - 1) 28.179 - # Get Public Key from Destination 28.180 - # Call vtpm_manager's migration part 1 28.181 - claim_lock vtpm_mgr 28.182 - $VTPM_MIG $1 $2 $instance $3 28.183 - release_lock vtpm_mgr 28.184 - ;; 28.185 - 28.186 - 2) 28.187 - # Call manager's migration step 2 and send result to destination 28.188 - # If successful remove from db 28.189 - claim_lock vtpm_mgr 28.190 - $VTPM_MIG $1 $2 $instance $3 28.191 - release_lock vtpm_mgr 28.192 - ;; 28.193 - 28.194 - 3) 28.195 - if `ps x | grep "$VTPM_MIG $1"`; then 28.196 - log err "VTPM Migration failed to complete." 28.197 - echo "Error: VTPM Migration failed to complete." 28.198 - fi 28.199 - ;; 28.200 - esac 28.201 - 28.202 -} 28.203 - 28.204 - 28.205 -function vtpm_migrate_recover() { 28.206 - echo "Error: Recovery not supported yet" 28.207 -} 28.208 - 28.209 -function vtpm_migrate_local() { 28.210 - echo "Error: local vTPM migration not supported" 28.211 -}
29.1 --- a/tools/examples/vtpm-migration.sh Tue Nov 18 10:55:51 2008 +0100 29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 29.3 @@ -1,19 +0,0 @@ 29.4 -# 29.5 -# Copyright (c) 2005 IBM Corporation 29.6 -# 29.7 -# This library is free software; you can redistribute it and/or 29.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 29.9 -# License as published by the Free Software Foundation. 29.10 -# 29.11 -# This library is distributed in the hope that it will be useful, 29.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 29.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29.14 -# Lesser General Public License for more details. 29.15 -# 29.16 -# You should have received a copy of the GNU Lesser General Public 29.17 -# License along with this library; if not, write to the Free Software 29.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29.19 -# 29.20 - 29.21 -dir=$(dirname "$0") 29.22 -. "$dir/vtpm-common.sh"
30.1 --- a/tools/examples/xen-backend.agent Tue Nov 18 10:55:51 2008 +0100 30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 30.3 @@ -1,39 +0,0 @@ 30.4 -#! /bin/bash 30.5 - 30.6 -PATH=/etc/xen/scripts:$PATH 30.7 - 30.8 -. /etc/xen/scripts/locking.sh 30.9 - 30.10 -claim_lock xenbus_hotplug_global 30.11 - 30.12 -case "$XENBUS_TYPE" in 30.13 - tap) 30.14 - /etc/xen/scripts/blktap "$ACTION" 30.15 - ;; 30.16 - vbd) 30.17 - /etc/xen/scripts/block "$ACTION" 30.18 - ;; 30.19 - vtpm) 30.20 - /etc/xen/scripts/vtpm "$ACTION" 30.21 - ;; 30.22 - vif) 30.23 - [ -n "$script" ] && $script "$ACTION" 30.24 - ;; 30.25 - vscsi) 30.26 - /etc/xen/scripts/vscsi "$ACTION" 30.27 - ;; 30.28 -esac 30.29 - 30.30 -case "$ACTION" in 30.31 - add) 30.32 - ;; 30.33 - remove) 30.34 - /etc/xen/scripts/xen-hotplug-cleanup 30.35 - ;; 30.36 - online) 30.37 - ;; 30.38 - offline) 30.39 - ;; 30.40 -esac 30.41 - 30.42 -release_lock xenbus_hotplug_global
31.1 --- a/tools/examples/xen-backend.rules Tue Nov 18 10:55:51 2008 +0100 31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 31.3 @@ -1,9 +0,0 @@ 31.4 -SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" 31.5 -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" 31.6 -SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" 31.7 -SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online" 31.8 -SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline" 31.9 -SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" 31.10 -SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" 31.11 -KERNEL=="evtchn", NAME="xen/%k" 31.12 -KERNEL=="blktap[0-9]*", NAME="xen/%k"
32.1 --- a/tools/examples/xen-hotplug-cleanup Tue Nov 18 10:55:51 2008 +0100 32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 32.3 @@ -1,22 +0,0 @@ 32.4 -#! /bin/bash 32.5 - 32.6 -dir=$(dirname "$0") 32.7 -. "$dir/xen-hotplug-common.sh" 32.8 - 32.9 -# Claim the lock protecting /etc/xen/scripts/block. This stops a race whereby 32.10 -# paths in the store would disappear underneath that script as it attempted to 32.11 -# read from the store checking for device sharing. 32.12 -# Any other scripts that do similar things will have to have their lock 32.13 -# claimed too. 32.14 -# This is pretty horrible, but there's not really a nicer way of solving this. 32.15 -claim_lock "block" 32.16 - 32.17 -# remove device frontend store entries 32.18 -xenstore-rm -t \ 32.19 - $(xenstore-read "$XENBUS_PATH/frontend" 2>/dev/null) 2>/dev/null || true 32.20 - 32.21 -# remove device backend store entries 32.22 -xenstore-rm -t "$XENBUS_PATH" 2>/dev/null || true 32.23 -xenstore-rm -t "error/$XENBUS_PATH" 2>/dev/null || true 32.24 - 32.25 -release_lock "block"
33.1 --- a/tools/examples/xen-hotplug-common.sh Tue Nov 18 10:55:51 2008 +0100 33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 33.3 @@ -1,93 +0,0 @@ 33.4 -# 33.5 -# Copyright (c) 2005 XenSource Ltd. 33.6 -# 33.7 -# This library is free software; you can redistribute it and/or 33.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 33.9 -# License as published by the Free Software Foundation. 33.10 -# 33.11 -# This library is distributed in the hope that it will be useful, 33.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 33.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33.14 -# Lesser General Public License for more details. 33.15 -# 33.16 -# You should have received a copy of the GNU Lesser General Public 33.17 -# License along with this library; if not, write to the Free Software 33.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33.19 -# 33.20 - 33.21 - 33.22 -dir=$(dirname "$0") 33.23 -. "$dir/logging.sh" 33.24 -. "$dir/xen-script-common.sh" 33.25 -. "$dir/locking.sh" 33.26 - 33.27 -exec 2>>/var/log/xen/xen-hotplug.log 33.28 - 33.29 -export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH" 33.30 -export LANG="POSIX" 33.31 -unset $(set | grep ^LC_ | cut -d= -f1) 33.32 - 33.33 -fatal() { 33.34 - xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \ 33.35 - "$XENBUS_PATH/hotplug-status" error 33.36 - log err "$@" 33.37 - exit 1 33.38 -} 33.39 - 33.40 -success() { 33.41 - # Tell DevController that backend is "connected" 33.42 - xenstore_write "$XENBUS_PATH/hotplug-status" connected 33.43 -} 33.44 - 33.45 -do_or_die() { 33.46 - "$@" || fatal "$@ failed" 33.47 -} 33.48 - 33.49 -do_without_error() { 33.50 - "$@" 2>/dev/null || log debug "$@ failed" 33.51 -} 33.52 - 33.53 -sigerr() { 33.54 - fatal "$0 failed; error detected." 33.55 -} 33.56 - 33.57 -trap sigerr ERR 33.58 - 33.59 - 33.60 -## 33.61 -# xenstore_read <path>+ 33.62 -# 33.63 -# Read each of the given paths, returning each result on a separate line, or 33.64 -# exit this script if any of the paths is missing. 33.65 -# 33.66 -xenstore_read() { 33.67 - local v=$(xenstore-read "$@" || true) 33.68 - [ "$v" != "" ] || fatal "xenstore-read $@ failed." 33.69 - echo "$v" 33.70 -} 33.71 - 33.72 - 33.73 -## 33.74 -# xenstore_read_default <path> <default> 33.75 -# 33.76 -# Read the given path, returning the value there or the given default if the 33.77 -# path is not present. 33.78 -# 33.79 -xenstore_read_default() { 33.80 - xenstore-read "$1" 2>/dev/null || echo "$2" 33.81 -} 33.82 - 33.83 - 33.84 -## 33.85 -# xenstore_write (<path> <value>)+ 33.86 -# 33.87 -# Write each of the key/value pairs to the store, and exit this script if any 33.88 -# such writing fails. 33.89 -# 33.90 -xenstore_write() { 33.91 - log debug "Writing $@ to xenstore." 33.92 - xenstore-write "$@" || fatal "Writing $@ to xenstore failed." 33.93 -} 33.94 - 33.95 - 33.96 -log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
34.1 --- a/tools/examples/xen-network-common.sh Tue Nov 18 10:55:51 2008 +0100 34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 34.3 @@ -1,118 +0,0 @@ 34.4 -# 34.5 -# Copyright (c) 2005 XenSource Ltd. 34.6 -# 34.7 -# This library is free software; you can redistribute it and/or 34.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 34.9 -# License as published by the Free Software Foundation. 34.10 -# 34.11 -# This library is distributed in the hope that it will be useful, 34.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 34.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 34.14 -# Lesser General Public License for more details. 34.15 -# 34.16 -# You should have received a copy of the GNU Lesser General Public 34.17 -# License along with this library; if not, write to the Free Software 34.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 34.19 -# 34.20 - 34.21 - 34.22 -# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives. 34.23 - 34.24 -# Other platforms just use ifup / ifdown directly. 34.25 - 34.26 -## 34.27 -# preiftransfer 34.28 -# 34.29 -# @param $1 The current name for the physical device, which is also the name 34.30 -# that the virtual device will take once the physical device has 34.31 -# been renamed. 34.32 - 34.33 -if ! which ifup >/dev/null 2>/dev/null 34.34 -then 34.35 - preiftransfer() 34.36 - { 34.37 - true 34.38 - } 34.39 - ifup() 34.40 - { 34.41 - false 34.42 - } 34.43 - ifdown() 34.44 - { 34.45 - false 34.46 - } 34.47 -else 34.48 - preiftransfer() 34.49 - { 34.50 - true 34.51 - } 34.52 -fi 34.53 - 34.54 - 34.55 -first_file() 34.56 -{ 34.57 - t="$1" 34.58 - shift 34.59 - for file in $@ 34.60 - do 34.61 - if [ "$t" "$file" ] 34.62 - then 34.63 - echo "$file" 34.64 - return 34.65 - fi 34.66 - done 34.67 -} 34.68 - 34.69 -find_dhcpd_conf_file() 34.70 -{ 34.71 - first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf 34.72 -} 34.73 - 34.74 - 34.75 -find_dhcpd_init_file() 34.76 -{ 34.77 - first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd} 34.78 -} 34.79 - 34.80 -find_dhcpd_arg_file() 34.81 -{ 34.82 - first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server 34.83 -} 34.84 - 34.85 -# configure interfaces which act as pure bridge ports: 34.86 -setup_bridge_port() { 34.87 - local dev="$1" 34.88 - 34.89 - # take interface down ... 34.90 - ip link set ${dev} down 34.91 - 34.92 - # ... and configure it 34.93 - ip addr flush ${dev} 34.94 -} 34.95 - 34.96 -# Usage: create_bridge bridge 34.97 -create_bridge () { 34.98 - local bridge=$1 34.99 - 34.100 - # Don't create the bridge if it already exists. 34.101 - if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then 34.102 - brctl addbr ${bridge} 34.103 - brctl stp ${bridge} off 34.104 - brctl setfd ${bridge} 0 34.105 - fi 34.106 -} 34.107 - 34.108 -# Usage: add_to_bridge bridge dev 34.109 -add_to_bridge () { 34.110 - local bridge=$1 34.111 - local dev=$2 34.112 - 34.113 - # Don't add $dev to $bridge if it's already on a bridge. 34.114 - if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then 34.115 - ip link set ${dev} up || true 34.116 - return 34.117 - fi 34.118 - brctl addif ${bridge} ${dev} 34.119 - ip link set ${dev} up 34.120 -} 34.121 -
35.1 --- a/tools/examples/xen-script-common.sh Tue Nov 18 10:55:51 2008 +0100 35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 35.3 @@ -1,44 +0,0 @@ 35.4 -# 35.5 -# Copyright (c) 2005 XenSource Ltd. 35.6 -# 35.7 -# This library is free software; you can redistribute it and/or 35.8 -# modify it under the terms of version 2.1 of the GNU Lesser General Public 35.9 -# License as published by the Free Software Foundation. 35.10 -# 35.11 -# This library is distributed in the hope that it will be useful, 35.12 -# but WITHOUT ANY WARRANTY; without even the implied warranty of 35.13 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 35.14 -# Lesser General Public License for more details. 35.15 -# 35.16 -# You should have received a copy of the GNU Lesser General Public 35.17 -# License along with this library; if not, write to the Free Software 35.18 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 35.19 -# 35.20 - 35.21 - 35.22 -set -e 35.23 - 35.24 - 35.25 -evalVariables() 35.26 -{ 35.27 - for arg in "$@" 35.28 - do 35.29 - if expr 'index' "$arg" '=' '>' '1' >/dev/null 35.30 - then 35.31 - eval "$arg" 35.32 - fi 35.33 - done 35.34 -} 35.35 - 35.36 - 35.37 -findCommand() 35.38 -{ 35.39 - for arg in "$@" 35.40 - do 35.41 - if ! expr 'index' "$arg" '=' >/dev/null 35.42 - then 35.43 - command="$arg" 35.44 - return 35.45 - fi 35.46 - done 35.47 -}
36.1 --- a/tools/firmware/hvmloader/config.h Tue Nov 18 10:55:51 2008 +0100 36.2 +++ b/tools/firmware/hvmloader/config.h Tue Nov 25 14:21:24 2008 +0900 36.3 @@ -23,7 +23,6 @@ 36.4 /* Memory map. */ 36.5 #define HYPERCALL_PHYSICAL_ADDRESS 0x00080000 36.6 #define VGABIOS_PHYSICAL_ADDRESS 0x000C0000 36.7 -#define ETHERBOOT_PHYSICAL_ADDRESS 0x000D0000 36.8 #define SMBIOS_PHYSICAL_ADDRESS 0x000E9000 36.9 #define SMBIOS_MAXIMUM_SIZE 0x00001000 36.10 #define ACPI_PHYSICAL_ADDRESS 0x000EA000
37.1 --- a/tools/firmware/hvmloader/hvmloader.c Tue Nov 18 10:55:51 2008 +0100 37.2 +++ b/tools/firmware/hvmloader/hvmloader.c Tue Nov 25 14:21:24 2008 +0900 37.3 @@ -322,60 +322,56 @@ static void pci_setup(void) 37.4 } 37.5 37.6 /* 37.7 - * Scan the PCI bus for the first NIC supported by etherboot, and copy 37.8 - * the corresponding rom data to *copy_rom_dest. Returns the length of the 37.9 - * selected rom, or 0 if no NIC found. 37.10 + * Scan the list of Option ROMs at @roms for one which supports 37.11 + * PCI (@vendor_id, @device_id) found at slot @devfn. If one is found, 37.12 + * copy it to @dest and return its size rounded up to a multiple 2kB. This 37.13 + * function will not copy ROMs beyond address 0xE0000. 37.14 */ 37.15 -static int scan_etherboot_nic(void *copy_rom_dest) 37.16 +#define round_option_rom(x) (((x) + 2047) & ~2047) 37.17 +static int scan_option_rom( 37.18 + uint8_t devfn, uint16_t vendor_id, uint16_t device_id, 37.19 + void *roms, uint32_t dest) 37.20 { 37.21 struct option_rom_header *rom; 37.22 struct option_rom_pnp_header *pnph; 37.23 struct option_rom_pci_header *pcih; 37.24 - uint32_t devfn; 37.25 - uint16_t class, vendor_id, device_id; 37.26 uint8_t csum; 37.27 int i; 37.28 37.29 - for ( devfn = 0; devfn < 128; devfn++ ) 37.30 - { 37.31 - class = pci_readw(devfn, PCI_CLASS_DEVICE); 37.32 - vendor_id = pci_readw(devfn, PCI_VENDOR_ID); 37.33 - device_id = pci_readw(devfn, PCI_DEVICE_ID); 37.34 + static uint32_t orom_ids[64]; 37.35 + static int nr_roms; 37.36 + 37.37 + /* Avoid duplicate ROMs. */ 37.38 + for ( i = 0; i < nr_roms; i++ ) 37.39 + if ( orom_ids[i] == (vendor_id | ((uint32_t)device_id << 16)) ) 37.40 + return 0; 37.41 37.42 - if ( (vendor_id == 0xffff) && (device_id == 0xffff) ) 37.43 - continue; 37.44 - 37.45 - /* We're only interested in NICs. */ 37.46 - if ( class != 0x0200 ) 37.47 - continue; 37.48 + rom = roms; 37.49 + for ( ; ; ) 37.50 + { 37.51 + /* Invalid signature means we're out of option ROMs. */ 37.52 + if ( strncmp((char *)rom->signature, "\x55\xaa", 2) || 37.53 + (rom->rom_size == 0) ) 37.54 + break; 37.55 37.56 - rom = (struct option_rom_header *)etherboot; 37.57 - for ( ; ; ) 37.58 - { 37.59 - /* Invalid signature means we're out of option ROMs. */ 37.60 - if ( strncmp((char *)rom->signature, "\x55\xaa", 2) || 37.61 - (rom->rom_size == 0) ) 37.62 - break; 37.63 + /* Invalid checksum means we're out of option ROMs. */ 37.64 + csum = 0; 37.65 + for ( i = 0; i < (rom->rom_size * 512); i++ ) 37.66 + csum += ((uint8_t *)rom)[i]; 37.67 + if ( csum != 0 ) 37.68 + break; 37.69 37.70 - /* Invalid checksum means we're out of option ROMs. */ 37.71 - csum = 0; 37.72 - for ( i = 0; i < (rom->rom_size * 512); i++ ) 37.73 - csum += ((uint8_t *)rom)[i]; 37.74 - if ( csum != 0 ) 37.75 - break; 37.76 + /* Check the PCI PnP header (if any) for a match. */ 37.77 + pcih = (struct option_rom_pci_header *) 37.78 + ((char *)rom + rom->pci_header_offset); 37.79 + if ( (rom->pci_header_offset != 0) && 37.80 + !strncmp((char *)pcih->signature, "PCIR", 4) && 37.81 + (pcih->vendor_id == vendor_id) && 37.82 + (pcih->device_id == device_id) ) 37.83 + goto found; 37.84 37.85 - /* Check the PCI PnP header (if any) for a match. */ 37.86 - pcih = (struct option_rom_pci_header *) 37.87 - ((char *)rom + rom->pci_header_offset); 37.88 - if ( (rom->pci_header_offset != 0) && 37.89 - !strncmp((char *)pcih->signature, "PCIR", 4) && 37.90 - (pcih->vendor_id == vendor_id) && 37.91 - (pcih->device_id == device_id) ) 37.92 - goto found; 37.93 - 37.94 - rom = (struct option_rom_header *) 37.95 - ((char *)rom + rom->rom_size * 512); 37.96 - } 37.97 + rom = (struct option_rom_header *) 37.98 + ((char *)rom + rom->rom_size * 512); 37.99 } 37.100 37.101 return 0; 37.102 @@ -392,15 +388,96 @@ static int scan_etherboot_nic(void *copy 37.103 ((char *)rom + pnph->next_header_offset)) 37.104 : ((struct option_rom_pnp_header *)NULL)); 37.105 37.106 - printf("Loading PXE ROM ...\n"); 37.107 + printf("Loading PCI Option ROM ...\n"); 37.108 if ( (pnph != NULL) && (pnph->manufacturer_name_offset != 0) ) 37.109 printf(" - Manufacturer: %s\n", 37.110 (char *)rom + pnph->manufacturer_name_offset); 37.111 if ( (pnph != NULL) && (pnph->product_name_offset != 0) ) 37.112 printf(" - Product name: %s\n", 37.113 (char *)rom + pnph->product_name_offset); 37.114 - memcpy(copy_rom_dest, rom, rom->rom_size * 512); 37.115 - return rom->rom_size * 512; 37.116 + 37.117 + if ( (dest + rom->rom_size * 512 + 1) > 0xe0000u ) 37.118 + { 37.119 + printf("Option ROM size %x exceeds available space\n", 37.120 + rom->rom_size * 512); 37.121 + return 0; 37.122 + } 37.123 + 37.124 + orom_ids[nr_roms++] = vendor_id | ((uint32_t)device_id << 16); 37.125 + memcpy((void *)dest, rom, rom->rom_size * 512); 37.126 + *(uint8_t *)(dest + rom->rom_size * 512) = devfn; 37.127 + return round_option_rom(rom->rom_size * 512 + 1); 37.128 +} 37.129 + 37.130 +/* 37.131 + * Scan the PCI bus for the first NIC supported by etherboot, and copy 37.132 + * the corresponding rom data to *copy_rom_dest. Returns the length of the 37.133 + * selected rom, or 0 if no NIC found. 37.134 + */ 37.135 +static int scan_etherboot_nic(uint32_t copy_rom_dest) 37.136 +{ 37.137 + uint8_t devfn; 37.138 + uint16_t class, vendor_id, device_id; 37.139 + 37.140 + for ( devfn = 0; devfn < 128; devfn++ ) 37.141 + { 37.142 + class = pci_readw(devfn, PCI_CLASS_DEVICE); 37.143 + vendor_id = pci_readw(devfn, PCI_VENDOR_ID); 37.144 + device_id = pci_readw(devfn, PCI_DEVICE_ID); 37.145 + 37.146 + /* We're only interested in NICs. */ 37.147 + if ( (vendor_id != 0xffff) && 37.148 + (device_id != 0xffff) && 37.149 + (class == 0x0200) ) 37.150 + return scan_option_rom( 37.151 + devfn, vendor_id, device_id, etherboot, copy_rom_dest); 37.152 + } 37.153 + 37.154 + return 0; 37.155 +} 37.156 + 37.157 +/* 37.158 + * Scan the PCI bus for the devices that have an option ROM, and copy 37.159 + * the corresponding rom data to rom_phys_addr. 37.160 + */ 37.161 +static int pci_load_option_roms(uint32_t rom_base_addr) 37.162 +{ 37.163 + uint32_t option_rom_addr, rom_phys_addr = rom_base_addr; 37.164 + uint16_t vendor_id, device_id; 37.165 + uint8_t devfn, class; 37.166 + 37.167 + for ( devfn = 0; devfn < 128; devfn++ ) 37.168 + { 37.169 + class = pci_readb(devfn, PCI_CLASS_DEVICE + 1); 37.170 + vendor_id = pci_readw(devfn, PCI_VENDOR_ID); 37.171 + device_id = pci_readw(devfn, PCI_DEVICE_ID); 37.172 + 37.173 + if ( (vendor_id == 0xffff) && (device_id == 0xffff) ) 37.174 + continue; 37.175 + 37.176 + /* 37.177 + * Currently only scan options from mass storage devices and serial 37.178 + * bus controller (Fibre Channel included). 37.179 + */ 37.180 + if ( (class != 0x1) && (class != 0xc) ) 37.181 + continue; 37.182 + 37.183 + option_rom_addr = pci_readl(devfn, PCI_ROM_ADDRESS); 37.184 + if ( !option_rom_addr ) 37.185 + continue; 37.186 + 37.187 + /* Ensure Expansion Bar is enabled before copying */ 37.188 + pci_writel(devfn, PCI_ROM_ADDRESS, option_rom_addr | 0x1); 37.189 + 37.190 + rom_phys_addr += scan_option_rom( 37.191 + devfn, vendor_id, device_id, 37.192 + (void *)(option_rom_addr & ~2047), rom_phys_addr); 37.193 + 37.194 + /* Restore the default original value of Expansion Bar */ 37.195 + pci_writel(devfn, PCI_ROM_ADDRESS, option_rom_addr); 37.196 + } 37.197 + 37.198 + return rom_phys_addr - rom_base_addr; 37.199 } 37.200 37.201 /* Replace possibly erroneous memory-size CMOS fields with correct values. */ 37.202 @@ -461,8 +538,9 @@ static uint16_t init_xen_platform_io_bas 37.203 37.204 int main(void) 37.205 { 37.206 - int vgabios_sz = 0, etherboot_sz = 0, rombios_sz, smbios_sz; 37.207 - uint32_t vga_ram = 0; 37.208 + int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0; 37.209 + int rombios_sz, smbios_sz; 37.210 + uint32_t etherboot_phys_addr, option_rom_phys_addr, vga_ram = 0; 37.211 uint16_t xen_pfiob; 37.212 37.213 printf("HVM Loader\n"); 37.214 @@ -497,13 +575,13 @@ int main(void) 37.215 printf("Loading Cirrus VGABIOS ...\n"); 37.216 memcpy((void *)VGABIOS_PHYSICAL_ADDRESS, 37.217 vgabios_cirrusvga, sizeof(vgabios_cirrusvga)); 37.218 - vgabios_sz = sizeof(vgabios_cirrusvga); 37.219 + vgabios_sz = round_option_rom(sizeof(vgabios_cirrusvga)); 37.220 break; 37.221 case VGA_std: 37.222 printf("Loading Standard VGABIOS ...\n"); 37.223 memcpy((void *)VGABIOS_PHYSICAL_ADDRESS, 37.224 vgabios_stdvga, sizeof(vgabios_stdvga)); 37.225 - vgabios_sz = sizeof(vgabios_stdvga); 37.226 + vgabios_sz = round_option_rom(sizeof(vgabios_stdvga)); 37.227 break; 37.228 default: 37.229 printf("No emulated VGA adaptor ...\n"); 37.230 @@ -516,7 +594,11 @@ int main(void) 37.231 printf("VGA RAM at %08x\n", vga_ram); 37.232 } 37.233 37.234 - etherboot_sz = scan_etherboot_nic((void*)ETHERBOOT_PHYSICAL_ADDRESS); 37.235 + etherboot_phys_addr = VGABIOS_PHYSICAL_ADDRESS + vgabios_sz; 37.236 + etherboot_sz = scan_etherboot_nic(etherboot_phys_addr); 37.237 + 37.238 + option_rom_phys_addr = etherboot_phys_addr + etherboot_sz; 37.239 + option_rom_sz = pci_load_option_roms(option_rom_phys_addr); 37.240 37.241 if ( get_acpi_enabled() ) 37.242 { 37.243 @@ -533,8 +615,12 @@ int main(void) 37.244 VGABIOS_PHYSICAL_ADDRESS + vgabios_sz - 1); 37.245 if ( etherboot_sz ) 37.246 printf(" %05x-%05x: Etherboot ROM\n", 37.247 - ETHERBOOT_PHYSICAL_ADDRESS, 37.248 - ETHERBOOT_PHYSICAL_ADDRESS + etherboot_sz - 1); 37.249 + etherboot_phys_addr, 37.250 + etherboot_phys_addr + etherboot_sz - 1); 37.251 + if ( option_rom_sz ) 37.252 + printf(" %05x-%05x: PCI Option ROMs\n", 37.253 + option_rom_phys_addr, 37.254 + option_rom_phys_addr + option_rom_sz - 1); 37.255 if ( smbios_sz ) 37.256 printf(" %05x-%05x: SMBIOS tables\n", 37.257 SMBIOS_PHYSICAL_ADDRESS,
38.1 --- a/tools/firmware/rombios/rombios.c Tue Nov 18 10:55:51 2008 +0100 38.2 +++ b/tools/firmware/rombios/rombios.c Tue Nov 25 14:21:24 2008 +0900 38.3 @@ -9677,20 +9677,35 @@ block_count_rounded: 38.4 pop ds 38.5 pop ax 38.6 #endif 38.7 - xor bx, bx ;; Restore DS back to 0000: 38.8 - mov ds, bx 38.9 push ax ;; Save AX 38.10 push di ;; Save DI 38.11 ;; Push addr of ROM entry point 38.12 push cx ;; Push seg 38.13 push #0x0003 ;; Push offset 38.14 38.15 + ;; Get the BDF into ax before invoking the option ROM 38.16 + mov bl, [2] 38.17 + mov al, bl 38.18 + shr al, #7 38.19 + cmp al, #1 38.20 + jne fetch_bdf 38.21 + mov ax, ds ;; Increment the DS since rom size larger than an segment 38.22 + add ax, #0x1000 38.23 + mov ds, ax 38.24 +fetch_bdf: 38.25 + shl bx, #9 38.26 + xor ax, ax 38.27 + mov al, [bx] 38.28 + 38.29 ;; Point ES:DI at "$PnP", which tells the ROM that we are a PnP BIOS. 38.30 ;; That should stop it grabbing INT 19h; we will use its BEV instead. 38.31 - mov ax, #0xf000 38.32 - mov es, ax 38.33 + mov bx, #0xf000 38.34 + mov es, bx 38.35 lea di, pnp_string 38.36 38.37 + xor bx, bx ;; Restore DS back to 0000: 38.38 + mov ds, bx 38.39 + 38.40 mov bp, sp ;; Call ROM init routine using seg:off on stack 38.41 db 0xff ;; call_far ss:[bp+0] 38.42 db 0x5e
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/tools/hotplug/Linux/Makefile Tue Nov 25 14:21:24 2008 +0900 39.3 @@ -0,0 +1,97 @@ 39.4 +XEN_ROOT = ../../../ 39.5 +include $(XEN_ROOT)/tools/Rules.mk 39.6 + 39.7 +# Init scripts. 39.8 +XEND_INITD = init.d/xend 39.9 +XENDOMAINS_INITD = init.d/xendomains 39.10 +XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains 39.11 + 39.12 +# Xen configuration dir and configs to go there. 39.13 +XEN_CONFIG_DIR = /etc/xen 39.14 + 39.15 +# Xen script dir and scripts to go there. 39.16 +XEN_SCRIPT_DIR = /etc/xen/scripts 39.17 +XEN_SCRIPTS = network-bridge vif-bridge 39.18 +XEN_SCRIPTS += network-route vif-route 39.19 +XEN_SCRIPTS += network-nat vif-nat 39.20 +XEN_SCRIPTS += block 39.21 +XEN_SCRIPTS += block-enbd block-nbd 39.22 +XEN_SCRIPTS += blktap 39.23 +XEN_SCRIPTS += vtpm vtpm-delete 39.24 +XEN_SCRIPTS += xen-hotplug-cleanup 39.25 +XEN_SCRIPTS += external-device-migrate 39.26 +XEN_SCRIPTS += vscsi 39.27 +XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh 39.28 +XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh 39.29 +XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh 39.30 +XEN_SCRIPT_DATA += vtpm-migration.sh vtpm-impl 39.31 + 39.32 +XEN_HOTPLUG_DIR = /etc/hotplug 39.33 +XEN_HOTPLUG_SCRIPTS = xen-backend.agent 39.34 + 39.35 +UDEV_RULES_DIR = /etc/udev 39.36 +UDEV_RULES = xen-backend.rules 39.37 + 39.38 +DI = $(if $(DISTDIR),$(shell readlink -f $(DISTDIR)),) 39.39 +DE = $(if $(DESTDIR),$(shell readlink -f $(DESTDIR)),) 39.40 +ifeq ($(findstring $(DI),$(DE)),$(DI)) 39.41 +HOTPLUGS=install-hotplug install-udev 39.42 +else 39.43 +ifeq ($(shell [ -x /usr/bin/udevinfo ] && [ `/usr/bin/udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/'` -ge 059 ] && echo 1),1) 39.44 +HOTPLUGS=install-udev 39.45 +else 39.46 +HOTPLUGS=install-hotplug 39.47 +endif 39.48 +endif 39.49 + 39.50 +.PHONY: all 39.51 +all: 39.52 + 39.53 +.PHONY: build 39.54 +build: 39.55 + 39.56 +.PHONY: install 39.57 +install: all install-initd install-scripts $(HOTPLUGS) 39.58 + 39.59 +.PHONY: install-initd 39.60 +install-initd: 39.61 + [ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d 39.62 + [ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig 39.63 + $(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d 39.64 + $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d 39.65 + $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains 39.66 + 39.67 +.PHONY: install-scripts 39.68 +install-scripts: 39.69 + [ -d $(DESTDIR)$(XEN_SCRIPT_DIR) ] || \ 39.70 + $(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR) 39.71 + set -e; for i in $(XEN_SCRIPTS); \ 39.72 + do \ 39.73 + $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 39.74 + done 39.75 + set -e; for i in $(XEN_SCRIPT_DATA); \ 39.76 + do \ 39.77 + $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 39.78 + done 39.79 + 39.80 +.PHONY: install-hotplug 39.81 +install-hotplug: 39.82 + [ -d $(DESTDIR)$(XEN_HOTPLUG_DIR) ] || \ 39.83 + $(INSTALL_DIR) $(DESTDIR)$(XEN_HOTPLUG_DIR) 39.84 + set -e; for i in $(XEN_HOTPLUG_SCRIPTS); \ 39.85 + do \ 39.86 + $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_HOTPLUG_DIR); \ 39.87 + done 39.88 + 39.89 +.PHONY: install-udev 39.90 +install-udev: 39.91 + [ -d $(DESTDIR)$(UDEV_RULES_DIR) ] || \ 39.92 + $(INSTALL_DIR) $(DESTDIR)$(UDEV_RULES_DIR)/rules.d 39.93 + set -e; for i in $(UDEV_RULES); \ 39.94 + do \ 39.95 + $(INSTALL_DATA) $$i $(DESTDIR)$(UDEV_RULES_DIR); \ 39.96 + ln -sf ../$$i $(DESTDIR)$(UDEV_RULES_DIR)/rules.d; \ 39.97 + done 39.98 + 39.99 +.PHONY: clean 39.100 +clean:
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/tools/hotplug/Linux/blktap Tue Nov 25 14:21:24 2008 +0900 40.3 @@ -0,0 +1,93 @@ 40.4 +#!/bin/bash 40.5 + 40.6 +# Copyright (c) 2005, XenSource Ltd. 40.7 + 40.8 +dir=$(dirname "$0") 40.9 +. "$dir/xen-hotplug-common.sh" 40.10 +. "$dir/block-common.sh" 40.11 + 40.12 +findCommand "$@" 40.13 + 40.14 +## 40.15 +# check_blktap_sharing file mode 40.16 +# 40.17 +# Perform the sharing check for the given blktap and mode. 40.18 +# 40.19 +check_blktap_sharing() 40.20 +{ 40.21 + local file="$1" 40.22 + local mode="$2" 40.23 + 40.24 + local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE" 40.25 + for dom in $(xenstore-list "$base_path") 40.26 + do 40.27 + for dev in $(xenstore-list "$base_path/$dom") 40.28 + do 40.29 + params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2) 40.30 + if [ "$file" = "$params" ] 40.31 + then 40.32 + 40.33 + if [ "$mode" = 'w' ] 40.34 + then 40.35 + if ! same_vm "$dom" 40.36 + then 40.37 + echo 'guest' 40.38 + return 40.39 + fi 40.40 + else 40.41 + local m=$(xenstore_read "$base_path/$dom/$dev/mode") 40.42 + m=$(canonicalise_mode "$m") 40.43 + 40.44 + if [ "$m" = 'w' ] 40.45 + then 40.46 + if ! same_vm "$dom" 40.47 + then 40.48 + echo 'guest' 40.49 + return 40.50 + fi 40.51 + fi 40.52 + fi 40.53 + fi 40.54 + done 40.55 + done 40.56 + 40.57 + echo 'ok' 40.58 +} 40.59 + 40.60 + 40.61 +t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') 40.62 +if [ -n "$t" ] 40.63 +then 40.64 + p=$(xenstore_read "$XENBUS_PATH/params") 40.65 + # if we have a ':', chew from head including : 40.66 + if echo $p | grep -q \: 40.67 + then 40.68 + p=${p#*:} 40.69 + fi 40.70 +fi 40.71 +# some versions of readlink cannot be passed a regular file 40.72 +if [ -L "$p" ]; then 40.73 + file=$(readlink -f "$p") || fatal "$p link does not exist." 40.74 +else 40.75 + file="$p" 40.76 +fi 40.77 + 40.78 +if [ "$command" = 'add' ] 40.79 +then 40.80 + [ -e "$file" ] || { fatal $file does not exist; } 40.81 + 40.82 + FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id") 40.83 + FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm") 40.84 + mode=$(xenstore_read "$XENBUS_PATH/mode") 40.85 + mode=$(canonicalise_mode "$mode") 40.86 + 40.87 + if [ "$mode" != '!' ] 40.88 + then 40.89 + result=$(check_blktap_sharing "$file" "$mode") 40.90 + [ "$result" = 'ok' ] || ebusy "$file already in use by other domain" 40.91 + fi 40.92 + 40.93 + success 40.94 +fi 40.95 + 40.96 +exit 0
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/tools/hotplug/Linux/block Tue Nov 25 14:21:24 2008 +0900 41.3 @@ -0,0 +1,381 @@ 41.4 +#!/bin/bash 41.5 + 41.6 +dir=$(dirname "$0") 41.7 +. "$dir/block-common.sh" 41.8 + 41.9 +expand_dev() { 41.10 + local dev 41.11 + case $1 in 41.12 + /*) 41.13 + dev=$1 41.14 + ;; 41.15 + *) 41.16 + dev=/dev/$1 41.17 + ;; 41.18 + esac 41.19 + echo -n $dev 41.20 +} 41.21 + 41.22 + 41.23 +## 41.24 +# check_sharing device mode 41.25 +# 41.26 +# Check whether the device requested is already in use. To use the device in 41.27 +# read-only mode, it may be in use in read-only mode, but may not be in use in 41.28 +# read-write anywhere at all. To use the device in read-write mode, it must 41.29 +# not be in use anywhere at all. 41.30 +# 41.31 +# Prints one of 41.32 +# 41.33 +# 'local': the device may not be used because it is mounted in the current 41.34 +# (i.e. the privileged domain) in a way incompatible with the 41.35 +# requested mode; 41.36 +# 'guest': the device may not be used because it already mounted by a guest 41.37 +# in a way incompatible with the requested mode; or 41.38 +# 'ok': the device may be used. 41.39 +# 41.40 +check_sharing() 41.41 +{ 41.42 + local dev="$1" 41.43 + local mode="$2" 41.44 + 41.45 + local devmm=$(device_major_minor "$dev") 41.46 + local file 41.47 + 41.48 + if [ "$mode" = 'w' ] 41.49 + then 41.50 + toskip="^$" 41.51 + else 41.52 + toskip="^[^ ]* [^ ]* [^ ]* ro[, ]" 41.53 + fi 41.54 + 41.55 + for file in $(cat /proc/mounts | grep -v "$toskip" | cut -f 1 -d ' ') 41.56 + do 41.57 + if [ -e "$file" ] 41.58 + then 41.59 + local d=$(device_major_minor "$file") 41.60 + 41.61 + if [ "$d" = "$devmm" ] 41.62 + then 41.63 + echo 'local' 41.64 + return 41.65 + fi 41.66 + fi 41.67 + done 41.68 + 41.69 + local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE" 41.70 + for dom in $(xenstore-list "$base_path") 41.71 + do 41.72 + for dev in $(xenstore-list "$base_path/$dom") 41.73 + do 41.74 + d=$(xenstore_read_default "$base_path/$dom/$dev/physical-device" "") 41.75 + 41.76 + if [ "$d" = "$devmm" ] 41.77 + then 41.78 + if [ "$mode" = 'w' ] 41.79 + then 41.80 + if ! same_vm $dom 41.81 + then 41.82 + echo 'guest' 41.83 + return 41.84 + fi 41.85 + else 41.86 + local m=$(xenstore_read "$base_path/$dom/$dev/mode") 41.87 + m=$(canonicalise_mode "$m") 41.88 + 41.89 + if [ "$m" = 'w' ] 41.90 + then 41.91 + if ! same_vm $dom 41.92 + then 41.93 + echo 'guest' 41.94 + return 41.95 + fi 41.96 + fi 41.97 + fi 41.98 + fi 41.99 + done 41.100 + done 41.101 + 41.102 + echo 'ok' 41.103 +} 41.104 + 41.105 + 41.106 +## 41.107 +# check_device_sharing dev mode 41.108 +# 41.109 +# Perform the sharing check for the given physical device and mode. 41.110 +# 41.111 +check_device_sharing() 41.112 +{ 41.113 + local dev="$1" 41.114 + local mode=$(canonicalise_mode "$2") 41.115 + local result 41.116 + 41.117 + if [ "x$mode" = 'x!' ] 41.118 + then 41.119 + return 0 41.120 + fi 41.121 + 41.122 + result=$(check_sharing "$dev" "$mode") 41.123 + 41.124 + if [ "$result" != 'ok' ] 41.125 + then 41.126 + do_ebusy "Device $dev is mounted " "$mode" "$result" 41.127 + fi 41.128 +} 41.129 + 41.130 + 41.131 +## 41.132 +# check_device_sharing file dev mode 41.133 +# 41.134 +# Perform the sharing check for the given file mounted through the given 41.135 +# loopback interface, in the given mode. 41.136 +# 41.137 +check_file_sharing() 41.138 +{ 41.139 + local file="$1" 41.140 + local dev="$2" 41.141 + local mode="$3" 41.142 + 41.143 + result=$(check_sharing "$dev" "$mode") 41.144 + 41.145 + if [ "$result" != 'ok' ] 41.146 + then 41.147 + do_ebusy "File $file is loopback-mounted through $dev, 41.148 +which is mounted " "$mode" "$result" 41.149 + fi 41.150 +} 41.151 + 41.152 + 41.153 +## 41.154 +# do_ebusy prefix mode result 41.155 +# 41.156 +# Helper function for check_device_sharing check_file_sharing, calling ebusy 41.157 +# with an error message constructed from the given prefix, mode, and result 41.158 +# from a call to check_sharing. 41.159 +# 41.160 +do_ebusy() 41.161 +{ 41.162 + local prefix="$1" 41.163 + local mode="$2" 41.164 + local result="$3" 41.165 + 41.166 + if [ "$result" = 'guest' ] 41.167 + then 41.168 + dom='a guest ' 41.169 + when='now' 41.170 + else 41.171 + dom='the privileged ' 41.172 + when='by a guest' 41.173 + fi 41.174 + 41.175 + if [ "$mode" = 'w' ] 41.176 + then 41.177 + m1='' 41.178 + m2='' 41.179 + else 41.180 + m1='read-write ' 41.181 + m2='read-only ' 41.182 + fi 41.183 + 41.184 + release_lock "block" 41.185 + ebusy \ 41.186 +"${prefix}${m1}in ${dom}domain, 41.187 +and so cannot be mounted ${m2}${when}." 41.188 +} 41.189 + 41.190 + 41.191 +t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') 41.192 + 41.193 +case "$command" in 41.194 + add) 41.195 + phys=$(xenstore_read_default "$XENBUS_PATH/physical-device" 'MISSING') 41.196 + if [ "$phys" != 'MISSING' ] 41.197 + then 41.198 + # Depending upon the hotplug configuration, it is possible for this 41.199 + # script to be called twice, so just bail. 41.200 + exit 0 41.201 + fi 41.202 + 41.203 + if [ -n "$t" ] 41.204 + then 41.205 + p=$(xenstore_read "$XENBUS_PATH/params") 41.206 + mode=$(xenstore_read "$XENBUS_PATH/mode") 41.207 + fi 41.208 + 41.209 + case $t in 41.210 + phy) 41.211 + dev=$(expand_dev $p) 41.212 + FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id") 41.213 + FRONTEND_UUID=$(xenstore_read_default \ 41.214 + "/local/domain/$FRONTEND_ID/vm" 'unknown') 41.215 + 41.216 + if [ -L "$dev" ] 41.217 + then 41.218 + dev=$(readlink -f "$dev") || fatal "$dev link does not exist." 41.219 + fi 41.220 + test -e "$dev" || fatal "$dev does not exist." 41.221 + test -b "$dev" || fatal "$dev is not a block device." 41.222 + 41.223 + claim_lock "block" 41.224 + check_device_sharing "$dev" "$mode" 41.225 + write_dev "$dev" 41.226 + release_lock "block" 41.227 + exit 0 41.228 + ;; 41.229 + 41.230 + file) 41.231 + # Canonicalise the file, for sharing check comparison, and the mode 41.232 + # for ease of use here. 41.233 + file=$(readlink -f "$p") || fatal "$p does not exist." 41.234 + test -f "$file" || fatal "$file does not exist." 41.235 + mode=$(canonicalise_mode "$mode") 41.236 + 41.237 + claim_lock "block" 41.238 + 41.239 + if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w 41.240 + then 41.241 + release_lock "block" 41.242 + ebusy \ 41.243 +"File $file is read-only, and so I will not 41.244 +mount it read-write in a guest domain." 41.245 + fi 41.246 + 41.247 + loopdev='' 41.248 + for dev in /dev/loop* 41.249 + do 41.250 + if [ ! -b "$dev" ] 41.251 + then 41.252 + continue 41.253 + fi 41.254 + 41.255 + f=$(losetup "$dev" 2>/dev/null) || f='' 41.256 + 41.257 + if [ "$f" ] 41.258 + then 41.259 + # $dev is in use. Check sharing. 41.260 + if [ "x$mode" = 'x!' ] 41.261 + then 41.262 + continue 41.263 + fi 41.264 + 41.265 + f=$(echo "$f" | sed -e 's/.*(\(.*\)).*/\1/g') 41.266 + 41.267 + # $f is the filename, as read from losetup, but the loopback 41.268 + # driver truncates filenames at 64 characters, so we need to go 41.269 + # trawling through the store if it's longer than that. Truncation 41.270 + # is indicated by an asterisk at the end of the filename. 41.271 + if expr index "$f" '*' >/dev/null 41.272 + then 41.273 + found="" 41.274 + for dom in $(xenstore-list "$XENBUS_BASE_PATH") 41.275 + do 41.276 + for domdev in $(xenstore-list "$XENBUS_BASE_PATH/$dom") 41.277 + do 41.278 + d=$(xenstore_read_default \ 41.279 + "$XENBUS_BASE_PATH/$dom/$domdev/node" "") 41.280 + if [ "$d" = "$dev" ] 41.281 + then 41.282 + f=$(xenstore_read "$XENBUS_BASE_PATH/$dom/$domdev/params") 41.283 + found=1 41.284 + break 2 41.285 + fi 41.286 + done 41.287 + done 41.288 + 41.289 + if [ ! "$found" ] 41.290 + then 41.291 + # This loopback device is in use by someone else, so skip it. 41.292 + log debug "Loopback sharing check skips device $dev." 41.293 + continue 41.294 + fi 41.295 + fi 41.296 + 41.297 + # Canonicalise the filename for the comparison. 41.298 + 41.299 + # I have seen this readlink fails because the filename given by 41.300 + # losetup is only the basename. This cannot happen when the loop 41.301 + # device is set up through this script, because file is 41.302 + # canonicalised above, but it may happen when loop devices are set 41.303 + # up some other way. This readlink may also conceivably fail if 41.304 + # the file backing this loop device has been removed. 41.305 + 41.306 + # For maximum safety, in the case that $f does not resolve, we 41.307 + # assume that $file and $f are in the same directory. 41.308 + 41.309 + # If you create a loopback filesystem, remove it and continue to 41.310 + # run on it, and then create another file with the same name, then 41.311 + # this check will block that -- don't do that. 41.312 + 41.313 + # If you create loop devices through some other mechanism, use 41.314 + # relative filenames, and then use the same filename through this 41.315 + # script, then this check will block that -- don't do that either. 41.316 + 41.317 + f=$(readlink -f "$f" || echo $(dirname "$file")/$(basename "$f")) 41.318 + 41.319 + 41.320 + if [ "$f" = "$file" ] 41.321 + then 41.322 + check_file_sharing "$file" "$dev" "$mode" 41.323 + fi 41.324 + else 41.325 + # $dev is not in use, so we'll remember it for use later; we want 41.326 + # to finish the sharing check first. 41.327 + 41.328 + if [ "$loopdev" = '' ] 41.329 + then 41.330 + loopdev="$dev" 41.331 + fi 41.332 + fi 41.333 + done 41.334 + 41.335 + if [ "$loopdev" = '' ] 41.336 + then 41.337 + release_lock "block" 41.338 + fatal 'Failed to find an unused loop device' 41.339 + fi 41.340 + 41.341 + if LANG=C losetup -h 2>&1 | grep read-only >/dev/null 41.342 + then 41.343 + roflag="-$mode"; roflag="${roflag#-w}"; roflag="${roflag#-!}" 41.344 + else 41.345 + roflag='' 41.346 + fi 41.347 + do_or_die losetup $roflag "$loopdev" "$file" 41.348 + xenstore_write "$XENBUS_PATH/node" "$loopdev" 41.349 + write_dev "$loopdev" 41.350 + release_lock "block" 41.351 + exit 0 41.352 + ;; 41.353 + 41.354 + "") 41.355 + claim_lock "block" 41.356 + success 41.357 + release_lock "block" 41.358 + ;; 41.359 + esac 41.360 + ;; 41.361 + 41.362 + remove) 41.363 + case $t in 41.364 + phy) 41.365 + exit 0 41.366 + ;; 41.367 + 41.368 + file) 41.369 + node=$(xenstore_read "$XENBUS_PATH/node") 41.370 + losetup -d "$node" 41.371 + exit 0 41.372 + ;; 41.373 + 41.374 + "") 41.375 + exit 0 41.376 + ;; 41.377 + esac 41.378 + ;; 41.379 + 41.380 +esac 41.381 + 41.382 +# If we've reached here, $t is neither phy nor file, so fire a helper script. 41.383 +[ -x /etc/xen/scripts/block-"$t" ] && \ 41.384 + /etc/xen/scripts/block-"$t" "$command" $node
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/tools/hotplug/Linux/block-common.sh Tue Nov 25 14:21:24 2008 +0900 42.3 @@ -0,0 +1,116 @@ 42.4 +# 42.5 +# Copyright (c) 2005 XenSource Ltd. 42.6 +# 42.7 +# This library is free software; you can redistribute it and/or 42.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 42.9 +# License as published by the Free Software Foundation. 42.10 +# 42.11 +# This library is distributed in the hope that it will be useful, 42.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 42.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 42.14 +# Lesser General Public License for more details. 42.15 +# 42.16 +# You should have received a copy of the GNU Lesser General Public 42.17 +# License along with this library; if not, write to the Free Software 42.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 42.19 +# 42.20 + 42.21 + 42.22 +dir=$(dirname "$0") 42.23 +. "$dir/xen-hotplug-common.sh" 42.24 + 42.25 +findCommand "$@" 42.26 + 42.27 +if [ "$command" != "add" ] && 42.28 + [ "$command" != "remove" ] 42.29 +then 42.30 + log err "Invalid command: $command" 42.31 + exit 1 42.32 +fi 42.33 + 42.34 + 42.35 +XENBUS_PATH="${XENBUS_PATH:?}" 42.36 + 42.37 + 42.38 +ebusy() 42.39 +{ 42.40 + xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \ 42.41 + "$XENBUS_PATH/hotplug-status" busy 42.42 + log err "$@" 42.43 + exit 1 42.44 +} 42.45 + 42.46 + 42.47 +## 42.48 +# Print the given device's major and minor numbers, written in hex and 42.49 +# separated by a colon. 42.50 +device_major_minor() 42.51 +{ 42.52 + stat -L -c %t:%T "$1" 42.53 +} 42.54 + 42.55 + 42.56 +## 42.57 +# Write physical-device = MM,mm to the store, where MM and mm are the major 42.58 +# and minor numbers of device respectively. 42.59 +# 42.60 +# @param device The device from which major and minor numbers are read, which 42.61 +# will be written into the store. 42.62 +# 42.63 +write_dev() { 42.64 + local mm 42.65 + 42.66 + mm=$(device_major_minor "$1") 42.67 + 42.68 + if [ -z $mm ] 42.69 + then 42.70 + fatal "Backend device does not exist" 42.71 + fi 42.72 + 42.73 + xenstore_write "$XENBUS_PATH/physical-device" "$mm" 42.74 + 42.75 + success 42.76 +} 42.77 + 42.78 + 42.79 +## 42.80 +# canonicalise_mode mode 42.81 +# 42.82 +# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations 42.83 +# thereof, and canonicalises them to one of 42.84 +# 42.85 +# 'r': perform checks for a new read-only mount; 42.86 +# 'w': perform checks for a read-write mount; or 42.87 +# '!': perform no checks at all. 42.88 +# 42.89 +canonicalise_mode() 42.90 +{ 42.91 + local mode="$1" 42.92 + 42.93 + if ! expr index "$mode" 'w' >/dev/null 42.94 + then 42.95 + echo 'r' 42.96 + elif ! expr index "$mode" '!' >/dev/null 42.97 + then 42.98 + echo 'w' 42.99 + else 42.100 + echo '!' 42.101 + fi 42.102 +} 42.103 + 42.104 + 42.105 +same_vm() 42.106 +{ 42.107 + local otherdom="$1" 42.108 + # Note that othervm can be MISSING here, because Xend will be racing with 42.109 + # the hotplug scripts -- the entries in /local/domain can be removed by 42.110 + # Xend before the hotplug scripts have removed the entry in 42.111 + # /local/domain/0/backend/. In this case, we want to pretend that the 42.112 + # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be 42.113 + # allowed. 42.114 + local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \ 42.115 + "$FRONTEND_UUID") 42.116 + 42.117 + [ "$FRONTEND_UUID" = "$othervm" ] 42.118 +} 42.119 +
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/tools/hotplug/Linux/block-enbd Tue Nov 25 14:21:24 2008 +0900 43.3 @@ -0,0 +1,27 @@ 43.4 +#!/bin/bash 43.5 + 43.6 +# Usage: block-enbd [bind server ctl_port |unbind node] 43.7 +# 43.8 +# The node argument to unbind is the name of the device node we are to 43.9 +# unbind. 43.10 +# 43.11 +# This assumes you're running a correctly configured server at the other end! 43.12 + 43.13 +dir=$(dirname "$0") 43.14 +. "$dir/block-common.sh" 43.15 + 43.16 +case "$command" in 43.17 + add) 43.18 + for dev in /dev/nd*; do 43.19 + if nbd-client $2:$3 $dev; then 43.20 + write_dev $dev 43.21 + exit 0 43.22 + fi 43.23 + done 43.24 + exit 1 43.25 + ;; 43.26 + remove) 43.27 + nbd-client -d $2 43.28 + exit 0 43.29 + ;; 43.30 +esac
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/tools/hotplug/Linux/block-nbd Tue Nov 25 14:21:24 2008 +0900 44.3 @@ -0,0 +1,27 @@ 44.4 +#!/bin/bash 44.5 + 44.6 +# Usage: block-nbd [bind server ctl_port |unbind node] 44.7 +# 44.8 +# The node argument to unbind is the name of the device node we are to 44.9 +# unbind. 44.10 +# 44.11 +# This assumes you're running a correctly configured server at the other end! 44.12 + 44.13 +dir=$(dirname "$0") 44.14 +. "$dir/block-common.sh" 44.15 + 44.16 +case "$command" in 44.17 + add) 44.18 + for dev in /dev/nbd*; do 44.19 + if nbd-client $2 $3 $dev; then 44.20 + write_dev $dev 44.21 + exit 0 44.22 + fi 44.23 + done 44.24 + exit 1 44.25 + ;; 44.26 + remove) 44.27 + nbd-client -d $2 44.28 + exit 0 44.29 + ;; 44.30 +esac
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/tools/hotplug/Linux/external-device-migrate Tue Nov 25 14:21:24 2008 +0900 45.3 @@ -0,0 +1,98 @@ 45.4 +#!/bin/bash 45.5 + 45.6 +# Copyright (c) 2005 IBM Corporation 45.7 +# 45.8 +# This library is free software; you can redistribute it and/or 45.9 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 45.10 +# License as published by the Free Software Foundation. 45.11 +# 45.12 +# This library is distributed in the hope that it will be useful, 45.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 45.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 45.15 +# Lesser General Public License for more details. 45.16 +# 45.17 +# You should have received a copy of the GNU Lesser General Public 45.18 +# License along with this library; if not, write to the Free Software 45.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 45.20 +# 45.21 + 45.22 +set -x 45.23 + 45.24 +# This script is called by XenD for migration of external devices 45.25 +# It does not handle the migration of those devices itself, but 45.26 +# passes the requests on to further applications 45.27 +# It handles the low-level command line parsing and some of the 45.28 +# synchronization 45.29 + 45.30 +dir=$(dirname "$0") 45.31 +. "$dir/logging.sh" 45.32 + 45.33 + 45.34 +function ext_dev_migrate_usage() { 45.35 +cat <<EOF 45.36 +Pass the following command line parameters to the script: 45.37 + 45.38 +-step <n> : n-th migration step 45.39 +-host <host> : the destination host 45.40 +-domname <domain name> : name of the domain that is migrating 45.41 +-type <device type> : the type of device that is migrating 45.42 +-subtype <dev. subtype>: the subtype of the device 45.43 +-recover : indicates recovery request; an error 45.44 + occurred during migration 45.45 +-help : display this help screen 45.46 +EOF 45.47 +} 45.48 + 45.49 +# Parse the command line paramters. The following parameters must be 45.50 +# passed as the first ones in the sequence: 45.51 +# -step [required] 45.52 +# -host [required] 45.53 +# -domname [required] 45.54 +# -type [required] 45.55 +# -subtype [optional] 45.56 +# -recover [optional] 45.57 +# The remaining ones will be passed to the called function. 45.58 +function evaluate_params() 45.59 +{ 45.60 + local step host domname typ recover filename func stype 45.61 + stype="" 45.62 + while [ $# -ge 1 ]; do 45.63 + case "$1" in 45.64 + -step) step=$2; shift; shift;; 45.65 + -host) host=$2; shift; shift;; 45.66 + -domname) domname=$2; shift; shift;; 45.67 + -type) typ=$2; shift; shift;; 45.68 + -subtype) stype=$2; shift; shift;; 45.69 + -recover) recover=1; shift;; 45.70 + -help) ext_dev_migrate_usage; exit 0;; 45.71 + *) break;; 45.72 + esac 45.73 + done 45.74 + 45.75 + if [ "$step" = "" -o \ 45.76 + "$host" = "" -o \ 45.77 + "$typ" = "" -o \ 45.78 + "$domname" = "" ]; then 45.79 + echo "Error: Parameter(s) missing (-step/-host/-type/-domname)" 1>&2 45.80 + echo "" 1>&2 45.81 + echo "$0 -help for usage." 1>&2 45.82 + exit 1 45.83 + fi 45.84 + 45.85 + filename="$dir/$typ$stype-migration.sh" 45.86 + if [ ! -r $filename ]; then 45.87 + echo "Error: Could not find script '$filename'" 45.88 + return 45.89 + fi 45.90 + . "$filename" 45.91 + 45.92 + if [ "$recover" = "1" ]; then 45.93 + func="$typ"_recover 45.94 + eval $func $host $domname $step $* 45.95 + else 45.96 + func="$typ"_migration_step 45.97 + eval $func $host $domname $step $* 45.98 + fi 45.99 +} 45.100 + 45.101 +evaluate_params "$@"
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/tools/hotplug/Linux/init.d/sysconfig.xendomains Tue Nov 25 14:21:24 2008 +0900 46.3 @@ -0,0 +1,137 @@ 46.4 +## Path: System/xen 46.5 +## Description: xen domain start/stop on boot 46.6 +## Type: string 46.7 +## Default: 46.8 +# 46.9 +# The xendomains script can send SysRq requests to domains on shutdown. 46.10 +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility 46.11 +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks 46.12 +# of the domains ("s"). 46.13 +# 46.14 +XENDOMAINS_SYSRQ="" 46.15 + 46.16 +## Type: integer 46.17 +## Default: 100000 46.18 +# 46.19 +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait 46.20 +# (in microseconds) after each SysRq, so the domain has a chance to react. 46.21 +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set 46.22 +# it to a relatively high value (1200000). 46.23 +# 46.24 +XENDOMAINS_USLEEP=100000 46.25 + 46.26 +## Type: integer 46.27 +## Default: 5000000 46.28 +# 46.29 +# When creating a guest domain, it is sensible to allow a little time for it 46.30 +# to get started before creating another domain or proceeding through the 46.31 +# boot process. Without this, the booting guests will thrash the disk as they 46.32 +# start up. This timeout (in microseconds) specifies the delay after guest 46.33 +# domain creation. 46.34 +# 46.35 +XENDOMAINS_CREATE_USLEEP=5000000 46.36 + 46.37 +## Type: string 46.38 +## Default: "" 46.39 +# 46.40 +# Set this to a non-empty string if you want to migrate virtual machines 46.41 +# on shutdown. The string will be passed to the xm migrate DOMID command 46.42 +# as is: It should contain the target IP address of the physical machine 46.43 +# to migrate to and optionally parameters like --live. Leave empty if 46.44 +# you don't want to try virtual machine relocation on shutdown. 46.45 +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for 46.46 +# that domain. 46.47 +# 46.48 +XENDOMAINS_MIGRATE="" 46.49 + 46.50 +## Type: string 46.51 +## Default: /var/lib/xen/save 46.52 +# 46.53 +# Directory to save running domains to when the system (dom0) is 46.54 +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE 46.55 +# is set (see below). Leave empty to disable domain saving on shutdown 46.56 +# (e.g. because you rather shut domains down). 46.57 +# If domain saving does succeed, SHUTDOWN will not be executed. 46.58 +# 46.59 +XENDOMAINS_SAVE=/var/lib/xen/save 46.60 + 46.61 +## Type: string 46.62 +## Default: "--halt --wait" 46.63 +# 46.64 +# If neither MIGRATE nor SAVE were enabled or if they failed, you can 46.65 +# try to shut down a domain by sending it a shutdown request. To do this, 46.66 +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting 46.67 +# for the domain to be really down. Leave empty to skip domain shutdown. 46.68 +# 46.69 +XENDOMAINS_SHUTDOWN="--halt --wait" 46.70 + 46.71 +## Type: string 46.72 +## Default: "--all --halt --wait" 46.73 +# 46.74 +# After we have gone over all virtual machines (resp. all automatically 46.75 +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, 46.76 +# migrated, saved and/or shutdown according to the settings above, we 46.77 +# might want to shutdown the virtual machines that are still running 46.78 +# for some reason or another. To do this, set this variable to 46.79 +# "--all --halt --wait", it will be passed to xm shutdown. 46.80 +# Leave it empty not to do anything special here. 46.81 +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY 46.82 +# is set.) 46.83 +# 46.84 +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" 46.85 + 46.86 +## Type: boolean 46.87 +## Default: true 46.88 +# 46.89 +# This variable determines whether saved domains from XENDOMAINS_SAVE 46.90 +# will be restored on system startup. 46.91 +# 46.92 +XENDOMAINS_RESTORE=true 46.93 + 46.94 +## Type: string 46.95 +## Default: /etc/xen/auto 46.96 +# 46.97 +# This variable sets the directory where domains configurations 46.98 +# are stored that should be started on system startup automatically. 46.99 +# Leave empty if you don't want to start domains automatically 46.100 +# (or just don't place any xen domain config files in that dir). 46.101 +# Note that the script tries to be clever if both RESTORE and AUTO are 46.102 +# set: It will first restore saved domains and then only start domains 46.103 +# in AUTO which are not running yet. 46.104 +# Note that the name matching is somewhat fuzzy. 46.105 +# 46.106 +XENDOMAINS_AUTO=/etc/xen/auto 46.107 + 46.108 +## Type: boolean 46.109 +## Default: false 46.110 +# 46.111 +# If this variable is set to "true", only the domains started via config 46.112 +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, 46.113 +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise 46.114 +# all running domains will be. 46.115 +# Note that the name matching is somewhat fuzzy. 46.116 +# 46.117 +XENDOMAINS_AUTO_ONLY=false 46.118 + 46.119 +## Type: integer 46.120 +## Default: 300 46.121 +# 46.122 +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, 46.123 +# shutdown --all) may be executed. In the worst case, these commands may 46.124 +# stall forever, which will prevent a successful shutdown of the machine. 46.125 +# If this variable is non-zero, the script will set up a watchdog timer 46.126 +# for every of these xm commands and time it out after the number of seconds 46.127 +# specified by this variable. 46.128 +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only 46.129 +# zombies are still running, so you don't need to enable this timeout just 46.130 +# for the zombie case. 46.131 +# The setting should be large enough to make sure that migrate/save/shutdown 46.132 +# can succeed. If you do live migrations, keep in mind that live migration 46.133 +# of a 1GB machine over Gigabit ethernet may actually take something like 46.134 +# 100s (assuming that live migration uses 10% of the network # bandwidth). 46.135 +# Depending on the virtual machine, a shutdown may also require a significant 46.136 +# amount of time. So better setup this variable to a huge number and hope the 46.137 +# watchdog never fires. 46.138 +# 46.139 +XENDOMAINS_STOP_MAXWAIT=300 46.140 +
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/tools/hotplug/Linux/init.d/xend Tue Nov 25 14:21:24 2008 +0900 47.3 @@ -0,0 +1,66 @@ 47.4 +#!/bin/bash 47.5 +# 47.6 +# xend Script to start and stop the Xen control daemon. 47.7 +# 47.8 +# Author: Keir Fraser <keir.fraser@cl.cam.ac.uk> 47.9 +# 47.10 +# chkconfig: 2345 98 01 47.11 +# description: Starts and stops the Xen control daemon. 47.12 +### BEGIN INIT INFO 47.13 +# Provides: xend 47.14 +# Required-Start: $syslog $remote_fs 47.15 +# Should-Start: 47.16 +# Required-Stop: $syslog $remote_fs 47.17 +# Should-Stop: 47.18 +# Default-Start: 3 4 5 47.19 +# Default-Stop: 0 1 2 6 47.20 +# Default-Enabled: yes 47.21 +# Short-Description: Start/stop xend 47.22 +# Description: Starts and stops the Xen control daemon. 47.23 +### END INIT INFO 47.24 + 47.25 +if ! grep -q "control_d" /proc/xen/capabilities ; then 47.26 + exit 0 47.27 +fi 47.28 + 47.29 +# Wait for Xend to be up 47.30 +function await_daemons_up 47.31 +{ 47.32 + i=1 47.33 + rets=10 47.34 + xend status 47.35 + while [ $? -ne 0 -a $i -lt $rets ]; do 47.36 + sleep 1 47.37 + echo -n . 47.38 + i=$(($i + 1)) 47.39 + xend status 47.40 + done 47.41 +} 47.42 + 47.43 +case "$1" in 47.44 + start) 47.45 + xend start 47.46 + await_daemons_up 47.47 + ;; 47.48 + stop) 47.49 + xend stop 47.50 + ;; 47.51 + status) 47.52 + xend status 47.53 + ;; 47.54 + reload) 47.55 + xend reload 47.56 + ;; 47.57 + restart|force-reload) 47.58 + xend restart 47.59 + await_daemons_up 47.60 + ;; 47.61 + *) 47.62 + # do not advertise unreasonable commands that there is no reason 47.63 + # to use with this device 47.64 + echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" 47.65 + exit 1 47.66 +esac 47.67 + 47.68 +exit $? 47.69 +
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/tools/hotplug/Linux/init.d/xendomains Tue Nov 25 14:21:24 2008 +0900 48.3 @@ -0,0 +1,531 @@ 48.4 +#!/bin/bash 48.5 +# 48.6 +# /etc/init.d/xendomains 48.7 +# Start / stop domains automatically when domain 0 boots / shuts down. 48.8 +# 48.9 +# chkconfig: 345 99 00 48.10 +# description: Start / stop Xen domains. 48.11 +# 48.12 +# This script offers fairly basic functionality. It should work on Redhat 48.13 +# but also on LSB-compliant SuSE releases and on Debian with the LSB package 48.14 +# installed. (LSB is the Linux Standard Base) 48.15 +# 48.16 +# Based on the example in the "Designing High Quality Integrated Linux 48.17 +# Applications HOWTO" by Avi Alkalay 48.18 +# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/> 48.19 +# 48.20 +### BEGIN INIT INFO 48.21 +# Provides: xendomains 48.22 +# Required-Start: $syslog $remote_fs xend 48.23 +# Should-Start: 48.24 +# Required-Stop: $syslog $remote_fs xend 48.25 +# Should-Stop: 48.26 +# Default-Start: 3 4 5 48.27 +# Default-Stop: 0 1 2 6 48.28 +# Default-Enabled: yes 48.29 +# Short-Description: Start/stop secondary xen domains 48.30 +# Description: Start / stop domains automatically when domain 0 48.31 +# boots / shuts down. 48.32 +### END INIT INFO 48.33 + 48.34 +# Correct exit code would probably be 5, but it's enough 48.35 +# if xend complains if we're not running as privileged domain 48.36 +if ! [ -e /proc/xen/privcmd ]; then 48.37 + exit 0 48.38 +fi 48.39 + 48.40 +LOCKFILE=/var/lock/subsys/xendomains 48.41 +XENDOM_CONFIG=/etc/sysconfig/xendomains 48.42 + 48.43 +test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing"; 48.44 + if [ "$1" = "stop" ]; then exit 0; 48.45 + else exit 6; fi; } 48.46 + 48.47 +. $XENDOM_CONFIG 48.48 + 48.49 +# Use the SUSE rc_ init script functions; 48.50 +# emulate them on LSB, RH and other systems 48.51 +if test -e /etc/rc.status; then 48.52 + # SUSE rc script library 48.53 + . /etc/rc.status 48.54 +else 48.55 + _cmd=$1 48.56 + declare -a _SMSG 48.57 + if test "${_cmd}" = "status"; then 48.58 + _SMSG=(running dead dead unused unknown) 48.59 + _RC_UNUSED=3 48.60 + else 48.61 + _SMSG=(done failed failed missed failed skipped unused failed failed) 48.62 + _RC_UNUSED=6 48.63 + fi 48.64 + if test -e /etc/init.d/functions; then 48.65 + # REDHAT 48.66 + . /etc/init.d/functions 48.67 + echo_rc() 48.68 + { 48.69 + #echo -n " [${_SMSG[${_RC_RV}]}] " 48.70 + if test ${_RC_RV} = 0; then 48.71 + success " [${_SMSG[${_RC_RV}]}] " 48.72 + else 48.73 + failure " [${_SMSG[${_RC_RV}]}] " 48.74 + fi 48.75 + } 48.76 + elif test -e /lib/lsb/init-functions; then 48.77 + # LSB 48.78 + . /lib/lsb/init-functions 48.79 + if alias log_success_msg >/dev/null 2>/dev/null; then 48.80 + echo_rc() 48.81 + { 48.82 + echo " [${_SMSG[${_RC_RV}]}] " 48.83 + } 48.84 + else 48.85 + echo_rc() 48.86 + { 48.87 + if test ${_RC_RV} = 0; then 48.88 + log_success_msg " [${_SMSG[${_RC_RV}]}] " 48.89 + else 48.90 + log_failure_msg " [${_SMSG[${_RC_RV}]}] " 48.91 + fi 48.92 + } 48.93 + fi 48.94 + else 48.95 + # emulate it 48.96 + echo_rc() 48.97 + { 48.98 + echo " [${_SMSG[${_RC_RV}]}] " 48.99 + } 48.100 + fi 48.101 + rc_reset() { _RC_RV=0; } 48.102 + rc_failed() 48.103 + { 48.104 + if test -z "$1"; then 48.105 + _RC_RV=1; 48.106 + elif test "$1" != "0"; then 48.107 + _RC_RV=$1; 48.108 + fi 48.109 + return ${_RC_RV} 48.110 + } 48.111 + rc_check() 48.112 + { 48.113 + return rc_failed $? 48.114 + } 48.115 + rc_status() 48.116 + { 48.117 + rc_failed $? 48.118 + if test "$1" = "-r"; then _RC_RV=0; shift; fi 48.119 + if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi 48.120 + if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi 48.121 + if test "$1" = "-v"; then echo_rc; shift; fi 48.122 + if test "$1" = "-r"; then _RC_RV=0; shift; fi 48.123 + return ${_RC_RV} 48.124 + } 48.125 + rc_exit() { exit ${_RC_RV}; } 48.126 + rc_active() 48.127 + { 48.128 + if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi 48.129 + if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi 48.130 + return 1 48.131 + } 48.132 +fi 48.133 + 48.134 +if ! which usleep >&/dev/null 48.135 +then 48.136 + usleep() 48.137 + { 48.138 + if [ -n "$1" ] 48.139 + then 48.140 + sleep $(( $1 / 1000000 )) 48.141 + fi 48.142 + } 48.143 +fi 48.144 + 48.145 +# Reset status of this service 48.146 +rc_reset 48.147 + 48.148 +## 48.149 +# Returns 0 (success) if the given parameter names a directory, and that 48.150 +# directory is not empty. 48.151 +# 48.152 +contains_something() 48.153 +{ 48.154 + if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ] 48.155 + then 48.156 + return 0 48.157 + else 48.158 + return 1 48.159 + fi 48.160 +} 48.161 + 48.162 +# read name from xen config file 48.163 +rdname() 48.164 +{ 48.165 + NM=$(xm create --quiet --dryrun --defconfig "$1" | 48.166 + sed -n 's/^.*(name \(.*\))$/\1/p') 48.167 +} 48.168 + 48.169 +rdnames() 48.170 +{ 48.171 + NAMES= 48.172 + if ! contains_something "$XENDOMAINS_AUTO" 48.173 + then 48.174 + return 48.175 + fi 48.176 + for dom in $XENDOMAINS_AUTO/*; do 48.177 + rdname $dom 48.178 + if test -z $NAMES; then 48.179 + NAMES=$NM; 48.180 + else 48.181 + NAMES="$NAMES|$NM" 48.182 + fi 48.183 + done 48.184 +} 48.185 + 48.186 +parseln() 48.187 +{ 48.188 + if [[ "$1" =~ "\(domain" ]]; then 48.189 + name=;id= 48.190 + else if [[ "$1" =~ "\(name" ]]; then 48.191 + name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/') 48.192 + else if [[ "$1" =~ "\(domid" ]]; then 48.193 + id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/') 48.194 + fi; fi; fi 48.195 + 48.196 + [ -n "$name" -a -n "$id" ] && return 0 || return 1 48.197 +} 48.198 + 48.199 +is_running() 48.200 +{ 48.201 + rdname $1 48.202 + RC=1 48.203 + name=;id= 48.204 + while read LN; do 48.205 + parseln "$LN" || continue 48.206 + if test $id = 0; then continue; fi 48.207 + case $name in 48.208 + ($NM) 48.209 + RC=0 48.210 + ;; 48.211 + esac 48.212 + done < <(xm list -l | grep '(\(domain\|domid\|name\)') 48.213 + return $RC 48.214 +} 48.215 + 48.216 +start() 48.217 +{ 48.218 + if [ -f $LOCKFILE ]; then 48.219 + echo -n "xendomains already running (lockfile exists)" 48.220 + return; 48.221 + fi 48.222 + 48.223 + saved_domains=" " 48.224 + if [ "$XENDOMAINS_RESTORE" = "true" ] && 48.225 + contains_something "$XENDOMAINS_SAVE" 48.226 + then 48.227 + mkdir -p $(dirname "$LOCKFILE") 48.228 + touch $LOCKFILE 48.229 + echo -n "Restoring Xen domains:" 48.230 + saved_domains=`ls $XENDOMAINS_SAVE` 48.231 + for dom in $XENDOMAINS_SAVE/*; do 48.232 + if [ -f $dom ] ; then 48.233 + HEADER=`head -c 16 $dom | head -n 1 2> /dev/null` 48.234 + if [ $HEADER = "LinuxGuestRecord" ]; then 48.235 + echo -n " ${dom##*/}" 48.236 + xm restore $dom 48.237 + if [ $? -ne 0 ]; then 48.238 + rc_failed $? 48.239 + echo -n '!' 48.240 + else 48.241 + # mv $dom ${dom%/*}/.${dom##*/} 48.242 + rm $dom 48.243 + fi 48.244 + fi 48.245 + fi 48.246 + done 48.247 + echo . 48.248 + fi 48.249 + 48.250 + if contains_something "$XENDOMAINS_AUTO" 48.251 + then 48.252 + touch $LOCKFILE 48.253 + echo -n "Starting auto Xen domains:" 48.254 + # We expect config scripts for auto starting domains to be in 48.255 + # XENDOMAINS_AUTO - they could just be symlinks to files elsewhere 48.256 + 48.257 + # Create all domains with config files in XENDOMAINS_AUTO. 48.258 + # TODO: We should record which domain name belongs 48.259 + # so we have the option to selectively shut down / migrate later 48.260 + # If a domain statefile from $XENDOMAINS_SAVE matches a domain name 48.261 + # in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't 48.262 + # restore correctly it requires administrative attention. 48.263 + for dom in $XENDOMAINS_AUTO/*; do 48.264 + echo -n " ${dom##*/}" 48.265 + shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p') 48.266 + echo $saved_domains | grep -w $shortdom > /dev/null 48.267 + if [ $? -eq 0 ] || is_running $dom; then 48.268 + echo -n "(skip)" 48.269 + else 48.270 + xm create --quiet --defconfig $dom 48.271 + if [ $? -ne 0 ]; then 48.272 + rc_failed $? 48.273 + echo -n '!' 48.274 + else 48.275 + usleep $XENDOMAINS_CREATE_USLEEP 48.276 + fi 48.277 + fi 48.278 + done 48.279 + fi 48.280 +} 48.281 + 48.282 +all_zombies() 48.283 +{ 48.284 + name=;id= 48.285 + while read LN; do 48.286 + parseln "$LN" || continue 48.287 + if test $id = 0; then continue; fi 48.288 + if test "$state" != "-b---d" -a "$state" != "-----d"; then 48.289 + return 1; 48.290 + fi 48.291 + done < <(xm list -l | grep '(\(domain\|domid\|name\)') 48.292 + return 0 48.293 +} 48.294 + 48.295 +# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish; 48.296 +# if it has not exited by that time kill it, so the init script will 48.297 +# succeed within a finite amount of time; if $2 is nonnull, it will 48.298 +# kill the command as well as soon as no domain (except for zombies) 48.299 +# are left (used for shutdown --all). 48.300 +watchdog_xm() 48.301 +{ 48.302 + if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then 48.303 + exit 48.304 + fi 48.305 + usleep 20000 48.306 + for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do 48.307 + # exit if xm save/migrate/shutdown is finished 48.308 + PSAX=`ps axlw | grep "xm $1" | grep -v grep` 48.309 + if test -z "$PSAX"; then exit; fi 48.310 + echo -n "."; sleep 1 48.311 + # go to kill immediately if there's only zombies left 48.312 + if all_zombies && test -n "$2"; then break; fi 48.313 + done 48.314 + sleep 1 48.315 + read PSF PSUID PSPID PSPPID < <(echo "$PSAX") 48.316 + # kill xm $1 48.317 + kill $PSPID >/dev/null 2>&1 48.318 +} 48.319 + 48.320 +stop() 48.321 +{ 48.322 + # Collect list of domains to shut down 48.323 + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then 48.324 + rdnames 48.325 + fi 48.326 + echo -n "Shutting down Xen domains:" 48.327 + name=;id= 48.328 + while read LN; do 48.329 + parseln "$LN" || continue 48.330 + if test $id = 0; then continue; fi 48.331 + echo -n " $name" 48.332 + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then 48.333 + eval " 48.334 + case \"\$name\" in 48.335 + ($NAMES) 48.336 + # nothing 48.337 + ;; 48.338 + (*) 48.339 + echo -n '(skip)' 48.340 + continue 48.341 + ;; 48.342 + esac 48.343 + " 48.344 + fi 48.345 + # XENDOMAINS_SYSRQ chould be something like just "s" 48.346 + # or "s e i u" or even "s e s i u o" 48.347 + # for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so 48.348 + if test -n "$XENDOMAINS_SYSRQ"; then 48.349 + for sysrq in $XENDOMAINS_SYSRQ; do 48.350 + echo -n "(SR-$sysrq)" 48.351 + xm sysrq $id $sysrq 48.352 + if test $? -ne 0; then 48.353 + rc_failed $? 48.354 + echo -n '!' 48.355 + fi 48.356 + # usleep just ignores empty arg 48.357 + usleep $XENDOMAINS_USLEEP 48.358 + done 48.359 + fi 48.360 + if test "$state" = "-b---d" -o "$state" = "-----d"; then 48.361 + echo -n "(zomb)" 48.362 + continue 48.363 + fi 48.364 + if test -n "$XENDOMAINS_MIGRATE"; then 48.365 + echo -n "(migr)" 48.366 + watchdog_xm migrate & 48.367 + WDOG_PID=$! 48.368 + xm migrate $id $XENDOMAINS_MIGRATE 48.369 + if test $? -ne 0; then 48.370 + rc_failed $? 48.371 + echo -n '!' 48.372 + kill $WDOG_PID >/dev/null 2>&1 48.373 + else 48.374 + kill $WDOG_PID >/dev/null 2>&1 48.375 + continue 48.376 + fi 48.377 + fi 48.378 + if test -n "$XENDOMAINS_SAVE"; then 48.379 + echo -n "(save)" 48.380 + watchdog_xm save & 48.381 + WDOG_PID=$! 48.382 + mkdir -p "$XENDOMAINS_SAVE" 48.383 + xm save $id $XENDOMAINS_SAVE/$name 48.384 + if test $? -ne 0; then 48.385 + rc_failed $? 48.386 + echo -n '!' 48.387 + kill $WDOG_PID >/dev/null 2>&1 48.388 + else 48.389 + kill $WDOG_PID >/dev/null 2>&1 48.390 + continue 48.391 + fi 48.392 + fi 48.393 + if test -n "$XENDOMAINS_SHUTDOWN"; then 48.394 + # XENDOMAINS_SHUTDOWN should be "--halt --wait" 48.395 + echo -n "(shut)" 48.396 + watchdog_xm shutdown & 48.397 + WDOG_PID=$! 48.398 + xm shutdown $id $XENDOMAINS_SHUTDOWN 48.399 + if test $? -ne 0; then 48.400 + rc_failed $? 48.401 + echo -n '!' 48.402 + fi 48.403 + kill $WDOG_PID >/dev/null 2>&1 48.404 + fi 48.405 + done < <(xm list -l | grep '(\(domain\|domid\|name\)') 48.406 + 48.407 + # NB. this shuts down ALL Xen domains (politely), not just the ones in 48.408 + # AUTODIR/* 48.409 + # This is because it's easier to do ;-) but arguably if this script is run 48.410 + # on system shutdown then it's also the right thing to do. 48.411 + if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then 48.412 + # XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait" 48.413 + echo -n " SHUTDOWN_ALL " 48.414 + watchdog_xm shutdown 1 & 48.415 + WDOG_PID=$! 48.416 + xm shutdown $XENDOMAINS_SHUTDOWN_ALL 48.417 + if test $? -ne 0; then 48.418 + rc_failed $? 48.419 + echo -n '!' 48.420 + fi 48.421 + kill $WDOG_PID >/dev/null 2>&1 48.422 + fi 48.423 + 48.424 + # Unconditionally delete lock file 48.425 + rm -f $LOCKFILE 48.426 +} 48.427 + 48.428 +check_domain_up() 48.429 +{ 48.430 + name=;id= 48.431 + while read LN; do 48.432 + parseln "$LN" || continue 48.433 + if test $id = 0; then continue; fi 48.434 + case $name in 48.435 + ($1) 48.436 + return 0 48.437 + ;; 48.438 + esac 48.439 + done < <(xm list -l | grep '(\(domain\|domid\|name\)') 48.440 + return 1 48.441 +} 48.442 + 48.443 +check_all_auto_domains_up() 48.444 +{ 48.445 + if ! contains_something "$XENDOMAINS_AUTO" 48.446 + then 48.447 + return 0 48.448 + fi 48.449 + missing= 48.450 + for nm in $XENDOMAINS_AUTO/*; do 48.451 + rdname $nm 48.452 + found=0 48.453 + if check_domain_up "$NM"; then 48.454 + echo -n " $name" 48.455 + else 48.456 + missing="$missing $NM" 48.457 + fi 48.458 + done 48.459 + if test -n "$missing"; then 48.460 + echo -n " MISS AUTO:$missing" 48.461 + return 1 48.462 + fi 48.463 + return 0 48.464 +} 48.465 + 48.466 +check_all_saved_domains_up() 48.467 +{ 48.468 + if ! contains_something "$XENDOMAINS_SAVE" 48.469 + then 48.470 + return 0 48.471 + fi 48.472 + missing=`/bin/ls $XENDOMAINS_SAVE` 48.473 + echo -n " MISS SAVED: " $missing 48.474 + return 1 48.475 +} 48.476 + 48.477 +# This does NOT necessarily restart all running domains: instead it 48.478 +# stops all running domains and then boots all the domains specified in 48.479 +# AUTODIR. If other domains have been started manually then they will 48.480 +# not get restarted. 48.481 +# Commented out to avoid confusion! 48.482 + 48.483 +restart() 48.484 +{ 48.485 + stop 48.486 + start 48.487 +} 48.488 + 48.489 +reload() 48.490 +{ 48.491 + restart 48.492 +} 48.493 + 48.494 + 48.495 +case "$1" in 48.496 + start) 48.497 + start 48.498 + rc_status 48.499 + if test -f $LOCKFILE; then rc_status -v; fi 48.500 + ;; 48.501 + 48.502 + stop) 48.503 + stop 48.504 + rc_status -v 48.505 + ;; 48.506 + 48.507 + restart) 48.508 + restart 48.509 + ;; 48.510 + reload) 48.511 + reload 48.512 + ;; 48.513 + 48.514 + status) 48.515 + echo -n "Checking for xendomains:" 48.516 + if test ! -f $LOCKFILE; then 48.517 + rc_failed 3 48.518 + else 48.519 + check_all_auto_domains_up 48.520 + rc_status 48.521 + check_all_saved_domains_up 48.522 + rc_status 48.523 + fi 48.524 + rc_status -v 48.525 + ;; 48.526 + 48.527 + *) 48.528 + echo "Usage: $0 {start|stop|restart|reload|status}" 48.529 + rc_failed 3 48.530 + rc_status -v 48.531 + ;; 48.532 +esac 48.533 + 48.534 +rc_exit
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/tools/hotplug/Linux/locking.sh Tue Nov 25 14:21:24 2008 +0900 49.3 @@ -0,0 +1,98 @@ 49.4 +# 49.5 +# Copyright (c) 2005 XenSource Ltd. 49.6 +# 49.7 +# This library is free software; you can redistribute it and/or 49.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 49.9 +# License as published by the Free Software Foundation. 49.10 +# 49.11 +# This library is distributed in the hope that it will be useful, 49.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 49.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 49.14 +# Lesser General Public License for more details. 49.15 +# 49.16 +# You should have received a copy of the GNU Lesser General Public 49.17 +# License along with this library; if not, write to the Free Software 49.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 49.19 +# 49.20 + 49.21 +# 49.22 +# Serialisation 49.23 +# 49.24 + 49.25 +LOCK_SLEEPTIME=1 49.26 +LOCK_SPINNING_RETRIES=5 49.27 +LOCK_RETRIES=100 49.28 +LOCK_BASEDIR=/var/run/xen-hotplug 49.29 + 49.30 + 49.31 +claim_lock() 49.32 +{ 49.33 + local lockdir="$LOCK_BASEDIR/$1" 49.34 + mkdir -p "$LOCK_BASEDIR" 49.35 + _claim_lock "$lockdir" 49.36 +} 49.37 + 49.38 + 49.39 +release_lock() 49.40 +{ 49.41 + _release_lock "$LOCK_BASEDIR/$1" 49.42 +} 49.43 + 49.44 + 49.45 +_claim_lock() 49.46 +{ 49.47 + local lockdir="$1" 49.48 + local owner=$(_lock_owner "$lockdir") 49.49 + local retries=0 49.50 + 49.51 + while [ $retries -lt $LOCK_RETRIES ] 49.52 + do 49.53 + mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR && 49.54 + _update_lock_info "$lockdir" && return 49.55 + 49.56 + local new_owner=$(_lock_owner "$lockdir") 49.57 + if [ "$new_owner" != "$owner" ] 49.58 + then 49.59 + owner="$new_owner" 49.60 + retries=0 49.61 + fi 49.62 + 49.63 + if [ $retries -gt $LOCK_SPINNING_RETRIES ] 49.64 + then 49.65 + sleep $LOCK_SLEEPTIME 49.66 + else 49.67 + sleep 0 49.68 + fi 49.69 + retries=$(($retries + 1)) 49.70 + done 49.71 + _steal_lock "$lockdir" 49.72 +} 49.73 + 49.74 + 49.75 +_release_lock() 49.76 +{ 49.77 + trap sigerr ERR 49.78 + rm -rf "$1" 2>/dev/null || true 49.79 +} 49.80 + 49.81 + 49.82 +_steal_lock() 49.83 +{ 49.84 + local lockdir="$1" 49.85 + local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown") 49.86 + log err "Forced to steal lock on $lockdir from $owner!" 49.87 + _release_lock "$lockdir" 49.88 + _claim_lock "$lockdir" 49.89 +} 49.90 + 49.91 + 49.92 +_lock_owner() 49.93 +{ 49.94 + cat "$1/owner" 2>/dev/null || echo "unknown" 49.95 +} 49.96 + 49.97 + 49.98 +_update_lock_info() 49.99 +{ 49.100 + echo "$$: $0" >"$1/owner" 49.101 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/tools/hotplug/Linux/logging.sh Tue Nov 25 14:21:24 2008 +0900 50.3 @@ -0,0 +1,22 @@ 50.4 +# 50.5 +# Copyright (c) 2005 XenSource Ltd. 50.6 +# 50.7 +# This library is free software; you can redistribute it and/or 50.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 50.9 +# License as published by the Free Software Foundation. 50.10 +# 50.11 +# This library is distributed in the hope that it will be useful, 50.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 50.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 50.14 +# Lesser General Public License for more details. 50.15 +# 50.16 +# You should have received a copy of the GNU Lesser General Public 50.17 +# License along with this library; if not, write to the Free Software 50.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 50.19 +# 50.20 + 50.21 +log() { 50.22 + local level="$1" 50.23 + shift 50.24 + logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2 50.25 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/tools/hotplug/Linux/network-bridge Tue Nov 25 14:21:24 2008 +0900 51.3 @@ -0,0 +1,310 @@ 51.4 +#!/bin/bash 51.5 +#============================================================================ 51.6 +# Default Xen network start/stop script. 51.7 +# Xend calls a network script when it starts. 51.8 +# The script name to use is defined in /etc/xen/xend-config.sxp 51.9 +# in the network-script field. 51.10 +# 51.11 +# This script creates a bridge (default ${netdev}), adds a device 51.12 +# (defaults to the device on the default gateway route) to it, copies 51.13 +# the IP addresses from the device to the bridge and adjusts the routes 51.14 +# accordingly. 51.15 +# 51.16 +# If all goes well, this should ensure that networking stays up. 51.17 +# However, some configurations are upset by this, especially 51.18 +# NFS roots. If the bridged setup does not meet your needs, 51.19 +# configure a different script, for example using routing instead. 51.20 +# 51.21 +# Usage: 51.22 +# 51.23 +# network-bridge (start|stop|status) {VAR=VAL}* 51.24 +# 51.25 +# Vars: 51.26 +# 51.27 +# bridge The bridge to use (default ${netdev}). 51.28 +# netdev The interface to add to the bridge (default gateway device). 51.29 +# antispoof Whether to use iptables to prevent spoofing (default no). 51.30 +# 51.31 +# Internal Vars: 51.32 +# pdev="p${netdev}" 51.33 +# tdev=tmpbridge 51.34 +# 51.35 +# start: 51.36 +# Creates the bridge as tdev 51.37 +# Copies the IP and MAC addresses from pdev to bridge 51.38 +# Renames netdev to be pdev 51.39 +# Renames tdev to bridge 51.40 +# Enslaves pdev to bridge 51.41 +# 51.42 +# stop: 51.43 +# Removes pdev from the bridge 51.44 +# Transfers addresses, routes from bridge to pdev 51.45 +# Renames bridge to tdev 51.46 +# Renames pdev to netdev 51.47 +# Deletes tdev 51.48 +# 51.49 +# status: 51.50 +# Print addresses, interfaces, routes 51.51 +# 51.52 +#============================================================================ 51.53 + 51.54 + 51.55 +dir=$(dirname "$0") 51.56 +. "$dir/xen-script-common.sh" 51.57 +. "$dir/xen-network-common.sh" 51.58 + 51.59 +findCommand "$@" 51.60 +evalVariables "$@" 51.61 + 51.62 +is_network_root () { 51.63 + local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab) 51.64 + local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab) 51.65 + 51.66 + [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && has_nfsroot=1 || has_nfsroot=0 51.67 + if [ $has_nfsroot -eq 1 ]; then 51.68 + local bparms=$(cat /proc/cmdline) 51.69 + for p in $bparms; do 51.70 + local ipaddr=$(echo $p | awk /nfsroot=/'{ print substr($1,9,index($1,":")-9) }') 51.71 + if [ "$ipaddr" != "" ]; then 51.72 + local nfsdev=$(ip route get $ipaddr | awk /$ipaddr/'{ print $3 }') 51.73 + [[ "$nfsdev" == "$netdev" ]] && return 0 || return 1 51.74 + fi 51.75 + done 51.76 + fi 51.77 + return 1 51.78 +} 51.79 + 51.80 +find_alt_device () { 51.81 + local interf=$1 51.82 + local prefix=${interf%[[:digit:]]} 51.83 + local ifs=$(ip link show | grep " $prefix" |\ 51.84 + gawk '{ printf ("%s",substr($2,1,length($2)-1)) }' |\ 51.85 + sed s/$interf//) 51.86 + echo "$ifs" 51.87 +} 51.88 + 51.89 +netdev=${netdev:-$(ip route list 0.0.0.0/0 | \ 51.90 + sed 's/.*dev \([a-z]\+[0-9]\+\).*$/\1/')} 51.91 +if is_network_root ; then 51.92 + altdevs=$(find_alt_device $netdev) 51.93 + for netdev in $altdevs; do break; done 51.94 + if [ -z "$netdev" ]; then 51.95 + [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting" 51.96 + exit 51.97 + fi 51.98 +fi 51.99 +netdev=${netdev:-eth0} 51.100 +bridge=${bridge:-${netdev}} 51.101 +antispoof=${antispoof:-no} 51.102 + 51.103 +pdev="p${netdev}" 51.104 +tdev=tmpbridge 51.105 + 51.106 +get_ip_info() { 51.107 + addr_pfx=`ip addr show dev $1 | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'` 51.108 + gateway=`ip route show dev $1 | fgrep default | sed 's/default via //'` 51.109 +} 51.110 + 51.111 +do_ifup() { 51.112 + if ! ifup $1 ; then 51.113 + if [ -n "$addr_pfx" ] ; then 51.114 + # use the info from get_ip_info() 51.115 + ip addr flush $1 51.116 + ip addr add ${addr_pfx} dev $1 51.117 + ip link set dev $1 up 51.118 + [ -n "$gateway" ] && ip route add default via ${gateway} 51.119 + fi 51.120 + fi 51.121 +} 51.122 + 51.123 +# Usage: transfer_addrs src dst 51.124 +# Copy all IP addresses (including aliases) from device $src to device $dst. 51.125 +transfer_addrs () { 51.126 + local src=$1 51.127 + local dst=$2 51.128 + # Don't bother if $dst already has IP addresses. 51.129 + if ip addr show dev ${dst} | egrep -q '^ *inet ' ; then 51.130 + return 51.131 + fi 51.132 + # Address lines start with 'inet' and have the device in them. 51.133 + # Replace 'inet' with 'ip addr add' and change the device name $src 51.134 + # to 'dev $src'. 51.135 + ip addr show dev ${src} | egrep '^ *inet ' | sed -e " 51.136 +s/inet/ip addr add/ 51.137 +s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@ 51.138 +s/${src}/dev ${dst} label ${dst}/ 51.139 +s/secondary// 51.140 +" | sh -e 51.141 + # Remove automatic routes on destination device 51.142 + ip route list | sed -ne " 51.143 +/dev ${dst}\( \|$\)/ { 51.144 + s/^/ip route del / 51.145 + p 51.146 +}" | sh -e 51.147 +} 51.148 + 51.149 +# Usage: transfer_routes src dst 51.150 +# Get all IP routes to device $src, delete them, and 51.151 +# add the same routes to device $dst. 51.152 +# The original routes have to be deleted, otherwise adding them 51.153 +# for $dst fails (duplicate routes). 51.154 +transfer_routes () { 51.155 + local src=$1 51.156 + local dst=$2 51.157 + # List all routes and grep the ones with $src in. 51.158 + # Stick 'ip route del' on the front to delete. 51.159 + # Change $src to $dst and use 'ip route add' to add. 51.160 + ip route list | sed -ne " 51.161 +/dev ${src}\( \|$\)/ { 51.162 + h 51.163 + s/^/ip route del / 51.164 + P 51.165 + g 51.166 + s/${src}/${dst}/ 51.167 + s/^/ip route add / 51.168 + P 51.169 + d 51.170 +}" | sh -e 51.171 +} 51.172 + 51.173 + 51.174 +## 51.175 +# link_exists interface 51.176 +# 51.177 +# Returns 0 if the interface named exists (whether up or down), 1 otherwise. 51.178 +# 51.179 +link_exists() 51.180 +{ 51.181 + if ip link show "$1" >/dev/null 2>/dev/null 51.182 + then 51.183 + return 0 51.184 + else 51.185 + return 1 51.186 + fi 51.187 +} 51.188 + 51.189 +# Set the default forwarding policy for $dev to drop. 51.190 +# Allow forwarding to the bridge. 51.191 +antispoofing () { 51.192 + iptables -P FORWARD DROP 51.193 + iptables -F FORWARD 51.194 + iptables -A FORWARD -m physdev --physdev-in ${pdev} -j ACCEPT 51.195 +} 51.196 + 51.197 +# Usage: show_status dev bridge 51.198 +# Print ifconfig and routes. 51.199 +show_status () { 51.200 + local dev=$1 51.201 + local bridge=$2 51.202 + 51.203 + echo '============================================================' 51.204 + ip addr show ${dev} 51.205 + ip addr show ${bridge} 51.206 + echo ' ' 51.207 + brctl show ${bridge} 51.208 + echo ' ' 51.209 + ip route list 51.210 + echo ' ' 51.211 + route -n 51.212 + echo '============================================================' 51.213 +} 51.214 + 51.215 +op_start () { 51.216 + if [ "${bridge}" = "null" ] ; then 51.217 + return 51.218 + fi 51.219 + 51.220 + if link_exists "$pdev"; then 51.221 + # The device is already up. 51.222 + return 51.223 + fi 51.224 + 51.225 + create_bridge ${tdev} 51.226 + 51.227 + preiftransfer ${netdev} 51.228 + transfer_addrs ${netdev} ${tdev} 51.229 + if ! ifdown ${netdev}; then 51.230 + # If ifdown fails, remember the IP details. 51.231 + get_ip_info ${netdev} 51.232 + ip link set ${netdev} down 51.233 + ip addr flush ${netdev} 51.234 + fi 51.235 + ip link set ${netdev} name ${pdev} 51.236 + ip link set ${tdev} name ${bridge} 51.237 + 51.238 + setup_bridge_port ${pdev} 51.239 + 51.240 + add_to_bridge2 ${bridge} ${pdev} 51.241 + do_ifup ${bridge} 51.242 + 51.243 + if [ ${antispoof} = 'yes' ] ; then 51.244 + antispoofing 51.245 + fi 51.246 +} 51.247 + 51.248 +op_stop () { 51.249 + if [ "${bridge}" = "null" ]; then 51.250 + return 51.251 + fi 51.252 + if ! link_exists "$bridge"; then 51.253 + return 51.254 + fi 51.255 + 51.256 + transfer_addrs ${bridge} ${pdev} 51.257 + if ! ifdown ${bridge}; then 51.258 + get_ip_info ${bridge} 51.259 + fi 51.260 + ip link set ${pdev} down 51.261 + ip addr flush ${bridge} 51.262 + 51.263 + brctl delif ${bridge} ${pdev} 51.264 + ip link set ${bridge} down 51.265 + 51.266 + ip link set ${bridge} name ${tdev} 51.267 + ip link set ${pdev} name ${netdev} 51.268 + do_ifup ${netdev} 51.269 + 51.270 + brctl delbr ${tdev} 51.271 +} 51.272 + 51.273 +# adds $dev to $bridge but waits for $dev to be in running state first 51.274 +add_to_bridge2() { 51.275 + local bridge=$1 51.276 + local dev=$2 51.277 + local maxtries=10 51.278 + 51.279 + echo -n "Waiting for ${dev} to negotiate link." 51.280 + ip link set ${dev} up 51.281 + for i in `seq ${maxtries}` ; do 51.282 + if ifconfig ${dev} | grep -q RUNNING ; then 51.283 + break 51.284 + else 51.285 + echo -n '.' 51.286 + sleep 1 51.287 + fi 51.288 + done 51.289 + 51.290 + if [ ${i} -eq ${maxtries} ] ; then echo -n '(link isnt in running state)' ; fi 51.291 + echo 51.292 + 51.293 + add_to_bridge ${bridge} ${dev} 51.294 +} 51.295 + 51.296 +case "$command" in 51.297 + start) 51.298 + op_start 51.299 + ;; 51.300 + 51.301 + stop) 51.302 + op_stop 51.303 + ;; 51.304 + 51.305 + status) 51.306 + show_status ${netdev} ${bridge} 51.307 + ;; 51.308 + 51.309 + *) 51.310 + echo "Unknown command: $command" >&2 51.311 + echo 'Valid commands are: start, stop, status' >&2 51.312 + exit 1 51.313 +esac
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/tools/hotplug/Linux/network-nat Tue Nov 25 14:21:24 2008 +0900 52.3 @@ -0,0 +1,119 @@ 52.4 +#!/bin/bash -x 52.5 +#============================================================================ 52.6 +# Default Xen network start/stop script when using NAT. 52.7 +# Xend calls a network script when it starts. 52.8 +# The script name to use is defined in /etc/xen/xend-config.sxp 52.9 +# in the network-script field. 52.10 +# 52.11 +# Usage: 52.12 +# 52.13 +# network-nat (start|stop|status) {VAR=VAL}* 52.14 +# 52.15 +# Vars: 52.16 +# 52.17 +# netdev The gateway interface (default eth0). 52.18 +# antispoof Whether to use iptables to prevent spoofing (default no). 52.19 +# dhcp Whether to alter the local DHCP configuration (default no). 52.20 +# 52.21 +#============================================================================ 52.22 + 52.23 +dir=$(dirname "$0") 52.24 +. "$dir/xen-script-common.sh" 52.25 +. "$dir/xen-network-common.sh" 52.26 + 52.27 +findCommand "$@" 52.28 +evalVariables "$@" 52.29 + 52.30 +netdev=${netdev:-eth0} 52.31 +# antispoofing not yet implemented 52.32 +antispoof=${antispoof:-no} 52.33 + 52.34 +# turn on dhcp feature by default if dhcpd is installed 52.35 +if [ -f /etc/dhcpd.conf ] 52.36 +then 52.37 + dhcp=${dhcp:-yes} 52.38 +else 52.39 + dhcp=${dhcp:-no} 52.40 +fi 52.41 + 52.42 + 52.43 +if [ "$dhcp" != 'no' ] 52.44 +then 52.45 + dhcpd_conf_file=$(find_dhcpd_conf_file) 52.46 + dhcpd_init_file=$(find_dhcpd_init_file) 52.47 + if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] 52.48 + then 52.49 + echo 'Failed to find dhcpd configuration or init file.' >&2 52.50 + exit 1 52.51 + fi 52.52 +fi 52.53 + 52.54 + 52.55 +function dhcp_start() 52.56 +{ 52.57 + if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file" 52.58 + then 52.59 + echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {}" 52.60 + fi 52.61 + 52.62 + "$dhcpd_init_file" restart 52.63 +} 52.64 + 52.65 + 52.66 +function dhcp_stop() 52.67 +{ 52.68 + local tmpfile=$(mktemp) 52.69 + grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile" 52.70 + if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null 52.71 + then 52.72 + rm "$tmpfile" 52.73 + else 52.74 + mv "$tmpfile" "$dhcpd_conf_file" 52.75 + fi 52.76 + 52.77 + "$dhcpd_init_file" restart 52.78 +} 52.79 + 52.80 + 52.81 +op_start() { 52.82 + echo 1 >/proc/sys/net/ipv4/ip_forward 52.83 + iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE 52.84 + [ "$dhcp" != 'no' ] && dhcp_start 52.85 +} 52.86 + 52.87 + 52.88 +op_stop() { 52.89 + [ "$dhcp" != 'no' ] && dhcp_stop 52.90 + iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE 52.91 +} 52.92 + 52.93 + 52.94 +show_status() { 52.95 + echo '============================================================' 52.96 + ifconfig 52.97 + echo ' ' 52.98 + ip route list 52.99 + echo ' ' 52.100 + route -n 52.101 + echo '============================================================' 52.102 + 52.103 +} 52.104 + 52.105 +case "$command" in 52.106 + start) 52.107 + op_start 52.108 + ;; 52.109 + 52.110 + stop) 52.111 + op_stop 52.112 + ;; 52.113 + 52.114 + status) 52.115 + show_status 52.116 + ;; 52.117 + 52.118 + *) 52.119 + echo "Unknown command: $command" >&2 52.120 + echo 'Valid commands are: start, stop, status' >&2 52.121 + exit 1 52.122 +esac
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/tools/hotplug/Linux/network-route Tue Nov 25 14:21:24 2008 +0900 53.3 @@ -0,0 +1,27 @@ 53.4 +#!/bin/bash 53.5 +#============================================================================ 53.6 +# Default Xen network start/stop script. 53.7 +# Xend calls a network script when it starts. 53.8 +# The script name to use is defined in /etc/xen/xend-config.sxp 53.9 +# in the network-script field. 53.10 +# 53.11 +# Usage: 53.12 +# 53.13 +# network-route (start|stop|status) {VAR=VAL}* 53.14 +# 53.15 +# Vars: 53.16 +# 53.17 +# netdev The gateway interface (default eth0). 53.18 +# antispoof Whether to use iptables to prevent spoofing (default yes). 53.19 +# 53.20 +#============================================================================ 53.21 + 53.22 +dir=$(dirname "$0") 53.23 +. "$dir/xen-script-common.sh" 53.24 + 53.25 +evalVariables "$@" 53.26 + 53.27 +netdev=${netdev:-eth${vifnum}} 53.28 + 53.29 +echo 1 >/proc/sys/net/ipv4/ip_forward 53.30 +echo 1 >/proc/sys/net/ipv4/conf/${netdev}/proxy_arp
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/tools/hotplug/Linux/vif-bridge Tue Nov 25 14:21:24 2008 +0900 54.3 @@ -0,0 +1,100 @@ 54.4 +#!/bin/bash 54.5 +#============================================================================ 54.6 +# /etc/xen/vif-bridge 54.7 +# 54.8 +# Script for configuring a vif in bridged mode. 54.9 +# The hotplugging system will call this script if it is specified either in 54.10 +# the device configuration given to Xend, or the default Xend configuration 54.11 +# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 54.12 +# places, then this script is the default. 54.13 +# 54.14 +# Usage: 54.15 +# vif-bridge (add|remove|online|offline) 54.16 +# 54.17 +# Environment vars: 54.18 +# vif vif interface name (required). 54.19 +# XENBUS_PATH path to this device's details in the XenStore (required). 54.20 +# 54.21 +# Read from the store: 54.22 +# bridge bridge to add the vif to (optional). Defaults to searching for the 54.23 +# bridge itself. 54.24 +# ip list of IP networks for the vif, space-separated (optional). 54.25 +# 54.26 +# up: 54.27 +# Enslaves the vif interface to the bridge and adds iptables rules 54.28 +# for its ip addresses (if any). 54.29 +# 54.30 +# down: 54.31 +# Removes the vif interface from the bridge and removes the iptables 54.32 +# rules for its ip addresses (if any). 54.33 +#============================================================================ 54.34 + 54.35 +dir=$(dirname "$0") 54.36 +. "$dir/vif-common.sh" 54.37 + 54.38 +bridge=${bridge:-} 54.39 +bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge") 54.40 + 54.41 +if [ -z "$bridge" ] 54.42 +then 54.43 + bridge=$(brctl show | cut -d " 54.44 +" -f 2 | cut -f 1) 54.45 + 54.46 + if [ -z "$bridge" ] 54.47 + then 54.48 + fatal "Could not find bridge, and none was specified" 54.49 + fi 54.50 +else 54.51 + # 54.52 + # Old style bridge setup with netloop, used to have a bridge name 54.53 + # of xenbrX, enslaving pethX and vif0.X, and then configuring 54.54 + # eth0. 54.55 + # 54.56 + # New style bridge setup does not use netloop, so the bridge name 54.57 + # is ethX and the physical device is enslaved pethX 54.58 + # 54.59 + # So if... 54.60 + # 54.61 + # - User asks for xenbrX 54.62 + # - AND xenbrX doesn't exist 54.63 + # - AND there is a ethX device which is a bridge 54.64 + # 54.65 + # ..then we translate xenbrX to ethX 54.66 + # 54.67 + # This lets old config files work without modification 54.68 + # 54.69 + if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ] 54.70 + then 54.71 + if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ] 54.72 + then 54.73 + bridge="eth${bridge#xenbr}" 54.74 + fi 54.75 + fi 54.76 +fi 54.77 + 54.78 +RET=0 54.79 +ip link show $bridge 1>/dev/null 2>&1 || RET=1 54.80 +if [ "$RET" -eq 1 ] 54.81 +then 54.82 + fatal "Could not find bridge device $bridge" 54.83 +fi 54.84 + 54.85 +case "$command" in 54.86 + online) 54.87 + setup_bridge_port "$vif" 54.88 + add_to_bridge "$bridge" "$vif" 54.89 + ;; 54.90 + 54.91 + offline) 54.92 + do_without_error brctl delif "$bridge" "$vif" 54.93 + do_without_error ifconfig "$vif" down 54.94 + ;; 54.95 +esac 54.96 + 54.97 +handle_iptable 54.98 + 54.99 +log debug "Successful vif-bridge $command for $vif, bridge $bridge." 54.100 +if [ "$command" == "online" ] 54.101 +then 54.102 + success 54.103 +fi
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/tools/hotplug/Linux/vif-common.sh Tue Nov 25 14:21:24 2008 +0900 55.3 @@ -0,0 +1,151 @@ 55.4 +# 55.5 +# Copyright (c) 2005 XenSource Ltd. 55.6 +# 55.7 +# This library is free software; you can redistribute it and/or 55.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 55.9 +# License as published by the Free Software Foundation. 55.10 +# 55.11 +# This library is distributed in the hope that it will be useful, 55.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 55.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 55.14 +# Lesser General Public License for more details. 55.15 +# 55.16 +# You should have received a copy of the GNU Lesser General Public 55.17 +# License along with this library; if not, write to the Free Software 55.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 55.19 +# 55.20 + 55.21 + 55.22 +dir=$(dirname "$0") 55.23 +. "$dir/xen-hotplug-common.sh" 55.24 +. "$dir/xen-network-common.sh" 55.25 + 55.26 +findCommand "$@" 55.27 + 55.28 +if [ "$command" != "online" ] && 55.29 + [ "$command" != "offline" ] && 55.30 + [ "$command" != "add" ] && 55.31 + [ "$command" != "remove" ] 55.32 +then 55.33 + log err "Invalid command: $command" 55.34 + exit 1 55.35 +fi 55.36 + 55.37 +case "$command" in 55.38 + add | remove) 55.39 + exit 0 55.40 + ;; 55.41 +esac 55.42 + 55.43 + 55.44 +# Parameters may be read from the environment, the command line arguments, and 55.45 +# the store, with overriding in that order. The environment is given by the 55.46 +# driver, the command line is given by the Xend global configuration, and 55.47 +# store details are given by the per-domain or per-device configuration. 55.48 + 55.49 +evalVariables "$@" 55.50 + 55.51 +ip=${ip:-} 55.52 +ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") 55.53 + 55.54 +# Check presence of compulsory args. 55.55 +XENBUS_PATH="${XENBUS_PATH:?}" 55.56 +vif="${vif:?}" 55.57 + 55.58 + 55.59 +vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "") 55.60 +if [ "$vifname" ] 55.61 +then 55.62 + if [ "$command" == "online" ] && ! ip link show "$vifname" >&/dev/null 55.63 + then 55.64 + do_or_die ip link set "$vif" name "$vifname" 55.65 + fi 55.66 + vif="$vifname" 55.67 +fi 55.68 + 55.69 + 55.70 +frob_iptable() 55.71 +{ 55.72 + if [ "$command" == "online" ] 55.73 + then 55.74 + local c="-A" 55.75 + else 55.76 + local c="-D" 55.77 + fi 55.78 + 55.79 + iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \ 55.80 + 2>/dev/null || 55.81 + [ "$c" == "-D" ] || 55.82 + log err \ 55.83 + "iptables $c FORWARD -m physdev --physdev-in $vif $@ -j ACCEPT failed. 55.84 +If you are using iptables, this may affect networking for guest domains." 55.85 +} 55.86 + 55.87 + 55.88 +## 55.89 +# Add or remove the appropriate entries in the iptables. With antispoofing 55.90 +# turned on, we have to explicitly allow packets to the interface, regardless 55.91 +# of the ip setting. If ip is set, then we additionally restrict the packets 55.92 +# to those coming from the specified networks, though we allow DHCP requests 55.93 +# as well. 55.94 +# 55.95 +handle_iptable() 55.96 +{ 55.97 + # Check for a working iptables installation. Checking for the iptables 55.98 + # binary is not sufficient, because the user may not have the appropriate 55.99 + # modules installed. If iptables is not working, then there's no need to do 55.100 + # anything with it, so we can just return. 55.101 + if ! iptables -L -n >&/dev/null 55.102 + then 55.103 + return 55.104 + fi 55.105 + 55.106 + if [ "$ip" != "" ] 55.107 + then 55.108 + local addr 55.109 + for addr in $ip 55.110 + do 55.111 + frob_iptable -s "$addr" 55.112 + done 55.113 + 55.114 + # Always allow the domain to talk to a DHCP server. 55.115 + frob_iptable -p udp --sport 68 --dport 67 55.116 + else 55.117 + # No IP addresses have been specified, so allow anything. 55.118 + frob_iptable 55.119 + fi 55.120 +} 55.121 + 55.122 + 55.123 +## 55.124 +# ip_of interface 55.125 +# 55.126 +# Print the IP address currently in use at the given interface, or nothing if 55.127 +# the interface is not up. 55.128 +# 55.129 +ip_of() 55.130 +{ 55.131 + ip addr show "$1" | awk "/^.*inet.*$1\$/{print \$2}" | sed -n '1 s,/.*,,p' 55.132 +} 55.133 + 55.134 + 55.135 +## 55.136 +# dom0_ip 55.137 +# 55.138 +# Print the IP address of the interface in dom0 through which we are routing. 55.139 +# This is the IP address on the interface specified as "netdev" as a parameter 55.140 +# to these scripts, or eth0 by default. This function will call fatal if no 55.141 +# such interface could be found. 55.142 +# 55.143 +dom0_ip() 55.144 +{ 55.145 + local nd=${netdev:-eth0} 55.146 + local result=$(ip_of "$nd") 55.147 + if [ -z "$result" ] 55.148 + then 55.149 + fatal 55.150 +"$netdev is not up. Bring it up or specify another interface with " \ 55.151 +"netdev=<if> as a parameter to $0." 55.152 + fi 55.153 + echo "$result" 55.154 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/tools/hotplug/Linux/vif-nat Tue Nov 25 14:21:24 2008 +0900 56.3 @@ -0,0 +1,192 @@ 56.4 +#!/bin/bash 56.5 +#============================================================================ 56.6 +# /etc/xen/vif-nat 56.7 +# 56.8 +# Script for configuring a vif in routed-nat mode. 56.9 +# The hotplugging system will call this script if it is specified either in 56.10 +# the device configuration given to Xend, or the default Xend configuration 56.11 +# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 56.12 +# places, then vif-bridge is the default. 56.13 +# 56.14 +# Usage: 56.15 +# vif-nat (add|remove|online|offline) 56.16 +# 56.17 +# Environment vars: 56.18 +# vif vif interface name (required). 56.19 +# XENBUS_PATH path to this device's details in the XenStore (required). 56.20 +# 56.21 +# Parameters: 56.22 +# dhcp Whether to alter the local DHCP configuration to include this 56.23 +# new host (default no). 56.24 +# 56.25 +# Read from the store: 56.26 +# ip list of IP networks for the vif, space-separated (default given in 56.27 +# this script). 56.28 +#============================================================================ 56.29 + 56.30 + 56.31 +dir=$(dirname "$0") 56.32 +. "$dir/vif-common.sh" 56.33 + 56.34 +# turn on dhcp feature by default if dhcpd is installed 56.35 +if [ -f /etc/dhcpd.conf ] 56.36 +then 56.37 + dhcp=${dhcp:-yes} 56.38 +else 56.39 + dhcp=${dhcp:-no} 56.40 +fi 56.41 + 56.42 +if [ "$dhcp" != 'no' ] 56.43 +then 56.44 + dhcpd_conf_file=$(find_dhcpd_conf_file) 56.45 + dhcpd_init_file=$(find_dhcpd_init_file) 56.46 + dhcpd_arg_file=$(find_dhcpd_arg_file) 56.47 + if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] || [ -z "$dhcpd_arg_file" ] 56.48 + then 56.49 + echo 'Failed to find dhcpd configuration or init or args file.' >&2 56.50 + exit 1 56.51 + fi 56.52 +fi 56.53 + 56.54 + 56.55 +domid=$(xenstore_read "$XENBUS_PATH/frontend-id") 56.56 +vifid=$(xenstore_read "$XENBUS_PATH/handle") 56.57 +vifid=$(( $vifid + 1 )) 56.58 + 56.59 + 56.60 +ip_from_dom() 56.61 +{ 56.62 + local domid1=$(( $domid / 256 )) 56.63 + local domid2=$(( $domid % 256 )) 56.64 + 56.65 + echo "10.$domid1.$domid2.$vifid/16" 56.66 +} 56.67 + 56.68 + 56.69 +routing_ip() 56.70 +{ 56.71 + echo $(echo $1 | awk -F. '{print $1"."$2"."$3"."$4 + 127}') 56.72 +} 56.73 + 56.74 + 56.75 +dotted_quad() 56.76 +{ 56.77 + echo\ 56.78 + $(( ($1 & 0xFF000000) >> 24))\ 56.79 +.$(( ($1 & 0x00FF0000) >> 16))\ 56.80 +.$(( ($1 & 0x0000FF00) >> 8 ))\ 56.81 +.$(( $1 & 0x000000FF )) 56.82 +} 56.83 + 56.84 + 56.85 +if [ "$ip" = "" ] 56.86 +then 56.87 + ip=$(ip_from_dom) 56.88 +fi 56.89 + 56.90 +router_ip=$(routing_ip "$ip") 56.91 + 56.92 +# Split the given IP/bits pair. 56.93 +vif_ip=`echo ${ip} | awk -F/ '{print $1}'` 56.94 + 56.95 +hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----') 56.96 +if [ "$vifid" != "1" ] 56.97 +then 56.98 + hostname="$hostname-$vifid" 56.99 +fi 56.100 + 56.101 +dhcparg_remove_entry() 56.102 +{ 56.103 + local tmpfile=$(mktemp) 56.104 + sed -e "s/$vif //" "$dhcpd_arg_file" >"$tmpfile" 56.105 + if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null 56.106 + then 56.107 + rm "$tmpfile" 56.108 + else 56.109 + mv "$tmpfile" "$dhcpd_arg_file" 56.110 + fi 56.111 +} 56.112 + 56.113 +dhcparg_add_entry() 56.114 +{ 56.115 + dhcparg_remove_entry 56.116 + local tmpfile=$(mktemp) 56.117 + # handle Red Hat, SUSE, and Debian styles, with or without quotes 56.118 + sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"$vif "'"/' \ 56.119 + "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 56.120 + sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"$vif "'"/' \ 56.121 + "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 56.122 + sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"$vif "'"/' \ 56.123 + "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file" 56.124 + rm -f "$tmpfile" 56.125 +} 56.126 + 56.127 +dhcp_remove_entry() 56.128 +{ 56.129 + local tmpfile=$(mktemp) 56.130 + grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile" 56.131 + if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null 56.132 + then 56.133 + rm "$tmpfile" 56.134 + else 56.135 + mv "$tmpfile" "$dhcpd_conf_file" 56.136 + fi 56.137 + dhcparg_remove_entry 56.138 +} 56.139 + 56.140 + 56.141 +dhcp_up() 56.142 +{ 56.143 + claim_lock "vif-nat-dhcp" 56.144 + dhcp_remove_entry 56.145 + mac=$(xenstore_read "$XENBUS_PATH/mac") 56.146 + echo >>"$dhcpd_conf_file" \ 56.147 +"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }" 56.148 + dhcparg_add_entry 56.149 + release_lock "vif-nat-dhcp" 56.150 + "$dhcpd_init_file" restart || true 56.151 +} 56.152 + 56.153 + 56.154 +dhcp_down() 56.155 +{ 56.156 + claim_lock "vif-nat-dhcp" 56.157 + dhcp_remove_entry 56.158 + release_lock "vif-nat-dhcp" 56.159 + "$dhcpd_init_file" restart || true # We need to ignore failure because 56.160 + # ISC dhcpd 3 borks if there is nothing 56.161 + # for it to do, which is the case if 56.162 + # the outgoing interface is not 56.163 + # configured to offer leases and there 56.164 + # are no vifs. 56.165 +} 56.166 + 56.167 + 56.168 +case "$command" in 56.169 + online) 56.170 + if ip route | grep -q "dev $vif" 56.171 + then 56.172 + log debug "$vif already up" 56.173 + exit 0 56.174 + fi 56.175 + 56.176 + do_or_die ip link set "$vif" up arp on 56.177 + do_or_die ip addr add "$router_ip" dev "$vif" 56.178 + do_or_die ip route add "$vif_ip" dev "$vif" src "$router_ip" 56.179 + echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp 56.180 + [ "$dhcp" != 'no' ] && dhcp_up 56.181 + ;; 56.182 + offline) 56.183 + [ "$dhcp" != 'no' ] && dhcp_down 56.184 + do_without_error ifconfig "$vif" down 56.185 + ;; 56.186 +esac 56.187 + 56.188 + 56.189 +handle_iptable 56.190 + 56.191 +log debug "Successful vif-nat $command for $vif." 56.192 +if [ "$command" = "online" ] 56.193 +then 56.194 + success 56.195 +fi
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/tools/hotplug/Linux/vif-route Tue Nov 25 14:21:24 2008 +0900 57.3 @@ -0,0 +1,56 @@ 57.4 +#!/bin/bash 57.5 +#============================================================================ 57.6 +# /etc/xen/vif-route 57.7 +# 57.8 +# Script for configuring a vif in routed mode. 57.9 +# The hotplugging system will call this script if it is specified either in 57.10 +# the device configuration given to Xend, or the default Xend configuration 57.11 +# in /etc/xen/xend-config.sxp. If the script is specified in neither of those 57.12 +# places, then vif-bridge is the default. 57.13 +# 57.14 +# Usage: 57.15 +# vif-route (add|remove|online|offline) 57.16 +# 57.17 +# Environment vars: 57.18 +# vif vif interface name (required). 57.19 +# XENBUS_PATH path to this device's details in the XenStore (required). 57.20 +# 57.21 +# Read from the store: 57.22 +# ip list of IP networks for the vif, space-separated (default given in 57.23 +# this script). 57.24 +#============================================================================ 57.25 + 57.26 +dir=$(dirname "$0") 57.27 +. "$dir/vif-common.sh" 57.28 + 57.29 +main_ip=$(dom0_ip) 57.30 + 57.31 +case "$command" in 57.32 + online) 57.33 + ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up 57.34 + echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp 57.35 + ipcmd='add' 57.36 + cmdprefix='' 57.37 + ;; 57.38 + offline) 57.39 + do_without_error ifdown ${vif} 57.40 + ipcmd='del' 57.41 + cmdprefix='do_without_error' 57.42 + ;; 57.43 +esac 57.44 + 57.45 +if [ "${ip}" ] ; then 57.46 + # If we've been given a list of IP addresses, then add routes from dom0 to 57.47 + # the guest using those addresses. 57.48 + for addr in ${ip} ; do 57.49 + ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip} 57.50 + done 57.51 +fi 57.52 + 57.53 +handle_iptable 57.54 + 57.55 +log debug "Successful vif-route $command for $vif." 57.56 +if [ "$command" = "online" ] 57.57 +then 57.58 + success 57.59 +fi
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/tools/hotplug/Linux/vscsi Tue Nov 25 14:21:24 2008 +0900 58.3 @@ -0,0 +1,22 @@ 58.4 +#!/bin/sh 58.5 +# 58.6 +# Copyright (c) 2007, FUJITSU Limited 58.7 +# Based on the block scripts code. 58.8 +# 58.9 + 58.10 +dir=$(dirname "$0") 58.11 +. "$dir/xen-hotplug-common.sh" 58.12 + 58.13 +findCommand "$@" 58.14 + 58.15 +case "$command" in 58.16 + add) 58.17 + success 58.18 + ;; 58.19 + remove) 58.20 + # TODO 58.21 + exit 0 58.22 + ;; 58.23 +esac 58.24 + 58.25 +exit 0
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/tools/hotplug/Linux/vtpm Tue Nov 25 14:21:24 2008 +0900 59.3 @@ -0,0 +1,22 @@ 59.4 +#!/bin/bash 59.5 + 59.6 +dir=$(dirname "$0") 59.7 +. "$dir/vtpm-hotplug-common.sh" 59.8 + 59.9 +vtpm_fatal_error=0 59.10 + 59.11 +case "$command" in 59.12 + add) 59.13 + vtpm_create_instance 59.14 + ;; 59.15 + remove) 59.16 + vtpm_remove_instance 59.17 + ;; 59.18 +esac 59.19 + 59.20 +if [ $vtpm_fatal_error -eq 0 ]; then 59.21 + log debug "Successful vTPM operation '$command'." 59.22 + success 59.23 +else 59.24 + fatal "Error while executing vTPM operation '$command'." 59.25 +fi
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 60.2 +++ b/tools/hotplug/Linux/vtpm-common.sh Tue Nov 25 14:21:24 2008 +0900 60.3 @@ -0,0 +1,448 @@ 60.4 +# 60.5 +# Copyright (c) 2005 IBM Corporation 60.6 +# Copyright (c) 2005 XenSource Ltd. 60.7 +# 60.8 +# This library is free software; you can redistribute it and/or 60.9 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 60.10 +# License as published by the Free Software Foundation. 60.11 +# 60.12 +# This library is distributed in the hope that it will be useful, 60.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 60.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 60.15 +# Lesser General Public License for more details. 60.16 +# 60.17 +# You should have received a copy of the GNU Lesser General Public 60.18 +# License along with this library; if not, write to the Free Software 60.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 60.20 +# 60.21 + 60.22 +dir=$(dirname "$0") 60.23 +. "$dir/logging.sh" 60.24 +. "$dir/locking.sh" 60.25 + 60.26 +VTPMDB="/var/vtpm/vtpm.db" 60.27 + 60.28 +#In the vtpm-impl file some commands should be defined: 60.29 +# vtpm_create, vtpm_setup, vtpm_start, etc. (see below) 60.30 +if [ -r "$dir/vtpm-impl.alt" ]; then 60.31 + . "$dir/vtpm-impl.alt" 60.32 +elif [ -r "$dir/vtpm-impl" ]; then 60.33 + . "$dir/vtpm-impl" 60.34 +else 60.35 + function vtpm_create () { 60.36 + true 60.37 + } 60.38 + function vtpm_setup() { 60.39 + true 60.40 + } 60.41 + function vtpm_start() { 60.42 + true 60.43 + } 60.44 + function vtpm_suspend() { 60.45 + true 60.46 + } 60.47 + function vtpm_resume() { 60.48 + true 60.49 + } 60.50 + function vtpm_delete() { 60.51 + true 60.52 + } 60.53 + function vtpm_migrate() { 60.54 + echo "Error: vTPM migration accross machines not implemented." 60.55 + } 60.56 + function vtpm_migrate_local() { 60.57 + echo "Error: local vTPM migration not supported" 60.58 + } 60.59 + function vtpm_migrate_recover() { 60.60 + true 60.61 + } 60.62 +fi 60.63 + 60.64 + 60.65 +#Find the instance number for the vtpm given the name of the domain 60.66 +# Parameters 60.67 +# - vmname : the name of the vm 60.68 +# Return value 60.69 +# Returns '0' if instance number could not be found, otherwise 60.70 +# it returns the instance number in the variable 'instance' 60.71 +function vtpmdb_find_instance () { 60.72 + local vmname ret instance 60.73 + vmname=$1 60.74 + ret=0 60.75 + 60.76 + instance=$(cat $VTPMDB | \ 60.77 + awk -vvmname=$vmname \ 60.78 + '{ \ 60.79 + if ( 1 != index($1,"#")) { \ 60.80 + if ( $1 == vmname ) { \ 60.81 + print $2; \ 60.82 + exit; \ 60.83 + } \ 60.84 + } \ 60.85 + }') 60.86 + if [ "$instance" != "" ]; then 60.87 + ret=$instance 60.88 + fi 60.89 + echo "$ret" 60.90 +} 60.91 + 60.92 + 60.93 +# Check whether a particular instance number is still available 60.94 +# returns "0" if it is not available, "1" otherwise. 60.95 +function vtpmdb_is_free_instancenum () { 60.96 + local instance instances avail i 60.97 + instance=$1 60.98 + avail=1 60.99 + #Allowed instance number range: 1-255 60.100 + if [ $instance -eq 0 -o $instance -gt 255 ]; then 60.101 + avail=0 60.102 + else 60.103 + instances=$(cat $VTPMDB | \ 60.104 + gawk \ 60.105 + '{ \ 60.106 + if (1 != index($1,"#")) { \ 60.107 + printf("%s ",$2); \ 60.108 + } \ 60.109 + }') 60.110 + for i in $instances; do 60.111 + if [ $i -eq $instance ]; then 60.112 + avail=0 60.113 + break 60.114 + fi 60.115 + done 60.116 + fi 60.117 + echo "$avail" 60.118 +} 60.119 + 60.120 + 60.121 +# Get an available instance number given the database 60.122 +# Returns an unused instance number 60.123 +function vtpmdb_get_free_instancenum () { 60.124 + local ctr instances don found 60.125 + instances=$(cat $VTPMDB | \ 60.126 + gawk \ 60.127 + '{ \ 60.128 + if (1 != index($1,"#")) { \ 60.129 + printf("%s ",$2); \ 60.130 + } \ 60.131 + }') 60.132 + ctr=1 60.133 + don=0 60.134 + while [ $don -eq 0 ]; do 60.135 + found=0 60.136 + for i in $instances; do 60.137 + if [ $i -eq $ctr ]; then 60.138 + found=1; 60.139 + break; 60.140 + fi 60.141 + done 60.142 + 60.143 + if [ $found -eq 0 ]; then 60.144 + don=1 60.145 + break 60.146 + fi 60.147 + let ctr=ctr+1 60.148 + done 60.149 + echo "$ctr" 60.150 +} 60.151 + 60.152 + 60.153 +# Add a domain name and instance number to the DB file 60.154 +function vtpmdb_add_instance () { 60.155 + local res vmname inst 60.156 + vmname=$1 60.157 + inst=$2 60.158 + 60.159 + if [ ! -f $VTPMDB ]; then 60.160 + echo "#Database for VM to vTPM association" > $VTPMDB 60.161 + echo "#1st column: domain name" >> $VTPMDB 60.162 + echo "#2nd column: TPM instance number" >> $VTPMDB 60.163 + fi 60.164 + res=$(vtpmdb_validate_entry $vmname $inst) 60.165 + if [ $res -eq 0 ]; then 60.166 + echo "$vmname $inst" >> $VTPMDB 60.167 + fi 60.168 +} 60.169 + 60.170 + 60.171 +#Validate whether an entry is the same as passed to this 60.172 +#function 60.173 +function vtpmdb_validate_entry () { 60.174 + local res rc vmname inst 60.175 + rc=0 60.176 + vmname=$1 60.177 + inst=$2 60.178 + 60.179 + res=$(cat $VTPMDB | \ 60.180 + gawk -vvmname=$vmname \ 60.181 + -vinst=$inst \ 60.182 + '{ \ 60.183 + if ( 1 == index($1,"#")) {\ 60.184 + } else \ 60.185 + if ( $1 == vmname && \ 60.186 + $2 == inst) { \ 60.187 + printf("1"); \ 60.188 + exit; \ 60.189 + } else \ 60.190 + if ( $1 == vmname || \ 60.191 + $2 == inst) { \ 60.192 + printf("2"); \ 60.193 + exit; \ 60.194 + } \ 60.195 + }') 60.196 + 60.197 + if [ "$res" == "1" ]; then 60.198 + rc=1 60.199 + elif [ "$res" == "2" ]; then 60.200 + rc=2 60.201 + fi 60.202 + echo "$rc" 60.203 +} 60.204 + 60.205 + 60.206 +#Remove an entry from the vTPM database given its domain name 60.207 +#and instance number 60.208 +function vtpmdb_remove_entry () { 60.209 + local vmname instance VTPMDB_TMP 60.210 + vmname=$1 60.211 + instance=$2 60.212 + VTPMDB_TMP="$VTPMDB".tmp 60.213 + 60.214 + $(cat $VTPMDB | \ 60.215 + gawk -vvmname=$vmname \ 60.216 + '{ \ 60.217 + if ( $1 != vmname ) { \ 60.218 + print $0; \ 60.219 + } \ 60.220 + '} > $VTPMDB_TMP) 60.221 + if [ -e $VTPMDB_TMP ]; then 60.222 + mv -f $VTPMDB_TMP $VTPMDB 60.223 + vtpm_delete $instance 60.224 + else 60.225 + log err "Error creating temporary file '$VTPMDB_TMP'." 60.226 + fi 60.227 +} 60.228 + 60.229 + 60.230 +# Find the reason for the creation of this device: 60.231 +# Returns 'resume' or 'create' 60.232 +function vtpm_get_create_reason () { 60.233 + local resume 60.234 + resume=$(xenstore_read $XENBUS_PATH/resume) 60.235 + if [ "$resume" == "True" ]; then 60.236 + echo "resume" 60.237 + else 60.238 + echo "create" 60.239 + fi 60.240 +} 60.241 + 60.242 + 60.243 +#Create a vTPM instance 60.244 +# If no entry in the TPM database is found, the instance is 60.245 +# created and an entry added to the database. 60.246 +function vtpm_create_instance () { 60.247 + local res instance domname reason uuid 60.248 + uuid=$(xenstore_read "$XENBUS_PATH"/uuid) 60.249 + reason=$(vtpm_get_create_reason) 60.250 + 60.251 + claim_lock vtpmdb 60.252 + 60.253 + instance="0" 60.254 + 60.255 + if [ "$uuid" != "" ]; then 60.256 + instance=$(vtpmdb_find_instance $uuid) 60.257 + fi 60.258 + if [ "$instance" == "0" ]; then 60.259 + domname=$(xenstore_read "$XENBUS_PATH"/domain) 60.260 + instance=$(vtpmdb_find_instance $domname) 60.261 + fi 60.262 + 60.263 + if [ "$instance" == "0" -a "$reason" != "create" ]; then 60.264 + release_lock vtpmdb 60.265 + return 60.266 + fi 60.267 + 60.268 + if [ "$instance" == "0" ]; then 60.269 + #Try to give the preferred instance to the domain 60.270 + instance=$(xenstore_read "$XENBUS_PATH"/pref_instance) 60.271 + if [ "$instance" != "" ]; then 60.272 + res=$(vtpmdb_is_free_instancenum $instance) 60.273 + if [ $res -eq 0 ]; then 60.274 + instance=$(vtpmdb_get_free_instancenum) 60.275 + fi 60.276 + else 60.277 + instance=$(vtpmdb_get_free_instancenum) 60.278 + fi 60.279 + 60.280 + vtpm_create $instance 60.281 + 60.282 + if [ $vtpm_fatal_error -eq 0 ]; then 60.283 + if [ "$uuid" != "" ]; then 60.284 + vtpmdb_add_instance $uuid $instance 60.285 + else 60.286 + vtpmdb_add_instance $domname $instance 60.287 + fi 60.288 + fi 60.289 + else 60.290 + if [ "$reason" == "resume" ]; then 60.291 + vtpm_resume $instance 60.292 + else 60.293 + vtpm_start $instance 60.294 + fi 60.295 + fi 60.296 + 60.297 + release_lock vtpmdb 60.298 + 60.299 + xenstore_write $XENBUS_PATH/instance $instance 60.300 +} 60.301 + 60.302 + 60.303 +#Remove an instance when a VM is terminating or suspending. 60.304 +#Since it is assumed that the VM will appear again, the 60.305 +#entry is kept in the VTPMDB file. 60.306 +function vtpm_remove_instance () { 60.307 + local instance reason domname uuid 60.308 + #Stop script execution quietly if path does not exist (anymore) 60.309 + xenstore-exists "$XENBUS_PATH"/domain 60.310 + uuid=$(xenstore_read "$XENBUS_PATH"/uuid) 60.311 + 60.312 + claim_lock vtpmdb 60.313 + 60.314 + instance="0" 60.315 + 60.316 + if [ "$uuid" != "" ]; then 60.317 + instance=$(vtpmdb_find_instance $uuid) 60.318 + fi 60.319 + 60.320 + if [ "$instance" == "0" ]; then 60.321 + domname=$(xenstore_read "$XENBUS_PATH"/domain) 60.322 + instance=$(vtpmdb_find_instance $domname) 60.323 + fi 60.324 + 60.325 + if [ "$instance" != "0" ]; then 60.326 + vtpm_suspend $instance 60.327 + fi 60.328 + 60.329 + release_lock vtpmdb 60.330 +} 60.331 + 60.332 + 60.333 +#Remove an entry in the VTPMDB file given the domain's name 60.334 +#1st parameter: The name of the domain 60.335 +function vtpm_delete_instance () { 60.336 + local instance 60.337 + 60.338 + claim_lock vtpmdb 60.339 + 60.340 + instance=$(vtpmdb_find_instance $1) 60.341 + if [ "$instance" != "0" ]; then 60.342 + vtpmdb_remove_entry $1 $instance 60.343 + fi 60.344 + 60.345 + release_lock vtpmdb 60.346 +} 60.347 + 60.348 +# Determine whether the given address is local to this machine 60.349 +# Return values: 60.350 +# "-1" : the given machine name is invalid 60.351 +# "0" : this is not an address of this machine 60.352 +# "1" : this is an address local to this machine 60.353 +function vtpm_isLocalAddress() { 60.354 + local addr res 60.355 + addr=$(ping $1 -c 1 | \ 60.356 + gawk '{ print substr($3,2,length($3)-2); exit }') 60.357 + if [ "$addr" == "" ]; then 60.358 + echo "-1" 60.359 + return 60.360 + fi 60.361 + res=$(ifconfig | grep "inet addr" | \ 60.362 + gawk -vaddr=$addr \ 60.363 + '{ \ 60.364 + if ( addr == substr($2, 6)) {\ 60.365 + print "1"; \ 60.366 + } \ 60.367 + }' \ 60.368 + ) 60.369 + if [ "$res" == "" ]; then 60.370 + echo "0" 60.371 + return 60.372 + fi 60.373 + echo "1" 60.374 +} 60.375 + 60.376 +# Perform a migration step. This function differentiates between migration 60.377 +# to the local host or to a remote machine. 60.378 +# Parameters: 60.379 +# 1st: destination host to migrate to 60.380 +# 2nd: name of the domain to migrate 60.381 +# 3rd: the migration step to perform 60.382 +function vtpm_migration_step() { 60.383 + local res=$(vtpm_isLocalAddress $1) 60.384 + if [ "$res" == "0" ]; then 60.385 + vtpm_migrate $1 $2 $3 60.386 + else 60.387 + vtpm_migrate_local 60.388 + fi 60.389 +} 60.390 + 60.391 +# Recover from migration due to an error. This function differentiates 60.392 +# between migration to the local host or to a remote machine. 60.393 +# Parameters: 60.394 +# 1st: destination host the migration was going to 60.395 +# 2nd: name of the domain that was to be migrated 60.396 +# 3rd: the last successful migration step that was done 60.397 +function vtpm_recover() { 60.398 + local res 60.399 + res=$(vtpm_isLocalAddress $1) 60.400 + if [ "$res" == "0" ]; then 60.401 + vtpm_migrate_recover $1 $2 $3 60.402 + fi 60.403 +} 60.404 + 60.405 + 60.406 +#Determine the domain id given a domain's name. 60.407 +#1st parameter: name of the domain 60.408 +#return value: domain id or -1 if domain id could not be determined 60.409 +function vtpm_domid_from_name () { 60.410 + local id name ids 60.411 + ids=$(xenstore-list /local/domain) 60.412 + for id in $ids; do 60.413 + name=$(xenstore-read /local/domain/$id/name) 60.414 + if [ "$name" == "$1" ]; then 60.415 + echo "$id" 60.416 + return 60.417 + fi 60.418 + done 60.419 + echo "-1" 60.420 +} 60.421 + 60.422 +#Determine the virtual TPM's instance number using the domain ID. 60.423 +#1st parm: domain ID 60.424 +function vtpm_uuid_by_domid() { 60.425 + echo $(xenstore-read /local/domain/0/backend/vtpm/$1/0/uuid) 60.426 +} 60.427 + 60.428 + 60.429 +# Determine the vTPM's UUID by the name of the VM 60.430 +function vtpm_uuid_from_vmname() { 60.431 + local domid=$(vtpm_domid_from_name $1) 60.432 + if [ "$domid" != "-1" ]; then 60.433 + echo $(vtpm_uuid_by_domid $domid) 60.434 + return 60.435 + fi 60.436 + echo "" 60.437 +} 60.438 + 60.439 +#Add a virtual TPM instance number and its associated domain name 60.440 +#to the VTPMDB file and activate usage of this virtual TPM instance 60.441 +#by writing the instance number into the xenstore 60.442 +#1st parm: name of virtual machine 60.443 +#2nd parm: instance of associated virtual TPM 60.444 +function vtpm_add_and_activate() { 60.445 + local domid=$(vtpm_domid_from_name $1) 60.446 + local vtpm_uuid=$(vtpm_uuid_from_vmname $1) 60.447 + if [ "$vtpm_uuid" != "" -a "$domid" != "-1" ]; then 60.448 + vtpmdb_add_instance $vtpm_uuid $2 60.449 + xenstore-write backend/vtpm/$domid/0/instance $2 60.450 + fi 60.451 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/tools/hotplug/Linux/vtpm-delete Tue Nov 25 14:21:24 2008 +0900 61.3 @@ -0,0 +1,18 @@ 61.4 +#!/bin/bash 61.5 + 61.6 +# This scripts must be called the following way: 61.7 +# vtpm-delete <vtpm uuid> 61.8 +# or 61.9 +# vtpm-delete --vmname <vm name> 61.10 + 61.11 +dir=$(dirname "$0") 61.12 +. "$dir/vtpm-common.sh" 61.13 + 61.14 +if [ "$1" == "--vmname" ]; then 61.15 + vtpm_uuid=$(vtpm_uuid_from_vmname $2) 61.16 + if [ "$vtpm_uuid" != "" ];then 61.17 + vtpm_delete_instance $vtpm_uuid 61.18 + fi 61.19 +else 61.20 + vtpm_delete_instance $1 61.21 +fi
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/tools/hotplug/Linux/vtpm-hotplug-common.sh Tue Nov 25 14:21:24 2008 +0900 62.3 @@ -0,0 +1,35 @@ 62.4 +# 62.5 +# Copyright (c) 2005 IBM Corporation 62.6 +# Copyright (c) 2005 XenSource Ltd. 62.7 +# 62.8 +# This library is free software; you can redistribute it and/or 62.9 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 62.10 +# License as published by the Free Software Foundation. 62.11 +# 62.12 +# This library is distributed in the hope that it will be useful, 62.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 62.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 62.15 +# Lesser General Public License for more details. 62.16 +# 62.17 +# You should have received a copy of the GNU Lesser General Public 62.18 +# License along with this library; if not, write to the Free Software 62.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 62.20 +# 62.21 + 62.22 +dir=$(dirname "$0") 62.23 +. "$dir/xen-hotplug-common.sh" 62.24 + 62.25 +findCommand "$@" 62.26 +if [ "$command" != "online" ] && 62.27 + [ "$command" != "offline" ] && 62.28 + [ "$command" != "add" ] && 62.29 + [ "$command" != "remove" ] 62.30 +then 62.31 + log err "Invalid command: $command" 62.32 + exit 1 62.33 +fi 62.34 + 62.35 + 62.36 +XENBUS_PATH="${XENBUS_PATH:?}" 62.37 + 62.38 +. "$dir/vtpm-common.sh"
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/tools/hotplug/Linux/vtpm-impl Tue Nov 25 14:21:24 2008 +0900 63.3 @@ -0,0 +1,208 @@ 63.4 +#!/bin/bash 63.5 +# =================================================================== 63.6 +# 63.7 +# Copyright (c) 2005, Intel Corp. 63.8 +# All rights reserved. 63.9 +# 63.10 +# Redistribution and use in source and binary forms, with or without 63.11 +# modification, are permitted provided that the following conditions 63.12 +# are met: 63.13 +# 63.14 +# * Redistributions of source code must retain the above copyright 63.15 +# notice, this list of conditions and the following disclaimer. 63.16 +# * Redistributions in binary form must reproduce the above 63.17 +# copyright notice, this list of conditions and the following 63.18 +# disclaimer in the documentation and/or other materials provided 63.19 +# with the distribution. 63.20 +# * Neither the name of Intel Corporation nor the names of its 63.21 +# contributors may be used to endorse or promote products derived 63.22 +# from this software without specific prior written permission. 63.23 +# 63.24 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 63.25 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 63.26 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 63.27 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 63.28 +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 63.29 +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 63.30 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 63.31 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63.32 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 63.33 +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63.34 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 63.35 +# OF THE POSSIBILITY OF SUCH DAMAGE. 63.36 +# =================================================================== 63.37 + 63.38 +# | SRC | TAG | CMD SIZE | ORD |mtype|strt 63.39 +TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x01 63.40 +TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x02 63.41 +TPM_CMD_CLOS=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x02 63.42 +TPM_CMD_DELE=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x03 63.43 + 63.44 +TPM_TYPE_PVM=\\x01 63.45 +TPM_TYPE_HVM=\\x02 63.46 + 63.47 +TPM_SUCCESS=00000000 63.48 + 63.49 +TX_VTPM_MANAGER=/var/vtpm/fifos/from_console.fifo 63.50 +RX_VTPM_MANAGER=/var/vtpm/fifos/to_console.fifo 63.51 + 63.52 +VTPM_MIG=/usr/bin/vtpm_migrator 63.53 + 63.54 +# -------------------- Helpers for binary streams ----------- 63.55 + 63.56 +function str_to_hex32() { 63.57 + printf "%0.8x" $1 63.58 +} 63.59 + 63.60 +function hex32_to_bin() { 63.61 + local inst=$(str_to_hex32 $1); 63.62 + 63.63 + local n1=`echo $inst | sed 's/\(..\)....../\\\\x\1/'` 63.64 + local n2=`echo $inst | sed 's/..\(..\)..../\\\\x\1/'` 63.65 + local n3=`echo $inst | sed 's/....\(..\)../\\\\x\1/'` 63.66 + local n4=`echo $inst | sed 's/......\(..\)/\\\\x\1/'` 63.67 + 63.68 + echo "$n1$n2$n3$n4" 63.69 +} 63.70 + 63.71 +function vtpm_manager_cmd() { 63.72 + local cmd=$1; 63.73 + local inst=$2; 63.74 + local inst_bin=$(hex32_to_bin $inst); 63.75 + 63.76 + claim_lock vtpm_mgr 63.77 + 63.78 + #send cmd to vtpm_manager 63.79 + printf "$cmd$inst_bin" > $TX_VTPM_MANAGER 63.80 + 63.81 + #recv response 63.82 + set +e 63.83 + local resp_hex=`dd skip=10 bs=1 count=4 if=$RX_VTPM_MANAGER 2> /dev/null | xxd -ps` 63.84 + set -e 63.85 + 63.86 + release_lock vtpm_mgr 63.87 + 63.88 + #return whether the command was successful 63.89 + if [ $resp_hex -ne $TPM_SUCCESS ]; then 63.90 + vtpm_fatal_error=1 63.91 + false 63.92 + else 63.93 + true 63.94 + fi 63.95 +} 63.96 + 63.97 +# Helper to get vm type to pass to vtpm_manager open/resume 63.98 +function vtpm_get_type() { 63.99 + local inst=$(xenstore_read $XENBUS_PATH/frontend-id) 63.100 + local vm=$(xenstore_read /local/domain/$inst/vm) 63.101 + if [ "$vm" != "" ]; then 63.102 + local ostype=$(xenstore-read $vm/image/ostype) 63.103 + if [ "$ostype" == "hvm" ]; then 63.104 + echo $TPM_TYPE_HVM; 63.105 + else 63.106 + echo $TPM_TYPE_PVM; 63.107 + fi 63.108 + fi 63.109 +} 63.110 + 63.111 +# ------------------ Command handlers ----------------- 63.112 + 63.113 +# Create new vtpm instance & set it up for use 63.114 +function vtpm_create () { 63.115 + # Creation is handled implicitly by the manager on first setup 63.116 + # so just set it up for use 63.117 + $(vtpm_start $1) 63.118 +} 63.119 + 63.120 +# Setup vtpm instance for use. 63.121 +function vtpm_start() { 63.122 + local vmtype=$(vtpm_get_type); 63.123 + $(vtpm_manager_cmd $TPM_CMD_OPEN$vmtype $1) 63.124 +} 63.125 + 63.126 +function vtpm_resume() { 63.127 + local vmtype=$(vtpm_get_type); 63.128 + $(vtpm_manager_cmd $TPM_CMD_RESM$vmtype $1) 63.129 +} 63.130 + 63.131 +# Reset the vtpm AKA clear PCRs 63.132 +function vtpm_reset() { 63.133 + #not used by current implemenation 63.134 + true 63.135 +} 63.136 + 63.137 +# Shutdown the vtpm while the vm is down 63.138 +# This could be a suspend of shutdown 63.139 +# we cannot distinquish, so save the state 63.140 +# and decide on startup if we should keep is 63.141 +function vtpm_suspend() { 63.142 + $(vtpm_manager_cmd $TPM_CMD_CLOS $1) 63.143 +} 63.144 + 63.145 + 63.146 +function vtpm_delete() { 63.147 + local inst=$1 63.148 + if $(vtpm_manager_cmd $TPM_CMD_DELE $inst); then 63.149 + rm -f /var/vtpm/vtpm_dm_$1.data 63.150 + true 63.151 + else 63.152 + vtpm_fatal_error=1 63.153 + false 63.154 + fi 63.155 +} 63.156 + 63.157 +# Perform a migration step. This function differentiates between migration 63.158 +# to the local host or to a remote machine. 63.159 +# Parameters: 63.160 +# 1st: destination host to migrate to 63.161 +# 2nd: name of the domain to migrate 63.162 +# 3rd: the migration step to perform 63.163 +function vtpm_migrate() { 63.164 + local instance res 63.165 + 63.166 + instance=$(vtpmdb_find_instance $2) 63.167 + if [ "$instance" == "" ]; then 63.168 + log err "VTPM Migratoin failed. Unable to translation of domain name" 63.169 + echo "Error: VTPM Migration failed while looking up instance number" 63.170 + fi 63.171 + 63.172 + case "$3" in 63.173 + 0) 63.174 + #Incicate migration supported 63.175 + echo "0" 63.176 + ;; 63.177 + 63.178 + 1) 63.179 + # Get Public Key from Destination 63.180 + # Call vtpm_manager's migration part 1 63.181 + claim_lock vtpm_mgr 63.182 + $VTPM_MIG $1 $2 $instance $3 63.183 + release_lock vtpm_mgr 63.184 + ;; 63.185 + 63.186 + 2) 63.187 + # Call manager's migration step 2 and send result to destination 63.188 + # If successful remove from db 63.189 + claim_lock vtpm_mgr 63.190 + $VTPM_MIG $1 $2 $instance $3 63.191 + release_lock vtpm_mgr 63.192 + ;; 63.193 + 63.194 + 3) 63.195 + if `ps x | grep "$VTPM_MIG $1"`; then 63.196 + log err "VTPM Migration failed to complete." 63.197 + echo "Error: VTPM Migration failed to complete." 63.198 + fi 63.199 + ;; 63.200 + esac 63.201 + 63.202 +} 63.203 + 63.204 + 63.205 +function vtpm_migrate_recover() { 63.206 + echo "Error: Recovery not supported yet" 63.207 +} 63.208 + 63.209 +function vtpm_migrate_local() { 63.210 + echo "Error: local vTPM migration not supported" 63.211 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/tools/hotplug/Linux/vtpm-migration.sh Tue Nov 25 14:21:24 2008 +0900 64.3 @@ -0,0 +1,19 @@ 64.4 +# 64.5 +# Copyright (c) 2005 IBM Corporation 64.6 +# 64.7 +# This library is free software; you can redistribute it and/or 64.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 64.9 +# License as published by the Free Software Foundation. 64.10 +# 64.11 +# This library is distributed in the hope that it will be useful, 64.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 64.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 64.14 +# Lesser General Public License for more details. 64.15 +# 64.16 +# You should have received a copy of the GNU Lesser General Public 64.17 +# License along with this library; if not, write to the Free Software 64.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 64.19 +# 64.20 + 64.21 +dir=$(dirname "$0") 64.22 +. "$dir/vtpm-common.sh"
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/tools/hotplug/Linux/xen-backend.agent Tue Nov 25 14:21:24 2008 +0900 65.3 @@ -0,0 +1,39 @@ 65.4 +#! /bin/bash 65.5 + 65.6 +PATH=/etc/xen/scripts:$PATH 65.7 + 65.8 +. /etc/xen/scripts/locking.sh 65.9 + 65.10 +claim_lock xenbus_hotplug_global 65.11 + 65.12 +case "$XENBUS_TYPE" in 65.13 + tap) 65.14 + /etc/xen/scripts/blktap "$ACTION" 65.15 + ;; 65.16 + vbd) 65.17 + /etc/xen/scripts/block "$ACTION" 65.18 + ;; 65.19 + vtpm) 65.20 + /etc/xen/scripts/vtpm "$ACTION" 65.21 + ;; 65.22 + vif) 65.23 + [ -n "$script" ] && $script "$ACTION" 65.24 + ;; 65.25 + vscsi) 65.26 + /etc/xen/scripts/vscsi "$ACTION" 65.27 + ;; 65.28 +esac 65.29 + 65.30 +case "$ACTION" in 65.31 + add) 65.32 + ;; 65.33 + remove) 65.34 + /etc/xen/scripts/xen-hotplug-cleanup 65.35 + ;; 65.36 + online) 65.37 + ;; 65.38 + offline) 65.39 + ;; 65.40 +esac 65.41 + 65.42 +release_lock xenbus_hotplug_global
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 66.2 +++ b/tools/hotplug/Linux/xen-backend.rules Tue Nov 25 14:21:24 2008 +0900 66.3 @@ -0,0 +1,9 @@ 66.4 +SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" 66.5 +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" 66.6 +SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" 66.7 +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online" 66.8 +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline" 66.9 +SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" 66.10 +SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" 66.11 +KERNEL=="evtchn", NAME="xen/%k" 66.12 +KERNEL=="blktap[0-9]*", NAME="xen/%k"
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/tools/hotplug/Linux/xen-hotplug-cleanup Tue Nov 25 14:21:24 2008 +0900 67.3 @@ -0,0 +1,22 @@ 67.4 +#! /bin/bash 67.5 + 67.6 +dir=$(dirname "$0") 67.7 +. "$dir/xen-hotplug-common.sh" 67.8 + 67.9 +# Claim the lock protecting /etc/xen/scripts/block. This stops a race whereby 67.10 +# paths in the store would disappear underneath that script as it attempted to 67.11 +# read from the store checking for device sharing. 67.12 +# Any other scripts that do similar things will have to have their lock 67.13 +# claimed too. 67.14 +# This is pretty horrible, but there's not really a nicer way of solving this. 67.15 +claim_lock "block" 67.16 + 67.17 +# remove device frontend store entries 67.18 +xenstore-rm -t \ 67.19 + $(xenstore-read "$XENBUS_PATH/frontend" 2>/dev/null) 2>/dev/null || true 67.20 + 67.21 +# remove device backend store entries 67.22 +xenstore-rm -t "$XENBUS_PATH" 2>/dev/null || true 67.23 +xenstore-rm -t "error/$XENBUS_PATH" 2>/dev/null || true 67.24 + 67.25 +release_lock "block"
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 68.2 +++ b/tools/hotplug/Linux/xen-hotplug-common.sh Tue Nov 25 14:21:24 2008 +0900 68.3 @@ -0,0 +1,93 @@ 68.4 +# 68.5 +# Copyright (c) 2005 XenSource Ltd. 68.6 +# 68.7 +# This library is free software; you can redistribute it and/or 68.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 68.9 +# License as published by the Free Software Foundation. 68.10 +# 68.11 +# This library is distributed in the hope that it will be useful, 68.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 68.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 68.14 +# Lesser General Public License for more details. 68.15 +# 68.16 +# You should have received a copy of the GNU Lesser General Public 68.17 +# License along with this library; if not, write to the Free Software 68.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 68.19 +# 68.20 + 68.21 + 68.22 +dir=$(dirname "$0") 68.23 +. "$dir/logging.sh" 68.24 +. "$dir/xen-script-common.sh" 68.25 +. "$dir/locking.sh" 68.26 + 68.27 +exec 2>>/var/log/xen/xen-hotplug.log 68.28 + 68.29 +export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH" 68.30 +export LANG="POSIX" 68.31 +unset $(set | grep ^LC_ | cut -d= -f1) 68.32 + 68.33 +fatal() { 68.34 + xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \ 68.35 + "$XENBUS_PATH/hotplug-status" error 68.36 + log err "$@" 68.37 + exit 1 68.38 +} 68.39 + 68.40 +success() { 68.41 + # Tell DevController that backend is "connected" 68.42 + xenstore_write "$XENBUS_PATH/hotplug-status" connected 68.43 +} 68.44 + 68.45 +do_or_die() { 68.46 + "$@" || fatal "$@ failed" 68.47 +} 68.48 + 68.49 +do_without_error() { 68.50 + "$@" 2>/dev/null || log debug "$@ failed" 68.51 +} 68.52 + 68.53 +sigerr() { 68.54 + fatal "$0 failed; error detected." 68.55 +} 68.56 + 68.57 +trap sigerr ERR 68.58 + 68.59 + 68.60 +## 68.61 +# xenstore_read <path>+ 68.62 +# 68.63 +# Read each of the given paths, returning each result on a separate line, or 68.64 +# exit this script if any of the paths is missing. 68.65 +# 68.66 +xenstore_read() { 68.67 + local v=$(xenstore-read "$@" || true) 68.68 + [ "$v" != "" ] || fatal "xenstore-read $@ failed." 68.69 + echo "$v" 68.70 +} 68.71 + 68.72 + 68.73 +## 68.74 +# xenstore_read_default <path> <default> 68.75 +# 68.76 +# Read the given path, returning the value there or the given default if the 68.77 +# path is not present. 68.78 +# 68.79 +xenstore_read_default() { 68.80 + xenstore-read "$1" 2>/dev/null || echo "$2" 68.81 +} 68.82 + 68.83 + 68.84 +## 68.85 +# xenstore_write (<path> <value>)+ 68.86 +# 68.87 +# Write each of the key/value pairs to the store, and exit this script if any 68.88 +# such writing fails. 68.89 +# 68.90 +xenstore_write() { 68.91 + log debug "Writing $@ to xenstore." 68.92 + xenstore-write "$@" || fatal "Writing $@ to xenstore failed." 68.93 +} 68.94 + 68.95 + 68.96 +log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/tools/hotplug/Linux/xen-network-common.sh Tue Nov 25 14:21:24 2008 +0900 69.3 @@ -0,0 +1,118 @@ 69.4 +# 69.5 +# Copyright (c) 2005 XenSource Ltd. 69.6 +# 69.7 +# This library is free software; you can redistribute it and/or 69.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 69.9 +# License as published by the Free Software Foundation. 69.10 +# 69.11 +# This library is distributed in the hope that it will be useful, 69.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 69.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 69.14 +# Lesser General Public License for more details. 69.15 +# 69.16 +# You should have received a copy of the GNU Lesser General Public 69.17 +# License along with this library; if not, write to the Free Software 69.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 69.19 +# 69.20 + 69.21 + 69.22 +# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives. 69.23 + 69.24 +# Other platforms just use ifup / ifdown directly. 69.25 + 69.26 +## 69.27 +# preiftransfer 69.28 +# 69.29 +# @param $1 The current name for the physical device, which is also the name 69.30 +# that the virtual device will take once the physical device has 69.31 +# been renamed. 69.32 + 69.33 +if ! which ifup >/dev/null 2>/dev/null 69.34 +then 69.35 + preiftransfer() 69.36 + { 69.37 + true 69.38 + } 69.39 + ifup() 69.40 + { 69.41 + false 69.42 + } 69.43 + ifdown() 69.44 + { 69.45 + false 69.46 + } 69.47 +else 69.48 + preiftransfer() 69.49 + { 69.50 + true 69.51 + } 69.52 +fi 69.53 + 69.54 + 69.55 +first_file() 69.56 +{ 69.57 + t="$1" 69.58 + shift 69.59 + for file in $@ 69.60 + do 69.61 + if [ "$t" "$file" ] 69.62 + then 69.63 + echo "$file" 69.64 + return 69.65 + fi 69.66 + done 69.67 +} 69.68 + 69.69 +find_dhcpd_conf_file() 69.70 +{ 69.71 + first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf 69.72 +} 69.73 + 69.74 + 69.75 +find_dhcpd_init_file() 69.76 +{ 69.77 + first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd} 69.78 +} 69.79 + 69.80 +find_dhcpd_arg_file() 69.81 +{ 69.82 + first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server 69.83 +} 69.84 + 69.85 +# configure interfaces which act as pure bridge ports: 69.86 +setup_bridge_port() { 69.87 + local dev="$1" 69.88 + 69.89 + # take interface down ... 69.90 + ip link set ${dev} down 69.91 + 69.92 + # ... and configure it 69.93 + ip addr flush ${dev} 69.94 +} 69.95 + 69.96 +# Usage: create_bridge bridge 69.97 +create_bridge () { 69.98 + local bridge=$1 69.99 + 69.100 + # Don't create the bridge if it already exists. 69.101 + if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then 69.102 + brctl addbr ${bridge} 69.103 + brctl stp ${bridge} off 69.104 + brctl setfd ${bridge} 0 69.105 + fi 69.106 +} 69.107 + 69.108 +# Usage: add_to_bridge bridge dev 69.109 +add_to_bridge () { 69.110 + local bridge=$1 69.111 + local dev=$2 69.112 + 69.113 + # Don't add $dev to $bridge if it's already on a bridge. 69.114 + if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then 69.115 + ip link set ${dev} up || true 69.116 + return 69.117 + fi 69.118 + brctl addif ${bridge} ${dev} 69.119 + ip link set ${dev} up 69.120 +} 69.121 +
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 70.2 +++ b/tools/hotplug/Linux/xen-script-common.sh Tue Nov 25 14:21:24 2008 +0900 70.3 @@ -0,0 +1,44 @@ 70.4 +# 70.5 +# Copyright (c) 2005 XenSource Ltd. 70.6 +# 70.7 +# This library is free software; you can redistribute it and/or 70.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 70.9 +# License as published by the Free Software Foundation. 70.10 +# 70.11 +# This library is distributed in the hope that it will be useful, 70.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 70.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 70.14 +# Lesser General Public License for more details. 70.15 +# 70.16 +# You should have received a copy of the GNU Lesser General Public 70.17 +# License along with this library; if not, write to the Free Software 70.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 70.19 +# 70.20 + 70.21 + 70.22 +set -e 70.23 + 70.24 + 70.25 +evalVariables() 70.26 +{ 70.27 + for arg in "$@" 70.28 + do 70.29 + if expr 'index' "$arg" '=' '>' '1' >/dev/null 70.30 + then 70.31 + eval "$arg" 70.32 + fi 70.33 + done 70.34 +} 70.35 + 70.36 + 70.37 +findCommand() 70.38 +{ 70.39 + for arg in "$@" 70.40 + do 70.41 + if ! expr 'index' "$arg" '=' >/dev/null 70.42 + then 70.43 + command="$arg" 70.44 + return 70.45 + fi 70.46 + done 70.47 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 71.2 +++ b/tools/hotplug/Makefile Tue Nov 25 14:21:24 2008 +0900 71.3 @@ -0,0 +1,9 @@ 71.4 +XEN_ROOT = ../../ 71.5 +include $(XEN_ROOT)/tools/Rules.mk 71.6 + 71.7 +SUBDIRS-y := common 71.8 +SUBDIRS-$(CONFIG_NetBSD) += NetBSD 71.9 +SUBDIRS-$(CONFIG_Linux) += Linux 71.10 + 71.11 +.PHONY: all clean install 71.12 +all clean install: %: subdirs-%
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 72.2 +++ b/tools/hotplug/NetBSD/Makefile Tue Nov 25 14:21:24 2008 +0900 72.3 @@ -0,0 +1,41 @@ 72.4 +XEN_ROOT = ../../../ 72.5 +include $(XEN_ROOT)/tools/Rules.mk 72.6 + 72.7 +# Xen configuration dir and configs to go there. 72.8 +XEN_CONFIG_DIR = $(PREFIX)/etc/xen 72.9 + 72.10 +# Xen script dir and scripts to go there. 72.11 +XEN_SCRIPT_DIR = $(PREFIX)/etc/xen/scripts 72.12 +XEN_SCRIPTS = 72.13 +XEN_SCRIPTS += block-nbsd 72.14 +XEN_SCRIPTS += hvm-nbsd 72.15 +XEN_SCRIPTS += netbsd1-nbsd 72.16 +XEN_SCRIPTS += qemu-ifup-nbsd 72.17 +XEN_SCRIPTS += vif-bridge-nbsd 72.18 +XEN_SCRIPTS += vif-ip-nbsd 72.19 + 72.20 +XEN_SCRIPT_DATA = 72.21 + 72.22 +.PHONY: all 72.23 +all: 72.24 + 72.25 +.PHONY: build 72.26 +build: 72.27 + 72.28 +.PHONY: install 72.29 +install: all install-scripts 72.30 + 72.31 +.PHONY: install-scripts 72.32 +install-scripts: 72.33 + $(INSTALL_DATA_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR) 72.34 + set -e; for i in $(XEN_SCRIPTS); \ 72.35 + do \ 72.36 + $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 72.37 + done 72.38 + set -e; for i in $(XEN_SCRIPT_DATA); \ 72.39 + do \ 72.40 + $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 72.41 + done 72.42 + 72.43 +.PHONY: clean 72.44 +clean:
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/tools/hotplug/NetBSD/block-nbsd Tue Nov 25 14:21:24 2008 +0900 73.3 @@ -0,0 +1,88 @@ 73.4 +#!/bin/sh -e 73.5 + 73.6 +# $NetBSD: block-nbsd,v 1.1.1.1 2008/08/07 20:26:57 cegger Exp $ 73.7 +# Called by xenbackendd 73.8 +# Usage: block xsdir_backend_path state 73.9 + 73.10 +PATH=/bin:/usr/bin:/sbin:/usr/sbin 73.11 +export PATH 73.12 + 73.13 +error() { 73.14 + echo "$@" >&2 73.15 + xenstore_write $xpath/hotplug-status error 73.16 + exit 1 73.17 +} 73.18 + 73.19 + 73.20 +xpath=$1 73.21 +xstatus=$2 73.22 +xtype=$(xenstore-read "$xpath/type") 73.23 +xparams=$(xenstore-read "$xpath/params") 73.24 + 73.25 +case $xstatus in 73.26 +6) 73.27 + # device removed 73.28 + case $xtype in 73.29 + file) 73.30 + vnd=$(xenstore-read "$xpath/vnd" || echo none) 73.31 + if [ $vnd != none ]; then 73.32 + vnconfig -u $vnd 73.33 + fi 73.34 + ;; 73.35 + phy) 73.36 + ;; 73.37 + *) 73.38 + echo "unknown type $xtype" >&2 73.39 + ;; 73.40 + esac 73.41 + xenstore-rm $xpath 73.42 + exit 0 73.43 + ;; 73.44 +2) 73.45 + case $xtype in 73.46 + file) 73.47 + # Store the list of available vnd(4) devices in 73.48 + #``available_disks'', and mark them as ``free''. 73.49 + list=`ls -1 /dev/vnd[0-9]*d | sed "s,/dev/vnd,,;s,d,," | sort -n` 73.50 + for i in $list; do 73.51 + disk="vnd$i" 73.52 + available_disks="$available_disks $disk" 73.53 + eval $disk=free 73.54 + done 73.55 + # Mark the used vnd(4) devices as ``used''. 73.56 + for disk in `sysctl hw.disknames`; do 73.57 + case $disk in 73.58 + vnd[0-9]*) eval $disk=used ;; 73.59 + esac 73.60 + done 73.61 + # Configure the first free vnd(4) device. 73.62 + for disk in $available_disks; do 73.63 + eval status=\$$disk 73.64 + if [ "$status" = "free" ] && \ 73.65 + vnconfig /dev/${disk}d $xparams >/dev/null; then 73.66 + device=/dev/${disk}d 73.67 + echo vnconfig /dev/${disk}d $xparams 73.68 + break 73.69 + fi 73.70 + done 73.71 + if [ x$device = x ] ; then 73.72 + error "no available vnd device" 73.73 + fi 73.74 + echo xenstore-write $xpath/vnd $device 73.75 + xenstore-write $xpath/vnd $device 73.76 + ;; 73.77 + phy) 73.78 + device=$xparams 73.79 + ;; 73.80 + esac 73.81 + physical_device=$(stat -f '%r' "$device") 73.82 + echo xenstore-write $xpath/physical-device $physical_device 73.83 + xenstore-write $xpath/physical-device $physical_device 73.84 + echo xenstore-write $xpath/hotplug-status connected 73.85 + xenstore-write $xpath/hotplug-status connected 73.86 + exit 0 73.87 + ;; 73.88 +*) 73.89 + exit 0 73.90 + ;; 73.91 +esac
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 74.2 +++ b/tools/hotplug/NetBSD/qemu-ifup-nbsd Tue Nov 25 14:21:24 2008 +0900 74.3 @@ -0,0 +1,3 @@ 74.4 +#!/bin/sh 74.5 +ifconfig $1 up 74.6 +exec /sbin/brconfig $2 add $1
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/tools/hotplug/NetBSD/vif-bridge-nbsd Tue Nov 25 14:21:24 2008 +0900 75.3 @@ -0,0 +1,35 @@ 75.4 +#!/bin/sh -e 75.5 + 75.6 +# $NetBSD: vif-bridge-nbsd,v 1.1.1.1 2008/08/07 20:26:57 cegger Exp $ 75.7 +# Called by xenbackendd 75.8 +# Usage: vif-bridge xsdir_backend_path state 75.9 + 75.10 +PATH=/bin:/usr/bin:/sbin:/usr/sbin 75.11 +export PATH 75.12 + 75.13 +xpath=$1 75.14 +xstatus=$2 75.15 + 75.16 +case $xstatus in 75.17 +6) 75.18 + # device removed 75.19 + xenstore-rm $xpath 75.20 + exit 0 75.21 + ;; 75.22 +2) 75.23 + xbridge=$(xenstore-read "$xpath/bridge") 75.24 + xfid=$(xenstore-read "$xpath/frontend-id") 75.25 + xhandle=$(xenstore-read "$xpath/handle") 75.26 + iface=xvif$xfid.$xhandle 75.27 + echo ifconfig $iface up 75.28 + ifconfig $iface up 75.29 + brconfig $xbridge add $iface 75.30 + echo brconfig $xbridge add $iface 75.31 + xenstore-write $xpath/hotplug-status connected 75.32 + echo xenstore-write $xpath/hotplug-status connected 75.33 + exit 0 75.34 + ;; 75.35 +*) 75.36 + exit 0 75.37 + ;; 75.38 +esac
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/tools/hotplug/NetBSD/vif-ip-nbsd Tue Nov 25 14:21:24 2008 +0900 76.3 @@ -0,0 +1,33 @@ 76.4 +#!/bin/sh -e 76.5 + 76.6 +# $NetBSD: vif-ip-nbsd,v 1.1.1.1 2008/08/07 20:26:57 cegger Exp $ 76.7 +# Called by xenbackendd 76.8 +# Usage: vif-ip xsdir_backend_path state 76.9 + 76.10 +PATH=/bin:/usr/bin:/sbin:/usr/sbin 76.11 +export PATH 76.12 + 76.13 +xpath=$1 76.14 +xstatus=$2 76.15 + 76.16 +case $xstatus in 76.17 +6) 76.18 + # device removed 76.19 + xenstore-rm $xpath 76.20 + exit 0 76.21 + ;; 76.22 +2) 76.23 + xip=$(xenstore-read "$xpath/ip") 76.24 + xfid=$(xenstore-read "$xpath/frontend-id") 76.25 + xhandle=$(xenstore-read "$xpath/handle") 76.26 + iface=xvif$xfid.$xhandle 76.27 + echo ifconfig $iface $xip up 76.28 + ifconfig $iface $xip up 76.29 + xenstore-write $xpath/hotplug-status connected 76.30 + echo xenstore-write $xpath/hotplug-status connected 76.31 + exit 0 76.32 + ;; 76.33 +*) 76.34 + exit 0 76.35 + ;; 76.36 +esac
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/tools/hotplug/common/Makefile Tue Nov 25 14:21:24 2008 +0900 77.3 @@ -0,0 +1,37 @@ 77.4 +XEN_ROOT = ../../../ 77.5 +include $(XEN_ROOT)/tools/Rules.mk 77.6 + 77.7 +# OS-independent hotplug scripts go in this directory 77.8 + 77.9 +# Xen configuration dir and configs to go there. 77.10 +XEN_CONFIG_DIR = /etc/xen 77.11 + 77.12 +# Xen script dir and scripts to go there. 77.13 +XEN_SCRIPT_DIR = /etc/xen/scripts 77.14 +XEN_SCRIPTS = 77.15 +XEN_SCRIPT_DATA = 77.16 + 77.17 +.PHONY: all 77.18 +all: 77.19 + 77.20 +.PHONY: build 77.21 +build: 77.22 + 77.23 +.PHONY: install 77.24 +install: all install-scripts 77.25 + 77.26 +.PHONY: install-scripts 77.27 +install-scripts: 77.28 + [ -d $(DESTDIR)$(XEN_SCRIPT_DIR) ] || \ 77.29 + $(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR) 77.30 + set -e; for i in $(XEN_SCRIPTS); \ 77.31 + do \ 77.32 + $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 77.33 + done 77.34 + set -e; for i in $(XEN_SCRIPT_DATA); \ 77.35 + do \ 77.36 + $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \ 77.37 + done 77.38 + 77.39 +.PHONY: clean 77.40 +clean:
78.1 --- a/tools/libxc/xc_cpufeature.h Tue Nov 18 10:55:51 2008 +0100 78.2 +++ b/tools/libxc/xc_cpufeature.h Tue Nov 25 14:21:24 2008 +0900 78.3 @@ -83,6 +83,7 @@ 78.4 #define X86_FEATURE_SSE4_1 (4*32+19) /* Streaming SIMD Extensions 4.1 */ 78.5 #define X86_FEATURE_SSE4_2 (4*32+20) /* Streaming SIMD Extensions 4.2 */ 78.6 #define X86_FEATURE_POPCNT (4*32+23) /* POPCNT instruction */ 78.7 +#define X86_FEATURE_HYPERVISOR (4*32+31) /* Running under some hypervisor */ 78.8 78.9 /* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */ 78.10 #define X86_FEATURE_XSTORE (5*32+ 2) /* on-CPU RNG present (xstore insn) */
79.1 --- a/tools/libxc/xc_cpuid_x86.c Tue Nov 18 10:55:51 2008 +0100 79.2 +++ b/tools/libxc/xc_cpuid_x86.c Tue Nov 25 14:21:24 2008 +0900 79.3 @@ -194,6 +194,8 @@ static void xc_cpuid_hvm_policy( 79.4 bitmaskof(X86_FEATURE_SSE4_2) | 79.5 bitmaskof(X86_FEATURE_POPCNT)); 79.6 79.7 + regs[2] |= bitmaskof(X86_FEATURE_HYPERVISOR); 79.8 + 79.9 regs[3] &= (bitmaskof(X86_FEATURE_FPU) | 79.10 bitmaskof(X86_FEATURE_VME) | 79.11 bitmaskof(X86_FEATURE_DE) | 79.12 @@ -309,6 +311,7 @@ static void xc_cpuid_pv_policy( 79.13 clear_bit(X86_FEATURE_XTPR, regs[2]); 79.14 clear_bit(X86_FEATURE_PDCM, regs[2]); 79.15 clear_bit(X86_FEATURE_DCA, regs[2]); 79.16 + set_bit(X86_FEATURE_HYPERVISOR, regs[2]); 79.17 break; 79.18 case 0x80000001: 79.19 if ( !guest_64bit )
80.1 --- a/tools/misc/xenpm.c Tue Nov 18 10:55:51 2008 +0100 80.2 +++ b/tools/misc/xenpm.c Tue Nov 25 14:21:24 2008 +0900 80.3 @@ -170,7 +170,7 @@ int main(int argc, char **argv) 80.4 if ( !pxstat->pt ) 80.5 { 80.6 fprintf(stderr, "failed to malloc for P-states table\n"); 80.7 - free(pxstat->pt); 80.8 + free(pxstat->trans_pt); 80.9 break; 80.10 } 80.11
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 81.2 +++ b/tools/python/xen/util/rwlock.py Tue Nov 25 14:21:24 2008 +0900 81.3 @@ -0,0 +1,137 @@ 81.4 +""" Reader-writer lock implementation based on a condition variable """ 81.5 + 81.6 +#============================================================================ 81.7 +# This library is free software; you can redistribute it and/or 81.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 81.9 +# License as published by the Free Software Foundation. 81.10 +# 81.11 +# This library is distributed in the hope that it will be useful, 81.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 81.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 81.14 +# Lesser General Public License for more details. 81.15 +# 81.16 +# You should have received a copy of the GNU Lesser General Public 81.17 +# License along with this library; if not, write to the Free Software 81.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 81.19 +#============================================================================ 81.20 +# Copyright (C) 2008 International Business Machines Corp. 81.21 +# Author: Stefan Berger <stefanb@us.ibm.com> 81.22 +#============================================================================ 81.23 + 81.24 +from threading import Condition 81.25 + 81.26 +class RWLock: 81.27 + 81.28 + RWLOCK_STATE_WRITER = -1 81.29 + RWLOCK_STATE_UNUSED = 0 81.30 + 81.31 + def __init__(self): 81.32 + self.__condition = Condition() 81.33 + self.__state = RWLock.RWLOCK_STATE_UNUSED 81.34 + self.__blocked_writers = 0 81.35 + 81.36 + def acquire_reader(self): 81.37 + self.__condition.acquire() 81.38 + while True: 81.39 + if self.__state == RWLock.RWLOCK_STATE_WRITER: 81.40 + self.__condition.wait() 81.41 + else: 81.42 + break 81.43 + self.__state += 1 81.44 + self.__condition.release() 81.45 + 81.46 + def acquire_writer(self): 81.47 + self.__condition.acquire() 81.48 + self.__acquire_writer(RWLock.RWLOCK_STATE_UNUSED) 81.49 + self.__condition.release() 81.50 + 81.51 + def __acquire_writer(self, wait_for_state): 81.52 + while True: 81.53 + if self.__state == wait_for_state: 81.54 + self.__state = RWLock.RWLOCK_STATE_WRITER 81.55 + break 81.56 + else: 81.57 + self.__blocked_writers += 1 81.58 + self.__condition.wait() 81.59 + self.__blocked_writers -= 1 81.60 + 81.61 + def release(self): 81.62 + self.__condition.acquire() 81.63 + if self.__state == RWLock.RWLOCK_STATE_WRITER: 81.64 + self.__state = RWLock.RWLOCK_STATE_UNUSED 81.65 + elif self.__state == RWLock.RWLOCK_STATE_UNUSED: 81.66 + assert False, 'Lock not in use.' 81.67 + else: 81.68 + self.__state -= 1 81.69 + self.__condition.notifyAll() 81.70 + self.__condition.release() 81.71 + 81.72 + 81.73 +if __name__ == '__main__': 81.74 + from threading import Thread 81.75 + from time import sleep 81.76 + 81.77 + rwlock = RWLock() 81.78 + 81.79 + class Base(Thread): 81.80 + def __init__(self, name, timeout): 81.81 + self.name = name 81.82 + self.timeout = timeout 81.83 + Thread.__init__(self) 81.84 + 81.85 + class Reader(Base): 81.86 + def __init__(self, name = 'Reader', timeout = 10): 81.87 + Base.__init__(self, name, timeout) 81.88 + 81.89 + def run(self): 81.90 + print '%s begin' % self.name 81.91 + rwlock.acquire_reader() 81.92 + print '%s acquired' % self.name 81.93 + sleep(self.timeout) 81.94 + rwlock.release() 81.95 + print '%s end' % self.name 81.96 + 81.97 + class ReaderTwice(Base): 81.98 + def __init__(self, name = 'Reader', timeout = 10): 81.99 + Base.__init__(self, name, timeout) 81.100 + 81.101 + def run(self): 81.102 + print '%s begin' % self.name 81.103 + rwlock.acquire_reader() 81.104 + print '%s acquired once' % self.name 81.105 + sleep(self.timeout) 81.106 + rwlock.acquire_reader() 81.107 + print '%s acquired twice' % self.name 81.108 + sleep(self.timeout) 81.109 + rwlock.release() 81.110 + rwlock.release() 81.111 + print '%s end' % self.name 81.112 + 81.113 + class Writer(Base): 81.114 + def __init__(self, name = 'Writer', timeout = 10): 81.115 + Base.__init__(self, name, timeout) 81.116 + 81.117 + def run(self): 81.118 + print '%s begin' % self.name 81.119 + rwlock.acquire_writer() 81.120 + print '%s acquired' % self.name 81.121 + sleep(self.timeout) 81.122 + rwlock.release() 81.123 + print '%s end' % self.name 81.124 + 81.125 + def run_test(threadlist, msg): 81.126 + print msg 81.127 + for t in threadlist: 81.128 + t.start() 81.129 + sleep(1) 81.130 + for t in threads: 81.131 + t.join() 81.132 + print 'Done\n\n' 81.133 + 81.134 + threads = [] 81.135 + threads.append( Reader('R1', 4) ) 81.136 + threads.append( Reader('R2', 4) ) 81.137 + threads.append( Writer('W1', 4) ) 81.138 + threads.append( Reader('R3', 4) ) 81.139 + run_test(threads, 81.140 + 'Test: readers may bypass blocked writers')
82.1 --- a/tools/python/xen/xend/XendAPI.py Tue Nov 18 10:55:51 2008 +0100 82.2 +++ b/tools/python/xen/xend/XendAPI.py Tue Nov 25 14:21:24 2008 +0900 82.3 @@ -431,7 +431,7 @@ def valid_object(class_name): 82.4 lambda *args, **kwargs: \ 82.5 _check_ref(lambda r: \ 82.6 XendAPIStore.get(r, class_name) is not None, 82.7 - 'PIF', func, *args, **kwargs) 82.8 + class_name, func, *args, **kwargs) 82.9 82.10 # ----------------------------- 82.11 # Bridge to Legacy XM API calls
83.1 --- a/tools/python/xen/xend/XendConfig.py Tue Nov 18 10:55:51 2008 +0100 83.2 +++ b/tools/python/xen/xend/XendConfig.py Tue Nov 25 14:21:24 2008 +0900 83.3 @@ -1032,8 +1032,6 @@ class XendConfig(dict): 83.4 sxpr.append([name, s]) 83.5 83.6 for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items(): 83.7 - if legacy in ('cpus'): # skip this 83.8 - continue 83.9 if self.has_key(xenapi) and self[xenapi] not in (None, []): 83.10 if type(self[xenapi]) == bool: 83.11 # convert booleans to ints before making an sxp item
84.1 --- a/tools/python/xen/xend/XendDomain.py Tue Nov 18 10:55:51 2008 +0100 84.2 +++ b/tools/python/xen/xend/XendDomain.py Tue Nov 25 14:21:24 2008 +0900 84.3 @@ -50,7 +50,7 @@ from xen.xend.XendAPIConstants import * 84.4 84.5 from xen.xend.xenstore.xstransact import xstransact 84.6 from xen.xend.xenstore.xswatch import xswatch 84.7 -from xen.util import mkdir 84.8 +from xen.util import mkdir, rwlock 84.9 from xen.xend import uuid 84.10 84.11 xc = xen.lowlevel.xc.xc() 84.12 @@ -93,6 +93,8 @@ class XendDomain: 84.13 self.managed_domains = {} 84.14 self.domains_lock = threading.RLock() 84.15 84.16 + self.policy_lock = rwlock.RWLock() 84.17 + 84.18 # xen api instance vars 84.19 # TODO: nothing uses this at the moment 84.20 self._allow_new_domains = True 84.21 @@ -1139,16 +1141,21 @@ class XendDomain: 84.22 """ 84.23 84.24 try: 84.25 - return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating) 84.26 - except XendError, e: 84.27 - log.exception("Restore failed") 84.28 - raise 84.29 - except: 84.30 - # I don't really want to log this exception here, but the error 84.31 - # handling in the relocation-socket handling code (relocate.py) is 84.32 - # poor, so we need to log this for debugging. 84.33 - log.exception("Restore failed") 84.34 - raise XendError("Restore failed") 84.35 + self.policy_lock.acquire_reader() 84.36 + 84.37 + try: 84.38 + return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating) 84.39 + except XendError, e: 84.40 + log.exception("Restore failed") 84.41 + raise 84.42 + except: 84.43 + # I don't really want to log this exception here, but the error 84.44 + # handling in the relocation-socket handling code (relocate.py) is 84.45 + # poor, so we need to log this for debugging. 84.46 + log.exception("Restore failed") 84.47 + raise XendError("Restore failed") 84.48 + finally: 84.49 + self.policy_lock.release() 84.50 84.51 def domain_unpause(self, domid): 84.52 """Unpause domain execution.
85.1 --- a/tools/python/xen/xend/XendDomainInfo.py Tue Nov 18 10:55:51 2008 +0100 85.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Tue Nov 25 14:21:24 2008 +0900 85.3 @@ -479,6 +479,14 @@ class XendDomainInfo: 85.4 if state in (DOM_STATE_SUSPENDED, DOM_STATE_HALTED): 85.5 try: 85.6 self._constructDomain() 85.7 + 85.8 + try: 85.9 + self._setCPUAffinity() 85.10 + except: 85.11 + # usually a CPU we want to set affinity to does not exist 85.12 + # we just ignore it so that the domain can still be restored 85.13 + log.warn("Cannot restore CPU affinity") 85.14 + 85.15 self._storeVmDetails() 85.16 self._createChannels() 85.17 self._createDevices() 85.18 @@ -2166,6 +2174,64 @@ class XendDomainInfo: 85.19 raise XendError(str(exn)) 85.20 85.21 85.22 + def _setCPUAffinity(self): 85.23 + """ Repin domain vcpus if a restricted cpus list is provided 85.24 + """ 85.25 + 85.26 + def has_cpus(): 85.27 + if self.info['cpus'] is not None: 85.28 + for c in self.info['cpus']: 85.29 + if c: 85.30 + return True 85.31 + return False 85.32 + 85.33 + if has_cpus(): 85.34 + for v in range(0, self.info['VCPUs_max']): 85.35 + if self.info['cpus'][v]: 85.36 + xc.vcpu_setaffinity(self.domid, v, self.info['cpus'][v]) 85.37 + else: 85.38 + def find_relaxed_node(node_list): 85.39 + import sys 85.40 + nr_nodes = info['nr_nodes'] 85.41 + if node_list is None: 85.42 + node_list = range(0, nr_nodes) 85.43 + nodeload = [0] 85.44 + nodeload = nodeload * nr_nodes 85.45 + from xen.xend import XendDomain 85.46 + doms = XendDomain.instance().list('all') 85.47 + for dom in filter (lambda d: d.domid != self.domid, doms): 85.48 + cpuinfo = dom.getVCPUInfo() 85.49 + for vcpu in sxp.children(cpuinfo, 'vcpu'): 85.50 + if sxp.child_value(vcpu, 'online') == 0: continue 85.51 + cpumap = list(sxp.child_value(vcpu,'cpumap')) 85.52 + for i in range(0, nr_nodes): 85.53 + node_cpumask = info['node_to_cpu'][i] 85.54 + for j in node_cpumask: 85.55 + if j in cpumap: 85.56 + nodeload[i] += 1 85.57 + break 85.58 + for i in range(0, nr_nodes): 85.59 + if len(info['node_to_cpu'][i]) > 0 and i in node_list: 85.60 + nodeload[i] = int(nodeload[i] * 16 / len(info['node_to_cpu'][i])) 85.61 + else: 85.62 + nodeload[i] = sys.maxint 85.63 + index = nodeload.index( min(nodeload) ) 85.64 + return index 85.65 + 85.66 + info = xc.physinfo() 85.67 + if info['nr_nodes'] > 1: 85.68 + node_memory_list = info['node_to_memory'] 85.69 + needmem = self.image.getRequiredAvailableMemory(self.info['memory_dynamic_max']) / 1024 85.70 + candidate_node_list = [] 85.71 + for i in range(0, info['nr_nodes']): 85.72 + if node_memory_list[i] >= needmem and len(info['node_to_cpu'][i]) > 0: 85.73 + candidate_node_list.append(i) 85.74 + index = find_relaxed_node(candidate_node_list) 85.75 + cpumask = info['node_to_cpu'][index] 85.76 + for v in range(0, self.info['VCPUs_max']): 85.77 + xc.vcpu_setaffinity(self.domid, v, cpumask) 85.78 + 85.79 + 85.80 def _initDomain(self): 85.81 log.debug('XendDomainInfo.initDomain: %s %s', 85.82 self.domid, 85.83 @@ -2185,58 +2251,7 @@ class XendDomainInfo: 85.84 # repin domain vcpus if a restricted cpus list is provided 85.85 # this is done prior to memory allocation to aide in memory 85.86 # distribution for NUMA systems. 85.87 - def has_cpus(): 85.88 - if self.info['cpus'] is not None: 85.89 - for c in self.info['cpus']: 85.90 - if c: 85.91 - return True 85.92 - return False 85.93 - 85.94 - if has_cpus(): 85.95 - for v in range(0, self.info['VCPUs_max']): 85.96 - if self.info['cpus'][v]: 85.97 - xc.vcpu_setaffinity(self.domid, v, self.info['cpus'][v]) 85.98 - else: 85.99 - def find_relaxed_node(node_list): 85.100 - import sys 85.101 - nr_nodes = info['nr_nodes'] 85.102 - if node_list is None: 85.103 - node_list = range(0, nr_nodes) 85.104 - nodeload = [0] 85.105 - nodeload = nodeload * nr_nodes 85.106 - from xen.xend import XendDomain 85.107 - doms = XendDomain.instance().list('all') 85.108 - for dom in filter (lambda d: d.domid != self.domid, doms): 85.109 - cpuinfo = dom.getVCPUInfo() 85.110 - for vcpu in sxp.children(cpuinfo, 'vcpu'): 85.111 - if sxp.child_value(vcpu, 'online') == 0: continue 85.112 - cpumap = list(sxp.child_value(vcpu,'cpumap')) 85.113 - for i in range(0, nr_nodes): 85.114 - node_cpumask = info['node_to_cpu'][i] 85.115 - for j in node_cpumask: 85.116 - if j in cpumap: 85.117 - nodeload[i] += 1 85.118 - break 85.119 - for i in range(0, nr_nodes): 85.120 - if len(info['node_to_cpu'][i]) > 0 and i in node_list: 85.121 - nodeload[i] = int(nodeload[i] * 16 / len(info['node_to_cpu'][i])) 85.122 - else: 85.123 - nodeload[i] = sys.maxint 85.124 - index = nodeload.index( min(nodeload) ) 85.125 - return index 85.126 - 85.127 - info = xc.physinfo() 85.128 - if info['nr_nodes'] > 1: 85.129 - node_memory_list = info['node_to_memory'] 85.130 - needmem = self.image.getRequiredAvailableMemory(self.info['memory_dynamic_max']) / 1024 85.131 - candidate_node_list = [] 85.132 - for i in range(0, info['nr_nodes']): 85.133 - if node_memory_list[i] >= needmem and len(info['node_to_cpu'][i]) > 0: 85.134 - candidate_node_list.append(i) 85.135 - index = find_relaxed_node(candidate_node_list) 85.136 - cpumask = info['node_to_cpu'][index] 85.137 - for v in range(0, self.info['VCPUs_max']): 85.138 - xc.vcpu_setaffinity(self.domid, v, cpumask) 85.139 + self._setCPUAffinity() 85.140 85.141 # Use architecture- and image-specific calculations to determine 85.142 # the various headrooms necessary, given the raw configured 85.143 @@ -3011,64 +3026,69 @@ class XendDomainInfo: 85.144 if not xspol: 85.145 xspol = poladmin.get_policy_by_name(policy) 85.146 85.147 - if state in [ DOM_STATE_RUNNING, DOM_STATE_PAUSED ]: 85.148 - #if domain is running or paused try to relabel in hypervisor 85.149 - if not xspol: 85.150 - return (-xsconstants.XSERR_POLICY_NOT_LOADED, "", "", 0) 85.151 - 85.152 - if typ != xspol.get_type_name() or \ 85.153 - policy != xspol.get_name(): 85.154 - return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.155 - 85.156 - if typ == xsconstants.ACM_POLICY_ID: 85.157 - new_ssidref = xspol.vmlabel_to_ssidref(label) 85.158 - if new_ssidref == xsconstants.INVALID_SSIDREF: 85.159 + try: 85.160 + xen.xend.XendDomain.instance().policy_lock.acquire_writer() 85.161 + 85.162 + if state in [ DOM_STATE_RUNNING, DOM_STATE_PAUSED ]: 85.163 + #if domain is running or paused try to relabel in hypervisor 85.164 + if not xspol: 85.165 + return (-xsconstants.XSERR_POLICY_NOT_LOADED, "", "", 0) 85.166 + 85.167 + if typ != xspol.get_type_name() or \ 85.168 + policy != xspol.get_name(): 85.169 return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.170 85.171 - # Check that all used resources are accessible under the 85.172 - # new label 85.173 - if not is_policy_update and \ 85.174 - not security.resources_compatible_with_vmlabel(xspol, 85.175 - self, label): 85.176 - return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.177 - 85.178 - #Check label against expected one. Can only do this 85.179 - # if the policy hasn't changed underneath in the meantime 85.180 - if xspol_old == None: 85.181 - old_label = self.get_security_label() 85.182 - if old_label != old_seclab: 85.183 - log.info("old_label != old_seclab: %s != %s" % 85.184 - (old_label, old_seclab)) 85.185 + if typ == xsconstants.ACM_POLICY_ID: 85.186 + new_ssidref = xspol.vmlabel_to_ssidref(label) 85.187 + if new_ssidref == xsconstants.INVALID_SSIDREF: 85.188 + return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.189 + 85.190 + # Check that all used resources are accessible under the 85.191 + # new label 85.192 + if not is_policy_update and \ 85.193 + not security.resources_compatible_with_vmlabel(xspol, 85.194 + self, label): 85.195 return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.196 85.197 - # relabel domain in the hypervisor 85.198 - rc, errors = security.relabel_domains([[domid, new_ssidref]]) 85.199 - log.info("rc from relabeling in HV: %d" % rc) 85.200 - else: 85.201 - return (-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED, "", "", 0) 85.202 - 85.203 - if rc == 0: 85.204 - # HALTED, RUNNING or PAUSED 85.205 - if domid == 0: 85.206 - if xspol: 85.207 - self.info['security_label'] = seclab 85.208 - ssidref = poladmin.set_domain0_bootlabel(xspol, label) 85.209 + #Check label against expected one. Can only do this 85.210 + # if the policy hasn't changed underneath in the meantime 85.211 + if xspol_old == None: 85.212 + old_label = self.get_security_label() 85.213 + if old_label != old_seclab: 85.214 + log.info("old_label != old_seclab: %s != %s" % 85.215 + (old_label, old_seclab)) 85.216 + return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.217 + 85.218 + # relabel domain in the hypervisor 85.219 + rc, errors = security.relabel_domains([[domid, new_ssidref]]) 85.220 + log.info("rc from relabeling in HV: %d" % rc) 85.221 else: 85.222 - return (-xsconstants.XSERR_POLICY_NOT_LOADED, "", "", 0) 85.223 - else: 85.224 - if self.info.has_key('security_label'): 85.225 - old_label = self.info['security_label'] 85.226 - # Check label against expected one, unless wildcard 85.227 - if old_label != old_seclab: 85.228 - return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.229 - 85.230 - self.info['security_label'] = seclab 85.231 - 85.232 - try: 85.233 - xen.xend.XendDomain.instance().managed_config_save(self) 85.234 - except: 85.235 - pass 85.236 - return (rc, errors, old_label, new_ssidref) 85.237 + return (-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED, "", "", 0) 85.238 + 85.239 + if rc == 0: 85.240 + # HALTED, RUNNING or PAUSED 85.241 + if domid == 0: 85.242 + if xspol: 85.243 + self.info['security_label'] = seclab 85.244 + ssidref = poladmin.set_domain0_bootlabel(xspol, label) 85.245 + else: 85.246 + return (-xsconstants.XSERR_POLICY_NOT_LOADED, "", "", 0) 85.247 + else: 85.248 + if self.info.has_key('security_label'): 85.249 + old_label = self.info['security_label'] 85.250 + # Check label against expected one, unless wildcard 85.251 + if old_label != old_seclab: 85.252 + return (-xsconstants.XSERR_BAD_LABEL, "", "", 0) 85.253 + 85.254 + self.info['security_label'] = seclab 85.255 + 85.256 + try: 85.257 + xen.xend.XendDomain.instance().managed_config_save(self) 85.258 + except: 85.259 + pass 85.260 + return (rc, errors, old_label, new_ssidref) 85.261 + finally: 85.262 + xen.xend.XendDomain.instance().policy_lock.release() 85.263 85.264 def get_on_shutdown(self): 85.265 after_shutdown = self.info.get('actions_after_shutdown')
86.1 --- a/tools/python/xen/xend/osdep.py Tue Nov 18 10:55:51 2008 +0100 86.2 +++ b/tools/python/xen/xend/osdep.py Tue Nov 25 14:21:24 2008 +0900 86.3 @@ -38,7 +38,10 @@ import os 86.4 "SunOS": "vif-vnic" 86.5 } 86.6 86.7 -def _linux_balloon_stat(label): 86.8 +PROC_XEN_BALLOON = '/proc/xen/balloon' 86.9 +SYSFS_XEN_MEMORY = '/sys/devices/system/xen_memory/xen_memory0' 86.10 + 86.11 +def _linux_balloon_stat_proc(label): 86.12 """Returns the value for the named label, or None if an error occurs.""" 86.13 86.14 xend2linux_labels = { 'current' : 'Current allocation', 86.15 @@ -47,7 +50,6 @@ def _linux_balloon_stat(label): 86.16 'high-balloon' : 'High-mem balloon', 86.17 'limit' : 'Xen hard limit' } 86.18 86.19 - PROC_XEN_BALLOON = '/proc/xen/balloon' 86.20 f = file(PROC_XEN_BALLOON, 'r') 86.21 try: 86.22 for line in f: 86.23 @@ -62,6 +64,29 @@ def _linux_balloon_stat(label): 86.24 finally: 86.25 f.close() 86.26 86.27 +def _linux_balloon_stat_sysfs(label): 86.28 + sysfiles = { 'target' : 'target_kb', 86.29 + 'current' : 'info/current_kb', 86.30 + 'low-balloon' : 'info/low_kb', 86.31 + 'high-balloon' : 'info/high_kb', 86.32 + 'limit' : 'info/hard_limit_kb' } 86.33 + 86.34 + name = os.path.join(SYSFS_XEN_MEMORY, sysfiles[label]) 86.35 + f = file(name, 'r') 86.36 + 86.37 + val = f.read().strip() 86.38 + if val.isdigit(): 86.39 + return int(val) 86.40 + return None 86.41 + 86.42 +def _linux_balloon_stat(label): 86.43 + if os.access(PROC_XEN_BALLOON, os.F_OK): 86.44 + return _linux_balloon_stat_proc(label) 86.45 + elif os.access(SYSFS_XEN_MEMORY, os.F_OK): 86.46 + return _linux_balloon_stat_sysfs(label) 86.47 + 86.48 + return None 86.49 + 86.50 def _solaris_balloon_stat(label): 86.51 """Returns the value for the named label, or None if an error occurs.""" 86.52
87.1 --- a/tools/python/xen/xend/server/pciif.py Tue Nov 18 10:55:51 2008 +0100 87.2 +++ b/tools/python/xen/xend/server/pciif.py Tue Nov 25 14:21:24 2008 +0900 87.3 @@ -35,6 +35,8 @@ import resource 87.4 import re 87.5 87.6 from xen.xend.server.pciquirk import * 87.7 +from xen.xend.xenstore.xstransact import xstransact 87.8 +from xen.xend.xenstore.xswatch import xswatch 87.9 87.10 xc = xen.lowlevel.xc.xc() 87.11 87.12 @@ -58,6 +60,7 @@ def parse_hex(val): 87.13 class PciController(DevController): 87.14 87.15 def __init__(self, vm): 87.16 + self.aerStateWatch = None 87.17 DevController.__init__(self, vm) 87.18 87.19 87.20 @@ -333,12 +336,6 @@ class PciController(DevController): 87.21 if rc<0: 87.22 raise VmError(('pci: failed to configure I/O memory on device '+ 87.23 '%s - errno=%d')%(dev.name,rc)) 87.24 - rc = xc.physdev_map_pirq(domid = fe_domid, 87.25 - index = dev.irq, 87.26 - pirq = dev.irq) 87.27 - if rc < 0: 87.28 - raise VmError(('pci: failed to map irq on device '+ 87.29 - '%s - errno=%d')%(dev.name,rc)) 87.30 87.31 if dev.msix: 87.32 for (start, size) in dev.msix_iomem: 87.33 @@ -353,6 +350,12 @@ class PciController(DevController): 87.34 if rc<0: 87.35 raise VmError(('pci: failed to remove msi-x iomem')) 87.36 87.37 + rc = xc.physdev_map_pirq(domid = fe_domid, 87.38 + index = dev.irq, 87.39 + pirq = dev.irq) 87.40 + if rc < 0: 87.41 + raise VmError(('pci: failed to map irq on device '+ 87.42 + '%s - errno=%d')%(dev.name,rc)) 87.43 if dev.irq>0: 87.44 log.debug('pci: enabling irq %d'%dev.irq) 87.45 rc = xc.domain_irq_permission(domid = fe_domid, pirq = dev.irq, 87.46 @@ -431,8 +434,22 @@ class PciController(DevController): 87.47 87.48 for (domain, bus, slot, func) in pci_dev_list: 87.49 self.setupOneDevice(domain, bus, slot, func) 87.50 + wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid()) 87.51 + self.aerStatePath = xswatch(wPath, self._handleAerStateWatch) 87.52 + log.debug('pci: register aer watch %s', wPath) 87.53 + return 87.54 87.55 - return 87.56 + def _handleAerStateWatch(self, _): 87.57 + log.debug('XendDomainInfo.handleAerStateWatch') 87.58 + if self.getDomid() == 0: 87.59 + raise XendError('Domain 0 cannot be shutdown') 87.60 + readPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid()) 87.61 + action = xstransact.Read(readPath) 87.62 + if action and action=='aerfail': 87.63 + log.debug('shutdown domain because of aer handle error') 87.64 + self.vm.shutdown('poweroff') 87.65 + return True 87.66 + 87.67 87.68 def cleanupOneDevice(self, domain, bus, slot, func): 87.69 """ Detach I/O resources for device from frontend domain 87.70 @@ -545,6 +562,22 @@ class PciController(DevController): 87.71 87.72 return new_num_devs 87.73 87.74 + def destroyDevice(self, devid, force): 87.75 + DevController.destroyDevice(self, devid, True) 87.76 + log.debug('pci: unregister aer watch') 87.77 + self.unwatchAerState 87.78 + 87.79 + def unwatchAerState(self): 87.80 + """Remove the watch on the domain's aerState node, if any.""" 87.81 + try: 87.82 + try: 87.83 + if self.aerStateWatch: 87.84 + self.aerStateWatch.unwatch() 87.85 + finally: 87.86 + self.aerStateWatch = None 87.87 + except: 87.88 + log.exception("Unwatching aerState failed.") 87.89 + 87.90 def waitForBackend(self,devid): 87.91 return (0, "ok - no hotplug") 87.92
88.1 --- a/tools/python/xen/xm/create.py Tue Nov 18 10:55:51 2008 +0100 88.2 +++ b/tools/python/xen/xm/create.py Tue Nov 25 14:21:24 2008 +0900 88.3 @@ -1202,8 +1202,9 @@ def make_domain(opts, config): 88.4 except: 88.5 server.xend.domain.destroy(dom) 88.6 err("Failed to unpause domain %s" % dom) 88.7 - opts.info("Started domain %s" % (dom)) 88.8 - return int(sxp.child_value(dominfo, 'domid')) 88.9 + domid = int(sxp.child_value(dominfo, 'domid')) 88.10 + opts.info("Started domain %s (id=%d)" % (dom, domid)) 88.11 + return domid 88.12 88.13 88.14 def get_xauthority():
89.1 --- a/unmodified_drivers/linux-2.6/balloon/Kbuild Tue Nov 18 10:55:51 2008 +0100 89.2 +++ b/unmodified_drivers/linux-2.6/balloon/Kbuild Tue Nov 25 14:21:24 2008 +0900 89.3 @@ -4,6 +4,5 @@ obj-m = xen-balloon.o 89.4 89.5 EXTRA_CFLAGS += -I$(M)/platform-pci 89.6 89.7 -xen-balloon-objs = 89.8 -xen-balloon-objs += balloon.o 89.9 -xen-balloon-objs += sysfs.o 89.10 +xen-balloon-y := balloon.o sysfs.o 89.11 +xen-balloon-$(CONFIG_XEN_SCRUB_PAGES) += scrub.o
90.1 --- a/unmodified_drivers/linux-2.6/mkbuildtree Tue Nov 18 10:55:51 2008 +0100 90.2 +++ b/unmodified_drivers/linux-2.6/mkbuildtree Tue Nov 25 14:21:24 2008 +0900 90.3 @@ -53,6 +53,7 @@ i[34567]86|x86_64) 90.4 ln -sf ${XL}/include/asm-x86/mach-xen/asm/synch_bitops*.h include/asm 90.5 ln -sf ${XL}/include/asm-x86/mach-xen/asm/maddr*.h include/asm 90.6 ln -sf ${XL}/include/asm-x86/mach-xen/asm/gnttab_dma.h include/asm 90.7 + ln -sf ${XL}/arch/x86/lib/scrub.c balloon 90.8 else 90.9 if [ $uname = x86_64 ]; then 90.10 mkdir -p include/asm-i386
91.1 --- a/unmodified_drivers/linux-2.6/platform-pci/machine_reboot.c Tue Nov 18 10:55:51 2008 +0100 91.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/machine_reboot.c Tue Nov 25 14:21:24 2008 +0900 91.3 @@ -34,7 +34,11 @@ static void ap_suspend(void *_info) 91.4 atomic_dec(&info->nr_spinning); 91.5 } 91.6 91.7 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) 91.8 #define initiate_ap_suspend(i) smp_call_function(ap_suspend, i, 0, 0) 91.9 +#else 91.10 +#define initiate_ap_suspend(i) smp_call_function(ap_suspend, i, 0) 91.11 +#endif 91.12 91.13 #else /* !defined(CONFIG_SMP) */ 91.14
92.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-compat.c Tue Nov 18 10:55:51 2008 +0100 92.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-compat.c Tue Nov 25 14:21:24 2008 +0900 92.3 @@ -14,7 +14,11 @@ EXPORT_SYMBOL(system_state); 92.4 92.5 void ctrl_alt_del(void) 92.6 { 92.7 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) 92.8 kill_proc(1, SIGINT, 1); /* interrupt init */ 92.9 +#else 92.10 + kill_cad_pid(SIGINT, 1); 92.11 +#endif 92.12 } 92.13 92.14 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)
93.1 --- a/xen/Rules.mk Tue Nov 18 10:55:51 2008 +0100 93.2 +++ b/xen/Rules.mk Tue Nov 25 14:21:24 2008 +0900 93.3 @@ -69,6 +69,9 @@ CFLAGS-$(frame_pointer) += -fno-omit-fra 93.4 ifneq ($(max_phys_cpus),) 93.5 CFLAGS-y += -DMAX_PHYS_CPUS=$(max_phys_cpus) 93.6 endif 93.7 +ifneq ($(max_phys_irqs),) 93.8 +CFLAGS-y += -DMAX_PHYS_IRQS=$(max_phys_irqs) 93.9 +endif 93.10 93.11 AFLAGS-y += -D__ASSEMBLY__ 93.12
94.1 --- a/xen/arch/x86/Makefile Tue Nov 18 10:55:51 2008 +0100 94.2 +++ b/xen/arch/x86/Makefile Tue Nov 25 14:21:24 2008 +0900 94.3 @@ -11,6 +11,7 @@ subdir-$(x86_64) += x86_64 94.4 obj-y += apic.o 94.5 obj-y += bitops.o 94.6 obj-y += clear_page.o 94.7 +obj-y += copy_page.o 94.8 obj-y += compat.o 94.9 obj-y += delay.o 94.10 obj-y += dmi_scan.o
95.1 --- a/xen/arch/x86/acpi/boot.c Tue Nov 18 10:55:51 2008 +0100 95.2 +++ b/xen/arch/x86/acpi/boot.c Tue Nov 25 14:21:24 2008 +0900 95.3 @@ -601,7 +601,7 @@ static int __init acpi_parse_madt_ioapic 95.4 95.5 count = 95.6 acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 95.7 - NR_IRQ_VECTORS); 95.8 + MAX_IRQ_SOURCES); 95.9 if (count < 0) { 95.10 printk(KERN_ERR PREFIX 95.11 "Error parsing interrupt source overrides entry\n"); 95.12 @@ -623,7 +623,7 @@ static int __init acpi_parse_madt_ioapic 95.13 95.14 count = 95.15 acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 95.16 - NR_IRQ_VECTORS); 95.17 + MAX_IRQ_SOURCES); 95.18 if (count < 0) { 95.19 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n"); 95.20 /* TBD: Cleanup to allow fallback to MPS */
96.1 --- a/xen/arch/x86/acpi/power.c Tue Nov 18 10:55:51 2008 +0100 96.2 +++ b/xen/arch/x86/acpi/power.c Tue Nov 25 14:21:24 2008 +0900 96.3 @@ -30,6 +30,8 @@ 96.4 96.5 #include <acpi/cpufreq/cpufreq.h> 96.6 96.7 +uint32_t system_reset_counter = 1; 96.8 + 96.9 static char opt_acpi_sleep[20]; 96.10 string_param("acpi_sleep", opt_acpi_sleep); 96.11 96.12 @@ -75,19 +77,47 @@ static void device_power_up(void) 96.13 static void freeze_domains(void) 96.14 { 96.15 struct domain *d; 96.16 + struct vcpu *v; 96.17 96.18 + rcu_read_lock(&domlist_read_lock); 96.19 for_each_domain ( d ) 96.20 - if ( d->domain_id != 0 ) 96.21 + { 96.22 + switch ( d->domain_id ) 96.23 + { 96.24 + case 0: 96.25 + for_each_vcpu ( d, v ) 96.26 + if ( v != current ) 96.27 + vcpu_pause(v); 96.28 + break; 96.29 + default: 96.30 domain_pause(d); 96.31 + break; 96.32 + } 96.33 + } 96.34 + rcu_read_unlock(&domlist_read_lock); 96.35 } 96.36 96.37 static void thaw_domains(void) 96.38 { 96.39 struct domain *d; 96.40 + struct vcpu *v; 96.41 96.42 + rcu_read_lock(&domlist_read_lock); 96.43 for_each_domain ( d ) 96.44 - if ( d->domain_id != 0 ) 96.45 + { 96.46 + switch ( d->domain_id ) 96.47 + { 96.48 + case 0: 96.49 + for_each_vcpu ( d, v ) 96.50 + if ( v != current ) 96.51 + vcpu_unpause(v); 96.52 + break; 96.53 + default: 96.54 domain_unpause(d); 96.55 + break; 96.56 + } 96.57 + } 96.58 + rcu_read_unlock(&domlist_read_lock); 96.59 } 96.60 96.61 static void acpi_sleep_prepare(u32 state) 96.62 @@ -163,6 +193,7 @@ static int enter_state(u32 state) 96.63 { 96.64 case ACPI_STATE_S3: 96.65 do_suspend_lowlevel(); 96.66 + system_reset_counter++; 96.67 break; 96.68 case ACPI_STATE_S5: 96.69 acpi_enter_sleep_state(ACPI_STATE_S5);
97.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 97.2 +++ b/xen/arch/x86/copy_page.S Tue Nov 25 14:21:24 2008 +0900 97.3 @@ -0,0 +1,66 @@ 97.4 +#include <xen/config.h> 97.5 +#include <asm/page.h> 97.6 + 97.7 +#ifdef __i386__ 97.8 +#define src_reg %esi 97.9 +#define dst_reg %edi 97.10 +#define WORD_SIZE 4 97.11 +#define tmp1_reg %eax 97.12 +#define tmp2_reg %edx 97.13 +#define tmp3_reg %ebx 97.14 +#define tmp4_reg %ebp 97.15 +#else 97.16 +#define src_reg %rsi 97.17 +#define dst_reg %rdi 97.18 +#define WORD_SIZE 8 97.19 +#define tmp1_reg %r8 97.20 +#define tmp2_reg %r9 97.21 +#define tmp3_reg %r10 97.22 +#define tmp4_reg %r11 97.23 +#endif 97.24 + 97.25 +ENTRY(copy_page_sse2) 97.26 +#ifdef __i386__ 97.27 + push %ebx 97.28 + push %ebp 97.29 + push %esi 97.30 + push %edi 97.31 + mov 6*4(%esp), src_reg 97.32 + mov 5*4(%esp), dst_reg 97.33 +#endif 97.34 + mov $PAGE_SIZE/(4*WORD_SIZE)-3, %ecx 97.35 + 97.36 + prefetchnta 2*4*WORD_SIZE(src_reg) 97.37 + mov (src_reg), tmp1_reg 97.38 + mov WORD_SIZE(src_reg), tmp2_reg 97.39 + mov 2*WORD_SIZE(src_reg), tmp3_reg 97.40 + mov 3*WORD_SIZE(src_reg), tmp4_reg 97.41 + 97.42 +0: prefetchnta 3*4*WORD_SIZE(src_reg) 97.43 +1: add $4*WORD_SIZE, src_reg 97.44 + movnti tmp1_reg, (dst_reg) 97.45 + mov (src_reg), tmp1_reg 97.46 + dec %ecx 97.47 + movnti tmp2_reg, WORD_SIZE(dst_reg) 97.48 + mov WORD_SIZE(src_reg), tmp2_reg 97.49 + movnti tmp3_reg, 2*WORD_SIZE(dst_reg) 97.50 + mov 2*WORD_SIZE(src_reg), tmp3_reg 97.51 + movnti tmp4_reg, 3*WORD_SIZE(dst_reg) 97.52 + lea 4*WORD_SIZE(dst_reg), dst_reg 97.53 + mov 3*WORD_SIZE(src_reg), tmp4_reg 97.54 + jg 0b 97.55 + jpe 1b 97.56 + 97.57 + movnti tmp1_reg, (dst_reg) 97.58 + movnti tmp2_reg, WORD_SIZE(dst_reg) 97.59 + movnti tmp3_reg, 2*WORD_SIZE(dst_reg) 97.60 + movnti tmp4_reg, 3*WORD_SIZE(dst_reg) 97.61 + 97.62 +#ifdef __i386__ 97.63 + pop %edi 97.64 + pop %esi 97.65 + pop %ebp 97.66 + pop %ebx 97.67 +#endif 97.68 + sfence 97.69 + ret
98.1 --- a/xen/arch/x86/cpu/common.c Tue Nov 18 10:55:51 2008 +0100 98.2 +++ b/xen/arch/x86/cpu/common.c Tue Nov 25 14:21:24 2008 +0900 98.3 @@ -564,7 +564,10 @@ void __cpuinit cpu_init(void) 98.4 { 98.5 int cpu = smp_processor_id(); 98.6 struct tss_struct *t = &init_tss[cpu]; 98.7 - char gdt_load[10]; 98.8 + struct desc_ptr gdt_desc = { 98.9 + .base = (unsigned long)(this_cpu(gdt_table) - FIRST_RESERVED_GDT_ENTRY), 98.10 + .limit = LAST_RESERVED_GDT_BYTE 98.11 + }; 98.12 98.13 if (cpu_test_and_set(cpu, cpu_initialized)) { 98.14 printk(KERN_WARNING "CPU#%d already initialized!\n", cpu); 98.15 @@ -578,9 +581,7 @@ void __cpuinit cpu_init(void) 98.16 /* Install correct page table. */ 98.17 write_ptbase(current); 98.18 98.19 - *(unsigned short *)(&gdt_load[0]) = LAST_RESERVED_GDT_BYTE; 98.20 - *(unsigned long *)(&gdt_load[2]) = GDT_VIRT_START(current); 98.21 - asm volatile ( "lgdt %0" : "=m" (gdt_load) ); 98.22 + asm volatile ( "lgdt %0" : : "m" (gdt_desc) ); 98.23 98.24 /* No nested task. */ 98.25 asm volatile ("pushf ; andw $0xbfff,(%"__OP"sp) ; popf" );
99.1 --- a/xen/arch/x86/cpu/mcheck/p4.c Tue Nov 18 10:55:51 2008 +0100 99.2 +++ b/xen/arch/x86/cpu/mcheck/p4.c Tue Nov 25 14:21:24 2008 +0900 99.3 @@ -51,7 +51,7 @@ static void intel_thermal_interrupt(stru 99.4 99.5 ack_APIC_irq(); 99.6 99.7 - if (NOW() > next[cpu]) 99.8 + if (NOW() < next[cpu]) 99.9 return; 99.10 99.11 next[cpu] = NOW() + MILLISECS(5000);
100.1 --- a/xen/arch/x86/domain.c Tue Nov 18 10:55:51 2008 +0100 100.2 +++ b/xen/arch/x86/domain.c Tue Nov 25 14:21:24 2008 +0900 100.3 @@ -184,7 +184,8 @@ static int setup_compat_l4(struct vcpu * 100.4 /* This page needs to look like a pagetable so that it can be shadowed */ 100.5 pg->u.inuse.type_info = PGT_l4_page_table|PGT_validated|1; 100.6 100.7 - l4tab = copy_page(page_to_virt(pg), idle_pg_table); 100.8 + l4tab = page_to_virt(pg); 100.9 + copy_page(l4tab, idle_pg_table); 100.10 l4tab[0] = l4e_empty(); 100.11 l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] = 100.12 l4e_from_page(pg, __PAGE_HYPERVISOR); 100.13 @@ -310,12 +311,7 @@ int vcpu_initialise(struct vcpu *v) 100.14 if ( is_idle_domain(d) ) 100.15 { 100.16 v->arch.schedule_tail = continue_idle_domain; 100.17 - if ( v->vcpu_id ) 100.18 - v->arch.cr3 = d->vcpu[0]->arch.cr3; 100.19 - else if ( !*idle_vcpu ) 100.20 - v->arch.cr3 = __pa(idle_pg_table); 100.21 - else if ( !(v->arch.cr3 = clone_idle_pagetable(v)) ) 100.22 - return -ENOMEM; 100.23 + v->arch.cr3 = __pa(idle_pg_table); 100.24 } 100.25 100.26 v->arch.guest_context.ctrlreg[4] = 100.27 @@ -1172,14 +1168,18 @@ static void paravirt_ctxt_switch_to(stru 100.28 } 100.29 } 100.30 100.31 +static inline int need_full_gdt(struct vcpu *v) 100.32 +{ 100.33 + return (!is_hvm_vcpu(v) && !is_idle_vcpu(v)); 100.34 +} 100.35 + 100.36 static void __context_switch(void) 100.37 { 100.38 struct cpu_user_regs *stack_regs = guest_cpu_user_regs(); 100.39 - unsigned int i, cpu = smp_processor_id(); 100.40 + unsigned int cpu = smp_processor_id(); 100.41 struct vcpu *p = per_cpu(curr_vcpu, cpu); 100.42 struct vcpu *n = current; 100.43 struct desc_struct *gdt; 100.44 - struct page_info *page; 100.45 struct desc_ptr gdt_desc; 100.46 100.47 ASSERT(p != n); 100.48 @@ -1208,16 +1208,19 @@ static void __context_switch(void) 100.49 100.50 gdt = !is_pv_32on64_vcpu(n) ? per_cpu(gdt_table, cpu) : 100.51 per_cpu(compat_gdt_table, cpu); 100.52 - page = virt_to_page(gdt); 100.53 - for (i = 0; i < NR_RESERVED_GDT_PAGES; ++i) 100.54 + if ( need_full_gdt(n) ) 100.55 { 100.56 - l1e_write(n->domain->arch.mm_perdomain_pt + 100.57 - (n->vcpu_id << GDT_LDT_VCPU_SHIFT) + 100.58 - FIRST_RESERVED_GDT_PAGE + i, 100.59 - l1e_from_page(page + i, __PAGE_HYPERVISOR)); 100.60 + struct page_info *page = virt_to_page(gdt); 100.61 + unsigned int i; 100.62 + for ( i = 0; i < NR_RESERVED_GDT_PAGES; i++ ) 100.63 + l1e_write(n->domain->arch.mm_perdomain_pt + 100.64 + (n->vcpu_id << GDT_LDT_VCPU_SHIFT) + 100.65 + FIRST_RESERVED_GDT_PAGE + i, 100.66 + l1e_from_page(page + i, __PAGE_HYPERVISOR)); 100.67 } 100.68 100.69 - if ( p->vcpu_id != n->vcpu_id ) 100.70 + if ( need_full_gdt(p) && 100.71 + ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(n)) ) 100.72 { 100.73 gdt_desc.limit = LAST_RESERVED_GDT_BYTE; 100.74 gdt_desc.base = (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY); 100.75 @@ -1226,8 +1229,10 @@ static void __context_switch(void) 100.76 100.77 write_ptbase(n); 100.78 100.79 - if ( p->vcpu_id != n->vcpu_id ) 100.80 + if ( need_full_gdt(n) && 100.81 + ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(p)) ) 100.82 { 100.83 + gdt_desc.limit = LAST_RESERVED_GDT_BYTE; 100.84 gdt_desc.base = GDT_VIRT_START(n); 100.85 asm volatile ( "lgdt %0" : : "m" (gdt_desc) ); 100.86 }
101.1 --- a/xen/arch/x86/domain_build.c Tue Nov 18 10:55:51 2008 +0100 101.2 +++ b/xen/arch/x86/domain_build.c Tue Nov 25 14:21:24 2008 +0900 101.3 @@ -194,30 +194,6 @@ static void __init process_dom0_ioports_ 101.4 } 101.5 } 101.6 101.7 -/* We run on dom0's page tables for the final part of the build process. */ 101.8 -static void dom0_pt_enter(struct vcpu *v) 101.9 -{ 101.10 - struct desc_ptr gdt_desc = { 101.11 - .limit = LAST_RESERVED_GDT_BYTE, 101.12 - .base = (unsigned long)(this_cpu(gdt_table) - FIRST_RESERVED_GDT_ENTRY) 101.13 - }; 101.14 - 101.15 - asm volatile ( "lgdt %0" : : "m" (gdt_desc) ); 101.16 - write_ptbase(v); 101.17 -} 101.18 - 101.19 -/* Return to idle domain's page tables. */ 101.20 -static void dom0_pt_exit(void) 101.21 -{ 101.22 - struct desc_ptr gdt_desc = { 101.23 - .limit = LAST_RESERVED_GDT_BYTE, 101.24 - .base = GDT_VIRT_START(current) 101.25 - }; 101.26 - 101.27 - write_ptbase(current); 101.28 - asm volatile ( "lgdt %0" : : "m" (gdt_desc) ); 101.29 -} 101.30 - 101.31 int __init construct_dom0( 101.32 struct domain *d, 101.33 unsigned long _image_start, unsigned long image_len, 101.34 @@ -479,8 +455,9 @@ int __init construct_dom0( 101.35 /* WARNING: The new domain must have its 'processor' field filled in! */ 101.36 l3start = l3tab = (l3_pgentry_t *)mpt_alloc; mpt_alloc += PAGE_SIZE; 101.37 l2start = l2tab = (l2_pgentry_t *)mpt_alloc; mpt_alloc += 4*PAGE_SIZE; 101.38 - memcpy(l2tab, idle_pg_table_l2, 4*PAGE_SIZE); 101.39 - for (i = 0; i < 4; i++) { 101.40 + for (i = 0; i < L3_PAGETABLE_ENTRIES; i++) { 101.41 + copy_page(l2tab + i * L2_PAGETABLE_ENTRIES, 101.42 + idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES); 101.43 l3tab[i] = l3e_from_paddr((u32)l2tab + i*PAGE_SIZE, L3_PROT); 101.44 l2tab[(LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT)+i] = 101.45 l2e_from_paddr((u32)l2tab + i*PAGE_SIZE, __PAGE_HYPERVISOR); 101.46 @@ -729,7 +706,8 @@ int __init construct_dom0( 101.47 else 101.48 update_cr3(v); 101.49 101.50 - dom0_pt_enter(v); 101.51 + /* We run on dom0's page tables for the final part of the build process. */ 101.52 + write_ptbase(v); 101.53 101.54 /* Copy the OS image and free temporary buffer. */ 101.55 elf.dest = (void*)vkern_start; 101.56 @@ -741,11 +719,11 @@ int __init construct_dom0( 101.57 (parms.virt_hypercall >= v_end) ) 101.58 { 101.59 write_ptbase(current); 101.60 - local_irq_enable(); 101.61 printk("Invalid HYPERCALL_PAGE field in ELF notes.\n"); 101.62 return -1; 101.63 } 101.64 - hypercall_page_initialise(d, (void *)(unsigned long)parms.virt_hypercall); 101.65 + hypercall_page_initialise( 101.66 + d, (void *)(unsigned long)parms.virt_hypercall); 101.67 } 101.68 101.69 /* Copy the initial ramdisk. */ 101.70 @@ -826,7 +804,8 @@ int __init construct_dom0( 101.71 xlat_start_info(si, XLAT_start_info_console_dom0); 101.72 #endif 101.73 101.74 - dom0_pt_exit(); 101.75 + /* Return to idle domain's page tables. */ 101.76 + write_ptbase(current); 101.77 101.78 #if defined(__i386__) 101.79 /* Destroy low mappings - they were only for our convenience. */
102.1 --- a/xen/arch/x86/domctl.c Tue Nov 18 10:55:51 2008 +0100 102.2 +++ b/xen/arch/x86/domctl.c Tue Nov 25 14:21:24 2008 +0900 102.3 @@ -1074,11 +1074,24 @@ void arch_get_info_guest(struct vcpu *v, 102.4 102.5 if ( is_hvm_vcpu(v) ) 102.6 { 102.7 + struct segment_register sreg; 102.8 memset(c.nat->ctrlreg, 0, sizeof(c.nat->ctrlreg)); 102.9 c.nat->ctrlreg[0] = v->arch.hvm_vcpu.guest_cr[0]; 102.10 c.nat->ctrlreg[2] = v->arch.hvm_vcpu.guest_cr[2]; 102.11 c.nat->ctrlreg[3] = v->arch.hvm_vcpu.guest_cr[3]; 102.12 c.nat->ctrlreg[4] = v->arch.hvm_vcpu.guest_cr[4]; 102.13 + hvm_get_segment_register(v, x86_seg_cs, &sreg); 102.14 + c.nat->user_regs.cs = sreg.sel; 102.15 + hvm_get_segment_register(v, x86_seg_ss, &sreg); 102.16 + c.nat->user_regs.ss = sreg.sel; 102.17 + hvm_get_segment_register(v, x86_seg_ds, &sreg); 102.18 + c.nat->user_regs.ds = sreg.sel; 102.19 + hvm_get_segment_register(v, x86_seg_es, &sreg); 102.20 + c.nat->user_regs.es = sreg.sel; 102.21 + hvm_get_segment_register(v, x86_seg_fs, &sreg); 102.22 + c.nat->user_regs.fs = sreg.sel; 102.23 + hvm_get_segment_register(v, x86_seg_gs, &sreg); 102.24 + c.nat->user_regs.gs = sreg.sel; 102.25 } 102.26 else 102.27 {
103.1 --- a/xen/arch/x86/hpet.c Tue Nov 18 10:55:51 2008 +0100 103.2 +++ b/xen/arch/x86/hpet.c Tue Nov 25 14:21:24 2008 +0900 103.3 @@ -265,23 +265,20 @@ int hpet_legacy_irq_tick(void) 103.4 u64 hpet_setup(void) 103.5 { 103.6 static u64 hpet_rate; 103.7 - static int initialised; 103.8 + static u32 system_reset_latch; 103.9 u32 hpet_id, hpet_period, cfg; 103.10 int i; 103.11 103.12 - if ( initialised ) 103.13 + if ( system_reset_latch == system_reset_counter ) 103.14 return hpet_rate; 103.15 - initialised = 1; 103.16 - 103.17 - if ( hpet_address == 0 ) 103.18 - return 0; 103.19 + system_reset_latch = system_reset_counter; 103.20 103.21 set_fixmap_nocache(FIX_HPET_BASE, hpet_address); 103.22 103.23 hpet_id = hpet_read32(HPET_ID); 103.24 - if ( hpet_id == 0 ) 103.25 + if ( (hpet_id & HPET_ID_REV) == 0 ) 103.26 { 103.27 - printk("BAD HPET vendor id.\n"); 103.28 + printk("BAD HPET revision id.\n"); 103.29 return 0; 103.30 } 103.31 103.32 @@ -299,9 +296,9 @@ u64 hpet_setup(void) 103.33 103.34 for ( i = 0; i <= ((hpet_id >> 8) & 31); i++ ) 103.35 { 103.36 - cfg = hpet_read32(HPET_T0_CFG + i*0x20); 103.37 + cfg = hpet_read32(HPET_Tn_CFG(i)); 103.38 cfg &= ~HPET_TN_ENABLE; 103.39 - hpet_write32(cfg & ~HPET_TN_ENABLE, HPET_T0_CFG); 103.40 + hpet_write32(cfg, HPET_Tn_CFG(i)); 103.41 } 103.42 103.43 cfg = hpet_read32(HPET_CFG);
104.1 --- a/xen/arch/x86/hvm/hvm.c Tue Nov 18 10:55:51 2008 +0100 104.2 +++ b/xen/arch/x86/hvm/hvm.c Tue Nov 25 14:21:24 2008 +0900 104.3 @@ -1884,6 +1884,25 @@ static long hvm_memory_op(int cmd, XEN_G 104.4 return rc; 104.5 } 104.6 104.7 +static long hvm_vcpu_op( 104.8 + int cmd, int vcpuid, XEN_GUEST_HANDLE(void) arg) 104.9 +{ 104.10 + long rc; 104.11 + 104.12 + switch ( cmd ) 104.13 + { 104.14 + case VCPUOP_register_runstate_memory_area: 104.15 + case VCPUOP_get_runstate_info: 104.16 + rc = do_vcpu_op(cmd, vcpuid, arg); 104.17 + break; 104.18 + default: 104.19 + rc = -ENOSYS; 104.20 + break; 104.21 + } 104.22 + 104.23 + return rc; 104.24 +} 104.25 + 104.26 typedef unsigned long hvm_hypercall_t( 104.27 unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); 104.28 104.29 @@ -1895,6 +1914,7 @@ typedef unsigned long hvm_hypercall_t( 104.30 static hvm_hypercall_t *hvm_hypercall32_table[NR_hypercalls] = { 104.31 [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op, 104.32 [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, 104.33 + [ __HYPERVISOR_vcpu_op ] = (hvm_hypercall_t *)hvm_vcpu_op, 104.34 HYPERCALL(xen_version), 104.35 HYPERCALL(event_channel_op), 104.36 HYPERCALL(sched_op), 104.37 @@ -1911,9 +1931,29 @@ static long hvm_memory_op_compat32(int c 104.38 return rc; 104.39 } 104.40 104.41 +static long hvm_vcpu_op_compat32( 104.42 + int cmd, int vcpuid, XEN_GUEST_HANDLE(void) arg) 104.43 +{ 104.44 + long rc; 104.45 + 104.46 + switch ( cmd ) 104.47 + { 104.48 + case VCPUOP_register_runstate_memory_area: 104.49 + case VCPUOP_get_runstate_info: 104.50 + rc = compat_vcpu_op(cmd, vcpuid, arg); 104.51 + break; 104.52 + default: 104.53 + rc = -ENOSYS; 104.54 + break; 104.55 + } 104.56 + 104.57 + return rc; 104.58 +} 104.59 + 104.60 static hvm_hypercall_t *hvm_hypercall64_table[NR_hypercalls] = { 104.61 [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op, 104.62 [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, 104.63 + [ __HYPERVISOR_vcpu_op ] = (hvm_hypercall_t *)hvm_vcpu_op, 104.64 HYPERCALL(xen_version), 104.65 HYPERCALL(event_channel_op), 104.66 HYPERCALL(sched_op), 104.67 @@ -1923,6 +1963,7 @@ static hvm_hypercall_t *hvm_hypercall64_ 104.68 static hvm_hypercall_t *hvm_hypercall32_table[NR_hypercalls] = { 104.69 [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op_compat32, 104.70 [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, 104.71 + [ __HYPERVISOR_vcpu_op ] = (hvm_hypercall_t *)hvm_vcpu_op_compat32, 104.72 HYPERCALL(xen_version), 104.73 HYPERCALL(event_channel_op), 104.74 HYPERCALL(sched_op), 104.75 @@ -2081,7 +2122,7 @@ static int hvmop_set_pci_intx_level( 104.76 104.77 void hvm_vcpu_reset_state(struct vcpu *v, uint16_t cs, uint16_t ip) 104.78 { 104.79 - struct domain *d = current->domain; 104.80 + struct domain *d = v->domain; 104.81 struct vcpu_guest_context *ctxt; 104.82 struct segment_register reg; 104.83
105.1 --- a/xen/arch/x86/hvm/mtrr.c Tue Nov 18 10:55:51 2008 +0100 105.2 +++ b/xen/arch/x86/hvm/mtrr.c Tue Nov 25 14:21:24 2008 +0900 105.3 @@ -392,12 +392,16 @@ uint32_t get_pat_flags(struct vcpu *v, 105.4 */ 105.5 if ( pat_entry_value == INVALID_MEM_TYPE ) 105.6 { 105.7 - gdprintk(XENLOG_WARNING, 105.8 - "Conflict occurs for a given guest l1e flags:%x " 105.9 - "at %"PRIx64" (the effective mm type:%d), " 105.10 - "because the host mtrr type is:%d\n", 105.11 - gl1e_flags, (uint64_t)gpaddr, guest_eff_mm_type, 105.12 - shadow_mtrr_type); 105.13 + struct domain *d = v->domain; 105.14 + p2m_type_t p2mt; 105.15 + gfn_to_mfn(d, paddr_to_pfn(gpaddr), &p2mt); 105.16 + if (p2m_is_ram(p2mt)) 105.17 + gdprintk(XENLOG_WARNING, 105.18 + "Conflict occurs for a given guest l1e flags:%x " 105.19 + "at %"PRIx64" (the effective mm type:%d), " 105.20 + "because the host mtrr type is:%d\n", 105.21 + gl1e_flags, (uint64_t)gpaddr, guest_eff_mm_type, 105.22 + shadow_mtrr_type); 105.23 pat_entry_value = PAT_TYPE_UNCACHABLE; 105.24 } 105.25 /* 4. Get the pte flags */
106.1 --- a/xen/arch/x86/hvm/svm/svm.c Tue Nov 18 10:55:51 2008 +0100 106.2 +++ b/xen/arch/x86/hvm/svm/svm.c Tue Nov 25 14:21:24 2008 +0900 106.3 @@ -739,6 +739,23 @@ static void svm_inject_exception( 106.4 struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb; 106.5 eventinj_t event = vmcb->eventinj; 106.6 106.7 + switch ( trapnr ) 106.8 + { 106.9 + case TRAP_debug: 106.10 + if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF ) 106.11 + { 106.12 + __restore_debug_registers(curr); 106.13 + vmcb->dr6 |= 0x4000; 106.14 + } 106.15 + case TRAP_int3: 106.16 + if ( curr->domain->debugger_attached ) 106.17 + { 106.18 + /* Debug/Int3: Trap to debugger. */ 106.19 + domain_pause_for_debugger(); 106.20 + return; 106.21 + } 106.22 + } 106.23 + 106.24 if ( unlikely(event.fields.v) && 106.25 (event.fields.type == X86_EVENTTYPE_HW_EXCEPTION) ) 106.26 { 106.27 @@ -765,13 +782,6 @@ static void svm_inject_exception( 106.28 { 106.29 HVMTRACE_2D(INJ_EXC, trapnr, errcode); 106.30 } 106.31 - 106.32 - if ( (trapnr == TRAP_debug) && 106.33 - (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) ) 106.34 - { 106.35 - __restore_debug_registers(curr); 106.36 - vmcb->dr6 |= 0x4000; 106.37 - } 106.38 } 106.39 106.40 static int svm_event_pending(struct vcpu *v)
107.1 --- a/xen/arch/x86/hvm/vioapic.c Tue Nov 18 10:55:51 2008 +0100 107.2 +++ b/xen/arch/x86/hvm/vioapic.c Tue Nov 25 14:21:24 2008 +0900 107.3 @@ -344,8 +344,8 @@ static void vioapic_deliver(struct hvm_h 107.4 } 107.5 else 107.6 #endif 107.7 - target = apic_round_robin(vioapic_domain(vioapic), 107.8 - vector, deliver_bitmask); 107.9 + target = apic_lowest_prio(vioapic_domain(vioapic), 107.10 + deliver_bitmask); 107.11 if ( target != NULL ) 107.12 { 107.13 ioapic_inj_irq(vioapic, target, vector, trig_mode, delivery_mode);
108.1 --- a/xen/arch/x86/hvm/vlapic.c Tue Nov 18 10:55:51 2008 +0100 108.2 +++ b/xen/arch/x86/hvm/vlapic.c Tue Nov 25 14:21:24 2008 +0900 108.3 @@ -377,26 +377,30 @@ static int vlapic_accept_irq(struct vcpu 108.4 } 108.5 108.6 /* This function is used by both ioapic and lapic.The bitmap is for vcpu_id. */ 108.7 -struct vlapic *apic_round_robin( 108.8 - struct domain *d, uint8_t vector, uint32_t bitmap) 108.9 +struct vlapic *apic_lowest_prio(struct domain *d, uint32_t bitmap) 108.10 { 108.11 - int next, old; 108.12 - struct vlapic *target = NULL; 108.13 + int old = d->arch.hvm_domain.irq.round_robin_prev_vcpu; 108.14 + uint32_t ppr, target_ppr = UINT_MAX; 108.15 + struct vlapic *vlapic, *target = NULL; 108.16 + struct vcpu *v; 108.17 108.18 - old = next = d->arch.hvm_domain.irq.round_robin_prev_vcpu; 108.19 + if ( unlikely((v = d->vcpu[old]) == NULL) ) 108.20 + return NULL; 108.21 108.22 do { 108.23 - if ( ++next == MAX_VIRT_CPUS ) 108.24 - next = 0; 108.25 - if ( (d->vcpu[next] == NULL) || !test_bit(next, &bitmap) ) 108.26 - continue; 108.27 - target = vcpu_vlapic(d->vcpu[next]); 108.28 - if ( vlapic_enabled(target) ) 108.29 - break; 108.30 - target = NULL; 108.31 - } while ( next != old ); 108.32 + v = v->next_in_list ? : d->vcpu[0]; 108.33 + vlapic = vcpu_vlapic(v); 108.34 + if ( test_bit(v->vcpu_id, &bitmap) && vlapic_enabled(vlapic) && 108.35 + ((ppr = vlapic_get_ppr(vlapic)) < target_ppr) ) 108.36 + { 108.37 + target = vlapic; 108.38 + target_ppr = ppr; 108.39 + } 108.40 + } while ( v->vcpu_id != old ); 108.41 108.42 - d->arch.hvm_domain.irq.round_robin_prev_vcpu = next; 108.43 + if ( target != NULL ) 108.44 + d->arch.hvm_domain.irq.round_robin_prev_vcpu = 108.45 + vlapic_vcpu(target)->vcpu_id; 108.46 108.47 return target; 108.48 } 108.49 @@ -456,7 +460,7 @@ int vlapic_ipi( 108.50 108.51 if ( delivery_mode == APIC_DM_LOWEST ) 108.52 { 108.53 - target = apic_round_robin(vlapic_domain(v), vector, lpr_map); 108.54 + target = apic_lowest_prio(vlapic_domain(v), lpr_map); 108.55 if ( target != NULL ) 108.56 rc = vlapic_accept_irq(vlapic_vcpu(target), delivery_mode, 108.57 vector, level, trig_mode);
109.1 --- a/xen/arch/x86/hvm/vmsi.c Tue Nov 18 10:55:51 2008 +0100 109.2 +++ b/xen/arch/x86/hvm/vmsi.c Tue Nov 25 14:21:24 2008 +0900 109.3 @@ -152,7 +152,7 @@ int vmsi_deliver(struct domain *d, int p 109.4 { 109.5 case dest_LowestPrio: 109.6 { 109.7 - target = apic_round_robin(d, vector, deliver_bitmask); 109.8 + target = apic_lowest_prio(d, deliver_bitmask); 109.9 if ( target != NULL ) 109.10 vmsi_inj_irq(d, target, vector, trig_mode, delivery_mode); 109.11 else
110.1 --- a/xen/arch/x86/hvm/vmx/intr.c Tue Nov 18 10:55:51 2008 +0100 110.2 +++ b/xen/arch/x86/hvm/vmx/intr.c Tue Nov 25 14:21:24 2008 +0900 110.3 @@ -140,12 +140,12 @@ asmlinkage void vmx_intr_assist(void) 110.4 110.5 if ( intack.source == hvm_intsrc_nmi ) 110.6 { 110.7 - vmx_inject_nmi(v); 110.8 + vmx_inject_nmi(); 110.9 } 110.10 else 110.11 { 110.12 HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0); 110.13 - vmx_inject_extint(v, intack.vector); 110.14 + vmx_inject_extint(intack.vector); 110.15 pt_intr_post(v, intack); 110.16 } 110.17
111.1 --- a/xen/arch/x86/hvm/vmx/realmode.c Tue Nov 18 10:55:51 2008 +0100 111.2 +++ b/xen/arch/x86/hvm/vmx/realmode.c Tue Nov 25 14:21:24 2008 +0900 111.3 @@ -69,7 +69,8 @@ static void realmode_deliver_exception( 111.4 frame[1] = csr->sel; 111.5 frame[2] = regs->eflags & ~X86_EFLAGS_RF; 111.6 111.7 - if ( hvmemul_ctxt->ctxt.addr_size == 32 ) 111.8 + /* We can't test hvmemul_ctxt->ctxt.sp_size: it may not be initialised. */ 111.9 + if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.db ) 111.10 { 111.11 regs->esp -= 6; 111.12 pstk = regs->esp; 111.13 @@ -148,17 +149,25 @@ static void realmode_emulate_one(struct 111.14 hvmemul_ctxt->exn_insn_len = 0; 111.15 } 111.16 111.17 - if ( curr->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE ) 111.18 + if ( unlikely(curr->domain->debugger_attached) && 111.19 + ((hvmemul_ctxt->exn_vector == TRAP_debug) || 111.20 + (hvmemul_ctxt->exn_vector == TRAP_int3)) ) 111.21 + { 111.22 + domain_pause_for_debugger(); 111.23 + } 111.24 + else if ( curr->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE ) 111.25 { 111.26 gdprintk(XENLOG_ERR, "Exception %02x in protected mode.\n", 111.27 hvmemul_ctxt->exn_vector); 111.28 goto fail; 111.29 } 111.30 - 111.31 - realmode_deliver_exception( 111.32 - hvmemul_ctxt->exn_vector, 111.33 - hvmemul_ctxt->exn_insn_len, 111.34 - hvmemul_ctxt); 111.35 + else 111.36 + { 111.37 + realmode_deliver_exception( 111.38 + hvmemul_ctxt->exn_vector, 111.39 + hvmemul_ctxt->exn_insn_len, 111.40 + hvmemul_ctxt); 111.41 + } 111.42 } 111.43 111.44 return;
112.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c Tue Nov 18 10:55:51 2008 +0100 112.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c Tue Nov 25 14:21:24 2008 +0900 112.3 @@ -444,6 +444,8 @@ static void vmx_set_host_env(struct vcpu 112.4 { 112.5 unsigned int cpu = smp_processor_id(); 112.6 112.7 + __vmwrite(HOST_GDTR_BASE, 112.8 + (unsigned long)(this_cpu(gdt_table) - FIRST_RESERVED_GDT_ENTRY)); 112.9 __vmwrite(HOST_IDTR_BASE, (unsigned long)idt_tables[cpu]); 112.10 112.11 __vmwrite(HOST_TR_SELECTOR, TSS_ENTRY << 3); 112.12 @@ -541,9 +543,6 @@ static int construct_vmcs(struct vcpu *v 112.13 __vmwrite(IO_BITMAP_A, virt_to_maddr((char *)hvm_io_bitmap + 0)); 112.14 __vmwrite(IO_BITMAP_B, virt_to_maddr((char *)hvm_io_bitmap + PAGE_SIZE)); 112.15 112.16 - /* Host GDTR base. */ 112.17 - __vmwrite(HOST_GDTR_BASE, GDT_VIRT_START(v)); 112.18 - 112.19 /* Host data selectors. */ 112.20 __vmwrite(HOST_SS_SELECTOR, __HYPERVISOR_DS); 112.21 __vmwrite(HOST_DS_SELECTOR, __HYPERVISOR_DS);
113.1 --- a/xen/arch/x86/hvm/vmx/vmx.c Tue Nov 18 10:55:51 2008 +0100 113.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c Tue Nov 25 14:21:24 2008 +0900 113.3 @@ -187,7 +187,7 @@ static enum handler_return long_mode_do_ 113.4 check_long_mode: 113.5 if ( !(hvm_long_mode_enabled(v)) ) 113.6 { 113.7 - vmx_inject_hw_exception(v, TRAP_gp_fault, 0); 113.8 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 113.9 return HNDL_exception_raised; 113.10 } 113.11 break; 113.12 @@ -284,7 +284,7 @@ static enum handler_return long_mode_do_ 113.13 uncanonical_address: 113.14 HVM_DBG_LOG(DBG_LEVEL_0, "Not cano address of msr write %x", ecx); 113.15 gp_fault: 113.16 - vmx_inject_hw_exception(v, TRAP_gp_fault, 0); 113.17 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 113.18 exception_raised: 113.19 return HNDL_exception_raised; 113.20 } 113.21 @@ -1094,8 +1094,7 @@ void ept_sync_domain(struct domain *d) 113.22 } 113.23 } 113.24 113.25 -static void __vmx_inject_exception( 113.26 - struct vcpu *v, int trap, int type, int error_code) 113.27 +static void __vmx_inject_exception(int trap, int type, int error_code) 113.28 { 113.29 unsigned long intr_fields; 113.30 113.31 @@ -1114,17 +1113,29 @@ static void __vmx_inject_exception( 113.32 } 113.33 113.34 __vmwrite(VM_ENTRY_INTR_INFO, intr_fields); 113.35 - 113.36 - if ( trap == TRAP_page_fault ) 113.37 - HVMTRACE_LONG_2D(PF_INJECT, error_code, 113.38 - TRC_PAR_LONG(v->arch.hvm_vcpu.guest_cr[2])); 113.39 - else 113.40 - HVMTRACE_2D(INJ_EXC, trap, error_code); 113.41 } 113.42 113.43 -void vmx_inject_hw_exception(struct vcpu *v, int trap, int error_code) 113.44 +void vmx_inject_hw_exception(int trap, int error_code) 113.45 { 113.46 unsigned long intr_info = __vmread(VM_ENTRY_INTR_INFO); 113.47 + struct vcpu *curr = current; 113.48 + 113.49 + switch ( trap ) 113.50 + { 113.51 + case TRAP_debug: 113.52 + if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF ) 113.53 + { 113.54 + __restore_debug_registers(curr); 113.55 + write_debugreg(6, read_debugreg(6) | 0x4000); 113.56 + } 113.57 + case TRAP_int3: 113.58 + if ( curr->domain->debugger_attached ) 113.59 + { 113.60 + /* Debug/Int3: Trap to debugger. */ 113.61 + domain_pause_for_debugger(); 113.62 + return; 113.63 + } 113.64 + } 113.65 113.66 if ( unlikely(intr_info & INTR_INFO_VALID_MASK) && 113.67 (((intr_info >> 8) & 7) == X86_EVENTTYPE_HW_EXCEPTION) ) 113.68 @@ -1134,37 +1145,34 @@ void vmx_inject_hw_exception(struct vcpu 113.69 error_code = 0; 113.70 } 113.71 113.72 - __vmx_inject_exception(v, trap, X86_EVENTTYPE_HW_EXCEPTION, error_code); 113.73 + __vmx_inject_exception(trap, X86_EVENTTYPE_HW_EXCEPTION, error_code); 113.74 + 113.75 + if ( trap == TRAP_page_fault ) 113.76 + HVMTRACE_LONG_2D(PF_INJECT, error_code, 113.77 + TRC_PAR_LONG(current->arch.hvm_vcpu.guest_cr[2])); 113.78 + else 113.79 + HVMTRACE_2D(INJ_EXC, trap, error_code); 113.80 } 113.81 113.82 -void vmx_inject_extint(struct vcpu *v, int trap) 113.83 +void vmx_inject_extint(int trap) 113.84 { 113.85 - __vmx_inject_exception(v, trap, X86_EVENTTYPE_EXT_INTR, 113.86 + __vmx_inject_exception(trap, X86_EVENTTYPE_EXT_INTR, 113.87 HVM_DELIVER_NO_ERROR_CODE); 113.88 } 113.89 113.90 -void vmx_inject_nmi(struct vcpu *v) 113.91 +void vmx_inject_nmi(void) 113.92 { 113.93 - __vmx_inject_exception(v, 2, X86_EVENTTYPE_NMI, 113.94 + __vmx_inject_exception(2, X86_EVENTTYPE_NMI, 113.95 HVM_DELIVER_NO_ERROR_CODE); 113.96 } 113.97 113.98 static void vmx_inject_exception( 113.99 unsigned int trapnr, int errcode, unsigned long cr2) 113.100 { 113.101 - struct vcpu *curr = current; 113.102 - 113.103 - vmx_inject_hw_exception(curr, trapnr, errcode); 113.104 - 113.105 if ( trapnr == TRAP_page_fault ) 113.106 - curr->arch.hvm_vcpu.guest_cr[2] = cr2; 113.107 + current->arch.hvm_vcpu.guest_cr[2] = cr2; 113.108 113.109 - if ( (trapnr == TRAP_debug) && 113.110 - (guest_cpu_user_regs()->eflags & X86_EFLAGS_TF) ) 113.111 - { 113.112 - __restore_debug_registers(curr); 113.113 - write_debugreg(6, read_debugreg(6) | 0x4000); 113.114 - } 113.115 + vmx_inject_hw_exception(trapnr, errcode); 113.116 } 113.117 113.118 static int vmx_event_pending(struct vcpu *v) 113.119 @@ -1315,7 +1323,7 @@ static void __update_guest_eip(unsigned 113.120 } 113.121 113.122 if ( regs->eflags & X86_EFLAGS_TF ) 113.123 - vmx_inject_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE, 0); 113.124 + vmx_inject_hw_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE); 113.125 } 113.126 113.127 static void vmx_fpu_dirty_intercept(void) 113.128 @@ -1636,7 +1644,6 @@ static int vmx_msr_read_intercept(struct 113.129 { 113.130 u64 msr_content = 0; 113.131 u32 ecx = regs->ecx, eax, edx; 113.132 - struct vcpu *v = current; 113.133 113.134 HVM_DBG_LOG(DBG_LEVEL_1, "ecx=%x", ecx); 113.135 113.136 @@ -1712,7 +1719,7 @@ done: 113.137 return X86EMUL_OKAY; 113.138 113.139 gp_fault: 113.140 - vmx_inject_hw_exception(v, TRAP_gp_fault, 0); 113.141 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 113.142 return X86EMUL_EXCEPTION; 113.143 } 113.144 113.145 @@ -1849,7 +1856,7 @@ static int vmx_msr_write_intercept(struc 113.146 113.147 if ( (rc < 0) || 113.148 (vmx_add_host_load_msr(ecx) < 0) ) 113.149 - vmx_inject_hw_exception(v, TRAP_machine_check, 0); 113.150 + vmx_inject_hw_exception(TRAP_machine_check, 0); 113.151 else 113.152 { 113.153 __vmwrite(GUEST_IA32_DEBUGCTL, msr_content); 113.154 @@ -1889,7 +1896,7 @@ static int vmx_msr_write_intercept(struc 113.155 return X86EMUL_OKAY; 113.156 113.157 gp_fault: 113.158 - vmx_inject_hw_exception(v, TRAP_gp_fault, 0); 113.159 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 113.160 return X86EMUL_EXCEPTION; 113.161 } 113.162 113.163 @@ -2197,7 +2204,7 @@ asmlinkage void vmx_vmexit_handler(struc 113.164 } 113.165 113.166 v->arch.hvm_vcpu.guest_cr[2] = exit_qualification; 113.167 - vmx_inject_hw_exception(v, TRAP_page_fault, regs->error_code); 113.168 + vmx_inject_hw_exception(TRAP_page_fault, regs->error_code); 113.169 break; 113.170 case TRAP_nmi: 113.171 if ( (intr_info & INTR_INFO_INTR_TYPE_MASK) != 113.172 @@ -2317,7 +2324,7 @@ asmlinkage void vmx_vmexit_handler(struc 113.173 case EXIT_REASON_VMWRITE: 113.174 case EXIT_REASON_VMXOFF: 113.175 case EXIT_REASON_VMXON: 113.176 - vmx_inject_hw_exception(v, TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE); 113.177 + vmx_inject_hw_exception(TRAP_invalid_op, HVM_DELIVER_NO_ERROR_CODE); 113.178 break; 113.179 113.180 case EXIT_REASON_TPR_BELOW_THRESHOLD: 113.181 @@ -2326,7 +2333,7 @@ asmlinkage void vmx_vmexit_handler(struc 113.182 case EXIT_REASON_IO_INSTRUCTION: 113.183 case EXIT_REASON_APIC_ACCESS: 113.184 if ( !handle_mmio() ) 113.185 - hvm_inject_exception(TRAP_gp_fault, 0, 0); 113.186 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 113.187 break; 113.188 113.189 case EXIT_REASON_INVD:
114.1 --- a/xen/arch/x86/hvm/vmx/vpmu_core2.c Tue Nov 18 10:55:51 2008 +0100 114.2 +++ b/xen/arch/x86/hvm/vmx/vpmu_core2.c Tue Nov 25 14:21:24 2008 +0900 114.3 @@ -335,7 +335,7 @@ static int core2_vpmu_do_wrmsr(struct cp 114.4 case MSR_CORE_PERF_GLOBAL_STATUS: 114.5 gdprintk(XENLOG_INFO, "Can not write readonly MSR: " 114.6 "MSR_PERF_GLOBAL_STATUS(0x38E)!\n"); 114.7 - vmx_inject_hw_exception(current, TRAP_gp_fault, 0); 114.8 + vmx_inject_hw_exception(TRAP_gp_fault, 0); 114.9 return 1; 114.10 case MSR_IA32_PEBS_ENABLE: 114.11 if ( msr_content & 1 )
115.1 --- a/xen/arch/x86/i8259.c Tue Nov 18 10:55:51 2008 +0100 115.2 +++ b/xen/arch/x86/i8259.c Tue Nov 25 14:21:24 2008 +0900 115.3 @@ -390,7 +390,7 @@ void __init init_IRQ(void) 115.4 115.5 init_8259A(0); 115.6 115.7 - for ( i = 0; i < NR_IRQS; i++ ) 115.8 + for ( i = 0; i < NR_VECTORS; i++ ) 115.9 { 115.10 irq_desc[i].status = IRQ_DISABLED; 115.11 irq_desc[i].handler = &no_irq_type;
116.1 --- a/xen/arch/x86/io_apic.c Tue Nov 18 10:55:51 2008 +0100 116.2 +++ b/xen/arch/x86/io_apic.c Tue Nov 25 14:21:24 2008 +0900 116.3 @@ -665,7 +665,7 @@ static inline int IO_APIC_irq_trigger(in 116.4 } 116.5 116.6 /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */ 116.7 -u8 irq_vector[NR_IRQ_VECTORS] __read_mostly; 116.8 +u8 irq_vector[NR_IRQS] __read_mostly; 116.9 116.10 int free_irq_vector(int vector) 116.11 { 116.12 @@ -686,7 +686,7 @@ int assign_irq_vector(int irq) 116.13 static unsigned current_vector = FIRST_DYNAMIC_VECTOR; 116.14 unsigned vector; 116.15 116.16 - BUG_ON(irq >= NR_IRQ_VECTORS); 116.17 + BUG_ON(irq >= NR_IRQS); 116.18 116.19 spin_lock(&vector_lock); 116.20 116.21 @@ -1547,20 +1547,10 @@ static struct hw_interrupt_type ioapic_l 116.22 .set_affinity = set_ioapic_affinity_vector, 116.23 }; 116.24 116.25 -static void mask_msi_vector(unsigned int vector) 116.26 -{ 116.27 - mask_msi_irq(vector); 116.28 -} 116.29 - 116.30 -static void unmask_msi_vector(unsigned int vector) 116.31 -{ 116.32 - unmask_msi_irq(vector); 116.33 -} 116.34 - 116.35 static unsigned int startup_msi_vector(unsigned int vector) 116.36 { 116.37 dprintk(XENLOG_INFO, "startup msi vector %x\n", vector); 116.38 - unmask_msi_irq(vector); 116.39 + unmask_msi_vector(vector); 116.40 return 0; 116.41 } 116.42 116.43 @@ -1576,13 +1566,13 @@ static void end_msi_vector(unsigned int 116.44 static void shutdown_msi_vector(unsigned int vector) 116.45 { 116.46 dprintk(XENLOG_INFO, "shutdown msi vector %x\n", vector); 116.47 - mask_msi_irq(vector); 116.48 + mask_msi_vector(vector); 116.49 } 116.50 116.51 static void set_msi_affinity_vector(unsigned int vector, cpumask_t cpu_mask) 116.52 { 116.53 set_native_irq_info(vector, cpu_mask); 116.54 - set_msi_irq_affinity(vector, cpu_mask); 116.55 + set_msi_affinity(vector, cpu_mask); 116.56 } 116.57 116.58 /* 116.59 @@ -2196,7 +2186,7 @@ int ioapic_guest_write(unsigned long phy 116.60 if ( new_rte.vector >= FIRST_DYNAMIC_VECTOR ) 116.61 new_irq = vector_irq[new_rte.vector]; 116.62 116.63 - if ( (old_irq != new_irq) && (old_irq != -1) && IO_APIC_IRQ(old_irq) ) 116.64 + if ( (old_irq != new_irq) && (old_irq >= 0) && IO_APIC_IRQ(old_irq) ) 116.65 { 116.66 if ( irq_desc[IO_APIC_VECTOR(old_irq)].action ) 116.67 { 116.68 @@ -2208,7 +2198,7 @@ int ioapic_guest_write(unsigned long phy 116.69 remove_pin_at_irq(old_irq, apic, pin); 116.70 } 116.71