Change in vdsm[ovirt-3.5]: migration: use context manager for semaphore

fromani at redhat.com fromani at redhat.com
Mon Jan 18 11:48:34 UTC 2016


Hello Nir Soffer, Vinzenz Feenstra, Dan Kenigsberg, Martin Polednik, Milan Zamazal,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/52341

to review the following change.

Change subject: migration: use context manager for semaphore
......................................................................

migration: use context manager for semaphore

The migration source code path needs to take the
ongoingMigrations semaphore, to throttle the outgoing
migrations.

The code did so using the pre-2.6 way, explicitly
using acquire() and release().

This patch switches the code to the context manager
semantics, to make the code a bit nicer and to unlock
further refactoring.

Change-Id: I8fb7bd6a66898804eefd9bd286c77fd8b9225bc4
Backport-To: 3.6
Backport-To: 3.5
Bug-Url: https://bugzilla.redhat.com/1296936
Signed-off-by: Francesco Romani <fromani at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/51655
Reviewed-by: Milan Zamazal <mzamazal at redhat.com>
Continuous-Integration: Jenkins CI
Reviewed-by: Vinzenz Feenstra <vfeenstr at redhat.com>
Reviewed-by: Martin Polednik <mpolednik at redhat.com>
Reviewed-by: Michal Skrivanek <michal.skrivanek at redhat.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/51827
Reviewed-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/virt/migration.py
1 file changed, 25 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/41/52341/1

diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py
index 76c3f7c..a274973 100644
--- a/vdsm/virt/migration.py
+++ b/vdsm/virt/migration.py
@@ -230,31 +230,31 @@
             self._setupVdsConnection()
             self._setupRemoteMachineParams()
             self._prepareGuest()
-            SourceThread._ongoingMigrations.acquire()
-            try:
-                if self._migrationCanceledEvt:
-                    self._raiseAbortError()
-                self.log.debug("migration semaphore acquired after %d seconds",
-                               time.time() - startTime)
-                self._vm.conf['_migrationParams'] = {
-                    'dst': self._dst,
-                    'mode': self._mode,
-                    'method': self._method,
-                    'dstparams': self._dstparams,
-                    'dstqemu': self._dstqemu}
-                self._vm.saveState()
-                self._startUnderlyingMigration(time.time())
-                self._finishSuccessfully()
-            except libvirt.libvirtError as e:
-                if e.get_error_code() == libvirt.VIR_ERR_OPERATION_ABORTED:
-                    self.status['status']['code'] = \
-                        errCode['migCancelErr']['status']['code']
-                    self.status['status']['message'] = 'Migration canceled'
-                raise
-            finally:
-                if '_migrationParams' in self._vm.conf:
-                    del self._vm.conf['_migrationParams']
-                SourceThread._ongoingMigrations.release()
+            with SourceThread._ongoingMigrations:
+                try:
+                    if self._migrationCanceledEvt:
+                        self._raiseAbortError()
+                    self.log.debug(
+                        "migration semaphore acquired after %d seconds",
+                        time.time() - startTime)
+                    self._vm.conf['_migrationParams'] = {
+                        'dst': self._dst,
+                        'mode': self._mode,
+                        'method': self._method,
+                        'dstparams': self._dstparams,
+                        'dstqemu': self._dstqemu}
+                    self._vm.saveState()
+                    self._startUnderlyingMigration(time.time())
+                    self._finishSuccessfully()
+                except libvirt.libvirtError as e:
+                    if e.get_error_code() == libvirt.VIR_ERR_OPERATION_ABORTED:
+                        self.status['status']['code'] = \
+                            errCode['migCancelErr']['status']['code']
+                        self.status['status']['message'] = 'Migration canceled'
+                    raise
+                finally:
+                    if '_migrationParams' in self._vm.conf:
+                        del self._vm.conf['_migrationParams']
         except Exception as e:
             self._recover(str(e))
             self.log.error("Failed to migrate", exc_info=True)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fb7bd6a66898804eefd9bd286c77fd8b9225bc4
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Martin Polednik <mpolednik at redhat.com>
Gerrit-Reviewer: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Vinzenz Feenstra <vfeenstr at redhat.com>


More information about the vdsm-patches mailing list