[libvirt] [PATCH 00/19] Start altering storage code to privatize of the object

Begin the process of making adjustments to the storage pool and volume code in order to privatize the virStoragePoolObj and virStoragePoolObjList Didn't want to post 40+ patches at one time... This is the first storage pile including some test driver cleanups w/r/t storage code. John Ferlan (19): test: Fix up formatting in storage test API's test: Use consistent variable names for storage test driver APIs test: Cleanup exit/failure paths of some storage pool APIs test: Add helpers to fetch active/inactive storage pool by name test: Add testStorageVolDefFindByName for storage volume tests storage: Fix return value checks for virAsprintf storage: Use consistent variable names in virstorageobj storage: Use consistent variable names for driver storage: Alter volume num, name, and export API's to just take obj storage: Create accessor API's for virStoragePoolObj storage: Introduce virStoragePoolObjNew storage: Introduce virStoragePoolObj{Get|Set}Autostart storage: Move autostartLink deletion to virstorageobj storage: Introduce storage volume add, delete, count APIs storage: Introduce virStoragePoolObjForEachVolume storage: Use virStoragePoolObj accessors for driver storage: Use virStoragePoolObj accessors for storage test API's storage: Use virStoragePoolObj accessors for storage_util storage: Change storage_util to use obj instead of pool src/conf/virstorageobj.c | 568 +++++++++----- src/conf/virstorageobj.h | 84 +- src/libvirt_private.syms | 16 + src/storage/storage_backend_disk.c | 31 +- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_backend_logical.c | 5 +- src/storage/storage_backend_mpath.c | 3 +- src/storage/storage_backend_rbd.c | 12 +- src/storage/storage_backend_sheepdog.c | 8 +- src/storage/storage_backend_zfs.c | 9 +- src/storage/storage_driver.c | 1308 ++++++++++++++++---------------- src/storage/storage_driver.h | 4 +- src/storage/storage_util.c | 200 ++--- src/storage/storage_util.h | 30 +- src/test/test_driver.c | 780 +++++++++---------- 15 files changed, 1614 insertions(+), 1447 deletions(-) -- 2.9.3

Fix some spacing/formatting in the storage pool/vol test driver code. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2db3f7d..548f318 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1035,6 +1035,7 @@ testParseInterfaces(testDriverPtr privconn, return ret; } + static int testOpenVolumesForPool(const char *file, xmlXPathContextPtr ctxt, @@ -1091,6 +1092,7 @@ testOpenVolumesForPool(const char *file, return ret; } + static int testParseStorage(testDriverPtr privconn, const char *file, @@ -1143,6 +1145,7 @@ testParseStorage(testDriverPtr privconn, return ret; } + static int testParseNodedevs(testDriverPtr privconn, const char *file, @@ -3996,8 +3999,8 @@ testInterfaceDestroy(virInterfacePtr iface, * Storage Driver routines */ - -static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) +static int +testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { pool->def->capacity = defaultPoolCap; @@ -4069,6 +4072,7 @@ testStoragePoolLookupByUUID(virConnectPtr conn, return ret; } + static virStoragePoolPtr testStoragePoolLookupByName(virConnectPtr conn, const char *name) @@ -4089,6 +4093,7 @@ testStoragePoolLookupByName(virConnectPtr conn, return ret; } + static virStoragePoolPtr testStoragePoolLookupByVolume(virStorageVolPtr vol) { @@ -4159,6 +4164,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn, return n; } + static int testConnectListAllStoragePools(virConnectPtr conn, virStoragePoolPtr **pools, @@ -4177,7 +4183,9 @@ testConnectListAllStoragePools(virConnectPtr conn, return ret; } -static int testStoragePoolIsActive(virStoragePoolPtr pool) + +static int +testStoragePoolIsActive(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; @@ -4194,7 +4202,9 @@ static int testStoragePoolIsActive(virStoragePoolPtr pool) return ret; } -static int testStoragePoolIsPersistent(virStoragePoolPtr pool) + +static int +testStoragePoolIsPersistent(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; @@ -4212,7 +4222,6 @@ static int testStoragePoolIsPersistent(virStoragePoolPtr pool) } - static int testStoragePoolCreate(virStoragePoolPtr pool, unsigned int flags) @@ -4247,6 +4256,7 @@ testStoragePoolCreate(virStoragePoolPtr pool, return ret; } + static char * testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type, @@ -4401,6 +4411,7 @@ testStoragePoolCreateXML(virConnectPtr conn, return ret; } + static virStoragePoolPtr testStoragePoolDefineXML(virConnectPtr conn, const char *xml, @@ -4448,6 +4459,7 @@ testStoragePoolDefineXML(virConnectPtr conn, return ret; } + static int testStoragePoolUndefine(virStoragePoolPtr pool) { @@ -4480,6 +4492,7 @@ testStoragePoolUndefine(virStoragePoolPtr pool) return ret; } + static int testStoragePoolBuild(virStoragePoolPtr pool, unsigned int flags) @@ -4677,6 +4690,7 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, return ret; } + static char * testStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) @@ -4698,6 +4712,7 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool, return ret; } + static int testStoragePoolGetAutostart(virStoragePoolPtr pool, int *autostart) @@ -4722,6 +4737,7 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, return ret; } + static int testStoragePoolSetAutostart(virStoragePoolPtr pool, int autostart) @@ -4832,6 +4848,7 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, return ret; } + static virStorageVolPtr testStorageVolLookupByName(virStoragePoolPtr pool, const char *name ATTRIBUTE_UNUSED) @@ -4905,6 +4922,7 @@ testStorageVolLookupByKey(virConnectPtr conn, return ret; } + static virStorageVolPtr testStorageVolLookupByPath(virConnectPtr conn, const char *path) @@ -4941,6 +4959,7 @@ testStorageVolLookupByPath(virConnectPtr conn, return ret; } + static virStorageVolPtr testStorageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, @@ -5007,6 +5026,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, return ret; } + static virStorageVolPtr testStorageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, @@ -5084,6 +5104,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, return ret; } + static int testStorageVolDelete(virStorageVolPtr vol, unsigned int flags) @@ -5136,7 +5157,8 @@ testStorageVolDelete(virStorageVolPtr vol, } -static int testStorageVolumeTypeForPool(int pooltype) +static int +testStorageVolumeTypeForPool(int pooltype) { switch (pooltype) { @@ -5149,6 +5171,7 @@ static int testStorageVolumeTypeForPool(int pooltype) } } + static int testStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) @@ -5188,6 +5211,7 @@ testStorageVolGetInfo(virStorageVolPtr vol, return ret; } + static char * testStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) @@ -5225,6 +5249,7 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, return ret; } + static char * testStorageVolGetPath(virStorageVolPtr vol) { -- 2.9.3

On Tue, May 09, 2017 at 11:30:08AM -0400, John Ferlan wrote:
Fix some spacing/formatting in the storage pool/vol test driver code.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

A virStoragePoolObjPtr will be an 'obj'. A virStoragePoolPtr will be a 'pool'. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 443 ++++++++++++++++++++++++------------------------- 1 file changed, 219 insertions(+), 224 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 548f318..c0e46af 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -565,7 +565,7 @@ static const char *defaultPoolSourcesNetFSXML = static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull); static const unsigned long long defaultPoolAlloc; -static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool); +static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj); static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info); static virDomainObjPtr @@ -1039,8 +1039,8 @@ testParseInterfaces(testDriverPtr privconn, static int testOpenVolumesForPool(const char *file, xmlXPathContextPtr ctxt, - virStoragePoolObjPtr pool, - int poolidx) + virStoragePoolObjPtr obj, + int objidx) { char *vol_xpath; size_t i; @@ -1049,7 +1049,7 @@ testOpenVolumesForPool(const char *file, virStorageVolDefPtr def = NULL; /* Find storage volumes */ - if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", poolidx) < 0) + if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", objidx) < 0) goto error; num = virXPathNodeSet(vol_xpath, ctxt, &nodes); @@ -1063,25 +1063,24 @@ testOpenVolumesForPool(const char *file, if (!node) goto error; - def = virStorageVolDefParseNode(pool->def, ctxt->doc, node, 0); + def = virStorageVolDefParseNode(obj->def, ctxt->doc, node, 0); if (!def) goto error; if (def->target.path == NULL) { if (virAsprintf(&def->target.path, "%s/%s", - pool->def->target.path, + obj->def->target.path, def->name) == -1) goto error; } if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0) goto error; - if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0) + if (VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, obj->volumes.count, def) < 0) goto error; - pool->def->allocation += def->target.allocation; - pool->def->available = (pool->def->capacity - - pool->def->allocation); + obj->def->allocation += def->target.allocation; + obj->def->available = (obj->def->capacity - obj->def->allocation); def = NULL; } @@ -4000,14 +3999,14 @@ testInterfaceDestroy(virInterfacePtr iface, */ static int -testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) +testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj) { - pool->def->capacity = defaultPoolCap; - pool->def->allocation = defaultPoolAlloc; - pool->def->available = defaultPoolCap - defaultPoolAlloc; + obj->def->capacity = defaultPoolCap; + obj->def->allocation = defaultPoolAlloc; + obj->def->available = defaultPoolCap - defaultPoolAlloc; - return VIR_STRDUP(pool->configFile, ""); + return VIR_STRDUP(obj->configFile, ""); } @@ -4015,18 +4014,18 @@ static virStoragePoolObjPtr testStoragePoolObjFindByName(testDriverPtr privconn, const char *name) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; testDriverLock(privconn); - pool = virStoragePoolObjFindByName(&privconn->pools, name); + obj = virStoragePoolObjFindByName(&privconn->pools, name); testDriverUnlock(privconn); - if (!pool) + if (!obj) virReportError(VIR_ERR_NO_STORAGE_POOL, _("no storage pool with matching name '%s'"), name); - return pool; + return obj; } @@ -4034,21 +4033,21 @@ static virStoragePoolObjPtr testStoragePoolObjFindByUUID(testDriverPtr privconn, const unsigned char *uuid) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; testDriverLock(privconn); - pool = virStoragePoolObjFindByUUID(&privconn->pools, uuid); + obj = virStoragePoolObjFindByUUID(&privconn->pools, uuid); testDriverUnlock(privconn); - if (!pool) { + if (!obj) { virUUIDFormat(uuid, uuidstr); virReportError(VIR_ERR_NO_STORAGE_POOL, _("no storage pool with matching uuid '%s'"), uuidstr); } - return pool; + return obj; } @@ -4057,18 +4056,18 @@ testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL; - if (!(pool = testStoragePoolObjFindByUUID(privconn, uuid))) + if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) goto cleanup; - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4078,18 +4077,18 @@ testStoragePoolLookupByName(virConnectPtr conn, const char *name) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL; - if (!(pool = testStoragePoolObjFindByName(privconn, name))) + if (!(obj = testStoragePoolObjFindByName(privconn, name))) goto cleanup; - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4227,22 +4226,22 @@ testStoragePoolCreate(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virObjectEventPtr event = NULL; virCheckFlags(0, -1); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (virStoragePoolObjIsActive(privpool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), pool->name); goto cleanup; } - privpool->active = 1; + obj->active = 1; event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, VIR_STORAGE_POOL_EVENT_STARTED, @@ -4251,8 +4250,8 @@ testStoragePoolCreate(virStoragePoolPtr pool, cleanup: testObjectEventQueue(privconn, event); - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4345,7 +4344,7 @@ testStoragePoolCreateXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL; virObjectEventPtr event = NULL; @@ -4355,58 +4354,58 @@ testStoragePoolCreateXML(virConnectPtr conn, if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; - pool = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid); - if (!pool) - pool = virStoragePoolObjFindByName(&privconn->pools, def->name); - if (pool) { + obj = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid); + if (!obj) + obj = virStoragePoolObjFindByName(&privconn->pools, def->name); + if (obj) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage pool already exists")); goto cleanup; } - if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; - if (pool->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { + if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { /* In the real code, we'd call virVHBAManageVport followed by * find_new_device, but we cannot do that here since we're not * mocking udev. The mock routine will copy an existing vHBA and * rename a few fields to mock that. */ if (testCreateVport(privconn, - pool->def->source.adapter.data.fchost.wwnn, - pool->def->source.adapter.data.fchost.wwpn) < 0) { - virStoragePoolObjRemove(&privconn->pools, pool); - pool = NULL; + obj->def->source.adapter.data.fchost.wwnn, + obj->def->source.adapter.data.fchost.wwpn) < 0) { + virStoragePoolObjRemove(&privconn->pools, obj); + obj = NULL; goto cleanup; } } - if (testStoragePoolObjSetDefaults(pool) == -1) { - virStoragePoolObjRemove(&privconn->pools, pool); - pool = NULL; + if (testStoragePoolObjSetDefaults(obj) == -1) { + virStoragePoolObjRemove(&privconn->pools, obj); + obj = NULL; goto cleanup; } /* *SetDefaults fills this in for the persistent pools, but this * would be a transient pool so remove it; otherwise, the Destroy * code will not Remove the pool */ - VIR_FREE(pool->configFile); + VIR_FREE(obj->configFile); - pool->active = 1; + obj->active = 1; - event = virStoragePoolEventLifecycleNew(pool->def->name, pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: virStoragePoolDefFree(def); testObjectEventQueue(privconn, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); testDriverUnlock(privconn); return ret; } @@ -4419,7 +4418,7 @@ testStoragePoolDefineXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL; virObjectEventPtr event = NULL; @@ -4433,28 +4432,28 @@ testStoragePoolDefineXML(virConnectPtr conn, def->allocation = defaultPoolAlloc; def->available = defaultPoolCap - defaultPoolAlloc; - if (!(pool = virStoragePoolObjAssignDef(&privconn->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; - event = virStoragePoolEventLifecycleNew(pool->def->name, pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, VIR_STORAGE_POOL_EVENT_DEFINED, 0); - if (testStoragePoolObjSetDefaults(pool) == -1) { - virStoragePoolObjRemove(&privconn->pools, pool); - pool = NULL; + if (testStoragePoolObjSetDefaults(obj) == -1) { + virStoragePoolObjRemove(&privconn->pools, obj); + obj = NULL; goto cleanup; } - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: virStoragePoolDefFree(def); testObjectEventQueue(privconn, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); testDriverUnlock(privconn); return ret; } @@ -4464,14 +4463,14 @@ static int testStoragePoolUndefine(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virObjectEventPtr event = NULL; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (virStoragePoolObjIsActive(privpool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), pool->name); goto cleanup; @@ -4481,13 +4480,13 @@ testStoragePoolUndefine(virStoragePoolPtr pool) VIR_STORAGE_POOL_EVENT_UNDEFINED, 0); - virStoragePoolObjRemove(&privconn->pools, privpool); - privpool = NULL; + virStoragePoolObjRemove(&privconn->pools, obj); + obj = NULL; ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); testObjectEventQueue(privconn, event); return ret; } @@ -4498,15 +4497,15 @@ testStoragePoolBuild(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virCheckFlags(0, -1); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (virStoragePoolObjIsActive(privpool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), pool->name); goto cleanup; @@ -4514,8 +4513,8 @@ testStoragePoolBuild(virStoragePoolPtr pool, ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4562,44 +4561,44 @@ static int testStoragePoolDestroy(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virObjectEventPtr event = NULL; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - privpool->active = 0; + obj->active = 0; - if (privpool->def->source.adapter.type == + if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { if (testDestroyVport(privconn, - privpool->def->source.adapter.data.fchost.wwnn, - privpool->def->source.adapter.data.fchost.wwpn) < 0) + obj->def->source.adapter.data.fchost.wwnn, + obj->def->source.adapter.data.fchost.wwpn) < 0) goto cleanup; } - event = virStoragePoolEventLifecycleNew(privpool->def->name, - privpool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - if (privpool->configFile == NULL) { - virStoragePoolObjRemove(&privconn->pools, privpool); - privpool = NULL; + if (obj->configFile == NULL) { + virStoragePoolObjRemove(&privconn->pools, obj); + obj = NULL; } ret = 0; cleanup: testObjectEventQueue(privconn, event); - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4609,15 +4608,15 @@ testStoragePoolDelete(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virCheckFlags(0, -1); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (virStoragePoolObjIsActive(privpool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), pool->name); goto cleanup; @@ -4626,8 +4625,8 @@ testStoragePoolDelete(virStoragePoolPtr pool, ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4637,16 +4636,16 @@ testStoragePoolRefresh(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; virObjectEventPtr event = NULL; virCheckFlags(0, -1); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; @@ -4657,8 +4656,8 @@ testStoragePoolRefresh(virStoragePoolPtr pool, cleanup: testObjectEventQueue(privconn, event); - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4668,25 +4667,25 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; memset(info, 0, sizeof(virStoragePoolInfo)); - if (privpool->active) + if (obj->active) info->state = VIR_STORAGE_POOL_RUNNING; else info->state = VIR_STORAGE_POOL_INACTIVE; - info->capacity = privpool->def->capacity; - info->allocation = privpool->def->allocation; - info->available = privpool->def->available; + info->capacity = obj->def->capacity; + info->allocation = obj->def->allocation; + info->available = obj->def->available; ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4696,19 +4695,19 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; char *ret = NULL; virCheckFlags(0, NULL); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - ret = virStoragePoolDefFormat(privpool->def); + ret = virStoragePoolDefFormat(obj->def); cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4718,22 +4717,22 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, int *autostart) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!privpool->configFile) { + if (!obj->configFile) { *autostart = 0; } else { - *autostart = privpool->autostart; + *autostart = obj->autostart; } ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4743,25 +4742,25 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, int autostart) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!privpool->configFile) { + if (!obj->configFile) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("pool has no config file")); goto cleanup; } autostart = (autostart != 0); - privpool->autostart = autostart; + obj->autostart = autostart; ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4770,24 +4769,24 @@ static int testStoragePoolNumOfVolumes(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - ret = virStoragePoolObjNumOfVolumes(&privpool->volumes, pool->conn, - privpool->def, NULL); + ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, + obj->def, NULL); cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4798,52 +4797,52 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, int maxnames) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; int n = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - n = virStoragePoolObjVolumeGetNames(&privpool->volumes, pool->conn, - privpool->def, NULL, names, maxnames); + n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, + obj->def, NULL, names, maxnames); cleanup: - virStoragePoolObjUnlock(privpool); + virStoragePoolObjUnlock(obj); return n; } static int -testStoragePoolListAllVolumes(virStoragePoolPtr obj, +testStoragePoolListAllVolumes(virStoragePoolPtr pool, virStorageVolPtr **vols, unsigned int flags) { - testDriverPtr privconn = obj->conn->privateData; - virStoragePoolObjPtr pool; + testDriverPtr privconn = pool->conn->privateData; + virStoragePoolObjPtr obj; int ret = -1; virCheckFlags(0, -1); - if (!(pool = testStoragePoolObjFindByUUID(privconn, obj->uuid))) + if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid))) return -1; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("storage pool is not active")); goto cleanup; } - ret = virStoragePoolObjVolumeListExport(obj->conn, &pool->volumes, - pool->def, vols, NULL); + ret = virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes, + obj->def, vols, NULL); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } @@ -4854,20 +4853,20 @@ testStorageVolLookupByName(virStoragePoolPtr pool, const char *name ATTRIBUTE_UNUSED) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; virStorageVolPtr ret = NULL; - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - privvol = virStorageVolDefFindByName(privpool, name); + privvol = virStorageVolDefFindByName(obj, name); if (!privvol) { virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -4875,13 +4874,13 @@ testStorageVolLookupByName(virStoragePoolPtr pool, goto cleanup; } - ret = virGetStorageVol(pool->conn, privpool->def->name, + ret = virGetStorageVol(pool->conn, obj->def->name, privvol->name, privvol->key, NULL, NULL); cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -4966,34 +4965,34 @@ testStorageVolCreateXML(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol = NULL; virStorageVolPtr ret = NULL; virCheckFlags(0, NULL); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - privvol = virStorageVolDefParseString(privpool->def, xmldesc, 0); + privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); if (privvol == NULL) goto cleanup; - if (virStorageVolDefFindByName(privpool, privvol->name)) { + if (virStorageVolDefFindByName(obj, privvol->name)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("storage vol already exists")); goto cleanup; } /* Make sure enough space */ - if ((privpool->def->allocation + privvol->target.allocation) > - privpool->def->capacity) { + if ((obj->def->allocation + privvol->target.allocation) > + obj->def->capacity) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not enough free space in pool for volume '%s'"), privvol->name); @@ -5001,28 +5000,27 @@ testStorageVolCreateXML(virStoragePoolPtr pool, } if (virAsprintf(&privvol->target.path, "%s/%s", - privpool->def->target.path, + obj->def->target.path, privvol->name) == -1) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || - VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs, - privpool->volumes.count, privvol) < 0) + VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, + obj->volumes.count, privvol) < 0) goto cleanup; - privpool->def->allocation += privvol->target.allocation; - privpool->def->available = (privpool->def->capacity - - privpool->def->allocation); + obj->def->allocation += privvol->target.allocation; + obj->def->available = (obj->def->capacity - obj->def->allocation); - ret = virGetStorageVol(pool->conn, privpool->def->name, + ret = virGetStorageVol(pool->conn, obj->def->name, privvol->name, privvol->key, NULL, NULL); privvol = NULL; cleanup: virStorageVolDefFree(privvol); - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -5034,32 +5032,32 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, unsigned int flags) { testDriverPtr privconn = pool->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol = NULL, origvol = NULL; virStorageVolPtr ret = NULL; virCheckFlags(0, NULL); - if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) goto cleanup; - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), pool->name); goto cleanup; } - privvol = virStorageVolDefParseString(privpool->def, xmldesc, 0); + privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); if (privvol == NULL) goto cleanup; - if (virStorageVolDefFindByName(privpool, privvol->name)) { + if (virStorageVolDefFindByName(obj, privvol->name)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("storage vol already exists")); goto cleanup; } - origvol = virStorageVolDefFindByName(privpool, clonevol->name); + origvol = virStorageVolDefFindByName(obj, clonevol->name); if (!origvol) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), @@ -5068,39 +5066,37 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, } /* Make sure enough space */ - if ((privpool->def->allocation + privvol->target.allocation) > - privpool->def->capacity) { + if ((obj->def->allocation + privvol->target.allocation) > + obj->def->capacity) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not enough free space in pool for volume '%s'"), privvol->name); goto cleanup; } - privpool->def->available = (privpool->def->capacity - - privpool->def->allocation); + obj->def->available = (obj->def->capacity - obj->def->allocation); if (virAsprintf(&privvol->target.path, "%s/%s", - privpool->def->target.path, + obj->def->target.path, privvol->name) == -1) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || - VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs, - privpool->volumes.count, privvol) < 0) + VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, + obj->volumes.count, privvol) < 0) goto cleanup; - privpool->def->allocation += privvol->target.allocation; - privpool->def->available = (privpool->def->capacity - - privpool->def->allocation); + obj->def->allocation += privvol->target.allocation; + obj->def->available = (obj->def->capacity - obj->def->allocation); - ret = virGetStorageVol(pool->conn, privpool->def->name, + ret = virGetStorageVol(pool->conn, obj->def->name, privvol->name, privvol->key, NULL, NULL); privvol = NULL; cleanup: virStorageVolDefFree(privvol); - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -5110,17 +5106,17 @@ testStorageVolDelete(virStorageVolPtr vol, unsigned int flags) { testDriverPtr privconn = vol->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; size_t i; int ret = -1; virCheckFlags(0, -1); - if (!(privpool = testStoragePoolObjFindByName(privconn, vol->pool))) + if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - privvol = virStorageVolDefFindByName(privpool, vol->name); + privvol = virStorageVolDefFindByName(obj, vol->name); if (privvol == NULL) { virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -5129,30 +5125,29 @@ testStorageVolDelete(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), vol->pool); goto cleanup; } - privpool->def->allocation -= privvol->target.allocation; - privpool->def->available = (privpool->def->capacity - - privpool->def->allocation); + obj->def->allocation -= privvol->target.allocation; + obj->def->available = (obj->def->capacity - obj->def->allocation); - for (i = 0; i < privpool->volumes.count; i++) { - if (privpool->volumes.objs[i] == privvol) { + for (i = 0; i < obj->volumes.count; i++) { + if (obj->volumes.objs[i] == privvol) { virStorageVolDefFree(privvol); - VIR_DELETE_ELEMENT(privpool->volumes.objs, i, privpool->volumes.count); + VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); break; } } ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -5177,14 +5172,14 @@ testStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) { testDriverPtr privconn = vol->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; int ret = -1; - if (!(privpool = testStoragePoolObjFindByName(privconn, vol->pool))) + if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - privvol = virStorageVolDefFindByName(privpool, vol->name); + privvol = virStorageVolDefFindByName(obj, vol->name); if (privvol == NULL) { virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -5193,21 +5188,21 @@ testStorageVolGetInfo(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), vol->pool); goto cleanup; } memset(info, 0, sizeof(*info)); - info->type = testStorageVolumeTypeForPool(privpool->def->type); + info->type = testStorageVolumeTypeForPool(obj->def->type); info->capacity = privvol->target.capacity; info->allocation = privvol->target.allocation; ret = 0; cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -5217,16 +5212,16 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { testDriverPtr privconn = vol->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; char *ret = NULL; virCheckFlags(0, NULL); - if (!(privpool = testStoragePoolObjFindByName(privconn, vol->pool))) + if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - privvol = virStorageVolDefFindByName(privpool, vol->name); + privvol = virStorageVolDefFindByName(obj, vol->name); if (privvol == NULL) { virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -5235,17 +5230,17 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), vol->pool); goto cleanup; } - ret = virStorageVolDefFormat(privpool->def, privvol); + ret = virStorageVolDefFormat(obj->def, privvol); cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -5254,14 +5249,14 @@ static char * testStorageVolGetPath(virStorageVolPtr vol) { testDriverPtr privconn = vol->conn->privateData; - virStoragePoolObjPtr privpool; + virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; char *ret = NULL; - if (!(privpool = testStoragePoolObjFindByName(privconn, vol->pool))) + if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) goto cleanup; - privvol = virStorageVolDefFindByName(privpool, vol->name); + privvol = virStorageVolDefFindByName(obj, vol->name); if (privvol == NULL) { virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -5270,7 +5265,7 @@ testStorageVolGetPath(virStorageVolPtr vol) goto cleanup; } - if (!virStoragePoolObjIsActive(privpool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), vol->pool); goto cleanup; @@ -5279,8 +5274,8 @@ testStorageVolGetPath(virStorageVolPtr vol) ignore_value(VIR_STRDUP(ret, privvol->target.path)); cleanup: - if (privpool) - virStoragePoolObjUnlock(privpool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } -- 2.9.3

On Tue, May 09, 2017 at 11:30:09AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 443 ++++++++++++++++++++++++------------------------- 1 file changed, 219 insertions(+), 224 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 548f318..c0e46af 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c
[...]
@@ -4057,18 +4056,18 @@ testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
There you didn't changed the "ret" to "pool".
- if (!(pool = testStoragePoolObjFindByUUID(privconn, uuid))) + if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
@@ -4078,18 +4077,18 @@ testStoragePoolLookupByName(virConnectPtr conn, const char *name) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
Same here.
- if (!(pool = testStoragePoolObjFindByName(privconn, name))) + if (!(obj = testStoragePoolObjFindByName(privconn, name))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
[...]
@@ -4345,7 +4344,7 @@ testStoragePoolCreateXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here.
virObjectEventPtr event = NULL;
[...]
@@ -4419,7 +4418,7 @@ testStoragePoolDefineXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here
virObjectEventPtr event = NULL;
[...] I don't like these type of patches. The value to noise ration is poor. I'm hesitating to give this patch an ACK even though I probably done that in the past. Pavel

On 07/11/2017 04:27 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:09AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 443 ++++++++++++++++++++++++------------------------- 1 file changed, 219 insertions(+), 224 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 548f318..c0e46af 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c
[...]
@@ -4057,18 +4056,18 @@ testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
There you didn't changed the "ret" to "pool".
- if (!(pool = testStoragePoolObjFindByUUID(privconn, uuid))) + if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
@@ -4078,18 +4077,18 @@ testStoragePoolLookupByName(virConnectPtr conn, const char *name) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
Same here.
- if (!(pool = testStoragePoolObjFindByName(privconn, name))) + if (!(obj = testStoragePoolObjFindByName(privconn, name))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
[...]
@@ -4345,7 +4344,7 @@ testStoragePoolCreateXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here.
virObjectEventPtr event = NULL;
[...]
@@ -4419,7 +4418,7 @@ testStoragePoolDefineXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here
I can adjust those... I was more focused on the "existing" @pool and @obj variables and didn't consider the existing @ret variables.
virObjectEventPtr event = NULL;
[...]
I don't like these type of patches. The value to noise ration is poor. I'm hesitating to give this patch an ACK even though I probably done that in the past.
Pavel
So while I understand the concern, my argument becomes is it technically incorrect to change the names? Secondary to that if you're considering multiple driver/vir*obj changes at one time, it is *far easier* to consider an "@obj" to be that thing in the list vir*obj.c list rather than what is either passed or gets returned from/to the consumer - a @pool. And yes, technically a @pool is an object - I know. The second thing that gets fixed by these changes is inconsistent usage. For instance, prior to these changes look at testParseStorage and testOpenVolumesForPool. The former uses @obj for a virStoragePoolObjPtr while the latter uses @pool for a virStoragePoolObjPtr. It becomes difficult to "follow" code with inconsistencies. So if someone takes the effort to make things consistent - I think that's better in the long run. Makes the code more maintainable for a reader, but yes a hassle for someone back porting some subsequent change because of the merge conflict. The make code more consistent wins the argument my left and right brain have over this. If there's not an ACK, then so be it - I can remove it, but it probably affects subsequent patches too. Thanks for going back to earlier series - I had partially given up on storage and network instead focusing more on secret, nodedev, interface, and nwfilter. I figured once I got those accepted, I could go back to storage and network later. This just reduces that workload ;-) John

On Thu, Jul 13, 2017 at 03:40:26PM -0400, John Ferlan wrote:
On 07/11/2017 04:27 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:09AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 443 ++++++++++++++++++++++++------------------------- 1 file changed, 219 insertions(+), 224 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 548f318..c0e46af 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c
[...]
@@ -4057,18 +4056,18 @@ testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
There you didn't changed the "ret" to "pool".
- if (!(pool = testStoragePoolObjFindByUUID(privconn, uuid))) + if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
@@ -4078,18 +4077,18 @@ testStoragePoolLookupByName(virConnectPtr conn, const char *name) { testDriverPtr privconn = conn->privateData; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolPtr ret = NULL;
Same here.
- if (!(pool = testStoragePoolObjFindByName(privconn, name))) + if (!(obj = testStoragePoolObjFindByName(privconn, name))) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, + ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
[...]
@@ -4345,7 +4344,7 @@ testStoragePoolCreateXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here.
virObjectEventPtr event = NULL;
[...]
@@ -4419,7 +4418,7 @@ testStoragePoolDefineXML(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStoragePoolPtr ret = NULL;
And here
I can adjust those... I was more focused on the "existing" @pool and @obj variables and didn't consider the existing @ret variables.
virObjectEventPtr event = NULL;
[...]
I don't like these type of patches. The value to noise ration is poor. I'm hesitating to give this patch an ACK even though I probably done that in the past.
Pavel
So while I understand the concern, my argument becomes is it technically incorrect to change the names? Secondary to that if you're considering multiple driver/vir*obj changes at one time, it is *far easier* to consider an "@obj" to be that thing in the list vir*obj.c list rather than what is either passed or gets returned from/to the consumer - a @pool. And yes, technically a @pool is an object - I know.
The second thing that gets fixed by these changes is inconsistent usage. For instance, prior to these changes look at testParseStorage and testOpenVolumesForPool. The former uses @obj for a virStoragePoolObjPtr while the latter uses @pool for a virStoragePoolObjPtr. It becomes difficult to "follow" code with inconsistencies. So if someone takes the effort to make things consistent - I think that's better in the long run. Makes the code more maintainable for a reader, but yes a hassle for someone back porting some subsequent change because of the merge conflict.
The make code more consistent wins the argument my left and right brain have over this.
If there's not an ACK, then so be it - I can remove it, but it probably affects subsequent patches too.
It's my personal feeling that there is no much value in this patch, however the code will be at least consistent. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Rework some of the test driver API's to remove the need to return failure when testStoragePoolObjFindByName returns NULL rather than going to cleanup. This removes the need for check for "if (obj)" and in some instances the need to for a cleanup label and a local ret variable. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c0e46af..efa54ff 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4060,14 +4060,12 @@ testStoragePoolLookupByUUID(virConnectPtr conn, virStoragePoolPtr ret = NULL; if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) - goto cleanup; + return NULL; ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4081,14 +4079,12 @@ testStoragePoolLookupByName(virConnectPtr conn, virStoragePoolPtr ret = NULL; if (!(obj = testStoragePoolObjFindByName(privconn, name))) - goto cleanup; + return NULL; ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4210,13 +4206,11 @@ testStoragePoolIsPersistent(virStoragePoolPtr pool) int ret = -1; if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid))) - goto cleanup; + return -1; ret = obj->configFile ? 1 : 0; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4668,10 +4662,9 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; + return -1; memset(info, 0, sizeof(virStoragePoolInfo)); if (obj->active) @@ -4681,12 +4674,9 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, info->capacity = obj->def->capacity; info->allocation = obj->def->allocation; info->available = obj->def->available; - ret = 0; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4701,13 +4691,11 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool, virCheckFlags(0, NULL); if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; + return NULL; ret = virStoragePoolDefFormat(obj->def); - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4718,22 +4706,18 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; + return -1; if (!obj->configFile) { *autostart = 0; } else { *autostart = obj->autostart; } - ret = 0; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4746,7 +4730,7 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, int ret = -1; if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; + return -1; if (!obj->configFile) { virReportError(VIR_ERR_INVALID_ARG, @@ -4759,8 +4743,7 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, ret = 0; cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } -- 2.9.3

On Tue, May 09, 2017 at 11:30:10AM -0400, John Ferlan wrote:
Rework some of the test driver API's to remove the need to return failure when testStoragePoolObjFindByName returns NULL rather than going to cleanup. This removes the need for check for "if (obj)" and in some instances the need to for a cleanup label and a local ret variable.
The recommended wrapping of commit message body is 72 columns.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

On 07/11/2017 04:33 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:10AM -0400, John Ferlan wrote:
Rework some of the test driver API's to remove the need to return failure when testStoragePoolObjFindByName returns NULL rather than going to cleanup. This removes the need for check for "if (obj)" and in some instances the need to for a cleanup label and a local ret variable.
The recommended wrapping of commit message body is 72 columns.
I must violate that a lot ;-) I adjusted... John
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Rather than have repetitive code - create/use a couple of helpers: testStoragePoolObjFindActiveByName and testStoragePoolObjFindInactiveByName This will also allow for the reduction of some cleanup path logic. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 256 +++++++++++++++++-------------------------------- 1 file changed, 86 insertions(+), 170 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index efa54ff..9918df6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4030,6 +4030,46 @@ testStoragePoolObjFindByName(testDriverPtr privconn, static virStoragePoolObjPtr +testStoragePoolObjFindActiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (!virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is not active"), name); + virStoragePoolObjUnlock(obj); + return NULL; + } + + return obj; +} + + +static virStoragePoolObjPtr +testStoragePoolObjFindInactiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is already active"), name); + virStoragePoolObjUnlock(obj); + return NULL; + } + + return obj; +} + + +static virStoragePoolObjPtr testStoragePoolObjFindByUUID(testDriverPtr privconn, const unsigned char *uuid) { @@ -4221,32 +4261,22 @@ testStoragePoolCreate(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; virObjectEventPtr event = NULL; virCheckFlags(0, -1); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is already active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name))) + return -1; obj->active = 1; event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - ret = 0; - cleanup: testObjectEventQueue(privconn, event); - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4458,31 +4488,19 @@ testStoragePoolUndefine(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; virObjectEventPtr event = NULL; - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is already active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name))) + return -1; event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, 0); virStoragePoolObjRemove(&privconn->pools, obj); - obj = NULL; - ret = 0; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); testObjectEventQueue(privconn, event); - return ret; + return 0; } @@ -4492,24 +4510,14 @@ testStoragePoolBuild(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; virCheckFlags(0, -1); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is already active"), pool->name); - goto cleanup; - } - ret = 0; + if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name))) + return -1; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4559,14 +4567,8 @@ testStoragePoolDestroy(virStoragePoolPtr pool) int ret = -1; virObjectEventPtr event = NULL; - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return -1; obj->active = 0; @@ -4603,25 +4605,14 @@ testStoragePoolDelete(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; virCheckFlags(0, -1); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is already active"), pool->name); - goto cleanup; - } - - ret = 0; + if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name))) + return -1; - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4631,28 +4622,18 @@ testStoragePoolRefresh(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; - int ret = -1; virObjectEventPtr event = NULL; virCheckFlags(0, -1); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return -1; event = virStoragePoolEventRefreshNew(pool->name, pool->uuid); - ret = 0; - cleanup: testObjectEventQueue(privconn, event); - if (obj) - virStoragePoolObjUnlock(obj); - return ret; + virStoragePoolObjUnlock(obj); + return 0; } @@ -4755,21 +4736,13 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) virStoragePoolObjPtr obj; int ret = -1; - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return -1; ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, obj->def, NULL); - cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4783,19 +4756,12 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, virStoragePoolObjPtr obj; int n = -1; - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return -1; - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } - n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, obj->def, NULL, names, maxnames); - cleanup: virStoragePoolObjUnlock(obj); return n; } @@ -4840,14 +4806,8 @@ testStorageVolLookupByName(virStoragePoolPtr pool, virStorageVolDefPtr privvol; virStorageVolPtr ret = NULL; - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return NULL; privvol = virStorageVolDefFindByName(obj, name); @@ -4862,8 +4822,7 @@ testStorageVolLookupByName(virStoragePoolPtr pool, NULL, NULL); cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -4954,14 +4913,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, virCheckFlags(0, NULL); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return NULL; privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); if (privvol == NULL) @@ -5002,8 +4955,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, cleanup: virStorageVolDefFree(privvol); - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -5021,14 +4973,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, virCheckFlags(0, NULL); - if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) - goto cleanup; - - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->name); - goto cleanup; - } + if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) + return NULL; privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); if (privvol == NULL) @@ -5078,8 +5024,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, cleanup: virStorageVolDefFree(privvol); - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -5096,8 +5041,8 @@ testStorageVolDelete(virStorageVolPtr vol, virCheckFlags(0, -1); - if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) - goto cleanup; + if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) + return -1; privvol = virStorageVolDefFindByName(obj, vol->name); @@ -5108,13 +5053,6 @@ testStorageVolDelete(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), vol->pool); - goto cleanup; - } - - obj->def->allocation -= privvol->target.allocation; obj->def->available = (obj->def->capacity - obj->def->allocation); @@ -5129,8 +5067,7 @@ testStorageVolDelete(virStorageVolPtr vol, ret = 0; cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -5159,8 +5096,8 @@ testStorageVolGetInfo(virStorageVolPtr vol, virStorageVolDefPtr privvol; int ret = -1; - if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) - goto cleanup; + if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) + return -1; privvol = virStorageVolDefFindByName(obj, vol->name); @@ -5171,12 +5108,6 @@ testStorageVolGetInfo(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), vol->pool); - goto cleanup; - } - memset(info, 0, sizeof(*info)); info->type = testStorageVolumeTypeForPool(obj->def->type); info->capacity = privvol->target.capacity; @@ -5184,8 +5115,7 @@ testStorageVolGetInfo(virStorageVolPtr vol, ret = 0; cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -5201,8 +5131,8 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, virCheckFlags(0, NULL); - if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) - goto cleanup; + if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) + return NULL; privvol = virStorageVolDefFindByName(obj, vol->name); @@ -5213,17 +5143,10 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, goto cleanup; } - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), vol->pool); - goto cleanup; - } - ret = virStorageVolDefFormat(obj->def, privvol); cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } @@ -5236,8 +5159,8 @@ testStorageVolGetPath(virStorageVolPtr vol) virStorageVolDefPtr privvol; char *ret = NULL; - if (!(obj = testStoragePoolObjFindByName(privconn, vol->pool))) - goto cleanup; + if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) + return NULL; privvol = virStorageVolDefFindByName(obj, vol->name); @@ -5248,17 +5171,10 @@ testStorageVolGetPath(virStorageVolPtr vol) goto cleanup; } - if (!virStoragePoolObjIsActive(obj)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), vol->pool); - goto cleanup; - } - ignore_value(VIR_STRDUP(ret, privvol->target.path)); cleanup: - if (obj) - virStoragePoolObjUnlock(obj); + virStoragePoolObjUnlock(obj); return ret; } -- 2.9.3

