From 814e7f8c827aa21a87a62594d5b6413bb49e31e1 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 24 Oct 2012 16:14:36 -0700 Subject: libvirt: persist volume attachments into config When you attach a volume to a running instance, only the running xml is updated in libvirt. This is due to the usage of the VIRT_DOMAIN_AFFECT_CURRENT flag passed to attach device. What we really want is to affect both the config and the running xml. There is no combination of flags that works in all states, so we explicitly set the right combination of flags depending on the running state of the vm. Includes a test to test_virt_drivers to ensure the flags are passed correctly. Fixes bug 1071069 Change-Id: I1992748b08daf99cf03dfeb0937ad42457fff1a3 --- nova/virt/libvirt/driver.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 34d667c16..a0b80ab1c 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -646,7 +646,13 @@ class LibvirtDriver(driver.ComputeDriver): self._conn.defineXML(domxml) else: try: - flags = (libvirt.VIR_DOMAIN_AFFECT_CURRENT) + # NOTE(vish): We can always affect config because our + # domains are persistent, but we should only + # affect live if the domain is running. + flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG + state = LIBVIRT_POWER_STATE[virt_dom.info()[0]] + if state == power_state.RUNNING: + flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE virt_dom.attachDeviceFlags(conf.to_xml(), flags) except Exception, ex: if isinstance(ex, libvirt.libvirtError): @@ -704,7 +710,13 @@ class LibvirtDriver(driver.ComputeDriver): domxml = virt_dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE) self._conn.defineXML(domxml) else: - flags = (libvirt.VIR_DOMAIN_AFFECT_CURRENT) + # NOTE(vish): We can always affect config because our + # domains are persistent, but we should only + # affect live if the domain is running. + flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG + state = LIBVIRT_POWER_STATE[virt_dom.info()[0]] + if state == power_state.RUNNING: + flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE virt_dom.detachDeviceFlags(xml, flags) except libvirt.libvirtError as ex: # NOTE(vish): This is called to cleanup volumes after live -- cgit