[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] This is a refactored version of a previous patch that destroys external



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Node ID 00ed59a6f043af31c584c5a78db2a6009f80df51
# Parent  e2d593dd1689f448329302868c2e64934e176236
This is a refactored version of a previous patch that destroys external
devices' state when a VM configuration file is destroyed. Currently only
the vTPM device's state needs to be explicitly destroyed.
I am also surrounding the saving of the managed domain's configuration
with a try-catch.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py       |    9 ++++++---
 tools/python/xen/xend/XendConstants.py |    6 ++++++
 tools/python/xen/xend/XendDevices.py   |   10 ++++++++++
 tools/python/xen/xend/XendDomain.py    |    3 ++-
 tools/python/xen/xend/server/tpmif.py  |    8 ++++++--
 5 files changed, 30 insertions(+), 6 deletions(-)

diff -r e2d593dd1689 -r 00ed59a6f043 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Tue Nov 21 10:21:00 2006 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Tue Nov 21 10:22:19 2006 +0000
@@ -1391,9 +1391,12 @@ class XendAPI:
         xendom = XendDomain.instance()
         if xendom.is_valid_vm(vtpm_struct['VM']):
             dom = xendom.get_vm_by_uuid(vtpm_struct['VM'])
-            vtpm_ref = dom.create_vtpm(vtpm_struct)
-            xendom.managed_config_save(dom)
-            return xen_api_success(vtpm_ref)
+            try:
+                vtpm_ref = dom.create_vtpm(vtpm_struct)
+                xendom.managed_config_save(dom)
+                return xen_api_success(vtpm_ref)
+            except XendError:
+                return xen_api_error(XEND_ERROR_TODO)
         else:
             return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
 
diff -r e2d593dd1689 -r 00ed59a6f043 tools/python/xen/xend/XendConstants.py
--- a/tools/python/xen/xend/XendConstants.py    Tue Nov 21 10:21:00 2006 +0000
+++ b/tools/python/xen/xend/XendConstants.py    Tue Nov 21 10:22:19 2006 +0000
@@ -89,6 +89,12 @@ DEV_MIGRATE_STEP3 = 3
 DEV_MIGRATE_STEP3 = 3
 
 #
+# VTPM-related constants
+#
+
+VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
+
+#
 # Xenstore Constants
 #
 
diff -r e2d593dd1689 -r 00ed59a6f043 tools/python/xen/xend/XendDevices.py
--- a/tools/python/xen/xend/XendDevices.py      Tue Nov 21 10:21:00 2006 +0000
+++ b/tools/python/xen/xend/XendDevices.py      Tue Nov 21 10:22:19 2006 +0000
@@ -71,3 +71,13 @@ class XendDevices:
 
     make_controller = classmethod(make_controller)
 
+    def destroy_device_state(cls, domain):
+        """Destroy the state of (external) devices. This is necessary
+           to do when a VM's configuration is destroyed.
+        
+        @param domain: domain this controller is handling devices for.
+        @type domain: XendDomainInfo
+        """
+        tpmif.destroy_vtpmstate(domain.getName())
+
+    destroy_device_state = classmethod(destroy_device_state)
diff -r e2d593dd1689 -r 00ed59a6f043 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Tue Nov 21 10:21:00 2006 +0000
+++ b/tools/python/xen/xend/XendDomain.py       Tue Nov 21 10:22:19 2006 +0000
@@ -37,6 +37,7 @@ from xen.xend.XendLogging import log
 from xen.xend.XendLogging import log
 from xen.xend.XendConstants import XS_VMROOT
 from xen.xend.XendConstants import DOM_STATE_HALTED, DOM_STATE_RUNNING
+from xen.xend.XendDevices import XendDevices
 
 from xen.xend.xenstore.xstransact import xstransact
 from xen.xend.xenstore.xswatch import xswatch
@@ -898,7 +899,7 @@ class XendDomain:
 
                 self._managed_domain_unregister(dominfo)
                 self._remove_domain(dominfo)
-                
+                XendDevices.destroy_device_state(dominfo)
             except Exception, ex:
                 raise XendError(str(ex))
         finally:
diff -r e2d593dd1689 -r 00ed59a6f043 tools/python/xen/xend/server/tpmif.py
--- a/tools/python/xen/xend/server/tpmif.py     Tue Nov 21 10:21:00 2006 +0000
+++ b/tools/python/xen/xend/server/tpmif.py     Tue Nov 21 10:22:19 2006 +0000
@@ -25,13 +25,17 @@ from xen.xend import XendRoot
 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
 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.
@@ -79,7 +83,7 @@ class TPMifController(DevController):
         if uuid:
             result['uuid'] = uuid
         if type:
-            result['type'] == type
+            result['type'] = type
 
         return result
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.