ia64/xen-unstable

changeset 15609:c1deef05c354

[VTPM] Make vTPM hotplug scripts use the UUID of the vTPM instance

Make the vTPM hotplug script use the UUID of the vTPM instance for
associating it with its instance number rather than the name of the
domain.
Also change the cleanup in the xm test to use the atexit mechanism
rather than explicitly calling a function to clean up.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kfraser@localhost.localdomain
date Tue Jul 17 10:33:26 2007 +0100 (2007-07-17)
parents 9559ba7c80f9
children ee7a5ddc1847
files tools/examples/vtpm-common.sh tools/python/xen/xend/XendDevices.py tools/python/xen/xend/server/tpmif.py tools/xm-test/tests/vtpm/01_vtpm-list_pos.py tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py tools/xm-test/tests/vtpm/03_vtpm-susp_res.py tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py tools/xm-test/tests/vtpm/vtpm_utils.py
line diff
     1.1 --- a/tools/examples/vtpm-common.sh	Tue Jul 17 10:20:21 2007 +0100
     1.2 +++ b/tools/examples/vtpm-common.sh	Tue Jul 17 10:33:26 2007 +0100
     1.3 @@ -20,7 +20,7 @@ dir=$(dirname "$0")
     1.4  . "$dir/logging.sh"
     1.5  . "$dir/locking.sh"
     1.6  
     1.7 -VTPMDB="/etc/xen/vtpm.db"
     1.8 +VTPMDB="/var/vtpm/vtpm.db"
     1.9  
    1.10  #In the vtpm-impl file some commands should be defined:
    1.11  #      vtpm_create, vtpm_setup, vtpm_start, etc. (see below)
    1.12 @@ -241,12 +241,21 @@ function vtpm_get_create_reason () {
    1.13  # If no entry in the TPM database is found, the instance is
    1.14  # created and an entry added to the database.
    1.15  function vtpm_create_instance () {
    1.16 -	local res instance domname reason
    1.17 -	domname=$(xenstore_read "$XENBUS_PATH"/domain)
    1.18 +	local res instance domname reason uuid
    1.19 +	uuid=$(xenstore_read "$XENBUS_PATH"/uuid)
    1.20  	reason=$(vtpm_get_create_reason)
    1.21  
    1.22  	claim_lock vtpmdb
    1.23 -	instance=$(vtpmdb_find_instance $domname)
    1.24 +
    1.25 +	instance="0"
    1.26 +
    1.27 +	if [ "$uuid" != "" ]; then
    1.28 +		instance=$(vtpmdb_find_instance $uuid)
    1.29 +	fi
    1.30 +	if [ "$instance" == "0" ]; then
    1.31 +		domname=$(xenstore_read "$XENBUS_PATH"/domain)
    1.32 +		instance=$(vtpmdb_find_instance $domname)
    1.33 +	fi
    1.34  
    1.35  	if [ "$instance" == "0" -a "$reason" != "create" ]; then
    1.36  		release_lock vtpmdb
    1.37 @@ -268,7 +277,11 @@ function vtpm_create_instance () {
    1.38  		vtpm_create $instance
    1.39  
    1.40  		if [ $vtpm_fatal_error -eq 0 ]; then
    1.41 -			vtpmdb_add_instance $domname $instance
    1.42 +			if [ "$uuid" != "" ]; then
    1.43 +				vtpmdb_add_instance $uuid $instance
    1.44 +			else
    1.45 +				vtpmdb_add_instance $domname $instance
    1.46 +			fi
    1.47  		fi
    1.48  	else
    1.49  		if [ "$reason" == "resume" ]; then
    1.50 @@ -288,22 +301,29 @@ function vtpm_create_instance () {
    1.51  #Since it is assumed that the VM will appear again, the
    1.52  #entry is kept in the VTPMDB file.
    1.53  function vtpm_remove_instance () {
    1.54 -	local instance reason domname
    1.55 +	local instance reason domname uuid
    1.56  	#Stop script execution quietly if path does not exist (anymore)
    1.57  	xenstore-exists "$XENBUS_PATH"/domain
    1.58 -	domname=$(xenstore_read "$XENBUS_PATH"/domain)
    1.59 +	uuid=$(xenstore_read "$XENBUS_PATH"/uuid)
    1.60 +
    1.61 +	claim_lock vtpmdb
    1.62  
    1.63 -	if [ "$domname" != "" ]; then
    1.64 -		claim_lock vtpmdb
    1.65 +	instance="0"
    1.66  
    1.67 -		instance=$(vtpmdb_find_instance $domname)
    1.68 +	if [ "$uuid != "" ]; then
    1.69 +		instance=$(vtpmdb_find_instance $uuid)
    1.70 +	fi
    1.71  
    1.72 -		if [ "$instance" != "0" ]; then
    1.73 -			vtpm_suspend $instance
    1.74 -		fi
    1.75 +	if [ "$instance == "0" ]; then
    1.76 +		domname=$(xenstore_read "$XENBUS_PATH"/domain)
    1.77 +		instance=$(vtpmdb_find_instance $domname)
    1.78 +	fi
    1.79  
    1.80 -		release_lock vtpmdb
    1.81 +	if [ "$instance" != "0" ]; then
    1.82 +		vtpm_suspend $instance
    1.83  	fi
    1.84 +
    1.85 +	release_lock vtpmdb
    1.86  }
    1.87  
    1.88  
     2.1 --- a/tools/python/xen/xend/XendDevices.py	Tue Jul 17 10:20:21 2007 +0100
     2.2 +++ b/tools/python/xen/xend/XendDevices.py	Tue Jul 17 10:33:26 2007 +0100
     2.3 @@ -78,6 +78,7 @@ class XendDevices:
     2.4          @param domain: domain this controller is handling devices for.
     2.5          @type domain: XendDomainInfo
     2.6          """
     2.7 -        tpmif.destroy_vtpmstate(domain.getName())
     2.8 +        from xen.xend.XendLogging import log
     2.9 +        tpmif.destroy_vtpmstate(domain.info.get('vtpm_refs'))
    2.10  
    2.11      destroy_device_state = classmethod(destroy_device_state)
     3.1 --- a/tools/python/xen/xend/server/tpmif.py	Tue Jul 17 10:20:21 2007 +0100
     3.2 +++ b/tools/python/xen/xend/server/tpmif.py	Tue Jul 17 10:33:26 2007 +0100
     3.3 @@ -31,9 +31,10 @@ import re
     3.4  
     3.5  xoptions = XendOptions.instance()
     3.6  
     3.7 -def destroy_vtpmstate(name):
     3.8 +def destroy_vtpmstate(uuids):
     3.9      if os.path.exists(VTPM_DELETE_SCRIPT):
    3.10 -        os.system(VTPM_DELETE_SCRIPT + " " + name)
    3.11 +        for uuid in uuids:
    3.12 +            os.system(VTPM_DELETE_SCRIPT + " " + uuid)
    3.13  
    3.14  class TPMifController(DevController):
    3.15      """TPM interface controller. Handles all TPM devices for a domain.
     4.1 --- a/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py	Tue Jul 17 10:20:21 2007 +0100
     4.2 +++ b/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py	Tue Jul 17 10:33:26 2007 +0100
     4.3 @@ -11,6 +11,7 @@ from XmTestLib import *
     4.4  from vtpm_utils import *
     4.5  import commands
     4.6  import os
     4.7 +import atexit
     4.8  
     4.9  config = {"vtpm":"instance=1,backend=0"}
    4.10  domain = XmTestDomain(extraConfig=config)
    4.11 @@ -23,18 +24,17 @@ except DomainError, e:
    4.12      vtpm_cleanup(domain.getName())
    4.13      FAIL("Unable to create domain")
    4.14  
    4.15 +
    4.16  domName = domain.getName()
    4.17  
    4.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    4.19 +
    4.20  status, output = traceCommand("xm vtpm-list %s" % domain.getId())
    4.21  eyecatcher = "/local/domain/0/backend/vtpm"
    4.22  where = output.find(eyecatcher)
    4.23  if status != 0:
    4.24 -    vtpm_cleanup(domName)
    4.25      FAIL("xm vtpm-list returned bad status, expected 0, status is %i" % status)
    4.26  elif where < 0:
    4.27 -    vtpm_cleanup(domName)
    4.28      FAIL("Fail to list virtual TPM device")
    4.29  
    4.30  domain.stop()
    4.31 -
    4.32 -vtpm_cleanup(domName)
     5.1 --- a/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py	Tue Jul 17 10:20:21 2007 +0100
     5.2 +++ b/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py	Tue Jul 17 10:33:26 2007 +0100
     5.3 @@ -11,6 +11,7 @@ from vtpm_utils import *
     5.4  import commands
     5.5  import os
     5.6  import os.path
     5.7 +import atexit
     5.8  
     5.9  config = {"vtpm":"instance=1,backend=0"}
    5.10  domain = XmTestDomain(extraConfig=config)
    5.11 @@ -21,32 +22,28 @@ try:
    5.12  except DomainError, e:
    5.13      if verbose:
    5.14          print e.extra
    5.15 -    vtpm_cleanup(domName)
    5.16      FAIL("Unable to create domain (%s)" % domName)
    5.17  
    5.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    5.19 +
    5.20  try:
    5.21      console.sendInput("input")
    5.22  except ConsoleError, e:
    5.23      saveLog(console.getHistory())
    5.24 -    vtpm_cleanup(domName)
    5.25      FAIL(str(e))
    5.26  
    5.27  try:
    5.28      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    5.29  except ConsoleError, e:
    5.30      saveLog(console.getHistory())
    5.31 -    vtpm_cleanup(domName)
    5.32      FAIL("No result from dumping the PCRs")
    5.33  
    5.34  if re.search("No such file",run["output"]):
    5.35 -    vtpm_cleanup(domName)
    5.36      FAIL("TPM frontend support not compiled into (domU?) kernel")
    5.37  
    5.38  domain.closeConsole()
    5.39  
    5.40  domain.stop()
    5.41  
    5.42 -vtpm_cleanup(domName)
    5.43 -
    5.44  if not re.search("PCR-00:",run["output"]):
    5.45      FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
     6.1 --- a/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py	Tue Jul 17 10:20:21 2007 +0100
     6.2 +++ b/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py	Tue Jul 17 10:33:26 2007 +0100
     6.3 @@ -12,6 +12,7 @@ from vtpm_utils import *
     6.4  import commands
     6.5  import os
     6.6  import os.path
     6.7 +import atexit
     6.8  
     6.9  config = {"vtpm":"instance=1,backend=0"}
    6.10  domain = XmTestDomain(extraConfig=config)
    6.11 @@ -23,25 +24,23 @@ try:
    6.12  except DomainError, e:
    6.13      if verbose:
    6.14          print e.extra
    6.15 -    vtpm_cleanup(domName)
    6.16      FAIL("Unable to create domain (%s)" % domName)
    6.17  
    6.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    6.19 +
    6.20  try:
    6.21      console.sendInput("input")
    6.22  except ConsoleError, e:
    6.23      saveLog(console.getHistory())
    6.24 -    vtpm_cleanup(domName)
    6.25      FAIL(str(e))
    6.26  
    6.27  try:
    6.28      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    6.29  except ConsoleError, e:
    6.30      saveLog(console.getHistory())
    6.31 -    vtpm_cleanup(domName)
    6.32      FAIL("No result from dumping the PCRs")
    6.33  
    6.34  if re.search("No such file",run["output"]):
    6.35 -    vtpm_cleanup(domName)
    6.36      FAIL("TPM frontend support not compiled into (domU?) kernel")
    6.37  
    6.38  consoleHistory = console.getHistory()
    6.39 @@ -56,12 +55,10 @@ while loop < 3:
    6.40  
    6.41      except TimeoutError, e:
    6.42          saveLog(consoleHistory)
    6.43 -        vtpm_cleanup(domName)
    6.44          FAIL(str(e))
    6.45  
    6.46      if status != 0:
    6.47          saveLog(consoleHistory)
    6.48 -        vtpm_cleanup(domName)
    6.49          FAIL("xm save did not succeed")
    6.50  
    6.51      try:
    6.52 @@ -71,32 +68,27 @@ while loop < 3:
    6.53      except TimeoutError, e:
    6.54          os.remove("%s.save" % domName)
    6.55          saveLog(consoleHistory)
    6.56 -        vtpm_cleanup(domName)
    6.57          FAIL(str(e))
    6.58  
    6.59      os.remove("%s.save" % domName)
    6.60  
    6.61      if status != 0:
    6.62          saveLog(consoleHistory)
    6.63 -        vtpm_cleanup(domName)
    6.64          FAIL("xm restore did not succeed")
    6.65  
    6.66      try:
    6.67          console = domain.getConsole()
    6.68      except ConsoleError, e:
    6.69 -        vtpm_cleanup(domName)
    6.70          FAIL(str(e))
    6.71  
    6.72      try:
    6.73          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    6.74      except ConsoleError, e:
    6.75          saveLog(console.getHistory())
    6.76 -        vtpm_cleanup(domName)
    6.77          FAIL(str(e))
    6.78  
    6.79      if not re.search("PCR-00:",run["output"]):
    6.80          saveLog(console.getHistory())
    6.81 -        vtpm_cleanup(domName)
    6.82          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
    6.83  
    6.84      loop += 1
    6.85 @@ -105,5 +97,3 @@ domain.closeConsole()
    6.86  
    6.87  domain.stop()
    6.88  
    6.89 -vtpm_cleanup(domName)
    6.90 -
     7.1 --- a/tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py	Tue Jul 17 10:20:21 2007 +0100
     7.2 +++ b/tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py	Tue Jul 17 10:33:26 2007 +0100
     7.3 @@ -13,6 +13,7 @@ from vtpm_utils import *
     7.4  import commands
     7.5  import os
     7.6  import os.path
     7.7 +import atexit
     7.8  
     7.9  config = {"vtpm":"instance=1,backend=0"}
    7.10  domain = XmTestDomain(extraConfig=config)
    7.11 @@ -24,25 +25,23 @@ try:
    7.12  except DomainError, e:
    7.13      if verbose:
    7.14          print e.extra
    7.15 -    vtpm_cleanup(domName)
    7.16      FAIL("Unable to create domain (%s)" % domName)
    7.17  
    7.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    7.19 +
    7.20  try:
    7.21      console.sendInput("input")
    7.22  except ConsoleError, e:
    7.23      saveLog(console.getHistory())
    7.24 -    vtpm_cleanup(domName)
    7.25      FAIL(str(e))
    7.26  
    7.27  try:
    7.28      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    7.29  except ConsoleError, e:
    7.30      saveLog(console.getHistory())
    7.31 -    vtpm_cleanup(domName)
    7.32      FAIL("No result from dumping the PCRs")
    7.33  
    7.34  if re.search("No such file",run["output"]):
    7.35 -    vtpm_cleanup(domName)
    7.36      FAIL("TPM frontend support not compiled into (domU?) kernel")
    7.37  
    7.38  consoleHistory = console.getHistory()
    7.39 @@ -58,12 +57,10 @@ while loop < 3:
    7.40                                        timeout=90)
    7.41      except TimeoutError, e:
    7.42          saveLog(consoleHistory)
    7.43 -        vtpm_cleanup(domName)
    7.44          FAIL(str(e))
    7.45  
    7.46      if status != 0:
    7.47          saveLog(consoleHistory)
    7.48 -        vtpm_cleanup(domName)
    7.49          FAIL("xm migrate did not succeed. External device migration activated?")
    7.50  
    7.51  
    7.52 @@ -71,26 +68,22 @@ while loop < 3:
    7.53      new_domid = domid(domName)
    7.54  
    7.55      if (old_domid == new_domid):
    7.56 -        vtpm_cleanup(domName)
    7.57          FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
    7.58               (old_domid,loop))
    7.59  
    7.60      try:
    7.61          console = domain.getConsole()
    7.62      except ConsoleError, e:
    7.63 -        vtpm_cleanup(domName)
    7.64          FAIL(str(e))
    7.65  
    7.66      try:
    7.67          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    7.68      except ConsoleError, e:
    7.69          saveLog(console.getHistory())
    7.70 -        vtpm_cleanup(domName)
    7.71          FAIL("No result from dumping the PCRs")
    7.72  
    7.73      if not re.search("PCR-00:",run["output"]):
    7.74          saveLog(console.getHistory())
    7.75 -        vtpm_cleanup(domName)
    7.76          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
    7.77  
    7.78      loop += 1
    7.79 @@ -98,5 +91,3 @@ while loop < 3:
    7.80  domain.closeConsole()
    7.81  
    7.82  domain.stop()
    7.83 -
    7.84 -vtpm_cleanup(domName)
     8.1 --- a/tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py	Tue Jul 17 10:20:21 2007 +0100
     8.2 +++ b/tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py	Tue Jul 17 10:33:26 2007 +0100
     8.3 @@ -13,6 +13,7 @@ from vtpm_utils import *
     8.4  import commands
     8.5  import os
     8.6  import os.path
     8.7 +import atexit
     8.8  
     8.9  config = {"vtpm":"instance=1,backend=0"}
    8.10  domain = XmTestDomain(extraConfig=config)
    8.11 @@ -24,25 +25,23 @@ try:
    8.12  except DomainError, e:
    8.13      if verbose:
    8.14          print e.extra
    8.15 -    vtpm_cleanup(domName)
    8.16      FAIL("Unable to create domain (%s)" % domName)
    8.17  
    8.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    8.19 +
    8.20  try:
    8.21      console.sendInput("input")
    8.22  except ConsoleError, e:
    8.23      saveLog(console.getHistory())
    8.24 -    vtpm_cleanup(domName)
    8.25      FAIL(str(e))
    8.26  
    8.27  try:
    8.28      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    8.29  except ConsoleError, e:
    8.30      saveLog(console.getHistory())
    8.31 -    vtpm_cleanup(domName)
    8.32      FAIL("No result from dumping the PCRs")
    8.33  
    8.34  if re.search("No such file",run["output"]):
    8.35 -    vtpm_cleanup(domName)
    8.36      FAIL("TPM frontend support not compiled into (domU?) kernel")
    8.37  
    8.38  consoleHistory = console.getHistory()
    8.39 @@ -58,12 +57,10 @@ while loop < 3:
    8.40                                        timeout=90)
    8.41      except TimeoutError, e:
    8.42          saveLog(consoleHistory)
    8.43 -        vtpm_cleanup(domName)
    8.44          FAIL(str(e))
    8.45  
    8.46      if status != 0:
    8.47          saveLog(consoleHistory)
    8.48 -        vtpm_cleanup(domName)
    8.49          FAIL("xm migrate did not succeed. External device migration activated?")
    8.50  
    8.51  
    8.52 @@ -71,26 +68,22 @@ while loop < 3:
    8.53      new_domid = domid(domName)
    8.54  
    8.55      if (old_domid == new_domid):
    8.56 -        vtpm_cleanup(domName)
    8.57          FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
    8.58               (old_domid,loop))
    8.59  
    8.60      try:
    8.61          console = domain.getConsole()
    8.62      except ConsoleError, e:
    8.63 -        vtpm_cleanup(domName)
    8.64          FAIL(str(e))
    8.65  
    8.66      try:
    8.67          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    8.68      except ConsoleError, e:
    8.69          saveLog(console.getHistory())
    8.70 -        vtpm_cleanup(domName)
    8.71          FAIL("No result from dumping the PCRs")
    8.72  
    8.73      if not re.search("PCR-00:",run["output"]):
    8.74          saveLog(console.getHistory())
    8.75 -        vtpm_cleanup(domName)
    8.76          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
    8.77  
    8.78      loop += 1
    8.79 @@ -98,5 +91,3 @@ while loop < 3:
    8.80  domain.closeConsole()
    8.81  
    8.82  domain.stop()
    8.83 -
    8.84 -vtpm_cleanup(domName)
     9.1 --- a/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py	Tue Jul 17 10:20:21 2007 +0100
     9.2 +++ b/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py	Tue Jul 17 10:33:26 2007 +0100
     9.3 @@ -13,6 +13,7 @@ from vtpm_utils import *
     9.4  import commands
     9.5  import os
     9.6  import os.path
     9.7 +import atexit
     9.8  
     9.9  config = {"vtpm":"instance=1,backend=0"}
    9.10  domain = XmTestDomain(extraConfig=config)
    9.11 @@ -24,45 +25,40 @@ try:
    9.12  except DomainError, e:
    9.13      if verbose:
    9.14          print e.extra
    9.15 -    vtpm_cleanup(domName)
    9.16      FAIL("Unable to create domain (%s)" % domName)
    9.17  
    9.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
    9.19 +
    9.20  try:
    9.21      console.sendInput("input")
    9.22  except ConsoleError, e:
    9.23      saveLog(console.getHistory())
    9.24 -    vtpm_cleanup(domName)
    9.25      FAIL(str(e))
    9.26  
    9.27  try:
    9.28      run = console.runCmd("mknod /dev/tpm0 c 10 224")
    9.29  except ConsoleError, e:
    9.30      saveLog(console.getHistory())
    9.31 -    vtpm_cleanup(domName)
    9.32      FAIL("Error while creating /dev/tpm0")
    9.33  
    9.34  try:
    9.35      run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
    9.36  except ConsoleError, e:
    9.37      saveLog(console.getHistory())
    9.38 -    vtpm_cleanup(domName)
    9.39      FAIL("Error while extending PCR 0")
    9.40  
    9.41  try:
    9.42      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    9.43  except ConsoleError, e:
    9.44      saveLog(console.getHistory())
    9.45 -    vtpm_cleanup(domName)
    9.46      FAIL("No result from dumping the PCRs")
    9.47  
    9.48  
    9.49  if re.search("No such file",run["output"]):
    9.50 -    vtpm_cleanup(domName)
    9.51      FAIL("TPM frontend support not compiled into (domU?) kernel")
    9.52  
    9.53  if not re.search("PCR-00:",run["output"]):
    9.54      saveLog(console.getHistory())
    9.55 -    vtpm_cleanup(domName)
    9.56      FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
    9.57  
    9.58  if not re.search("PCR-00: 1E A7 BD",run["output"]):
    9.59 @@ -81,12 +77,10 @@ while loop < 3:
    9.60  
    9.61      except TimeoutError, e:
    9.62          saveLog(consoleHistory)
    9.63 -        vtpm_cleanup(domName)
    9.64          FAIL(str(e))
    9.65  
    9.66      if status != 0:
    9.67          saveLog(consoleHistory)
    9.68 -        vtpm_cleanup(domName)
    9.69          FAIL("xm save did not succeed")
    9.70  
    9.71      try:
    9.72 @@ -96,37 +90,31 @@ while loop < 3:
    9.73      except TimeoutError, e:
    9.74          os.remove("%s.save" % domName)
    9.75          saveLog(consoleHistory)
    9.76 -        vtpm_cleanup(domName)
    9.77          FAIL(str(e))
    9.78  
    9.79      os.remove("%s.save" % domName)
    9.80  
    9.81      if status != 0:
    9.82          saveLog(consoleHistory)
    9.83 -        vtpm_cleanup(domName)
    9.84          FAIL("xm restore did not succeed")
    9.85  
    9.86      try:
    9.87          console = domain.getConsole()
    9.88      except ConsoleError, e:
    9.89 -        vtpm_cleanup(domName)
    9.90          FAIL(str(e))
    9.91  
    9.92      try:
    9.93          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    9.94      except ConsoleError, e:
    9.95          saveLog(console.getHistory())
    9.96 -        vtpm_cleanup(domName)
    9.97          FAIL(str(e))
    9.98  
    9.99      if not re.search("PCR-00:",run["output"]):
   9.100          saveLog(console.getHistory())
   9.101 -        vtpm_cleanup(domName)
   9.102          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
   9.103  
   9.104      if not re.search("PCR-00: 1E A7 BD",run["output"]):
   9.105          saveLog(console.getHistory())
   9.106 -        vtpm_cleanup(domName)
   9.107          FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
   9.108  
   9.109      loop += 1
   9.110 @@ -135,5 +123,3 @@ domain.closeConsole()
   9.111  
   9.112  domain.stop()
   9.113  
   9.114 -vtpm_cleanup(domName)
   9.115 -
    10.1 --- a/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py	Tue Jul 17 10:20:21 2007 +0100
    10.2 +++ b/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py	Tue Jul 17 10:33:26 2007 +0100
    10.3 @@ -14,6 +14,7 @@ from vtpm_utils import *
    10.4  import commands
    10.5  import os
    10.6  import os.path
    10.7 +import atexit
    10.8  
    10.9  config = {"vtpm":"instance=1,backend=0"}
   10.10  domain = XmTestDomain(extraConfig=config)
   10.11 @@ -25,45 +26,40 @@ try:
   10.12  except DomainError, e:
   10.13      if verbose:
   10.14          print e.extra
   10.15 -    vtpm_cleanup(domName)
   10.16      FAIL("Unable to create domain (%s)" % domName)
   10.17  
   10.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
   10.19 +
   10.20  try:
   10.21      console.sendInput("input")
   10.22  except ConsoleError, e:
   10.23      saveLog(console.getHistory())
   10.24 -    vtpm_cleanup(domName)
   10.25      FAIL(str(e))
   10.26  
   10.27  try:
   10.28      run = console.runCmd("mknod /dev/tpm0 c 10 224")
   10.29  except ConsoleError, e:
   10.30      saveLog(console.getHistory())
   10.31 -    vtpm_cleanup(domName)
   10.32      FAIL("Error while creating /dev/tpm0")
   10.33  
   10.34  try:
   10.35      run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
   10.36  except ConsoleError, e:
   10.37      saveLog(console.getHistory())
   10.38 -    vtpm_cleanup(domName)
   10.39      FAIL("Error while extending PCR 0")
   10.40  
   10.41  try:
   10.42      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
   10.43  except ConsoleError, e:
   10.44      saveLog(console.getHistory())
   10.45 -    vtpm_cleanup(domName)
   10.46      FAIL("No result from dumping the PCRs")
   10.47  
   10.48  
   10.49  if re.search("No such file",run["output"]):
   10.50 -    vtpm_cleanup(domName)
   10.51      FAIL("TPM frontend support not compiled into (domU?) kernel")
   10.52  
   10.53  if not re.search("PCR-00:",run["output"]):
   10.54      saveLog(console.getHistory())
   10.55 -    vtpm_cleanup(domName)
   10.56      FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
   10.57  
   10.58  if not re.search("PCR-00: 1E A7 BD",run["output"]):
   10.59 @@ -83,12 +79,10 @@ while loop < 3:
   10.60                                        timeout=90)
   10.61      except TimeoutError, e:
   10.62          saveLog(consoleHistory)
   10.63 -        vtpm_cleanup(domName)
   10.64          FAIL(str(e))
   10.65  
   10.66      if status != 0:
   10.67          saveLog(consoleHistory)
   10.68 -        vtpm_cleanup(domName)
   10.69          FAIL("xm migrate did not succeed. External device migration activated?")
   10.70  
   10.71  
   10.72 @@ -96,31 +90,26 @@ while loop < 3:
   10.73      new_domid = domid(domName)
   10.74  
   10.75      if (old_domid == new_domid):
   10.76 -        vtpm_cleanup(domName)
   10.77          FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
   10.78               (old_domid,loop))
   10.79  
   10.80      try:
   10.81          console = domain.getConsole()
   10.82      except ConsoleError, e:
   10.83 -        vtpm_cleanup(domName)
   10.84          FAIL(str(e))
   10.85  
   10.86      try:
   10.87          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
   10.88      except ConsoleError, e:
   10.89          saveLog(console.getHistory())
   10.90 -        vtpm_cleanup(domName)
   10.91          FAIL("No result from dumping the PCRs")
   10.92  
   10.93      if not re.search("PCR-00:",run["output"]):
   10.94          saveLog(console.getHistory())
   10.95 -        vtpm_cleanup(domName)
   10.96          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
   10.97  
   10.98      if not re.search("PCR-00: 1E A7 BD",run["output"]):
   10.99          saveLog(console.getHistory())
  10.100 -        vtpm_cleanup(domName)
  10.101          FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
  10.102  
  10.103      loop += 1
  10.104 @@ -128,5 +117,3 @@ while loop < 3:
  10.105  domain.closeConsole()
  10.106  
  10.107  domain.stop()
  10.108 -
  10.109 -vtpm_cleanup(domName)
    11.1 --- a/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py	Tue Jul 17 10:20:21 2007 +0100
    11.2 +++ b/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py	Tue Jul 17 10:33:26 2007 +0100
    11.3 @@ -14,6 +14,7 @@ from vtpm_utils import *
    11.4  import commands
    11.5  import os
    11.6  import os.path
    11.7 +import atexit
    11.8  
    11.9  config = {"vtpm":"instance=1,backend=0"}
   11.10  domain = XmTestDomain(extraConfig=config)
   11.11 @@ -25,45 +26,40 @@ try:
   11.12  except DomainError, e:
   11.13      if verbose:
   11.14          print e.extra
   11.15 -    vtpm_cleanup(domName)
   11.16      FAIL("Unable to create domain (%s)" % domName)
   11.17  
   11.18 +atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
   11.19 +
   11.20  try:
   11.21      console.sendInput("input")
   11.22  except ConsoleError, e:
   11.23      saveLog(console.getHistory())
   11.24 -    vtpm_cleanup(domName)
   11.25      FAIL(str(e))
   11.26  
   11.27  try:
   11.28      run = console.runCmd("mknod /dev/tpm0 c 10 224")
   11.29  except ConsoleError, e:
   11.30      saveLog(console.getHistory())
   11.31 -    vtpm_cleanup(domName)
   11.32      FAIL("Error while creating /dev/tpm0")
   11.33  
   11.34  try:
   11.35      run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
   11.36  except ConsoleError, e:
   11.37      saveLog(console.getHistory())
   11.38 -    vtpm_cleanup(domName)
   11.39      FAIL("Error while extending PCR 0")
   11.40  
   11.41  try:
   11.42      run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
   11.43  except ConsoleError, e:
   11.44      saveLog(console.getHistory())
   11.45 -    vtpm_cleanup(domName)
   11.46      FAIL("No result from dumping the PCRs")
   11.47  
   11.48  
   11.49  if re.search("No such file",run["output"]):
   11.50 -    vtpm_cleanup(domName)
   11.51      FAIL("TPM frontend support not compiled into (domU?) kernel")
   11.52  
   11.53  if not re.search("PCR-00:",run["output"]):
   11.54      saveLog(console.getHistory())
   11.55 -    vtpm_cleanup(domName)
   11.56      FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
   11.57  
   11.58  if not re.search("PCR-00: 1E A7 BD",run["output"]):
   11.59 @@ -83,12 +79,10 @@ while loop < 3:
   11.60                                        timeout=90)
   11.61      except TimeoutError, e:
   11.62          saveLog(consoleHistory)
   11.63 -        vtpm_cleanup(domName)
   11.64          FAIL(str(e))
   11.65  
   11.66      if status != 0:
   11.67          saveLog(consoleHistory)
   11.68 -        vtpm_cleanup(domName)
   11.69          FAIL("xm migrate did not succeed. External device migration activated?")
   11.70  
   11.71  
   11.72 @@ -96,31 +90,26 @@ while loop < 3:
   11.73      new_domid = domid(domName)
   11.74  
   11.75      if (old_domid == new_domid):
   11.76 -        vtpm_cleanup(domName)
   11.77          FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
   11.78               (old_domid,loop))
   11.79  
   11.80      try:
   11.81          console = domain.getConsole()
   11.82      except ConsoleError, e:
   11.83 -        vtpm_cleanup(domName)
   11.84          FAIL(str(e))
   11.85  
   11.86      try:
   11.87          run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
   11.88      except ConsoleError, e:
   11.89          saveLog(console.getHistory())
   11.90 -        vtpm_cleanup(domName)
   11.91          FAIL("No result from dumping the PCRs")
   11.92  
   11.93      if not re.search("PCR-00:",run["output"]):
   11.94          saveLog(console.getHistory())
   11.95 -        vtpm_cleanup(domName)
   11.96          FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
   11.97  
   11.98      if not re.search("PCR-00: 1E A7 BD",run["output"]):
   11.99          saveLog(console.getHistory())
  11.100 -        vtpm_cleanup(domName)
  11.101          FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
  11.102  
  11.103      loop += 1
  11.104 @@ -128,5 +117,3 @@ while loop < 3:
  11.105  domain.closeConsole()
  11.106  
  11.107  domain.stop()
  11.108 -
  11.109 -vtpm_cleanup(domName)
    12.1 --- a/tools/xm-test/tests/vtpm/vtpm_utils.py	Tue Jul 17 10:20:21 2007 +0100
    12.2 +++ b/tools/xm-test/tests/vtpm/vtpm_utils.py	Tue Jul 17 10:33:26 2007 +0100
    12.3 @@ -15,4 +15,16 @@ if output == "":
    12.4           "need /dev/tpm0")
    12.5  
    12.6  def vtpm_cleanup(domName):
    12.7 -    traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
    12.8 +    traceCommand("/etc/xen/scripts/vtpm-delete "
    12.9 +                 "`xenstore-read /local/domain/0/backend/vtpm/%s/0/uuid`" %
   12.10 +                 str(domid(domName)))
   12.11 +
   12.12 +def vtpm_cleanup(uuid):
   12.13 +    from xen.xm import main
   12.14 +    if main.serverType != main.SERVER_XEN_API:
   12.15 +        traceCommand("/etc/xen/scripts/vtpm-delete %s" % uuid)
   12.16 +
   12.17 +def vtpm_get_uuid(domainid):
   12.18 +    s, o = traceCommand("xenstore-read "
   12.19 +                        "/local/domain/0/backend/vtpm/%s/0/uuid" % domainid)
   12.20 +    return o