Index: xen/xen-unstable.hg/tools/xm-test/configure.ac =================================================================== --- xen.orig/xen-unstable.hg/tools/xm-test/configure.ac +++ xen/xen-unstable.hg/tools/xm-test/configure.ac @@ -93,6 +93,7 @@ AC_CONFIG_FILES([ tests/unpause/Makefile tests/vcpu-pin/Makefile tests/vcpu-disable/Makefile + tests/vtpm/Makefile tests/enforce_dom0_cpus/Makefile lib/XmTestReport/xmtest.py lib/XmTestLib/config.py Index: xen/xen-unstable.hg/tools/xm-test/tests/Makefile.am =================================================================== --- xen.orig/xen-unstable.hg/tools/xm-test/tests/Makefile.am +++ xen/xen-unstable.hg/tools/xm-test/tests/Makefile.am @@ -23,6 +23,7 @@ SUBDIRS = \ unpause \ vcpu-disable \ vcpu-pin \ + vtpm \ enforce_dom0_cpus \ save restore migrate Index: xen/xen-unstable.hg/tools/xm-test/tests/vtpm/Makefile.am =================================================================== --- /dev/null +++ xen/xen-unstable.hg/tools/xm-test/tests/vtpm/Makefile.am @@ -0,0 +1,22 @@ + +SUBDIRS = + +TESTS = 01_vtpm-list_pos.test \ + 02_vtpm-cat_pcrs.test + +XFAIL_TESTS = + +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) + +TESTS_ENVIRONMENT=@TENV@ + +%.test: %.py + cp $< $@ + chmod +x $@ + +clean-local: am_config_clean-local + +am_config_clean-local: + rm -f *test + rm -f *log + rm -f *~ Index: xen/xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenDomain.py =================================================================== --- xen.orig/xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenDomain.py +++ xen/xen-unstable.hg/tools/xm-test/lib/XmTestLib/XenDomain.py @@ -99,6 +99,7 @@ class XenConfig: # These options need to be lists self.defaultOpts["disk"] = [] self.defaultOpts["vif"] = [] + self.defaultOpts["vtpm"] = [] self.opts = self.defaultOpts Index: xen/xen-unstable.hg/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py =================================================================== --- /dev/null +++ xen/xen-unstable.hg/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +# Copyright (C) International Business Machines Corp., 2006 +# Author: Stefan Berger > $VTPMDB echo "#2nd column: TPM instance number" >> $VTPMDB fi - validate_entry $vmname $inst - if [ $? -eq 0 ]; then + vtpmdb_validate_entry $vmname $inst + if [ $res -eq 0 ]; then echo "$vmname $inst" >> $VTPMDB fi } @@ -168,11 +170,10 @@ function add_instance () { #Validate whether an entry is the same as passed to this #function -function validate_entry () { +function vtpmdb_validate_entry () { local rc=0 local vmname=$1 local inst=$2 - local res res=`cat $VTPMDB | \ gawk -vvmname=$vmname \ @@ -197,13 +198,15 @@ function validate_entry () { elif [ "$res" == "2" ]; then let rc=2 fi - return $rc + res=$rc } #Remove an entry from the vTPM database given its domain name -function remove_entry () { +#and instance number +function vtpmdb_remove_entry () { local vmname=$1 + local instance=$2 local VTPMDB_TMP="$VTPMDB".tmp `cat $VTPMDB | \ gawk -vvmname=$vmname \ @@ -214,6 +217,7 @@ function remove_entry () { '} > $VTPMDB_TMP` if [ -e $VTPMDB_TMP ]; then mv -f $VTPMDB_TMP $VTPMDB + vtpm_delete $instance else log err "Error creating temporary file '$VTPMDB_TMP'." fi @@ -222,7 +226,7 @@ function remove_entry () { # Find the reason for the creation of this device: # Set global REASON variable to 'resume' or 'create' -function get_create_reason () { +function vtpm_get_create_reason () { local resume=$(xenstore-read $XENBUS_PATH/resume) if [ "$resume" == "True" ]; then REASON="resume" @@ -237,26 +241,22 @@ function get_create_reason () { function vtpm_create_instance () { local domname=$(xenstore_read "$XENBUS_PATH"/domain) local res - set +e - get_create_reason + vtpm_get_create_reason claim_lock vtpmdb - - find_instance $domname - res=$? + vtpmdb_find_instance $domname if [ $res -eq 0 ]; then #Try to give the preferred instance to the domain instance=$(xenstore_read "$XENBUS_PATH"/pref_instance) if [ "$instance" != "" ]; then - is_free_instancenum $instance - res=$? + vtpmdb_is_free_instancenum $instance if [ $res -eq 0 ]; then - get_free_instancenum + vtpmdb_get_free_instancenum fi else - get_free_instancenum + vtpmdb_get_free_instancenum fi - add_instance $domname $instance + vtpmdb_add_instance $domname $instance if [ "$REASON" == "create" ]; then vtpm_create $instance elif [ "$REASON" == "resume" ]; then @@ -279,25 +279,35 @@ function vtpm_create_instance () { true fi xenstore_write $XENBUS_PATH/instance $instance - set -e } #Remove an instance function vtpm_remove_instance () { local domname=$(xenstore_read "$XENBUS_PATH"/domain) - set +e - find_instance $domname - res=$? + vtpmdb_find_instance $domname if [ $res -eq 0 ]; then - #Something is really wrong with the DB + #Something is really wrong with the VTPMDB log err "vTPM DB file $VTPMDB has no entry for '$domname'" else if [ "$REASON" == "suspend" ]; then vtpm_suspend $instance fi fi - set -e } +#Remove a entry in the directory given the domain's name +#1st parameter: The name of the domain +function vtpm_delete_instance () { + local rc + + claim_lock vtpmdb + + vtpmdb_find_instance $1 + if [ $res -ne 0 ]; then + vtpmdb_remove_entry $1 $instance + fi + + release_lock vtpmdb +} Index: xen/xen-unstable.hg/tools/examples/vtpm-delete =================================================================== --- /dev/null +++ xen/xen-unstable.hg/tools/examples/vtpm-delete @@ -0,0 +1,18 @@ +#!/bin/sh + +# This scripts must be called the following way: +# vtpm-delete + +if [ $1 != "remove" ]; then + exec sh -c "bash $0 remove $*" +fi + + +XENBUS_PATH=" " + +dir=$(dirname "$0") +. "$dir/vtpm-common.sh" + +shift + +vtpm_delete_instance $1