Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/virstorageobj.c | 116 ++++++++++++++-------------------------
1 file changed, 42 insertions(+), 74 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index c837f96ae6..fe868d25fa 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -455,11 +455,11 @@ virStoragePoolObjListSearchCb(const void *payload,
virStoragePoolObj *obj = (virStoragePoolObj *) payload;
struct _virStoragePoolObjListSearchData *data =
(struct _virStoragePoolObjListSearchData *)opaque;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
- virObjectLock(obj);
if (data->searcher(obj, data->opaque))
return 1;
- virObjectUnlock(obj);
+
return 0;
}
@@ -632,20 +632,19 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj,
return -1;
}
- virObjectLock(volobj);
+ VIR_WITH_OBJECT_LOCK_GUARD(volobj) {
+ g_hash_table_insert(volumes->objsKey, g_strdup(voldef->key), volobj);
+ virObjectRef(volobj);
- g_hash_table_insert(volumes->objsKey, g_strdup(voldef->key), volobj);
- virObjectRef(volobj);
+ g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj);
+ virObjectRef(volobj);
- g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj);
- virObjectRef(volobj);
-
- g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path), volobj);
- virObjectRef(volobj);
+ g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path),
volobj);
+ virObjectRef(volobj);
- volobj->voldef = voldef;
+ volobj->voldef = voldef;
+ }
- virObjectUnlock(volobj);
virObjectUnref(volobj);
virObjectRWUnlock(volumes);
return 0;
@@ -671,11 +670,11 @@ virStoragePoolObjRemoveVol(virStoragePoolObj *obj,
voldef->name, obj->def->name);
virObjectRef(volobj);
- virObjectLock(volobj);
- g_hash_table_remove(volumes->objsKey, voldef->key);
- g_hash_table_remove(volumes->objsName, voldef->name);
- g_hash_table_remove(volumes->objsPath, voldef->target.path);
- virObjectUnlock(volobj);
+ VIR_WITH_OBJECT_LOCK_GUARD(volobj) {
+ g_hash_table_remove(volumes->objsKey, voldef->key);
+ g_hash_table_remove(volumes->objsName, voldef->name);
+ g_hash_table_remove(volumes->objsPath, voldef->target.path);
+ }
virObjectUnref(volobj);
virObjectRWUnlock(volumes);
}
@@ -704,16 +703,14 @@ virStoragePoolObjForEachVolumeCb(void *payload,
const char *name G_GNUC_UNUSED,
void *opaque)
{
- int ret = 0;
virStorageVolObj *volobj = payload;
struct _virStoragePoolObjForEachVolData *data = opaque;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
- virObjectLock(volobj);
if (data->iter(volobj->voldef, data->opaque) < 0)
- ret = -1;
- virObjectUnlock(volobj);
+ return -1;
- return ret;
+ return 0;
}
@@ -746,14 +743,12 @@ virStoragePoolObjSearchVolumeCb(const void *payload,
virStorageVolObj *volobj = (virStorageVolObj *) payload;
struct _virStoragePoolObjSearchVolData *data =
(struct _virStoragePoolObjSearchVolData *) opaque;
- int found = 0;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
- virObjectLock(volobj);
if (data->iter(volobj->voldef, data->opaque))
- found = 1;
- virObjectUnlock(volobj);
+ return 1;
- return found;
+ return 0;
}
@@ -842,17 +837,12 @@ virStoragePoolObjNumOfVolumesCb(void *payload,
{
virStorageVolObj *volobj = payload;
struct _virStorageVolObjCountData *data = opaque;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
- virObjectLock(volobj);
-
- if (data->filter &&
- !data->filter(data->conn, data->pooldef, volobj->voldef))
- goto cleanup;
+ if (data->filter && !data->filter(data->conn, data->pooldef,
volobj->voldef))
+ return 0;
data->count++;
-
- cleanup:
- virObjectUnlock(volobj);
return 0;
}
@@ -891,6 +881,7 @@ virStoragePoolObjVolumeGetNamesCb(void *payload,
{
virStorageVolObj *volobj = payload;
struct _virStorageVolObjNameData *data = opaque;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
if (data->error)
return 0;
@@ -898,19 +889,13 @@ virStoragePoolObjVolumeGetNamesCb(void *payload,
if (data->maxnames >= 0 && data->nnames == data->maxnames)
return 0;
- virObjectLock(volobj);
-
- if (data->filter &&
- !data->filter(data->conn, data->pooldef, volobj->voldef))
- goto cleanup;
+ if (data->filter && !data->filter(data->conn, data->pooldef,
volobj->voldef))
+ return 0;
if (data->names)
data->names[data->nnames] = g_strdup(volobj->voldef->name);
data->nnames++;
-
- cleanup:
- virObjectUnlock(volobj);
return 0;
}
@@ -961,30 +946,25 @@ virStoragePoolObjVolumeListExportCallback(void *payload,
virStorageVolObj *volobj = payload;
virStoragePoolObjVolumeListExportData *data = opaque;
virStorageVolPtr vol = NULL;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
if (data->error)
return 0;
- virObjectLock(volobj);
-
- if (data->filter &&
- !data->filter(data->conn, data->pooldef, volobj->voldef))
- goto cleanup;
+ if (data->filter && !data->filter(data->conn, data->pooldef,
volobj->voldef))
+ return 0;
if (data->vols) {
if (!(vol = virGetStorageVol(data->conn, data->pooldef->name,
volobj->voldef->name,
volobj->voldef->key,
NULL, NULL))) {
data->error = true;
- goto cleanup;
+ return 0;
}
data->vols[data->nvols] = vol;
}
data->nvols++;
-
- cleanup:
- virObjectUnlock(volobj);
return 0;
}
@@ -1799,19 +1779,15 @@ virStoragePoolObjNumOfStoragePoolsCb(void *payload,
{
virStoragePoolObj *obj = payload;
struct _virStoragePoolCountData *data = opaque;
-
- virObjectLock(obj);
+ VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
if (data->filter && !data->filter(data->conn, obj->def))
- goto cleanup;
+ return 0;
if (data->wantActive != virStoragePoolObjIsActive(obj))
- goto cleanup;
+ return 0;
data->count++;
-
- cleanup:
- virObjectUnlock(obj);
return 0;
}
@@ -1851,6 +1827,7 @@ virStoragePoolObjGetNamesCb(void *payload,
{
virStoragePoolObj *obj = payload;
struct _virStoragePoolNameData *data = opaque;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
if (data->error)
return 0;
@@ -1858,21 +1835,16 @@ virStoragePoolObjGetNamesCb(void *payload,
if (data->maxnames >= 0 && data->nnames == data->maxnames)
return 0;
- virObjectLock(obj);
-
if (data->filter && !data->filter(data->conn, obj->def))
- goto cleanup;
+ return 0;
if (data->wantActive != virStoragePoolObjIsActive(obj))
- goto cleanup;
+ return 0;
if (data->names)
data->names[data->nnames] = g_strdup(obj->def->name);
data->nnames++;
-
- cleanup:
- virObjectUnlock(obj);
return 0;
}
@@ -1994,31 +1966,27 @@ virStoragePoolObjListExportCallback(void *payload,
virStoragePoolObj *obj = payload;
virStoragePoolObjListExportData *data = opaque;
virStoragePoolPtr pool = NULL;
+ VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
if (data->error)
return 0;
- virObjectLock(obj);
-
if (data->filter && !data->filter(data->conn, obj->def))
- goto cleanup;
+ return 0;
if (!virStoragePoolObjMatch(obj, data->flags))
- goto cleanup;
+ return 0;
if (data->pools) {
if (!(pool = virGetStoragePool(data->conn, obj->def->name,
obj->def->uuid, NULL, NULL))) {
data->error = true;
- goto cleanup;
+ return 0;
}
data->pools[data->nPools] = pool;
}
data->nPools++;
-
- cleanup:
- virObjectUnlock(obj);
return 0;
}
--
2.31.1