On Tue, May 09, 2017 at 11:30:11AM -0400, John Ferlan wrote:
Rather than have repetitive code - create/use a couple of helpers:
testStoragePoolObjFindActiveByName and testStoragePoolObjFindInactiveByName
I would wrap this line, it's too long for no reason.
This will also allow for the reduction of some cleanup path logic.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 256 +++++++++++++++++-------------------------------- 1 file changed, 86 insertions(+), 170 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index efa54ff..9918df6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4030,6 +4030,46 @@ testStoragePoolObjFindByName(testDriverPtr privconn,
static virStoragePoolObjPtr +testStoragePoolObjFindActiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (!virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is not active"), name); + virStoragePoolObjUnlock(obj); + return NULL; + } + + return obj; +} + + +static virStoragePoolObjPtr +testStoragePoolObjFindInactiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is already active"), name);
I would remove the "already" for the error message. Since this is only test driver I'll leave it up to you. The reason is that for some APIs like "Undefine" the error message doesn't make sense. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

On 07/11/2017 07:30 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:11AM -0400, John Ferlan wrote:
Rather than have repetitive code - create/use a couple of helpers:
testStoragePoolObjFindActiveByName and testStoragePoolObjFindInactiveByName
I would wrap this line, it's too long for no reason.
OK - I made them a list, e.g.: testStoragePoolObjFindActiveByName testStoragePoolObjFindInactiveByName
This will also allow for the reduction of some cleanup path logic.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 256 +++++++++++++++++-------------------------------- 1 file changed, 86 insertions(+), 170 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index efa54ff..9918df6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4030,6 +4030,46 @@ testStoragePoolObjFindByName(testDriverPtr privconn,
static virStoragePoolObjPtr +testStoragePoolObjFindActiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (!virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is not active"), name); + virStoragePoolObjUnlock(obj); + return NULL; + } + + return obj; +} + + +static virStoragePoolObjPtr +testStoragePoolObjFindInactiveByName(testDriverPtr privconn, + const char *name) +{ + virStoragePoolObjPtr obj; + + if (!(obj = testStoragePoolObjFindByName(privconn, name))) + return NULL; + + if (virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is already active"), name);
I would remove the "already" for the error message. Since this is only test driver I'll leave it up to you. The reason is that for some APIs like "Undefine" the error message doesn't make sense.
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Done. John

Remove repetitive code, replace with common function. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 56 +++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 9918df6..460aa88 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4797,9 +4797,24 @@ testStoragePoolListAllVolumes(virStoragePoolPtr pool, } +static virStorageVolDefPtr +testStorageVolDefFindByName(virStoragePoolObjPtr obj, + const char *name) +{ + virStorageVolDefPtr privvol; + + if (!(privvol = virStorageVolDefFindByName(obj, name))) { + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), name); + } + + return privvol; +} + + static virStorageVolPtr testStorageVolLookupByName(virStoragePoolPtr pool, - const char *name ATTRIBUTE_UNUSED) + const char *name) { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; @@ -4809,13 +4824,8 @@ testStorageVolLookupByName(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return NULL; - privvol = virStorageVolDefFindByName(obj, name); - - if (!privvol) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), name); + if (!(privvol = testStorageVolDefFindByName(obj, name))) goto cleanup; - } ret = virGetStorageVol(pool->conn, obj->def->name, privvol->name, privvol->key, @@ -5044,14 +5054,8 @@ testStorageVolDelete(virStorageVolPtr vol, if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return -1; - privvol = virStorageVolDefFindByName(obj, vol->name); - - if (privvol == NULL) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), - vol->name); + if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - } obj->def->allocation -= privvol->target.allocation; obj->def->available = (obj->def->capacity - obj->def->allocation); @@ -5099,14 +5103,8 @@ testStorageVolGetInfo(virStorageVolPtr vol, if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return -1; - privvol = virStorageVolDefFindByName(obj, vol->name); - - if (privvol == NULL) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), - vol->name); + if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - } memset(info, 0, sizeof(*info)); info->type = testStorageVolumeTypeForPool(obj->def->type); @@ -5134,14 +5132,8 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return NULL; - privvol = virStorageVolDefFindByName(obj, vol->name); - - if (privvol == NULL) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), - vol->name); + if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - } ret = virStorageVolDefFormat(obj->def, privvol); @@ -5162,14 +5154,8 @@ testStorageVolGetPath(virStorageVolPtr vol) if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return NULL; - privvol = virStorageVolDefFindByName(obj, vol->name); - - if (privvol == NULL) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), - vol->name); + if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - } ignore_value(VIR_STRDUP(ret, privvol->target.path)); -- 2.9.3

On Tue, May 09, 2017 at 11:30:12AM -0400, John Ferlan wrote:
Remove repetitive code, replace with common function.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 56 +++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Use the < 0 rather than == -1 (consistently) for virAsprintf errors. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_backend_logical.c | 2 +- src/storage/storage_backend_rbd.c | 8 ++++---- src/storage/storage_backend_sheepdog.c | 4 ++-- src/storage/storage_backend_zfs.c | 4 ++-- src/storage/storage_util.c | 6 +++--- src/test/test_driver.c | 9 +++------ 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index ed26c24..67f70e5 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -948,7 +948,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, - vol->name) == -1) + vol->name) < 0) return -1; cmd = virCommandNewArgList(LVCREATE, diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index c806d6d..7b8887b 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -404,13 +404,13 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->source.name, - vol->name) == -1) + vol->name) < 0) goto cleanup; VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", pool->def->source.name, - vol->name) == -1) + vol->name) < 0) goto cleanup; ret = 0; @@ -662,13 +662,13 @@ virStorageBackendRBDCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->source.name, - vol->name) == -1) + vol->name) < 0) return -1; VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", pool->def->source.name, - vol->name) == -1) + vol->name) < 0) return -1; return 0; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index a9a2301..b55d96a 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -249,7 +249,7 @@ virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", - pool->def->source.name, vol->name) == -1) + pool->def->source.name, vol->name) < 0) return -1; VIR_FREE(vol->target.path); @@ -374,7 +374,7 @@ virStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", - pool->def->source.name, vol->name) == -1) + pool->def->source.name, vol->name) < 0) goto cleanup; VIR_FREE(vol->target.path); diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c index 004d95a..c6dae71 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -89,7 +89,7 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, char *devpath; if (virAsprintf(&devpath, "/dev/zvol/%s", - pool->def->source.name) == -1) + pool->def->source.name) < 0) return -1; *isActive = virFileIsDir(devpath); VIR_FREE(devpath); @@ -322,7 +322,7 @@ virStorageBackendZFSCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, vol->name) == -1) + pool->def->target.path, vol->name) < 0) return -1; if (VIR_STRDUP(vol->key, vol->target.path) < 0) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 43f3561..08dca94 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1982,7 +1982,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, while ((direrr = virDirRead(dh, &dent, NULL)) > 0) { if (virAsprintf(&stablepath, "%s/%s", pool->def->target.path, - dent->d_name) == -1) { + dent->d_name) < 0) { VIR_DIR_CLOSE(dh); return NULL; } @@ -2082,7 +2082,7 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, - vol->name) == -1) + vol->name) < 0) return -1; if (virFileExists(vol->target.path)) { @@ -3553,7 +3553,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, vol->target.format = VIR_STORAGE_FILE_RAW; /* Real value is filled in during probe */ if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, - vol->name) == -1) + vol->name) < 0) goto cleanup; if (VIR_STRDUP(vol->key, vol->target.path) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 460aa88..8d03bdb 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1069,8 +1069,7 @@ testOpenVolumesForPool(const char *file, if (def->target.path == NULL) { if (virAsprintf(&def->target.path, "%s/%s", - obj->def->target.path, - def->name) == -1) + obj->def->target.path, def->name) < 0) goto error; } @@ -4946,8 +4945,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, } if (virAsprintf(&privvol->target.path, "%s/%s", - obj->def->target.path, - privvol->name) == -1) + obj->def->target.path, privvol->name) < 0) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || @@ -5015,8 +5013,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, obj->def->available = (obj->def->capacity - obj->def->allocation); if (virAsprintf(&privvol->target.path, "%s/%s", - obj->def->target.path, - privvol->name) == -1) + obj->def->target.path, privvol->name) < 0) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || -- 2.9.3

On Tue, May 09, 2017 at 11:30:13AM -0400, John Ferlan wrote:
Use the < 0 rather than == -1 (consistently) for virAsprintf errors.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_backend_logical.c | 2 +- src/storage/storage_backend_rbd.c | 8 ++++---- src/storage/storage_backend_sheepdog.c | 4 ++-- src/storage/storage_backend_zfs.c | 4 ++-- src/storage/storage_util.c | 6 +++--- src/test/test_driver.c | 9 +++------ 6 files changed, 15 insertions(+), 18 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

