mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
virstorageobj: Replace deprecated virHash functions
Checking for duplicate / NULL keys beforehand will simplify error handling in a later patch significantly. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
08e097f605
commit
a5af1a437c
@ -521,8 +521,8 @@ virStoragePoolObjRemove(virStoragePoolObjList *pools,
|
|||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
virObjectRWLockWrite(pools);
|
virObjectRWLockWrite(pools);
|
||||||
virObjectLock(obj);
|
virObjectLock(obj);
|
||||||
virHashRemoveEntry(pools->objs, uuidstr);
|
g_hash_table_remove(pools->objs, uuidstr);
|
||||||
virHashRemoveEntry(pools->objsName, obj->def->name);
|
g_hash_table_remove(pools->objsName, obj->def->name);
|
||||||
virObjectUnref(obj);
|
virObjectUnref(obj);
|
||||||
virObjectRWUnlock(pools);
|
virObjectRWUnlock(pools);
|
||||||
}
|
}
|
||||||
@ -621,9 +621,9 @@ virStoragePoolObjClearVols(virStoragePoolObj *obj)
|
|||||||
if (!obj->volumes)
|
if (!obj->volumes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virHashRemoveAll(obj->volumes->objsKey);
|
g_hash_table_remove_all(obj->volumes->objsKey);
|
||||||
virHashRemoveAll(obj->volumes->objsName);
|
g_hash_table_remove_all(obj->volumes->objsName);
|
||||||
virHashRemoveAll(obj->volumes->objsPath);
|
g_hash_table_remove_all(obj->volumes->objsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -639,21 +639,19 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj,
|
|||||||
if (!(volobj = virStorageVolObjNew()))
|
if (!(volobj = virStorageVolObjNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virHashAddEntry(volumes->objsKey, voldef->key, volobj) < 0)
|
if (!voldef->key || !voldef->name || !voldef->target.path ||
|
||||||
|
g_hash_table_contains(volumes->objsKey, voldef->key) ||
|
||||||
|
g_hash_table_contains(volumes->objsName, voldef->name) ||
|
||||||
|
g_hash_table_contains(volumes->objsPath, voldef->target.path))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
g_hash_table_insert(volumes->objsKey, g_strdup(voldef->key), volobj);
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
|
|
||||||
if (virHashAddEntry(volumes->objsName, voldef->name, volobj) < 0) {
|
g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj);
|
||||||
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
|
|
||||||
if (virHashAddEntry(volumes->objsPath, voldef->target.path, volobj) < 0) {
|
g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path), volobj);
|
||||||
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
|
||||||
virHashRemoveEntry(volumes->objsName, voldef->name);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
|
|
||||||
volobj->voldef = voldef;
|
volobj->voldef = voldef;
|
||||||
@ -688,9 +686,9 @@ virStoragePoolObjRemoveVol(virStoragePoolObj *obj,
|
|||||||
|
|
||||||
virObjectRef(volobj);
|
virObjectRef(volobj);
|
||||||
virObjectLock(volobj);
|
virObjectLock(volobj);
|
||||||
virHashRemoveEntry(volumes->objsKey, voldef->key);
|
g_hash_table_remove(volumes->objsKey, voldef->key);
|
||||||
virHashRemoveEntry(volumes->objsName, voldef->name);
|
g_hash_table_remove(volumes->objsName, voldef->name);
|
||||||
virHashRemoveEntry(volumes->objsPath, voldef->target.path);
|
g_hash_table_remove(volumes->objsPath, voldef->target.path);
|
||||||
virStorageVolObjEndAPI(&volobj);
|
virStorageVolObjEndAPI(&volobj);
|
||||||
|
|
||||||
virObjectRWUnlock(volumes);
|
virObjectRWUnlock(volumes);
|
||||||
@ -1582,15 +1580,18 @@ virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virUUIDFormat((*def)->uuid, uuidstr);
|
virUUIDFormat((*def)->uuid, uuidstr);
|
||||||
if (virHashAddEntry(pools->objs, uuidstr, obj) < 0)
|
|
||||||
|
if (!(*def)->name ||
|
||||||
|
g_hash_table_contains(pools->objs, uuidstr) ||
|
||||||
|
g_hash_table_contains(pools->objsName, (*def)->name))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
g_hash_table_insert(pools->objs, g_strdup(uuidstr), obj);
|
||||||
virObjectRef(obj);
|
virObjectRef(obj);
|
||||||
|
|
||||||
if (virHashAddEntry(pools->objsName, (*def)->name, obj) < 0) {
|
g_hash_table_insert(pools->objsName, g_strdup((*def)->name), obj);
|
||||||
virHashRemoveEntry(pools->objs, uuidstr);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
virObjectRef(obj);
|
virObjectRef(obj);
|
||||||
|
|
||||||
obj->def = g_steal_pointer(def);
|
obj->def = g_steal_pointer(def);
|
||||||
virObjectRWUnlock(pools);
|
virObjectRWUnlock(pools);
|
||||||
return obj;
|
return obj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user