ia64/xen-unstable

changeset 9806:6af7b456e684

The attached patch allows external devices to migrate. The patch
contains code that allows to at least detect local migration of a
virtual machine and handles this for the virtual TPM (results in a no-op
for local migr.). If migration of a virtual machine with attached vTPM
to another machine is attempted, XenD will return an error.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Fri Apr 21 11:54:12 2006 +0100 (2006-04-21)
parents 42358db788fd
children 73d847cafc87
files tools/examples/Makefile tools/examples/external-device-migrate tools/examples/vtpm-common.sh tools/examples/vtpm-migration.sh
line diff
     1.1 --- a/tools/examples/Makefile	Fri Apr 21 10:44:54 2006 +0100
     1.2 +++ b/tools/examples/Makefile	Fri Apr 21 11:54:12 2006 +0100
     1.3 @@ -28,9 +28,11 @@ XEN_SCRIPTS += block
     1.4  XEN_SCRIPTS += block-enbd block-nbd
     1.5  XEN_SCRIPTS += vtpm vtpm-delete
     1.6  XEN_SCRIPTS += xen-hotplug-cleanup
     1.7 +XEN_SCRIPTS += external-device-migrate
     1.8  XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
     1.9  XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
    1.10  XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh
    1.11 +XEN_SCRIPT_DATA += vtpm-migration.sh
    1.12  
    1.13  XEN_HOTPLUG_DIR = /etc/hotplug
    1.14  XEN_HOTPLUG_SCRIPTS = xen-backend.agent
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/examples/external-device-migrate	Fri Apr 21 11:54:12 2006 +0100
     2.3 @@ -0,0 +1,85 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +# Copyright (c) 2005 IBM Corporation
     2.7 +#
     2.8 +# This library is free software; you can redistribute it and/or
     2.9 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    2.10 +# License as published by the Free Software Foundation.
    2.11 +#
    2.12 +# This library is distributed in the hope that it will be useful,
    2.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.15 +# Lesser General Public License for more details.
    2.16 +#
    2.17 +# You should have received a copy of the GNU Lesser General Public
    2.18 +# License along with this library; if not, write to the Free Software
    2.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 +#
    2.21 +
    2.22 +
    2.23 +# This script is called by XenD for migration of external devices
    2.24 +# It does not handle the migration of those devices itself, but
    2.25 +# passes the requests on to further applications
    2.26 +# It handles the low-level command line parsing and some of the
    2.27 +# synchronization
    2.28 +
    2.29 +dir=$(dirname "$0")
    2.30 +. "$dir/logging.sh"
    2.31 +
    2.32 +
    2.33 +function usage() {
    2.34 +	echo " Pass the following command line paremeters to the script:"
    2.35 +	echo ""
    2.36 +	echo "-step <n>     : n-th migration step"
    2.37 +	echo "-host <host>  : the destination host"
    2.38 +	echo "-domname <domain name> : name of the domain that is migrating"
    2.39 +	echo "-type <device type>    : the type of device that is migrating"
    2.40 +	echo "-recover               : indicates recovery request; an error"
    2.41 +	echo "                         occurred during migration"
    2.42 +	echo "-help                  : display this help screen"
    2.43 +}
    2.44 +
    2.45 +while [ 1 ]; do
    2.46 +	if [ "$1" == "-step" ]; then
    2.47 +		shift
    2.48 +		step=$1
    2.49 +	elif [ "$1" == "-host" ]; then
    2.50 +		shift
    2.51 +		host=$1
    2.52 +	elif [ "$1" == "-domname" ]; then
    2.53 +		shift
    2.54 +		domname=$1
    2.55 +	elif [ "$1" == "-type" ]; then
    2.56 +		shift
    2.57 +		typ=$1
    2.58 +	elif [ "$1" == "-recover" ]; then
    2.59 +		recover=1
    2.60 +	elif [ "$1" == "-help" ]; then
    2.61 +		usage
    2.62 +		exit
    2.63 +	else
    2.64 +		break
    2.65 +	fi
    2.66 +	shift
    2.67 +done
    2.68 +
    2.69 +if [ "$step"    == "" -o \
    2.70 +     "$host"    == "" -o \
    2.71 +     "$typ"     == "" -o \
    2.72 +     "$domname" == "" ]; then
    2.73 +	echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
    2.74 +set
    2.75 +	echo ""
    2.76 +	echo "$0 --help for usage."
    2.77 +	exit
    2.78 +fi
    2.79 +
    2.80 +. "$dir/$typ-migration.sh"
    2.81 +
    2.82 +if [ "$recover" == "1" ]; then
    2.83 +	func="$typ"_recover
    2.84 +	eval $func $host $domname $step
    2.85 +else
    2.86 +	func="$typ"_migration_step
    2.87 +	eval $func $host $domname $step
    2.88 +fi
     3.1 --- a/tools/examples/vtpm-common.sh	Fri Apr 21 10:44:54 2006 +0100
     3.2 +++ b/tools/examples/vtpm-common.sh	Fri Apr 21 11:54:12 2006 +0100
     3.3 @@ -48,6 +48,12 @@ if [ -z "$VTPM_IMPL_DEFINED" ]; then
     3.4  	function vtpm_delete() {
     3.5  		true
     3.6  	}
     3.7 +	function vtpm_migrate() {
     3.8 +		echo "Error: vTPM migration accross machines not implemented."
     3.9 +	}
    3.10 +	function vtpm_migrate_recover() {
    3.11 +		true
    3.12 +	}
    3.13  fi
    3.14  
    3.15  
    3.16 @@ -300,3 +306,62 @@ function vtpm_delete_instance () {
    3.17  
    3.18  	release_lock vtpmdb
    3.19  }
    3.20 +
    3.21 +# Determine whether the given address is local to this machine
    3.22 +# Return values:
    3.23 +#  "-1" : the given machine name is invalid
    3.24 +#  "0"  : this is not an address of this machine
    3.25 +#  "1"  : this is an address local to this machine
    3.26 +function isLocalAddress() {
    3.27 +	local addr=$(ping $1 -c 1 |  \
    3.28 +	             gawk '{ print substr($3,2,length($3)-2); exit }')
    3.29 +	if [ "$addr" == "" ]; then
    3.30 +		echo "-1"
    3.31 +		return
    3.32 +	fi
    3.33 +	local res=$(ifconfig | grep "inet addr" |  \
    3.34 +	           gawk -vaddr=$addr               \
    3.35 +	           '{                              \
    3.36 +	              if ( addr == substr($2, 6)) {\
    3.37 +	                print "1";                 \
    3.38 +	              }                            \
    3.39 +	           }'                              \
    3.40 +	          )
    3.41 +	if [ "$res" == "" ]; then
    3.42 +		echo "0"
    3.43 +		return
    3.44 +	fi
    3.45 +	echo "1"
    3.46 +}
    3.47 +
    3.48 +# Perform a migration step. This function differentiates between migration
    3.49 +# to the local host or to a remote machine.
    3.50 +# Parameters:
    3.51 +# 1st: destination host to migrate to
    3.52 +# 2nd: name of the domain to migrate
    3.53 +# 3rd: the migration step to perform
    3.54 +function vtpm_migration_step() {
    3.55 +	local instance=$(vtpmdb_find_instance $2)
    3.56 +	if [ "$instance" == "" ]; then
    3.57 +		echo "Error: Translation of domain name ($2) to instance failed. Check /etc/xen/vtpm.db"
    3.58 +		log err "Error during translation of domain name"
    3.59 +	else
    3.60 +		res=$(isLocalAddress $1)
    3.61 +		if [ "$res" == "0" ]; then
    3.62 +			vtpm_migrate $1 $2 $3
    3.63 +		fi
    3.64 +	fi
    3.65 +}
    3.66 +
    3.67 +# Recover from migration due to an error. This function differentiates
    3.68 +# between migration to the local host or to a remote machine.
    3.69 +# Parameters:
    3.70 +# 1st: destination host the migration was going to
    3.71 +# 2nd: name of the domain that was to be migrated
    3.72 +# 3rd: the last successful migration step that was done
    3.73 +function vtpm_recover() {
    3.74 +	res=$(isLocalAddress $1)
    3.75 +	if [ "$res" == "0" ]; then
    3.76 +		vtpm_migrate_recover $1 $2 $3
    3.77 +	fi
    3.78 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/examples/vtpm-migration.sh	Fri Apr 21 11:54:12 2006 +0100
     4.3 @@ -0,0 +1,19 @@
     4.4 +#
     4.5 +# Copyright (c) 2005 IBM Corporation
     4.6 +#
     4.7 +# This library is free software; you can redistribute it and/or
     4.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     4.9 +# License as published by the Free Software Foundation.
    4.10 +#
    4.11 +# This library is distributed in the hope that it will be useful,
    4.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.14 +# Lesser General Public License for more details.
    4.15 +#
    4.16 +# You should have received a copy of the GNU Lesser General Public
    4.17 +# License along with this library; if not, write to the Free Software
    4.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.19 +#
    4.20 +
    4.21 +dir=$(dirname "$0")
    4.22 +. "$dir/vtpm-common.sh"