A virStoragePoolObjPtr will be an 'obj'. A virStoragePoolPtr will be a 'pool'. NB: Also modify the @matchpool to @matchobj. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 342 +++++++++++++++++++++++------------------------ src/conf/virstorageobj.h | 20 +-- 2 files changed, 180 insertions(+), 182 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index dd41701..74a9c67 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -70,15 +70,15 @@ virStoragePoolObjListFree(virStoragePoolObjListPtr pools) void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr pool) + virStoragePoolObjPtr obj) { size_t i; - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); for (i = 0; i < pools->count; i++) { virStoragePoolObjLock(pools->objs[i]); - if (pools->objs[i] == pool) { + if (pools->objs[i] == obj) { virStoragePoolObjUnlock(pools->objs[i]); virStoragePoolObjFree(pools->objs[i]); @@ -125,15 +125,15 @@ virStoragePoolObjFindByName(virStoragePoolObjListPtr pools, static virStoragePoolObjPtr -virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr pool, +virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr obj, virStoragePoolDefPtr def) { size_t i, j; - for (i = 0; i < pool->def->source.ndevice; i++) { + for (i = 0; i < obj->def->source.ndevice; i++) { for (j = 0; j < def->source.ndevice; j++) { - if (STREQ(pool->def->source.devices[i].path, def->source.devices[j].path)) - return pool; + if (STREQ(obj->def->source.devices[i].path, def->source.devices[j].path)) + return obj; } } @@ -142,54 +142,54 @@ virStoragePoolSourceFindDuplicateDevices(virStoragePoolObjPtr pool, void -virStoragePoolObjClearVols(virStoragePoolObjPtr pool) +virStoragePoolObjClearVols(virStoragePoolObjPtr obj) { size_t i; - for (i = 0; i < pool->volumes.count; i++) - virStorageVolDefFree(pool->volumes.objs[i]); + for (i = 0; i < obj->volumes.count; i++) + virStorageVolDefFree(obj->volumes.objs[i]); - VIR_FREE(pool->volumes.objs); - pool->volumes.count = 0; + VIR_FREE(obj->volumes.objs); + obj->volumes.count = 0; } virStorageVolDefPtr -virStorageVolDefFindByKey(virStoragePoolObjPtr pool, +virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key) { size_t i; - for (i = 0; i < pool->volumes.count; i++) - if (STREQ(pool->volumes.objs[i]->key, key)) - return pool->volumes.objs[i]; + for (i = 0; i < obj->volumes.count; i++) + if (STREQ(obj->volumes.objs[i]->key, key)) + return obj->volumes.objs[i]; return NULL; } virStorageVolDefPtr -virStorageVolDefFindByPath(virStoragePoolObjPtr pool, +virStorageVolDefFindByPath(virStoragePoolObjPtr obj, const char *path) { size_t i; - for (i = 0; i < pool->volumes.count; i++) - if (STREQ(pool->volumes.objs[i]->target.path, path)) - return pool->volumes.objs[i]; + for (i = 0; i < obj->volumes.count; i++) + if (STREQ(obj->volumes.objs[i]->target.path, path)) + return obj->volumes.objs[i]; return NULL; } virStorageVolDefPtr -virStorageVolDefFindByName(virStoragePoolObjPtr pool, +virStorageVolDefFindByName(virStoragePoolObjPtr obj, const char *name) { size_t i; - for (i = 0; i < pool->volumes.count; i++) - if (STREQ(pool->volumes.objs[i]->name, name)) - return pool->volumes.objs[i]; + for (i = 0; i < obj->volumes.count; i++) + if (STREQ(obj->volumes.objs[i]->name, name)) + return obj->volumes.objs[i]; return NULL; } @@ -296,39 +296,39 @@ virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; - if ((pool = virStoragePoolObjFindByName(pools, def->name))) { - if (!virStoragePoolObjIsActive(pool)) { - virStoragePoolDefFree(pool->def); - pool->def = def; + if ((obj = virStoragePoolObjFindByName(pools, def->name))) { + if (!virStoragePoolObjIsActive(obj)) { + virStoragePoolDefFree(obj->def); + obj->def = def; } else { - virStoragePoolDefFree(pool->newDef); - pool->newDef = def; + virStoragePoolDefFree(obj->newDef); + obj->newDef = def; } - return pool; + return obj; } - if (VIR_ALLOC(pool) < 0) + if (VIR_ALLOC(obj) < 0) return NULL; - if (virMutexInit(&pool->lock) < 0) { + if (virMutexInit(&obj->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); - VIR_FREE(pool); + VIR_FREE(obj); return NULL; } - virStoragePoolObjLock(pool); - pool->active = 0; + virStoragePoolObjLock(obj); + obj->active = 0; - if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, pool) < 0) { - virStoragePoolObjUnlock(pool); - virStoragePoolObjFree(pool); + if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, obj) < 0) { + virStoragePoolObjUnlock(obj); + virStoragePoolObjFree(obj); return NULL; } - pool->def = def; + obj->def = def; - return pool; + return obj; } @@ -339,7 +339,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, const char *autostartLink) { virStoragePoolDefPtr def; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; if (!(def = virStoragePoolDefParseFile(path))) return NULL; @@ -353,26 +353,26 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, return NULL; } - if (!(pool = virStoragePoolObjAssignDef(pools, def))) { + if (!(obj = virStoragePoolObjAssignDef(pools, def))) { virStoragePoolDefFree(def); return NULL; } - VIR_FREE(pool->configFile); /* for driver reload */ - if (VIR_STRDUP(pool->configFile, path) < 0) { - virStoragePoolObjRemove(pools, pool); + VIR_FREE(obj->configFile); /* for driver reload */ + if (VIR_STRDUP(obj->configFile, path) < 0) { + virStoragePoolObjRemove(pools, obj); return NULL; } - VIR_FREE(pool->autostartLink); /* for driver reload */ - if (VIR_STRDUP(pool->autostartLink, autostartLink) < 0) { - virStoragePoolObjRemove(pools, pool); + VIR_FREE(obj->autostartLink); /* for driver reload */ + if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0) { + virStoragePoolObjRemove(pools, obj); return NULL; } - pool->autostart = virFileLinkPointsTo(pool->autostartLink, - pool->configFile); + obj->autostart = virFileLinkPointsTo(obj->autostartLink, + obj->configFile); - return pool; + return obj; } @@ -383,7 +383,7 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools, { char *stateFile = NULL; virStoragePoolDefPtr def = NULL; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; xmlDocPtr xml = NULL; xmlXPathContextPtr ctxt = NULL; xmlNodePtr node = NULL; @@ -413,7 +413,7 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools, } /* create the object */ - if (!(pool = virStoragePoolObjAssignDef(pools, def))) + if (!(obj = virStoragePoolObjAssignDef(pools, def))) goto error; /* XXX: future handling of some additional useful status data, @@ -421,13 +421,13 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools, * as active */ - pool->active = 1; + obj->active = 1; cleanup: VIR_FREE(stateFile); xmlFreeDoc(xml); xmlXPathFreeContext(ctxt); - return pool; + return obj; error: virStoragePoolDefFree(def); @@ -448,15 +448,14 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools, return rc; while ((ret = virDirRead(dir, &entry, stateDir)) > 0) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; if (!virFileStripSuffix(entry->d_name, ".xml")) continue; - if (!(pool = virStoragePoolObjLoadState(pools, stateDir, - entry->d_name))) + if (!(obj = virStoragePoolObjLoadState(pools, stateDir, entry->d_name))) continue; - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); } VIR_DIR_CLOSE(dir); @@ -480,7 +479,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools, while ((ret = virDirRead(dir, &entry, configDir)) > 0) { char *path; char *autostartLink; - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; if (!virFileHasSuffix(entry->d_name, ".xml")) continue; @@ -494,10 +493,9 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools, continue; } - pool = virStoragePoolObjLoad(pools, entry->d_name, path, - autostartLink); - if (pool) - virStoragePoolObjUnlock(pool); + obj = virStoragePoolObjLoad(pools, entry->d_name, path, autostartLink); + if (obj) + virStoragePoolObjUnlock(obj); VIR_FREE(path); VIR_FREE(autostartLink); @@ -510,10 +508,10 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools, int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStoragePoolDefPtr def) { - if (!pool->configFile) { + if (!obj->configFile) { if (virFileMakePath(driver->configDir) < 0) { virReportSystemError(errno, _("cannot create config directory %s"), @@ -521,35 +519,35 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, return -1; } - if (!(pool->configFile = virFileBuildPath(driver->configDir, - def->name, ".xml"))) { + if (!(obj->configFile = virFileBuildPath(driver->configDir, + def->name, ".xml"))) { return -1; } - if (!(pool->autostartLink = virFileBuildPath(driver->autostartDir, - def->name, ".xml"))) { - VIR_FREE(pool->configFile); + if (!(obj->autostartLink = virFileBuildPath(driver->autostartDir, + def->name, ".xml"))) { + VIR_FREE(obj->configFile); return -1; } } - return virStoragePoolSaveConfig(pool->configFile, def); + return virStoragePoolSaveConfig(obj->configFile, def); } int -virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool) +virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj) { - if (!pool->configFile) { + if (!obj->configFile) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("no config file for %s"), pool->def->name); + _("no config file for %s"), obj->def->name); return -1; } - if (unlink(pool->configFile) < 0) { + if (unlink(obj->configFile) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot remove config for %s"), - pool->def->name); + obj->def->name); return -1; } @@ -632,27 +630,27 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, unsigned int check_active) { int ret = -1; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; /* See if a Pool with matching UUID already exists */ - pool = virStoragePoolObjFindByUUID(pools, def->uuid); - if (pool) { + obj = virStoragePoolObjFindByUUID(pools, def->uuid); + if (obj) { /* UUID matches, but if names don't match, refuse it */ - if (STRNEQ(pool->def->name, def->name)) { + if (STRNEQ(obj->def->name, def->name)) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(pool->def->uuid, uuidstr); + virUUIDFormat(obj->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, _("pool '%s' is already defined with uuid %s"), - pool->def->name, uuidstr); + obj->def->name, uuidstr); goto cleanup; } if (check_active) { /* UUID & name match, but if Pool is already active, refuse it */ - if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("pool is already active as '%s'"), - pool->def->name); + obj->def->name); goto cleanup; } } @@ -660,10 +658,10 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, ret = 1; } else { /* UUID does not match, but if a name matches, refuse it */ - pool = virStoragePoolObjFindByName(pools, def->name); - if (pool) { + obj = virStoragePoolObjFindByName(pools, def->name); + if (obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(pool->def->uuid, uuidstr); + virUUIDFormat(obj->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, _("pool '%s' already exists with uuid %s"), def->name, uuidstr); @@ -673,8 +671,8 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, } cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } @@ -839,10 +837,10 @@ virStoragePoolSourceMatchSingleHost(virStoragePoolSourcePtr poolsrc, static bool -virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr matchpool, +virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr obj, virStoragePoolDefPtr def) { - virStoragePoolSourcePtr poolsrc = &matchpool->def->source; + virStoragePoolSourcePtr poolsrc = &obj->def->source; virStoragePoolSourcePtr defsrc = &def->source; /* NB: Do not check the source host name */ @@ -854,23 +852,23 @@ virStoragePoolSourceISCSIMatch(virStoragePoolObjPtr matchpool, static virStoragePoolObjPtr -virStoragePoolObjSourceMatchTypeDIR(virStoragePoolObjPtr pool, +virStoragePoolObjSourceMatchTypeDIR(virStoragePoolObjPtr obj, virStoragePoolDefPtr def) { - if (pool->def->type == VIR_STORAGE_POOL_DIR) { - if (STREQ(pool->def->target.path, def->target.path)) - return pool; - } else if (pool->def->type == VIR_STORAGE_POOL_GLUSTER) { - if (STREQ(pool->def->source.name, def->source.name) && - STREQ_NULLABLE(pool->def->source.dir, def->source.dir) && - virStoragePoolSourceMatchSingleHost(&pool->def->source, + if (obj->def->type == VIR_STORAGE_POOL_DIR) { + if (STREQ(obj->def->target.path, def->target.path)) + return obj; + } else if (obj->def->type == VIR_STORAGE_POOL_GLUSTER) { + if (STREQ(obj->def->source.name, def->source.name) && + STREQ_NULLABLE(obj->def->source.dir, def->source.dir) && + virStoragePoolSourceMatchSingleHost(&obj->def->source, &def->source)) - return pool; - } else if (pool->def->type == VIR_STORAGE_POOL_NETFS) { - if (STREQ(pool->def->source.dir, def->source.dir) && - virStoragePoolSourceMatchSingleHost(&pool->def->source, + return obj; + } else if (obj->def->type == VIR_STORAGE_POOL_NETFS) { + if (STREQ(obj->def->source.dir, def->source.dir) && + virStoragePoolSourceMatchSingleHost(&obj->def->source, &def->source)) - return pool; + return obj; } return NULL; @@ -878,11 +876,11 @@ virStoragePoolObjSourceMatchTypeDIR(virStoragePoolObjPtr pool, static virStoragePoolObjPtr -virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, +virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr obj, virStoragePoolDefPtr def, virConnectPtr conn) { - virStorageAdapterPtr pool_adapter = &pool->def->source.adapter; + virStorageAdapterPtr pool_adapter = &obj->def->source.adapter; virStorageAdapterPtr def_adapter = &def->source.adapter; virStorageAdapterSCSIHostPtr pool_scsi_host; virStorageAdapterSCSIHostPtr def_scsi_host; @@ -899,7 +897,7 @@ virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, if (STREQ(pool_fchost->wwnn, def_fchost->wwnn) && STREQ(pool_fchost->wwpn, def_fchost->wwpn)) - return pool; + return obj; } else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST && def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { pool_scsi_host = &pool_adapter->data.scsi_host; @@ -908,13 +906,13 @@ virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, if (pool_scsi_host->has_parent && def_scsi_host->has_parent && matchSCSIAdapterParent(pool_scsi_host, def_scsi_host)) - return pool; + return obj; if (getSCSIHostNumber(pool_scsi_host, &pool_hostnum) < 0 || getSCSIHostNumber(def_scsi_host, &def_hostnum) < 0) return NULL; if (pool_hostnum == def_hostnum) - return pool; + return obj; } else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST && def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { pool_fchost = &pool_adapter->data.fchost; @@ -925,7 +923,7 @@ virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, return NULL; if (matchFCHostToSCSIHost(conn, pool_fchost, scsi_hostnum)) - return pool; + return obj; } else if (pool_adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST && def_adapter->type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { @@ -936,7 +934,7 @@ virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, return NULL; if (matchFCHostToSCSIHost(conn, def_fchost, scsi_hostnum)) - return pool; + return obj; } return NULL; @@ -944,20 +942,20 @@ virStoragePoolObjSourceMatchTypeISCSI(virStoragePoolObjPtr pool, static virStoragePoolObjPtr -virStoragePoolObjSourceMatchTypeDEVICE(virStoragePoolObjPtr pool, +virStoragePoolObjSourceMatchTypeDEVICE(virStoragePoolObjPtr obj, virStoragePoolDefPtr def) { - virStoragePoolObjPtr matchpool = NULL; + virStoragePoolObjPtr matchobj = NULL; - if (pool->def->type == VIR_STORAGE_POOL_ISCSI) { + if (obj->def->type == VIR_STORAGE_POOL_ISCSI) { if (def->type != VIR_STORAGE_POOL_ISCSI) return NULL; - if ((matchpool = virStoragePoolSourceFindDuplicateDevices(pool, def))) { - if (!virStoragePoolSourceISCSIMatch(matchpool, def)) + if ((matchobj = virStoragePoolSourceFindDuplicateDevices(obj, def))) { + if (!virStoragePoolSourceISCSIMatch(matchobj, def)) return NULL; } - return matchpool; + return matchobj; } if (def->type == VIR_STORAGE_POOL_ISCSI) @@ -967,7 +965,7 @@ virStoragePoolObjSourceMatchTypeDEVICE(virStoragePoolObjPtr pool, * VIR_STORAGE_POOL_LOGICAL * VIR_STORAGE_POOL_DISK * VIR_STORAGE_POOL_ZFS */ - return virStoragePoolSourceFindDuplicateDevices(pool, def); + return virStoragePoolSourceFindDuplicateDevices(obj, def); } @@ -978,30 +976,30 @@ virStoragePoolObjSourceFindDuplicate(virConnectPtr conn, { size_t i; int ret = 1; - virStoragePoolObjPtr pool = NULL; - virStoragePoolObjPtr matchpool = NULL; + virStoragePoolObjPtr obj = NULL; + virStoragePoolObjPtr matchobj = NULL; /* Check the pool list for duplicate underlying storage */ for (i = 0; i < pools->count; i++) { - pool = pools->objs[i]; + obj = pools->objs[i]; /* Don't match against ourself if re-defining existing pool ! */ - if (STREQ(pool->def->name, def->name)) + if (STREQ(obj->def->name, def->name)) continue; - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); - switch ((virStoragePoolType)pool->def->type) { + switch ((virStoragePoolType)obj->def->type) { case VIR_STORAGE_POOL_DIR: case VIR_STORAGE_POOL_GLUSTER: case VIR_STORAGE_POOL_NETFS: - if (def->type == pool->def->type) - matchpool = virStoragePoolObjSourceMatchTypeDIR(pool, def); + if (def->type == obj->def->type) + matchobj = virStoragePoolObjSourceMatchTypeDIR(obj, def); break; case VIR_STORAGE_POOL_SCSI: - if (def->type == pool->def->type) - matchpool = virStoragePoolObjSourceMatchTypeISCSI(pool, def, + if (def->type == obj->def->type) + matchobj = virStoragePoolObjSourceMatchTypeISCSI(obj, def, conn); break; @@ -1015,42 +1013,42 @@ virStoragePoolObjSourceFindDuplicate(virConnectPtr conn, def->type == VIR_STORAGE_POOL_LOGICAL || def->type == VIR_STORAGE_POOL_DISK || def->type == VIR_STORAGE_POOL_ZFS) - matchpool = virStoragePoolObjSourceMatchTypeDEVICE(pool, def); + matchobj = virStoragePoolObjSourceMatchTypeDEVICE(obj, def); break; case VIR_STORAGE_POOL_SHEEPDOG: - if (def->type == pool->def->type && - virStoragePoolSourceMatchSingleHost(&pool->def->source, + if (def->type == obj->def->type && + virStoragePoolSourceMatchSingleHost(&obj->def->source, &def->source)) - matchpool = pool; + matchobj = obj; break; case VIR_STORAGE_POOL_MPATH: /* Only one mpath pool is valid per host */ - if (def->type == pool->def->type) - matchpool = pool; + if (def->type == obj->def->type) + matchobj = obj; break; case VIR_STORAGE_POOL_VSTORAGE: - if (def->type == pool->def->type && - STREQ(pool->def->source.name, def->source.name)) - matchpool = pool; + if (def->type == obj->def->type && + STREQ(obj->def->source.name, def->source.name)) + matchobj = obj; break; case VIR_STORAGE_POOL_RBD: case VIR_STORAGE_POOL_LAST: break; } - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); - if (matchpool) + if (matchobj) break; } - if (matchpool) { + if (matchobj) { virReportError(VIR_ERR_OPERATION_FAILED, _("Storage source conflict with pool: '%s'"), - matchpool->def->name); + matchobj->def->name); ret = -1; } return ret; @@ -1073,61 +1071,61 @@ virStoragePoolObjUnlock(virStoragePoolObjPtr obj) #define MATCH(FLAG) (flags & (FLAG)) static bool -virStoragePoolMatch(virStoragePoolObjPtr poolobj, +virStoragePoolMatch(virStoragePoolObjPtr obj, unsigned int flags) { /* filter by active state */ if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) && !((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE) && - virStoragePoolObjIsActive(poolobj)) || + virStoragePoolObjIsActive(obj)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE) && - !virStoragePoolObjIsActive(poolobj)))) + !virStoragePoolObjIsActive(obj)))) return false; /* filter by persistence */ if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT) && !((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT) && - poolobj->configFile) || + obj->configFile) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT) && - !poolobj->configFile))) + !obj->configFile))) return false; /* filter by autostart option */ if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART) && !((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART) && - poolobj->autostart) || + obj->autostart) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART) && - !poolobj->autostart))) + !obj->autostart))) return false; /* filter by pool type */ if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)) { if (!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DIR) && - (poolobj->def->type == VIR_STORAGE_POOL_DIR)) || + (obj->def->type == VIR_STORAGE_POOL_DIR)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FS) && - (poolobj->def->type == VIR_STORAGE_POOL_FS)) || + (obj->def->type == VIR_STORAGE_POOL_FS)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NETFS) && - (poolobj->def->type == VIR_STORAGE_POOL_NETFS)) || + (obj->def->type == VIR_STORAGE_POOL_NETFS)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL) && - (poolobj->def->type == VIR_STORAGE_POOL_LOGICAL)) || + (obj->def->type == VIR_STORAGE_POOL_LOGICAL)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DISK) && - (poolobj->def->type == VIR_STORAGE_POOL_DISK)) || + (obj->def->type == VIR_STORAGE_POOL_DISK)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI) && - (poolobj->def->type == VIR_STORAGE_POOL_ISCSI)) || + (obj->def->type == VIR_STORAGE_POOL_ISCSI)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SCSI) && - (poolobj->def->type == VIR_STORAGE_POOL_SCSI)) || + (obj->def->type == VIR_STORAGE_POOL_SCSI)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_MPATH) && - (poolobj->def->type == VIR_STORAGE_POOL_MPATH)) || + (obj->def->type == VIR_STORAGE_POOL_MPATH)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_RBD) && - (poolobj->def->type == VIR_STORAGE_POOL_RBD)) || + (obj->def->type == VIR_STORAGE_POOL_RBD)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG) && - (poolobj->def->type == VIR_STORAGE_POOL_SHEEPDOG)) || + (obj->def->type == VIR_STORAGE_POOL_SHEEPDOG)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER) && - (poolobj->def->type == VIR_STORAGE_POOL_GLUSTER)) || + (obj->def->type == VIR_STORAGE_POOL_GLUSTER)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ZFS) && - (poolobj->def->type == VIR_STORAGE_POOL_ZFS)) || + (obj->def->type == VIR_STORAGE_POOL_ZFS)) || (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE) && - (poolobj->def->type == VIR_STORAGE_POOL_VSTORAGE)))) + (obj->def->type == VIR_STORAGE_POOL_VSTORAGE)))) return false; } @@ -1153,23 +1151,23 @@ virStoragePoolObjListExport(virConnectPtr conn, goto cleanup; for (i = 0; i < poolobjs->count; i++) { - virStoragePoolObjPtr poolobj = poolobjs->objs[i]; - virStoragePoolObjLock(poolobj); - if ((!filter || filter(conn, poolobj->def)) && - virStoragePoolMatch(poolobj, flags)) { + virStoragePoolObjPtr obj = poolobjs->objs[i]; + virStoragePoolObjLock(obj); + if ((!filter || filter(conn, obj->def)) && + virStoragePoolMatch(obj, flags)) { if (pools) { if (!(pool = virGetStoragePool(conn, - poolobj->def->name, - poolobj->def->uuid, + obj->def->name, + obj->def->uuid, NULL, NULL))) { - virStoragePoolObjUnlock(poolobj); + virStoragePoolObjUnlock(obj); goto cleanup; } tmp_pools[npools] = pool; } npools++; } - virStoragePoolObjUnlock(poolobj); + virStoragePoolObjUnlock(obj); } if (tmp_pools) { diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 7c11910..494b888 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -71,9 +71,9 @@ typedef bool virStoragePoolDefPtr def); static inline int -virStoragePoolObjIsActive(virStoragePoolObjPtr pool) +virStoragePoolObjIsActive(virStoragePoolObjPtr obj) { - return pool->active; + return obj->active; } int @@ -94,19 +94,19 @@ virStoragePoolObjFindByName(virStoragePoolObjListPtr pools, const char *name); virStorageVolDefPtr -virStorageVolDefFindByKey(virStoragePoolObjPtr pool, +virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key); virStorageVolDefPtr -virStorageVolDefFindByPath(virStoragePoolObjPtr pool, +virStorageVolDefFindByPath(virStoragePoolObjPtr obj, const char *path); virStorageVolDefPtr -virStorageVolDefFindByName(virStoragePoolObjPtr pool, +virStorageVolDefFindByName(virStoragePoolObjPtr obj, const char *name); void -virStoragePoolObjClearVols(virStoragePoolObjPtr pool); +virStoragePoolObjClearVols(virStoragePoolObjPtr obj); typedef bool (*virStoragePoolVolumeACLFilter)(virConnectPtr conn, @@ -140,11 +140,11 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStoragePoolDefPtr def); int -virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool); +virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj); typedef bool (*virStoragePoolObjListACLFilter)(virConnectPtr conn, virStoragePoolDefPtr def); @@ -164,14 +164,14 @@ virStoragePoolObjGetNames(virStoragePoolObjListPtr pools, int maxnames); void -virStoragePoolObjFree(virStoragePoolObjPtr pool); +virStoragePoolObjFree(virStoragePoolObjPtr obj); void virStoragePoolObjListFree(virStoragePoolObjListPtr pools); void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr pool); + virStoragePoolObjPtr obj); int virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, -- 2.9.3

On Tue, May 09, 2017 at 11:30:14AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
There is no such change in this commit.
NB: Also modify the @matchpool to @matchobj. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 342 +++++++++++++++++++++++------------------------ src/conf/virstorageobj.h | 20 +-- 2 files changed, 180 insertions(+), 182 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index dd41701..74a9c67 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -70,15 +70,15 @@ virStoragePoolObjListFree(virStoragePoolObjListPtr pools)
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr pool) + virStoragePoolObjPtr obj)
This is why I'm not a fan of this change, to make the code consistent we should also rename "pools" to "objs" which I don't like so probably "objList" or something else. Pavel

On 07/12/2017 04:17 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:14AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
There is no such change in this commit.
Simple enough to remove.
NB: Also modify the @matchpool to @matchobj. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 342 +++++++++++++++++++++++------------------------ src/conf/virstorageobj.h | 20 +-- 2 files changed, 180 insertions(+), 182 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index dd41701..74a9c67 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -70,15 +70,15 @@ virStoragePoolObjListFree(virStoragePoolObjListPtr pools)
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr pool) + virStoragePoolObjPtr obj)
This is why I'm not a fan of this change, to make the code consistent we should also rename "pools" to "objs" which I don't like so probably "objList" or something else.
Pavel
I understand the objections and I agree @pools could be something else... Similarly @devs, @nwfilters, @secrets, @interfaces, etc. The difference between @pools and @pool/@obj is the usage of @pool/@obj wasn't consistent. At least there's only one @pools - OK, well two one in _virStorageDriverState and one in _testDriver. I guess that's the line I didn't cross. John

On Thu, Jul 13, 2017 at 05:49:35PM -0400, John Ferlan wrote:
On 07/12/2017 04:17 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:14AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
There is no such change in this commit.
Simple enough to remove.
NB: Also modify the @matchpool to @matchobj. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 342 +++++++++++++++++++++++------------------------ src/conf/virstorageobj.h | 20 +-- 2 files changed, 180 insertions(+), 182 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index dd41701..74a9c67 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -70,15 +70,15 @@ virStoragePoolObjListFree(virStoragePoolObjListPtr pools)
void virStoragePoolObjRemove(virStoragePoolObjListPtr pools, - virStoragePoolObjPtr pool) + virStoragePoolObjPtr obj)
This is why I'm not a fan of this change, to make the code consistent we should also rename "pools" to "objs" which I don't like so probably "objList" or something else.
Pavel
I understand the objections and I agree @pools could be something else... Similarly @devs, @nwfilters, @secrets, @interfaces, etc.
The difference between @pools and @pool/@obj is the usage of @pool/@obj wasn't consistent. At least there's only one @pools - OK, well two one in _virStorageDriverState and one in _testDriver.
I guess that's the line I didn't cross.
This can be addressed as a followup. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

A virStoragePoolObjPtr will be an 'obj'. A virStoragePoolPtr will be a 'pool'. A virStorageVolPtr will be a 'vol'. A virStorageVolDefPtr will be a 'voldef'. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 1158 +++++++++++++++++++++--------------------- src/storage/storage_driver.h | 4 +- 2 files changed, 582 insertions(+), 580 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 2103ed1..6122396 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -87,45 +87,45 @@ static void storageDriverUnlock(void) * pools are removed. */ static void -virStoragePoolUpdateInactive(virStoragePoolObjPtr *poolptr) +virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) { - virStoragePoolObjPtr pool = *poolptr; + virStoragePoolObjPtr obj = *objptr; - if (pool->configFile == NULL) { - virStoragePoolObjRemove(&driver->pools, pool); - *poolptr = NULL; - } else if (pool->newDef) { - virStoragePoolDefFree(pool->def); - pool->def = pool->newDef; - pool->newDef = NULL; + if (obj->configFile == NULL) { + virStoragePoolObjRemove(&driver->pools, obj); + *objptr = NULL; + } else if (obj->newDef) { + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; } } static void -storagePoolUpdateState(virStoragePoolObjPtr pool) +storagePoolUpdateState(virStoragePoolObjPtr obj) { bool active = false; virStorageBackendPtr backend; char *stateFile; if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"))) + obj->def->name, ".xml"))) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) { + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing backend %d"), pool->def->type); + _("Missing backend %d"), obj->def->type); goto cleanup; } /* Backends which do not support 'checkPool' are considered * inactive by default. */ if (backend->checkPool && - backend->checkPool(pool, &active) < 0) { + backend->checkPool(obj, &active) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to initialize storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); active = false; } @@ -134,21 +134,21 @@ storagePoolUpdateState(virStoragePoolObjPtr pool) * continue with other pools. */ if (active) { - virStoragePoolObjClearVols(pool); - if (backend->refreshPool(NULL, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (backend->refreshPool(NULL, obj) < 0) { if (backend->stopPool) - backend->stopPool(NULL, pool); + backend->stopPool(NULL, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to restart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); active = false; } } - pool->active = active; + obj->active = active; - if (!pool->active) - virStoragePoolUpdateInactive(&pool); + if (!obj->active) + virStoragePoolUpdateInactive(&obj); cleanup: if (!active && stateFile) @@ -164,11 +164,11 @@ storagePoolUpdateAllState(void) size_t i; for (i = 0; i < driver->pools.count; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + virStoragePoolObjPtr obj = driver->pools.objs[i]; - virStoragePoolObjLock(pool); - storagePoolUpdateState(pool); - virStoragePoolObjUnlock(pool); + virStoragePoolObjLock(obj); + storagePoolUpdateState(obj); + virStoragePoolObjUnlock(obj); } } @@ -186,24 +186,24 @@ storageDriverAutostart(void) /* Ignoring NULL conn - let backends decide */ for (i = 0; i < driver->pools.count; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + virStoragePoolObjPtr obj = driver->pools.objs[i]; virStorageBackendPtr backend; bool started = false; - virStoragePoolObjLock(pool); - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) { - virStoragePoolObjUnlock(pool); + virStoragePoolObjLock(obj); + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { + virStoragePoolObjUnlock(obj); continue; } - if (pool->autostart && - !virStoragePoolObjIsActive(pool)) { + if (obj->autostart && + !virStoragePoolObjIsActive(obj)) { if (backend->startPool && - backend->startPool(conn, pool) < 0) { + backend->startPool(conn, obj) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); - virStoragePoolObjUnlock(pool); + obj->def->name, virGetLastErrorMessage()); + virStoragePoolObjUnlock(obj); continue; } started = true; @@ -212,25 +212,25 @@ storageDriverAutostart(void) if (started) { char *stateFile; - virStoragePoolObjClearVols(pool); + virStoragePoolObjClearVols(obj); stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml"); if (!stateFile || - virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(conn, pool) < 0) { + virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(conn, pool); + backend->stopPool(conn, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); } else { - pool->active = true; + obj->active = true; } VIR_FREE(stateFile); } - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); } virObjectUnref(conn); @@ -391,10 +391,10 @@ static virStoragePoolObjPtr storagePoolObjFindByUUID(const unsigned char *uuid, const char *name) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, uuid))) { + if (!(obj = virStoragePoolObjFindByUUID(&driver->pools, uuid))) { virUUIDFormat(uuid, uuidstr); if (name) virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -406,7 +406,7 @@ storagePoolObjFindByUUID(const unsigned char *uuid, uuidstr); } - return pool; + return obj; } @@ -426,15 +426,15 @@ virStoragePoolObjFromStoragePool(virStoragePoolPtr pool) static virStoragePoolObjPtr storagePoolObjFindByName(const char *name) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; storageDriverLock(); - if (!(pool = 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(); - return pool; + return obj; } @@ -442,65 +442,63 @@ static virStoragePoolPtr storagePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL; storageDriverLock(); - pool = storagePoolObjFindByUUID(uuid, NULL); + obj = storagePoolObjFindByUUID(uuid, NULL); storageDriverUnlock(); - if (!pool) + if (!obj) return NULL; - if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0) + if (virStoragePoolLookupByUUIDEnsureACL(conn, obj->def) < 0) goto cleanup; - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; } static virStoragePoolPtr storagePoolLookupByName(virConnectPtr conn, const char *name) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL; - if (!(pool = storagePoolObjFindByName(name))) + if (!(obj = storagePoolObjFindByName(name))) return NULL; - if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0) + if (virStoragePoolLookupByNameEnsureACL(conn, obj->def) < 0) goto cleanup; - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; } static virStoragePoolPtr storagePoolLookupByVolume(virStorageVolPtr vol) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL; - if (!(pool = storagePoolObjFindByName(vol->pool))) + if (!(obj = storagePoolObjFindByName(vol->pool))) return NULL; - if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0) + if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, obj->def) < 0) goto cleanup; - ret = virGetStoragePool(vol->conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(vol->conn, obj->def->name, obj->def->uuid, + NULL, NULL); cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; } static int @@ -613,7 +611,8 @@ storageConnectFindStoragePoolSources(virConnectPtr conn, } -static int storagePoolIsActive(virStoragePoolPtr pool) +static int +storagePoolIsActive(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; int ret = -1; @@ -631,7 +630,9 @@ static int storagePoolIsActive(virStoragePoolPtr pool) return ret; } -static int storagePoolIsPersistent(virStoragePoolPtr pool) + +static int +storagePoolIsPersistent(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; int ret = -1; @@ -656,8 +657,8 @@ storagePoolCreateXML(virConnectPtr conn, unsigned int flags) { virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj = NULL; + virStoragePoolPtr pool = NULL; virStorageBackendPtr backend; virObjectEventPtr event = NULL; char *stateFile = NULL; @@ -686,7 +687,7 @@ storagePoolCreateXML(virConnectPtr conn, if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; - if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; def = NULL; @@ -698,56 +699,55 @@ storagePoolCreateXML(virConnectPtr conn, if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { - if (backend->buildPool(conn, pool, build_flags) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + if (backend->buildPool(conn, obj, build_flags) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; } } } if (backend->startPool && - backend->startPool(conn, pool) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + backend->startPool(conn, obj) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; } stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml"); - virStoragePoolObjClearVols(pool); - if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(conn, pool); - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + backend->stopPool(conn, obj); + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; } - event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - VIR_INFO("Creating storage pool '%s'", pool->def->name); - pool->active = true; + VIR_INFO("Creating storage pool '%s'", obj->def->name); + obj->active = true; - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: VIR_FREE(stateFile); virStoragePoolDefFree(def); if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); - return ret; + return pool; } static virStoragePoolPtr @@ -756,8 +756,8 @@ storagePoolDefineXML(virConnectPtr conn, unsigned int flags) { virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj = NULL; + virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL; virCheckFlags(0, NULL); @@ -781,13 +781,13 @@ storagePoolDefineXML(virConnectPtr conn, if (virStorageBackendForType(def->type) == NULL) goto cleanup; - if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; - if (virStoragePoolObjSaveDef(driver, pool, def) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); + if (virStoragePoolObjSaveDef(driver, obj, def) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); def = NULL; - pool = NULL; + obj = NULL; goto cleanup; } @@ -797,86 +797,85 @@ storagePoolDefineXML(virConnectPtr conn, def = NULL; - VIR_INFO("Defining storage pool '%s'", pool->def->name); - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + VIR_INFO("Defining storage pool '%s'", obj->def->name); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolDefFree(def); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); - return ret; + return pool; } static int -storagePoolUndefine(virStoragePoolPtr obj) +storagePoolUndefine(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virObjectEventPtr event = NULL; int ret = -1; storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; - if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolUndefineEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - pool->def->name); + obj->def->name); goto cleanup; } - if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; } - if (virStoragePoolObjDeleteDef(pool) < 0) + if (virStoragePoolObjDeleteDef(obj) < 0) goto cleanup; - if (unlink(pool->autostartLink) < 0 && + if (unlink(obj->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { char ebuf[1024]; VIR_ERROR(_("Failed to delete autostart link '%s': %s"), - pool->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); + obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); } - VIR_FREE(pool->configFile); - VIR_FREE(pool->autostartLink); + VIR_FREE(obj->configFile); + VIR_FREE(obj->autostartLink); - event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, 0); - VIR_INFO("Undefining storage pool '%s'", pool->def->name); - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + VIR_INFO("Undefining storage pool '%s'", obj->def->name); + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; ret = 0; cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; } static int -storagePoolCreate(virStoragePoolPtr obj, +storagePoolCreate(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virObjectEventPtr event = NULL; int ret = -1; @@ -890,19 +889,19 @@ storagePoolCreate(virStoragePoolPtr obj, VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, -1); - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolCreateEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolCreateEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - pool->def->name); + obj->def->name); goto cleanup; } @@ -914,117 +913,117 @@ storagePoolCreate(virStoragePoolPtr obj, if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { - if (backend->buildPool(obj->conn, pool, build_flags) < 0) + if (backend->buildPool(pool->conn, obj, build_flags) < 0) goto cleanup; } } - VIR_INFO("Starting up storage pool '%s'", pool->def->name); + VIR_INFO("Starting up storage pool '%s'", obj->def->name); if (backend->startPool && - backend->startPool(obj->conn, pool) < 0) + backend->startPool(pool->conn, obj) < 0) goto cleanup; stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml"); - virStoragePoolObjClearVols(pool); - if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(obj->conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(pool->conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(obj->conn, pool); + backend->stopPool(pool->conn, obj); goto cleanup; } - event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - pool->active = true; + obj->active = true; ret = 0; cleanup: VIR_FREE(stateFile); if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolBuild(virStoragePoolPtr obj, +storagePoolBuild(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; int ret = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolBuildEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolBuildEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - pool->def->name); + obj->def->name); goto cleanup; } if (backend->buildPool && - backend->buildPool(obj->conn, pool, flags) < 0) + backend->buildPool(pool->conn, obj, flags) < 0) goto cleanup; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolDestroy(virStoragePoolPtr obj) +storagePoolDestroy(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virObjectEventPtr event = NULL; char *stateFile = NULL; int ret = -1; storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; - if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolDestroyEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - VIR_INFO("Destroying storage pool '%s'", pool->def->name); + VIR_INFO("Destroying storage pool '%s'", obj->def->name); - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; } if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, + obj->def->name, ".xml"))) goto cleanup; @@ -1032,67 +1031,67 @@ storagePoolDestroy(virStoragePoolPtr obj) VIR_FREE(stateFile); if (backend->stopPool && - backend->stopPool(obj->conn, pool) < 0) + backend->stopPool(pool->conn, obj) < 0) goto cleanup; - virStoragePoolObjClearVols(pool); + virStoragePoolObjClearVols(obj); - event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - pool->active = false; + obj->active = false; - virStoragePoolUpdateInactive(&pool); + virStoragePoolUpdateInactive(&obj); ret = 0; cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; } static int -storagePoolDelete(virStoragePoolPtr obj, +storagePoolDelete(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; char *stateFile = NULL; int ret = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolDeleteEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolDeleteEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - VIR_INFO("Deleting storage pool '%s'", pool->def->name); + VIR_INFO("Deleting storage pool '%s'", obj->def->name); - if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - pool->def->name); + obj->def->name); goto cleanup; } - if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; } if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, + obj->def->name, ".xml"))) goto cleanup; @@ -1104,22 +1103,22 @@ storagePoolDelete(virStoragePoolPtr obj, "%s", _("pool does not support pool deletion")); goto cleanup; } - if (backend->deletePool(obj->conn, pool, flags) < 0) + if (backend->deletePool(pool->conn, obj, flags) < 0) goto cleanup; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolRefresh(virStoragePoolPtr obj, +storagePoolRefresh(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; int ret = -1; virObjectEventPtr event = NULL; @@ -1127,165 +1126,165 @@ storagePoolRefresh(virStoragePoolPtr obj, virCheckFlags(0, -1); storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; - if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolRefreshEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; } - virStoragePoolObjClearVols(pool); - if (backend->refreshPool(obj->conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (backend->refreshPool(pool->conn, obj) < 0) { if (backend->stopPool) - backend->stopPool(obj->conn, pool); + backend->stopPool(pool->conn, obj); - event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - pool->active = false; + obj->active = false; - virStoragePoolUpdateInactive(&pool); + virStoragePoolUpdateInactive(&obj); goto cleanup; } - event = virStoragePoolEventRefreshNew(pool->def->name, - pool->def->uuid); + event = virStoragePoolEventRefreshNew(obj->def->name, + obj->def->uuid); ret = 0; cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; } static int -storagePoolGetInfo(virStoragePoolPtr obj, +storagePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolGetInfoEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetInfoEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (virStorageBackendForType(pool->def->type) == NULL) + if (virStorageBackendForType(obj->def->type) == NULL) goto cleanup; memset(info, 0, sizeof(virStoragePoolInfo)); - if (pool->active) + if (obj->active) info->state = VIR_STORAGE_POOL_RUNNING; else info->state = VIR_STORAGE_POOL_INACTIVE; - info->capacity = pool->def->capacity; - info->allocation = pool->def->allocation; - info->available = pool->def->available; + info->capacity = obj->def->capacity; + info->allocation = obj->def->allocation; + info->available = obj->def->available; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static char * -storagePoolGetXMLDesc(virStoragePoolPtr obj, +storagePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolDefPtr def; char *ret = NULL; virCheckFlags(VIR_STORAGE_XML_INACTIVE, NULL); - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; - if (virStoragePoolGetXMLDescEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetXMLDescEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if ((flags & VIR_STORAGE_XML_INACTIVE) && pool->newDef) - def = pool->newDef; + if ((flags & VIR_STORAGE_XML_INACTIVE) && obj->newDef) + def = obj->newDef; else - def = pool->def; + def = obj->def; ret = virStoragePoolDefFormat(def); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolGetAutostart(virStoragePoolPtr obj, +storagePoolGetAutostart(virStoragePoolPtr pool, int *autostart) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolGetAutostartEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!pool->configFile) { + if (!obj->configFile) { *autostart = 0; } else { - *autostart = pool->autostart; + *autostart = obj->autostart; } + ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolSetAutostart(virStoragePoolPtr obj, +storagePoolSetAutostart(virStoragePoolPtr pool, int autostart) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1; storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; - if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!pool->configFile) { + if (!obj->configFile) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("pool has no config file")); - goto cleanup; } autostart = (autostart != 0); - if (pool->autostart != autostart) { + if (obj->autostart != autostart) { if (autostart) { if (virFileMakePath(driver->autostartDir) < 0) { virReportSystemError(errno, @@ -1294,85 +1293,86 @@ storagePoolSetAutostart(virStoragePoolPtr obj, goto cleanup; } - if (symlink(pool->configFile, pool->autostartLink) < 0) { + if (symlink(obj->configFile, obj->autostartLink) < 0) { virReportSystemError(errno, _("Failed to create symlink '%s' to '%s'"), - pool->autostartLink, pool->configFile); + obj->autostartLink, obj->configFile); goto cleanup; } } else { - if (unlink(pool->autostartLink) < 0 && + if (unlink(obj->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { virReportSystemError(errno, _("Failed to delete symlink '%s'"), - pool->autostartLink); + obj->autostartLink); goto cleanup; } } - pool->autostart = autostart; + obj->autostart = autostart; } + ret = 0; cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; } static int -storagePoolNumOfVolumes(virStoragePoolPtr obj) +storagePoolNumOfVolumes(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolNumOfVolumesEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolNumOfVolumesEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - ret = virStoragePoolObjNumOfVolumes(&pool->volumes, obj->conn, pool->def, + ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, obj->def, virStoragePoolNumOfVolumesCheckACL); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storagePoolListVolumes(virStoragePoolPtr obj, +storagePoolListVolumes(virStoragePoolPtr pool, char **const names, int maxnames) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int n = -1; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolListVolumesEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolListVolumesEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - n = virStoragePoolObjVolumeGetNames(&pool->volumes, obj->conn, pool->def, + n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, obj->def, virStoragePoolListVolumesCheckACL, names, maxnames); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return n; } @@ -1411,40 +1411,40 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, } static virStorageVolPtr -storageVolLookupByName(virStoragePoolPtr obj, +storageVolLookupByName(virStoragePoolPtr pool, const char *name) { - virStoragePoolObjPtr pool; - virStorageVolDefPtr vol; - virStorageVolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStorageVolDefPtr voldef; + virStorageVolPtr vol = NULL; - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - vol = virStorageVolDefFindByName(pool, name); + voldef = virStorageVolDefFindByName(obj, name); - if (!vol) { + if (!voldef) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), name); goto cleanup; } - if (virStorageVolLookupByNameEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolLookupByNameEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup; - ret = virGetStorageVol(obj->conn, pool->def->name, vol->name, vol->key, - NULL, NULL); + vol = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + voldef->key, NULL, NULL); cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return vol; } @@ -1453,39 +1453,39 @@ storageVolLookupByKey(virConnectPtr conn, const char *key) { size_t i; - virStorageVolPtr ret = NULL; + virStorageVolPtr vol = NULL; storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { + for (i = 0; i < driver->pools.count && !vol; i++) { virStoragePoolObjLock(driver->pools.objs[i]); if (virStoragePoolObjIsActive(driver->pools.objs[i])) { - virStorageVolDefPtr vol = + virStorageVolDefPtr voldef = virStorageVolDefFindByKey(driver->pools.objs[i], key); - if (vol) { + if (voldef) { virStoragePoolDefPtr def = driver->pools.objs[i]->def; - if (virStorageVolLookupByKeyEnsureACL(conn, def, vol) < 0) { + if (virStorageVolLookupByKeyEnsureACL(conn, def, voldef) < 0) { virStoragePoolObjUnlock(driver->pools.objs[i]); goto cleanup; } - ret = virGetStorageVol(conn, + vol = virGetStorageVol(conn, def->name, - vol->name, - vol->key, + voldef->name, + voldef->key, NULL, NULL); } } virStoragePoolObjUnlock(driver->pools.objs[i]); } - if (!ret) + if (!vol) virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching key %s"), key); cleanup: storageDriverUnlock(); - return ret; + return vol; } static virStorageVolPtr @@ -1493,7 +1493,7 @@ storageVolLookupByPath(virConnectPtr conn, const char *path) { size_t i; - virStorageVolPtr ret = NULL; + virStorageVolPtr vol = NULL; char *cleanpath; cleanpath = virFileSanitizePath(path); @@ -1501,19 +1501,19 @@ storageVolLookupByPath(virConnectPtr conn, return NULL; storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; - virStorageVolDefPtr vol; + for (i = 0; i < driver->pools.count && !vol; i++) { + virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStorageVolDefPtr voldef; char *stable_path = NULL; - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); - if (!virStoragePoolObjIsActive(pool)) { - virStoragePoolObjUnlock(pool); + if (!virStoragePoolObjIsActive(obj)) { + virStoragePoolObjUnlock(obj); continue; } - switch ((virStoragePoolType) pool->def->type) { + switch ((virStoragePoolType) obj->def->type) { case VIR_STORAGE_POOL_DIR: case VIR_STORAGE_POOL_FS: case VIR_STORAGE_POOL_NETFS: @@ -1523,7 +1523,7 @@ storageVolLookupByPath(virConnectPtr conn, case VIR_STORAGE_POOL_SCSI: case VIR_STORAGE_POOL_MPATH: case VIR_STORAGE_POOL_VSTORAGE: - stable_path = virStorageBackendStablePath(pool, + stable_path = virStorageBackendStablePath(obj, cleanpath, false); if (stable_path == NULL) { @@ -1531,8 +1531,8 @@ storageVolLookupByPath(virConnectPtr conn, * getting the stable path for some of the pools. */ VIR_WARN("Failed to get stable path for pool '%s'", - pool->def->name); - virStoragePoolObjUnlock(pool); + obj->def->name); + virStoragePoolObjUnlock(obj); continue; } break; @@ -1543,30 +1543,30 @@ storageVolLookupByPath(virConnectPtr conn, case VIR_STORAGE_POOL_ZFS: case VIR_STORAGE_POOL_LAST: if (VIR_STRDUP(stable_path, path) < 0) { - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); goto cleanup; } break; } - vol = virStorageVolDefFindByPath(pool, stable_path); + voldef = virStorageVolDefFindByPath(obj, stable_path); VIR_FREE(stable_path); - if (vol) { - if (virStorageVolLookupByPathEnsureACL(conn, pool->def, vol) < 0) { - virStoragePoolObjUnlock(pool); + if (voldef) { + if (virStorageVolLookupByPathEnsureACL(conn, obj->def, voldef) < 0) { + virStoragePoolObjUnlock(obj); goto cleanup; } - ret = virGetStorageVol(conn, pool->def->name, - vol->name, vol->key, + vol = virGetStorageVol(conn, obj->def->name, + voldef->name, voldef->key, NULL, NULL); } - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); } - if (!ret) { + if (!vol) { if (STREQ(path, cleanpath)) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching path '%s'"), path); @@ -1580,7 +1580,7 @@ storageVolLookupByPath(virConnectPtr conn, cleanup: VIR_FREE(cleanpath); storageDriverUnlock(); - return ret; + return vol; } virStoragePoolPtr @@ -1588,7 +1588,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, const char *path) { size_t i; - virStoragePoolPtr ret = NULL; + virStoragePoolPtr pool = NULL; char *cleanpath; cleanpath = virFileSanitizePath(path); @@ -1596,49 +1596,49 @@ storagePoolLookupByTargetPath(virConnectPtr conn, return NULL; storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + for (i = 0; i < driver->pools.count && !pool; i++) { + virStoragePoolObjPtr obj = driver->pools.objs[i]; - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); - if (!virStoragePoolObjIsActive(pool)) { - virStoragePoolObjUnlock(pool); + if (!virStoragePoolObjIsActive(obj)) { + virStoragePoolObjUnlock(obj); continue; } - if (STREQ(path, pool->def->target.path)) { - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + if (STREQ(path, obj->def->target.path)) { + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, + NULL, NULL); } - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); } storageDriverUnlock(); - if (!ret) { + if (!pool) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage pool with matching target path '%s'"), path); } VIR_FREE(cleanpath); - return ret; + return pool; } static void -storageVolRemoveFromPool(virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +storageVolRemoveFromPool(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) { size_t i; - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i] == vol) { + for (i = 0; i < obj->volumes.count; i++) { + if (obj->volumes.objs[i] == voldef) { VIR_INFO("Deleting volume '%s' from storage pool '%s'", - vol->name, pool->def->name); - virStorageVolDefFree(vol); + voldef->name, obj->def->name); + virStorageVolDefFree(voldef); - VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count); + VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); break; } } @@ -1646,10 +1646,10 @@ storageVolRemoveFromPool(virStoragePoolObjPtr pool, static int -storageVolDeleteInternal(virStorageVolPtr obj, +storageVolDeleteInternal(virStorageVolPtr vol, virStorageBackendPtr backend, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol, + virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef, unsigned int flags, bool updateMeta) { @@ -1662,7 +1662,7 @@ storageVolDeleteInternal(virStorageVolPtr obj, goto cleanup; } - if (backend->deleteVol(obj->conn, pool, vol, flags) < 0) + if (backend->deleteVol(vol->conn, obj, voldef, flags) < 0) goto cleanup; /* Update pool metadata - don't update meta data from error paths @@ -1670,13 +1670,13 @@ storageVolDeleteInternal(virStorageVolPtr obj, * Ignore the disk backend since it updates the pool values. */ if (updateMeta) { - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation -= vol->target.allocation; - pool->def->available += vol->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation -= voldef->target.allocation; + obj->def->available += voldef->target.allocation; } } - storageVolRemoveFromPool(pool, vol); + storageVolRemoveFromPool(obj, voldef); ret = 0; cleanup: @@ -1685,109 +1685,109 @@ storageVolDeleteInternal(virStorageVolPtr obj, static virStorageVolDefPtr -virStorageVolDefFromVol(virStorageVolPtr obj, - virStoragePoolObjPtr *pool, +virStorageVolDefFromVol(virStorageVolPtr vol, + virStoragePoolObjPtr *obj, virStorageBackendPtr *backend) { - virStorageVolDefPtr vol = NULL; + virStorageVolDefPtr voldef = NULL; - if (!(*pool = storagePoolObjFindByName(obj->pool))) + if (!(*obj = storagePoolObjFindByName(vol->pool))) return NULL; - if (!virStoragePoolObjIsActive(*pool)) { + if (!virStoragePoolObjIsActive(*obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), - (*pool)->def->name); + (*obj)->def->name); goto error; } - if (!(vol = virStorageVolDefFindByName(*pool, obj->name))) { + if (!(voldef = virStorageVolDefFindByName(*obj, vol->name))) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), - obj->name); + vol->name); goto error; } if (backend) { - if (!(*backend = virStorageBackendForType((*pool)->def->type))) + if (!(*backend = virStorageBackendForType((*obj)->def->type))) goto error; } - return vol; + return voldef; error: - virStoragePoolObjUnlock(*pool); - *pool = NULL; + virStoragePoolObjUnlock(*obj); + *obj = NULL; return NULL; } static int -storageVolDelete(virStorageVolPtr obj, +storageVolDelete(virStorageVolPtr vol, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; - virStorageVolDefPtr vol = NULL; + virStorageVolDefPtr voldef = NULL; int ret = -1; - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolDeleteEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolDeleteEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - if (vol->in_use) { + if (voldef->in_use) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still in use."), - vol->name); + voldef->name); goto cleanup; } - if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; } - if (storageVolDeleteInternal(obj, backend, pool, vol, flags, true) < 0) + if (storageVolDeleteInternal(vol, backend, obj, voldef, flags, true) < 0) goto cleanup; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static virStorageVolPtr -storageVolCreateXML(virStoragePoolPtr obj, +storageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolPtr vol = NULL, volobj = NULL; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); - if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - voldef = virStorageVolDefParseString(pool->def, xmldesc, + voldef = virStorageVolDefParseString(obj->def, xmldesc, VIR_VOL_XML_PARSE_OPT_CAPACITY); if (voldef == NULL) goto cleanup; @@ -1799,10 +1799,10 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; } - if (virStorageVolCreateXMLEnsureACL(obj->conn, pool->def, voldef) < 0) + if (virStorageVolCreateXMLEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup; - if (virStorageVolDefFindByName(pool, voldef->name)) { + if (virStorageVolDefFindByName(obj, voldef->name)) { virReportError(VIR_ERR_STORAGE_VOL_EXIST, _("'%s'"), voldef->name); goto cleanup; @@ -1815,21 +1815,21 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; } - if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) + if (VIR_REALLOC_N(obj->volumes.objs, + obj->volumes.count + 1) < 0) goto cleanup; /* Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(voldef->key); - if (backend->createVol(obj->conn, pool, voldef) < 0) + if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup; - pool->volumes.objs[pool->volumes.count++] = voldef; - volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name, + obj->volumes.objs[obj->volumes.count++] = voldef; + volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, voldef->key, NULL, NULL); if (!volobj) { - pool->volumes.count--; + obj->volumes.count--; goto cleanup; } @@ -1850,24 +1850,24 @@ storageVolCreateXML(virStoragePoolPtr obj, memcpy(buildvoldef, voldef, sizeof(*voldef)); /* Drop the pool lock during volume allocation */ - pool->asyncjobs++; + obj->asyncjobs++; voldef->building = true; - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); - buildret = backend->buildVol(obj->conn, pool, buildvoldef, flags); + buildret = backend->buildVol(pool->conn, obj, buildvoldef, flags); VIR_FREE(buildvoldef); storageDriverLock(); - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); storageDriverUnlock(); voldef->building = false; - pool->asyncjobs--; + obj->asyncjobs--; if (buildret < 0) { /* buildVol handles deleting volume on failure */ - storageVolRemoveFromPool(pool, voldef); + storageVolRemoveFromPool(obj, voldef); voldef = NULL; goto cleanup; } @@ -1875,8 +1875,8 @@ storageVolCreateXML(virStoragePoolPtr obj, } if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, voldef) < 0) { - storageVolDeleteInternal(volobj, backend, pool, voldef, + backend->refreshVol(pool->conn, obj, voldef) < 0) { + storageVolDeleteInternal(volobj, backend, obj, voldef, 0, false); voldef = NULL; goto cleanup; @@ -1885,35 +1885,39 @@ storageVolCreateXML(virStoragePoolPtr obj, /* Update pool metadata ignoring the disk backend since * it updates the pool values. */ - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += voldef->target.allocation; - pool->def->available -= voldef->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation += voldef->target.allocation; + obj->def->available -= voldef->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, pool->def->name); - ret = volobj; + volobj->name, obj->def->name); + vol = volobj; volobj = NULL; voldef = NULL; cleanup: virObjectUnref(volobj); virStorageVolDefFree(voldef); - if (pool) - virStoragePoolObjUnlock(pool); - return ret; + if (obj) + virStoragePoolObjUnlock(obj); + return vol; } static virStorageVolPtr -storageVolCreateXMLFrom(virStoragePoolPtr obj, +storageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, - virStorageVolPtr vobj, + virStorageVolPtr volsrc, unsigned int flags) { - virStoragePoolObjPtr pool, origpool = NULL; + virStoragePoolObjPtr obj; + virStoragePoolObjPtr objsrc = NULL; virStorageBackendPtr backend; - virStorageVolDefPtr origvol = NULL, newvol = NULL, shadowvol = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolDefPtr voldefsrc = NULL; + virStorageVolDefPtr voldef = NULL; + virStorageVolDefPtr shadowvol = NULL; + virStorageVolPtr volobj = NULL; + virStorageVolPtr vol = NULL; int buildret; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | @@ -1921,80 +1925,80 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, NULL); storageDriverLock(); - pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); - if (pool && STRNEQ(obj->name, vobj->pool)) { - virStoragePoolObjUnlock(pool); - origpool = virStoragePoolObjFindByName(&driver->pools, vobj->pool); - virStoragePoolObjLock(pool); + obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid); + if (obj && STRNEQ(pool->name, volsrc->pool)) { + virStoragePoolObjUnlock(obj); + objsrc = virStoragePoolObjFindByName(&driver->pools, volsrc->pool); + virStoragePoolObjLock(obj); } storageDriverUnlock(); - if (!pool) { + if (!obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->uuid, uuidstr); + virUUIDFormat(pool->uuid, uuidstr); virReportError(VIR_ERR_NO_STORAGE_POOL, _("no storage pool with matching uuid '%s' (%s)"), - uuidstr, obj->name); + uuidstr, pool->name); goto cleanup; } - if (STRNEQ(obj->name, vobj->pool) && !origpool) { + if (STRNEQ(pool->name, volsrc->pool) && !objsrc) { virReportError(VIR_ERR_NO_STORAGE_POOL, _("no storage pool with matching name '%s'"), - vobj->pool); + volsrc->pool); goto cleanup; } - if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; } - if (origpool && !virStoragePoolObjIsActive(origpool)) { + if (objsrc && !virStoragePoolObjIsActive(objsrc)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), - origpool->def->name); + objsrc->def->name); goto cleanup; } - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup; - origvol = virStorageVolDefFindByName(origpool ? - origpool : pool, vobj->name); - if (!origvol) { + voldefsrc = virStorageVolDefFindByName(objsrc ? + objsrc : obj, volsrc->name); + if (!voldefsrc) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), - vobj->name); + volsrc->name); goto cleanup; } - newvol = virStorageVolDefParseString(pool->def, xmldesc, + voldef = virStorageVolDefParseString(obj->def, xmldesc, VIR_VOL_XML_PARSE_NO_CAPACITY); - if (newvol == NULL) + if (voldef == NULL) goto cleanup; - if (virStorageVolCreateXMLFromEnsureACL(obj->conn, pool->def, newvol) < 0) + if (virStorageVolCreateXMLFromEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup; - if (virStorageVolDefFindByName(pool, newvol->name)) { + if (virStorageVolDefFindByName(obj, voldef->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("storage volume name '%s' already in use."), - newvol->name); + voldef->name); goto cleanup; } /* Use the original volume's capacity in case the new capacity * is less than that, or it was omitted */ - if (newvol->target.capacity < origvol->target.capacity) - newvol->target.capacity = origvol->target.capacity; + if (voldef->target.capacity < voldefsrc->target.capacity) + voldef->target.capacity = voldefsrc->target.capacity; /* If the allocation was not provided in the XML, then use capacity * as it's specifically documented "If omitted when creating a volume, * the volume will be fully allocated at time of creation.". This * is especially important for logical volume creation. */ - if (!newvol->target.has_allocation) - newvol->target.allocation = newvol->target.capacity; + if (!voldef->target.has_allocation) + voldef->target.allocation = voldef->target.capacity; if (!backend->buildVolFrom) { virReportError(VIR_ERR_NO_SUPPORT, @@ -2003,26 +2007,25 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, goto cleanup; } - if (origvol->building) { + if (voldefsrc->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - origvol->name); + voldefsrc->name); goto cleanup; } if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, origvol) < 0) + backend->refreshVol(pool->conn, obj, voldefsrc) < 0) goto cleanup; - if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) + if (VIR_REALLOC_N(obj->volumes.objs, obj->volumes.count + 1) < 0) goto cleanup; /* 'Define' the new volume so we get async progress reporting. * Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ - VIR_FREE(newvol->key); - if (backend->createVol(obj->conn, pool, newvol) < 0) + VIR_FREE(voldef->key); + if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup; /* Make a shallow copy of the 'defined' volume definition, since the @@ -2032,103 +2035,103 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, if (VIR_ALLOC(shadowvol) < 0) goto cleanup; - memcpy(shadowvol, newvol, sizeof(*newvol)); + memcpy(shadowvol, voldef, sizeof(*voldef)); - pool->volumes.objs[pool->volumes.count++] = newvol; - volobj = virGetStorageVol(obj->conn, pool->def->name, newvol->name, - newvol->key, NULL, NULL); + obj->volumes.objs[obj->volumes.count++] = voldef; + volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + voldef->key, NULL, NULL); if (!volobj) { - pool->volumes.count--; + obj->volumes.count--; goto cleanup; } /* Drop the pool lock during volume allocation */ - pool->asyncjobs++; - newvol->building = true; - origvol->in_use++; - virStoragePoolObjUnlock(pool); + obj->asyncjobs++; + voldef->building = true; + voldefsrc->in_use++; + virStoragePoolObjUnlock(obj); - if (origpool) { - origpool->asyncjobs++; - virStoragePoolObjUnlock(origpool); + if (objsrc) { + objsrc->asyncjobs++; + virStoragePoolObjUnlock(objsrc); } - buildret = backend->buildVolFrom(obj->conn, pool, shadowvol, origvol, flags); + buildret = backend->buildVolFrom(pool->conn, obj, shadowvol, voldefsrc, flags); storageDriverLock(); - virStoragePoolObjLock(pool); - if (origpool) - virStoragePoolObjLock(origpool); + virStoragePoolObjLock(obj); + if (objsrc) + virStoragePoolObjLock(objsrc); storageDriverUnlock(); - origvol->in_use--; - newvol->building = false; - pool->asyncjobs--; + voldefsrc->in_use--; + voldef->building = false; + obj->asyncjobs--; - if (origpool) { - origpool->asyncjobs--; - virStoragePoolObjUnlock(origpool); - origpool = NULL; + if (objsrc) { + objsrc->asyncjobs--; + virStoragePoolObjUnlock(objsrc); + objsrc = NULL; } if (buildret < 0 || (backend->refreshVol && - backend->refreshVol(obj->conn, pool, newvol) < 0)) { - storageVolDeleteInternal(volobj, backend, pool, newvol, 0, false); - newvol = NULL; + backend->refreshVol(pool->conn, obj, voldef) < 0)) { + storageVolDeleteInternal(volobj, backend, obj, voldef, 0, false); + voldef = NULL; goto cleanup; } /* Updating pool metadata ignoring the disk backend since * it updates the pool values */ - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += newvol->target.allocation; - pool->def->available -= newvol->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation += voldef->target.allocation; + obj->def->available -= voldef->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, pool->def->name); - ret = volobj; + volobj->name, obj->def->name); + vol = volobj; volobj = NULL; - newvol = NULL; + voldef = NULL; cleanup: virObjectUnref(volobj); - virStorageVolDefFree(newvol); + virStorageVolDefFree(voldef); VIR_FREE(shadowvol); - if (pool) - virStoragePoolObjUnlock(pool); - if (origpool) - virStoragePoolObjUnlock(origpool); - return ret; + if (obj) + virStoragePoolObjUnlock(obj); + if (objsrc) + virStoragePoolObjUnlock(objsrc); + return vol; } static int -storageVolDownload(virStorageVolPtr obj, +storageVolDownload(virStorageVolPtr vol, virStreamPtr stream, unsigned long long offset, unsigned long long length, unsigned int flags) { virStorageBackendPtr backend; - virStoragePoolObjPtr pool = NULL; - virStorageVolDefPtr vol = NULL; + virStoragePoolObjPtr obj = NULL; + virStorageVolDefPtr voldef = NULL; int ret = -1; virCheckFlags(0, -1); - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolDownloadEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolDownloadEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; } @@ -2138,11 +2141,11 @@ storageVolDownload(virStorageVolPtr obj, goto cleanup; } - ret = backend->downloadVol(obj->conn, pool, vol, stream, + ret = backend->downloadVol(vol->conn, obj, voldef, stream, offset, length, flags); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } @@ -2215,7 +2218,7 @@ virStorageVolPoolRefreshThread(void *opaque) { virStorageVolStreamInfoPtr cbdata = opaque; - virStoragePoolObjPtr pool = NULL; + virStoragePoolObjPtr obj = NULL; virStorageBackendPtr backend; virObjectEventPtr event = NULL; @@ -2224,25 +2227,25 @@ virStorageVolPoolRefreshThread(void *opaque) if (virStorageBackendPloopRestoreDesc(cbdata->vol_path) < 0) goto cleanup; } - if (!(pool = virStoragePoolObjFindByName(&driver->pools, - cbdata->pool_name))) + if (!(obj = virStoragePoolObjFindByName(&driver->pools, + cbdata->pool_name))) goto cleanup; - if (!(backend = virStorageBackendForType(pool->def->type))) + if (!(backend = virStorageBackendForType(obj->def->type))) goto cleanup; - virStoragePoolObjClearVols(pool); - if (backend->refreshPool(NULL, pool) < 0) + virStoragePoolObjClearVols(obj); + if (backend->refreshPool(NULL, obj) < 0) VIR_DEBUG("Failed to refresh storage pool"); - event = virStoragePoolEventRefreshNew(pool->def->name, - pool->def->uuid); + event = virStoragePoolEventRefreshNew(obj->def->name, + obj->def->uuid); cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); virStorageVolPoolRefreshDataFree(cbdata); } @@ -2273,37 +2276,37 @@ virStorageVolFDStreamCloseCb(virStreamPtr st ATTRIBUTE_UNUSED, } static int -storageVolUpload(virStorageVolPtr obj, +storageVolUpload(virStorageVolPtr vol, virStreamPtr stream, unsigned long long offset, unsigned long long length, unsigned int flags) { virStorageBackendPtr backend; - virStoragePoolObjPtr pool = NULL; - virStorageVolDefPtr vol = NULL; + virStoragePoolObjPtr obj = NULL; + virStorageVolDefPtr voldef = NULL; virStorageVolStreamInfoPtr cbdata = NULL; int ret = -1; virCheckFlags(0, -1); - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolUploadEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolUploadEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - if (vol->in_use) { + if (voldef->in_use) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still in use."), - vol->name); + voldef->name); goto cleanup; } - if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; } @@ -2320,13 +2323,13 @@ storageVolUpload(virStorageVolPtr obj, * routine in order to call the refresh API. */ if (VIR_ALLOC(cbdata) < 0 || - VIR_STRDUP(cbdata->pool_name, pool->def->name) < 0) + VIR_STRDUP(cbdata->pool_name, obj->def->name) < 0) goto cleanup; - if (vol->type == VIR_STORAGE_VOL_PLOOP && - VIR_STRDUP(cbdata->vol_path, vol->target.path) < 0) + if (voldef->type == VIR_STORAGE_VOL_PLOOP && + VIR_STRDUP(cbdata->vol_path, voldef->target.path) < 0) goto cleanup; - if ((ret = backend->uploadVol(obj->conn, pool, vol, stream, + if ((ret = backend->uploadVol(vol->conn, obj, voldef, stream, offset, length, flags)) < 0) goto cleanup; @@ -2339,7 +2342,7 @@ storageVolUpload(virStorageVolPtr obj, cbdata = NULL; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); if (cbdata) virStorageVolPoolRefreshDataFree(cbdata); @@ -2347,13 +2350,13 @@ storageVolUpload(virStorageVolPtr obj, } static int -storageVolResize(virStorageVolPtr obj, +storageVolResize(virStorageVolPtr vol, unsigned long long capacity, unsigned int flags) { virStorageBackendPtr backend; - virStoragePoolObjPtr pool = NULL; - virStorageVolDefPtr vol = NULL; + virStoragePoolObjPtr obj = NULL; + virStorageVolDefPtr voldef = NULL; unsigned long long abs_capacity, delta = 0; int ret = -1; @@ -2361,44 +2364,44 @@ storageVolResize(virStorageVolPtr obj, VIR_STORAGE_VOL_RESIZE_DELTA | VIR_STORAGE_VOL_RESIZE_SHRINK, -1); - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolResizeEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolResizeEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - if (vol->in_use) { + if (voldef->in_use) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still in use."), - vol->name); + voldef->name); goto cleanup; } - if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; } if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) { if (flags & VIR_STORAGE_VOL_RESIZE_SHRINK) - abs_capacity = vol->target.capacity - MIN(capacity, vol->target.capacity); + abs_capacity = voldef->target.capacity - MIN(capacity, voldef->target.capacity); else - abs_capacity = vol->target.capacity + capacity; + abs_capacity = voldef->target.capacity + capacity; flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA; } else { abs_capacity = capacity; } - if (abs_capacity < vol->target.allocation) { + if (abs_capacity < voldef->target.allocation) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("can't shrink capacity below " "existing allocation")); goto cleanup; } - if (abs_capacity < vol->target.capacity && + if (abs_capacity < voldef->target.capacity && !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Can't shrink capacity below current " @@ -2407,9 +2410,9 @@ storageVolResize(virStorageVolPtr obj, } if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) - delta = abs_capacity - vol->target.allocation; + delta = abs_capacity - voldef->target.allocation; - if (delta > pool->def->available) { + if (delta > obj->def->available) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Not enough space left in storage pool")); goto cleanup; @@ -2422,37 +2425,37 @@ storageVolResize(virStorageVolPtr obj, goto cleanup; } - if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0) + if (backend->resizeVol(vol->conn, obj, voldef, abs_capacity, flags) < 0) goto cleanup; - vol->target.capacity = abs_capacity; + voldef->target.capacity = abs_capacity; /* Only update the allocation and pool values if we actually did the * allocation; otherwise, this is akin to a create operation with a * capacity value different and potentially much larger than available */ if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) { - vol->target.allocation = abs_capacity; - pool->def->allocation += delta; - pool->def->available -= delta; + voldef->target.allocation = abs_capacity; + obj->def->allocation += delta; + obj->def->available -= delta; } ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storageVolWipePattern(virStorageVolPtr obj, +storageVolWipePattern(virStorageVolPtr vol, unsigned int algorithm, unsigned int flags) { virStorageBackendPtr backend; - virStoragePoolObjPtr pool = NULL; - virStorageVolDefPtr vol = NULL; + virStoragePoolObjPtr obj = NULL; + virStorageVolDefPtr voldef = NULL; int ret = -1; virCheckFlags(0, -1); @@ -2464,24 +2467,23 @@ storageVolWipePattern(virStorageVolPtr obj, return -1; } - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - - if (virStorageVolWipePatternEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolWipePatternEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - if (vol->in_use) { + if (voldef->in_use) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still in use."), - vol->name); + voldef->name); goto cleanup; } - if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; } @@ -2491,120 +2493,120 @@ storageVolWipePattern(virStorageVolPtr obj, goto cleanup; } - if (backend->wipeVol(obj->conn, pool, vol, algorithm, flags) < 0) + if (backend->wipeVol(vol->conn, obj, voldef, algorithm, flags) < 0) goto cleanup; if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, vol) < 0) + backend->refreshVol(vol->conn, obj, voldef) < 0) goto cleanup; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storageVolWipe(virStorageVolPtr obj, +storageVolWipe(virStorageVolPtr vol, unsigned int flags) { - return storageVolWipePattern(obj, VIR_STORAGE_VOL_WIPE_ALG_ZERO, flags); + return storageVolWipePattern(vol, VIR_STORAGE_VOL_WIPE_ALG_ZERO, flags); } static int -storageVolGetInfoFlags(virStorageVolPtr obj, +storageVolGetInfoFlags(virStorageVolPtr vol, virStorageVolInfoPtr info, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; - virStorageVolDefPtr vol; + virStorageVolDefPtr voldef; int ret = -1; virCheckFlags(VIR_STORAGE_VOL_GET_PHYSICAL, -1); - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolGetInfoFlagsEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolGetInfoFlagsEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, vol) < 0) + backend->refreshVol(vol->conn, obj, voldef) < 0) goto cleanup; memset(info, 0, sizeof(*info)); - info->type = vol->type; - info->capacity = vol->target.capacity; + info->type = voldef->type; + info->capacity = voldef->target.capacity; if (flags & VIR_STORAGE_VOL_GET_PHYSICAL) - info->allocation = vol->target.physical; + info->allocation = voldef->target.physical; else - info->allocation = vol->target.allocation; + info->allocation = voldef->target.allocation; ret = 0; cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static int -storageVolGetInfo(virStorageVolPtr obj, +storageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) { - return storageVolGetInfoFlags(obj, info, 0); + return storageVolGetInfoFlags(vol, info, 0); } static char * -storageVolGetXMLDesc(virStorageVolPtr obj, +storageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; - virStorageVolDefPtr vol; + virStorageVolDefPtr voldef; char *ret = NULL; virCheckFlags(0, NULL); - if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return NULL; - if (virStorageVolGetXMLDescEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolGetXMLDescEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, vol) < 0) + backend->refreshVol(vol->conn, obj, voldef) < 0) goto cleanup; - ret = virStorageVolDefFormat(pool->def, vol); + ret = virStorageVolDefFormat(obj->def, voldef); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } static char * -storageVolGetPath(virStorageVolPtr obj) +storageVolGetPath(virStorageVolPtr vol) { - virStoragePoolObjPtr pool; - virStorageVolDefPtr vol; + virStoragePoolObjPtr obj; + virStorageVolDefPtr voldef; char *ret = NULL; - if (!(vol = virStorageVolDefFromVol(obj, &pool, NULL))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, NULL))) return NULL; - if (virStorageVolGetPathEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolGetPathEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup; - ignore_value(VIR_STRDUP(ret, vol->target.path)); + ignore_value(VIR_STRDUP(ret, voldef->target.path)); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; } @@ -3531,18 +3533,18 @@ virStorageTranslateDiskSourcePool(virConnectPtr conn, virStoragePoolObjPtr virStoragePoolObjFindPoolByUUID(const unsigned char *uuid) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; storageDriverLock(); - pool = virStoragePoolObjFindByUUID(&driver->pools, uuid); + obj = virStoragePoolObjFindByUUID(&driver->pools, uuid); storageDriverUnlock(); - return pool; + return obj; } /* * virStoragePoolObjBuildTempFilePath - * @pool: pool object pointer + * @obj: pool object pointer * @vol: volume definition * * Generate a name for a temporary file using the driver stateDir @@ -3552,13 +3554,13 @@ virStoragePoolObjFindPoolByUUID(const unsigned char *uuid) * Returns a string pointer on success, NULL on failure */ char * -virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) { char *tmp = NULL; ignore_value(virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX", - driver->stateDir, pool->def->name, vol->name)); + driver->stateDir, obj->def->name, voldef->name)); return tmp; } diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index 530bc33..67aaa82 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -65,8 +65,8 @@ storagePoolLookupByTargetPath(virConnectPtr conn, const char *path) ATTRIBUTE_NONNULL(2); -char *virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +char *virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; int storageRegister(void); -- 2.9.3

On Tue, May 09, 2017 at 11:30:15AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
Now that I'm thinking about it, this should be poolObj or poolobj, it would make it easier using git grep and also some functions takes more than one object. We should thought about it earlier, some of these patches are already pushed. Let's discuss it before pushing more of these patches. The rest is OK.
A virStoragePoolPtr will be a 'pool'.
A virStorageVolPtr will be a 'vol'.
A virStorageVolDefPtr will be a 'voldef'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 1158 +++++++++++++++++++++--------------------- src/storage/storage_driver.h | 4 +- 2 files changed, 582 insertions(+), 580 deletions(-)
Pavel

On 07/14/2017 09:53 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:15AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
Now that I'm thinking about it, this should be poolObj or poolobj, it would make it easier using git grep and also some functions takes more than one object. We should thought about it earlier, some of these patches are already pushed.
Consistently speaking for any of the drivers (nodedev, nwfilter, secret, interface, network, pool, volume, and domain) - I've been going with @obj whenever possible, but I do see value in @poolobj, @nodedevobj, @nwfilterobj, @secretobj, @interfaceobj, @networkobj, @vol[ume]obj, and @domainobj. But going through another round of changes to just change the name isn't something I'd look forward to. If you think back to my original series - everything was a @poolobj because my object was a PoolObj. Still to me an @obj within the specific driver/vir*obj.c source is the same. When there's more than one type of @obj, then @obj would be for the primary object while @XXXobj would be for the secondary object. Thus for storage pools an obj is a poolobj. Using git grep or cscope to find @obj and filtering further via the "src/storage" or "src/nodedevice", etc. shouldn't be that difficult. The caveat to all that is the storage pools also have volume objs, which I think you point out in the follow up I needed to be more consistent about. The general way I had those was @volobj. John
Let's discuss it before pushing more of these patches.
The rest is OK.
A virStoragePoolPtr will be a 'pool'.
A virStorageVolPtr will be a 'vol'.
A virStorageVolDefPtr will be a 'voldef'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 1158 +++++++++++++++++++++--------------------- src/storage/storage_driver.h | 4 +- 2 files changed, 582 insertions(+), 580 deletions(-)
Pavel

On Tue, May 09, 2017 at 11:30:15AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
A virStorageVolPtr will be a 'vol'.
A virStorageVolDefPtr will be a 'voldef'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 1158 +++++++++++++++++++++--------------------- src/storage/storage_driver.h | 4 +- 2 files changed, 582 insertions(+), 580 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 2103ed1..6122396 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -87,45 +87,45 @@ static void storageDriverUnlock(void) * pools are removed. */ static void -virStoragePoolUpdateInactive(virStoragePoolObjPtr *poolptr) +virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) { - virStoragePoolObjPtr pool = *poolptr; + virStoragePoolObjPtr obj = *objptr;
- if (pool->configFile == NULL) { - virStoragePoolObjRemove(&driver->pools, pool); - *poolptr = NULL; - } else if (pool->newDef) { - virStoragePoolDefFree(pool->def); - pool->def = pool->newDef; - pool->newDef = NULL; + if (obj->configFile == NULL) { + virStoragePoolObjRemove(&driver->pools, obj); + *objptr = NULL; + } else if (obj->newDef) { + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; } }
static void -storagePoolUpdateState(virStoragePoolObjPtr pool) +storagePoolUpdateState(virStoragePoolObjPtr obj) { bool active = false; virStorageBackendPtr backend; char *stateFile;
if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"))) + obj->def->name, ".xml"))) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) { + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing backend %d"), pool->def->type); + _("Missing backend %d"), obj->def->type); goto cleanup; }
/* Backends which do not support 'checkPool' are considered * inactive by default. */ if (backend->checkPool && - backend->checkPool(pool, &active) < 0) { + backend->checkPool(obj, &active) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to initialize storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); active = false; }
@@ -134,21 +134,21 @@ storagePoolUpdateState(virStoragePoolObjPtr pool) * continue with other pools. */ if (active) { - virStoragePoolObjClearVols(pool); - if (backend->refreshPool(NULL, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (backend->refreshPool(NULL, obj) < 0) { if (backend->stopPool) - backend->stopPool(NULL, pool); + backend->stopPool(NULL, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to restart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); active = false; } }
- pool->active = active; + obj->active = active;
- if (!pool->active) - virStoragePoolUpdateInactive(&pool); + if (!obj->active) + virStoragePoolUpdateInactive(&obj);
cleanup: if (!active && stateFile) @@ -164,11 +164,11 @@ storagePoolUpdateAllState(void) size_t i;
for (i = 0; i < driver->pools.count; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + virStoragePoolObjPtr obj = driver->pools.objs[i];
- virStoragePoolObjLock(pool); - storagePoolUpdateState(pool); - virStoragePoolObjUnlock(pool); + virStoragePoolObjLock(obj); + storagePoolUpdateState(obj); + virStoragePoolObjUnlock(obj); } }
@@ -186,24 +186,24 @@ storageDriverAutostart(void) /* Ignoring NULL conn - let backends decide */
for (i = 0; i < driver->pools.count; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + virStoragePoolObjPtr obj = driver->pools.objs[i]; virStorageBackendPtr backend; bool started = false;
- virStoragePoolObjLock(pool); - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) { - virStoragePoolObjUnlock(pool); + virStoragePoolObjLock(obj); + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { + virStoragePoolObjUnlock(obj); continue; }
- if (pool->autostart && - !virStoragePoolObjIsActive(pool)) { + if (obj->autostart && + !virStoragePoolObjIsActive(obj)) { if (backend->startPool && - backend->startPool(conn, pool) < 0) { + backend->startPool(conn, obj) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); - virStoragePoolObjUnlock(pool); + obj->def->name, virGetLastErrorMessage()); + virStoragePoolObjUnlock(obj); continue; } started = true; @@ -212,25 +212,25 @@ storageDriverAutostart(void) if (started) { char *stateFile;
- virStoragePoolObjClearVols(pool); + virStoragePoolObjClearVols(obj); stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml"); if (!stateFile || - virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(conn, pool) < 0) { + virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(conn, pool); + backend->stopPool(conn, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); + obj->def->name, virGetLastErrorMessage()); } else { - pool->active = true; + obj->active = true; } VIR_FREE(stateFile); } - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); }
virObjectUnref(conn); @@ -391,10 +391,10 @@ static virStoragePoolObjPtr storagePoolObjFindByUUID(const unsigned char *uuid, const char *name) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, uuid))) { + if (!(obj = virStoragePoolObjFindByUUID(&driver->pools, uuid))) { virUUIDFormat(uuid, uuidstr); if (name) virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -406,7 +406,7 @@ storagePoolObjFindByUUID(const unsigned char *uuid, uuidstr); }
- return pool; + return obj; }
@@ -426,15 +426,15 @@ virStoragePoolObjFromStoragePool(virStoragePoolPtr pool) static virStoragePoolObjPtr storagePoolObjFindByName(const char *name) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj;
storageDriverLock(); - if (!(pool = 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();
- return pool; + return obj; }
@@ -442,65 +442,63 @@ static virStoragePoolPtr storagePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL;
storageDriverLock(); - pool = storagePoolObjFindByUUID(uuid, NULL); + obj = storagePoolObjFindByUUID(uuid, NULL); storageDriverUnlock(); - if (!pool) + if (!obj) return NULL;
- if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0) + if (virStoragePoolLookupByUUIDEnsureACL(conn, obj->def) < 0) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; }
static virStoragePoolPtr storagePoolLookupByName(virConnectPtr conn, const char *name) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL;
- if (!(pool = storagePoolObjFindByName(name))) + if (!(obj = storagePoolObjFindByName(name))) return NULL;
- if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0) + if (virStoragePoolLookupByNameEnsureACL(conn, obj->def) < 0) goto cleanup;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; }
static virStoragePoolPtr storagePoolLookupByVolume(virStorageVolPtr vol) { - virStoragePoolObjPtr pool; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStoragePoolPtr pool = NULL;
- if (!(pool = storagePoolObjFindByName(vol->pool))) + if (!(obj = storagePoolObjFindByName(vol->pool))) return NULL;
- if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0) + if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, obj->def) < 0) goto cleanup;
- ret = virGetStoragePool(vol->conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(vol->conn, obj->def->name, obj->def->uuid, + NULL, NULL);
cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return pool; }
static int @@ -613,7 +611,8 @@ storageConnectFindStoragePoolSources(virConnectPtr conn, }
-static int storagePoolIsActive(virStoragePoolPtr pool) +static int +storagePoolIsActive(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; int ret = -1; @@ -631,7 +630,9 @@ static int storagePoolIsActive(virStoragePoolPtr pool) return ret; }
-static int storagePoolIsPersistent(virStoragePoolPtr pool) + +static int +storagePoolIsPersistent(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; int ret = -1; @@ -656,8 +657,8 @@ storagePoolCreateXML(virConnectPtr conn, unsigned int flags) { virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj = NULL; + virStoragePoolPtr pool = NULL; virStorageBackendPtr backend; virObjectEventPtr event = NULL; char *stateFile = NULL; @@ -686,7 +687,7 @@ storagePoolCreateXML(virConnectPtr conn, if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup;
- if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; def = NULL;
@@ -698,56 +699,55 @@ storagePoolCreateXML(virConnectPtr conn,
if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { - if (backend->buildPool(conn, pool, build_flags) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + if (backend->buildPool(conn, obj, build_flags) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; } } }
if (backend->startPool && - backend->startPool(conn, pool) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + backend->startPool(conn, obj) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; }
stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml");
- virStoragePoolObjClearVols(pool); - if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(conn, pool); - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + backend->stopPool(conn, obj); + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; goto cleanup; }
- event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0);
- VIR_INFO("Creating storage pool '%s'", pool->def->name); - pool->active = true; + VIR_INFO("Creating storage pool '%s'", obj->def->name); + obj->active = true;
- ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: VIR_FREE(stateFile); virStoragePoolDefFree(def); if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); - return ret; + return pool; }
static virStoragePoolPtr @@ -756,8 +756,8 @@ storagePoolDefineXML(virConnectPtr conn, unsigned int flags) { virStoragePoolDefPtr def; - virStoragePoolObjPtr pool = NULL; - virStoragePoolPtr ret = NULL; + virStoragePoolObjPtr obj = NULL; + virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL;
virCheckFlags(0, NULL); @@ -781,13 +781,13 @@ storagePoolDefineXML(virConnectPtr conn, if (virStorageBackendForType(def->type) == NULL) goto cleanup;
- if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def))) + if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup;
- if (virStoragePoolObjSaveDef(driver, pool, def) < 0) { - virStoragePoolObjRemove(&driver->pools, pool); + if (virStoragePoolObjSaveDef(driver, obj, def) < 0) { + virStoragePoolObjRemove(&driver->pools, obj); def = NULL; - pool = NULL; + obj = NULL; goto cleanup; }
@@ -797,86 +797,85 @@ storagePoolDefineXML(virConnectPtr conn,
def = NULL;
- VIR_INFO("Defining storage pool '%s'", pool->def->name); - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + VIR_INFO("Defining storage pool '%s'", obj->def->name); + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolDefFree(def); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); - return ret; + return pool; }
static int -storagePoolUndefine(virStoragePoolPtr obj) +storagePoolUndefine(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virObjectEventPtr event = NULL; int ret = -1;
storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup;
- if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolUndefineEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - pool->def->name); + obj->def->name); goto cleanup; }
- if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; }
- if (virStoragePoolObjDeleteDef(pool) < 0) + if (virStoragePoolObjDeleteDef(obj) < 0) goto cleanup;
- if (unlink(pool->autostartLink) < 0 && + if (unlink(obj->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { char ebuf[1024]; VIR_ERROR(_("Failed to delete autostart link '%s': %s"), - pool->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); + obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); }
- VIR_FREE(pool->configFile); - VIR_FREE(pool->autostartLink); + VIR_FREE(obj->configFile); + VIR_FREE(obj->autostartLink);
- event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, 0);
- VIR_INFO("Undefining storage pool '%s'", pool->def->name); - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + VIR_INFO("Undefining storage pool '%s'", obj->def->name); + virStoragePoolObjRemove(&driver->pools, obj); + obj = NULL; ret = 0;
cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; }
static int -storagePoolCreate(virStoragePoolPtr obj, +storagePoolCreate(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virObjectEventPtr event = NULL; int ret = -1; @@ -890,19 +889,19 @@ storagePoolCreate(virStoragePoolPtr obj, VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, -1);
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolCreateEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolCreateEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - pool->def->name); + obj->def->name); goto cleanup; }
@@ -914,117 +913,117 @@ storagePoolCreate(virStoragePoolPtr obj,
if (build_flags || (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) { - if (backend->buildPool(obj->conn, pool, build_flags) < 0) + if (backend->buildPool(pool->conn, obj, build_flags) < 0) goto cleanup; } }
- VIR_INFO("Starting up storage pool '%s'", pool->def->name); + VIR_INFO("Starting up storage pool '%s'", obj->def->name); if (backend->startPool && - backend->startPool(obj->conn, pool) < 0) + backend->startPool(pool->conn, obj) < 0) goto cleanup;
stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); + obj->def->name, ".xml");
- virStoragePoolObjClearVols(pool); - if (!stateFile || virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(obj->conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + backend->refreshPool(pool->conn, obj) < 0) { if (stateFile) unlink(stateFile); if (backend->stopPool) - backend->stopPool(obj->conn, pool); + backend->stopPool(pool->conn, obj); goto cleanup; }
- event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0);
- pool->active = true; + obj->active = true; ret = 0;
cleanup: VIR_FREE(stateFile); if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolBuild(virStoragePoolPtr obj, +storagePoolBuild(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; int ret = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolBuildEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolBuildEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - pool->def->name); + obj->def->name); goto cleanup; }
if (backend->buildPool && - backend->buildPool(obj->conn, pool, flags) < 0) + backend->buildPool(pool->conn, obj, flags) < 0) goto cleanup; ret = 0;
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolDestroy(virStoragePoolPtr obj) +storagePoolDestroy(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virObjectEventPtr event = NULL; char *stateFile = NULL; int ret = -1;
storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup;
- if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolDestroyEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- VIR_INFO("Destroying storage pool '%s'", pool->def->name); + VIR_INFO("Destroying storage pool '%s'", obj->def->name);
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; }
if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, + obj->def->name, ".xml"))) goto cleanup;
@@ -1032,67 +1031,67 @@ storagePoolDestroy(virStoragePoolPtr obj) VIR_FREE(stateFile);
if (backend->stopPool && - backend->stopPool(obj->conn, pool) < 0) + backend->stopPool(pool->conn, obj) < 0) goto cleanup;
- virStoragePoolObjClearVols(pool); + virStoragePoolObjClearVols(obj);
- event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0);
- pool->active = false; + obj->active = false;
- virStoragePoolUpdateInactive(&pool); + virStoragePoolUpdateInactive(&obj);
ret = 0;
cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; }
static int -storagePoolDelete(virStoragePoolPtr obj, +storagePoolDelete(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; char *stateFile = NULL; int ret = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolDeleteEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolDeleteEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- VIR_INFO("Deleting storage pool '%s'", pool->def->name); + VIR_INFO("Deleting storage pool '%s'", obj->def->name);
- if (virStoragePoolObjIsActive(pool)) { + if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - pool->def->name); + obj->def->name); goto cleanup; }
- if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; }
if (!(stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, + obj->def->name, ".xml"))) goto cleanup;
@@ -1104,22 +1103,22 @@ storagePoolDelete(virStoragePoolPtr obj, "%s", _("pool does not support pool deletion")); goto cleanup; } - if (backend->deletePool(obj->conn, pool, flags) < 0) + if (backend->deletePool(pool->conn, obj, flags) < 0) goto cleanup;
ret = 0;
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolRefresh(virStoragePoolPtr obj, +storagePoolRefresh(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; int ret = -1; virObjectEventPtr event = NULL; @@ -1127,165 +1126,165 @@ storagePoolRefresh(virStoragePoolPtr obj, virCheckFlags(0, -1);
storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup;
- if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolRefreshEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- if (pool->asyncjobs > 0) { + if (obj->asyncjobs > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - pool->def->name); + obj->def->name); goto cleanup; }
- virStoragePoolObjClearVols(pool); - if (backend->refreshPool(obj->conn, pool) < 0) { + virStoragePoolObjClearVols(obj); + if (backend->refreshPool(pool->conn, obj) < 0) { if (backend->stopPool) - backend->stopPool(obj->conn, pool); + backend->stopPool(pool->conn, obj);
- event = virStoragePoolEventLifecycleNew(pool->def->name, - pool->def->uuid, + event = virStoragePoolEventLifecycleNew(obj->def->name, + obj->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - pool->active = false; + obj->active = false;
- virStoragePoolUpdateInactive(&pool); + virStoragePoolUpdateInactive(&obj);
goto cleanup; }
- event = virStoragePoolEventRefreshNew(pool->def->name, - pool->def->uuid); + event = virStoragePoolEventRefreshNew(obj->def->name, + obj->def->uuid); ret = 0;
cleanup: if (event) virObjectEventStateQueue(driver->storageEventState, event); - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; }
static int -storagePoolGetInfo(virStoragePoolPtr obj, +storagePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolGetInfoEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetInfoEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (virStorageBackendForType(pool->def->type) == NULL) + if (virStorageBackendForType(obj->def->type) == NULL) goto cleanup;
memset(info, 0, sizeof(virStoragePoolInfo)); - if (pool->active) + if (obj->active) info->state = VIR_STORAGE_POOL_RUNNING; else info->state = VIR_STORAGE_POOL_INACTIVE; - info->capacity = pool->def->capacity; - info->allocation = pool->def->allocation; - info->available = pool->def->available; + info->capacity = obj->def->capacity; + info->allocation = obj->def->allocation; + info->available = obj->def->available; ret = 0;
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static char * -storagePoolGetXMLDesc(virStoragePoolPtr obj, +storagePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStoragePoolDefPtr def; char *ret = NULL;
virCheckFlags(VIR_STORAGE_XML_INACTIVE, NULL);
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL;
- if (virStoragePoolGetXMLDescEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetXMLDescEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if ((flags & VIR_STORAGE_XML_INACTIVE) && pool->newDef) - def = pool->newDef; + if ((flags & VIR_STORAGE_XML_INACTIVE) && obj->newDef) + def = obj->newDef; else - def = pool->def; + def = obj->def;
ret = virStoragePoolDefFormat(def);
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolGetAutostart(virStoragePoolPtr obj, +storagePoolGetAutostart(virStoragePoolPtr pool, int *autostart) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolGetAutostartEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!pool->configFile) { + if (!obj->configFile) { *autostart = 0; } else { - *autostart = pool->autostart; + *autostart = obj->autostart; } + ret = 0;
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolSetAutostart(virStoragePoolPtr obj, +storagePoolSetAutostart(virStoragePoolPtr pool, int autostart) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1;
storageDriverLock(); - if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name))) + if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup;
- if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!pool->configFile) { + if (!obj->configFile) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("pool has no config file")); - goto cleanup; }
autostart = (autostart != 0);
- if (pool->autostart != autostart) { + if (obj->autostart != autostart) { if (autostart) { if (virFileMakePath(driver->autostartDir) < 0) { virReportSystemError(errno, @@ -1294,85 +1293,86 @@ storagePoolSetAutostart(virStoragePoolPtr obj, goto cleanup; }
- if (symlink(pool->configFile, pool->autostartLink) < 0) { + if (symlink(obj->configFile, obj->autostartLink) < 0) { virReportSystemError(errno, _("Failed to create symlink '%s' to '%s'"), - pool->autostartLink, pool->configFile); + obj->autostartLink, obj->configFile); goto cleanup; } } else { - if (unlink(pool->autostartLink) < 0 && + if (unlink(obj->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) { virReportSystemError(errno, _("Failed to delete symlink '%s'"), - pool->autostartLink); + obj->autostartLink); goto cleanup; } } - pool->autostart = autostart; + obj->autostart = autostart; } + ret = 0;
cleanup: - if (pool) - virStoragePoolObjUnlock(pool); + if (obj) + virStoragePoolObjUnlock(obj); storageDriverUnlock(); return ret; }
static int -storagePoolNumOfVolumes(virStoragePoolPtr obj) +storagePoolNumOfVolumes(virStoragePoolPtr pool) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int ret = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolNumOfVolumesEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolNumOfVolumesEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- ret = virStoragePoolObjNumOfVolumes(&pool->volumes, obj->conn, pool->def, + ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, obj->def, virStoragePoolNumOfVolumesCheckACL);
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static int -storagePoolListVolumes(virStoragePoolPtr obj, +storagePoolListVolumes(virStoragePoolPtr pool, char **const names, int maxnames) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; int n = -1;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1;
- if (virStoragePoolListVolumesEnsureACL(obj->conn, pool->def) < 0) + if (virStoragePoolListVolumesEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- n = virStoragePoolObjVolumeGetNames(&pool->volumes, obj->conn, pool->def, + n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, obj->def, virStoragePoolListVolumesCheckACL, names, maxnames); cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return n; }
@@ -1411,40 +1411,40 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, }
static virStorageVolPtr -storageVolLookupByName(virStoragePoolPtr obj, +storageVolLookupByName(virStoragePoolPtr pool, const char *name) { - virStoragePoolObjPtr pool; - virStorageVolDefPtr vol; - virStorageVolPtr ret = NULL; + virStoragePoolObjPtr obj; + virStorageVolDefPtr voldef; + virStorageVolPtr vol = NULL;
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- vol = virStorageVolDefFindByName(pool, name); + voldef = virStorageVolDefFindByName(obj, name);
- if (!vol) { + if (!voldef) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), name); goto cleanup; }
- if (virStorageVolLookupByNameEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolLookupByNameEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup;
- ret = virGetStorageVol(obj->conn, pool->def->name, vol->name, vol->key, - NULL, NULL); + vol = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + voldef->key, NULL, NULL);
cleanup: - virStoragePoolObjUnlock(pool); - return ret; + virStoragePoolObjUnlock(obj); + return vol; }
@@ -1453,39 +1453,39 @@ storageVolLookupByKey(virConnectPtr conn, const char *key) { size_t i; - virStorageVolPtr ret = NULL; + virStorageVolPtr vol = NULL;
storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { + for (i = 0; i < driver->pools.count && !vol; i++) { virStoragePoolObjLock(driver->pools.objs[i]); if (virStoragePoolObjIsActive(driver->pools.objs[i])) { - virStorageVolDefPtr vol = + virStorageVolDefPtr voldef = virStorageVolDefFindByKey(driver->pools.objs[i], key);
- if (vol) { + if (voldef) { virStoragePoolDefPtr def = driver->pools.objs[i]->def; - if (virStorageVolLookupByKeyEnsureACL(conn, def, vol) < 0) { + if (virStorageVolLookupByKeyEnsureACL(conn, def, voldef) < 0) { virStoragePoolObjUnlock(driver->pools.objs[i]); goto cleanup; }
- ret = virGetStorageVol(conn, + vol = virGetStorageVol(conn, def->name, - vol->name, - vol->key, + voldef->name, + voldef->key, NULL, NULL); } } virStoragePoolObjUnlock(driver->pools.objs[i]); }
- if (!ret) + if (!vol) virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching key %s"), key);
cleanup: storageDriverUnlock(); - return ret; + return vol; }
static virStorageVolPtr @@ -1493,7 +1493,7 @@ storageVolLookupByPath(virConnectPtr conn, const char *path) { size_t i; - virStorageVolPtr ret = NULL; + virStorageVolPtr vol = NULL; char *cleanpath;
cleanpath = virFileSanitizePath(path); @@ -1501,19 +1501,19 @@ storageVolLookupByPath(virConnectPtr conn, return NULL;
storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; - virStorageVolDefPtr vol; + for (i = 0; i < driver->pools.count && !vol; i++) { + virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStorageVolDefPtr voldef; char *stable_path = NULL;
- virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj);
- if (!virStoragePoolObjIsActive(pool)) { - virStoragePoolObjUnlock(pool); + if (!virStoragePoolObjIsActive(obj)) { + virStoragePoolObjUnlock(obj); continue; }
- switch ((virStoragePoolType) pool->def->type) { + switch ((virStoragePoolType) obj->def->type) { case VIR_STORAGE_POOL_DIR: case VIR_STORAGE_POOL_FS: case VIR_STORAGE_POOL_NETFS: @@ -1523,7 +1523,7 @@ storageVolLookupByPath(virConnectPtr conn, case VIR_STORAGE_POOL_SCSI: case VIR_STORAGE_POOL_MPATH: case VIR_STORAGE_POOL_VSTORAGE: - stable_path = virStorageBackendStablePath(pool, + stable_path = virStorageBackendStablePath(obj, cleanpath, false); if (stable_path == NULL) { @@ -1531,8 +1531,8 @@ storageVolLookupByPath(virConnectPtr conn, * getting the stable path for some of the pools. */ VIR_WARN("Failed to get stable path for pool '%s'", - pool->def->name); - virStoragePoolObjUnlock(pool); + obj->def->name); + virStoragePoolObjUnlock(obj); continue; } break; @@ -1543,30 +1543,30 @@ storageVolLookupByPath(virConnectPtr conn, case VIR_STORAGE_POOL_ZFS: case VIR_STORAGE_POOL_LAST: if (VIR_STRDUP(stable_path, path) < 0) { - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); goto cleanup; } break; }
- vol = virStorageVolDefFindByPath(pool, stable_path); + voldef = virStorageVolDefFindByPath(obj, stable_path); VIR_FREE(stable_path);
- if (vol) { - if (virStorageVolLookupByPathEnsureACL(conn, pool->def, vol) < 0) { - virStoragePoolObjUnlock(pool); + if (voldef) { + if (virStorageVolLookupByPathEnsureACL(conn, obj->def, voldef) < 0) { + virStoragePoolObjUnlock(obj); goto cleanup; }
- ret = virGetStorageVol(conn, pool->def->name, - vol->name, vol->key, + vol = virGetStorageVol(conn, obj->def->name, + voldef->name, voldef->key, NULL, NULL); }
- virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); }
- if (!ret) { + if (!vol) { if (STREQ(path, cleanpath)) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching path '%s'"), path); @@ -1580,7 +1580,7 @@ storageVolLookupByPath(virConnectPtr conn, cleanup: VIR_FREE(cleanpath); storageDriverUnlock(); - return ret; + return vol; }
virStoragePoolPtr @@ -1588,7 +1588,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, const char *path) { size_t i; - virStoragePoolPtr ret = NULL; + virStoragePoolPtr pool = NULL; char *cleanpath;
cleanpath = virFileSanitizePath(path); @@ -1596,49 +1596,49 @@ storagePoolLookupByTargetPath(virConnectPtr conn, return NULL;
storageDriverLock(); - for (i = 0; i < driver->pools.count && !ret; i++) { - virStoragePoolObjPtr pool = driver->pools.objs[i]; + for (i = 0; i < driver->pools.count && !pool; i++) { + virStoragePoolObjPtr obj = driver->pools.objs[i];
- virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj);
- if (!virStoragePoolObjIsActive(pool)) { - virStoragePoolObjUnlock(pool); + if (!virStoragePoolObjIsActive(obj)) { + virStoragePoolObjUnlock(obj); continue; }
- if (STREQ(path, pool->def->target.path)) { - ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, - NULL, NULL); + if (STREQ(path, obj->def->target.path)) { + pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, + NULL, NULL); }
- virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); } storageDriverUnlock();
- if (!ret) { + if (!pool) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage pool with matching target path '%s'"), path); }
VIR_FREE(cleanpath); - return ret; + return pool; }
static void -storageVolRemoveFromPool(virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +storageVolRemoveFromPool(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) { size_t i;
- for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i] == vol) { + for (i = 0; i < obj->volumes.count; i++) { + if (obj->volumes.objs[i] == voldef) { VIR_INFO("Deleting volume '%s' from storage pool '%s'", - vol->name, pool->def->name); - virStorageVolDefFree(vol); + voldef->name, obj->def->name); + virStorageVolDefFree(voldef);
- VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count); + VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); break; } } @@ -1646,10 +1646,10 @@ storageVolRemoveFromPool(virStoragePoolObjPtr pool,
static int -storageVolDeleteInternal(virStorageVolPtr obj, +storageVolDeleteInternal(virStorageVolPtr vol, virStorageBackendPtr backend, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol, + virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef, unsigned int flags, bool updateMeta) { @@ -1662,7 +1662,7 @@ storageVolDeleteInternal(virStorageVolPtr obj, goto cleanup; }
- if (backend->deleteVol(obj->conn, pool, vol, flags) < 0) + if (backend->deleteVol(vol->conn, obj, voldef, flags) < 0) goto cleanup;
/* Update pool metadata - don't update meta data from error paths @@ -1670,13 +1670,13 @@ storageVolDeleteInternal(virStorageVolPtr obj, * Ignore the disk backend since it updates the pool values. */ if (updateMeta) { - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation -= vol->target.allocation; - pool->def->available += vol->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation -= voldef->target.allocation; + obj->def->available += voldef->target.allocation; } }
- storageVolRemoveFromPool(pool, vol); + storageVolRemoveFromPool(obj, voldef); ret = 0;
cleanup: @@ -1685,109 +1685,109 @@ storageVolDeleteInternal(virStorageVolPtr obj,
static virStorageVolDefPtr -virStorageVolDefFromVol(virStorageVolPtr obj, - virStoragePoolObjPtr *pool, +virStorageVolDefFromVol(virStorageVolPtr vol, + virStoragePoolObjPtr *obj, virStorageBackendPtr *backend) { - virStorageVolDefPtr vol = NULL; + virStorageVolDefPtr voldef = NULL;
- if (!(*pool = storagePoolObjFindByName(obj->pool))) + if (!(*obj = storagePoolObjFindByName(vol->pool))) return NULL;
- if (!virStoragePoolObjIsActive(*pool)) { + if (!virStoragePoolObjIsActive(*obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), - (*pool)->def->name); + (*obj)->def->name); goto error; }
- if (!(vol = virStorageVolDefFindByName(*pool, obj->name))) { + if (!(voldef = virStorageVolDefFindByName(*obj, vol->name))) { virReportError(VIR_ERR_NO_STORAGE_VOL, _("no storage vol with matching name '%s'"), - obj->name); + vol->name); goto error; }
if (backend) { - if (!(*backend = virStorageBackendForType((*pool)->def->type))) + if (!(*backend = virStorageBackendForType((*obj)->def->type))) goto error; }
- return vol; + return voldef;
error: - virStoragePoolObjUnlock(*pool); - *pool = NULL; + virStoragePoolObjUnlock(*obj); + *obj = NULL;
return NULL; }
static int -storageVolDelete(virStorageVolPtr obj, +storageVolDelete(virStorageVolPtr vol, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; - virStorageVolDefPtr vol = NULL; + virStorageVolDefPtr voldef = NULL; int ret = -1;
- if (!(vol = virStorageVolDefFromVol(obj, &pool, &backend))) + if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1;
- if (virStorageVolDeleteEnsureACL(obj->conn, pool->def, vol) < 0) + if (virStorageVolDeleteEnsureACL(vol->conn, obj->def, voldef) < 0) goto cleanup;
- if (vol->in_use) { + if (voldef->in_use) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still in use."), - vol->name); + voldef->name); goto cleanup; }
- if (vol->building) { + if (voldef->building) { virReportError(VIR_ERR_OPERATION_INVALID, _("volume '%s' is still being allocated."), - vol->name); + voldef->name); goto cleanup; }
- if (storageVolDeleteInternal(obj, backend, pool, vol, flags, true) < 0) + if (storageVolDeleteInternal(vol, backend, obj, voldef, flags, true) < 0) goto cleanup;
ret = 0;
cleanup: - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj); return ret; }
static virStorageVolPtr -storageVolCreateXML(virStoragePoolPtr obj, +storageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolPtr vol = NULL, volobj = NULL;
The @volobj should be also renamed, I would rename it like this: @ret -> @vol @volobj -> @newvol and ...
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- voldef = virStorageVolDefParseString(pool->def, xmldesc, + voldef = virStorageVolDefParseString(obj->def, xmldesc, VIR_VOL_XML_PARSE_OPT_CAPACITY); if (voldef == NULL) goto cleanup; @@ -1799,10 +1799,10 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; }
- if (virStorageVolCreateXMLEnsureACL(obj->conn, pool->def, voldef) < 0) + if (virStorageVolCreateXMLEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup;
- if (virStorageVolDefFindByName(pool, voldef->name)) { + if (virStorageVolDefFindByName(obj, voldef->name)) { virReportError(VIR_ERR_STORAGE_VOL_EXIST, _("'%s'"), voldef->name); goto cleanup; @@ -1815,21 +1815,21 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; }
- if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) + if (VIR_REALLOC_N(obj->volumes.objs, + obj->volumes.count + 1) < 0) goto cleanup;
/* Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(voldef->key); - if (backend->createVol(obj->conn, pool, voldef) < 0) + if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup;
- pool->volumes.objs[pool->volumes.count++] = voldef; - volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name, + obj->volumes.objs[obj->volumes.count++] = voldef; + volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, voldef->key, NULL, NULL); if (!volobj) { - pool->volumes.count--; + obj->volumes.count--; goto cleanup; }
@@ -1850,24 +1850,24 @@ storageVolCreateXML(virStoragePoolPtr obj, memcpy(buildvoldef, voldef, sizeof(*voldef));
/* Drop the pool lock during volume allocation */ - pool->asyncjobs++; + obj->asyncjobs++; voldef->building = true; - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj);
- buildret = backend->buildVol(obj->conn, pool, buildvoldef, flags); + buildret = backend->buildVol(pool->conn, obj, buildvoldef, flags);
VIR_FREE(buildvoldef);
storageDriverLock(); - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); storageDriverUnlock();
voldef->building = false; - pool->asyncjobs--; + obj->asyncjobs--;
if (buildret < 0) { /* buildVol handles deleting volume on failure */ - storageVolRemoveFromPool(pool, voldef); + storageVolRemoveFromPool(obj, voldef); voldef = NULL; goto cleanup; } @@ -1875,8 +1875,8 @@ storageVolCreateXML(virStoragePoolPtr obj, }
if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, voldef) < 0) { - storageVolDeleteInternal(volobj, backend, pool, voldef, + backend->refreshVol(pool->conn, obj, voldef) < 0) { + storageVolDeleteInternal(volobj, backend, obj, voldef, 0, false); voldef = NULL; goto cleanup; @@ -1885,35 +1885,39 @@ storageVolCreateXML(virStoragePoolPtr obj, /* Update pool metadata ignoring the disk backend since * it updates the pool values. */ - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += voldef->target.allocation; - pool->def->available -= voldef->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation += voldef->target.allocation; + obj->def->available -= voldef->target.allocation; }
VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, pool->def->name); - ret = volobj; + volobj->name, obj->def->name); + vol = volobj; volobj = NULL; voldef = NULL;
cleanup: virObjectUnref(volobj); virStorageVolDefFree(voldef); - if (pool) - virStoragePoolObjUnlock(pool); - return ret; + if (obj) + virStoragePoolObjUnlock(obj); + return vol; }
static virStorageVolPtr -storageVolCreateXMLFrom(virStoragePoolPtr obj, +storageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, - virStorageVolPtr vobj, + virStorageVolPtr volsrc, unsigned int flags) { - virStoragePoolObjPtr pool, origpool = NULL; + virStoragePoolObjPtr obj; + virStoragePoolObjPtr objsrc = NULL; virStorageBackendPtr backend; - virStorageVolDefPtr origvol = NULL, newvol = NULL, shadowvol = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolDefPtr voldefsrc = NULL; + virStorageVolDefPtr voldef = NULL; + virStorageVolDefPtr shadowvol = NULL; + virStorageVolPtr volobj = NULL; + virStorageVolPtr vol = NULL;
... same here. Pavel

On 07/14/2017 11:07 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:15AM -0400, John Ferlan wrote:
A virStoragePoolObjPtr will be an 'obj'.
A virStoragePoolPtr will be a 'pool'.
A virStorageVolPtr will be a 'vol'.
A virStorageVolDefPtr will be a 'voldef'.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 1158 +++++++++++++++++++++--------------------- src/storage/storage_driver.h | 4 +- 2 files changed, 582 insertions(+), 580 deletions(-)
I have had some more time to think about the other comment regarding whether @obj should be @poolObj or @poolobj... If some day in the future (as noted in the patch 7 response) the @pools changes to @poolobjs it'll be eye test in order to spot the difference between @poolobj and @poolobjs, so I'd like to keep it as @obj. Long time ago I had the sheer joy of trying to search code for 'l' and '1' as well as 'O' and '0'
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 2103ed1..6122396 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c
[...] lots to cut to first comment I saw [...]
static virStorageVolPtr -storageVolCreateXML(virStoragePoolPtr obj, +storageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, unsigned int flags) { - virStoragePoolObjPtr pool; + virStoragePoolObjPtr obj; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolPtr vol = NULL, volobj = NULL;
The @volobj should be also renamed, I would rename it like this:
@ret -> @vol @volobj -> @newvol
and ...
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
- if (!(pool = virStoragePoolObjFromStoragePool(obj))) + if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL;
- if (!virStoragePoolObjIsActive(pool)) { + if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), pool->def->name); + _("storage pool '%s' is not active"), obj->def->name); goto cleanup; }
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + if ((backend = virStorageBackendForType(obj->def->type)) == NULL) goto cleanup;
- voldef = virStorageVolDefParseString(pool->def, xmldesc, + voldef = virStorageVolDefParseString(obj->def, xmldesc, VIR_VOL_XML_PARSE_OPT_CAPACITY); if (voldef == NULL) goto cleanup; @@ -1799,10 +1799,10 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; }
- if (virStorageVolCreateXMLEnsureACL(obj->conn, pool->def, voldef) < 0) + if (virStorageVolCreateXMLEnsureACL(pool->conn, obj->def, voldef) < 0) goto cleanup;
- if (virStorageVolDefFindByName(pool, voldef->name)) { + if (virStorageVolDefFindByName(obj, voldef->name)) { virReportError(VIR_ERR_STORAGE_VOL_EXIST, _("'%s'"), voldef->name); goto cleanup; @@ -1815,21 +1815,21 @@ storageVolCreateXML(virStoragePoolPtr obj, goto cleanup; }
- if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) + if (VIR_REALLOC_N(obj->volumes.objs, + obj->volumes.count + 1) < 0) goto cleanup;
/* Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(voldef->key); - if (backend->createVol(obj->conn, pool, voldef) < 0) + if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup;
- pool->volumes.objs[pool->volumes.count++] = voldef; - volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name, + obj->volumes.objs[obj->volumes.count++] = voldef; + volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, voldef->key, NULL, NULL); if (!volobj) { - pool->volumes.count--; + obj->volumes.count--; goto cleanup; }
@@ -1850,24 +1850,24 @@ storageVolCreateXML(virStoragePoolPtr obj, memcpy(buildvoldef, voldef, sizeof(*voldef));
/* Drop the pool lock during volume allocation */ - pool->asyncjobs++; + obj->asyncjobs++; voldef->building = true; - virStoragePoolObjUnlock(pool); + virStoragePoolObjUnlock(obj);
- buildret = backend->buildVol(obj->conn, pool, buildvoldef, flags); + buildret = backend->buildVol(pool->conn, obj, buildvoldef, flags);
VIR_FREE(buildvoldef);
storageDriverLock(); - virStoragePoolObjLock(pool); + virStoragePoolObjLock(obj); storageDriverUnlock();
voldef->building = false; - pool->asyncjobs--; + obj->asyncjobs--;
if (buildret < 0) { /* buildVol handles deleting volume on failure */ - storageVolRemoveFromPool(pool, voldef); + storageVolRemoveFromPool(obj, voldef); voldef = NULL; goto cleanup; } @@ -1875,8 +1875,8 @@ storageVolCreateXML(virStoragePoolPtr obj, }
if (backend->refreshVol && - backend->refreshVol(obj->conn, pool, voldef) < 0) { - storageVolDeleteInternal(volobj, backend, pool, voldef, + backend->refreshVol(pool->conn, obj, voldef) < 0) { + storageVolDeleteInternal(volobj, backend, obj, voldef, 0, false); voldef = NULL; goto cleanup; @@ -1885,35 +1885,39 @@ storageVolCreateXML(virStoragePoolPtr obj, /* Update pool metadata ignoring the disk backend since * it updates the pool values. */ - if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += voldef->target.allocation; - pool->def->available -= voldef->target.allocation; + if (obj->def->type != VIR_STORAGE_POOL_DISK) { + obj->def->allocation += voldef->target.allocation; + obj->def->available -= voldef->target.allocation; }
VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, pool->def->name); - ret = volobj; + volobj->name, obj->def->name); + vol = volobj; volobj = NULL; voldef = NULL;
cleanup: virObjectUnref(volobj); virStorageVolDefFree(voldef); - if (pool) - virStoragePoolObjUnlock(pool); - return ret; + if (obj) + virStoragePoolObjUnlock(obj); + return vol; }
static virStorageVolPtr -storageVolCreateXMLFrom(virStoragePoolPtr obj, +storageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, - virStorageVolPtr vobj, + virStorageVolPtr volsrc, unsigned int flags) { - virStoragePoolObjPtr pool, origpool = NULL; + virStoragePoolObjPtr obj; + virStoragePoolObjPtr objsrc = NULL; virStorageBackendPtr backend; - virStorageVolDefPtr origvol = NULL, newvol = NULL, shadowvol = NULL; - virStorageVolPtr ret = NULL, volobj = NULL; + virStorageVolDefPtr voldefsrc = NULL; + virStorageVolDefPtr voldef = NULL; + virStorageVolDefPtr shadowvol = NULL; + virStorageVolPtr volobj = NULL; + virStorageVolPtr vol = NULL;
... same here.
Pavel
Works for me - consider it done. John

Alter the virStoragePoolObjNumOfVolumes, virStoragePoolObjVolumeGetNames, and virStoragePoolObjVolumeListExport APIs to take a virStoragePoolObjPtr instead of the &obj->volumes and obj->def. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 15 +++++++++------ src/conf/virstorageobj.h | 9 +++------ src/storage/storage_driver.c | 7 +++---- src/test/test_driver.c | 9 +++------ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 74a9c67..23346f3 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -196,11 +196,12 @@ virStorageVolDefFindByName(virStoragePoolObjPtr obj, int -virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, +virStoragePoolObjNumOfVolumes(virStoragePoolObjPtr obj, virConnectPtr conn, - virStoragePoolDefPtr pooldef, virStoragePoolVolumeACLFilter aclfilter) { + virStoragePoolDefPtr pooldef = obj->def; + virStorageVolDefListPtr volumes = &obj->volumes; int nvolumes = 0; size_t i; @@ -216,13 +217,14 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, int -virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes, +virStoragePoolObjVolumeGetNames(virStoragePoolObjPtr obj, virConnectPtr conn, - virStoragePoolDefPtr pooldef, virStoragePoolVolumeACLFilter aclfilter, char **const names, int maxnames) { + virStoragePoolDefPtr pooldef = obj->def; + virStorageVolDefListPtr volumes = &obj->volumes; int nnames = 0; size_t i; @@ -247,11 +249,12 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes, int virStoragePoolObjVolumeListExport(virConnectPtr conn, - virStorageVolDefListPtr volumes, - virStoragePoolDefPtr pooldef, + virStoragePoolObjPtr obj, virStorageVolPtr **vols, virStoragePoolVolumeACLFilter aclfilter) { + virStoragePoolDefPtr pooldef = obj->def; + virStorageVolDefListPtr volumes = &obj->volumes; int ret = -1; size_t i; virStorageVolPtr *tmp_vols = NULL; diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 494b888..5a61b2a 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -114,23 +114,20 @@ typedef bool virStorageVolDefPtr def); int -virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, +virStoragePoolObjNumOfVolumes(virStoragePoolObjPtr obj, virConnectPtr conn, - virStoragePoolDefPtr pooldef, virStoragePoolVolumeACLFilter aclfilter); int -virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes, +virStoragePoolObjVolumeGetNames(virStoragePoolObjPtr obj, virConnectPtr conn, - virStoragePoolDefPtr pooldef, virStoragePoolVolumeACLFilter aclfilter, char **const names, int maxnames); int virStoragePoolObjVolumeListExport(virConnectPtr conn, - virStorageVolDefListPtr volumes, - virStoragePoolDefPtr pooldef, + virStoragePoolObjPtr obj, virStorageVolPtr **vols, virStoragePoolVolumeACLFilter aclfilter); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6122396..6289314 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1339,7 +1339,7 @@ storagePoolNumOfVolumes(virStoragePoolPtr pool) goto cleanup; } - ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, obj->def, + ret = virStoragePoolObjNumOfVolumes(obj, pool->conn, virStoragePoolNumOfVolumesCheckACL); cleanup: @@ -1368,7 +1368,7 @@ storagePoolListVolumes(virStoragePoolPtr pool, goto cleanup; } - n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, obj->def, + n = virStoragePoolObjVolumeGetNames(obj, pool->conn, virStoragePoolListVolumesCheckACL, names, maxnames); cleanup: @@ -1399,8 +1399,7 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, goto cleanup; } - ret = virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes, - obj->def, vols, + ret = virStoragePoolObjVolumeListExport(pool->conn, obj, vols, virStoragePoolListAllVolumesCheckACL); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8d03bdb..68f1412 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4738,8 +4738,7 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return -1; - ret = virStoragePoolObjNumOfVolumes(&obj->volumes, pool->conn, - obj->def, NULL); + ret = virStoragePoolObjNumOfVolumes(obj, pool->conn, NULL); virStoragePoolObjUnlock(obj); return ret; @@ -4758,8 +4757,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return -1; - n = virStoragePoolObjVolumeGetNames(&obj->volumes, pool->conn, - obj->def, NULL, names, maxnames); + n = virStoragePoolObjVolumeGetNames(obj, pool->conn, NULL, names, maxnames); virStoragePoolObjUnlock(obj); return n; @@ -4786,8 +4784,7 @@ testStoragePoolListAllVolumes(virStoragePoolPtr pool, goto cleanup; } - ret = virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes, - obj->def, vols, NULL); + ret = virStoragePoolObjVolumeListExport(pool->conn, obj, vols, NULL); cleanup: virStoragePoolObjUnlock(obj); -- 2.9.3

On Tue, May 09, 2017 at 11:30:16AM -0400, John Ferlan wrote:
Alter the virStoragePoolObjNumOfVolumes, virStoragePoolObjVolumeGetNames, and virStoragePoolObjVolumeListExport APIs to take a virStoragePoolObjPtr instead of the &obj->volumes and obj->def.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 15 +++++++++------ src/conf/virstorageobj.h | 9 +++------ src/storage/storage_driver.c | 7 +++---- src/test/test_driver.c | 9 +++------ 4 files changed, 18 insertions(+), 22 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

In preparation for making a private object, create accessor API's for consumer storage functions to use: virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 23346f3..7d6b311 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,80 @@ VIR_LOG_INIT("conf.virstorageobj"); +virStoragePoolDefPtr +virStoragePoolObjGetDef(virStoragePoolObjPtr obj) +{ + return obj->def; +} + + +virStoragePoolDefPtr +virStoragePoolObjGetNewDef(virStoragePoolObjPtr obj) +{ + return obj->newDef; +} + + +void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj) +{ + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; +} + + +char * +virStoragePoolObjGetConfigFile(virStoragePoolObjPtr obj) +{ + return obj->configFile; +} + + +void +virStoragePoolObjSetConfigFile(virStoragePoolObjPtr obj, + char *configFile) +{ + obj->configFile = configFile; +} + + +bool +virStoragePoolObjIsActive(virStoragePoolObjPtr obj) +{ + return obj->active; +} + + +void +virStoragePoolObjSetActive(virStoragePoolObjPtr obj, + bool active) +{ + obj->active = active; +} + + +unsigned int +virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj) +{ + return obj->asyncjobs; +} + + +void +virStoragePoolObjIncrAsyncjobs(virStoragePoolObjPtr obj) +{ + obj->asyncjobs++; +} + + +void +virStoragePoolObjDecrAsyncjobs(virStoragePoolObjPtr obj) +{ + obj->asyncjobs--; +} + + void virStoragePoolObjFree(virStoragePoolObjPtr obj) { diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 5a61b2a..d47b233 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -70,11 +70,37 @@ typedef bool (*virStoragePoolObjListFilter)(virConnectPtr conn, virStoragePoolDefPtr def); -static inline int -virStoragePoolObjIsActive(virStoragePoolObjPtr obj) -{ - return obj->active; -} +virStoragePoolDefPtr +virStoragePoolObjGetDef(virStoragePoolObjPtr obj); + +virStoragePoolDefPtr +virStoragePoolObjGetNewDef(virStoragePoolObjPtr obj); + +void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj); + +char * +virStoragePoolObjGetConfigFile(virStoragePoolObjPtr obj); + +void +virStoragePoolObjSetConfigFile(virStoragePoolObjPtr obj, + char *configFile); + +bool +virStoragePoolObjIsActive(virStoragePoolObjPtr obj); + +void +virStoragePoolObjSetActive(virStoragePoolObjPtr obj, + bool active); + +unsigned int +virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj); + +void +virStoragePoolObjIncrAsyncjobs(virStoragePoolObjPtr obj); + +void +virStoragePoolObjDecrAsyncjobs(virStoragePoolObjPtr obj); int virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4cca0ca..edd3174 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1009,10 +1009,17 @@ virSecretObjSetValueSize; # conf/virstorageobj.h virStoragePoolObjAssignDef; virStoragePoolObjClearVols; +virStoragePoolObjDecrAsyncjobs; virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; +virStoragePoolObjGetAsyncjobs; +virStoragePoolObjGetConfigFile; +virStoragePoolObjGetDef; virStoragePoolObjGetNames; +virStoragePoolObjGetNewDef; +virStoragePoolObjIncrAsyncjobs; +virStoragePoolObjIsActive; virStoragePoolObjIsDuplicate; virStoragePoolObjListExport; virStoragePoolObjListFree; @@ -1023,7 +1030,10 @@ virStoragePoolObjNumOfStoragePools; virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjSaveDef; +virStoragePoolObjSetActive; +virStoragePoolObjSetConfigFile; virStoragePoolObjSourceFindDuplicate; +virStoragePoolObjStealNewDef; virStoragePoolObjUnlock; virStoragePoolObjVolumeGetNames; virStoragePoolObjVolumeListExport; -- 2.9.3

On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
Base on the review of following patches we need to add one more accessor virStoragePoolObjGetAutostartLink(). The rest is OK. Pavel

On 07/14/2017 09:55 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
Base on the review of following patches we need to add one more accessor virStoragePoolObjGetAutostartLink().
I will place it right after virStoragePoolObjGetConfigFile since the _virStoragePoolObj has autotstartLink after configFile. John
The rest is OK.
Pavel

On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 23346f3..7d6b311 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,80 @@ VIR_LOG_INIT("conf.virstorageobj");
[...]
+void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj) +{ + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; +}
I didn't notice this until the usage in following patches, the "Steal" part of the name is confusing. We have a macro "VIR_STEAL_PTR" which returns pointer and sets the original one to NULL. This function doesn't return the pointer, it replaces @def with @newDef. How about virStoragePoolObjUseNewDef() or virStoragePoolObjDefUseNewDef() or feel free to come up with another name which would be better than "Steel". Pavel

On 07/14/2017 11:37 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 23346f3..7d6b311 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,80 @@ VIR_LOG_INIT("conf.virstorageobj");
[...]
+void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj) +{ + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; +}
I didn't notice this until the usage in following patches, the "Steal" part of the name is confusing. We have a macro "VIR_STEAL_PTR" which returns pointer and sets the original one to NULL. This function doesn't return the pointer, it replaces @def with @newDef.
How about virStoragePoolObjUseNewDef() or virStoragePoolObjDefUseNewDef() or feel free to come up with another name which would be better than "Steel".
Pavel
It's theft by deception. How about virStoragePoolObjDefSwapNewDef John

On Thu, Jul 20, 2017 at 05:38:53PM -0400, John Ferlan wrote:
On 07/14/2017 11:37 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 23346f3..7d6b311 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,80 @@ VIR_LOG_INIT("conf.virstorageobj");
[...]
+void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj) +{ + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; +}
I didn't notice this until the usage in following patches, the "Steal" part of the name is confusing. We have a macro "VIR_STEAL_PTR" which returns pointer and sets the original one to NULL. This function doesn't return the pointer, it replaces @def with @newDef.
How about virStoragePoolObjUseNewDef() or virStoragePoolObjDefUseNewDef() or feel free to come up with another name which would be better than "Steel".
Pavel
It's theft by deception.
How about virStoragePoolObjDefSwapNewDef
"Swap" is not a good choice as well, it replaces and discards the original @def by @newDef, "Swap" can mean that the @def will be @newDef. Pavel

On 07/21/2017 04:22 AM, Pavel Hrdina wrote:
On Thu, Jul 20, 2017 at 05:38:53PM -0400, John Ferlan wrote:
On 07/14/2017 11:37 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:17AM -0400, John Ferlan wrote:
In preparation for making a private object, create accessor API's for consumer storage functions to use:
virStoragePoolObjGetDef virStoragePoolObjGetNewDef virStoragePoolObjStealNewDef virStoragePoolObjGetConfigFile virStoragePoolObjSetConfigFile virStoragePoolObjIsActive virStoragePoolObjSetActive virStoragePoolObjGetAsyncjobs virStoragePoolObjIncrAsyncjobs virStoragePoolObjDecrAsyncjobs
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 36 +++++++++++++++++++---- src/libvirt_private.syms | 10 +++++++ 3 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 23346f3..7d6b311 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,80 @@ VIR_LOG_INIT("conf.virstorageobj");
[...]
+void +virStoragePoolObjStealNewDef(virStoragePoolObjPtr obj) +{ + virStoragePoolDefFree(obj->def); + obj->def = obj->newDef; + obj->newDef = NULL; +}
I didn't notice this until the usage in following patches, the "Steal" part of the name is confusing. We have a macro "VIR_STEAL_PTR" which returns pointer and sets the original one to NULL. This function doesn't return the pointer, it replaces @def with @newDef.
How about virStoragePoolObjUseNewDef() or virStoragePoolObjDefUseNewDef() or feel free to come up with another name which would be better than "Steel".
Pavel
It's theft by deception.
How about virStoragePoolObjDefSwapNewDef
"Swap" is not a good choice as well, it replaces and discards the original @def by @newDef, "Swap" can mean that the @def will be @newDef.
Pavel
I'll go with virStoragePoolObjDefUseNewDef Although it's more like : virStoragePoolObjDefFreeAndAssignNewDefToDef at some point the name of the function can be too descriptive and too long;-). Not sure Use is the best either, but I did waste some time looking at synonyms with nothing that made me think - yeah *that's* it although Transmogrify came close (google transmogrify+calvin+hobbes - when I worked at HP that's what we called the layer that "converted" or "virtualized" privileged machine instructions into instructions that the guest could run). John

Create/use a helper to perform object allocation. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7d6b311..0079472 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,27 @@ VIR_LOG_INIT("conf.virstorageobj"); +static virStoragePoolObjPtr +virStoragePoolObjNew(virStoragePoolDefPtr def) +{ + 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; + obj->def = def; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -386,24 +407,15 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return obj; } - if (VIR_ALLOC(obj) < 0) + if (!(obj = virStoragePoolObjNew(def))) 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) { + obj->def = NULL; virStoragePoolObjUnlock(obj); virStoragePoolObjFree(obj); return NULL; } - obj->def = def; return obj; } -- 2.9.3

On Tue, May 09, 2017 at 11:30:18AM -0400, John Ferlan wrote:
Create/use a helper to perform object allocation.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7d6b311..0079472 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,27 @@ VIR_LOG_INIT("conf.virstorageobj");
+static virStoragePoolObjPtr +virStoragePoolObjNew(virStoragePoolDefPtr def) +{ + 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; + obj->def = def; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -386,24 +407,15 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return obj; }
- if (VIR_ALLOC(obj) < 0) + if (!(obj = virStoragePoolObjNew(def))) return NULL;
The new virStoragePoolObjNew() doesn't have to take @def and ...
- 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) { + obj->def = NULL;
... need to set the @obj->def to NULL and ...
virStoragePoolObjUnlock(obj); virStoragePoolObjFree(obj); return NULL; } - obj->def = def;
... just keep this line as it is.
return obj; } -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 07/11/2017 11:17 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:18AM -0400, John Ferlan wrote:
Create/use a helper to perform object allocation.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7d6b311..0079472 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,27 @@ VIR_LOG_INIT("conf.virstorageobj");
+static virStoragePoolObjPtr +virStoragePoolObjNew(virStoragePoolDefPtr def) +{ + 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; + obj->def = def; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -386,24 +407,15 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return obj; }
- if (VIR_ALLOC(obj) < 0) + if (!(obj = virStoragePoolObjNew(def))) return NULL;
The new virStoragePoolObjNew() doesn't have to take @def and ...
- 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) { + obj->def = NULL;
... need to set the @obj->def to NULL and ...
virStoragePoolObjUnlock(obj); virStoragePoolObjFree(obj); return NULL; } - obj->def = def;
... just keep this line as it is.
True... Again these are patches that I know I'm going to have to rework anyway to fit whatever virObject* gets created. John
return obj; } -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 07/11/2017 11:17 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:18AM -0400, John Ferlan wrote:
Create/use a helper to perform object allocation.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7d6b311..0079472 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,27 @@ VIR_LOG_INIT("conf.virstorageobj");
+static virStoragePoolObjPtr +virStoragePoolObjNew(virStoragePoolDefPtr def) +{ + 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; + obj->def = def; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -386,24 +407,15 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return obj; }
- if (VIR_ALLOC(obj) < 0) + if (!(obj = virStoragePoolObjNew(def))) return NULL;
The new virStoragePoolObjNew() doesn't have to take @def and ...
- 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) { + obj->def = NULL;
... need to set the @obj->def to NULL and ...
virStoragePoolObjUnlock(obj); virStoragePoolObjFree(obj); return NULL; } - obj->def = def;
... just keep this line as it is.
These are all changed in my local branch. I figure as long as you're good with my most recent comments to 8/19 that since I have ACKs now through 9/19 - I'll push those, then post a new version for the rest (eventually, but not right away). Hopefully that works. I think I want to work through the NodeDev, Secrets, NWFilter, and Interface first. Then jump back into Storage and Network before perhaps one day considering domain. Thanks for the reviews here though - I certainly appreciate it. John
return obj; } -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Jul 20, 2017 at 06:00:05PM -0400, John Ferlan wrote:
On 07/11/2017 11:17 AM, Pavel Hrdina wrote:
On Tue, May 09, 2017 at 11:30:18AM -0400, John Ferlan wrote:
Create/use a helper to perform object allocation.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7d6b311..0079472 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -37,6 +37,27 @@ VIR_LOG_INIT("conf.virstorageobj");
+static virStoragePoolObjPtr +virStoragePoolObjNew(virStoragePoolDefPtr def) +{ + 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; + obj->def = def; + return obj; +} + + virStoragePoolDefPtr virStoragePoolObjGetDef(virStoragePoolObjPtr obj) { @@ -386,24 +407,15 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return obj; }
- if (VIR_ALLOC(obj) < 0) + if (!(obj = virStoragePoolObjNew(def))) return NULL;
The new virStoragePoolObjNew() doesn't have to take @def and ...
- 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) { + obj->def = NULL;
... need to set the @obj->def to NULL and ...
virStoragePoolObjUnlock(obj); virStoragePoolObjFree(obj); return NULL; } - obj->def = def;
... just keep this line as it is.
These are all changed in my local branch.
I figure as long as you're good with my most recent comments to 8/19 that since I have ACKs now through 9/19 - I'll push those, then post a new version for the rest (eventually, but not right away).
That sound good to me, patches 01-09 with the fixes can be pushed.
Hopefully that works. I think I want to work through the NodeDev, Secrets, NWFilter, and Interface first. Then jump back into Storage and Network before perhaps one day considering domain.
Sure, the Storage and Network objects are more complex so it makes perfect sense.
Thanks for the reviews here though - I certainly appreciate it.
You're welcome :) Pavel

Rather than have the logic in the storage driver, move it to virstorageobj. NB: virStoragePoolObjGetAutostart can take liberties with not needing the same if...else construct. Also pass a NULL for testStoragePoolSetAutostart to avoid the autostartLink setup using the autostartDir for the test driver. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 8 +++++++ src/libvirt_private.syms | 2 ++ src/storage/storage_driver.c | 41 +++---------------------------- src/test/test_driver.c | 13 ++-------- 5 files changed, 72 insertions(+), 49 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 0079472..9ce3840 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -111,6 +111,63 @@ virStoragePoolObjSetActive(virStoragePoolObjPtr obj, } +int +virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj) +{ + if (!obj->configFile) + return 0; + + return obj->autostart; +} + + +int +virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj, + const char *autostartDir, + int autostart) +{ + obj->autostart = autostart; + + if (!obj->configFile) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("pool has no config file")); + return -1; + } + + autostart = (autostart != 0); + + if (obj->autostart != autostart) { + if (autostart && autostartDir) { + if (virFileMakePath(autostartDir) < 0) { + virReportSystemError(errno, + _("cannot create autostart directory %s"), + autostartDir); + return -1; + } + + if (symlink(obj->configFile, obj->autostartLink) < 0) { + virReportSystemError(errno, + _("Failed to create symlink '%s' to '%s'"), + obj->autostartLink, obj->configFile); + return -1; + } + } else { + if (unlink(obj->autostartLink) < 0 && + errno != ENOENT && errno != ENOTDIR) { + virReportSystemError(errno, + _("Failed to delete symlink '%s'"), + obj->autostartLink); + return -1; + } + } + + obj->autostart = autostart; + } + + return 0; +} + + unsigned int virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj) { diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index d47b233..3b6e395 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -93,6 +93,14 @@ void virStoragePoolObjSetActive(virStoragePoolObjPtr obj, bool active); +int +virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj); + +int +virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj, + const char *autostartDir, + int autostart); + unsigned int virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index edd3174..e8b4eda 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1014,6 +1014,7 @@ virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; virStoragePoolObjGetAsyncjobs; +virStoragePoolObjGetAutostart; virStoragePoolObjGetConfigFile; virStoragePoolObjGetDef; virStoragePoolObjGetNames; @@ -1031,6 +1032,7 @@ virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolObjSetActive; +virStoragePoolObjSetAutostart; virStoragePoolObjSetConfigFile; virStoragePoolObjSourceFindDuplicate; virStoragePoolObjStealNewDef; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6289314..c4e4e7b 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1250,11 +1250,7 @@ storagePoolGetAutostart(virStoragePoolPtr pool, if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!obj->configFile) { - *autostart = 0; - } else { - *autostart = obj->autostart; - } + *autostart = virStoragePoolObjGetAutostart(obj); ret = 0; @@ -1277,39 +1273,8 @@ storagePoolSetAutostart(virStoragePoolPtr pool, if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup; - if (!obj->configFile) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("pool has no config file")); - } - - autostart = (autostart != 0); - - if (obj->autostart != autostart) { - if (autostart) { - if (virFileMakePath(driver->autostartDir) < 0) { - virReportSystemError(errno, - _("cannot create autostart directory %s"), - driver->autostartDir); - goto cleanup; - } - - if (symlink(obj->configFile, obj->autostartLink) < 0) { - virReportSystemError(errno, - _("Failed to create symlink '%s' to '%s'"), - obj->autostartLink, obj->configFile); - goto cleanup; - } - } else { - if (unlink(obj->autostartLink) < 0 && - errno != ENOENT && errno != ENOTDIR) { - virReportSystemError(errno, - _("Failed to delete symlink '%s'"), - obj->autostartLink); - goto cleanup; - } - } - obj->autostart = autostart; - } + if (virStoragePoolObjSetAutostart(obj, driver->autostartDir, autostart) < 0) + goto cleanup; ret = 0; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 68f1412..d68a18d 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4690,11 +4690,7 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1; - if (!obj->configFile) { - *autostart = 0; - } else { - *autostart = obj->autostart; - } + *autostart = virStoragePoolObjGetAutostart(obj); virStoragePoolObjUnlock(obj); return 0; @@ -4712,14 +4708,9 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1; - if (!obj->configFile) { - virReportError(VIR_ERR_INVALID_ARG, - "%s", _("pool has no config file")); + if (virStoragePoolObjSetAutostart(obj, NULL, autostart) < 0) goto cleanup; - } - autostart = (autostart != 0); - obj->autostart = autostart; ret = 0; cleanup: -- 2.9.3

