Skip to contentSkip to conversation

Make vTPM hotplug scripts use the UUID of the vTPM instance

PATCH New Stefan Berger 1 participant 1 message Jul 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 xen-unstable.hg/tools/examples/vtpm-common.sh                     |   48 +++++++---
 xen-unstable.hg/tools/python/xen/xend/XendDevices.py              |    3 
 xen-unstable.hg/tools/python/xen/xend/server/tpmif.py             |    5 -
 xen-unstable.hg/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py      |    8 -
 xen-unstable.hg/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py      |    9 -
 xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py      |   16 ---
 xen-unstable.hg/tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py      |   15 ---
 xen-unstable.hg/tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py      |   15 ---
 xen-unstable.hg/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py |   20 ----
 xen-unstable.hg/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py      |   19 ---
 xen-unstable.hg/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py      |   19 ---
 xen-unstable.hg/tools/xm-test/tests/vtpm/vtpm_utils.py            |   14 ++
 12 files changed, 77 insertions(+), 114 deletions(-)
xen-unstable.hg/tools/examples/vtpm-common.sh +34 -14
Index: root/xen-unstable.hg/tools/examples/vtpm-common.sh
===================================================================
@@ -20,7 +20,7 @@ dir=$(dirname "$0")
 . "$dir/logging.sh"
 . "$dir/locking.sh"
 
-VTPMDB="/etc/xen/vtpm.db"
+VTPMDB="/var/vtpm/vtpm.db"
 
 #In the vtpm-impl file some commands should be defined:
 #      vtpm_create, vtpm_setup, vtpm_start, etc. (see below)
