scsi: Clean up createVport exit paths

Use the ret = -1, goto cleanup, etc. rather than current hodgepodge.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2016-11-18 07:19:28 -05:00
parent 8b629a3c01
commit 79ab093518

View File

@ -697,6 +697,7 @@ createVport(virConnectPtr conn,
char *parent_hoststr = NULL; char *parent_hoststr = NULL;
virStoragePoolFCRefreshInfoPtr cbdata = NULL; virStoragePoolFCRefreshInfoPtr cbdata = NULL;
virThread thread; virThread thread;
int ret = -1;
if (adapter->type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) if (adapter->type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
return 0; return 0;
@ -725,17 +726,14 @@ createVport(virConnectPtr conn,
*/ */
if ((name = virGetFCHostNameByWWN(NULL, adapter->data.fchost.wwnn, if ((name = virGetFCHostNameByWWN(NULL, adapter->data.fchost.wwnn,
adapter->data.fchost.wwpn))) { adapter->data.fchost.wwpn))) {
int retval = 0;
/* If a parent was provided, let's make sure the 'name' we've /* If a parent was provided, let's make sure the 'name' we've
* retrieved has the same parent * retrieved has the same parent
*/ */
if (adapter->data.fchost.parent && if (adapter->data.fchost.parent &&
!checkVhbaSCSIHostParent(conn, name, adapter->data.fchost.parent)) checkVhbaSCSIHostParent(conn, name, adapter->data.fchost.parent))
retval = -1; ret = 0;
VIR_FREE(name); goto cleanup;
return retval;
} }
if (!adapter->data.fchost.parent) { if (!adapter->data.fchost.parent) {
@ -743,13 +741,11 @@ createVport(virConnectPtr conn,
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("'parent' for vHBA not specified, and " _("'parent' for vHBA not specified, and "
"cannot find one on this host")); "cannot find one on this host"));
return -1; goto cleanup;
} }
if (virGetSCSIHostNumber(parent_hoststr, &parent_host) < 0) { if (virGetSCSIHostNumber(parent_hoststr, &parent_host) < 0)
VIR_FREE(parent_hoststr); goto cleanup;
return -1;
}
/* NOTE: /* NOTE:
* We do not save the parent_hoststr in adapter->data.fchost.parent * We do not save the parent_hoststr in adapter->data.fchost.parent
@ -759,7 +755,6 @@ createVport(virConnectPtr conn,
* parent. Besides we have a way to determine the parent based on * parent. Besides we have a way to determine the parent based on
* the 'name' field. * the 'name' field.
*/ */
VIR_FREE(parent_hoststr);
} }
/* Since we're creating the vHBA, then we need to manage removing it /* Since we're creating the vHBA, then we need to manage removing it
@ -771,13 +766,13 @@ createVport(virConnectPtr conn,
adapter->data.fchost.managed = VIR_TRISTATE_BOOL_YES; adapter->data.fchost.managed = VIR_TRISTATE_BOOL_YES;
if (configFile) { if (configFile) {
if (virStoragePoolSaveConfig(configFile, pool->def) < 0) if (virStoragePoolSaveConfig(configFile, pool->def) < 0)
return -1; goto cleanup;
} }
} }
if (virManageVport(parent_host, adapter->data.fchost.wwpn, if (virManageVport(parent_host, adapter->data.fchost.wwpn,
adapter->data.fchost.wwnn, VPORT_CREATE) < 0) adapter->data.fchost.wwnn, VPORT_CREATE) < 0)
return -1; goto cleanup;
virFileWaitForDevices(); virFileWaitForDevices();
@ -790,8 +785,7 @@ createVport(virConnectPtr conn,
adapter->data.fchost.wwpn))) { adapter->data.fchost.wwpn))) {
if (VIR_ALLOC(cbdata) == 0) { if (VIR_ALLOC(cbdata) == 0) {
memcpy(cbdata->pool_uuid, pool->def->uuid, VIR_UUID_BUFLEN); memcpy(cbdata->pool_uuid, pool->def->uuid, VIR_UUID_BUFLEN);
cbdata->fchost_name = name; VIR_STEAL_PTR(cbdata->fchost_name, name);
name = NULL;
if (virThreadCreate(&thread, false, virStoragePoolFCRefreshThread, if (virThreadCreate(&thread, false, virStoragePoolFCRefreshThread,
cbdata) < 0) { cbdata) < 0) {
@ -800,10 +794,14 @@ createVport(virConnectPtr conn,
virStoragePoolFCRefreshDataFree(cbdata); virStoragePoolFCRefreshDataFree(cbdata);
} }
} }
VIR_FREE(name);
} }
return 0; ret = 0;
cleanup:
VIR_FREE(name);
VIR_FREE(parent_hoststr);
return ret;
} }
static int static int