On Tue, May 09, 2017 at 11:30:19AM -0400, John Ferlan wrote:
Rather than have the logic in the storage driver, move it to virstorageobj.
NB: virStoragePoolObjGetAutostart can take liberties with not needing the same if...else construct. Also pass a NULL for testStoragePoolSetAutostart to avoid the autostartLink setup using the autostartDir for the test driver.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 8 +++++++ src/libvirt_private.syms | 2 ++ src/storage/storage_driver.c | 41 +++---------------------------- src/test/test_driver.c | 13 ++-------- 5 files changed, 72 insertions(+), 49 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 0079472..9ce3840 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -111,6 +111,63 @@ virStoragePoolObjSetActive(virStoragePoolObjPtr obj, }
+int +virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj) +{ + if (!obj->configFile) + return 0; + + return obj->autostart; +}
The getter is correct.
+ + +int +virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj, + const char *autostartDir, + int autostart) +{ + obj->autostart = autostart; +
However, the setter does a lot more than it should be doing.
+ if (!obj->configFile) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("pool has no config file")); + return -1; + } + + autostart = (autostart != 0); + + if (obj->autostart != autostart) { + if (autostart && autostartDir) { + if (virFileMakePath(autostartDir) < 0) { + virReportSystemError(errno, + _("cannot create autostart directory %s"), + autostartDir); + return -1; + }
The autostartDir is owned by the storage driver so it is up to the storage driver to create the directory and create/remove the symlink.
+ + if (symlink(obj->configFile, obj->autostartLink) < 0) { + virReportSystemError(errno, + _("Failed to create symlink '%s' to '%s'"), + obj->autostartLink, obj->configFile); + return -1; + } + } else { + if (unlink(obj->autostartLink) < 0 && + errno != ENOENT && errno != ENOTDIR) { + virReportSystemError(errno, + _("Failed to delete symlink '%s'"), + obj->autostartLink); + return -1; + } + } + + obj->autostart = autostart;
This is duplicated the beginning of the function. The one at the beginning of the function is wrong, the @autostart should be changed only if we actually creates the symlink. I see that you've probably added it at the beginning of the function to reuse it in the test driver but that's wrong, it may cause issues for real storage driver.
+ } + + return 0; +} + + unsigned int virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj) { diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index d47b233..3b6e395 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -93,6 +93,14 @@ void virStoragePoolObjSetActive(virStoragePoolObjPtr obj, bool active);
+int +virStoragePoolObjGetAutostart(virStoragePoolObjPtr obj); + +int +virStoragePoolObjSetAutostart(virStoragePoolObjPtr obj, + const char *autostartDir, + int autostart); + unsigned int virStoragePoolObjGetAsyncjobs(virStoragePoolObjPtr obj);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index edd3174..e8b4eda 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1014,6 +1014,7 @@ virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; virStoragePoolObjGetAsyncjobs; +virStoragePoolObjGetAutostart; virStoragePoolObjGetConfigFile; virStoragePoolObjGetDef; virStoragePoolObjGetNames; @@ -1031,6 +1032,7 @@ virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolObjSetActive; +virStoragePoolObjSetAutostart; virStoragePoolObjSetConfigFile; virStoragePoolObjSourceFindDuplicate; virStoragePoolObjStealNewDef; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6289314..c4e4e7b 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1250,11 +1250,7 @@ storagePoolGetAutostart(virStoragePoolPtr pool, if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!obj->configFile) { - *autostart = 0; - } else { - *autostart = obj->autostart; - } + *autostart = virStoragePoolObjGetAutostart(obj);
ret = 0;
@@ -1277,39 +1273,8 @@ storagePoolSetAutostart(virStoragePoolPtr pool, if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0) goto cleanup;
- if (!obj->configFile) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("pool has no config file")); - } - - autostart = (autostart != 0); - - if (obj->autostart != autostart) { - if (autostart) { - if (virFileMakePath(driver->autostartDir) < 0) { - virReportSystemError(errno, - _("cannot create autostart directory %s"), - driver->autostartDir); - goto cleanup; - } - - if (symlink(obj->configFile, obj->autostartLink) < 0) { - virReportSystemError(errno, - _("Failed to create symlink '%s' to '%s'"), - obj->autostartLink, obj->configFile); - goto cleanup; - } - } else { - if (unlink(obj->autostartLink) < 0 && - errno != ENOENT && errno != ENOTDIR) { - virReportSystemError(errno, - _("Failed to delete symlink '%s'"), - obj->autostartLink); - goto cleanup; - } - } - obj->autostart = autostart;
I would leave the symlink creation logic here, to do that we need to have additional accessor API virStoragePoolObjGetAutostartLink(). Pavel
- } + if (virStoragePoolObjSetAutostart(obj, driver->autostartDir, autostart) < 0) + goto cleanup;
ret = 0;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 68f1412..d68a18d 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4690,11 +4690,7 @@ testStoragePoolGetAutostart(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1;
- if (!obj->configFile) { - *autostart = 0; - } else { - *autostart = obj->autostart; - } + *autostart = virStoragePoolObjGetAutostart(obj);
virStoragePoolObjUnlock(obj); return 0; @@ -4712,14 +4708,9 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1;
- if (!obj->configFile) { - virReportError(VIR_ERR_INVALID_ARG, - "%s", _("pool has no config file")); + if (virStoragePoolObjSetAutostart(obj, NULL, autostart) < 0) goto cleanup; - }
- autostart = (autostart != 0); - obj->autostart = autostart; ret = 0;
cleanup: -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

The virStoragePoolObjDeleteDef already dealt with the configFile - just add in the autostartLink as well. If there is no autostartLink defined, then no need to attempt unlink - which also allows removal of one errno check in moved function. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 11 +++++++++++ src/storage/storage_driver.c | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 9ce3840..69ed66d 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -696,6 +696,17 @@ virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj) obj->def->name); return -1; } + VIR_FREE(obj->configFile); + + if (!obj->autostartLink) + return 0; + + if (unlink(obj->autostartLink) < 0 && errno != ENOTDIR) { + char ebuf[1024]; + VIR_ERROR(_("Failed to delete autostart link '%s': %s"), + obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); + } + VIR_FREE(obj->autostartLink); return 0; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c4e4e7b..c4650cd 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -841,17 +841,6 @@ storagePoolUndefine(virStoragePoolPtr pool) if (virStoragePoolObjDeleteDef(obj) < 0) goto cleanup; - if (unlink(obj->autostartLink) < 0 && - errno != ENOENT && - errno != ENOTDIR) { - char ebuf[1024]; - VIR_ERROR(_("Failed to delete autostart link '%s': %s"), - obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); - } - - VIR_FREE(obj->configFile); - VIR_FREE(obj->autostartLink); - event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, -- 2.9.3

