Index: xen/xen-unstable.hg/tools/examples/Makefile =================================================================== --- xen.orig/xen-unstable.hg/tools/examples/Makefile +++ xen/xen-unstable.hg/tools/examples/Makefile @@ -28,9 +28,11 @@ XEN_SCRIPTS += block XEN_SCRIPTS += block-enbd block-nbd XEN_SCRIPTS += vtpm vtpm-delete XEN_SCRIPTS += xen-hotplug-cleanup +XEN_SCRIPTS += external-device-migrate XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh +XEN_SCRIPT_DATA += vtpm-migration.sh XEN_HOTPLUG_DIR = /etc/hotplug XEN_HOTPLUG_SCRIPTS = xen-backend.agent Index: xen/xen-unstable.hg/tools/examples/external-device-migrate =================================================================== --- /dev/null +++ xen/xen-unstable.hg/tools/examples/external-device-migrate @@ -0,0 +1,85 @@ +#!/bin/sh + +# Copyright (c) 2005 IBM Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + + +# This script is called by XenD for migration of external devices +# It does not handle the migration of those devices itself, but +# passes the requests on to further applications +# It handles the low-level command line parsing and some of the +# synchronization + +dir=$(dirname "$0") +. "$dir/logging.sh" + + +function usage() { + echo " Pass the following command line paremeters to the script:" + echo "" + echo "-step : n-th migration step" + echo "-host : the destination host" + echo "-domname : name of the domain that is migrating" + echo "-type : the type of device that is migrating" + echo "-recover : indicates recovery request; an error" + echo " occurred during migration" + echo "-help : display this help screen" +} + +while [ 1 ]; do + if [ "$1" == "-step" ]; then + shift + step=$1 + elif [ "$1" == "-host" ]; then + shift + host=$1 + elif [ "$1" == "-domname" ]; then + shift + domname=$1 + elif [ "$1" == "-type" ]; then + shift + typ=$1 + elif [ "$1" == "-recover" ]; then + recover=1 + elif [ "$1" == "-help" ]; then + usage + exit + else + break + fi + shift +done + +if [ "$step" == "" -o \ + "$host" == "" -o \ + "$typ" == "" -o \ + "$domname" == "" ]; then + echo "Error: Parameter(s) missing (-step/-host/-type/-domname)" +set + echo "" + echo "$0 --help for usage." + exit +fi + +. "$dir/$typ-migration.sh" + +if [ "$recover" == "1" ]; then + func="$typ"_recover + eval $func $host $domname $step +else + func="$typ"_migration_step + eval $func $host $domname $step +fi Index: xen/xen-unstable.hg/tools/examples/vtpm-migration.sh =================================================================== --- /dev/null +++ xen/xen-unstable.hg/tools/examples/vtpm-migration.sh @@ -0,0 +1,19 @@ +# +# Copyright (c) 2005 IBM Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +dir=$(dirname "$0") +. "$dir/vtpm-common.sh" Index: xen/xen-unstable.hg/tools/examples/vtpm-common.sh =================================================================== --- xen.orig/xen-unstable.hg/tools/examples/vtpm-common.sh +++ xen/xen-unstable.hg/tools/examples/vtpm-common.sh @@ -48,6 +48,12 @@ if [ -z "$VTPM_IMPL_DEFINED" ]; then function vtpm_delete() { true } + function vtpm_migrate() { + echo "Error: vTPM migration accross machines not implemented." + } + function vtpm_migrate_recover() { + true + } fi @@ -300,3 +306,62 @@ function vtpm_delete_instance () { release_lock vtpmdb } + +# Determine whether the given address is local to this machine +# Return values: +# "-1" : the given machine name is invalid +# "0" : this is not an address of this machine +# "1" : this is an address local to this machine +function isLocalAddress() { + local addr=$(ping $1 -c 1 | \ + gawk '{ print substr($3,2,length($3)-2); exit }') + if [ "$addr" == "" ]; then + echo "-1" + return + fi + local res=$(ifconfig | grep "inet addr" | \ + gawk -vaddr=$addr \ + '{ \ + if ( addr == substr($2, 6)) {\ + print "1"; \ + } \ + }' \ + ) + if [ "$res" == "" ]; then + echo "0" + return + fi + echo "1" +} + +# Perform a migration step. This function differentiates between migration +# to the local host or to a remote machine. +# Parameters: +# 1st: destination host to migrate to +# 2nd: name of the domain to migrate +# 3rd: the migration step to perform +function vtpm_migration_step() { + local instance=$(vtpmdb_find_instance $2) + if [ "$instance" == "" ]; then + echo "Error: Translation of domain name ($2) to instance failed. Check /etc/xen/vtpm.db" + log err "Error during translation of domain name" + else + res=$(isLocalAddress $1) + if [ "$res" == "0" ]; then + vtpm_migrate $1 $2 $3 + fi + fi +} + +# Recover from migration due to an error. This function differentiates +# between migration to the local host or to a remote machine. +# Parameters: +# 1st: destination host the migration was going to +# 2nd: name of the domain that was to be migrated +# 3rd: the last successful migration step that was done +function vtpm_recover() { + res=$(isLocalAddress $1) + if [ "$res" == "0" ]; then + vtpm_migrate_recover $1 $2 $3 + fi +}