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