ia64/xen-unstable

changeset 12530:00ed59a6f043

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@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Nov 21 10:22:19 2006 +0000 (2006-11-21)
parents e2d593dd1689
children 6661355c450e
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendConstants.py tools/python/xen/xend/XendDevices.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/server/tpmif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Tue Nov 21 10:21:00 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue Nov 21 10:22:19 2006 +0000
     1.3 @@ -1391,9 +1391,12 @@ class XendAPI:
     1.4          xendom = XendDomain.instance()
     1.5          if xendom.is_valid_vm(vtpm_struct['VM']):
     1.6              dom = xendom.get_vm_by_uuid(vtpm_struct['VM'])
     1.7 -            vtpm_ref = dom.create_vtpm(vtpm_struct)
     1.8 -            xendom.managed_config_save(dom)
     1.9 -            return xen_api_success(vtpm_ref)
    1.10 +            try:
    1.11 +                vtpm_ref = dom.create_vtpm(vtpm_struct)
    1.12 +                xendom.managed_config_save(dom)
    1.13 +                return xen_api_success(vtpm_ref)
    1.14 +            except XendError:
    1.15 +                return xen_api_error(XEND_ERROR_TODO)
    1.16          else:
    1.17              return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
    1.18  
     2.1 --- a/tools/python/xen/xend/XendConstants.py	Tue Nov 21 10:21:00 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendConstants.py	Tue Nov 21 10:22:19 2006 +0000
     2.3 @@ -89,6 +89,12 @@ DEV_MIGRATE_STEP2 = 2
     2.4  DEV_MIGRATE_STEP3 = 3
     2.5  
     2.6  #
     2.7 +# VTPM-related constants
     2.8 +#
     2.9 +
    2.10 +VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
    2.11 +
    2.12 +#
    2.13  # Xenstore Constants
    2.14  #
    2.15  
     3.1 --- a/tools/python/xen/xend/XendDevices.py	Tue Nov 21 10:21:00 2006 +0000
     3.2 +++ b/tools/python/xen/xend/XendDevices.py	Tue Nov 21 10:22:19 2006 +0000
     3.3 @@ -71,3 +71,13 @@ class XendDevices:
     3.4  
     3.5      make_controller = classmethod(make_controller)
     3.6  
     3.7 +    def destroy_device_state(cls, domain):
     3.8 +        """Destroy the state of (external) devices. This is necessary
     3.9 +           to do when a VM's configuration is destroyed.
    3.10 +        
    3.11 +        @param domain: domain this controller is handling devices for.
    3.12 +        @type domain: XendDomainInfo
    3.13 +        """
    3.14 +        tpmif.destroy_vtpmstate(domain.getName())
    3.15 +
    3.16 +    destroy_device_state = classmethod(destroy_device_state)
     4.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Nov 21 10:21:00 2006 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Nov 21 10:22:19 2006 +0000
     4.3 @@ -37,6 +37,7 @@ from xen.xend.XendError import XendError
     4.4  from xen.xend.XendLogging import log
     4.5  from xen.xend.XendConstants import XS_VMROOT
     4.6  from xen.xend.XendConstants import DOM_STATE_HALTED, DOM_STATE_RUNNING
     4.7 +from xen.xend.XendDevices import XendDevices
     4.8  
     4.9  from xen.xend.xenstore.xstransact import xstransact
    4.10  from xen.xend.xenstore.xswatch import xswatch
    4.11 @@ -898,7 +899,7 @@ class XendDomain:
    4.12  
    4.13                  self._managed_domain_unregister(dominfo)
    4.14                  self._remove_domain(dominfo)
    4.15 -                
    4.16 +                XendDevices.destroy_device_state(dominfo)
    4.17              except Exception, ex:
    4.18                  raise XendError(str(ex))
    4.19          finally:
     5.1 --- a/tools/python/xen/xend/server/tpmif.py	Tue Nov 21 10:21:00 2006 +0000
     5.2 +++ b/tools/python/xen/xend/server/tpmif.py	Tue Nov 21 10:22:19 2006 +0000
     5.3 @@ -25,7 +25,7 @@ from xen.xend import sxp
     5.4  from xen.xend import XendRoot
     5.5  from xen.xend.XendLogging import log
     5.6  from xen.xend.XendError import XendError
     5.7 -from xen.xend.XendConstants import DEV_MIGRATE_TEST
     5.8 +from xen.xend.XendConstants import DEV_MIGRATE_TEST, VTPM_DELETE_SCRIPT
     5.9  from xen.xend.server.DevController import DevController
    5.10  
    5.11  import os
    5.12 @@ -33,6 +33,10 @@ import re
    5.13  
    5.14  xroot = XendRoot.instance()
    5.15  
    5.16 +def destroy_vtpmstate(name):
    5.17 +    if os.path.exists(VTPM_DELETE_SCRIPT):
    5.18 +        os.system(VTPM_DELETE_SCRIPT + " " + name)
    5.19 +
    5.20  class TPMifController(DevController):
    5.21      """TPM interface controller. Handles all TPM devices for a domain.
    5.22      """
    5.23 @@ -79,7 +83,7 @@ class TPMifController(DevController):
    5.24          if uuid:
    5.25              result['uuid'] = uuid
    5.26          if type:
    5.27 -            result['type'] == type
    5.28 +            result['type'] = type
    5.29  
    5.30          return result
    5.31