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

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: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 6fcc3440
...@@ -7578,11 +7578,10 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, ...@@ -7578,11 +7578,10 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr def, virDomainHostdevSubsysSCSIPtr def,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
int ret = -1;
int auth_secret_usage = -1; int auth_secret_usage = -1;
xmlNodePtr cur; xmlNodePtr cur;
virStorageAuthDefPtr authdef = NULL;
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &def->u.iscsi; virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &def->u.iscsi;
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
/* For the purposes of command line creation, this needs to look /* For the purposes of command line creation, this needs to look
* like a disk storage source */ * like a disk storage source */
...@@ -7594,23 +7593,23 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, ...@@ -7594,23 +7593,23 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
if (!(iscsisrc->src->path = virXMLPropString(sourcenode, "name"))) { if (!(iscsisrc->src->path = virXMLPropString(sourcenode, "name"))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing iSCSI hostdev source path name")); _("missing iSCSI hostdev source path name"));
goto cleanup; return -1;
} }
if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->src->hosts, if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->src->hosts,
&iscsisrc->src->nhosts) < 0) &iscsisrc->src->nhosts) < 0)
goto cleanup; return -1;
if (iscsisrc->src->nhosts < 1) { if (iscsisrc->src->nhosts < 1) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing the host address for the iSCSI hostdev")); _("missing the host address for the iSCSI hostdev"));
goto cleanup; return -1;
} }
if (iscsisrc->src->nhosts > 1) { if (iscsisrc->src->nhosts > 1) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("only one source host address may be specified " _("only one source host address may be specified "
"for the iSCSI hostdev")); "for the iSCSI hostdev"));
goto cleanup; return -1;
} }
cur = sourcenode->children; cur = sourcenode->children;
...@@ -7618,29 +7617,25 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, ...@@ -7618,29 +7617,25 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
if (cur->type == XML_ELEMENT_NODE && if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "auth")) { virXMLNodeNameEqual(cur, "auth")) {
if (!(authdef = virStorageAuthDefParse(cur, ctxt))) if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
goto cleanup; return -1;
if ((auth_secret_usage = if ((auth_secret_usage =
virSecretUsageTypeFromString(authdef->secrettype)) < 0) { virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid secret type %s"), _("invalid secret type %s"),
authdef->secrettype); authdef->secrettype);
goto cleanup; return -1;
} }
if (auth_secret_usage != VIR_SECRET_USAGE_TYPE_ISCSI) { if (auth_secret_usage != VIR_SECRET_USAGE_TYPE_ISCSI) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("hostdev invalid secret type '%s'"), _("hostdev invalid secret type '%s'"),
authdef->secrettype); authdef->secrettype);
goto cleanup; return -1;
} }
VIR_STEAL_PTR(iscsisrc->src->auth, authdef); VIR_STEAL_PTR(iscsisrc->src->auth, authdef);
} }
cur = cur->next; cur = cur->next;
} }
ret = 0; return 0;
cleanup:
virStorageAuthDefFree(authdef);
return ret;
} }
static int static int
...@@ -9683,7 +9678,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, ...@@ -9683,7 +9678,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
virStorageEncryptionPtr encryption = NULL; virStorageEncryptionPtr encryption = NULL;
char *serial = NULL; char *serial = NULL;
char *startupPolicy = NULL; char *startupPolicy = NULL;
virStorageAuthDefPtr authdef = NULL;
char *tray = NULL; char *tray = NULL;
char *removable = NULL; char *removable = NULL;
char *logical_block_size = NULL; char *logical_block_size = NULL;
...@@ -9692,6 +9686,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, ...@@ -9692,6 +9686,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
char *vendor = NULL; char *vendor = NULL;
char *product = NULL; char *product = NULL;
char *domain_name = NULL; char *domain_name = NULL;
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
if (!(def = virDomainDiskDefNew(xmlopt))) if (!(def = virDomainDiskDefNew(xmlopt)))
return NULL; return NULL;
...@@ -10093,7 +10088,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, ...@@ -10093,7 +10088,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(tray); VIR_FREE(tray);
VIR_FREE(removable); VIR_FREE(removable);
virStorageAuthDefFree(authdef);
VIR_FREE(devaddr); VIR_FREE(devaddr);
VIR_FREE(serial); VIR_FREE(serial);
virStorageEncryptionFree(encryption); virStorageEncryptionFree(encryption);
......
...@@ -458,11 +458,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -458,11 +458,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
int nsource; int nsource;
size_t i; size_t i;
virStoragePoolOptionsPtr options; virStoragePoolOptionsPtr options;
virStorageAuthDefPtr authdef = NULL;
char *name = NULL; char *name = NULL;
char *port = NULL; char *port = NULL;
char *ver = NULL; char *ver = NULL;
int n; int n;
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
relnode = ctxt->node; relnode = ctxt->node;
ctxt->node = node; ctxt->node = node;
...@@ -614,7 +614,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -614,7 +614,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
VIR_FREE(port); VIR_FREE(port);
VIR_FREE(nodeset); VIR_FREE(nodeset);
virStorageAuthDefFree(authdef);
return ret; return ret;
} }
......
...@@ -59,7 +59,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, ...@@ -59,7 +59,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
char *sock = NULL; char *sock = NULL;
char *volimg = NULL; char *volimg = NULL;
char *secret = NULL; char *secret = NULL;
virStorageAuthDefPtr authdef = NULL; VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
if (VIR_ALLOC(def->src->hosts) < 0) if (VIR_ALLOC(def->src->hosts) < 0)
goto error; goto error;
...@@ -151,7 +151,6 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, ...@@ -151,7 +151,6 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
error: error:
virStorageNetHostDefClear(def->src->hosts); virStorageNetHostDefClear(def->src->hosts);
VIR_FREE(def->src->hosts); VIR_FREE(def->src->hosts);
virStorageAuthDefFree(authdef);
goto cleanup; goto cleanup;
} }
......
...@@ -1879,25 +1879,23 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef) ...@@ -1879,25 +1879,23 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef)
virStorageAuthDefPtr virStorageAuthDefPtr
virStorageAuthDefCopy(const virStorageAuthDef *src) virStorageAuthDefCopy(const virStorageAuthDef *src)
{ {
virStorageAuthDefPtr authdef;
virStorageAuthDefPtr ret = NULL; virStorageAuthDefPtr ret = NULL;
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
if (VIR_ALLOC(authdef) < 0) if (VIR_ALLOC(authdef) < 0)
return NULL; return NULL;
if (VIR_STRDUP(authdef->username, src->username) < 0) if (VIR_STRDUP(authdef->username, src->username) < 0)
goto cleanup; return NULL;
/* Not present for storage pool, but used for disk source */ /* Not present for storage pool, but used for disk source */
if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0) if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0)
goto cleanup; return NULL;
authdef->authType = src->authType; authdef->authType = src->authType;
if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef) < 0) if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef) < 0)
goto cleanup; return NULL;
VIR_STEAL_PTR(ret, authdef); VIR_STEAL_PTR(ret, authdef);
cleanup:
virStorageAuthDefFree(authdef);
return ret; return ret;
} }
...@@ -1907,10 +1905,10 @@ virStorageAuthDefParse(xmlNodePtr node, ...@@ -1907,10 +1905,10 @@ virStorageAuthDefParse(xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr saveNode = ctxt->node; xmlNodePtr saveNode = ctxt->node;
virStorageAuthDefPtr authdef = NULL;
virStorageAuthDefPtr ret = NULL; virStorageAuthDefPtr ret = NULL;
xmlNodePtr secretnode = NULL; xmlNodePtr secretnode = NULL;
char *authtype = NULL; char *authtype = NULL;
VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
ctxt->node = node; ctxt->node = node;
...@@ -1958,7 +1956,6 @@ virStorageAuthDefParse(xmlNodePtr node, ...@@ -1958,7 +1956,6 @@ virStorageAuthDefParse(xmlNodePtr node,
cleanup: cleanup:
VIR_FREE(authtype); VIR_FREE(authtype);
virStorageAuthDefFree(authdef);
ctxt->node = saveNode; ctxt->node = saveNode;
return ret; return ret;
...@@ -2832,7 +2829,7 @@ virStorageSourceParseRBDColonString(const char *rbdstr, ...@@ -2832,7 +2829,7 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
{ {
char *options = NULL; char *options = NULL;
char *p, *e, *next; char *p, *e, *next;
virStorageAuthDefPtr authdef = NULL; VIR_AUTOPTR(virStorageAuthDef) authdef = NULL;
/* optionally skip the "rbd:" prefix if provided */ /* optionally skip the "rbd:" prefix if provided */
if (STRPREFIX(rbdstr, "rbd:")) if (STRPREFIX(rbdstr, "rbd:"))
...@@ -2935,7 +2932,6 @@ virStorageSourceParseRBDColonString(const char *rbdstr, ...@@ -2935,7 +2932,6 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
error: error:
VIR_FREE(options); VIR_FREE(options);
virStorageAuthDefFree(authdef);
return -1; return -1;
} }
......
...@@ -543,4 +543,6 @@ void virStorageFileReportBrokenChain(int errcode, ...@@ -543,4 +543,6 @@ void virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr src, virStorageSourcePtr src,
virStorageSourcePtr parent); virStorageSourcePtr parent);
VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree);
#endif /* LIBVIRT_VIRSTORAGEFILE_H */ #endif /* LIBVIRT_VIRSTORAGEFILE_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册