On Tue, May 09, 2017 at 11:30:20AM -0400, John Ferlan wrote:
The virStoragePoolObjDeleteDef already dealt with the configFile - just add in the autostartLink as well. If there is no autostartLink defined, then no need to attempt unlink - which also allows removal of one errno check in moved function.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 11 +++++++++++ src/storage/storage_driver.c | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 9ce3840..69ed66d 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -696,6 +696,17 @@ virStoragePoolObjDeleteDef(virStoragePoolObjPtr obj) obj->def->name); return -1; } + VIR_FREE(obj->configFile); + + if (!obj->autostartLink) + return 0; + + if (unlink(obj->autostartLink) < 0 && errno != ENOTDIR) { + char ebuf[1024]; + VIR_ERROR(_("Failed to delete autostart link '%s': %s"), + obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); + } + VIR_FREE(obj->autostartLink);
return 0; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c4e4e7b..c4650cd 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -841,17 +841,6 @@ storagePoolUndefine(virStoragePoolPtr pool) if (virStoragePoolObjDeleteDef(obj) < 0) goto cleanup;
- if (unlink(obj->autostartLink) < 0 && - errno != ENOENT && - errno != ENOTDIR) { - char ebuf[1024]; - VIR_ERROR(_("Failed to delete autostart link '%s': %s"), - obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf))); - }
The same as for the previous patch, keep the unlink in storage driver and use the new virStoragePoolObjGetAutostartLink().
- - VIR_FREE(obj->configFile); - VIR_FREE(obj->autostartLink); -
This can be safely removed since it's handled by virStoragePoolObjFree() which is called in virStoragePoolObjRemove().
event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Create/use virStoragePoolObjAddVol in order to add volumes onto list. Create/use virStoragePoolObjRemoveVol in order to remove volumes from list. Create/use virStoragePoolObjGetVolumesCount to get count of volumes on list. For the storage driver, the logic alters when the volumes.obj list grows to after we've fetched the volobj. This is an optimization of sorts, but also doesn't "needlessly" grow the volumes.objs list and then just decr the count if the virGetStorageVol fails. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 37 ++++++++++++++++++++++++ src/conf/virstorageobj.h | 11 +++++++ src/libvirt_private.syms | 3 ++ src/storage/storage_backend_disk.c | 5 ++-- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_mpath.c | 3 +- src/storage/storage_backend_rbd.c | 4 +-- src/storage/storage_backend_sheepdog.c | 4 +-- src/storage/storage_backend_zfs.c | 5 +--- src/storage/storage_driver.c | 53 +++++++++------------------------- src/storage/storage_util.c | 4 +-- src/test/test_driver.c | 18 ++++-------- 13 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 69ed66d..cc3464e 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -305,6 +305,43 @@ virStoragePoolObjClearVols(virStoragePoolObjPtr obj) } +int +virStoragePoolObjAddVol(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) +{ + if (VIR_APPEND_ELEMENT(obj->volumes.objs, obj->volumes.count, voldef) < 0) + return -1; + return 0; +} + + +void +virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef) +{ + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); + size_t i; + + for (i = 0; i < obj->volumes.count; i++) { + if (obj->volumes.objs[i] == voldef) { + VIR_INFO("Deleting volume '%s' from storage pool '%s'", + voldef->name, def->name); + virStorageVolDefFree(voldef); + + VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); + return; + } + } +} + + +size_t +virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj) +{ + return obj->volumes.count; +} + + virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 3b6e395..d27ff57 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -127,6 +127,17 @@ virStoragePoolObjPtr virStoragePoolObjFindByName(virStoragePoolObjListPtr pools, const char *name); +int +virStoragePoolObjAddVol(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef); + +void +virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj, + virStorageVolDefPtr voldef); + +size_t +virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj); + virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e8b4eda..03777a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1007,6 +1007,7 @@ virSecretObjSetValueSize; # conf/virstorageobj.h +virStoragePoolObjAddVol; virStoragePoolObjAssignDef; virStoragePoolObjClearVols; virStoragePoolObjDecrAsyncjobs; @@ -1019,6 +1020,7 @@ virStoragePoolObjGetConfigFile; virStoragePoolObjGetDef; virStoragePoolObjGetNames; virStoragePoolObjGetNewDef; +virStoragePoolObjGetVolumesCount; virStoragePoolObjIncrAsyncjobs; virStoragePoolObjIsActive; virStoragePoolObjIsDuplicate; @@ -1030,6 +1032,7 @@ virStoragePoolObjLock; virStoragePoolObjNumOfStoragePools; virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; +virStoragePoolObjRemoveVol; virStoragePoolObjSaveDef; virStoragePoolObjSetActive; virStoragePoolObjSetAutostart; diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index e8f67bb..0bf5567 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -65,8 +65,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, if (VIR_ALLOC(vol) < 0) return -1; if (VIR_STRDUP(vol->name, partname) < 0 || - VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, - pool->volumes.count, vol) < 0) { + virStoragePoolObjAddVol(pool, vol) < 0) { virStorageVolDefFree(vol); return -1; } @@ -595,7 +594,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, break; } } - if (i == pool->volumes.count) { + if (i == virStoragePoolObjGetVolumesCount(pool)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no extended partition found and no primary partition available")); return -1; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index 93dce40..afd93b7 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -385,8 +385,7 @@ virStorageBackendGlusterRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, if (okay < 0) goto cleanup; - if (vol && VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, - vol) < 0) + if (vol && virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; } if (errno) { diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 67f70e5..2f2782c 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -356,8 +356,7 @@ virStorageBackendLogicalMakeVol(char **const groups, if (virStorageBackendLogicalParseVolExtents(vol, groups) < 0) goto cleanup; - if (is_new_vol && - VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) + if (is_new_vol && virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; ret = 0; diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 606b399..fcaaa0e 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -71,8 +71,9 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, if (VIR_STRDUP(vol->key, vol->target.path) < 0) goto cleanup; - if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, vol) < 0) + if (virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; + pool->def->capacity += vol->target.capacity; pool->def->allocation += vol->target.allocation; ret = 0; diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 7b8887b..6731677 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -506,7 +506,7 @@ virStorageBackendRBDRefreshPool(virConnectPtr conn, goto cleanup; } - if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) { + if (virStoragePoolObjAddVol(pool, vol) < 0) { virStorageVolDefFree(vol); virStoragePoolObjClearVols(pool); goto cleanup; @@ -514,7 +514,7 @@ virStorageBackendRBDRefreshPool(virConnectPtr conn, } VIR_DEBUG("Found %zu images in RBD pool %s", - pool->volumes.count, pool->def->source.name); + virStoragePoolObjGetVolumesCount(pool), pool->def->source.name); ret = 0; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index b55d96a..e72dcda 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -130,11 +130,9 @@ virStorageBackendSheepdogAddVolume(virConnectPtr conn ATTRIBUTE_UNUSED, if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0) goto error; - if (VIR_EXPAND_N(pool->volumes.objs, pool->volumes.count, 1) < 0) + if (virStoragePoolObjAddVol(pool, vol) < 0) goto error; - pool->volumes.objs[pool->volumes.count - 1] = vol; - return 0; error: diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c index c6dae71..c063090 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -161,10 +161,7 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool, if (volume->target.allocation < volume->target.capacity) volume->target.sparse = true; - if (is_new_vol && - VIR_APPEND_ELEMENT(pool->volumes.objs, - pool->volumes.count, - volume) < 0) + if (is_new_vol && virStoragePoolObjAddVol(pool, volume) < 0) goto cleanup; ret = 0; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c4650cd..fc393dd 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1579,25 +1579,6 @@ storagePoolLookupByTargetPath(virConnectPtr conn, } -static void -storageVolRemoveFromPool(virStoragePoolObjPtr obj, - virStorageVolDefPtr voldef) -{ - size_t i; - - for (i = 0; i < obj->volumes.count; i++) { - if (obj->volumes.objs[i] == voldef) { - VIR_INFO("Deleting volume '%s' from storage pool '%s'", - voldef->name, obj->def->name); - virStorageVolDefFree(voldef); - - VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); - break; - } - } -} - - static int storageVolDeleteInternal(virStorageVolPtr vol, virStorageBackendPtr backend, @@ -1629,7 +1610,7 @@ storageVolDeleteInternal(virStorageVolPtr vol, } } - storageVolRemoveFromPool(obj, voldef); + virStoragePoolObjRemoveVol(obj, voldef); ret = 0; cleanup: @@ -1768,24 +1749,19 @@ storageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - if (VIR_REALLOC_N(obj->volumes.objs, - obj->volumes.count + 1) < 0) - goto cleanup; - /* Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(voldef->key); if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup; - obj->volumes.objs[obj->volumes.count++] = voldef; - volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, - voldef->key, NULL, NULL); - if (!volobj) { - obj->volumes.count--; + if (!(volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + voldef->key, NULL, NULL))) goto cleanup; - } + /* NB: Upon success voldef "owned" by storage pool for deletion purposes */ + if (virStoragePoolObjAddVol(obj, voldef) < 0) + goto cleanup; if (backend->buildVol) { int buildret; @@ -1820,7 +1796,7 @@ storageVolCreateXML(virStoragePoolPtr pool, if (buildret < 0) { /* buildVol handles deleting volume on failure */ - storageVolRemoveFromPool(obj, voldef); + virStoragePoolObjRemoveVol(obj, voldef); voldef = NULL; goto cleanup; } @@ -1971,9 +1947,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, backend->refreshVol(pool->conn, obj, voldefsrc) < 0) goto cleanup; - if (VIR_REALLOC_N(obj->volumes.objs, obj->volumes.count + 1) < 0) - goto cleanup; - /* 'Define' the new volume so we get async progress reporting. * Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ @@ -1990,13 +1963,13 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, memcpy(shadowvol, voldef, sizeof(*voldef)); - obj->volumes.objs[obj->volumes.count++] = voldef; - volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, - voldef->key, NULL, NULL); - if (!volobj) { - obj->volumes.count--; + if (!(volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + voldef->key, NULL, NULL))) + goto cleanup; + + /* NB: Upon success voldef "owned" by storage pool for deletion purposes */ + if (virStoragePoolObjAddVol(obj, voldef) < 0) goto cleanup; - } /* Drop the pool lock during volume allocation */ obj->asyncjobs++; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 08dca94..8d9dd3f 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3595,7 +3595,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, * An error message was raised, but we just continue. */ } - if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) + if (virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; } if (direrr < 0) @@ -3783,7 +3783,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, pool->def->capacity += vol->target.capacity; pool->def->allocation += vol->target.allocation; - if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) + if (virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; vol = NULL; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d68a18d..6ea3a5b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1075,7 +1075,8 @@ testOpenVolumesForPool(const char *file, if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0) goto error; - if (VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, obj->volumes.count, def) < 0) + + if (virStoragePoolObjAddVol(obj, def) < 0) goto error; obj->def->allocation += def->target.allocation; @@ -4937,8 +4938,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || - VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, - obj->volumes.count, privvol) < 0) + virStoragePoolObjAddVol(obj, privvol) < 0) goto cleanup; obj->def->allocation += privvol->target.allocation; @@ -5005,8 +5005,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || - VIR_APPEND_ELEMENT_COPY(obj->volumes.objs, - obj->volumes.count, privvol) < 0) + virStoragePoolObjAddVol(obj, privvol) < 0) goto cleanup; obj->def->allocation += privvol->target.allocation; @@ -5031,7 +5030,6 @@ testStorageVolDelete(virStorageVolPtr vol, testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr obj; virStorageVolDefPtr privvol; - size_t i; int ret = -1; virCheckFlags(0, -1); @@ -5045,14 +5043,8 @@ testStorageVolDelete(virStorageVolPtr vol, obj->def->allocation -= privvol->target.allocation; obj->def->available = (obj->def->capacity - obj->def->allocation); - for (i = 0; i < obj->volumes.count; i++) { - if (obj->volumes.objs[i] == privvol) { - virStorageVolDefFree(privvol); + virStoragePoolObjRemoveVol(obj, privvol); - VIR_DELETE_ELEMENT(obj->volumes.objs, i, obj->volumes.count); - break; - } - } ret = 0; cleanup: -- 2.9.3

