1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStoragePoolDef

Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
John Ferlan 2019-01-31 10:21:47 -05:00
parent d2ddcdc1a2
commit 2f92d59c78
11 changed files with 24 additions and 41 deletions

View File

@ -30988,12 +30988,12 @@ int
virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
{
virConnectPtr conn = NULL;
virStoragePoolDefPtr pooldef = NULL;
virStoragePoolPtr pool = NULL;
virStorageVolPtr vol = NULL;
char *poolxml = NULL;
virStorageVolInfo info;
int ret = -1;
VIR_AUTOPTR(virStoragePoolDef) pooldef = NULL;
if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
return 0;
@ -31152,7 +31152,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
virObjectUnref(pool);
virObjectUnref(vol);
VIR_FREE(poolxml);
virStoragePoolDefFree(pooldef);
return ret;
}

View File

@ -737,12 +737,12 @@ virStoragePoolDefPtr
virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
{
virStoragePoolOptionsPtr options;
virStoragePoolDefPtr def;
virStoragePoolDefPtr ret = NULL;
xmlNodePtr source_node;
char *type = NULL;
char *uuid = NULL;
char *target_path = NULL;
VIR_AUTOPTR(virStoragePoolDef) def = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
@ -883,7 +883,6 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
VIR_STEAL_PTR(ret, def);
cleanup:
virStoragePoolDefFree(def);
VIR_FREE(uuid);
VIR_FREE(type);
VIR_FREE(target_path);

View File

@ -461,6 +461,7 @@ VIR_ENUM_DECL(virStoragePartedFs);
VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolDef, virStoragePoolDefFree);
VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree);
#endif /* LIBVIRT_STORAGE_CONF_H */

View File

