summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Treinish <treinish@linux.vnet.ibm.com>2013-01-10 14:39:00 -0500
committerMatthew Treinish <treinish@linux.vnet.ibm.com>2013-01-11 13:39:39 -0500
commite710897a50f4daac6337e9db114e8a73bf025dda (patch)
treefe00ec5e3822ab74c551c58bfa3ccc988b22dc28
parent7529e513e2f71e6e054639aa3475ff21934625d4 (diff)
downloadnova-e710897a50f4daac6337e9db114e8a73bf025dda.tar.gz
nova-e710897a50f4daac6337e9db114e8a73bf025dda.tar.xz
nova-e710897a50f4daac6337e9db114e8a73bf025dda.zip
Skip domains on libvirt errors in get_vcpu_used()
This commit is to avoid a race condition between deletes and creates. It is possible for a delete to remove a domain from the list returned by _conn.listDomainsID() while get_vcpu_used() is looping over the list. If this happens libVirt raises a LibVirtError and sets the instance to the ERROR state. To avoid this LibVirtError is caught and the loop continues instead of raising the exception. Change-Id: I3206142e36726936013bb27ccd4359de4f94b3a3
-rw-r--r--nova/virt/libvirt/driver.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index ea6e0e6a0..b2cc39e4f 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -2043,15 +2043,26 @@ class LibvirtDriver(driver.ComputeDriver):
"""
total = 0
- for dom_id in self.list_instance_ids():
- dom = self._conn.lookupByID(dom_id)
- vcpus = dom.vcpus()
- if vcpus is None:
- # dom.vcpus is not implemented for lxc, but returning 0 for
- # a used count is hardly useful for something measuring usage
- total += 1
- else:
- total += len(vcpus[1])
+ dom_ids = self.list_instance_ids()
+ for dom_id in dom_ids:
+ try:
+ dom = self._conn.lookupByID(dom_id)
+ vcpus = dom.vcpus()
+ if vcpus is None:
+ # dom.vcpus is not implemented for lxc, but returning 0 for
+ # a used count is hardly useful for something measuring
+ # usage
+ total += 1
+ else:
+ total += len(vcpus[1])
+ except libvirt.libvirtError as err:
+ if err.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
+ LOG.debug(_("List of domains returned by libVirt: %s")
+ % dom_ids)
+ LOG.warn(_("libVirt can't find a domain with id: %s")
+ % dom_id)
+ continue
+ raise
# NOTE(gtt116): give change to do other task.
greenthread.sleep(0)
return total