mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
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@jp.fujitsu.com>
This commit is contained in:
1 parent
a60d80e39e
commit
2f42a37e57
4 files changed
+21
-29
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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.
|
||||
"""
|
||||
|
||||
@@ -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()
|
||||
|
||||