mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +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");
|
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
|
virStoragePoolDefPtr
|
||||||
virStoragePoolObjGetDef(virStoragePoolObjPtr obj)
|
virStoragePoolObjGetDef(virStoragePoolObjPtr obj)
|
||||||
{
|
{
|
||||||
@ -421,18 +441,9 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(obj) < 0)
|
if (!(obj = virStoragePoolObjNew()))
|
||||||
return NULL;
|
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) {
|
if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, obj) < 0) {
|
||||||
virStoragePoolObjUnlock(obj);
|
virStoragePoolObjUnlock(obj);
|
||||||
virStoragePoolObjFree(obj);
|
virStoragePoolObjFree(obj);
|
||||||
|
@ -70,6 +70,9 @@ typedef bool
|
|||||||
(*virStoragePoolObjListFilter)(virConnectPtr conn,
|
(*virStoragePoolObjListFilter)(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
|
||||||
|
virStoragePoolObjPtr
|
||||||
|
virStoragePoolObjNew(void);
|
||||||
|
|
||||||
virStoragePoolDefPtr
|
virStoragePoolDefPtr
|
||||||
virStoragePoolObjGetDef(virStoragePoolObjPtr obj);
|
virStoragePoolObjGetDef(virStoragePoolObjPtr obj);
|
||||||
|
|
||||||
|
@ -1075,6 +1075,7 @@ virStoragePoolObjListFree;
|
|||||||
virStoragePoolObjLoadAllConfigs;
|
virStoragePoolObjLoadAllConfigs;
|
||||||
virStoragePoolObjLoadAllState;
|
virStoragePoolObjLoadAllState;
|
||||||
virStoragePoolObjLock;
|
virStoragePoolObjLock;
|
||||||
|
virStoragePoolObjNew;
|
||||||
virStoragePoolObjNumOfStoragePools;
|
virStoragePoolObjNumOfStoragePools;
|
||||||
virStoragePoolObjNumOfVolumes;
|
virStoragePoolObjNumOfVolumes;
|
||||||
virStoragePoolObjRemove;
|
virStoragePoolObjRemove;
|
||||||
|
@ -885,7 +885,10 @@ storagevolxml2argvtest_SOURCES = \
|
|||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
storagevolxml2argvtest_LDADD = \
|
storagevolxml2argvtest_LDADD = \
|
||||||
$(LIBXML_LIBS) \
|
$(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
|
else ! WITH_STORAGE
|
||||||
EXTRA_DIST += storagevolxml2argvtest.c
|
EXTRA_DIST += storagevolxml2argvtest.c
|
||||||
|
@ -50,18 +50,21 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
|
|
||||||
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
||||||
virStoragePoolDefPtr pool = NULL;
|
virStoragePoolDefPtr def = NULL;
|
||||||
virStoragePoolDefPtr inputpool = NULL;
|
virStoragePoolDefPtr inputpool = NULL;
|
||||||
virStoragePoolObj poolobj = {.def = NULL };
|
virStoragePoolObjPtr obj = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (!(conn = virGetConnect()))
|
if (!(conn = virGetConnect()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(pool = virStoragePoolDefParseFile(poolxml)))
|
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
poolobj.def = pool;
|
if (!(obj = virStoragePoolObjNew())) {
|
||||||
|
virStoragePoolDefFree(def);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
virStoragePoolObjSetDef(obj, def);
|
||||||
|
|
||||||
if (inputpoolxml) {
|
if (inputpoolxml) {
|
||||||
if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
|
if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
|
||||||
@ -71,17 +74,17 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
if (inputvolxml)
|
if (inputvolxml)
|
||||||
parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
|
parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
|
||||||
|
|
||||||
if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags)))
|
if (!(vol = virStorageVolDefParseFile(def, volxml, parse_flags)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (inputvolxml &&
|
if (inputvolxml &&
|
||||||
!(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
|
!(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
testSetVolumeType(vol, pool);
|
testSetVolumeType(vol, def);
|
||||||
testSetVolumeType(inputvol, inputpool);
|
testSetVolumeType(inputvol, inputpool);
|
||||||
|
|
||||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol,
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol,
|
||||||
inputvol, flags,
|
inputvol, flags,
|
||||||
create_tool, imgformat,
|
create_tool, imgformat,
|
||||||
NULL);
|
NULL);
|
||||||
@ -102,12 +105,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStoragePoolDefFree(pool);
|
|
||||||
virStoragePoolDefFree(inputpool);
|
virStoragePoolDefFree(inputpool);
|
||||||
virStorageVolDefFree(vol);
|
virStorageVolDefFree(vol);
|
||||||
virStorageVolDefFree(inputvol);
|
virStorageVolDefFree(inputvol);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(actualCmdline);
|
VIR_FREE(actualCmdline);
|
||||||
|
virStoragePoolObjUnlock(obj);
|
||||||
|
virStoragePoolObjFree(obj);
|
||||||
virObjectUnref(conn);
|
virObjectUnref(conn);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user