1#!/bin/bash 2 3# Copyright (c) 2005 IBM Corporation 4# 5# This library is free software; you can redistribute it and/or 6# modify it under the terms of version 2.1 of the GNU Lesser General Public 7# License as published by the Free Software Foundation. 8# 9# This library is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12# Lesser General Public License for more details. 13# 14# You should have received a copy of the GNU Lesser General Public 15# License along with this library; If not, see <http://www.gnu.org/licenses/>. 16# 17 18set -x 19 20# This script is called by XenD for migration of external devices 21# It does not handle the migration of those devices itself, but 22# passes the requests on to further applications 23# It handles the low-level command line parsing and some of the 24# synchronization 25 26dir=$(dirname "$0") 27. "$dir/logging.sh" 28 29 30function ext_dev_migrate_usage() { 31cat <<EOF 32Pass the following command line parameters to the script: 33 34-step <n> : n-th migration step 35-host <host> : the destination host 36-domname <domain name> : name of the domain that is migrating 37-type <device type> : the type of device that is migrating 38-subtype <dev. subtype>: the subtype of the device 39-recover : indicates recovery request; an error 40 occurred during migration 41-help : display this help screen 42EOF 43} 44 45# Parse the command line paramters. The following parameters must be 46# passed as the first ones in the sequence: 47# -step [required] 48# -host [required] 49# -domname [required] 50# -type [required] 51# -subtype [optional] 52# -recover [optional] 53# The remaining ones will be passed to the called function. 54function evaluate_params() 55{ 56 local step host domname typ recover filename func stype 57 stype="" 58 while [ $# -ge 1 ]; do 59 case "$1" in 60 -step) step=$2; shift; shift;; 61 -host) host=$2; shift; shift;; 62 -domname) domname=$2; shift; shift;; 63 -type) typ=$2; shift; shift;; 64 -subtype) stype=$2; shift; shift;; 65 -recover) recover=1; shift;; 66 -help) ext_dev_migrate_usage; exit 0;; 67 *) break;; 68 esac 69 done 70 71 if [ "$step" = "" -o \ 72 "$host" = "" -o \ 73 "$typ" = "" -o \ 74 "$domname" = "" ]; then 75 echo "Error: Parameter(s) missing (-step/-host/-type/-domname)" 1>&2 76 echo "" 1>&2 77 echo "$0 -help for usage." 1>&2 78 exit 1 79 fi 80 81 filename="$dir/$typ$stype-migration.sh" 82 if [ ! -r $filename ]; then 83 echo "Error: Could not find script '$filename'" 84 return 85 fi 86 . "$filename" 87 88 if [ "$recover" = "1" ]; then 89 func="$typ"_recover 90 eval $func $host $domname $step $* 91 else 92 func="$typ"_migration_step 93 eval $func $host $domname $step $* 94 fi 95} 96 97evaluate_params "$@" 98