On Tue, May 09, 2017 at 11:30:21AM -0400, John Ferlan wrote:
Create/use virStoragePoolObjAddVol in order to add volumes onto list.
Create/use virStoragePoolObjRemoveVol in order to remove volumes from list.
Create/use virStoragePoolObjGetVolumesCount to get count of volumes on list.
For the storage driver, the logic alters when the volumes.obj list grows to after we've fetched the volobj. This is an optimization of sorts, but also doesn't "needlessly" grow the volumes.objs list and then just decr the count if the virGetStorageVol fails.
Reminder: long lines.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 37 ++++++++++++++++++++++++ src/conf/virstorageobj.h | 11 +++++++ src/libvirt_private.syms | 3 ++ src/storage/storage_backend_disk.c | 5 ++-- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_mpath.c | 3 +- src/storage/storage_backend_rbd.c | 4 +-- src/storage/storage_backend_sheepdog.c | 4 +-- src/storage/storage_backend_zfs.c | 5 +--- src/storage/storage_driver.c | 53 +++++++++------------------------- src/storage/storage_util.c | 4 +-- src/test/test_driver.c | 18 ++++-------- 13 files changed, 81 insertions(+), 72 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Create/Use API to "walk" the storage pool object volume list. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 10 ++++++++++ src/conf/virstorageobj.h | 4 ++++ src/libvirt_private.syms | 1 + src/storage/storage_backend_disk.c | 26 +++++++++++++++----------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index cc3464e..14feecb 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -343,6 +343,16 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj) virStorageVolDefPtr +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + size_t curidx) +{ + if (curidx < obj->volumes.count) + return obj->volumes.objs[curidx]; + return NULL; +} + + +virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key) { diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index d27ff57..df0b4ae 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -139,6 +139,10 @@ size_t virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj); virStorageVolDefPtr +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + size_t curidx); + +virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03777a3..fe0e203 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1014,6 +1014,7 @@ virStoragePoolObjDecrAsyncjobs; virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; +virStoragePoolObjForEachVolume; virStoragePoolObjGetAsyncjobs; virStoragePoolObjGetAutostart; virStoragePoolObjGetConfigFile; diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 0bf5567..0ec601e 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -192,12 +192,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, /* Find the extended partition and increase the allocation value */ if (vol->source.partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { size_t i; + virStorageVolDefPtr voldef; - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == - VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { - pool->volumes.objs[i]->target.allocation += - vol->target.allocation; + for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) { + if (voldef->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { + voldef->target.allocation += vol->target.allocation; break; } } @@ -533,8 +532,10 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) can't be more than 3 to create a new primary partition */ size_t i; int count = 0; - for (i = 0; i < pool->volumes.count; i++) { - int partType = pool->volumes.objs[i]->source.partType; + virStorageVolDefPtr voldef; + + for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) { + int partType = voldef->source.partType; if (partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY || partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) count++; @@ -553,6 +554,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, char** partFormat) { size_t i; + virStorageVolDefPtr voldef; + if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { const char *partedFormat; partedFormat = virStoragePartedFsTypeToString(vol->target.format); @@ -563,8 +566,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, } if (vol->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) { /* make sure we don't have an extended partition already */ - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == + for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); i++) { + if (voldef->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("extended partition already exists")); @@ -585,8 +588,9 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, break; case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL: /* make sure we have an extended partition */ - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == + for (i = 0; (voldef = virStoragePoolObjForEachVolume(pool, i)); + i++) { + if (voldef->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { if (virAsprintf(partFormat, "logical %s", partedFormat) < 0) -- 2.9.3

On Tue, May 09, 2017 at 11:30:22 -0400, John Ferlan wrote:
Create/Use API to "walk" the storage pool object volume list.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 10 ++++++++++ src/conf/virstorageobj.h | 4 ++++ src/libvirt_private.syms | 1 + src/storage/storage_backend_disk.c | 26 +++++++++++++++----------- 4 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index cc3464e..14feecb 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -343,6 +343,16 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj)
virStorageVolDefPtr +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + size_t curidx)
All 'foreach' functions in libvirt take a callback and iterate the objects calling the callback. This is just a generic accessor. Naming it foreach is very confusing.

On 05/19/2017 06:46 AM, Peter Krempa wrote:
On Tue, May 09, 2017 at 11:30:22 -0400, John Ferlan wrote:
Create/Use API to "walk" the storage pool object volume list.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 10 ++++++++++ src/conf/virstorageobj.h | 4 ++++ src/libvirt_private.syms | 1 + src/storage/storage_backend_disk.c | 26 +++++++++++++++----------- 4 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index cc3464e..14feecb 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -343,6 +343,16 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj)
virStorageVolDefPtr +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + size_t curidx)
All 'foreach' functions in libvirt take a callback and iterate the objects calling the callback. This is just a generic accessor. Naming it foreach is very confusing.
Sure eventually that's where things are going, but if I still have to get from point A to point D or E or F... I was trying to find a "cheap" way (for now) to not have the volumes.count in the storage backend and only in the virstorageobj. Eventually (point E, F, G) this becomes a "search" (e.g. virHashSearch) looking for a specific truism. I can make this better though to not offend the expectations of existing ForEach functions. John

