ia64/xen-unstable
changeset 10722:28b766e3bcca
Move the content of the script file vtpm-addtodb into the
vtpm-common.sh
script. The newly created function 'vtpm_add_and_activate' also
assigns
the instance number to the xenstore entry to activate the backend.
Renaming of isLocalAddress function to vtpm_isLocalAddress.
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
vtpm-common.sh
script. The newly created function 'vtpm_add_and_activate' also
assigns
the instance number to the xenstore entry to activate the backend.
Renaming of isLocalAddress function to vtpm_isLocalAddress.
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author | kfraser@localhost.localdomain |
---|---|
date | Mon Jul 10 17:36:41 2006 +0100 (2006-07-10) |
parents | 3243ab41b09e |
children | 405c7e86b24a |
files | tools/examples/Makefile tools/examples/README tools/examples/vtpm-addtodb tools/examples/vtpm-common.sh tools/examples/vtpm-impl |
line diff
1.1 --- a/tools/examples/Makefile Mon Jul 10 17:33:45 2006 +0100 1.2 +++ b/tools/examples/Makefile Mon Jul 10 17:36:41 2006 +0100 1.3 @@ -26,7 +26,7 @@ XEN_SCRIPTS += network-route vif-route 1.4 XEN_SCRIPTS += network-nat vif-nat 1.5 XEN_SCRIPTS += block 1.6 XEN_SCRIPTS += block-enbd block-nbd 1.7 -XEN_SCRIPTS += vtpm vtpm-delete vtpm-addtodb 1.8 +XEN_SCRIPTS += vtpm vtpm-delete 1.9 XEN_SCRIPTS += xen-hotplug-cleanup 1.10 XEN_SCRIPTS += external-device-migrate 1.11 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
2.1 --- a/tools/examples/README Mon Jul 10 17:33:45 2006 +0100 2.2 +++ b/tools/examples/README Mon Jul 10 17:36:41 2006 +0100 2.3 @@ -25,7 +25,6 @@ vif-common.sh - sourced by vif-bri 2.4 vif-nat - xen virtual network start/stop script in NAT mode 2.5 vif-route - xen virtual network start/stop script in routed mode 2.6 vtpm - called by xen-backend.agent to bind/unbind vTPM devices 2.7 -vtpm-addtodb - script for adding a vTPM instance to the vTPM table 2.8 vtpm-common.sh - common code for vTPM handling 2.9 vtpm-delete - remove an entry from the vTPM table given the 2.10 domain's name
3.1 --- a/tools/examples/vtpm-addtodb Mon Jul 10 17:33:45 2006 +0100 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,10 +0,0 @@ 3.4 -#!/bin/sh 3.5 - 3.6 -# This script must be called with the following parameters to have 3.7 -# an entry added to the TPM-to-domain associations table in /etc/xen/vtpm.db 3.8 -# vtpm-addtodb <dom name> <instance number> 3.9 - 3.10 -dir=$(dirname "$0") 3.11 -. "$dir/vtpm-common.sh" 3.12 - 3.13 -vtpmdb_add_instance $1 $2
4.1 --- a/tools/examples/vtpm-common.sh Mon Jul 10 17:33:45 2006 +0100 4.2 +++ b/tools/examples/vtpm-common.sh Mon Jul 10 17:36:41 2006 +0100 4.3 @@ -24,12 +24,9 @@ VTPMDB="/etc/xen/vtpm.db" 4.4 4.5 #In the vtpm-impl file some commands should be defined: 4.6 # vtpm_create, vtpm_setup, vtpm_start, etc. (see below) 4.7 -#This should be indicated by setting VTPM_IMPL_DEFINED. 4.8 if [ -r "$dir/vtpm-impl" ]; then 4.9 . "$dir/vtpm-impl" 4.10 -fi 4.11 - 4.12 -if [ -z "$VTPM_IMPL_DEFINED" ]; then 4.13 +else 4.14 function vtpm_create () { 4.15 true 4.16 } 4.17 @@ -245,6 +242,12 @@ function vtpm_create_instance () { 4.18 4.19 claim_lock vtpmdb 4.20 instance=$(vtpmdb_find_instance $domname) 4.21 + 4.22 + if [ "$instance" == "0" -a "$reason" != "create" ]; then 4.23 + release_lock vtpmdb 4.24 + return 4.25 + fi 4.26 + 4.27 if [ "$instance" == "0" ]; then 4.28 #Try to give the preferred instance to the domain 4.29 instance=$(xenstore_read "$XENBUS_PATH"/pref_instance) 4.30 @@ -317,7 +320,7 @@ function vtpm_delete_instance () { 4.31 # "-1" : the given machine name is invalid 4.32 # "0" : this is not an address of this machine 4.33 # "1" : this is an address local to this machine 4.34 -function isLocalAddress() { 4.35 +function vtpm_isLocalAddress() { 4.36 local addr res 4.37 addr=$(ping $1 -c 1 | \ 4.38 gawk '{ print substr($3,2,length($3)-2); exit }') 4.39 @@ -347,7 +350,7 @@ function isLocalAddress() { 4.40 # 2nd: name of the domain to migrate 4.41 # 3rd: the migration step to perform 4.42 function vtpm_migration_step() { 4.43 - local res=$(isLocalAddress $1) 4.44 + local res=$(vtpm_isLocalAddress $1) 4.45 if [ "$res" == "0" ]; then 4.46 vtpm_migrate $1 $2 $3 4.47 fi 4.48 @@ -361,8 +364,39 @@ function vtpm_migration_step() { 4.49 # 3rd: the last successful migration step that was done 4.50 function vtpm_recover() { 4.51 local res 4.52 - res=$(isLocalAddress $1) 4.53 + res=$(vtpm_isLocalAddress $1) 4.54 if [ "$res" == "0" ]; then 4.55 vtpm_migrate_recover $1 $2 $3 4.56 fi 4.57 } 4.58 + 4.59 + 4.60 +#Determine the domain id given a domain's name. 4.61 +#1st parameter: name of the domain 4.62 +#return value: domain id or -1 if domain id could not be determined 4.63 +function vtpm_domid_from_name () { 4.64 + local id name ids 4.65 + ids=$(xenstore-list /local/domain) 4.66 + for id in $ids; do 4.67 + name=$(xenstore-read /local/domain/$id/name) 4.68 + if [ "$name" == "$1" ]; then 4.69 + echo "$id" 4.70 + return 4.71 + fi 4.72 + done 4.73 + echo "-1" 4.74 +} 4.75 + 4.76 + 4.77 +#Add a virtual TPM instance number and its associated domain name 4.78 +#to the VTPMDB file and activate usage of this virtual TPM instance 4.79 +#by writing the instance number into the xenstore 4.80 +#1st parm: name of virtual machine 4.81 +#2nd parm: instance of assoicate virtual TPM 4.82 +function vtpm_add_and_activate() { 4.83 + local domid=$(vtpm_domid_from_name $1) 4.84 + if [ "$domid" != "-1" ]; then 4.85 + vtpmdb_add_instance $1 $2 4.86 + xenstore-write backend/vtpm/$domid/0/instance $2 4.87 + fi 4.88 +}
5.1 --- a/tools/examples/vtpm-impl Mon Jul 10 17:33:45 2006 +0100 5.2 +++ b/tools/examples/vtpm-impl Mon Jul 10 17:36:41 2006 +0100 5.3 @@ -32,8 +32,6 @@ 5.4 # OF THE POSSIBILITY OF SUCH DAMAGE. 5.5 # =================================================================== 5.6 5.7 -VTPM_IMPL_DEFINED=1 5.8 - 5.9 # | SRC | TAG | CMD SIZE | ORD | type| mode 5.10 TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x01\\x01 5.11 TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x01\\x02