mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
virStoragePoolObjListAdd: Transfer definition ownership
Upon successful return from virStoragePoolObjListAdd() the virStoragePoolObj is the owner of secret definition. To make this ownership transfer even more visible, lets pass the definition as a double pointer and use g_steal_pointer(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
8196a213b4
commit
900fb1a315
@ -1513,20 +1513,20 @@ virStoragePoolObjSourceFindDuplicate(virStoragePoolObjList *pools,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
virStoragePoolObjAssignDef(virStoragePoolObj *obj,
|
virStoragePoolObjAssignDef(virStoragePoolObj *obj,
|
||||||
virStoragePoolDef *def,
|
virStoragePoolDef **def,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
if (virStoragePoolObjIsActive(obj) ||
|
if (virStoragePoolObjIsActive(obj) ||
|
||||||
virStoragePoolObjIsStarting(obj)) {
|
virStoragePoolObjIsStarting(obj)) {
|
||||||
virStoragePoolDefFree(obj->newDef);
|
virStoragePoolDefFree(obj->newDef);
|
||||||
obj->newDef = def;
|
obj->newDef = g_steal_pointer(def);
|
||||||
} else {
|
} else {
|
||||||
if (!obj->newDef &&
|
if (!obj->newDef &&
|
||||||
flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE)
|
flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE)
|
||||||
obj->newDef = g_steal_pointer(&obj->def);
|
obj->newDef = g_steal_pointer(&obj->def);
|
||||||
|
|
||||||
virStoragePoolDefFree(obj->def);
|
virStoragePoolDefFree(obj->def);
|
||||||
obj->def = def;
|
obj->def = g_steal_pointer(def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1548,11 +1548,16 @@ virStoragePoolObjAssignDef(virStoragePoolObj *obj,
|
|||||||
* If VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE is set in @flags
|
* If VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE is set in @flags
|
||||||
* then this will fail if the pool exists and is active.
|
* then this will fail if the pool exists and is active.
|
||||||
*
|
*
|
||||||
|
* Upon successful return the virStoragePool object is the owner
|
||||||
|
* of @def and callers should use virStoragePoolObjGetDef() or
|
||||||
|
* virStoragePoolObjGetNewDef() if they need to access the
|
||||||
|
* definition as @def is set to NULL.
|
||||||
|
*
|
||||||
* Returns locked and reffed object pointer or NULL on error
|
* Returns locked and reffed object pointer or NULL on error
|
||||||
*/
|
*/
|
||||||
virStoragePoolObj *
|
virStoragePoolObj *
|
||||||
virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
||||||
virStoragePoolDef *def,
|
virStoragePoolDef **def,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virStoragePoolObj *obj = NULL;
|
virStoragePoolObj *obj = NULL;
|
||||||
@ -1561,10 +1566,10 @@ virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
|||||||
|
|
||||||
virObjectRWLockWrite(pools);
|
virObjectRWLockWrite(pools);
|
||||||
|
|
||||||
if (virStoragePoolObjSourceFindDuplicate(pools, def) < 0)
|
if (virStoragePoolObjSourceFindDuplicate(pools, *def) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
rc = virStoragePoolObjIsDuplicate(pools, def,
|
rc = virStoragePoolObjIsDuplicate(pools, *def,
|
||||||
!!(flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE),
|
!!(flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE),
|
||||||
&obj);
|
&obj);
|
||||||
|
|
||||||
@ -1579,17 +1584,17 @@ virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
|||||||
if (!(obj = virStoragePoolObjNew()))
|
if (!(obj = virStoragePoolObjNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virUUIDFormat(def->uuid, uuidstr);
|
virUUIDFormat((*def)->uuid, uuidstr);
|
||||||
if (virHashAddEntry(pools->objs, uuidstr, obj) < 0)
|
if (virHashAddEntry(pools->objs, uuidstr, obj) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
virObjectRef(obj);
|
virObjectRef(obj);
|
||||||
|
|
||||||
if (virHashAddEntry(pools->objsName, def->name, obj) < 0) {
|
if (virHashAddEntry(pools->objsName, (*def)->name, obj) < 0) {
|
||||||
virHashRemoveEntry(pools->objs, uuidstr);
|
virHashRemoveEntry(pools->objs, uuidstr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
virObjectRef(obj);
|
virObjectRef(obj);
|
||||||
obj->def = def;
|
obj->def = g_steal_pointer(def);
|
||||||
virObjectRWUnlock(pools);
|
virObjectRWUnlock(pools);
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
@ -1620,9 +1625,8 @@ virStoragePoolObjLoad(virStoragePoolObjList *pools,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(pools, def, 0)))
|
if (!(obj = virStoragePoolObjListAdd(pools, &def, 0)))
|
||||||
return NULL;
|
return NULL;
|
||||||
def = NULL;
|
|
||||||
|
|
||||||
VIR_FREE(obj->configFile); /* for driver reload */
|
VIR_FREE(obj->configFile); /* for driver reload */
|
||||||
obj->configFile = g_strdup(path);
|
obj->configFile = g_strdup(path);
|
||||||
@ -1673,10 +1677,9 @@ virStoragePoolObjLoadState(virStoragePoolObjList *pools,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create the object */
|
/* create the object */
|
||||||
if (!(obj = virStoragePoolObjListAdd(pools, def,
|
if (!(obj = virStoragePoolObjListAdd(pools, &def,
|
||||||
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
||||||
return NULL;
|
return NULL;
|
||||||
def = NULL;
|
|
||||||
|
|
||||||
/* XXX: future handling of some additional useful status data,
|
/* XXX: future handling of some additional useful status data,
|
||||||
* for now, if a status file for a pool exists, the pool will be marked
|
* for now, if a status file for a pool exists, the pool will be marked
|
||||||
|
@ -203,7 +203,7 @@ typedef enum {
|
|||||||
|
|
||||||
virStoragePoolObj *
|
virStoragePoolObj *
|
||||||
virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
virStoragePoolObjListAdd(virStoragePoolObjList *pools,
|
||||||
virStoragePoolDef *def,
|
virStoragePoolDef **def,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -746,11 +746,10 @@ storagePoolCreateXML(virConnectPtr conn,
|
|||||||
if ((backend = virStorageBackendForType(newDef->type)) == NULL)
|
if ((backend = virStorageBackendForType(newDef->type)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef,
|
if (!(obj = virStoragePoolObjListAdd(driver->pools, &newDef,
|
||||||
VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE |
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE |
|
||||||
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
newDef = NULL;
|
|
||||||
def = virStoragePoolObjGetDef(obj);
|
def = virStoragePoolObjGetDef(obj);
|
||||||
|
|
||||||
virStoragePoolObjSetStarting(obj, true);
|
virStoragePoolObjSetStarting(obj, true);
|
||||||
@ -830,7 +829,7 @@ storagePoolDefineXML(virConnectPtr conn,
|
|||||||
if (virStorageBackendForType(newDef->type) == NULL)
|
if (virStorageBackendForType(newDef->type) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef, 0)))
|
if (!(obj = virStoragePoolObjListAdd(driver->pools, &newDef, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
newDef = virStoragePoolObjGetNewDef(obj);
|
newDef = virStoragePoolObjGetNewDef(obj);
|
||||||
def = virStoragePoolObjGetDef(obj);
|
def = virStoragePoolObjGetDef(obj);
|
||||||
|
@ -1226,7 +1226,7 @@ testParseStorage(testDriver *privconn,
|
|||||||
if (!def)
|
if (!def)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(privconn->pools, def, 0))) {
|
if (!(obj = virStoragePoolObjListAdd(privconn->pools, &def, 0))) {
|
||||||
virStoragePoolDefFree(def);
|
virStoragePoolDefFree(def);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -6675,10 +6675,9 @@ testStoragePoolCreateXML(virConnectPtr conn,
|
|||||||
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef,
|
if (!(obj = virStoragePoolObjListAdd(privconn->pools, &newDef,
|
||||||
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
newDef = NULL;
|
|
||||||
def = virStoragePoolObjGetDef(obj);
|
def = virStoragePoolObjGetDef(obj);
|
||||||
|
|
||||||
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
|
||||||
@ -6742,9 +6741,8 @@ testStoragePoolDefineXML(virConnectPtr conn,
|
|||||||
newDef->allocation = defaultPoolAlloc;
|
newDef->allocation = defaultPoolAlloc;
|
||||||
newDef->available = defaultPoolCap - defaultPoolAlloc;
|
newDef->available = defaultPoolCap - defaultPoolAlloc;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef, 0)))
|
if (!(obj = virStoragePoolObjListAdd(privconn->pools, &newDef, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
newDef = NULL;
|
|
||||||
def = virStoragePoolObjGetDef(obj);
|
def = virStoragePoolObjGetDef(obj);
|
||||||
|
|
||||||
event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
|
event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user