@ -1579,8 +1579,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
const char *path,
const char *autostartLink)
{
virStoragePoolDefPtr def;
virStoragePoolObjPtr obj;
VIR_AUTOPTR(virStoragePoolDef) def = NULL;
if (!(def = virStoragePoolDefParseFile(path)))
return NULL;
@ -1590,14 +1590,12 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
_("Storage pool config filename '%s' does "
"not match pool name '%s'"),
path, def->name);
virStoragePoolDefFree(def);
return NULL;
}
if (!(obj = virStoragePoolObjAssignDef(pools, def, false))) {
virStoragePoolDefFree(def);
if (!(obj = virStoragePoolObjAssignDef(pools, def, false)))
return NULL;
}
def = NULL;
VIR_FREE(obj->configFile); /* for driver reload */
if (VIR_STRDUP(obj->configFile, path) < 0) {
@ -1625,39 +1623,40 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools,
const char *name)
{
char *stateFile = NULL;
virStoragePoolDefPtr def = NULL;
virStoragePoolObjPtr obj = NULL;
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr node = NULL;
VIR_AUTOPTR(virStoragePoolDef) def = NULL;
if (!(stateFile = virFileBuildPath(stateDir, name, ".xml")))
goto error;
return NULL;
if (!(xml = virXMLParseCtxt(stateFile, NULL, _("(pool state)"), &ctxt)))
goto error;
goto cleanup;
if (!(node = virXPathNode("//pool", ctxt))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not find any 'pool' element in state file"));
goto error;
goto cleanup;
}
ctxt->node = node;
if (!(def = virStoragePoolDefParseXML(ctxt)))
goto error;
goto cleanup;
if (STRNEQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Storage pool state file '%s' does not match "
"pool name '%s'"),
stateFile, def->name);
goto error;
goto cleanup;
}
/* create the object */
if (!(obj = virStoragePoolObjAssignDef(pools, def, true)))
goto error;
goto cleanup;
def = NULL;
/* XXX: future handling of some additional useful status data,
* for now, if a status file for a pool exists, the pool will be marked
@ -1671,10 +1670,6 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools,
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return obj;
error:
virStoragePoolDefFree(def);
goto cleanup;
}

View File

@ -1952,11 +1952,11 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
{
virCheckFlags(0, NULL);
virStoragePoolDefPtr spdef = NULL;
virStorageVolPtr vol = NULL;
virStorageVolPtr dup_vol = NULL;
char *key = NULL;
VIR_AUTOPTR(virStorageVolDef) voldef = NULL;
VIR_AUTOPTR(virStoragePoolDef) spdef = NULL;
if (VIR_ALLOC(spdef) < 0)
return NULL;
@ -2031,13 +2031,11 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
goto err;
VIR_FREE(key);
virStoragePoolDefFree(spdef);
return vol;
err:
VIR_FREE(key);
virStoragePoolDefFree(spdef);
virObjectUnref(vol);
return NULL;
}

View File

@ -690,7 +690,6 @@ storagePoolCreateXML(virConnectPtr conn,
const char *xml,
unsigned int flags)
{
virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
@ -698,6 +697,7 @@ storagePoolCreateXML(virConnectPtr conn,
virObjectEventPtr event = NULL;
char *stateFile = NULL;
unsigned int build_flags = 0;
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
@ -762,7 +762,6 @@ storagePoolCreateXML(virConnectPtr conn,
cleanup:
VIR_FREE(stateFile);
virStoragePoolDefFree(newDef);
virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolObjEndAPI(&obj);
return pool;
@ -779,11 +778,11 @@ storagePoolDefineXML(virConnectPtr conn,
const char *xml,
unsigned int flags)
{
virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
virObjectEventPtr event = NULL;
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
virCheckFlags(0, NULL);
@ -822,7 +821,6 @@ storagePoolDefineXML(virConnectPtr conn,
cleanup:
virObjectEventStateQueue(driver->storageEventState, event);
virStoragePoolDefFree(newDef);
virStoragePoolObjEndAPI(&obj);
return pool;
}

View File

@ -4472,11 +4472,11 @@ testStoragePoolCreateXML(virConnectPtr conn,
unsigned int flags)
{
testDriverPtr privconn = conn->privateData;
virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
virObjectEventPtr event = NULL;
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
virCheckFlags(0, NULL);
@ -4525,7 +4525,6 @@ testStoragePoolCreateXML(virConnectPtr conn,
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
cleanup:
virStoragePoolDefFree(newDef);
virObjectEventStateQueue(privconn->eventState, event);
virStoragePoolObjEndAPI(&obj);
virObjectUnlock(privconn);
@ -4539,11 +4538,11 @@ testStoragePoolDefineXML(virConnectPtr conn,
unsigned int flags)
{
testDriverPtr privconn = conn->privateData;
virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
virObjectEventPtr event = NULL;
VIR_AUTOPTR(virStoragePoolDef) newDef = NULL;
virCheckFlags(0, NULL);
@ -4574,7 +4573,6 @@ testStoragePoolDefineXML(virConnectPtr conn,
pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
cleanup:
virStoragePoolDefFree(newDef);
virObjectEventStateQueue(privconn->eventState, event);
virStoragePoolObjEndAPI(&obj);
virObjectUnlock(privconn);

View File

@ -59,7 +59,7 @@ test_node_info_parser(const void *opaque)
collie_test test = data->data;
int ret = -1;
char *output = NULL;
virStoragePoolDefPtr pool = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
goto cleanup;
@ -82,7 +82,6 @@ test_node_info_parser(const void *opaque)
cleanup:
VIR_FREE(output);
virStoragePoolDefFree(pool);
return ret;
}
@ -93,7 +92,7 @@ test_vdi_list_parser(const void *opaque)
collie_test test = data->data;
int ret = -1;
char *output = NULL;
virStoragePoolDefPtr pool = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
VIR_AUTOPTR(virStorageVolDef) vol = NULL;
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
@ -120,7 +119,6 @@ test_vdi_list_parser(const void *opaque)
cleanup:
VIR_FREE(output);
virStoragePoolDefFree(pool);
return ret;
}

View File

@ -20,7 +20,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr dev = NULL;
VIR_AUTOPTR(virStoragePoolDef) dev = NULL;
if (!(dev = virStoragePoolDefParseFile(inxml)))
goto fail;
@ -35,7 +35,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
fail:
VIR_FREE(actual);
virStoragePoolDefFree(dev);
return ret;
}

View File

@ -49,10 +49,10 @@ testCompareXMLToArgvFiles(bool shouldFail,
virCommandPtr cmd = NULL;
virStoragePoolDefPtr def = NULL;
virStoragePoolDefPtr inputpool = NULL;
virStoragePoolObjPtr obj = NULL;
VIR_AUTOPTR(virStorageVolDef) vol = NULL;
VIR_AUTOPTR(virStorageVolDef) inputvol = NULL;
VIR_AUTOPTR(virStoragePoolDef) inputpool = NULL;
if (!(def = virStoragePoolDefParseFile(poolxml)))
goto cleanup;
@ -139,7 +139,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
ret = 0;
cleanup:
virStoragePoolDefFree(inputpool);
virCommandFree(cmd);
VIR_FREE(actualCmdline);
virStoragePoolObjEndAPI(&obj);

View File

@ -19,7 +19,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
{
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr pool = NULL;
VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
VIR_AUTOPTR(virStorageVolDef) dev = NULL;
if (!(pool = virStoragePoolDefParseFile(poolxml)))
@ -38,7 +38,6 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
fail:
VIR_FREE(actual);
virStoragePoolDefFree(pool);
return ret;
}