提交 38362460 编写于 作者: J John Ferlan

storage: Use VIR_AUTOFREE for storage driver

Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 50287816
...@@ -122,7 +122,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, ...@@ -122,7 +122,7 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj,
virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
bool active = false; bool active = false;
virStorageBackendPtr backend; virStorageBackendPtr backend;
char *stateFile; VIR_AUTOFREE(char *) stateFile = NULL;
if ((backend = virStorageBackendForType(def->type)) == NULL) { if ((backend = virStorageBackendForType(def->type)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -164,8 +164,6 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj, ...@@ -164,8 +164,6 @@ storagePoolUpdateStateCallback(virStoragePoolObjPtr obj,
if (!virStoragePoolObjIsActive(obj)) if (!virStoragePoolObjIsActive(obj))
virStoragePoolUpdateInactive(&obj); virStoragePoolUpdateInactive(&obj);
VIR_FREE(stateFile);
return; return;
} }
...@@ -203,7 +201,7 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, ...@@ -203,7 +201,7 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj,
} }
if (started) { if (started) {
char *stateFile; VIR_AUTOFREE(char *) stateFile = NULL;
virStoragePoolObjClearVols(obj); virStoragePoolObjClearVols(obj);
stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"); stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
...@@ -217,7 +215,6 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj, ...@@ -217,7 +215,6 @@ storageDriverAutostartCallback(virStoragePoolObjPtr obj,
} else { } else {
virStoragePoolObjSetActive(obj, true); virStoragePoolObjSetActive(obj, true);
} }
VIR_FREE(stateFile);
} }
} }
...@@ -240,16 +237,15 @@ storageStateInitialize(bool privileged, ...@@ -240,16 +237,15 @@ storageStateInitialize(bool privileged,
virStateInhibitCallback callback ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED) void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1; VIR_AUTOFREE(char *) configdir = NULL;
char *configdir = NULL; VIR_AUTOFREE(char *) rundir = NULL;
char *rundir = NULL;
if (VIR_ALLOC(driver) < 0) if (VIR_ALLOC(driver) < 0)
return ret; return -1;
if (virMutexInit(&driver->lock) < 0) { if (virMutexInit(&driver->lock) < 0) {
VIR_FREE(driver); VIR_FREE(driver);
return ret; return -1;
} }
storageDriverLock(); storageDriverLock();
...@@ -302,16 +298,12 @@ storageStateInitialize(bool privileged, ...@@ -302,16 +298,12 @@ storageStateInitialize(bool privileged,
storageDriverUnlock(); storageDriverUnlock();
ret = 0; return 0;
cleanup:
VIR_FREE(configdir);
VIR_FREE(rundir);
return ret;
error: error:
storageDriverUnlock(); storageDriverUnlock();
storageStateCleanup(); storageStateCleanup();
goto cleanup; return -1;
} }
/** /**
...@@ -695,9 +687,9 @@ storagePoolCreateXML(virConnectPtr conn, ...@@ -695,9 +687,9 @@ storagePoolCreateXML(virConnectPtr conn,
virStoragePoolPtr pool = NULL; virStoragePoolPtr pool = NULL;
virStorageBackendPtr backend; virStorageBackendPtr backend;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
char *stateFile = NULL;
unsigned int build_flags = 0; unsigned int build_flags = 0;
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL; VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
VIR_AUTOFREE(char *) stateFile = NULL;
virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
...@@ -761,7 +753,6 @@ storagePoolCreateXML(virConnectPtr conn, ...@@ -761,7 +753,6 @@ storagePoolCreateXML(virConnectPtr conn,
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
cleanup: cleanup:
VIR_FREE(stateFile);
virObjectEventStateQueue(driver->storageEventState, event); virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolObjEndAPI(&obj); virStoragePoolObjEndAPI(&obj);
return pool; return pool;
...@@ -892,8 +883,8 @@ storagePoolCreate(virStoragePoolPtr pool, ...@@ -892,8 +883,8 @@ storagePoolCreate(virStoragePoolPtr pool,
virStorageBackendPtr backend; virStorageBackendPtr backend;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
int ret = -1; int ret = -1;
char *stateFile = NULL;
unsigned int build_flags = 0; unsigned int build_flags = 0;
VIR_AUTOFREE(char *) stateFile = NULL;
virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
...@@ -955,7 +946,6 @@ storagePoolCreate(virStoragePoolPtr pool, ...@@ -955,7 +946,6 @@ storagePoolCreate(virStoragePoolPtr pool,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(stateFile);
virObjectEventStateQueue(driver->storageEventState, event); virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolObjEndAPI(&obj); virStoragePoolObjEndAPI(&obj);
return ret; return ret;
...@@ -1013,8 +1003,8 @@ storagePoolDestroy(virStoragePoolPtr pool) ...@@ -1013,8 +1003,8 @@ storagePoolDestroy(virStoragePoolPtr pool)
virStoragePoolDefPtr def; virStoragePoolDefPtr def;
virStorageBackendPtr backend; virStorageBackendPtr backend;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
char *stateFile = NULL;
int ret = -1; int ret = -1;
VIR_AUTOFREE(char *) stateFile = NULL;
if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name))) if (!(obj = storagePoolObjFindByUUID(pool->uuid, pool->name)))
goto cleanup; goto cleanup;
...@@ -1045,7 +1035,6 @@ storagePoolDestroy(virStoragePoolPtr pool) ...@@ -1045,7 +1035,6 @@ storagePoolDestroy(virStoragePoolPtr pool)
goto cleanup; goto cleanup;
unlink(stateFile); unlink(stateFile);
VIR_FREE(stateFile);
if (backend->stopPool && if (backend->stopPool &&
backend->stopPool(obj) < 0) backend->stopPool(obj) < 0)
...@@ -1078,8 +1067,8 @@ storagePoolDelete(virStoragePoolPtr pool, ...@@ -1078,8 +1067,8 @@ storagePoolDelete(virStoragePoolPtr pool,
virStoragePoolDefPtr def; virStoragePoolDefPtr def;
virStorageBackendPtr backend; virStorageBackendPtr backend;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
char *stateFile = NULL;
int ret = -1; int ret = -1;
VIR_AUTOFREE(char *) stateFile = NULL;
if (!(obj = virStoragePoolObjFromStoragePool(pool))) if (!(obj = virStoragePoolObjFromStoragePool(pool)))
return -1; return -1;
...@@ -1111,7 +1100,6 @@ storagePoolDelete(virStoragePoolPtr pool, ...@@ -1111,7 +1100,6 @@ storagePoolDelete(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
unlink(stateFile); unlink(stateFile);
VIR_FREE(stateFile);
if (!backend->deletePool) { if (!backend->deletePool) {
virReportError(VIR_ERR_NO_SUPPORT, virReportError(VIR_ERR_NO_SUPPORT,
...@@ -1172,10 +1160,10 @@ storagePoolRefresh(virStoragePoolPtr pool, ...@@ -1172,10 +1160,10 @@ storagePoolRefresh(virStoragePoolPtr pool,
virStoragePoolObjClearVols(obj); virStoragePoolObjClearVols(obj);
if (backend->refreshPool(obj) < 0) { if (backend->refreshPool(obj) < 0) {
char *stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml"); VIR_AUTOFREE(char *) stateFile = NULL;
stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
storagePoolRefreshFailCleanup(backend, obj, stateFile); storagePoolRefreshFailCleanup(backend, obj, stateFile);
VIR_FREE(stateFile);
event = virStoragePoolEventLifecycleNew(def->name, event = virStoragePoolEventLifecycleNew(def->name,
def->uuid, def->uuid,
...@@ -1540,7 +1528,7 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr obj, ...@@ -1540,7 +1528,7 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr obj,
{ {
struct storageVolLookupData *data = (struct storageVolLookupData *)opaque; struct storageVolLookupData *data = (struct storageVolLookupData *)opaque;
virStoragePoolDefPtr def; virStoragePoolDefPtr def;
char *stable_path = NULL; VIR_AUTOFREE(char *) stable_path = NULL;
if (!virStoragePoolObjIsActive(obj)) if (!virStoragePoolObjIsActive(obj))
return false; return false;
...@@ -1579,7 +1567,6 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr obj, ...@@ -1579,7 +1567,6 @@ storageVolLookupByPathCallback(virStoragePoolObjPtr obj,
} }
data->voldef = virStorageVolDefFindByPath(obj, stable_path); data->voldef = virStorageVolDefFindByPath(obj, stable_path);
VIR_FREE(stable_path);
return !!data->voldef; return !!data->voldef;
} }
...@@ -1649,7 +1636,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, ...@@ -1649,7 +1636,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
virStoragePoolObjPtr obj; virStoragePoolObjPtr obj;
virStoragePoolDefPtr def; virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL; virStoragePoolPtr pool = NULL;
char *cleanpath; VIR_AUTOFREE(char *) cleanpath = NULL;
cleanpath = virFileSanitizePath(path); cleanpath = virFileSanitizePath(path);
if (!cleanpath) if (!cleanpath)
...@@ -1660,7 +1647,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, ...@@ -1660,7 +1647,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
cleanpath))) { cleanpath))) {
def = virStoragePoolObjGetDef(obj); def = virStoragePoolObjGetDef(obj);
if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0) if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0)
goto cleanup; return NULL;
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
virStoragePoolObjEndAPI(&obj); virStoragePoolObjEndAPI(&obj);
...@@ -1678,8 +1665,6 @@ storagePoolLookupByTargetPath(virConnectPtr conn, ...@@ -1678,8 +1665,6 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
} }
} }
cleanup:
VIR_FREE(cleanpath);
return pool; return pool;
} }
...@@ -2206,40 +2191,31 @@ virStorageVolPoolRefreshDataFree(void *opaque) ...@@ -2206,40 +2191,31 @@ virStorageVolPoolRefreshDataFree(void *opaque)
static int static int
virStorageBackendPloopRestoreDesc(char *path) virStorageBackendPloopRestoreDesc(char *path)
{ {
int ret = -1;
char *refresh_tool = NULL;
char *desc = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
VIR_AUTOFREE(char *) refresh_tool = NULL;
VIR_AUTOFREE(char *) desc = NULL;
if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0) if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
return ret; return -1;
if (virFileRemove(desc, 0, 0) < 0) { if (virFileRemove(desc, 0, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("refresh ploop failed:" _("refresh ploop failed:"
" unable to delete DiskDescriptor.xml")); " unable to delete DiskDescriptor.xml"));
goto cleanup; return -1;
} }
refresh_tool = virFindFileInPath("ploop"); refresh_tool = virFindFileInPath("ploop");
if (!refresh_tool) { if (!refresh_tool) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unable to find ploop, please install ploop tools")); _("unable to find ploop, please install ploop tools"));
goto cleanup; return -1;
} }
cmd = virCommandNewArgList(refresh_tool, "restore-descriptor", cmd = virCommandNewArgList(refresh_tool, "restore-descriptor",
path, NULL); path, NULL);
virCommandAddArgFormat(cmd, "%s/root.hds", path); virCommandAddArgFormat(cmd, "%s/root.hds", path);
if (virCommandRun(cmd, NULL) < 0) return virCommandRun(cmd, NULL);
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(refresh_tool);
VIR_FREE(desc);
return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册