mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
storage: Introduce virStoragePoolObjNew
Create/use a helper to perform object allocation. Adjust storagevolxml2argvtest.c in order to use the allocator and setting of the obj->def. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
b31982868a
commit
407e6a3678
@ -37,6 +37,26 @@
|
||||
VIR_LOG_INIT("conf.virstorageobj");
|
||||
|
||||
|
||||
virStoragePoolObjPtr
|
||||
virStoragePoolObjNew(void)
|
||||
{
|
||||
virStoragePoolObjPtr obj;
|
||||
|
||||
if (VIR_ALLOC(obj) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&obj->lock) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("cannot initialize mutex"));
|
||||
VIR_FREE(obj);
|
||||
return NULL;
|
||||
}
|
||||
virStoragePoolObjLock(obj);
|
||||
obj->active = 0;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
virStoragePoolDefPtr
|
||||
virStoragePoolObjGetDef(virStoragePoolObjPtr obj)
|
||||
{
|
||||
@ -421,18 +441,9 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(obj) < 0)
|
||||
if (!(obj = virStoragePoolObjNew()))
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&obj->lock) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("cannot initialize mutex"));
|
||||
VIR_FREE(obj);
|
||||
return NULL;
|
||||
}
|
||||
virStoragePoolObjLock(obj);
|
||||
obj->active = 0;
|
||||
|
||||
if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, obj) < 0) {
|
||||
virStoragePoolObjUnlock(obj);
|
||||
virStoragePoolObjFree(obj);
|
||||
|
@ -70,6 +70,9 @@ typedef bool
|
||||
(*virStoragePoolObjListFilter)(virConnectPtr conn,
|
||||
virStoragePoolDefPtr def);
|
||||
|
||||
virStoragePoolObjPtr
|
||||
virStoragePoolObjNew(void);
|
||||
|
||||
virStoragePoolDefPtr
|
||||
virStoragePoolObjGetDef(virStoragePoolObjPtr obj);
|
||||
|
||||
|
@ -1075,6 +1075,7 @@ virStoragePoolObjListFree;
|
||||
virStoragePoolObjLoadAllConfigs;
|
||||
virStoragePoolObjLoadAllState;
|
||||
virStoragePoolObjLock;
|
||||
virStoragePoolObjNew;
|
||||
virStoragePoolObjNumOfStoragePools;
|
||||
virStoragePoolObjNumOfVolumes;
|
||||
virStoragePoolObjRemove;
|
||||
|
@ -885,7 +885,10 @@ storagevolxml2argvtest_SOURCES = \
|
||||
testutils.c testutils.h
|
||||
storagevolxml2argvtest_LDADD = \
|
||||
$(LIBXML_LIBS) \
|
||||
../src/libvirt_driver_storage_impl.la $(LDADDS)
|
||||
../src/libvirt_driver_storage_impl.la \
|
||||
../src/libvirt_conf.la \
|
||||
../src/libvirt_util.la \
|
||||
$(LDADDS)
|
||||
|
||||
else ! WITH_STORAGE
|
||||
EXTRA_DIST += storagevolxml2argvtest.c
|
||||
|
@ -50,18 +50,21 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
virConnectPtr conn;
|
||||
|
||||
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
||||
virStoragePoolDefPtr pool = NULL;
|
||||
virStoragePoolDefPtr def = NULL;
|
||||
virStoragePoolDefPtr inputpool = NULL;
|
||||
virStoragePoolObj poolobj = {.def = NULL };
|
||||
|
||||
virStoragePoolObjPtr obj = NULL;
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto cleanup;
|
||||
|
||||
if (!(pool = virStoragePoolDefParseFile(poolxml)))
|
||||
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
||||
goto cleanup;
|
||||
|
||||
poolobj.def = pool;
|
||||
if (!(obj = virStoragePoolObjNew())) {
|
||||
virStoragePoolDefFree(def);
|
||||
goto cleanup;
|
||||
}
|
||||
virStoragePoolObjSetDef(obj, def);
|
||||
|
||||
if (inputpoolxml) {
|
||||
if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
|
||||
@ -71,17 +74,17 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
if (inputvolxml)
|
||||
parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
|
||||
|
||||
if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags)))
|
||||
if (!(vol = virStorageVolDefParseFile(def, volxml, parse_flags)))
|
||||
goto cleanup;
|
||||
|
||||
if (inputvolxml &&
|
||||
!(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
|
||||
goto cleanup;
|
||||
|
||||
testSetVolumeType(vol, pool);
|
||||
testSetVolumeType(vol, def);
|
||||
testSetVolumeType(inputvol, inputpool);
|
||||
|
||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol,
|
||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol,
|
||||
inputvol, flags,
|
||||
create_tool, imgformat,
|
||||
NULL);
|
||||
@ -102,12 +105,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virStoragePoolDefFree(pool);
|
||||
virStoragePoolDefFree(inputpool);
|
||||
virStorageVolDefFree(vol);
|
||||
virStorageVolDefFree(inputvol);
|
||||
virCommandFree(cmd);
|
||||
VIR_FREE(actualCmdline);
|
||||
virStoragePoolObjUnlock(obj);
|
||||
virStoragePoolObjFree(obj);
|
||||
virObjectUnref(conn);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user