Daniel Erez has uploaded a new change for review.
Change subject: task: refactor lock acquiring helper functions
......................................................................
task: refactor lock acquiring helper functions
Refactored 'getExclusiveLock' and 'getSharedLock' functions
on Task class:
* Both functions now gets a list of resources names
and a dictionary of options.
- The list of resources are joined by '_' character in
a new inner private function: '_acquireResource'
(i.e. the functions keep backwards compatibility).
- The options dictionary can be used for the optional
timeout value.
* Modified usages of both these functions accordingly on
'hsm -> removeVM/updateVM/deleteImage'.
Change-Id: Iac7eaa5ad577279a602651ab2df9e53ee58ac9d5
Signed-off-by: Daniel Erez <derez(a)redhat.com>
---
M vdsm/storage/hsm.py
M vdsm/storage/task.py
2 files changed, 18 insertions(+), 23 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/29729/1
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 30767b4..0170d5d 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -1341,7 +1341,7 @@
if not sdUUID or sdUUID == sd.BLANK_UUID:
sdUUID = pool.masterDomain.sdUUID
- vars.task.getExclusiveLock(STORAGE, "vms_" + sdUUID)
+ vars.task.getExclusiveLock(STORAGE, "vms", sdUUID)
pool.updateVM(vmList=vmList, sdUUID=sdUUID)
@public
@@ -1364,8 +1364,8 @@
if not sdUUID or sdUUID == sd.BLANK_UUID:
sdUUID = pool.masterDomain.sdUUID
- vars.task.getSharedLock(STORAGE, "vms_" + sdUUID)
- vars.task.getExclusiveLock(STORAGE, "vms_%s_%s" % (vmUUID, sdUUID))
+ vars.task.getSharedLock(STORAGE, "vms", sdUUID)
+ vars.task.getExclusiveLock(STORAGE, "vms", vmUUID, sdUUID)
pool.removeVM(vmUUID=vmUUID, sdUUID=sdUUID)
@public
@@ -1494,7 +1494,7 @@
# Taking an exclusive lock on both imgUUID and sdUUID since
# an image can exist on two SDs concurrently (e.g. during LSM flow);
# hence, we need a unique identifier.
- vars.task.getExclusiveLock(STORAGE, "%s_%s" % (imgUUID, sdUUID))
+ vars.task.getExclusiveLock(STORAGE, imgUUID, sdUUID)
vars.task.getSharedLock(STORAGE, sdUUID)
allVols = dom.getAllVolumes()
volsByImg = sd.getVolsOfImage(allVols, imgUUID)
diff --git a/vdsm/storage/task.py b/vdsm/storage/task.py
index f9ce837..d5849c3 100644
--- a/vdsm/storage/task.py
+++ b/vdsm/storage/task.py
@@ -439,6 +439,9 @@
class Task:
+
+ DEFAULT_TIMEOUT = config.getint('irs',
'task_resource_default_timeout')
+
# External Task info
fields = {
# field_name: type
@@ -1323,24 +1326,16 @@
return s
@misc.logskip("ResourceManager")
- def getExclusiveLock(
- self,
- namespace,
- resName,
- timeout=config.getint('irs',
- 'task_resource_default_timeout')):
- self.resOwner.acquire(namespace,
- resName,
- resourceManager.LockType.exclusive,
- timeout)
+ def getExclusiveLock(self, namespace, *resources, **options):
+ self._acquireResource(resourceManager.LockType.exclusive, namespace,
+ resources, options)
@misc.logskip("ResourceManager")
- def getSharedLock(self,
- namespace,
- resName,
- timeout=config.getint('irs',
- 'task_resource_default_timeout')):
- self.resOwner.acquire(namespace,
- resName,
- resourceManager.LockType.shared,
- timeout)
+ def getSharedLock(self, namespace, *resources, **options):
+ self._acquireResource(resourceManager.LockType.shared, namespace,
+ resources, options)
+
+ def _acquireResource(self, lock_type, namespace, resources, options):
+ resource_name = '_'.join(resources)
+ timeout = options.get('timeout', self.DEFAULT_TIMEOUT)
+ self.resOwner.acquire(namespace, resource_name, lock_type, timeout)
\ No newline at end of file
--
To view, visit
http://gerrit.ovirt.org/29729
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac7eaa5ad577279a602651ab2df9e53ee58ac9d5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Daniel Erez <derez(a)redhat.com>