@@ -241,12 +241,21 @@ function vtpm_get_create_reason () {
 # If no entry in the TPM database is found, the instance is
 # created and an entry added to the database.
 function vtpm_create_instance () {
-	local res instance domname reason
-	domname=$(xenstore_read "$XENBUS_PATH"/domain)
+	local res instance domname reason uuid
+	uuid=$(xenstore_read "$XENBUS_PATH"/uuid)
 	reason=$(vtpm_get_create_reason)
 
 	claim_lock vtpmdb
-	instance=$(vtpmdb_find_instance $domname)
+
+	instance="0"
+
+	if [ "$uuid" != "" ]; then
+		instance=$(vtpmdb_find_instance $uuid)
+	fi
+	if [ "$instance" == "0" ]; then
+		domname=$(xenstore_read "$XENBUS_PATH"/domain)
+		instance=$(vtpmdb_find_instance $domname)
+	fi
 
 	if [ "$instance" == "0" -a "$reason" != "create" ]; then
 		release_lock vtpmdb
@@ -268,7 +277,11 @@ function vtpm_create_instance () {
 		vtpm_create $instance
 
 		if [ $vtpm_fatal_error -eq 0 ]; then
-			vtpmdb_add_instance $domname $instance
+			if [ "$uuid" != "" ]; then
+				vtpmdb_add_instance $uuid $instance
+			else
+				vtpmdb_add_instance $domname $instance
+			fi
 		fi
 	else
 		if [ "$reason" == "resume" ]; then
@@ -288,22 +301,29 @@ function vtpm_create_instance () {
 #Since it is assumed that the VM will appear again, the
 #entry is kept in the VTPMDB file.
 function vtpm_remove_instance () {
-	local instance reason domname
+	local instance reason domname uuid
 	#Stop script execution quietly if path does not exist (anymore)
 	xenstore-exists "$XENBUS_PATH"/domain
-	domname=$(xenstore_read "$XENBUS_PATH"/domain)
+	uuid=$(xenstore_read "$XENBUS_PATH"/uuid)
 
-	if [ "$domname" != "" ]; then
-		claim_lock vtpmdb
+	claim_lock vtpmdb
 
-		instance=$(vtpmdb_find_instance $domname)
+	instance="0"
 
-		if [ "$instance" != "0" ]; then
-			vtpm_suspend $instance
-		fi
+	if [ "$uuid != "" ]; then
+		instance=$(vtpmdb_find_instance $uuid)
+	fi
 
-		release_lock vtpmdb
+	if [ "$instance == "0" ]; then
+		domname=$(xenstore_read "$XENBUS_PATH"/domain)
+		instance=$(vtpmdb_find_instance $domname)
 	fi
+
+	if [ "$instance" != "0" ]; then
+		vtpm_suspend $instance
+	fi
+
+	release_lock vtpmdb
 }
 
 
xen-unstable.hg/tools/python/xen/xend/XendDevices.py +2 -1
Index: root/xen-unstable.hg/tools/python/xen/xend/XendDevices.py
===================================================================
@@ -78,6 +78,7 @@ class XendDevices:
         @param domain: domain this controller is handling devices for.
         @type domain: XendDomainInfo
         """
-        tpmif.destroy_vtpmstate(domain.getName())
+        from xen.xend.XendLogging import log
+        tpmif.destroy_vtpmstate(domain.info.get('vtpm_refs'))
 
     destroy_device_state = classmethod(destroy_device_state)
xen-unstable.hg/tools/python/xen/xend/server/tpmif.py +3 -2
Index: root/xen-unstable.hg/tools/python/xen/xend/server/tpmif.py
===================================================================
@@ -31,9 +31,10 @@ import re
 
 xoptions = XendOptions.instance()
 
-def destroy_vtpmstate(name):
+def destroy_vtpmstate(uuids):
     if os.path.exists(VTPM_DELETE_SCRIPT):
-        os.system(VTPM_DELETE_SCRIPT + " " + name)
+        for uuid in uuids:
+            os.system(VTPM_DELETE_SCRIPT + " " + uuid)
 
 class TPMifController(DevController):
     """TPM interface controller. Handles all TPM devices for a domain.
xen-unstable.hg/tools/xm-test/tests/vtpm/vtpm_utils.py +13 -1
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/vtpm_utils.py
===================================================================
@@ -17,4 +17,16 @@ if output == "":
 def vtpm_cleanup(domName):
     from xen.xm import main
     if main.serverType != main.SERVER_XEN_API:
-        traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
+        traceCommand("/etc/xen/scripts/vtpm-delete "
+              "`xenstore-read /local/domain/0/backend/vtpm/%s/0/uuid`" %
+              str(domid(domName)))
+
+def vtpm_cleanup(uuid):
+    from xen.xm import main
+    if main.serverType != main.SERVER_XEN_API:
+        traceCommand("/etc/xen/scripts/vtpm-delete %s" % uuid)
+
+def vtpm_get_uuid(domainid):
+    s, o = traceCommand("xenstore-read "
+                        "/local/domain/0/backend/vtpm/%s/0/uuid" % domainid)
+    return o
xen-unstable.hg/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py +4 -4
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py
===================================================================
@@ -11,6 +11,7 @@ from XmTestLib import *
 from vtpm_utils import *
 import commands
 import os
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -23,18 +24,17 @@ except DomainError, e:
     vtpm_cleanup(domain.getName())
     FAIL("Unable to create domain")
 
+
 domName = domain.getName()
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 status, output = traceCommand("xm vtpm-list %s" % domain.getId())
 eyecatcher = "/local/domain/0/backend/vtpm"
 where = output.find(eyecatcher)
 if status != 0:
-    vtpm_cleanup(domName)
     FAIL("xm vtpm-list returned bad status, expected 0, status is %i" % status)
 elif where < 0:
-    vtpm_cleanup(domName)
     FAIL("Fail to list virtual TPM device")
 
 domain.stop()
-
-vtpm_cleanup(domName)
xen-unstable.hg/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py +3 -6
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py
===================================================================
@@ -11,6 +11,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -21,32 +22,28 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 domain.closeConsole()
 
 domain.stop()
 
-vtpm_cleanup(domName)
-
 if not re.search("PCR-00:",run["output"]):
     FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py +3 -13
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py
===================================================================
@@ -12,6 +12,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -23,25 +24,23 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 consoleHistory = console.getHistory()
@@ -59,12 +58,10 @@ while loop < 3:
 
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm save did not succeed")
 
     try:
@@ -74,32 +71,27 @@ while loop < 3:
     except TimeoutError, e:
         os.remove("%s.save" % domName)
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     os.remove("%s.save" % domName)
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm restore did not succeed")
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     loop += 1
@@ -108,5 +100,3 @@ domain.closeConsole()
 
 domain.stop()
 
-vtpm_cleanup(domName)
-
xen-unstable.hg/tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py +3 -12
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/04_vtpm-loc_migr.py
===================================================================
@@ -13,6 +13,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -24,25 +25,23 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 consoleHistory = console.getHistory()
@@ -61,12 +60,10 @@ while loop < 3:
                                       timeout=90)
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm migrate did not succeed. External device migration activated?")
 
 
@@ -74,26 +71,22 @@ while loop < 3:
     new_domid = domid(domName)
 
     if (old_domid == new_domid):
-        vtpm_cleanup(domName)
         FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
              (old_domid,loop))
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("No result from dumping the PCRs")
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     loop += 1
@@ -101,5 +94,3 @@ while loop < 3:
 domain.closeConsole()
 
 domain.stop()
-
-vtpm_cleanup(domName)
xen-unstable.hg/tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py +3 -12
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/05_vtpm-loc_migr.py
===================================================================
@@ -13,6 +13,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -24,25 +25,23 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 consoleHistory = console.getHistory()
@@ -61,12 +60,10 @@ while loop < 3:
                                       timeout=90)
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm migrate did not succeed. External device migration activated?")
 
 
@@ -74,26 +71,22 @@ while loop < 3:
     new_domid = domid(domName)
 
     if (old_domid == new_domid):
-        vtpm_cleanup(domName)
         FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
              (old_domid,loop))
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("No result from dumping the PCRs")
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     loop += 1
@@ -101,5 +94,3 @@ while loop < 3:
 domain.closeConsole()
 
 domain.stop()
-
-vtpm_cleanup(domName)
xen-unstable.hg/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py +3 -17
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py
===================================================================
@@ -13,6 +13,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -24,45 +25,40 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("mknod /dev/tpm0 c 10 224")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while creating /dev/tpm0")
 
 try:
     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")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while extending PCR 0")
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 if not re.search("PCR-00:",run["output"]):
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
 
 if not re.search("PCR-00: 1E A7 BD",run["output"]):
@@ -84,12 +80,10 @@ while loop < 3:
 
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm save did not succeed")
 
     try:
@@ -99,37 +93,31 @@ while loop < 3:
     except TimeoutError, e:
         os.remove("%s.save" % domName)
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     os.remove("%s.save" % domName)
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm restore did not succeed")
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     if not re.search("PCR-00: 1E A7 BD",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
 
     loop += 1
@@ -138,5 +126,3 @@ domain.closeConsole()
 
 domain.stop()
 
-vtpm_cleanup(domName)
-
xen-unstable.hg/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py +3 -16
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/07_vtpm-mig_pcrs.py
===================================================================
@@ -14,6 +14,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -25,45 +26,40 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("mknod /dev/tpm0 c 10 224")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while creating /dev/tpm0")
 
 try:
     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")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while extending PCR 0")
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 if not re.search("PCR-00:",run["output"]):
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
 
 if not re.search("PCR-00: 1E A7 BD",run["output"]):
@@ -86,12 +82,10 @@ while loop < 3:
                                       timeout=90)
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm migrate did not succeed. External device migration activated?")
 
 
@@ -99,31 +93,26 @@ while loop < 3:
     new_domid = domid(domName)
 
     if (old_domid == new_domid):
