Marcin Mirecki has uploaded a new change for review.

Change subject: vm: nic hotunplug, perform libvirt operation before modyfing 
vdsm nic objects
......................................................................

vm: nic hotunplug, perform libvirt operation before modyfing vdsm nic objects

When a nic is hotunpluged, it is first removed from the vdsm devices, and then 
from libvirt.
When the libvirt operation fails, the vdsm devices are in conflict with libvirt.
This is fixed by performing the libvirt operations first.

This is an alternative solution to:
https://gerrit.ovirt.org/#/c/51187/
and
https://gerrit.ovirt.org/#/c/51190/

Change-Id: I31ba3c622fa92e9c0898860eb93f6bb42bee3041
Bug-Url: https://bugzilla.redhat.com/1134256
Signed-off-by: Marcin Mirecki <mmire...@redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 13 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/51193/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 8939603..055c852 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -2288,21 +2288,6 @@
                            nicParams)
             return response.error('hotunplugNic', "NIC not found")
 
-        # Remove found NIC from vm's NICs list
-        if nic:
-            self._devices[hwclass.NIC].remove(nic)
-        # Find and remove NIC device from vm's conf
-        nicDev = None
-        for dev in self.conf['devices'][:]:
-            if (dev['type'] == hwclass.NIC and
-                    dev['macAddr'].lower() == nicParams['macAddr'].lower()):
-                with self._confLock:
-                    self.conf['devices'].remove(dev)
-                nicDev = dev
-                break
-
-        self.saveState()
-
         try:
             self._dom.detachDevice(nicXml)
             self._waitForDeviceRemoval(nic)
@@ -2310,12 +2295,6 @@
                 hostdev.reattach_detachable(nic.hostdev)
         except HotunplugTimeout as e:
             self.log.error("%s", e)
-            if nicDev:
-                with self._confLock:
-                    self.conf['devices'].append(nicDev)
-            if nic:
-                self._devices[hwclass.NIC].append(nic)
-            self.saveState()
             hooks.after_nic_hotunplug_fail(nicXml, self.conf,
                                            params=nic.custom)
             return response.error('hotunplugNic', "%s" % e)
@@ -2323,17 +2302,24 @@
             self.log.exception("Hotunplug failed")
             if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
                 return response.error('noVM')
-            # Restore NIC device in vm's conf and _devices
-            if nicDev:
-                with self._confLock:
-                    self.conf['devices'].append(nicDev)
-            if nic:
-                self._devices[hwclass.NIC].append(nic)
             self.saveState()
             hooks.after_nic_hotunplug_fail(nicXml, self.conf,
                                            params=nic.custom)
             return response.error('hotunplugNic', e.message)
 
+        # Remove found NIC from vm's NICs list
+        if nic:
+            self._devices[hwclass.NIC].remove(nic)
+        # Find and remove NIC device from vm's conf
+        for dev in self.conf['devices'][:]:
+            if (dev['type'] == hwclass.NIC and
+                    dev['macAddr'].lower() ==
+                    nicParams['macAddr'].lower()):
+                with self._confLock:
+                    self.conf['devices'].remove(dev)
+                break
+        self.saveState()
+
         hooks.after_nic_hotunplug(nicXml, self.conf,
                                   params=nic.custom)
         return {'status': doneCode, 'vmList': self.status()}


-- 
To view, visit https://gerrit.ovirt.org/51193
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I31ba3c622fa92e9c0898860eb93f6bb42bee3041
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Marcin Mirecki <mmire...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to