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

[Xen-changelog] [xen-unstable] xend: Fix VDI-VBD link for XenAPI



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1255075003 -3600
# Node ID 540721f1c0c10ce05644b6ae3a202a149ff35cb0
# Parent  2a67c7e64582170223decb408bbf54eca65d47e7
xend: Fix VDI-VBD link for XenAPI

I detected problems of VDI-VBD link again.
  - In the case of inactive managed domains, VDI->VBD link was lost
    by xend restarting (or host OS rebooting).
  - In the case of active domains, both VDI->VBD link and VBD->VDI
    link were lost by xend restarting.

When xend is restarted, information of VDI instances is restored from
a vdi.xml file.  But the vdi.xml file does not have UUID of VBD
because xend does not write the UUID to the vdi.xml file.  Therefore,
VDI->VBD link is lost.  When xend is restarted, information of VBD
instances is restored from xenstore.  But xenstore does not have UUID
of VDI.  Therefore, VBD->VDI link is lost.

This patch solves the problems.  VDI instances stop having UUID of
VBD.  Instead, xend gathers UUID of VBD each time it's required.  The
method is the same as Network->VIF link.  Information of VBD instances
is restored not only from xenstore but from a config.sxp file.  UUID
of VDI is restored from the config.sxp file.

FYI, VBD->VDI link of inactive managed domains is not lost because
information of VBD instances is restored from the config.sxp file.
UUID of VDI is written by xend to the config.sxp file.

Signed-off-by: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py        |    4 ----
 tools/python/xen/xend/XendDomain.py     |   13 +++++++++++--
 tools/python/xen/xend/XendDomainInfo.py |   14 --------------
 tools/python/xen/xend/XendVDI.py        |   19 ++++++++++---------
 4 files changed, 21 insertions(+), 29 deletions(-)

diff -r 2a67c7e64582 -r 540721f1c0c1 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Fri Oct 09 08:55:43 2009 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Fri Oct 09 08:56:43 2009 +0100
@@ -1986,8 +1986,6 @@ class XendAPI(object):
             log.exception("Error in VBD_create")
             return xen_api_error(['INTERNAL_ERROR', str(e)]) 
             
-        vdi.addVBD(vbd_ref)
-
         xendom.managed_config_save(dom)
         return xen_api_success(vbd_ref)
 
@@ -2004,8 +2002,6 @@ class XendAPI(object):
 
         XendTask.log_progress(0, 100, vm.destroy_vbd, vbd_ref)
 
-        vdi.removeVBD(vbd_ref)
-        
         return xen_api_success_void()
 
     def _VBD_get(self, vbd_ref, prop):
diff -r 2a67c7e64582 -r 540721f1c0c1 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Fri Oct 09 08:55:43 2009 +0100
+++ b/tools/python/xen/xend/XendDomain.py       Fri Oct 09 08:56:43 2009 +0100
@@ -203,6 +203,17 @@ class XendDomain:
                             if key not in XendConfig.LEGACY_XENSTORE_VM_PARAMS 
and \
                                    key in dom:
                                 running_dom.info[key] = dom[key]
+                        # Devices information is restored from xenstore,
+                        # but VDI value in devices information can be not
+                        # restored because there is not VDI value in
+                        # xenstore. So we restore VDI value by using the
+                        # domain config file.
+                        for vbd_ref in running_dom.info['vbd_refs']:
+                            if dom['devices'].has_key(vbd_ref):
+                                r_devtype, r_devinfo = 
running_dom.info['devices'][vbd_ref]
+                                _, m_devinfo = dom['devices'][vbd_ref]
+                                r_devinfo['VDI'] = m_devinfo.get('VDI', '')
+                                running_dom.info['devices'][vbd_ref] = 
(r_devtype, r_devinfo)
                 except Exception:
                     log.exception("Failed to create reference to managed "
                                   "domain: %s" % dom_name)
@@ -347,7 +358,6 @@ class XendDomain:
             if self.is_domain_managed(dom):
                 self._managed_config_remove(dom.get_uuid())
                 del self.managed_domains[dom.get_uuid()]
-                dom.unlink_xapi_instances()
                 dom.destroy_xapi_instances()
         except ValueError:
             log.warn("Domain is not registered: %s" % dom.get_uuid())
@@ -486,7 +496,6 @@ class XendDomain:
             if domid in self.domains:
                 del self.domains[domid]
 
-            info.unlink_xapi_instances()
             info.destroy_xapi_instances()
         else:
             log.warning("Attempted to remove non-existent domain.")
diff -r 2a67c7e64582 -r 540721f1c0c1 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Fri Oct 09 08:55:43 2009 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Fri Oct 09 08:56:43 2009 +0100
@@ -4048,20 +4048,6 @@ class XendDomainInfo:
             except Exception, exn:
                 raise XendError('Failed to destroy device')
 
-    def unlink_xapi_instances(self):
-        from xen.xend import XendDomain
-        if XendDomain.instance().is_valid_vm(self.info.get('uuid')):
-            # domain still exists.
-            return
-
-        for vbd_ref in self.info.get('vbd_refs'):
-            dev_info = self.info['devices'].get(vbd_ref)[1]
-            vdi_uuid = dev_info.get('VDI', None)
-            if vdi_uuid and XendNode.instance().is_valid_vdi(vdi_uuid):
-                vdi = XendNode.instance().get_vdi_by_uuid(vdi_uuid)
-                if vdi.getVBDs().count(vbd_ref):
-                    vdi.removeVBD(vbd_ref)
-
     def destroy_xapi_instances(self):
         """Destroy Xen-API instances stored in XendAPIStore.
         """
diff -r 2a67c7e64582 -r 540721f1c0c1 tools/python/xen/xend/XendVDI.py
--- a/tools/python/xen/xend/XendVDI.py  Fri Oct 09 08:55:43 2009 +0100
+++ b/tools/python/xen/xend/XendVDI.py  Fri Oct 09 08:56:43 2009 +0100
@@ -76,16 +76,17 @@ class XendVDI(AutoSaveObject):
         self.read_only = False
         self.type = "system"
         self.other_config = {}
-        self.vbds = []
-
-    def addVBD(self, vbd_ref):
-        self.vbds.append(vbd_ref)
-
-    def removeVBD(self, vbd_ref):
-        self.vbds.remove(vbd_ref)
 
     def getVBDs(self):
-        return self.vbds
+        from xen.xend import XendDomain
+        vbd_refs = [d.get_vbds() for d in XendDomain.instance().list('all')]
+        vbd_refs = reduce(lambda x, y: x + y, vbd_refs)
+        vbds = []
+        for vbd_ref in vbd_refs:
+            vdi = XendDomain.instance().get_dev_property_by_uuid('vbd', 
vbd_ref, 'VDI')
+            if vdi == self.uuid:
+                vbds.append(vbd_ref)
+        return vbds
 
     def load_config_dict(self, cfg):
         """Loads configuration into the object from a dict.
@@ -161,7 +162,7 @@ class XendVDI(AutoSaveObject):
                 'type': self.type,
                 'SR': self.sr_uuid,
                 'other_config': self.other_config,
-                'VBDs': self.vbds}
+                'VBDs': self.getVBDs()}
 
     def get_location(self):
         raise NotImplementedError()

_______________________________________________
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®.