mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
virstorageobject: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
bafcc61548
commit
0c4b391e2a
@ -455,11 +455,11 @@ virStoragePoolObjListSearchCb(const void *payload,
|
|||||||
virStoragePoolObj *obj = (virStoragePoolObj *) payload;
|
virStoragePoolObj *obj = (virStoragePoolObj *) payload;
|
||||||
struct _virStoragePoolObjListSearchData *data =
|
struct _virStoragePoolObjListSearchData *data =
|
||||||
(struct _virStoragePoolObjListSearchData *)opaque;
|
(struct _virStoragePoolObjListSearchData *)opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
|
||||||
|
|
||||||
virObjectLock(obj);
|
|
||||||
if (data->searcher(obj, data->opaque))
|
if (data->searcher(obj, data->opaque))
|
||||||
return 1;
|
return 1;
|
||||||
virObjectUnlock(obj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,20 +632,19 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj,
|
|||||||
return -1;
|
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);
|
g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj);
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
|
|
||||||
g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj);
|
g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path), volobj);
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
|
|
||||||
g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path), volobj);
|
volobj->voldef = voldef;
|
||||||
virObjectRef(volobj);
|
}
|
||||||
|
|
||||||
volobj->voldef = voldef;
|
|
||||||
|
|
||||||
virObjectUnlock(volobj);
|
|
||||||
virObjectUnref(volobj);
|
virObjectUnref(volobj);
|
||||||
virObjectRWUnlock(volumes);
|
virObjectRWUnlock(volumes);
|
||||||
return 0;
|
return 0;
|
||||||
@ -671,11 +670,11 @@ virStoragePoolObjRemoveVol(virStoragePoolObj *obj,
|
|||||||
voldef->name, obj->def->name);
|
voldef->name, obj->def->name);
|
||||||
|
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
virObjectLock(volobj);
|
VIR_WITH_OBJECT_LOCK_GUARD(volobj) {
|
||||||
g_hash_table_remove(volumes->objsKey, voldef->key);
|
g_hash_table_remove(volumes->objsKey, voldef->key);
|
||||||
g_hash_table_remove(volumes->objsName, voldef->name);
|
g_hash_table_remove(volumes->objsName, voldef->name);
|
||||||
g_hash_table_remove(volumes->objsPath, voldef->target.path);
|
g_hash_table_remove(volumes->objsPath, voldef->target.path);
|
||||||
virObjectUnlock(volobj);
|
}
|
||||||
virObjectUnref(volobj);
|
virObjectUnref(volobj);
|
||||||
virObjectRWUnlock(volumes);
|
virObjectRWUnlock(volumes);
|
||||||
}
|
}
|
||||||
@ -704,16 +703,14 @@ virStoragePoolObjForEachVolumeCb(void *payload,
|
|||||||
const char *name G_GNUC_UNUSED,
|
const char *name G_GNUC_UNUSED,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
virStorageVolObj *volobj = payload;
|
virStorageVolObj *volobj = payload;
|
||||||
struct _virStoragePoolObjForEachVolData *data = opaque;
|
struct _virStoragePoolObjForEachVolData *data = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
|
||||||
|
|
||||||
virObjectLock(volobj);
|
|
||||||
if (data->iter(volobj->voldef, data->opaque) < 0)
|
if (data->iter(volobj->voldef, data->opaque) < 0)
|
||||||
ret = -1;
|
return -1;
|
||||||
virObjectUnlock(volobj);
|
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -746,14 +743,12 @@ virStoragePoolObjSearchVolumeCb(const void *payload,
|
|||||||
virStorageVolObj *volobj = (virStorageVolObj *) payload;
|
virStorageVolObj *volobj = (virStorageVolObj *) payload;
|
||||||
struct _virStoragePoolObjSearchVolData *data =
|
struct _virStoragePoolObjSearchVolData *data =
|
||||||
(struct _virStoragePoolObjSearchVolData *) opaque;
|
(struct _virStoragePoolObjSearchVolData *) opaque;
|
||||||
int found = 0;
|
VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
|
||||||
|
|
||||||
virObjectLock(volobj);
|
|
||||||
if (data->iter(volobj->voldef, data->opaque))
|
if (data->iter(volobj->voldef, data->opaque))
|
||||||
found = 1;
|
return 1;
|
||||||
virObjectUnlock(volobj);
|
|
||||||
|
|
||||||
return found;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -842,17 +837,12 @@ virStoragePoolObjNumOfVolumesCb(void *payload,
|
|||||||
{
|
{
|
||||||
virStorageVolObj *volobj = payload;
|
virStorageVolObj *volobj = payload;
|
||||||
struct _virStorageVolObjCountData *data = opaque;
|
struct _virStorageVolObjCountData *data = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
|
||||||
|
|
||||||
virObjectLock(volobj);
|
if (data->filter && !data->filter(data->conn, data->pooldef, volobj->voldef))
|
||||||
|
return 0;
|
||||||
if (data->filter &&
|
|
||||||
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
data->count++;
|
data->count++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(volobj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,6 +881,7 @@ virStoragePoolObjVolumeGetNamesCb(void *payload,
|
|||||||
{
|
{
|
||||||
virStorageVolObj *volobj = payload;
|
virStorageVolObj *volobj = payload;
|
||||||
struct _virStorageVolObjNameData *data = opaque;
|
struct _virStorageVolObjNameData *data = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
|
||||||
|
|
||||||
if (data->error)
|
if (data->error)
|
||||||
return 0;
|
return 0;
|
||||||
@ -898,19 +889,13 @@ virStoragePoolObjVolumeGetNamesCb(void *payload,
|
|||||||
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virObjectLock(volobj);
|
if (data->filter && !data->filter(data->conn, data->pooldef, volobj->voldef))
|
||||||
|
return 0;
|
||||||
if (data->filter &&
|
|
||||||
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (data->names)
|
if (data->names)
|
||||||
data->names[data->nnames] = g_strdup(volobj->voldef->name);
|
data->names[data->nnames] = g_strdup(volobj->voldef->name);
|
||||||
|
|
||||||
data->nnames++;
|
data->nnames++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(volobj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,30 +946,25 @@ virStoragePoolObjVolumeListExportCallback(void *payload,
|
|||||||
virStorageVolObj *volobj = payload;
|
virStorageVolObj *volobj = payload;
|
||||||
virStoragePoolObjVolumeListExportData *data = opaque;
|
virStoragePoolObjVolumeListExportData *data = opaque;
|
||||||
virStorageVolPtr vol = NULL;
|
virStorageVolPtr vol = NULL;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(volobj);
|
||||||
|
|
||||||
if (data->error)
|
if (data->error)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virObjectLock(volobj);
|
if (data->filter && !data->filter(data->conn, data->pooldef, volobj->voldef))
|
||||||
|
return 0;
|
||||||
if (data->filter &&
|
|
||||||
!data->filter(data->conn, data->pooldef, volobj->voldef))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (data->vols) {
|
if (data->vols) {
|
||||||
if (!(vol = virGetStorageVol(data->conn, data->pooldef->name,
|
if (!(vol = virGetStorageVol(data->conn, data->pooldef->name,
|
||||||
volobj->voldef->name, volobj->voldef->key,
|
volobj->voldef->name, volobj->voldef->key,
|
||||||
NULL, NULL))) {
|
NULL, NULL))) {
|
||||||
data->error = true;
|
data->error = true;
|
||||||
goto cleanup;
|
return 0;
|
||||||
}
|
}
|
||||||
data->vols[data->nvols] = vol;
|
data->vols[data->nvols] = vol;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->nvols++;
|
data->nvols++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(volobj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1799,19 +1779,15 @@ virStoragePoolObjNumOfStoragePoolsCb(void *payload,
|
|||||||
{
|
{
|
||||||
virStoragePoolObj *obj = payload;
|
virStoragePoolObj *obj = payload;
|
||||||
struct _virStoragePoolCountData *data = opaque;
|
struct _virStoragePoolCountData *data = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
|
||||||
virObjectLock(obj);
|
|
||||||
|
|
||||||
if (data->filter && !data->filter(data->conn, obj->def))
|
if (data->filter && !data->filter(data->conn, obj->def))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
data->count++;
|
data->count++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(obj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1851,6 +1827,7 @@ virStoragePoolObjGetNamesCb(void *payload,
|
|||||||
{
|
{
|
||||||
virStoragePoolObj *obj = payload;
|
virStoragePoolObj *obj = payload;
|
||||||
struct _virStoragePoolNameData *data = opaque;
|
struct _virStoragePoolNameData *data = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
|
||||||
|
|
||||||
if (data->error)
|
if (data->error)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1858,21 +1835,16 @@ virStoragePoolObjGetNamesCb(void *payload,
|
|||||||
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
if (data->maxnames >= 0 && data->nnames == data->maxnames)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virObjectLock(obj);
|
|
||||||
|
|
||||||
if (data->filter && !data->filter(data->conn, obj->def))
|
if (data->filter && !data->filter(data->conn, obj->def))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
if (data->wantActive != virStoragePoolObjIsActive(obj))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
if (data->names)
|
if (data->names)
|
||||||
data->names[data->nnames] = g_strdup(obj->def->name);
|
data->names[data->nnames] = g_strdup(obj->def->name);
|
||||||
|
|
||||||
data->nnames++;
|
data->nnames++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(obj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1994,31 +1966,27 @@ virStoragePoolObjListExportCallback(void *payload,
|
|||||||
virStoragePoolObj *obj = payload;
|
virStoragePoolObj *obj = payload;
|
||||||
virStoragePoolObjListExportData *data = opaque;
|
virStoragePoolObjListExportData *data = opaque;
|
||||||
virStoragePoolPtr pool = NULL;
|
virStoragePoolPtr pool = NULL;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
|
||||||
|
|
||||||
if (data->error)
|
if (data->error)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virObjectLock(obj);
|
|
||||||
|
|
||||||
if (data->filter && !data->filter(data->conn, obj->def))
|
if (data->filter && !data->filter(data->conn, obj->def))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
if (!virStoragePoolObjMatch(obj, data->flags))
|
if (!virStoragePoolObjMatch(obj, data->flags))
|
||||||
goto cleanup;
|
return 0;
|
||||||
|
|
||||||
if (data->pools) {
|
if (data->pools) {
|
||||||
if (!(pool = virGetStoragePool(data->conn, obj->def->name,
|
if (!(pool = virGetStoragePool(data->conn, obj->def->name,
|
||||||
obj->def->uuid, NULL, NULL))) {
|
obj->def->uuid, NULL, NULL))) {
|
||||||
data->error = true;
|
data->error = true;
|
||||||
goto cleanup;
|
return 0;
|
||||||
}
|
}
|
||||||
data->pools[data->nPools] = pool;
|
data->pools[data->nPools] = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->nPools++;
|
data->nPools++;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(obj);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user