Move the structure into virstorageobj.c. Use the virStoragePoolObjListNew allocator to fill in the @pools for the storage driver and test driver. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virstorageobj.c | 19 +++++++++++- src/conf/virstorageobj.h | 9 +++--- src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 69 +++++++++++++++++++++++--------------------- src/test/test_driver.c | 46 ++++++++++++++--------------- 5 files changed, 82 insertions(+), 62 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 357e6a967..a48346b24 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -62,6 +62,11 @@ struct _virStoragePoolObj { virStorageVolDefList volumes; }; +struct _virStoragePoolObjList { + size_t count; + virStoragePoolObjPtr *objs; +}; + static int virStoragePoolObjOnceInit(void) @@ -241,7 +246,19 @@ virStoragePoolObjListFree(virStoragePoolObjListPtr pools) for (i = 0; i < pools->count; i++) virObjectUnref(pools->objs[i]); VIR_FREE(pools->objs); - pools->count = 0; + VIR_FREE(pools); +} + + +virStoragePoolObjListPtr +virStoragePoolObjListNew(void) +{ + virStoragePoolObjListPtr pools; + + if (VIR_ALLOC(pools) < 0) + return NULL; + + return pools; } diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 34c4c9e10..d4165fbe7 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -29,10 +29,6 @@ typedef virStoragePoolObj *virStoragePoolObjPtr; typedef struct _virStoragePoolObjList virStoragePoolObjList; typedef virStoragePoolObjList *virStoragePoolObjListPtr; -struct _virStoragePoolObjList { - size_t count; - virStoragePoolObjPtr *objs; -}; typedef struct _virStorageDriverState virStorageDriverState; typedef virStorageDriverState *virStorageDriverStatePtr; @@ -40,7 +36,7 @@ typedef virStorageDriverState *virStorageDriverStatePtr; struct _virStorageDriverState { virMutex lock; - virStoragePoolObjList pools; + virStoragePoolObjListPtr pools; char *configDir; char *autostartDir; @@ -244,6 +240,9 @@ virStoragePoolObjListSearch(virStoragePoolObjListPtr pools, virStoragePoolObjListSearcher searcher, const void *opaque); +virStoragePoolObjListPtr +virStoragePoolObjListNew(void); + void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, virStoragePoolObjPtr obj); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 53057aa82..e4744378c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1096,6 +1096,7 @@ virStoragePoolObjIsDuplicate; virStoragePoolObjListExport; virStoragePoolObjListForEach; virStoragePoolObjListFree; +virStoragePoolObjListNew; virStoragePoolObjListSearch; virStoragePoolObjLoadAllConfigs; virStoragePoolObjLoadAllState; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 699a38281..e0748615a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -93,7 +93,7 @@ virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) virStoragePoolObjPtr obj = *objptr; if (!virStoragePoolObjGetConfigFile(obj)) { - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); *objptr = NULL; } else if (virStoragePoolObjGetNewDef(obj)) { virStoragePoolObjDefUseNewDef(obj); @@ -162,7 +162,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, static void storagePoolUpdateAllState(void) { - virStoragePoolObjListForEach(&driver->pools, + virStoragePoolObjListForEach(driver->pools, storagePoolUpdateStateCallback, NULL); } @@ -227,7 +227,7 @@ storageDriverAutostart(void) conn = virConnectOpen("qemu:///session"); /* Ignoring NULL conn - let backends decide */ - virStoragePoolObjListForEach(&driver->pools, + virStoragePoolObjListForEach(driver->pools, storageDriverAutostartCallback, conn); @@ -257,6 +257,9 @@ storageStateInitialize(bool privileged, } storageDriverLock(); + if (!(driver->pools = virStoragePoolObjListNew())) + goto error; + if (privileged) { if (VIR_STRDUP(driver->configDir, SYSCONFDIR "/libvirt/storage") < 0 || @@ -288,11 +291,11 @@ storageStateInitialize(bool privileged, goto error; } - if (virStoragePoolObjLoadAllState(&driver->pools, + if (virStoragePoolObjLoadAllState(driver->pools, driver->stateDir) < 0) goto error; - if (virStoragePoolObjLoadAllConfigs(&driver->pools, + if (virStoragePoolObjLoadAllConfigs(driver->pools, driver->configDir, driver->autostartDir) < 0) goto error; @@ -344,9 +347,9 @@ storageStateReload(void) return -1; storageDriverLock(); - virStoragePoolObjLoadAllState(&driver->pools, + virStoragePoolObjLoadAllState(driver->pools, driver->stateDir); - virStoragePoolObjLoadAllConfigs(&driver->pools, + virStoragePoolObjLoadAllConfigs(driver->pools, driver->configDir, driver->autostartDir); storageDriverAutostart(); @@ -372,7 +375,7 @@ storageStateCleanup(void) virObjectUnref(driver->storageEventState); /* free inactive pools */ - virStoragePoolObjListFree(&driver->pools); + virStoragePoolObjListFree(driver->pools); VIR_FREE(driver->configDir); VIR_FREE(driver->autostartDir); @@ -392,7 +395,7 @@ storagePoolObjFindByUUID(const unsigned char *uuid, virStoragePoolObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!(obj = virStoragePoolObjFindByUUID(&driver->pools, uuid))) { + if (!(obj = virStoragePoolObjFindByUUID(driver->pools, uuid))) { virUUIDFormat(uuid, uuidstr); if (name) virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -427,7 +430,7 @@ storagePoolObjFindByName(const char *name) virStoragePoolObjPtr obj; storageDriverLock(); - if (!(obj = virStoragePoolObjFindByName(&driver->pools, name))) + if (!(obj = virStoragePoolObjFindByName(driver->pools, name))) virReportError(VIR_ERR_NO_STORAGE_POOL, _("no storage pool with matching name '%s'"), name); storageDriverUnlock(); @@ -513,7 +516,7 @@ storageConnectNumOfStoragePools(virConnectPtr conn) return -1; storageDriverLock(); - nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, true, + nactive = virStoragePoolObjNumOfStoragePools(driver->pools, conn, true, virConnectNumOfStoragePoolsCheckACL); storageDriverUnlock(); @@ -532,7 +535,7 @@ storageConnectListStoragePools(virConnectPtr conn, return -1; storageDriverLock(); - got = virStoragePoolObjGetNames(&driver->pools, conn, true, + got = virStoragePoolObjGetNames(driver->pools, conn, true, virConnectListStoragePoolsCheckACL, names, maxnames); storageDriverUnlock(); @@ -548,7 +551,7 @@ storageConnectNumOfDefinedStoragePools(virConnectPtr conn) return -1; storageDriverLock(); - nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, false, + nactive = virStoragePoolObjNumOfStoragePools(driver->pools, conn, false, virConnectNumOfDefinedStoragePoolsCheckACL); storageDriverUnlock(); @@ -567,7 +570,7 @@ storageConnectListDefinedStoragePools(virConnectPtr conn, return -1; storageDriverLock(); - got = virStoragePoolObjGetNames(&driver->pools, conn, false, + got = virStoragePoolObjGetNames(driver->pools, conn, false, virConnectListDefinedStoragePoolsCheckACL, names, maxnames); storageDriverUnlock(); @@ -686,16 +689,16 @@ storagePoolCreateXML(virConnectPtr conn, if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0) goto cleanup; - if (virStoragePoolObjIsDuplicate(&driver->pools, newDef, 1) < 0) + if (virStoragePoolObjIsDuplicate(driver->pools, newDef, 1) < 0) goto cleanup; - if (virStoragePoolObjSourceFindDuplicate(conn, &driver->pools, newDef) < 0) + if (virStoragePoolObjSourceFindDuplicate(conn, driver->pools, newDef) < 0) goto cleanup; if ((backend = virStorageBackendForType(newDef->type)) == NULL) goto cleanup; - if (!(obj = virStoragePoolObjAssignDef(&driver->pools, newDef))) + if (!(obj = virStoragePoolObjAssignDef(driver->pools, newDef))) goto cleanup; newDef = NULL; def = virStoragePoolObjGetDef(obj); @@ -709,7 +712,7 @@ storagePoolCreateXML(virConnectPtr conn, if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { if (backend->buildPool(conn, obj, build_flags) < 0) { - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); obj = NULL; goto cleanup; } @@ -718,7 +721,7 @@ storagePoolCreateXML(virConnectPtr conn, if (backend->startPool && backend->startPool(conn, obj) < 0) { - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); obj = NULL; goto cleanup; } @@ -732,7 +735,7 @@ storagePoolCreateXML(virConnectPtr conn, unlink(stateFile); if (backend->stopPool) backend->stopPool(conn, obj); - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); obj = NULL; goto cleanup; } @@ -780,22 +783,22 @@ storagePoolDefineXML(virConnectPtr conn, if (virStoragePoolDefineXMLEnsureACL(conn, newDef) < 0) goto cleanup; - if (virStoragePoolObjIsDuplicate(&driver->pools, newDef, 0) < 0) + if (virStoragePoolObjIsDuplicate(driver->pools, newDef, 0) < 0) goto cleanup; - if (virStoragePoolObjSourceFindDuplicate(conn, &driver->pools, newDef) < 0) + if (virStoragePoolObjSourceFindDuplicate(conn, driver->pools, newDef) < 0) goto cleanup; if (virStorageBackendForType(newDef->type) == NULL) goto cleanup; - if (!(obj = virStoragePoolObjAssignDef(&driver->pools, newDef))) + if (!(obj = virStoragePoolObjAssignDef(driver->pools, newDef))) goto cleanup; newDef = NULL; def = virStoragePoolObjGetDef(obj); if (virStoragePoolObjSaveDef(driver, obj, def) < 0) { - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); obj = NULL; goto cleanup; } @@ -864,7 +867,7 @@ storagePoolUndefine(virStoragePoolPtr pool) 0); VIR_INFO("Undefining storage pool '%s'", def->name); - virStoragePoolObjRemove(&driver->pools, obj); + virStoragePoolObjRemove(driver->pools, obj); obj = NULL; ret = 0; @@ -1521,7 +1524,7 @@ storageVolLookupByKey(virConnectPtr conn, virStorageVolPtr vol = NULL; storageDriverLock(); - if ((obj = virStoragePoolObjListSearch(&driver->pools, + if ((obj = virStoragePoolObjListSearch(driver->pools, storageVolLookupByKeyCallback, &data)) && data.voldef) { def = virStoragePoolObjGetDef(obj); @@ -1606,7 +1609,7 @@ storageVolLookupByPath(virConnectPtr conn, return NULL; storageDriverLock(); - if ((obj = virStoragePoolObjListSearch(&driver->pools, + if ((obj = virStoragePoolObjListSearch(driver->pools, storageVolLookupByPathCallback, &data)) && data.voldef) { def = virStoragePoolObjGetDef(obj); @@ -1665,7 +1668,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, return NULL; storageDriverLock(); - if ((obj = virStoragePoolObjListSearch(&driver->pools, + if ((obj = virStoragePoolObjListSearch(driver->pools, storagePoolLookupByTargetPathCallback, cleanpath))) { def = virStoragePoolObjGetDef(obj); @@ -1971,10 +1974,10 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, NULL); storageDriverLock(); - obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid); + obj = virStoragePoolObjFindByUUID(driver->pools, pool->uuid); if (obj && STRNEQ(pool->name, volsrc->pool)) { virObjectUnlock(obj); - objsrc = virStoragePoolObjFindByName(&driver->pools, volsrc->pool); + objsrc = virStoragePoolObjFindByName(driver->pools, volsrc->pool); virObjectLock(obj); } storageDriverUnlock(); @@ -2271,7 +2274,7 @@ virStorageVolPoolRefreshThread(void *opaque) if (virStorageBackendPloopRestoreDesc(cbdata->vol_path) < 0) goto cleanup; } - if (!(obj = virStoragePoolObjFindByName(&driver->pools, + if (!(obj = virStoragePoolObjFindByName(driver->pools, cbdata->pool_name))) goto cleanup; def = virStoragePoolObjGetDef(obj); @@ -2687,7 +2690,7 @@ storageConnectListAllStoragePools(virConnectPtr conn, goto cleanup; storageDriverLock(); - ret = virStoragePoolObjListExport(conn, &driver->pools, pools, + ret = virStoragePoolObjListExport(conn, driver->pools, pools, virConnectListAllStoragePoolsCheckACL, flags); storageDriverUnlock(); @@ -3092,7 +3095,7 @@ virStoragePoolObjFindPoolByUUID(const unsigned char *uuid) virStoragePoolObjPtr obj; storageDriverLock(); - obj = virStoragePoolObjFindByUUID(&driver->pools, uuid); + obj = virStoragePoolObjFindByUUID(driver->pools, uuid); storageDriverUnlock(); return obj; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 25b6592bc..531e2880c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -100,7 +100,7 @@ struct _testDriver { virInterfaceObjListPtr ifaces; bool transaction_running; virInterfaceObjListPtr backupIfaces; - virStoragePoolObjList pools; + virStoragePoolObjListPtr pools; virNodeDeviceObjListPtr devs; int numCells; testCell cells[MAX_CELLS]; @@ -155,7 +155,7 @@ testDriverFree(testDriverPtr driver) virNodeDeviceObjListFree(driver->devs); virObjectUnref(driver->networks); virObjectUnref(driver->ifaces); - virStoragePoolObjListFree(&driver->pools); + virStoragePoolObjListFree(driver->pools); virObjectUnref(driver->eventState); virMutexUnlock(&driver->lock); virMutexDestroy(&driver->lock); @@ -419,7 +419,8 @@ testDriverNew(void) !(ret->ifaces = virInterfaceObjListNew()) || !(ret->domains = virDomainObjListNew()) || !(ret->networks = virNetworkObjListNew()) || - !(ret->devs = virNodeDeviceObjListNew())) + !(ret->devs = virNodeDeviceObjListNew()) || + !(ret->pools = virStoragePoolObjListNew())) goto error; virAtomicIntSet(&ret->nextDomID, 1); @@ -1112,8 +1113,7 @@ testParseStorage(testDriverPtr privconn, if (!def) goto error; - if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, - def))) { + if (!(obj = virStoragePoolObjAssignDef(privconn->pools, def))) { virStoragePoolDefFree(def); goto error; } @@ -4076,7 +4076,7 @@ testStoragePoolObjFindByName(testDriverPtr privconn, virStoragePoolObjPtr obj; testDriverLock(privconn); - obj = virStoragePoolObjFindByName(&privconn->pools, name); + obj = virStoragePoolObjFindByName(privconn->pools, name); testDriverUnlock(privconn); if (!obj) @@ -4136,7 +4136,7 @@ testStoragePoolObjFindByUUID(testDriverPtr privconn, char uuidstr[VIR_UUID_STRING_BUFLEN]; testDriverLock(privconn); - obj = virStoragePoolObjFindByUUID(&privconn->pools, uuid); + obj = virStoragePoolObjFindByUUID(privconn->pools, uuid); testDriverUnlock(privconn); if (!obj) { @@ -4204,7 +4204,7 @@ testConnectNumOfStoragePools(virConnectPtr conn) int numActive = 0; testDriverLock(privconn); - numActive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn, + numActive = virStoragePoolObjNumOfStoragePools(privconn->pools, conn, true, NULL); testDriverUnlock(privconn); @@ -4221,7 +4221,7 @@ testConnectListStoragePools(virConnectPtr conn, int n = 0; testDriverLock(privconn); - n = virStoragePoolObjGetNames(&privconn->pools, conn, true, NULL, + n = virStoragePoolObjGetNames(privconn->pools, conn, true, NULL, names, maxnames); testDriverUnlock(privconn); @@ -4236,7 +4236,7 @@ testConnectNumOfDefinedStoragePools(virConnectPtr conn) int numInactive = 0; testDriverLock(privconn); - numInactive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn, + numInactive = virStoragePoolObjNumOfStoragePools(privconn->pools, conn, false, NULL); testDriverUnlock(privconn); @@ -4253,7 +4253,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn, int n = 0; testDriverLock(privconn); - n = virStoragePoolObjGetNames(&privconn->pools, conn, false, NULL, + n = virStoragePoolObjGetNames(privconn->pools, conn, false, NULL, names, maxnames); testDriverUnlock(privconn); @@ -4272,7 +4272,7 @@ testConnectListAllStoragePools(virConnectPtr conn, virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1); testDriverLock(privconn); - ret = virStoragePoolObjListExport(conn, &privconn->pools, pools, + ret = virStoragePoolObjListExport(conn, privconn->pools, pools, NULL, flags); testDriverUnlock(privconn); @@ -4440,16 +4440,16 @@ testStoragePoolCreateXML(virConnectPtr conn, if (!(newDef = virStoragePoolDefParseString(xml))) goto cleanup; - obj = virStoragePoolObjFindByUUID(&privconn->pools, newDef->uuid); + obj = virStoragePoolObjFindByUUID(privconn->pools, newDef->uuid); if (!obj) - obj = virStoragePoolObjFindByName(&privconn->pools, newDef->name); + obj = virStoragePoolObjFindByName(privconn->pools, newDef->name); if (obj) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool already exists")); goto cleanup; } - if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef))) + if (!(obj = virStoragePoolObjAssignDef(privconn->pools, newDef))) goto cleanup; newDef = NULL; def = virStoragePoolObjGetDef(obj); @@ -4462,14 +4462,14 @@ testStoragePoolCreateXML(virConnectPtr conn, if (testCreateVport(privconn, def->source.adapter.data.fchost.wwnn, def->source.adapter.data.fchost.wwpn) < 0) { - virStoragePoolObjRemove(&privconn->pools, obj); + virStoragePoolObjRemove(privconn->pools, obj); obj = NULL; goto cleanup; } } if (testStoragePoolObjSetDefaults(obj) == -1) { - virStoragePoolObjRemove(&privconn->pools, obj); + virStoragePoolObjRemove(privconn->pools, obj); obj = NULL; goto cleanup; } @@ -4518,7 +4518,7 @@ testStoragePoolDefineXML(virConnectPtr conn, newDef->allocation = defaultPoolAlloc; newDef->available = defaultPoolCap - defaultPoolAlloc; - if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef))) + if (!(obj = virStoragePoolObjAssignDef(privconn->pools, newDef))) goto cleanup; newDef = NULL; def = virStoragePoolObjGetDef(obj); @@ -4528,7 +4528,7 @@ testStoragePoolDefineXML(virConnectPtr conn, 0); if (testStoragePoolObjSetDefaults(obj) == -1) { - virStoragePoolObjRemove(&privconn->pools, obj); + virStoragePoolObjRemove(privconn->pools, obj); obj = NULL; goto cleanup; } @@ -4558,7 +4558,7 @@ testStoragePoolUndefine(virStoragePoolPtr pool) VIR_STORAGE_POOL_EVENT_UNDEFINED, 0); - virStoragePoolObjRemove(&privconn->pools, obj); + virStoragePoolObjRemove(privconn->pools, obj); testObjectEventQueue(privconn, event); return 0; @@ -4651,7 +4651,7 @@ testStoragePoolDestroy(virStoragePoolPtr pool) 0); if (!(virStoragePoolObjGetConfigFile(obj))) { - virStoragePoolObjRemove(&privconn->pools, obj); + virStoragePoolObjRemove(privconn->pools, obj); obj = NULL; } ret = 0; @@ -4940,7 +4940,7 @@ testStorageVolLookupByKey(virConnectPtr conn, virStorageVolPtr vol = NULL; testDriverLock(privconn); - if ((obj = virStoragePoolObjListSearch(&privconn->pools, + if ((obj = virStoragePoolObjListSearch(privconn->pools, testStorageVolLookupByKeyCallback, &data)) && data.voldef) { def = virStoragePoolObjGetDef(obj); @@ -4984,7 +4984,7 @@ testStorageVolLookupByPath(virConnectPtr conn, virStorageVolPtr vol = NULL; testDriverLock(privconn); - if ((obj = virStoragePoolObjListSearch(&privconn->pools, + if ((obj = virStoragePoolObjListSearch(privconn->pools, testStorageVolLookupByPathCallback, &data)) && data.voldef) { def = virStoragePoolObjGetDef(obj); -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list