Change in vdsm[master]: migration: use context manager for semaphore
fromani at redhat.com
fromani at redhat.com
Mon Jan 11 15:17:24 UTC 2016
Francesco Romani has uploaded a new change for review.
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
Bug-Url: https://bugzilla.redhat.com/1296936
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/migration.py
1 file changed, 25 insertions(+), 24 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/51655/1
diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py
index afd54c4..f512b51 100644
--- a/vdsm/virt/migration.py
+++ b/vdsm/virt/migration.py
@@ -279,30 +279,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': METHOD_ONLINE,
- '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 = response.error('migCancelErr',
- 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': METHOD_ONLINE,
+ '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 = response.error(
+ 'migCancelErr', message='Migration canceled')
+ raise
+ finally:
+ if '_migrationParams' in self._vm.conf:
+ del self._vm.conf['_migrationParams']
except MigrationDestinationSetupError as e:
self._recover(str(e))
# we know what happened, no need to dump hollow stack trace
--
To view, visit https://gerrit.ovirt.org/51655
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fb7bd6a66898804eefd9bd286c77fd8b9225bc4
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list