Skip to contentSkip to conversation

Destroy the state of a vTPM if a VM is destroyed

PATCH New Stefan Berger 1 participant 1 message Nov 14, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Destroy the state of a vTPM if a VM is destroyed

Explicitly destroy the state of a vTPM - using an external bash script - if its VM is destroyed .

xen-unstable.hg/tools/python/xen/xend/XendAPI.py +8 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py
===================================================================
@@ -1006,6 +1006,8 @@ class XendAPI:
     def vm_clone(self, session, vm_ref):
         return xen_api_error(XEND_ERROR_UNSUPPORTED)
     def vm_destroy(self, session, vm_ref):
+        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+        self.vtpm_destroy_by_vmname(dom.getName())
         return do_vm_func("domain_delete", vm_ref)
     def vm_hard_reboot(self, session, vm_ref):
         return xen_api_error(XEND_ERROR_UNSUPPORTED)    
@@ -1390,6 +1392,12 @@ class XendAPI:
         else:
             return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
 
+    # private class methods (unexported)
+    def vtpm_destroy_by_vmname(self, vmname):
+        # Destroy the vTPM's state if a VM is destroyed
+        from xen.xend.server.tpmif import destroy_vtpmstate
+        destroy_vtpmstate(vmname)
+
 
     # Xen API: Class SR
     # ----------------------------------------------------------------
xen-unstable.hg/tools/python/xen/xend/XendConstants.py +6 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendConstants.py
===================================================================
@@ -89,6 +89,12 @@ DEV_MIGRATE_STEP2 = 2
 DEV_MIGRATE_STEP3 = 3
 
 #
+# VTPM-related constants
+#
+
+VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
+
+#
 # Xenstore Constants
 #
 
xen-unstable.hg/tools/python/xen/xend/server/tpmif.py +5 -1
Index: root/xen-unstable.hg/tools/python/xen/xend/server/tpmif.py
===================================================================
@@ -25,7 +25,7 @@ from xen.xend import sxp
 from xen.xend import XendRoot
 from xen.xend.XendLogging import log
 from xen.xend.XendError import XendError
-from xen.xend.XendConstants import DEV_MIGRATE_TEST
+from xen.xend.XendConstants import DEV_MIGRATE_TEST, VTPM_DELETE_SCRIPT
 from xen.xend.server.DevController import DevController
 
 import os
@@ -33,6 +33,10 @@ import re
 
 xroot = XendRoot.instance()
 
+def destroy_vtpmstate(name):
+    if os.path.exists(VTPM_DELETE_SCRIPT):
+        os.system(VTPM_DELETE_SCRIPT + " " + name)
+
 class TPMifController(DevController):
     """TPM interface controller. Handles all TPM devices for a domain.
     """

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