This patch reduces the number of return points in the storage driver
methods
storage_driver.c | 570 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 313 insertions(+), 257 deletions(-)
Daniel
diff --git a/src/storage_driver.c b/src/storage_driver.c
--- a/src/storage_driver.c
+++ b/src/storage_driver.c
@@ -254,36 +254,40 @@ static virStoragePoolPtr
static virStoragePoolPtr
storagePoolLookupByUUID(virConnectPtr conn,
const unsigned char *uuid) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
uuid);
- virStoragePoolPtr ret;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ virStoragePoolPtr ret = NULL;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, uuid);
if (!pool) {
virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL,
"%s", _("no pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
+
+cleanup:
return ret;
}
static virStoragePoolPtr
storagePoolLookupByName(virConnectPtr conn,
const char *name) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByName(&driver->pools,
name);
- virStoragePoolPtr ret;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ virStoragePoolPtr ret = NULL;
+ pool = virStoragePoolObjFindByName(&driver->pools, name);
if (!pool) {
virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL,
"%s", _("no pool with matching
name"));
- return NULL;
+ goto cleanup;
}
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
+
+cleanup:
return ret;
}
@@ -311,8 +315,7 @@ storageClose(virConnectPtr conn) {
static int
storageNumPools(virConnectPtr conn) {
- virStorageDriverStatePtr driver
- = (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
unsigned int i, nactive = 0;
for (i = 0 ; i < driver->pools.count ; i++)
@@ -326,8 +329,7 @@ storageListPools(virConnectPtr conn,
storageListPools(virConnectPtr conn,
char **const names,
int nnames) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
int got = 0, i;
for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
@@ -353,8 +355,7 @@ storageListPools(virConnectPtr conn,
static int
storageNumDefinedPools(virConnectPtr conn) {
- virStorageDriverStatePtr driver
- = (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
unsigned int i, nactive = 0;
for (i = 0 ; i < driver->pools.count ; i++)
@@ -368,8 +369,7 @@ storageListDefinedPools(virConnectPtr co
storageListDefinedPools(virConnectPtr conn,
char **const names,
int nnames) {
- virStorageDriverStatePtr driver
- = (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
int got = 0, i;
for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
@@ -401,19 +401,21 @@ storageFindPoolSources(virConnectPtr con
{
int backend_type;
virStorageBackendPtr backend;
+ char *ret = NULL;
backend_type = virStoragePoolTypeFromString(type);
if (backend_type < 0)
- return NULL;
+ goto cleanup;
backend = virStorageBackendForType(backend_type);
if (backend == NULL)
- return NULL;
+ goto cleanup;
if (backend->findPoolSources)
- return backend->findPoolSources(conn, srcSpec, flags);
+ ret = backend->findPoolSources(conn, srcSpec, flags);
- return NULL;
+cleanup:
+ return ret;
}
@@ -421,46 +423,47 @@ storagePoolCreate(virConnectPtr conn,
storagePoolCreate(virConnectPtr conn,
const char *xml,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr )conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
virStoragePoolDefPtr def;
virStoragePoolObjPtr pool;
- virStoragePoolPtr ret;
+ virStoragePoolPtr ret = NULL;
virStorageBackendPtr backend;
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
- return NULL;
+ goto cleanup;
- if (virStoragePoolObjFindByUUID(&driver->pools, def->uuid) ||
- virStoragePoolObjFindByName(&driver->pools, def->name)) {
+ pool = virStoragePoolObjFindByUUID(&driver->pools, def->uuid);
+ if (!pool)
+ pool = virStoragePoolObjFindByName(&driver->pools, def->name);
+
+ if (pool) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool already
exists"));
- virStoragePoolDefFree(def);
- return NULL;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(def->type)) == NULL) {
- virStoragePoolDefFree(def);
- return NULL;
- }
+ if ((backend = virStorageBackendForType(def->type)) == NULL)
+ goto cleanup;
- if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def))) {
- virStoragePoolDefFree(def);
- return NULL;
- }
+ if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def)))
+ goto cleanup;
+ def = NULL;
if (backend->startPool &&
backend->startPool(conn, pool) < 0)
- return NULL;
+ goto cleanup;
+
if (backend->refreshPool(conn, pool) < 0) {
if (backend->stopPool)
backend->stopPool(conn, pool);
- return NULL;
+ goto cleanup;
}
pool->active = 1;
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
+cleanup:
+ virStoragePoolDefFree(def);
return ret;
}
@@ -468,55 +471,55 @@ storagePoolDefine(virConnectPtr conn,
storagePoolDefine(virConnectPtr conn,
const char *xml,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver
- = (virStorageDriverStatePtr )conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
virStoragePoolDefPtr def;
virStoragePoolObjPtr pool;
- virStoragePoolPtr ret;
+ virStoragePoolPtr ret = NULL;
virStorageBackendPtr backend;
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
- return NULL;
+ goto cleanup;
- if ((backend = virStorageBackendForType(def->type)) == NULL) {
- virStoragePoolDefFree(def);
- return NULL;
- }
+ if ((backend = virStorageBackendForType(def->type)) == NULL)
+ goto cleanup;
- if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def))) {
- virStoragePoolDefFree(def);
- return NULL;
- }
+ if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def)))
+ goto cleanup;
+ def = NULL;
if (virStoragePoolObjSaveDef(conn, driver, pool, def) < 0) {
virStoragePoolObjRemove(&driver->pools, pool);
- return NULL;
+ goto cleanup;
}
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
+
+cleanup:
+ virStoragePoolDefFree(def);
return ret;
}
static int
storagePoolUndefine(virStoragePoolPtr obj) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("pool is still active"));
- return -1;
+ goto cleanup;
}
if (virStoragePoolObjDeleteDef(obj->conn, pool) < 0)
- return -1;
+ goto cleanup;
if (unlink(pool->autostartLink) < 0 && errno != ENOENT && errno
!= ENOTDIR)
storageLog("Failed to delete autostart link '%s': %s",
@@ -526,105 +529,112 @@ storagePoolUndefine(virStoragePoolPtr ob
VIR_FREE(pool->autostartLink);
virStoragePoolObjRemove(&driver->pools, pool);
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolStart(virStoragePoolPtr obj,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
if (virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("pool already active"));
- return -1;
+ goto cleanup;
}
if (backend->startPool &&
backend->startPool(obj->conn, pool) < 0)
- return -1;
+ goto cleanup;
+
if (backend->refreshPool(obj->conn, pool) < 0) {
if (backend->stopPool)
backend->stopPool(obj->conn, pool);
- return -1;
+ goto cleanup;
}
pool->active = 1;
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolBuild(virStoragePoolPtr obj,
unsigned int flags) {
- virStorageDriverStatePtr driver
- = (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
if (virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is already
active"));
- return -1;
+ goto cleanup;
}
if (backend->buildPool &&
backend->buildPool(obj->conn, pool, flags) < 0)
- return -1;
+ goto cleanup;
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolDestroy(virStoragePoolPtr obj) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
if (backend->stopPool &&
backend->stopPool(obj->conn, pool) < 0)
- return -1;
+ goto cleanup;
virStoragePoolObjClearVols(pool);
@@ -632,74 +642,77 @@ storagePoolDestroy(virStoragePoolPtr obj
if (pool->configFile == NULL)
virStoragePoolObjRemove(&driver->pools, pool);
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolDelete(virStoragePoolPtr obj,
unsigned int flags) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
if (virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is still
active"));
- return -1;
+ goto cleanup;
}
if (!backend->deletePool) {
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
"%s", _("pool does not support volume
delete"));
- return -1;
+ goto cleanup;
}
if (backend->deletePool(obj->conn, pool, flags) < 0)
- return -1;
+ goto cleanup;
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolRefresh(virStoragePoolPtr obj,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
- int ret = 0;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
virStoragePoolObjClearVols(pool);
- if ((ret = backend->refreshPool(obj->conn, pool)) < 0) {
+ if (backend->refreshPool(obj->conn, pool) < 0) {
if (backend->stopPool)
backend->stopPool(obj->conn, pool);
@@ -707,8 +720,11 @@ storagePoolRefresh(virStoragePoolPtr obj
if (pool->configFile == NULL)
virStoragePoolObjRemove(&driver->pools, pool);
+ goto cleanup;
}
+ ret = 0;
+cleanup:
return ret;
}
@@ -716,20 +732,20 @@ static int
static int
storagePoolGetInfo(virStoragePoolPtr obj,
virStoragePoolInfoPtr info) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
- if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
- return -1;
- }
+ if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
+ goto cleanup;
memset(info, 0, sizeof(virStoragePoolInfo));
if (pool->active)
@@ -739,37 +755,44 @@ storagePoolGetInfo(virStoragePoolPtr obj
info->capacity = pool->def->capacity;
info->allocation = pool->def->allocation;
info->available = pool->def->available;
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static char *
storagePoolDumpXML(virStoragePoolPtr obj,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ char *ret = NULL;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
- return virStoragePoolDefFormat(obj->conn, pool->def);
+ ret = virStoragePoolDefFormat(obj->conn, pool->def);
+
+cleanup:
+ return ret;
}
static int
storagePoolGetAutostart(virStoragePoolPtr obj,
int *autostart) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!pool->configFile) {
@@ -777,110 +800,118 @@ storagePoolGetAutostart(virStoragePoolPt
} else {
*autostart = pool->autostart;
}
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolSetAutostart(virStoragePoolPtr obj,
int autostart) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!pool->configFile) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_ARG,
"%s", _("pool has no config file"));
- return -1;
+ goto cleanup;
}
autostart = (autostart != 0);
- if (pool->autostart == autostart)
- return 0;
+ if (pool->autostart != autostart) {
+ if (autostart) {
+ int err;
- if (autostart) {
- int err;
+ if ((err = virFileMakePath(driver->autostartDir))) {
+ virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
+ _("cannot create autostart directory %s:
%s"),
+ driver->autostartDir, strerror(err));
+ goto cleanup;
+ }
- if ((err = virFileMakePath(driver->autostartDir))) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot create autostart directory %s:
%s"),
- driver->autostartDir, strerror(err));
- return -1;
+ if (symlink(pool->configFile, pool->autostartLink) < 0) {
+ virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Failed to create symlink '%s' to
'%s': %s"),
+ pool->autostartLink, pool->configFile,
+ strerror(errno));
+ goto cleanup;
+ }
+ } else {
+ if (unlink(pool->autostartLink) < 0 &&
+ errno != ENOENT && errno != ENOTDIR) {
+ virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
+ _("Failed to delete symlink '%s':
%s"),
+ pool->autostartLink, strerror(errno));
+ goto cleanup;
+ }
}
- if (symlink(pool->configFile, pool->autostartLink) < 0) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to create symlink '%s' to
'%s': %s"),
- pool->autostartLink, pool->configFile,
- strerror(errno));
- return -1;
- }
- } else {
- if (unlink(pool->autostartLink) < 0 &&
- errno != ENOENT && errno != ENOTDIR) {
- virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
- _("Failed to delete symlink '%s':
%s"),
- pool->autostartLink, strerror(errno));
- return -1;
- }
+ pool->autostart = autostart;
}
+ ret = 0;
- pool->autostart = autostart;
-
- return 0;
+cleanup:
+ return ret;
}
static int
storagePoolNumVolumes(virStoragePoolPtr obj) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
+ int ret = -1;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
+ ret = pool->volumes.count;
- return pool->volumes.count;
+cleanup:
+ return ret;
}
static int
storagePoolListVolumes(virStoragePoolPtr obj,
char **const names,
int maxnames) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
int i, n = 0;
+ memset(names, 0, maxnames);
+
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
- memset(names, 0, maxnames);
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY,
@@ -893,7 +924,7 @@ storagePoolListVolumes(virStoragePoolPtr
cleanup:
for (n = 0 ; n < maxnames ; n++)
- VIR_FREE(names[i]);
+ VIR_FREE(names[n]);
memset(names, 0, maxnames);
return -1;
@@ -903,21 +934,22 @@ static virStorageVolPtr
static virStorageVolPtr
storageVolumeLookupByName(virStoragePoolPtr obj,
const char *name) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageVolDefPtr vol;
+ virStorageVolPtr ret = NULL;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return NULL;
+ goto cleanup;
}
vol = virStorageVolDefFindByName(pool, name);
@@ -925,44 +957,51 @@ storageVolumeLookupByName(virStoragePool
if (!vol) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage vol with matching
name"));
- return NULL;
+ goto cleanup;
}
- return virGetStorageVol(obj->conn, pool->def->name, vol->name,
vol->key);
+ ret = virGetStorageVol(obj->conn, pool->def->name, vol->name,
vol->key);
+
+cleanup:
+ return ret;
}
static virStorageVolPtr
storageVolumeLookupByKey(virConnectPtr conn,
const char *key) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
unsigned int i;
+ virStorageVolPtr ret = NULL;
for (i = 0 ; i < driver->pools.count ; i++) {
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
virStorageVolDefPtr vol =
virStorageVolDefFindByKey(driver->pools.objs[i], key);
- if (vol)
- return virGetStorageVol(conn,
+ if (vol) {
+ ret = virGetStorageVol(conn,
driver->pools.objs[i]->def->name,
vol->name,
vol->key);
+ break;
+ }
}
}
- virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
- "%s", _("no storage vol with matching
key"));
- return NULL;
+ if (!ret)
+ virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
+ "%s", _("no storage vol with matching
key"));
+
+ return ret;
}
static virStorageVolPtr
storageVolumeLookupByPath(virConnectPtr conn,
const char *path) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)conn->storagePrivateData;
+ virStorageDriverStatePtr driver = conn->storagePrivateData;
unsigned int i;
+ virStorageVolPtr ret = NULL;
for (i = 0 ; i < driver->pools.count ; i++) {
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
@@ -978,132 +1017,140 @@ storageVolumeLookupByPath(virConnectPtr
* propagating the return code
*/
if (stable_path == NULL)
- return NULL;
+ goto cleanup;
vol = virStorageVolDefFindByPath(driver->pools.objs[i],
stable_path);
VIR_FREE(stable_path);
- if (vol)
- return virGetStorageVol(conn,
- driver->pools.objs[i]->def->name,
- vol->name,
- vol->key);
+ if (vol) {
+ ret = virGetStorageVol(conn,
+ driver->pools.objs[i]->def->name,
+ vol->name,
+ vol->key);
+ break;
+ }
}
}
- virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
- "%s", _("no storage vol with matching
path"));
- return NULL;
+ if (!ret)
+ virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
+ "%s", _("no storage vol with matching
path"));
+
+cleanup:
+ return ret;
}
static virStorageVolPtr
storageVolumeCreateXML(virStoragePoolPtr obj,
const char *xmldesc,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByUUID(&driver->pools,
obj->uuid);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
- virStorageVolDefPtr vol;
+ virStorageVolDefPtr vol = NULL;
+ virStorageVolPtr ret = NULL;
+ pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return NULL;
+ goto cleanup;
}
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
- return NULL;
+ goto cleanup;
vol = virStorageVolDefParse(obj->conn, pool->def, xmldesc, NULL);
if (vol == NULL)
- return NULL;
+ goto cleanup;
if (virStorageVolDefFindByName(pool, vol->name)) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("storage vol already
exists"));
- virStorageVolDefFree(vol);
- return NULL;
+ goto cleanup;
}
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) {
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, NULL);
- virStorageVolDefFree(vol);
- return NULL;
+ goto cleanup;
}
if (!backend->createVol) {
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
"%s", _("storage pool does not support
volume creation"));
- virStorageVolDefFree(vol);
- return NULL;
+ goto cleanup;
}
if (backend->createVol(obj->conn, pool, vol) < 0) {
- virStorageVolDefFree(vol);
- return NULL;
+ goto cleanup;
}
pool->volumes.objs[pool->volumes.count++] = vol;
+ vol = NULL;
- return virGetStorageVol(obj->conn, pool->def->name, vol->name,
vol->key);
+ ret = virGetStorageVol(obj->conn, pool->def->name, vol->name,
vol->key);
+
+cleanup:
+ virStorageVolDefFree(vol);
+ return ret;
}
static int
storageVolumeDelete(virStorageVolPtr obj,
unsigned int flags) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByName(&driver->pools,
obj->pool);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
- virStorageVolDefPtr vol;
+ virStorageVolDefPtr vol = NULL;
unsigned int i;
+ int ret = -1;
+ pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
- return -1;
+ goto cleanup;
vol = virStorageVolDefFindByName(pool, obj->name);
if (!vol) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage vol with matching
name"));
- return -1;
+ goto cleanup;
}
if (!backend->deleteVol) {
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
"%s", _("storage pool does not support vol
deletion"));
- virStorageVolDefFree(vol);
- return -1;
+
+ goto cleanup;
}
- if (backend->deleteVol(obj->conn, pool, vol, flags) < 0) {
- return -1;
- }
+ if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
+ goto cleanup;
for (i = 0 ; i < pool->volumes.count ; i++) {
if (pool->volumes.objs[i] == vol) {
virStorageVolDefFree(vol);
+ vol = NULL;
if (i < (pool->volumes.count - 1))
memmove(pool->volumes.objs + i, pool->volumes.objs + i + 1,
@@ -1117,29 +1164,33 @@ storageVolumeDelete(virStorageVolPtr obj
break;
}
}
+ ret = 0;
- return 0;
+cleanup:
+ virStorageVolDefFree(vol);
+ return ret;
}
static int
storageVolumeGetInfo(virStorageVolPtr obj,
virStorageVolInfoPtr info) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByName(&driver->pools,
obj->pool);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
virStorageVolDefPtr vol;
+ int ret = -1;
+ pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return -1;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return -1;
+ goto cleanup;
}
vol = virStorageVolDefFindByName(pool, obj->name);
@@ -1147,43 +1198,46 @@ storageVolumeGetInfo(virStorageVolPtr ob
if (!vol) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage vol with matching
name"));
- return -1;
+ goto cleanup;
}
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
- return -1;
+ goto cleanup;
if (backend->refreshVol &&
backend->refreshVol(obj->conn, pool, vol) < 0)
- return -1;
+ goto cleanup;
memset(info, 0, sizeof(*info));
info->type = vol->type;
info->capacity = vol->capacity;
info->allocation = vol->allocation;
+ ret = 0;
- return 0;
+cleanup:
+ return ret;
}
static char *
storageVolumeGetXMLDesc(virStorageVolPtr obj,
unsigned int flags ATTRIBUTE_UNUSED) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
- virStoragePoolObjPtr pool = virStoragePoolObjFindByName(&driver->pools,
obj->pool);
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
+ virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
virStorageVolDefPtr vol;
+ char *ret = NULL;
+ pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return NULL;
+ goto cleanup;
}
vol = virStorageVolDefFindByName(pool, obj->name);
@@ -1191,33 +1245,35 @@ storageVolumeGetXMLDesc(virStorageVolPtr
if (!vol) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage vol with matching
name"));
- return NULL;
+ goto cleanup;
}
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
- return NULL;
+ goto cleanup;
- return virStorageVolDefFormat(obj->conn, pool->def, vol);
+ ret = virStorageVolDefFormat(obj->conn, pool->def, vol);
+
+cleanup:
+ return ret;
}
static char *
storageVolumeGetPath(virStorageVolPtr obj) {
- virStorageDriverStatePtr driver =
- (virStorageDriverStatePtr)obj->conn->storagePrivateData;
+ virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
virStoragePoolObjPtr pool = virStoragePoolObjFindByName(&driver->pools,
obj->pool);
virStorageVolDefPtr vol;
- char *ret;
+ char *ret = NULL;
if (!pool) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage pool with matching
uuid"));
- return NULL;
+ goto cleanup;
}
if (!virStoragePoolObjIsActive(pool)) {
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool is not
active"));
- return NULL;
+ goto cleanup;
}
vol = virStorageVolDefFindByName(pool, obj->name);
@@ -1225,14 +1281,14 @@ storageVolumeGetPath(virStorageVolPtr ob
if (!vol) {
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
"%s", _("no storage vol with matching
name"));
- return NULL;
+ goto cleanup;
}
ret = strdup(vol->target.path);
- if (ret == NULL) {
+ if (ret == NULL)
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, "%s",
_("path"));
- return NULL;
- }
+
+cleanup:
return ret;
}
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|