From: Stefan Berger Subject: [PATCH] [vtpm] script function for identifying vTPM by its UUID Date: Mon, 25 Feb 2008 12:31:54 -0500 Message-ID: <1203960714.24238.6.camel@gsal-3.watson.ibm.com> Reply-To: stefanb@us.ibm.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-smue5vT9hAnevRUAW0IM" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org --=-smue5vT9hAnevRUAW0IM Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-smue5vT9hAnevRUAW0IM Content-Disposition: attachment; filename=vtpm_scripts_functions_use_uuid.diff Content-Type: text/x-vhdl; name=vtpm_scripts_functions_use_uuid.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit --- xen-unstable.hg/tools/examples/vtpm-common.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) Index: root/xen-unstable.hg/tools/examples/vtpm-common.sh =================================================================== --- root.orig/xen-unstable.hg/tools/examples/vtpm-common.sh +++ root/xen-unstable.hg/tools/examples/vtpm-common.sh @@ -407,7 +407,7 @@ function vtpm_domid_from_name () { local id name ids ids=$(xenstore-list /local/domain) for id in $ids; do - name=$(xenstore_read /local/domain/$id/name) + name=$(xenstore-read /local/domain/$id/name) if [ "$name" == "$1" ]; then echo "$id" return @@ -416,16 +416,33 @@ function vtpm_domid_from_name () { echo "-1" } +#Determine the virtual TPM's instance number using the domain ID. +#1st parm: domain ID +function vtpm_uuid_by_domid() { + echo $(xenstore-read /local/domain/0/backend/vtpm/$1/0/uuid) +} + + +# Determine the vTPM's UUID by the name of the VM +function vtpm_uuid_from_vmname() { + local domid=$(vtpm_domid_from_name $1) + if [ "$domid" != "-1" ]; then + echo $(vtpm_uuid_by_domid $domid) + return + fi + echo "" +} #Add a virtual TPM instance number and its associated domain name #to the VTPMDB file and activate usage of this virtual TPM instance #by writing the instance number into the xenstore #1st parm: name of virtual machine -#2nd parm: instance of assoicate virtual TPM +#2nd parm: instance of associated virtual TPM function vtpm_add_and_activate() { local domid=$(vtpm_domid_from_name $1) - if [ "$domid" != "-1" ]; then - vtpmdb_add_instance $1 $2 + local vtpm_uuid=$(vtpm_uuid_from_vmname $1) + if [ "$vtpm_uuid" != "" -a "$domid" != "-1" ]; then + vtpmdb_add_instance $vtpm_uuid $2 xenstore-write backend/vtpm/$domid/0/instance $2 fi } Index: root/xen-unstable.hg/tools/examples/vtpm-delete =================================================================== --- root.orig/xen-unstable.hg/tools/examples/vtpm-delete +++ root/xen-unstable.hg/tools/examples/vtpm-delete @@ -1,9 +1,18 @@ #!/bin/bash # This scripts must be called the following way: -# vtpm-delete +# vtpm-delete +# or +# vtpm-delete --vmname dir=$(dirname "$0") . "$dir/vtpm-common.sh" -vtpm_delete_instance $1 +if [ "$1" == "--vmname" ]; then + vtpm_uuid=$(vtpm_uuid_from_vmname $2) + if [ "$vtpm_uuid" != "" ];then + vtpm_delete_instance $vtpm_uuid + fi +else + vtpm_delete_instance $1 +fi --=-smue5vT9hAnevRUAW0IM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-smue5vT9hAnevRUAW0IM--