Introduce virStoragePoolObjForEachVolume to scan each volume calling the passed callback function until all volumes have been processed in the storage pool volume list, unless the callback function returns an error. Introduce virStoragePoolObjSearchVolume to search each volume calling the passed callback function until it returns true indicating that the desired volume was found. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 32 ++++++++++++++ src/conf/virstorageobj.h | 18 ++++++++ src/libvirt_private.syms | 2 + src/storage/storage_backend_disk.c | 90 +++++++++++++++++++++++--------------- 4 files changed, 107 insertions(+), 35 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index cc3464e..a62d69a 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -342,6 +342,38 @@ virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj) } +int +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + virStorageVolObjListIterator iter, + const void *opaque) +{ + size_t i; + + for (i = 0; i < obj->volumes.count; i++) { + if (iter(obj->volumes.objs[i], opaque) < 0) + return -1; + } + + return 0; +} + + +virStorageVolDefPtr +virStoragePoolObjSearchVolume(virStoragePoolObjPtr obj, + virStorageVolObjListSearcher iter, + const void *opaque) +{ + size_t i; + + for (i = 0; i < obj->volumes.count; i++) { + if (iter(obj->volumes.objs[i], opaque)) + return obj->volumes.objs[i]; + } + + return NULL; +} + + virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index d27ff57..1fb51ff 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -138,6 +138,24 @@ virStoragePoolObjRemoveVol(virStoragePoolObjPtr obj, size_t virStoragePoolObjGetVolumesCount(virStoragePoolObjPtr obj); +typedef int +(*virStorageVolObjListIterator)(virStorageVolDefPtr voldef, + const void *opaque); + +int +virStoragePoolObjForEachVolume(virStoragePoolObjPtr obj, + virStorageVolObjListIterator iter, + const void *opaque); + +typedef bool +(*virStorageVolObjListSearcher)(virStorageVolDefPtr voldef, + const void *opaque); + +virStorageVolDefPtr +virStoragePoolObjSearchVolume(virStoragePoolObjPtr obj, + virStorageVolObjListSearcher iter, + const void *opaque); + virStorageVolDefPtr virStorageVolDefFindByKey(virStoragePoolObjPtr obj, const char *key); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d559fa0..8ced61e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1015,6 +1015,7 @@ virStoragePoolObjDecrAsyncjobs; virStoragePoolObjDeleteDef; virStoragePoolObjFindByName; virStoragePoolObjFindByUUID; +virStoragePoolObjForEachVolume; virStoragePoolObjGetAsyncjobs; virStoragePoolObjGetAutostart; virStoragePoolObjGetConfigFile; @@ -1035,6 +1036,7 @@ virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjRemoveVol; virStoragePoolObjSaveDef; +virStoragePoolObjSearchVolume; virStoragePoolObjSetActive; virStoragePoolObjSetAutostart; virStoragePoolObjSetConfigFile; diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 0bf5567..dfe9938 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -43,6 +43,17 @@ VIR_LOG_INIT("storage.storage_backend_disk"); #define SECTOR_SIZE 512 +static bool +virStorageVolPartFindExtended(virStorageVolDefPtr def, + const void *opaque ATTRIBUTE_UNUSED) +{ + if (def->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) + return true; + + return false; +} + + static int virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, char **const groups, @@ -191,16 +202,13 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, /* Find the extended partition and increase the allocation value */ if (vol->source.partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { - size_t i; + virStorageVolDefPtr voldef; - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == - VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { - pool->volumes.objs[i]->target.allocation += - vol->target.allocation; - break; - } - } + voldef = virStoragePoolObjSearchVolume(pool, + virStorageVolPartFindExtended, + NULL); + if (voldef) + voldef->target.allocation += vol->target.allocation; } if (STRNEQ(groups[2], "metadata")) @@ -521,6 +529,25 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, return ret; } + +struct virStorageVolNumData { + int count; +}; + +static int +virStorageVolNumOfPartTypes(virStorageVolDefPtr def, + const void *opaque) +{ + struct virStorageVolNumData *data = (struct virStorageVolNumData *)opaque; + + if (def->source.partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY || + def->source.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) + data->count++; + + return 0; +} + + /** * Decides what kind of partition type that should be created. * Important when the partition table is of msdos type @@ -528,19 +555,16 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) { + struct virStorageVolNumData data = { .count = 0 }; + if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { /* count primary and extended partitions, can't be more than 3 to create a new primary partition */ - size_t i; - int count = 0; - for (i = 0; i < pool->volumes.count; i++) { - int partType = pool->volumes.objs[i]->source.partType; - if (partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY || - partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) - count++; + if (virStoragePoolObjForEachVolume(pool, virStorageVolNumOfPartTypes, + &data) == 0) { + if (data.count >= 4) + return VIR_STORAGE_VOL_DISK_TYPE_LOGICAL; } - if (count >= 4) - return VIR_STORAGE_VOL_DISK_TYPE_LOGICAL; } /* for all other cases, all partitions are primary */ @@ -552,7 +576,6 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, char** partFormat) { - size_t i; if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) { const char *partedFormat; partedFormat = virStoragePartedFsTypeToString(vol->target.format); @@ -563,13 +586,12 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, } if (vol->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) { /* make sure we don't have an extended partition already */ - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == - VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { + if (virStoragePoolObjSearchVolume(pool, + virStorageVolPartFindExtended, + NULL)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("extended partition already exists")); return -1; - } } if (VIR_STRDUP(*partFormat, partedFormat) < 0) return -1; @@ -585,18 +607,16 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, break; case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL: /* make sure we have an extended partition */ - for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->source.partType == - VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { - if (virAsprintf(partFormat, "logical %s", - partedFormat) < 0) - return -1; - break; - } - } - if (i == virStoragePoolObjGetVolumesCount(pool)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("no extended partition found and no primary partition available")); + if (virStoragePoolObjSearchVolume(pool, + virStorageVolPartFindExtended, + NULL)) { + if (virAsprintf(partFormat, "logical %s", + partedFormat) < 0) + return -1; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("no extended partition found and no " + "primary partition available")); return -1; } break; -- 2.9.3

On Fri, May 19, 2017 at 08:38:16AM -0400, John Ferlan wrote:
Introduce virStoragePoolObjForEachVolume to scan each volume calling the passed callback function until all volumes have been processed in the storage pool volume list, unless the callback function returns an error.
Introduce virStoragePoolObjSearchVolume to search each volume calling the passed callback function until it returns true indicating that the desired volume was found.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virstorageobj.c | 32 ++++++++++++++ src/conf/virstorageobj.h | 18 ++++++++ src/libvirt_private.syms | 2 + src/storage/storage_backend_disk.c | 90 +++++++++++++++++++++++--------------- 4 files changed, 107 insertions(+), 35 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

In preparation for privatizing the object, use the accessors. Perform some minor code cleanup along the w/r/t spacing, line wraps, etc. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_driver.c | 426 ++++++++++++++++++++++++------------------- 1 file changed, 242 insertions(+), 184 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index fc393dd..7d491bf 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -90,14 +90,14 @@ static void virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) { virStoragePoolObjPtr obj = *objptr; + virStoragePoolDefPtr newDef = virStoragePoolObjGetNewDef(obj); + char *configFile = virStoragePoolObjGetConfigFile(obj); - if (obj->configFile == NULL) { + if (!configFile) { virStoragePoolObjRemove(&driver->pools, obj); *objptr = NULL; - } else if (obj->newDef) { - virStoragePoolDefFree(obj->def); - obj->def = obj->newDef; - obj->newDef = NULL; + } else if (newDef) { + virStoragePoolObjStealNewDef(obj); } } @@ -105,17 +105,17 @@ virStoragePoolUpdateInactive(virStoragePoolObjPtr *objptr) static void storagePoolUpdateState(virStoragePoolObjPtr obj) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); bool active = false; virStorageBackendPtr backend; char *stateFile; - if (!(stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, ".xml"))) + if (!(stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"))) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { + if ((backend = virStorageBackendForType(def->type)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing backend %d"), obj->def->type); + _("Missing backend %d"), def->type); goto cleanup; } @@ -125,7 +125,7 @@ storagePoolUpdateState(virStoragePoolObjPtr obj) backend->checkPool(obj, &active) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to initialize storage pool '%s': %s"), - obj->def->name, virGetLastErrorMessage()); + def->name, virGetLastErrorMessage()); active = false; } @@ -140,14 +140,14 @@ storagePoolUpdateState(virStoragePoolObjPtr obj) backend->stopPool(NULL, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to restart storage pool '%s': %s"), - obj->def->name, virGetLastErrorMessage()); + def->name, virGetLastErrorMessage()); active = false; } } - obj->active = active; + virStoragePoolObjSetActive(obj, active); - if (!obj->active) + if (!virStoragePoolObjIsActive(obj)) virStoragePoolUpdateInactive(&obj); cleanup: @@ -187,22 +187,23 @@ storageDriverAutostart(void) for (i = 0; i < driver->pools.count; i++) { virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); virStorageBackendPtr backend; bool started = false; virStoragePoolObjLock(obj); - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) { + if ((backend = virStorageBackendForType(def->type)) == NULL) { virStoragePoolObjUnlock(obj); continue; } - if (obj->autostart && + if (virStoragePoolObjGetAutostart(obj) && !virStoragePoolObjIsActive(obj)) { if (backend->startPool && backend->startPool(conn, obj) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - obj->def->name, virGetLastErrorMessage()); + def->name, virGetLastErrorMessage()); virStoragePoolObjUnlock(obj); continue; } @@ -213,10 +214,9 @@ storageDriverAutostart(void) char *stateFile; virStoragePoolObjClearVols(obj); - stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, ".xml"); + stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"); if (!stateFile || - virStoragePoolSaveState(stateFile, obj->def) < 0 || + virStoragePoolSaveState(stateFile, def) < 0 || backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); @@ -224,9 +224,9 @@ storageDriverAutostart(void) backend->stopPool(conn, obj); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), - obj->def->name, virGetLastErrorMessage()); + def->name, virGetLastErrorMessage()); } else { - obj->active = true; + virStoragePoolObjSetActive(obj, true); } VIR_FREE(stateFile); } @@ -443,6 +443,7 @@ storagePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; storageDriverLock(); @@ -450,11 +451,12 @@ storagePoolLookupByUUID(virConnectPtr conn, storageDriverUnlock(); if (!obj) return NULL; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolLookupByUUIDEnsureACL(conn, obj->def) < 0) + if (virStoragePoolLookupByUUIDEnsureACL(conn, def) < 0) goto cleanup; - pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); + pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); cleanup: virStoragePoolObjUnlock(obj); @@ -466,15 +468,17 @@ storagePoolLookupByName(virConnectPtr conn, const char *name) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; if (!(obj = storagePoolObjFindByName(name))) return NULL; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolLookupByNameEnsureACL(conn, obj->def) < 0) + if (virStoragePoolLookupByNameEnsureACL(conn, def) < 0) goto cleanup; - pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); + pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); cleanup: virStoragePoolObjUnlock(obj); @@ -485,16 +489,17 @@ static virStoragePoolPtr storagePoolLookupByVolume(virStorageVolPtr vol) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; if (!(obj = storagePoolObjFindByName(vol->pool))) return NULL; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, obj->def) < 0) + if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, def) < 0) goto cleanup; - pool = virGetStoragePool(vol->conn, obj->def->name, obj->def->uuid, - NULL, NULL); + pool = virGetStoragePool(vol->conn, def->name, def->uuid, NULL, NULL); cleanup: virStoragePoolObjUnlock(obj); @@ -615,12 +620,14 @@ static int storagePoolIsActive(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolIsActiveEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolIsActiveEnsureACL(pool->conn, def) < 0) goto cleanup; ret = virStoragePoolObjIsActive(obj); @@ -635,15 +642,17 @@ static int storagePoolIsPersistent(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolIsPersistentEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolIsPersistentEnsureACL(pool->conn, def) < 0) goto cleanup; - ret = obj->configFile ? 1 : 0; + ret = virStoragePoolObjGetConfigFile(obj) ? 1 : 0; cleanup: virStoragePoolObjUnlock(obj); @@ -658,6 +667,7 @@ storagePoolCreateXML(virConnectPtr conn, { virStoragePoolDefPtr def; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr objdef; virStoragePoolPtr pool = NULL; virStorageBackendPtr backend; virObjectEventPtr event = NULL; @@ -690,6 +700,7 @@ storagePoolCreateXML(virConnectPtr conn, if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; def = NULL; + objdef = virStoragePoolObjGetDef(obj); if (backend->buildPool) { if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE) @@ -714,11 +725,10 @@ storagePoolCreateXML(virConnectPtr conn, goto cleanup; } - stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, ".xml"); + stateFile = virFileBuildPath(driver->stateDir, objdef->name, ".xml"); virStoragePoolObjClearVols(obj); - if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + if (!stateFile || virStoragePoolSaveState(stateFile, objdef) < 0 || backend->refreshPool(conn, obj) < 0) { if (stateFile) unlink(stateFile); @@ -729,15 +739,15 @@ storagePoolCreateXML(virConnectPtr conn, goto cleanup; } - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(objdef->name, + objdef->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - VIR_INFO("Creating storage pool '%s'", obj->def->name); - obj->active = true; + VIR_INFO("Creating storage pool '%s'", objdef->name); + virStoragePoolObjSetActive(obj, true); - pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); + pool = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL); cleanup: VIR_FREE(stateFile); @@ -757,6 +767,7 @@ storagePoolDefineXML(virConnectPtr conn, { virStoragePoolDefPtr def; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr objdef; virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL; @@ -783,22 +794,21 @@ storagePoolDefineXML(virConnectPtr conn, if (!(obj = virStoragePoolObjAssignDef(&driver->pools, def))) goto cleanup; + def = NULL; + objdef = virStoragePoolObjGetDef(obj); - if (virStoragePoolObjSaveDef(driver, obj, def) < 0) { + if (virStoragePoolObjSaveDef(driver, obj, objdef) < 0) { virStoragePoolObjRemove(&driver->pools, obj); - def = NULL; obj = NULL; goto cleanup; } - event = virStoragePoolEventLifecycleNew(def->name, def->uuid, + event = virStoragePoolEventLifecycleNew(objdef->name, objdef->uuid, VIR_STORAGE_POOL_EVENT_DEFINED, 0); - def = NULL; - - VIR_INFO("Defining storage pool '%s'", obj->def->name); - pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL); + VIR_INFO("Defining storage pool '%s'", objdef->name); + pool = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL); cleanup: if (event) @@ -814,39 +824,41 @@ static int storagePoolUndefine(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virObjectEventPtr event = NULL; int ret = -1; storageDriverLock(); if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolUndefineEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolUndefineEnsureACL(pool->conn, def) < 0) goto cleanup; if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - obj->def->name); + def->name); goto cleanup; } - if (obj->asyncjobs > 0) { + if (virStoragePoolObjGetAsyncjobs(obj) > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - obj->def->name); + def->name); goto cleanup; } if (virStoragePoolObjDeleteDef(obj) < 0) goto cleanup; - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(def->name, + def->uuid, VIR_STORAGE_POOL_EVENT_UNDEFINED, 0); - VIR_INFO("Undefining storage pool '%s'", obj->def->name); + VIR_INFO("Undefining storage pool '%s'", def->name); virStoragePoolObjRemove(&driver->pools, obj); obj = NULL; ret = 0; @@ -865,6 +877,7 @@ storagePoolCreate(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event = NULL; int ret = -1; @@ -880,17 +893,18 @@ storagePoolCreate(virStoragePoolPtr pool, if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolCreateEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolCreateEnsureACL(pool->conn, def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - obj->def->name); + def->name); goto cleanup; } @@ -907,16 +921,15 @@ storagePoolCreate(virStoragePoolPtr pool, } } - VIR_INFO("Starting up storage pool '%s'", obj->def->name); + VIR_INFO("Starting up storage pool '%s'", def->name); if (backend->startPool && backend->startPool(pool->conn, obj) < 0) goto cleanup; - stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, ".xml"); + stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"); virStoragePoolObjClearVols(obj); - if (!stateFile || virStoragePoolSaveState(stateFile, obj->def) < 0 || + if (!stateFile || virStoragePoolSaveState(stateFile, def) < 0 || backend->refreshPool(pool->conn, obj) < 0) { if (stateFile) unlink(stateFile); @@ -925,12 +938,12 @@ storagePoolCreate(virStoragePoolPtr pool, goto cleanup; } - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(def->name, + def->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - obj->active = true; + virStoragePoolObjSetActive(obj, true); ret = 0; cleanup: @@ -947,22 +960,24 @@ storagePoolBuild(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolBuildEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolBuildEnsureACL(pool->conn, def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is already active"), - obj->def->name); + def->name); goto cleanup; } @@ -981,6 +996,7 @@ static int storagePoolDestroy(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event = NULL; char *stateFile = NULL; @@ -989,31 +1005,30 @@ storagePoolDestroy(virStoragePoolPtr pool) storageDriverLock(); if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolDestroyEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolDestroyEnsureACL(pool->conn, def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; - VIR_INFO("Destroying storage pool '%s'", obj->def->name); + VIR_INFO("Destroying storage pool '%s'", def->name); if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } - if (obj->asyncjobs > 0) { + if (virStoragePoolObjGetAsyncjobs(obj) > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - obj->def->name); + def->name); goto cleanup; } - if (!(stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, - ".xml"))) + if (!(stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"))) goto cleanup; unlink(stateFile); @@ -1025,12 +1040,12 @@ storagePoolDestroy(virStoragePoolPtr pool) virStoragePoolObjClearVols(obj); - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(def->name, + def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - obj->active = false; + virStoragePoolObjSetActive(obj, false); virStoragePoolUpdateInactive(&obj); @@ -1050,38 +1065,38 @@ storagePoolDelete(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; char *stateFile = NULL; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolDeleteEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolDeleteEnsureACL(pool->conn, def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; - VIR_INFO("Deleting storage pool '%s'", obj->def->name); + VIR_INFO("Deleting storage pool '%s'", def->name); if (virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is still active"), - obj->def->name); + def->name); goto cleanup; } - if (obj->asyncjobs > 0) { + if (virStoragePoolObjGetAsyncjobs(obj) > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - obj->def->name); + def->name); goto cleanup; } - if (!(stateFile = virFileBuildPath(driver->stateDir, - obj->def->name, - ".xml"))) + if (!(stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"))) goto cleanup; unlink(stateFile); @@ -1108,6 +1123,7 @@ storagePoolRefresh(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; int ret = -1; virObjectEventPtr event = NULL; @@ -1117,23 +1133,24 @@ storagePoolRefresh(virStoragePoolPtr pool, storageDriverLock(); if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolRefreshEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolRefreshEnsureACL(pool->conn, def) < 0) goto cleanup; - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } - if (obj->asyncjobs > 0) { + if (virStoragePoolObjGetAsyncjobs(obj) > 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("pool '%s' has asynchronous jobs running."), - obj->def->name); + def->name); goto cleanup; } @@ -1142,19 +1159,19 @@ storagePoolRefresh(virStoragePoolPtr pool, if (backend->stopPool) backend->stopPool(pool->conn, obj); - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(def->name, + def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - obj->active = false; + virStoragePoolObjSetActive(obj, false); virStoragePoolUpdateInactive(&obj); goto cleanup; } - event = virStoragePoolEventRefreshNew(obj->def->name, - obj->def->uuid); + event = virStoragePoolEventRefreshNew(def->name, + def->uuid); ret = 0; cleanup: @@ -1172,25 +1189,27 @@ storagePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolGetInfoEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolGetInfoEnsureACL(pool->conn, def) < 0) goto cleanup; - if (virStorageBackendForType(obj->def->type) == NULL) + if (virStorageBackendForType(def->type) == NULL) goto cleanup; memset(info, 0, sizeof(virStoragePoolInfo)); - if (obj->active) + if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else info->state = VIR_STORAGE_POOL_INACTIVE; - info->capacity = obj->def->capacity; - info->allocation = obj->def->allocation; - info->available = obj->def->available; + info->capacity = def->capacity; + info->allocation = def->allocation; + info->available = def->available; ret = 0; cleanup: @@ -1203,6 +1222,8 @@ storagePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr objdef; + virStoragePoolDefPtr newDef; virStoragePoolDefPtr def; char *ret = NULL; @@ -1210,14 +1231,16 @@ storagePoolGetXMLDesc(virStoragePoolPtr pool, if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; + objdef = virStoragePoolObjGetDef(obj); + newDef = virStoragePoolObjGetNewDef(obj); - if (virStoragePoolGetXMLDescEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolGetXMLDescEnsureACL(pool->conn, objdef) < 0) goto cleanup; - if ((flags & VIR_STORAGE_XML_INACTIVE) && obj->newDef) - def = obj->newDef; + if ((flags & VIR_STORAGE_XML_INACTIVE) && newDef) + def = newDef; else - def = obj->def; + def = objdef; ret = virStoragePoolDefFormat(def); @@ -1236,7 +1259,8 @@ storagePoolGetAutostart(virStoragePoolPtr pool, if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; - if (virStoragePoolGetAutostartEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolGetAutostartEnsureACL(pool->conn, + virStoragePoolObjGetDef(obj)) < 0) goto cleanup; *autostart = virStoragePoolObjGetAutostart(obj); @@ -1259,7 +1283,8 @@ storagePoolSetAutostart(virStoragePoolPtr pool, if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) goto cleanup; - if (virStoragePoolSetAutostartEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolSetAutostartEnsureACL(pool->conn, + virStoragePoolObjGetDef(obj)) < 0) goto cleanup; if (virStoragePoolObjSetAutostart(obj, driver->autostartDir, autostart) < 0) @@ -1279,17 +1304,19 @@ static int storagePoolNumOfVolumes(virStoragePoolPtr pool) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolNumOfVolumesEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolNumOfVolumesEnsureACL(pool->conn, def) < 0) goto cleanup; if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } @@ -1308,17 +1335,19 @@ storagePoolListVolumes(virStoragePoolPtr pool, int maxnames) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int n = -1; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolListVolumesEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolListVolumesEnsureACL(pool->conn, def) < 0) goto cleanup; if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } @@ -1337,19 +1366,21 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; virCheckFlags(0, -1); if (!(obj = virStoragePoolObjFromStoragePool(pool))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStoragePoolListAllVolumesEnsureACL(pool->conn, obj->def) < 0) + if (virStoragePoolListAllVolumesEnsureACL(pool->conn, def) < 0) goto cleanup; if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } @@ -1368,15 +1399,17 @@ storageVolLookupByName(virStoragePoolPtr pool, const char *name) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr voldef; virStorageVolPtr vol = NULL; if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; + def = virStoragePoolObjGetDef(obj); if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } @@ -1389,10 +1422,10 @@ storageVolLookupByName(virStoragePoolPtr pool, goto cleanup; } - if (virStorageVolLookupByNameEnsureACL(pool->conn, obj->def, voldef) < 0) + if (virStorageVolLookupByNameEnsureACL(pool->conn, def, voldef) < 0) goto cleanup; - vol = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + vol = virGetStorageVol(pool->conn, def->name, voldef->name, voldef->key, NULL, NULL); cleanup: @@ -1410,26 +1443,26 @@ storageVolLookupByKey(virConnectPtr conn, storageDriverLock(); for (i = 0; i < driver->pools.count && !vol; i++) { - virStoragePoolObjLock(driver->pools.objs[i]); - if (virStoragePoolObjIsActive(driver->pools.objs[i])) { - virStorageVolDefPtr voldef = - virStorageVolDefFindByKey(driver->pools.objs[i], key); + virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStoragePoolDefPtr def; + + virStoragePoolObjLock(obj); + def = virStoragePoolObjGetDef(obj); + if (virStoragePoolObjIsActive(obj)) { + virStorageVolDefPtr voldef = virStorageVolDefFindByKey(obj, key); if (voldef) { - virStoragePoolDefPtr def = driver->pools.objs[i]->def; if (virStorageVolLookupByKeyEnsureACL(conn, def, voldef) < 0) { - virStoragePoolObjUnlock(driver->pools.objs[i]); + virStoragePoolObjUnlock(obj); goto cleanup; } - vol = virGetStorageVol(conn, - def->name, - voldef->name, - voldef->key, + vol = virGetStorageVol(conn, def->name, + voldef->name, voldef->key, NULL, NULL); } } - virStoragePoolObjUnlock(driver->pools.objs[i]); + virStoragePoolObjUnlock(obj); } if (!vol) @@ -1456,17 +1489,19 @@ storageVolLookupByPath(virConnectPtr conn, storageDriverLock(); for (i = 0; i < driver->pools.count && !vol; i++) { virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStoragePoolDefPtr def; virStorageVolDefPtr voldef; char *stable_path = NULL; virStoragePoolObjLock(obj); + def = virStoragePoolObjGetDef(obj); if (!virStoragePoolObjIsActive(obj)) { virStoragePoolObjUnlock(obj); continue; } - switch ((virStoragePoolType) obj->def->type) { + switch ((virStoragePoolType) def->type) { case VIR_STORAGE_POOL_DIR: case VIR_STORAGE_POOL_FS: case VIR_STORAGE_POOL_NETFS: @@ -1484,7 +1519,7 @@ storageVolLookupByPath(virConnectPtr conn, * getting the stable path for some of the pools. */ VIR_WARN("Failed to get stable path for pool '%s'", - obj->def->name); + def->name); virStoragePoolObjUnlock(obj); continue; } @@ -1506,12 +1541,12 @@ storageVolLookupByPath(virConnectPtr conn, VIR_FREE(stable_path); if (voldef) { - if (virStorageVolLookupByPathEnsureACL(conn, obj->def, voldef) < 0) { + if (virStorageVolLookupByPathEnsureACL(conn, def, voldef) < 0) { virStoragePoolObjUnlock(obj); goto cleanup; } - vol = virGetStorageVol(conn, obj->def->name, + vol = virGetStorageVol(conn, def->name, voldef->name, voldef->key, NULL, NULL); } @@ -1551,18 +1586,18 @@ storagePoolLookupByTargetPath(virConnectPtr conn, storageDriverLock(); for (i = 0; i < driver->pools.count && !pool; i++) { virStoragePoolObjPtr obj = driver->pools.objs[i]; + virStoragePoolDefPtr def; virStoragePoolObjLock(obj); + def = virStoragePoolObjGetDef(obj); if (!virStoragePoolObjIsActive(obj)) { virStoragePoolObjUnlock(obj); continue; } - if (STREQ(path, obj->def->target.path)) { - pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, - NULL, NULL); - } + if (STREQ(path, def->target.path)) + pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjUnlock(obj); } @@ -1587,6 +1622,7 @@ storageVolDeleteInternal(virStorageVolPtr vol, unsigned int flags, bool updateMeta) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int ret = -1; if (!backend->deleteVol) { @@ -1604,9 +1640,9 @@ storageVolDeleteInternal(virStorageVolPtr vol, * Ignore the disk backend since it updates the pool values. */ if (updateMeta) { - if (obj->def->type != VIR_STORAGE_POOL_DISK) { - obj->def->allocation -= voldef->target.allocation; - obj->def->available += voldef->target.allocation; + if (def->type != VIR_STORAGE_POOL_DISK) { + def->allocation -= voldef->target.allocation; + def->available += voldef->target.allocation; } } @@ -1624,14 +1660,16 @@ virStorageVolDefFromVol(virStorageVolPtr vol, virStorageBackendPtr *backend) { virStorageVolDefPtr voldef = NULL; + virStoragePoolDefPtr def; if (!(*obj = storagePoolObjFindByName(vol->pool))) return NULL; + def = virStoragePoolObjGetDef(*obj); if (!virStoragePoolObjIsActive(*obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), - (*obj)->def->name); + def->name); goto error; } @@ -1643,7 +1681,7 @@ virStorageVolDefFromVol(virStorageVolPtr vol, } if (backend) { - if (!(*backend = virStorageBackendForType((*obj)->def->type))) + if (!(*backend = virStorageBackendForType(def->type))) goto error; } @@ -1669,7 +1707,8 @@ storageVolDelete(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolDeleteEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolDeleteEnsureACL(vol->conn, virStoragePoolObjGetDef(obj), + voldef) < 0) goto cleanup; if (voldef->in_use) { @@ -1703,6 +1742,7 @@ storageVolCreateXML(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; virStorageVolPtr vol = NULL, volobj = NULL; @@ -1711,17 +1751,18 @@ storageVolCreateXML(virStoragePoolPtr pool, if (!(obj = virStoragePoolObjFromStoragePool(pool))) return NULL; + def = virStoragePoolObjGetDef(obj); if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; - voldef = virStorageVolDefParseString(obj->def, xmldesc, + voldef = virStorageVolDefParseString(def, xmldesc, VIR_VOL_XML_PARSE_OPT_CAPACITY); if (voldef == NULL) goto cleanup; @@ -1733,7 +1774,7 @@ storageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - if (virStorageVolCreateXMLEnsureACL(pool->conn, obj->def, voldef) < 0) + if (virStorageVolCreateXMLEnsureACL(pool->conn, def, voldef) < 0) goto cleanup; if (virStorageVolDefFindByName(obj, voldef->name)) { @@ -1755,7 +1796,7 @@ storageVolCreateXML(virStoragePoolPtr pool, if (backend->createVol(pool->conn, obj, voldef) < 0) goto cleanup; - if (!(volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + if (!(volobj = virGetStorageVol(pool->conn, def->name, voldef->name, voldef->key, NULL, NULL))) goto cleanup; @@ -1779,7 +1820,7 @@ storageVolCreateXML(virStoragePoolPtr pool, memcpy(buildvoldef, voldef, sizeof(*voldef)); /* Drop the pool lock during volume allocation */ - obj->asyncjobs++; + virStoragePoolObjIncrAsyncjobs(obj); voldef->building = true; virStoragePoolObjUnlock(obj); @@ -1792,7 +1833,7 @@ storageVolCreateXML(virStoragePoolPtr pool, storageDriverUnlock(); voldef->building = false; - obj->asyncjobs--; + virStoragePoolObjDecrAsyncjobs(obj); if (buildret < 0) { /* buildVol handles deleting volume on failure */ @@ -1814,13 +1855,13 @@ storageVolCreateXML(virStoragePoolPtr pool, /* Update pool metadata ignoring the disk backend since * it updates the pool values. */ - if (obj->def->type != VIR_STORAGE_POOL_DISK) { - obj->def->allocation += voldef->target.allocation; - obj->def->available -= voldef->target.allocation; + if (def->type != VIR_STORAGE_POOL_DISK) { + def->allocation += voldef->target.allocation; + def->available -= voldef->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, obj->def->name); + volobj->name, def->name); vol = volobj; volobj = NULL; voldef = NULL; @@ -1840,6 +1881,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolObjPtr objsrc = NULL; virStorageBackendPtr backend; virStorageVolDefPtr voldefsrc = NULL; @@ -1869,6 +1911,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, uuidstr, pool->name); goto cleanup; } + def = virStoragePoolObjGetDef(obj); if (STRNEQ(pool->name, volsrc->pool) && !objsrc) { virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -1879,18 +1922,19 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, if (!virStoragePoolObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), obj->def->name); + _("storage pool '%s' is not active"), def->name); goto cleanup; } if (objsrc && !virStoragePoolObjIsActive(objsrc)) { + virStoragePoolDefPtr objsrcdef = virStoragePoolObjGetDef(objsrc); virReportError(VIR_ERR_OPERATION_INVALID, _("storage pool '%s' is not active"), - objsrc->def->name); + objsrcdef->name); goto cleanup; } - if ((backend = virStorageBackendForType(obj->def->type)) == NULL) + if ((backend = virStorageBackendForType(def->type)) == NULL) goto cleanup; voldefsrc = virStorageVolDefFindByName(objsrc ? @@ -1902,12 +1946,12 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - voldef = virStorageVolDefParseString(obj->def, xmldesc, + voldef = virStorageVolDefParseString(def, xmldesc, VIR_VOL_XML_PARSE_NO_CAPACITY); if (voldef == NULL) goto cleanup; - if (virStorageVolCreateXMLFromEnsureACL(pool->conn, obj->def, voldef) < 0) + if (virStorageVolCreateXMLFromEnsureACL(pool->conn, def, voldef) < 0) goto cleanup; if (virStorageVolDefFindByName(obj, voldef->name)) { @@ -1963,7 +2007,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, memcpy(shadowvol, voldef, sizeof(*voldef)); - if (!(volobj = virGetStorageVol(pool->conn, obj->def->name, voldef->name, + if (!(volobj = virGetStorageVol(pool->conn, def->name, voldef->name, voldef->key, NULL, NULL))) goto cleanup; @@ -1972,13 +2016,13 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; /* Drop the pool lock during volume allocation */ - obj->asyncjobs++; + virStoragePoolObjIncrAsyncjobs(obj); voldef->building = true; voldefsrc->in_use++; virStoragePoolObjUnlock(obj); if (objsrc) { - objsrc->asyncjobs++; + virStoragePoolObjIncrAsyncjobs(objsrc); virStoragePoolObjUnlock(objsrc); } @@ -1992,10 +2036,10 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, voldefsrc->in_use--; voldef->building = false; - obj->asyncjobs--; + virStoragePoolObjDecrAsyncjobs(obj); if (objsrc) { - objsrc->asyncjobs--; + virStoragePoolObjDecrAsyncjobs(objsrc); virStoragePoolObjUnlock(objsrc); objsrc = NULL; } @@ -2011,13 +2055,13 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, /* Updating pool metadata ignoring the disk backend since * it updates the pool values */ - if (obj->def->type != VIR_STORAGE_POOL_DISK) { - obj->def->allocation += voldef->target.allocation; - obj->def->available -= voldef->target.allocation; + if (def->type != VIR_STORAGE_POOL_DISK) { + def->allocation += voldef->target.allocation; + def->available -= voldef->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", - volobj->name, obj->def->name); + volobj->name, def->name); vol = volobj; volobj = NULL; voldef = NULL; @@ -2051,7 +2095,8 @@ storageVolDownload(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolDownloadEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolDownloadEnsureACL(vol->conn, virStoragePoolObjGetDef(obj), + voldef) < 0) goto cleanup; if (voldef->building) { @@ -2145,6 +2190,7 @@ virStorageVolPoolRefreshThread(void *opaque) virStorageVolStreamInfoPtr cbdata = opaque; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr def; virStorageBackendPtr backend; virObjectEventPtr event = NULL; @@ -2156,16 +2202,16 @@ virStorageVolPoolRefreshThread(void *opaque) if (!(obj = virStoragePoolObjFindByName(&driver->pools, cbdata->pool_name))) goto cleanup; + def = virStoragePoolObjGetDef(obj); - if (!(backend = virStorageBackendForType(obj->def->type))) + if (!(backend = virStorageBackendForType(def->type))) goto cleanup; virStoragePoolObjClearVols(obj); if (backend->refreshPool(NULL, obj) < 0) VIR_DEBUG("Failed to refresh storage pool"); - event = virStoragePoolEventRefreshNew(obj->def->name, - obj->def->uuid); + event = virStoragePoolEventRefreshNew(def->name, def->uuid); cleanup: if (event) @@ -2210,6 +2256,7 @@ storageVolUpload(virStorageVolPtr vol, { virStorageBackendPtr backend; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr def; virStorageVolDefPtr voldef = NULL; virStorageVolStreamInfoPtr cbdata = NULL; int ret = -1; @@ -2218,8 +2265,9 @@ storageVolUpload(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStorageVolUploadEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolUploadEnsureACL(vol->conn, def, voldef) < 0) goto cleanup; if (voldef->in_use) { @@ -2249,7 +2297,7 @@ storageVolUpload(virStorageVolPtr vol, * routine in order to call the refresh API. */ if (VIR_ALLOC(cbdata) < 0 || - VIR_STRDUP(cbdata->pool_name, obj->def->name) < 0) + VIR_STRDUP(cbdata->pool_name, def->name) < 0) goto cleanup; if (voldef->type == VIR_STORAGE_VOL_PLOOP && VIR_STRDUP(cbdata->vol_path, voldef->target.path) < 0) @@ -2282,6 +2330,7 @@ storageVolResize(virStorageVolPtr vol, { virStorageBackendPtr backend; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr def; virStorageVolDefPtr voldef = NULL; unsigned long long abs_capacity, delta = 0; int ret = -1; @@ -2292,8 +2341,9 @@ storageVolResize(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; + def = virStoragePoolObjGetDef(obj); - if (virStorageVolResizeEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolResizeEnsureACL(vol->conn, def, voldef) < 0) goto cleanup; if (voldef->in_use) { @@ -2338,7 +2388,7 @@ storageVolResize(virStorageVolPtr vol, if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) delta = abs_capacity - voldef->target.allocation; - if (delta > obj->def->available) { + if (delta > def->available) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Not enough space left in storage pool")); goto cleanup; @@ -2361,8 +2411,8 @@ storageVolResize(virStorageVolPtr vol, */ if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) { voldef->target.allocation = abs_capacity; - obj->def->allocation += delta; - obj->def->available -= delta; + def->allocation += delta; + def->available -= delta; } ret = 0; @@ -2396,7 +2446,9 @@ storageVolWipePattern(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolWipePatternEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolWipePatternEnsureACL(vol->conn, + virStoragePoolObjGetDef(obj), + voldef) < 0) goto cleanup; if (voldef->in_use) { @@ -2457,7 +2509,9 @@ storageVolGetInfoFlags(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return -1; - if (virStorageVolGetInfoFlagsEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolGetInfoFlagsEnsureACL(vol->conn, + virStoragePoolObjGetDef(obj), + voldef) < 0) goto cleanup; if (backend->refreshVol && @@ -2492,6 +2546,7 @@ storageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageBackendPtr backend; virStorageVolDefPtr voldef; char *ret = NULL; @@ -2500,15 +2555,16 @@ storageVolGetXMLDesc(virStorageVolPtr vol, if (!(voldef = virStorageVolDefFromVol(vol, &obj, &backend))) return NULL; + def = virStoragePoolObjGetDef(obj); - if (virStorageVolGetXMLDescEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolGetXMLDescEnsureACL(vol->conn, def, voldef) < 0) goto cleanup; if (backend->refreshVol && backend->refreshVol(vol->conn, obj, voldef) < 0) goto cleanup; - ret = virStorageVolDefFormat(obj->def, voldef); + ret = virStorageVolDefFormat(def, voldef); cleanup: virStoragePoolObjUnlock(obj); @@ -2526,7 +2582,8 @@ storageVolGetPath(virStorageVolPtr vol) if (!(voldef = virStorageVolDefFromVol(vol, &obj, NULL))) return NULL; - if (virStorageVolGetPathEnsureACL(vol->conn, obj->def, voldef) < 0) + if (virStorageVolGetPathEnsureACL(vol->conn, virStoragePoolObjGetDef(obj), + voldef) < 0) goto cleanup; ignore_value(VIR_STRDUP(ret, voldef->target.path)); @@ -3484,9 +3541,10 @@ virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr obj, virStorageVolDefPtr voldef) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); char *tmp = NULL; ignore_value(virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX", - driver->stateDir, obj->def->name, voldef->name)); + driver->stateDir, def->name, voldef->name)); return tmp; } -- 2.9.3

In preparation for privatizing the object, use the accessors. Perform some minor code cleanup along the w/r/t spacing, line wraps, etc. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/test/test_driver.c | 186 ++++++++++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 79 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6ea3a5b..af5955d 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1042,6 +1042,7 @@ testOpenVolumesForPool(const char *file, virStoragePoolObjPtr obj, int objidx) { + virStoragePoolDefPtr objdef = virStoragePoolObjGetDef(obj); char *vol_xpath; size_t i; int num, ret = -1; @@ -1063,13 +1064,13 @@ testOpenVolumesForPool(const char *file, if (!node) goto error; - def = virStorageVolDefParseNode(obj->def, ctxt->doc, node, 0); + def = virStorageVolDefParseNode(objdef, ctxt->doc, node, 0); if (!def) goto error; if (def->target.path == NULL) { if (virAsprintf(&def->target.path, "%s/%s", - obj->def->target.path, def->name) < 0) + objdef->target.path, def->name) < 0) goto error; } @@ -1079,8 +1080,8 @@ testOpenVolumesForPool(const char *file, if (virStoragePoolObjAddVol(obj, def) < 0) goto error; - obj->def->allocation += def->target.allocation; - obj->def->available = (obj->def->capacity - obj->def->allocation); + objdef->allocation += def->target.allocation; + objdef->available = (objdef->capacity - objdef->allocation); def = NULL; } @@ -1127,7 +1128,7 @@ testParseStorage(testDriverPtr privconn, virStoragePoolObjUnlock(obj); goto error; } - obj->active = 1; + virStoragePoolObjSetActive(obj, true); /* Find storage volumes */ if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) { @@ -4001,12 +4002,18 @@ testInterfaceDestroy(virInterfacePtr iface, static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj) { + char *configFile; + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); + + def->capacity = defaultPoolCap; + def->allocation = defaultPoolAlloc; + def->available = defaultPoolCap - defaultPoolAlloc; - obj->def->capacity = defaultPoolCap; - obj->def->allocation = defaultPoolAlloc; - obj->def->available = defaultPoolCap - defaultPoolAlloc; + if (VIR_STRDUP(configFile, "") < 0) + return -1; - return VIR_STRDUP(obj->configFile, ""); + virStoragePoolObjSetConfigFile(obj, configFile); + return 0; } @@ -4097,13 +4104,14 @@ testStoragePoolLookupByUUID(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolPtr ret = NULL; if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid))) return NULL; + def = virStoragePoolObjGetDef(obj); - ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, - NULL, NULL); + ret = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjUnlock(obj); return ret; @@ -4116,13 +4124,14 @@ testStoragePoolLookupByName(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStoragePoolPtr ret = NULL; if (!(obj = testStoragePoolObjFindByName(privconn, name))) return NULL; + def = virStoragePoolObjGetDef(obj); - ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, - NULL, NULL); + ret = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjUnlock(obj); return ret; @@ -4248,7 +4257,7 @@ testStoragePoolIsPersistent(virStoragePoolPtr pool) if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid))) return -1; - ret = obj->configFile ? 1 : 0; + ret = virStoragePoolObjGetConfigFile(obj) ? 1 : 0; virStoragePoolObjUnlock(obj); return ret; @@ -4268,7 +4277,7 @@ testStoragePoolCreate(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name))) return -1; - obj->active = 1; + virStoragePoolObjSetActive(obj, true); event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, VIR_STORAGE_POOL_EVENT_STARTED, @@ -4369,6 +4378,8 @@ testStoragePoolCreateXML(virConnectPtr conn, testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr objdef; + char *configFile; virStoragePoolPtr ret = NULL; virObjectEventPtr event = NULL; @@ -4390,15 +4401,16 @@ testStoragePoolCreateXML(virConnectPtr conn, if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; + objdef = virStoragePoolObjGetDef(obj); - if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { + if (objdef->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { /* In the real code, we'd call virVHBAManageVport followed by * find_new_device, but we cannot do that here since we're not * mocking udev. The mock routine will copy an existing vHBA and * rename a few fields to mock that. */ if (testCreateVport(privconn, - obj->def->source.adapter.data.fchost.wwnn, - obj->def->source.adapter.data.fchost.wwpn) < 0) { + objdef->source.adapter.data.fchost.wwnn, + objdef->source.adapter.data.fchost.wwpn) < 0) { virStoragePoolObjRemove(&privconn->pools, obj); obj = NULL; goto cleanup; @@ -4414,16 +4426,17 @@ testStoragePoolCreateXML(virConnectPtr conn, /* *SetDefaults fills this in for the persistent pools, but this * would be a transient pool so remove it; otherwise, the Destroy * code will not Remove the pool */ - VIR_FREE(obj->configFile); + configFile = virStoragePoolObjGetConfigFile(obj); + VIR_FREE(configFile); + virStoragePoolObjSetConfigFile(obj, NULL); - obj->active = 1; + virStoragePoolObjSetActive(obj, true); - event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, + event = virStoragePoolEventLifecycleNew(objdef->name, objdef->uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, - NULL, NULL); + ret = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL); cleanup: virStoragePoolDefFree(def); @@ -4443,6 +4456,7 @@ testStoragePoolDefineXML(virConnectPtr conn, testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr obj = NULL; + virStoragePoolDefPtr objdef; virStoragePoolPtr ret = NULL; virObjectEventPtr event = NULL; @@ -4459,8 +4473,9 @@ testStoragePoolDefineXML(virConnectPtr conn, if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def))) goto cleanup; def = NULL; + objdef = virStoragePoolObjGetDef(obj); - event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid, + event = virStoragePoolEventLifecycleNew(objdef->name, objdef->uuid, VIR_STORAGE_POOL_EVENT_DEFINED, 0); @@ -4470,8 +4485,7 @@ testStoragePoolDefineXML(virConnectPtr conn, goto cleanup; } - ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid, - NULL, NULL); + ret = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL); cleanup: virStoragePoolDefFree(def); @@ -4564,28 +4578,29 @@ testStoragePoolDestroy(virStoragePoolPtr pool) { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; int ret = -1; virObjectEventPtr event = NULL; if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return -1; + def = virStoragePoolObjGetDef(obj); - obj->active = 0; + virStoragePoolObjSetActive(obj, false); - if (obj->def->source.adapter.type == - VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { + if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { if (testDestroyVport(privconn, - obj->def->source.adapter.data.fchost.wwnn, - obj->def->source.adapter.data.fchost.wwpn) < 0) + def->source.adapter.data.fchost.wwnn, + def->source.adapter.data.fchost.wwpn) < 0) goto cleanup; } - event = virStoragePoolEventLifecycleNew(obj->def->name, - obj->def->uuid, + event = virStoragePoolEventLifecycleNew(def->name, + def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - if (obj->configFile == NULL) { + if (!(virStoragePoolObjGetConfigFile(obj))) { virStoragePoolObjRemove(&privconn->pools, obj); obj = NULL; } @@ -4643,18 +4658,20 @@ testStoragePoolGetInfo(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return -1; + def = virStoragePoolObjGetDef(obj); memset(info, 0, sizeof(virStoragePoolInfo)); - if (obj->active) + if (virStoragePoolObjIsActive(obj)) info->state = VIR_STORAGE_POOL_RUNNING; else info->state = VIR_STORAGE_POOL_INACTIVE; - info->capacity = obj->def->capacity; - info->allocation = obj->def->allocation; - info->available = obj->def->available; + info->capacity = def->capacity; + info->allocation = def->allocation; + info->available = def->available; virStoragePoolObjUnlock(obj); return 0; @@ -4674,7 +4691,7 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindByName(privconn, pool->name))) return NULL; - ret = virStoragePoolDefFormat(obj->def); + ret = virStoragePoolDefFormat(virStoragePoolObjGetDef(obj)); virStoragePoolObjUnlock(obj); return ret; @@ -4806,16 +4823,18 @@ testStorageVolLookupByName(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr privvol; virStorageVolPtr ret = NULL; if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return NULL; + def = virStoragePoolObjGetDef(obj); if (!(privvol = testStorageVolDefFindByName(obj, name))) goto cleanup; - ret = virGetStorageVol(pool->conn, obj->def->name, + ret = virGetStorageVol(pool->conn, def->name, privvol->name, privvol->key, NULL, NULL); @@ -4835,22 +4854,23 @@ testStorageVolLookupByKey(virConnectPtr conn, testDriverLock(privconn); for (i = 0; i < privconn->pools.count; i++) { - virStoragePoolObjLock(privconn->pools.objs[i]); - if (virStoragePoolObjIsActive(privconn->pools.objs[i])) { - virStorageVolDefPtr privvol = - virStorageVolDefFindByKey(privconn->pools.objs[i], key); + virStoragePoolObjPtr obj = privconn->pools.objs[i]; + virStoragePoolDefPtr def; + + virStoragePoolObjLock(obj); + def = virStoragePoolObjGetDef(obj); + if (virStoragePoolObjIsActive(obj)) { + virStorageVolDefPtr privvol = virStorageVolDefFindByKey(obj, key); if (privvol) { - ret = virGetStorageVol(conn, - privconn->pools.objs[i]->def->name, - privvol->name, - privvol->key, + ret = virGetStorageVol(conn, def->name, + privvol->name, privvol->key, NULL, NULL); - virStoragePoolObjUnlock(privconn->pools.objs[i]); + virStoragePoolObjUnlock(obj); break; } } - virStoragePoolObjUnlock(privconn->pools.objs[i]); + virStoragePoolObjUnlock(obj); } testDriverUnlock(privconn); @@ -4872,22 +4892,23 @@ testStorageVolLookupByPath(virConnectPtr conn, testDriverLock(privconn); for (i = 0; i < privconn->pools.count; i++) { - virStoragePoolObjLock(privconn->pools.objs[i]); - if (virStoragePoolObjIsActive(privconn->pools.objs[i])) { - virStorageVolDefPtr privvol = - virStorageVolDefFindByPath(privconn->pools.objs[i], path); + virStoragePoolObjPtr obj = privconn->pools.objs[i]; + virStoragePoolDefPtr def; + + virStoragePoolObjLock(obj); + def = virStoragePoolObjGetDef(obj); + if (virStoragePoolObjIsActive(obj)) { + virStorageVolDefPtr privvol = virStorageVolDefFindByPath(obj, path); if (privvol) { - ret = virGetStorageVol(conn, - privconn->pools.objs[i]->def->name, - privvol->name, - privvol->key, + ret = virGetStorageVol(conn, def->name, + privvol->name, privvol->key, NULL, NULL); - virStoragePoolObjUnlock(privconn->pools.objs[i]); + virStoragePoolObjUnlock(obj); break; } } - virStoragePoolObjUnlock(privconn->pools.objs[i]); + virStoragePoolObjUnlock(obj); } testDriverUnlock(privconn); @@ -4906,6 +4927,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr privvol = NULL; virStorageVolPtr ret = NULL; @@ -4913,8 +4935,9 @@ testStorageVolCreateXML(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return NULL; + def = virStoragePoolObjGetDef(obj); - privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); + privvol = virStorageVolDefParseString(def, xmldesc, 0); if (privvol == NULL) goto cleanup; @@ -4925,8 +4948,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, } /* Make sure enough space */ - if ((obj->def->allocation + privvol->target.allocation) > - obj->def->capacity) { + if ((def->allocation + privvol->target.allocation) > + def->capacity) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not enough free space in pool for volume '%s'"), privvol->name); @@ -4934,17 +4957,17 @@ testStorageVolCreateXML(virStoragePoolPtr pool, } if (virAsprintf(&privvol->target.path, "%s/%s", - obj->def->target.path, privvol->name) < 0) + def->target.path, privvol->name) < 0) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || virStoragePoolObjAddVol(obj, privvol) < 0) goto cleanup; - obj->def->allocation += privvol->target.allocation; - obj->def->available = (obj->def->capacity - obj->def->allocation); + def->allocation += privvol->target.allocation; + def->available = (def->capacity - def->allocation); - ret = virGetStorageVol(pool->conn, obj->def->name, + ret = virGetStorageVol(pool->conn, def->name, privvol->name, privvol->key, NULL, NULL); privvol = NULL; @@ -4964,6 +4987,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, { testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr privvol = NULL, origvol = NULL; virStorageVolPtr ret = NULL; @@ -4971,8 +4995,9 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name))) return NULL; + def = virStoragePoolObjGetDef(obj); - privvol = virStorageVolDefParseString(obj->def, xmldesc, 0); + privvol = virStorageVolDefParseString(def, xmldesc, 0); if (privvol == NULL) goto cleanup; @@ -4991,27 +5016,26 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, } /* Make sure enough space */ - if ((obj->def->allocation + privvol->target.allocation) > - obj->def->capacity) { + if ((def->allocation + privvol->target.allocation) > def->capacity) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not enough free space in pool for volume '%s'"), privvol->name); goto cleanup; } - obj->def->available = (obj->def->capacity - obj->def->allocation); + def->available = (def->capacity - def->allocation); if (virAsprintf(&privvol->target.path, "%s/%s", - obj->def->target.path, privvol->name) < 0) + def->target.path, privvol->name) < 0) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || virStoragePoolObjAddVol(obj, privvol) < 0) goto cleanup; - obj->def->allocation += privvol->target.allocation; - obj->def->available = (obj->def->capacity - obj->def->allocation); + def->allocation += privvol->target.allocation; + def->available = (def->capacity - def->allocation); - ret = virGetStorageVol(pool->conn, obj->def->name, + ret = virGetStorageVol(pool->conn, def->name, privvol->name, privvol->key, NULL, NULL); privvol = NULL; @@ -5029,6 +5053,7 @@ testStorageVolDelete(virStorageVolPtr vol, { testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr privvol; int ret = -1; @@ -5036,12 +5061,13 @@ testStorageVolDelete(virStorageVolPtr vol, if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return -1; + def = virStoragePoolObjGetDef(obj); if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - obj->def->allocation -= privvol->target.allocation; - obj->def->available = (obj->def->capacity - obj->def->allocation); + def->allocation -= privvol->target.allocation; + def->available = (def->capacity - def->allocation); virStoragePoolObjRemoveVol(obj, privvol); @@ -5074,17 +5100,19 @@ testStorageVolGetInfo(virStorageVolPtr vol, { testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr obj; + virStoragePoolDefPtr def; virStorageVolDefPtr privvol; int ret = -1; if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool))) return -1; + def = virStoragePoolObjGetDef(obj); if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; memset(info, 0, sizeof(*info)); - info->type = testStorageVolumeTypeForPool(obj->def->type); + info->type = testStorageVolumeTypeForPool(def->type); info->capacity = privvol->target.capacity; info->allocation = privvol->target.allocation; ret = 0; @@ -5112,7 +5140,7 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, if (!(privvol = testStorageVolDefFindByName(obj, vol->name))) goto cleanup; - ret = virStorageVolDefFormat(obj->def, privvol); + ret = virStorageVolDefFormat(virStoragePoolObjGetDef(obj), privvol); cleanup: virStoragePoolObjUnlock(obj); -- 2.9.3

In preparation for privatizing the object, use the accessors. Perform some minor code cleanup along the w/r/t spacing, line wraps, etc. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 116 ++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 8d9dd3f..63ffc53 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -396,6 +396,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); int ret = -1; int fd = -1; int operation_flags; @@ -431,7 +432,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, } operation_flags = VIR_FILE_OPEN_FORCE_MODE | VIR_FILE_OPEN_FORCE_OWNER; - if (pool->def->type == VIR_STORAGE_POOL_NETFS) + if (def->type == VIR_STORAGE_POOL_NETFS) operation_flags |= VIR_FILE_OPEN_FORK; if (vol->target.perms->mode != (mode_t) -1) @@ -597,6 +598,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virCommandPtr cmd) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); struct stat st; gid_t gid; uid_t uid; @@ -606,7 +608,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, bool filecreated = false; int ret = -1; - if ((pool->def->type == VIR_STORAGE_POOL_NETFS) + if ((def->type == VIR_STORAGE_POOL_NETFS) && (((geteuid() == 0) && (vol->target.perms->uid != (uid_t) -1) && (vol->target.perms->uid != 0)) @@ -1029,6 +1031,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool, virStorageVolDefPtr inputvol, struct _virStorageBackendQemuImgInfo *info) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); int accessRetCode = -1; char *absolutePath = NULL; @@ -1071,7 +1074,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool, * validation. */ if ('/' != *(info->backingPath) && - virAsprintf(&absolutePath, "%s/%s", pool->def->target.path, + virAsprintf(&absolutePath, "%s/%s", def->target.path, info->backingPath) < 0) return -1; accessRetCode = access(absolutePath ? absolutePath : @@ -1921,7 +1924,7 @@ virStorageBackendPoolPathIsStable(const char *path) /* * Given a volume path directly in /dev/XXX, iterate over the - * entries in the directory pool->def->target.path and find the + * entries in the directory def->target.path and find the * first symlink pointing to the volume path. * * If, the target.path is /dev/, then return the original volume @@ -1940,6 +1943,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, const char *devpath, bool loop) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); DIR *dh; struct dirent *dent; char *stablepath; @@ -1948,8 +1952,8 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, int direrr; /* Logical pools are under /dev but already have stable paths */ - if (pool->def->type == VIR_STORAGE_POOL_LOGICAL || - !virStorageBackendPoolPathIsStable(pool->def->target.path)) + if (def->type == VIR_STORAGE_POOL_LOGICAL || + !virStorageBackendPoolPathIsStable(def->target.path)) goto ret_strdup; /* We loop here because /dev/disk/by-{id,path} may not have existed @@ -1957,7 +1961,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, * get created. */ reopen: - if (virDirOpenQuiet(&dh, pool->def->target.path) < 0) { + if (virDirOpenQuiet(&dh, def->target.path) < 0) { opentries++; if (loop && errno == ENOENT && opentries < 50) { usleep(100 * 1000); @@ -1965,7 +1969,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, } virReportSystemError(errno, _("cannot read dir '%s'"), - pool->def->target.path); + def->target.path); return NULL; } @@ -1981,8 +1985,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, retry: while ((direrr = virDirRead(dh, &dent, NULL)) > 0) { if (virAsprintf(&stablepath, "%s/%s", - pool->def->target.path, - dent->d_name) < 0) { + def->target.path, dent->d_name) < 0) { VIR_DIR_CLOSE(dh); return NULL; } @@ -2020,6 +2023,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); int err; virCheckFlags(0, -1); @@ -2044,7 +2048,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, vol->target.perms->mode), vol->target.perms->uid, vol->target.perms->gid, - (pool->def->type == VIR_STORAGE_POOL_NETFS + (def->type == VIR_STORAGE_POOL_NETFS ? VIR_DIR_CREATE_AS_UID : 0))) < 0) { return -1; } @@ -2064,6 +2068,8 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + if (vol->target.format == VIR_STORAGE_FILE_DIR) vol->type = VIR_STORAGE_VOL_DIR; else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) @@ -2081,8 +2087,7 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, - vol->name) < 0) + def->target.path, vol->name) < 0) return -1; if (virFileExists(vol->target.path)) { @@ -2767,6 +2772,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, int virStorageBackendBuildLocal(virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); int ret = -1; char *parent = NULL; char *p = NULL; @@ -2774,12 +2780,12 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) bool needs_create_as_uid; unsigned int dir_create_flags; - if (VIR_STRDUP(parent, pool->def->target.path) < 0) + if (VIR_STRDUP(parent, def->target.path) < 0) goto cleanup; if (!(p = strrchr(parent, '/'))) { virReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), - pool->def->target.path); + def->target.path); goto cleanup; } @@ -2795,11 +2801,11 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) } dir_create_flags = VIR_DIR_CREATE_ALLOW_EXIST; - needs_create_as_uid = (pool->def->type == VIR_STORAGE_POOL_NETFS); - mode = pool->def->target.perms.mode; + needs_create_as_uid = (def->type == VIR_STORAGE_POOL_NETFS); + mode = def->target.perms.mode; if (mode == (mode_t) -1 && - (needs_create_as_uid || !virFileExists(pool->def->target.path))) + (needs_create_as_uid || !virFileExists(def->target.path))) mode = VIR_STORAGE_DEFAULT_POOL_PERM_MODE; if (needs_create_as_uid) dir_create_flags |= VIR_DIR_CREATE_AS_UID; @@ -2807,10 +2813,10 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) /* Now create the final dir in the path with the uid/gid/mode * requested in the config. If the dir already exists, just set * the perms. */ - if (virDirCreate(pool->def->target.path, + if (virDirCreate(def->target.path, mode, - pool->def->target.perms.uid, - pool->def->target.perms.gid, + def->target.perms.uid, + def->target.perms.gid, dir_create_flags) < 0) goto cleanup; @@ -2835,14 +2841,16 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, unsigned int flags) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virCheckFlags(0, -1); /* XXX delete all vols first ? */ - if (rmdir(pool->def->target.path) < 0) { + if (rmdir(def->target.path) < 0) { virReportSystemError(errno, _("failed to remove pool '%s'"), - pool->def->target.path); + def->target.path); return -1; } @@ -3522,6 +3530,7 @@ int virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); DIR *dir; struct dirent *ent; struct statvfs sb; @@ -3531,15 +3540,15 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, int direrr; int fd = -1, ret = -1; - if (virDirOpen(&dir, pool->def->target.path) < 0) + if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; - while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) { + while ((direrr = virDirRead(dir, &ent, def->target.path)) > 0) { int err; if (virStringHasControlChars(ent->d_name)) { VIR_WARN("Ignoring file with control characters under '%s'", - pool->def->target.path); + def->target.path); continue; } @@ -3552,8 +3561,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, vol->type = VIR_STORAGE_VOL_FILE; vol->target.format = VIR_STORAGE_FILE_RAW; /* Real value is filled in during probe */ if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, - vol->name) < 0) + def->target.path, vol->name) < 0) goto cleanup; if (VIR_STRDUP(vol->key, vol->target.path) < 0) @@ -3606,17 +3614,17 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, if (VIR_ALLOC(target)) goto cleanup; - if ((fd = open(pool->def->target.path, O_RDONLY)) < 0) { + if ((fd = open(def->target.path, O_RDONLY)) < 0) { virReportSystemError(errno, _("cannot open path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } if (fstat(fd, &statbuf) < 0) { virReportSystemError(errno, _("cannot stat path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } @@ -3624,24 +3632,24 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; /* VolTargetInfoFD doesn't update capacity correctly for the pool case */ - if (statvfs(pool->def->target.path, &sb) < 0) { + if (statvfs(def->target.path, &sb) < 0) { virReportSystemError(errno, _("cannot statvfs path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } - pool->def->capacity = ((unsigned long long)sb.f_frsize * - (unsigned long long)sb.f_blocks); - pool->def->available = ((unsigned long long)sb.f_bfree * - (unsigned long long)sb.f_frsize); - pool->def->allocation = pool->def->capacity - pool->def->available; + def->capacity = ((unsigned long long)sb.f_frsize * + (unsigned long long)sb.f_blocks); + def->available = ((unsigned long long)sb.f_bfree * + (unsigned long long)sb.f_frsize); + def->allocation = def->capacity - def->available; - pool->def->target.perms.mode = target->perms->mode; - pool->def->target.perms.uid = target->perms->uid; - pool->def->target.perms.gid = target->perms->gid; - VIR_FREE(pool->def->target.perms.label); - if (VIR_STRDUP(pool->def->target.perms.label, target->perms->label) < 0) + def->target.perms.mode = target->perms->mode; + def->target.perms.uid = target->perms->uid; + def->target.perms.gid = target->perms->gid; + VIR_FREE(def->target.perms.label); + if (VIR_STRDUP(def->target.perms.label, target->perms->label) < 0) goto cleanup; ret = 0; @@ -3711,6 +3719,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, uint32_t lun, const char *dev) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStorageVolDefPtr vol = NULL; char *devpath = NULL; int retval = -1; @@ -3722,12 +3731,12 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, * path to the device if the virDirRead loop to search the * target pool path for our devpath had failed. */ - if (!virStorageBackendPoolPathIsStable(pool->def->target.path) && - !(STREQ(pool->def->target.path, "/dev") || - STREQ(pool->def->target.path, "/dev/"))) { + if (!virStorageBackendPoolPathIsStable(def->target.path) && + !(STREQ(def->target.path, "/dev") || + STREQ(def->target.path, "/dev/"))) { virReportError(VIR_ERR_INVALID_ARG, _("unable to use target path '%s' for dev '%s'"), - NULLSTR(pool->def->target.path), dev); + NULLSTR(def->target.path), dev); goto cleanup; } @@ -3761,11 +3770,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, goto cleanup; if (STREQ(devpath, vol->target.path) && - !(STREQ(pool->def->target.path, "/dev") || - STREQ(pool->def->target.path, "/dev/"))) { + !(STREQ(def->target.path, "/dev") || + STREQ(def->target.path, "/dev/"))) { VIR_DEBUG("No stable path found for '%s' in '%s'", - devpath, pool->def->target.path); + devpath, def->target.path); retval = -2; goto cleanup; @@ -3780,8 +3789,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, if (!(vol->key = virStorageBackendSCSISerial(vol->target.path))) goto cleanup; - pool->def->capacity += vol->target.capacity; - pool->def->allocation += vol->target.allocation; + def->capacity += vol->target.capacity; + def->allocation += vol->target.allocation; if (virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; @@ -4058,6 +4067,7 @@ int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, uint32_t scanhost) { + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); int retval = 0; uint32_t bus, target, lun; const char *device_path = "/sys/bus/scsi/devices"; @@ -4099,7 +4109,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, if (retval < 0) return -1; - VIR_DEBUG("Found %d LUs for pool %s", found, pool->def->name); + VIR_DEBUG("Found %d LUs for pool %s", found, def->name); return found; } -- 2.9.3

For consistency sake - use @obj as the variable name. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 106 ++++++++++++++++++++++----------------------- src/storage/storage_util.h | 30 ++++++------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 63ffc53..ad05cbf 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -223,7 +223,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, static int storageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) @@ -391,12 +391,12 @@ createRawFile(int fd, virStorageVolDefPtr vol, static int storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int ret = -1; int fd = -1; int operation_flags; @@ -594,11 +594,11 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, } static int -virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, +virStorageBackendCreateExecCommand(virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virCommandPtr cmd) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); struct stat st; gid_t gid; uid_t uid; @@ -696,7 +696,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, * if function fails to create image file the directory will be deleted.*/ static int storageBackendCreatePloop(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) @@ -1026,12 +1026,12 @@ storageBackendCreateQemuImgSetInput(virStorageVolDefPtr inputvol, static int -storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool, +storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, struct _virStorageBackendQemuImgInfo *info) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int accessRetCode = -1; char *absolutePath = NULL; @@ -1151,7 +1151,7 @@ storageBackendCreateQemuImgSecretObject(virCommandPtr cmd, */ virCommandPtr virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags, @@ -1231,7 +1231,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, return NULL; if (vol->target.backingStore && - storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, &info) < 0) + storageBackendCreateQemuImgSetBacking(obj, vol, inputvol, &info) < 0) return NULL; if (info.encryption && @@ -1288,7 +1288,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, static char * storageBackendCreateQemuImgSecretPath(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol) { virStorageEncryptionPtr enc = vol->target.encryption; @@ -1312,7 +1312,7 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn, return NULL; } - if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol))) + if (!(secretPath = virStoragePoolObjBuildTempFilePath(obj, vol))) goto cleanup; if ((fd = mkostemp(secretPath, O_CLOEXEC)) < 0) { @@ -1358,7 +1358,7 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn, static int storageBackendCreateQemuImg(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) @@ -1387,17 +1387,17 @@ storageBackendCreateQemuImg(virConnectPtr conn, vol->target.encryption && vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { if (!(secretPath = - storageBackendCreateQemuImgSecretPath(conn, pool, vol))) + storageBackendCreateQemuImgSecretPath(conn, obj, vol))) goto cleanup; } - cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, pool, vol, inputvol, + cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol, inputvol, flags, create_tool, imgformat, secretPath); if (!cmd) goto cleanup; - ret = virStorageBackendCreateExecCommand(pool, vol, cmd); + ret = virStorageBackendCreateExecCommand(obj, vol, cmd); virCommandFree(cmd); cleanup: @@ -1939,11 +1939,11 @@ virStorageBackendPoolPathIsStable(const char *path) * a change to appear. */ char * -virStorageBackendStablePath(virStoragePoolObjPtr pool, +virStorageBackendStablePath(virStoragePoolObjPtr obj, const char *devpath, bool loop) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); DIR *dh; struct dirent *dent; char *stablepath; @@ -2018,12 +2018,12 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, /* Common/Local File System/Directory Volume API's */ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int err; virCheckFlags(0, -1); @@ -2065,10 +2065,10 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, */ int virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); if (vol->target.format == VIR_STORAGE_FILE_DIR) vol->type = VIR_STORAGE_VOL_DIR; @@ -2104,7 +2104,7 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED, static int storageBackendVolBuildLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) @@ -2133,7 +2133,7 @@ storageBackendVolBuildLocal(virConnectPtr conn, create_func = storageBackendCreateQemuImg; } - if (create_func(conn, pool, vol, inputvol, flags) < 0) + if (create_func(conn, obj, vol, inputvol, flags) < 0) return -1; return 0; } @@ -2146,11 +2146,11 @@ storageBackendVolBuildLocal(virConnectPtr conn, */ int virStorageBackendVolBuildLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, unsigned int flags) { - return storageBackendVolBuildLocal(conn, pool, vol, NULL, flags); + return storageBackendVolBuildLocal(conn, obj, vol, NULL, flags); } @@ -2159,12 +2159,12 @@ virStorageBackendVolBuildLocal(virConnectPtr conn, */ int virStorageBackendVolBuildFromLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags) { - return storageBackendVolBuildLocal(conn, pool, vol, inputvol, flags); + return storageBackendVolBuildLocal(conn, obj, vol, inputvol, flags); } @@ -2173,7 +2173,7 @@ virStorageBackendVolBuildFromLocal(virConnectPtr conn, */ int virStorageBackendVolDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, unsigned int flags) { @@ -2270,7 +2270,7 @@ storageBackendLoadDefaultSecrets(virConnectPtr conn, */ int virStorageBackendVolRefreshLocal(virConnectPtr conn, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol) { int ret; @@ -2323,7 +2323,7 @@ storageBackendResizeQemuImg(const char *path, */ int virStorageBackendVolResizeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, unsigned long long capacity, unsigned int flags) @@ -2395,7 +2395,7 @@ storageBackendPloopHasSnapshots(char *path) int virStorageBackendVolUploadLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, @@ -2441,7 +2441,7 @@ virStorageBackendVolUploadLocal(virConnectPtr conn ATTRIBUTE_UNUSED, int virStorageBackendVolDownloadLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, @@ -2738,7 +2738,7 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol, int virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr obj ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, unsigned int algorithm, unsigned int flags) @@ -2762,7 +2762,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, /** - * @pool: storage pool to build + * @obj: storage pool to build * @dir_create_flags: flags for directory creation * * Common code to build a directory based storage pool @@ -2770,9 +2770,9 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, * Returns 0 on success, -1 on failure */ int -virStorageBackendBuildLocal(virStoragePoolObjPtr pool) +virStorageBackendBuildLocal(virStoragePoolObjPtr obj) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int ret = -1; char *parent = NULL; char *p = NULL; @@ -2830,7 +2830,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) /** * @conn connection to report errors against - * @pool storage pool to delete + * @obj storage pool to delete * * Delete a directory based storage pool * @@ -2838,10 +2838,10 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) */ int virStorageBackendDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, unsigned int flags) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); virCheckFlags(0, -1); @@ -3528,9 +3528,9 @@ storageBackendProbeTarget(virStorageSourcePtr target, */ int virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool) + virStoragePoolObjPtr obj) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); DIR *dir; struct dirent *ent; struct statvfs sb; @@ -3603,7 +3603,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, * An error message was raised, but we just continue. */ } - if (virStoragePoolObjAddVol(pool, vol) < 0) + if (virStoragePoolObjAddVol(obj, vol) < 0) goto cleanup; } if (direrr < 0) @@ -3659,7 +3659,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageVolDefFree(vol); virStorageSourceFree(target); if (ret < 0) - virStoragePoolObjClearVols(pool); + virStoragePoolObjClearVols(obj); return ret; } @@ -3712,14 +3712,14 @@ virStorageBackendSCSISerial(const char *dev) * -2 => Failure to find a stable path, not fatal, caller can try another */ static int -virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, +virStorageBackendSCSINewLun(virStoragePoolObjPtr obj, uint32_t host ATTRIBUTE_UNUSED, uint32_t bus, uint32_t target, uint32_t lun, const char *dev) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); virStorageVolDefPtr vol = NULL; char *devpath = NULL; int retval = -1; @@ -3764,7 +3764,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, * dir every time its run. Should figure out a more efficient * way of doing this... */ - if ((vol->target.path = virStorageBackendStablePath(pool, + if ((vol->target.path = virStorageBackendStablePath(obj, devpath, true)) == NULL) goto cleanup; @@ -3792,7 +3792,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, def->capacity += vol->target.capacity; def->allocation += vol->target.allocation; - if (virStoragePoolObjAddVol(pool, vol) < 0) + if (virStoragePoolObjAddVol(obj, vol) < 0) goto cleanup; vol = NULL; @@ -4011,7 +4011,7 @@ getDeviceType(uint32_t host, * -2 => non-fatal error or a non-disk entry */ static int -processLU(virStoragePoolObjPtr pool, +processLU(virStoragePoolObjPtr obj, uint32_t host, uint32_t bus, uint32_t target, @@ -4046,7 +4046,7 @@ processLU(virStoragePoolObjPtr pool, return retval; } - retval = virStorageBackendSCSINewLun(pool, host, bus, target, lun, + retval = virStorageBackendSCSINewLun(obj, host, bus, target, lun, block_device); if (retval < 0) { VIR_DEBUG("Failed to create new storage volume for %u:%u:%u:%u", @@ -4064,10 +4064,10 @@ processLU(virStoragePoolObjPtr pool, int -virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, +virStorageBackendSCSIFindLUs(virStoragePoolObjPtr obj, uint32_t scanhost) { - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); int retval = 0; uint32_t bus, target, lun; const char *device_path = "/sys/bus/scsi/devices"; @@ -4095,7 +4095,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, VIR_DEBUG("Found possible LU '%s'", lun_dirent->d_name); - rc = processLU(pool, scanhost, bus, target, lun); + rc = processLU(obj, scanhost, bus, target, lun); if (rc == -1) { retval = -1; break; diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h index a05c35d..106a3ae 100644 --- a/src/storage/storage_util.h +++ b/src/storage/storage_util.h @@ -32,37 +32,37 @@ virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, virStorageVolDefPtr inputvol); int virStorageBackendVolCreateLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol); int virStorageBackendVolBuildLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, unsigned int flags); int virStorageBackendVolBuildFromLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags); int virStorageBackendVolDeleteLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, unsigned int flags); int virStorageBackendVolRefreshLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol); int virStorageBackendVolResizeLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, unsigned long long capacity, unsigned int flags); int virStorageBackendVolUploadLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, @@ -70,7 +70,7 @@ int virStorageBackendVolUploadLocal(virConnectPtr conn, unsigned int flags); int virStorageBackendVolDownloadLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, @@ -78,20 +78,20 @@ int virStorageBackendVolDownloadLocal(virConnectPtr conn, unsigned int flags); int virStorageBackendVolWipeLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, unsigned int algorithm, unsigned int flags); /* Local/Common Storage Pool Backend APIs */ -int virStorageBackendBuildLocal(virStoragePoolObjPtr pool); +int virStorageBackendBuildLocal(virStoragePoolObjPtr obj); int virStorageBackendDeleteLocal(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, unsigned int flags); int virStorageBackendRefreshLocal(virConnectPtr conn, - virStoragePoolObjPtr pool); + virStoragePoolObjPtr obj); int virStorageUtilGlusterExtractPoolSources(const char *host, const char *xml, @@ -150,13 +150,13 @@ int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target, struct stat *sb); bool virStorageBackendPoolPathIsStable(const char *path); -char *virStorageBackendStablePath(virStoragePoolObjPtr pool, +char *virStorageBackendStablePath(virStoragePoolObjPtr obj, const char *devpath, bool loop); virCommandPtr virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, - virStoragePoolObjPtr pool, + virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, unsigned int flags, @@ -164,7 +164,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, int imgformat, const char *secretPath); -int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, +int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr obj, uint32_t scanhost); int -- 2.9.3

ping? Tks - John On 05/09/2017 11:30 AM, John Ferlan wrote:
Begin the process of making adjustments to the storage pool and volume code in order to privatize the virStoragePoolObj and virStoragePoolObjList
Didn't want to post 40+ patches at one time... This is the first storage pile including some test driver cleanups w/r/t storage code.
John Ferlan (19): test: Fix up formatting in storage test API's test: Use consistent variable names for storage test driver APIs test: Cleanup exit/failure paths of some storage pool APIs test: Add helpers to fetch active/inactive storage pool by name test: Add testStorageVolDefFindByName for storage volume tests storage: Fix return value checks for virAsprintf storage: Use consistent variable names in virstorageobj storage: Use consistent variable names for driver storage: Alter volume num, name, and export API's to just take obj storage: Create accessor API's for virStoragePoolObj storage: Introduce virStoragePoolObjNew storage: Introduce virStoragePoolObj{Get|Set}Autostart storage: Move autostartLink deletion to virstorageobj storage: Introduce storage volume add, delete, count APIs storage: Introduce virStoragePoolObjForEachVolume storage: Use virStoragePoolObj accessors for driver storage: Use virStoragePoolObj accessors for storage test API's storage: Use virStoragePoolObj accessors for storage_util storage: Change storage_util to use obj instead of pool
src/conf/virstorageobj.c | 568 +++++++++----- src/conf/virstorageobj.h | 84 +- src/libvirt_private.syms | 16 + src/storage/storage_backend_disk.c | 31 +- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_backend_logical.c | 5 +- src/storage/storage_backend_mpath.c | 3 +- src/storage/storage_backend_rbd.c | 12 +- src/storage/storage_backend_sheepdog.c | 8 +- src/storage/storage_backend_zfs.c | 9 +- src/storage/storage_driver.c | 1308 ++++++++++++++++---------------- src/storage/storage_driver.h | 4 +- src/storage/storage_util.c | 200 ++--- src/storage/storage_util.h | 30 +- src/test/test_driver.c | 780 +++++++++---------- 15 files changed, 1614 insertions(+), 1447 deletions(-)
participants (3)
-
John Ferlan
-
Pavel Hrdina
-
Peter Krempa