mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStorageAuthDef
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
6fcc344082
commit
13395548b2
@ -7578,11 +7578,10 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
||||
virDomainHostdevSubsysSCSIPtr def,
|
||||
xmlXPathContextPtr ctxt)
|
||||
{
|
||||
int ret = -1;
|
||||
int auth_secret_usage = -1;
|
||||
xmlNodePtr cur;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &def->u.iscsi;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
/* For the purposes of command line creation, this needs to look
|
||||
* like a disk storage source */
|
||||
@ -7594,23 +7593,23 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
||||
if (!(iscsisrc->src->path = virXMLPropString(sourcenode, "name"))) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("missing iSCSI hostdev source path name"));
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->src->hosts,
|
||||
&iscsisrc->src->nhosts) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (iscsisrc->src->nhosts < 1) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("missing the host address for the iSCSI hostdev"));
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
if (iscsisrc->src->nhosts > 1) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("only one source host address may be specified "
|
||||
"for the iSCSI hostdev"));
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cur = sourcenode->children;
|
||||
@ -7618,29 +7617,25 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
||||
if (cur->type == XML_ELEMENT_NODE &&
|
||||
virXMLNodeNameEqual(cur, "auth")) {
|
||||
if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
if ((auth_secret_usage =
|
||||
virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("invalid secret type %s"),
|
||||
authdef->secrettype);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
if (auth_secret_usage != VIR_SECRET_USAGE_TYPE_ISCSI) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("hostdev invalid secret type '%s'"),
|
||||
authdef->secrettype);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
VIR_STEAL_PTR(iscsisrc->src->auth, authdef);
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virStorageAuthDefFree(authdef);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -9683,7 +9678,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virStorageEncryptionPtr encryption = NULL;
|
||||
char *serial = NULL;
|
||||
char *startupPolicy = NULL;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
char *tray = NULL;
|
||||
char *removable = NULL;
|
||||
char *logical_block_size = NULL;
|
||||
@ -9692,6 +9686,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
char *vendor = NULL;
|
||||
char *product = NULL;
|
||||
char *domain_name = NULL;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
if (!(def = virDomainDiskDefNew(xmlopt)))
|
||||
return NULL;
|
||||
@ -10093,7 +10088,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
VIR_FREE(target);
|
||||
VIR_FREE(tray);
|
||||
VIR_FREE(removable);
|
||||
virStorageAuthDefFree(authdef);
|
||||
VIR_FREE(devaddr);
|
||||
VIR_FREE(serial);
|
||||
virStorageEncryptionFree(encryption);
|
||||
|
@ -458,11 +458,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
|
||||
int nsource;
|
||||
size_t i;
|
||||
virStoragePoolOptionsPtr options;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
char *name = NULL;
|
||||
char *port = NULL;
|
||||
char *ver = NULL;
|
||||
int n;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
relnode = ctxt->node;
|
||||
ctxt->node = node;
|
||||
@ -614,7 +614,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
|
||||
|
||||
VIR_FREE(port);
|
||||
VIR_FREE(nodeset);
|
||||
virStorageAuthDefFree(authdef);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
|
||||
char *sock = NULL;
|
||||
char *volimg = NULL;
|
||||
char *secret = NULL;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
if (VIR_ALLOC(def->src->hosts) < 0)
|
||||
goto error;
|
||||
@ -151,7 +151,6 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
|
||||
error:
|
||||
virStorageNetHostDefClear(def->src->hosts);
|
||||
VIR_FREE(def->src->hosts);
|
||||
virStorageAuthDefFree(authdef);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -1879,25 +1879,23 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef)
|
||||
virStorageAuthDefPtr
|
||||
virStorageAuthDefCopy(const virStorageAuthDef *src)
|
||||
{
|
||||
virStorageAuthDefPtr authdef;
|
||||
virStorageAuthDefPtr ret = NULL;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
if (VIR_ALLOC(authdef) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_STRDUP(authdef->username, src->username) < 0)
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
/* Not present for storage pool, but used for disk source */
|
||||
if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0)
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
authdef->authType = src->authType;
|
||||
|
||||
if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef) < 0)
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
|
||||
VIR_STEAL_PTR(ret, authdef);
|
||||
cleanup:
|
||||
virStorageAuthDefFree(authdef);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1907,10 +1905,10 @@ virStorageAuthDefParse(xmlNodePtr node,
|
||||
xmlXPathContextPtr ctxt)
|
||||
{
|
||||
xmlNodePtr saveNode = ctxt->node;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
virStorageAuthDefPtr ret = NULL;
|
||||
xmlNodePtr secretnode = NULL;
|
||||
char *authtype = NULL;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
@ -1958,7 +1956,6 @@ virStorageAuthDefParse(xmlNodePtr node,
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(authtype);
|
||||
virStorageAuthDefFree(authdef);
|
||||
ctxt->node = saveNode;
|
||||
|
||||
return ret;
|
||||
@ -2832,7 +2829,7 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
|
||||
{
|
||||
char *options = NULL;
|
||||
char *p, *e, *next;
|
||||
virStorageAuthDefPtr authdef = NULL;
|
||||
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
|
||||
|
||||
/* optionally skip the "rbd:" prefix if provided */
|
||||
if (STRPREFIX(rbdstr, "rbd:"))
|
||||
@ -2935,7 +2932,6 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
|
||||
|
||||
error:
|
||||
VIR_FREE(options);
|
||||
virStorageAuthDefFree(authdef);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -543,4 +543,6 @@ void virStorageFileReportBrokenChain(int errcode,
|
||||
virStorageSourcePtr src,
|
||||
virStorageSourcePtr parent);
|
||||
|
||||
VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree);
|
||||
|
||||
#endif /* LIBVIRT_VIRSTORAGEFILE_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user