mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStoragePoolSource
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:
parent
13395548b2
commit
cf46075293
@ -625,7 +625,8 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
|
||||
xmlDocPtr doc = NULL;
|
||||
xmlNodePtr node = NULL;
|
||||
xmlXPathContextPtr xpath_ctxt = NULL;
|
||||
virStoragePoolSourcePtr def = NULL, ret = NULL;
|
||||
virStoragePoolSourcePtr ret = NULL;
|
||||
VIR_AUTOPTR(virStoragePoolSource) def = NULL;
|
||||
|
||||
if (!(doc = virXMLParseStringCtxt(srcSpec,
|
||||
_("(storage_source_specification)"),
|
||||
@ -647,7 +648,6 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
|
||||
|
||||
VIR_STEAL_PTR(ret, def);
|
||||
cleanup:
|
||||
virStoragePoolSourceFree(def);
|
||||
xmlFreeDoc(doc);
|
||||
xmlXPathFreeContext(xpath_ctxt);
|
||||
|
||||
|
@ -460,4 +460,6 @@ VIR_ENUM_DECL(virStoragePartedFs);
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART | \
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
|
||||
|
||||
VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
|
||||
|
||||
#endif /* LIBVIRT_STORAGE_CONF_H */
|
||||
|
@ -145,11 +145,11 @@ virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
|
||||
.sources = NULL
|
||||
}
|
||||
};
|
||||
virStoragePoolSourcePtr source = NULL;
|
||||
char *ret = NULL;
|
||||
size_t i;
|
||||
int retNFS = -1;
|
||||
int retGluster = 0;
|
||||
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -196,7 +196,6 @@ virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
|
||||
virStoragePoolSourceClear(&state.list.sources[i]);
|
||||
VIR_FREE(state.list.sources);
|
||||
|
||||
virStoragePoolSourceFree(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -489,10 +489,10 @@ virStorageBackendGlusterFindPoolSources(const char *srcSpec,
|
||||
.nsources = 0,
|
||||
.sources = NULL
|
||||
};
|
||||
virStoragePoolSourcePtr source = NULL;
|
||||
char *ret = NULL;
|
||||
int rc;
|
||||
size_t i;
|
||||
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -532,7 +532,6 @@ virStorageBackendGlusterFindPoolSources(const char *srcSpec,
|
||||
virStoragePoolSourceClear(&list.sources[i]);
|
||||
VIR_FREE(list.sources);
|
||||
|
||||
virStoragePoolSourceFree(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,6 @@ static char *
|
||||
virStorageBackendISCSIFindPoolSources(const char *srcSpec,
|
||||
unsigned int flags)
|
||||
{
|
||||
virStoragePoolSourcePtr source = NULL;
|
||||
size_t ntargets = 0;
|
||||
char **targets = NULL;
|
||||
char *ret = NULL;
|
||||
@ -169,6 +168,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
|
||||
.sources = NULL
|
||||
};
|
||||
char *portal = NULL;
|
||||
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -227,7 +227,6 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
|
||||
VIR_FREE(targets[i]);
|
||||
VIR_FREE(targets);
|
||||
VIR_FREE(portal);
|
||||
virStoragePoolSourceFree(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -486,7 +486,6 @@ static char *
|
||||
virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
|
||||
unsigned int flags)
|
||||
{
|
||||
virStoragePoolSourcePtr source = NULL;
|
||||
size_t ntargets = 0;
|
||||
char **targets = NULL;
|
||||
char *ret = NULL;
|
||||
@ -497,6 +496,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
|
||||
.sources = NULL
|
||||
};
|
||||
char *portal = NULL;
|
||||
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -557,7 +557,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
|
||||
VIR_FREE(targets[i]);
|
||||
VIR_FREE(targets);
|
||||
VIR_FREE(portal);
|
||||
virStoragePoolSourceFree(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -4394,9 +4394,9 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
const char *srcSpec,
|
||||
unsigned int flags)
|
||||
{
|
||||
virStoragePoolSourcePtr source = NULL;
|
||||
int pool_type;
|
||||
char *ret = NULL;
|
||||
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -4404,40 +4404,38 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
if (!pool_type) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unknown storage pool type %s"), type);
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (srcSpec) {
|
||||
source = virStoragePoolDefParseSourceString(srcSpec, pool_type);
|
||||
if (!source)
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (pool_type) {
|
||||
|
||||
case VIR_STORAGE_POOL_LOGICAL:
|
||||
ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
|
||||
break;
|
||||
return ret;
|
||||
|
||||
case VIR_STORAGE_POOL_NETFS:
|
||||
if (!source || !source->hosts[0].name) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("hostname must be specified for netfs sources"));
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML,
|
||||
source->hosts[0].name));
|
||||
break;
|
||||
return ret;
|
||||
|
||||
default:
|
||||
virReportError(VIR_ERR_NO_SUPPORT,
|
||||
_("pool type '%s' does not support source discovery"), type);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStoragePoolSourceFree(source);
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user