-        vtpm_cleanup(domName)
         FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
              (old_domid,loop))
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("No result from dumping the PCRs")
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     if not re.search("PCR-00: 1E A7 BD",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
 
     loop += 1
@@ -131,5 +120,3 @@ while loop < 3:
 domain.closeConsole()
 
 domain.stop()
-
-vtpm_cleanup(domName)
xen-unstable.hg/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py +3 -16
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/08_vtpm-mig_pcrs.py
===================================================================
@@ -14,6 +14,7 @@ from vtpm_utils import *
 import commands
 import os
 import os.path
+import atexit
 
 config = {"vtpm":"instance=1,backend=0"}
 domain = XmTestDomain(extraConfig=config)
@@ -25,45 +26,40 @@ try:
 except DomainError, e:
     if verbose:
         print e.extra
-    vtpm_cleanup(domName)
     FAIL("Unable to create domain (%s)" % domName)
 
+atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))
+
 try:
     console.sendInput("input")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL(str(e))
 
 try:
     run = console.runCmd("mknod /dev/tpm0 c 10 224")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while creating /dev/tpm0")
 
 try:
     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")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Error while extending PCR 0")
 
 try:
     run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
 except ConsoleError, e:
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("No result from dumping the PCRs")
 
 
 if re.search("No such file",run["output"]):
-    vtpm_cleanup(domName)
     FAIL("TPM frontend support not compiled into (domU?) kernel")
 
 if not re.search("PCR-00:",run["output"]):
     saveLog(console.getHistory())
-    vtpm_cleanup(domName)
     FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
 
 if not re.search("PCR-00: 1E A7 BD",run["output"]):
@@ -86,12 +82,10 @@ while loop < 3:
                                       timeout=90)
     except TimeoutError, e:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     if status != 0:
         saveLog(consoleHistory)
-        vtpm_cleanup(domName)
         FAIL("xm migrate did not succeed. External device migration activated?")
 
 
@@ -99,31 +93,26 @@ while loop < 3:
     new_domid = domid(domName)
 
     if (old_domid == new_domid):
-        vtpm_cleanup(domName)
         FAIL("xm migrate failed, domain id is still %s (loop=%d)" %
              (old_domid,loop))
 
     try:
         console = domain.getConsole()
     except ConsoleError, e:
-        vtpm_cleanup(domName)
         FAIL(str(e))
 
     try:
         run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
     except ConsoleError, e:
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("No result from dumping the PCRs")
 
     if not re.search("PCR-00:",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
 
     if not re.search("PCR-00: 1E A7 BD",run["output"]):
         saveLog(console.getHistory())
-        vtpm_cleanup(domName)
         FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
 
     loop += 1
@@ -131,5 +120,3 @@ while loop < 3:
 domain.closeConsole()
 
 domain.stop()
-
-vtpm_cleanup(domName)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel