ia64/xen-unstable

changeset 17116:b6323bf8dae0

vtpm: script function for identifying vTPM by its UUID

I am adding some functions for external tools to call the vTPM scripts.
It also contains a fix for the functions that previously used to be
called by domain name, but now are using the vTPM's uuid as parameter.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 26 14:34:50 2008 +0000 (2008-02-26)
parents d34e99141506
children 9dd235d6174d
files tools/examples/vtpm-common.sh tools/examples/vtpm-delete
line diff
     1.1 --- a/tools/examples/vtpm-common.sh	Mon Feb 25 16:34:49 2008 +0000
     1.2 +++ b/tools/examples/vtpm-common.sh	Tue Feb 26 14:34:50 2008 +0000
     1.3 @@ -407,7 +407,7 @@ function vtpm_domid_from_name () {
     1.4  	local id name ids
     1.5  	ids=$(xenstore-list /local/domain)
     1.6  	for id in $ids; do
     1.7 -		name=$(xenstore_read /local/domain/$id/name)
     1.8 +		name=$(xenstore-read /local/domain/$id/name)
     1.9  		if [ "$name" == "$1" ]; then
    1.10  			echo "$id"
    1.11  			return
    1.12 @@ -416,16 +416,33 @@ function vtpm_domid_from_name () {
    1.13  	echo "-1"
    1.14  }
    1.15  
    1.16 +#Determine the virtual TPM's instance number using the domain ID.
    1.17 +#1st parm: domain ID
    1.18 +function vtpm_uuid_by_domid() {
    1.19 +	echo $(xenstore-read /local/domain/0/backend/vtpm/$1/0/uuid)
    1.20 +}
    1.21 +
    1.22 +
    1.23 +# Determine the vTPM's UUID by the name of the VM
    1.24 +function vtpm_uuid_from_vmname() {
    1.25 +	local domid=$(vtpm_domid_from_name $1)
    1.26 +	if [ "$domid" != "-1" ]; then
    1.27 +		echo $(vtpm_uuid_by_domid $domid)
    1.28 +		return
    1.29 +	fi
    1.30 +	echo ""
    1.31 +}
    1.32  
    1.33  #Add a virtual TPM instance number and its associated domain name
    1.34  #to the VTPMDB file and activate usage of this virtual TPM instance
    1.35  #by writing the instance number into the xenstore
    1.36  #1st parm: name of virtual machine
    1.37 -#2nd parm: instance of assoicate virtual TPM
    1.38 +#2nd parm: instance of associated virtual TPM
    1.39  function vtpm_add_and_activate() {
    1.40  	local domid=$(vtpm_domid_from_name $1)
    1.41 -	if [ "$domid" != "-1" ]; then
    1.42 -		vtpmdb_add_instance $1 $2
    1.43 +	local vtpm_uuid=$(vtpm_uuid_from_vmname $1)
    1.44 +	if [ "$vtpm_uuid" != "" -a "$domid" != "-1" ]; then
    1.45 +		vtpmdb_add_instance $vtpm_uuid $2
    1.46  		xenstore-write backend/vtpm/$domid/0/instance $2
    1.47  	fi
    1.48  }
     2.1 --- a/tools/examples/vtpm-delete	Mon Feb 25 16:34:49 2008 +0000
     2.2 +++ b/tools/examples/vtpm-delete	Tue Feb 26 14:34:50 2008 +0000
     2.3 @@ -1,9 +1,18 @@
     2.4  #!/bin/bash
     2.5  
     2.6  # This scripts must be called the following way:
     2.7 -# vtpm-delete <domain name>
     2.8 +# vtpm-delete <vtpm uuid>
     2.9 +# or
    2.10 +# vtpm-delete --vmname <vm name>
    2.11  
    2.12  dir=$(dirname "$0")
    2.13  . "$dir/vtpm-common.sh"
    2.14  
    2.15 -vtpm_delete_instance $1
    2.16 +if [ "$1" == "--vmname" ]; then
    2.17 +	vtpm_uuid=$(vtpm_uuid_from_vmname $2)
    2.18 +	if [ "$vtpm_uuid" != "" ];then
    2.19 +		vtpm_delete_instance $vtpm_uuid
    2.20 +	fi
    2.21 +else
    2.22 +	vtpm_delete_instance $1
    2.23 +fi