qemu_migration_params.c: modernize qemuMigrationParamsEnableTLS()

Use g_autoptr() and remove both 'cleanup' and 'error' labels.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-07-13 06:49:42 -03:00 committed by Michal Privoznik
parent 5b4ae09e71
commit 769de4695b

View File

@ -953,23 +953,22 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
qemuMigrationParamsPtr migParams) qemuMigrationParamsPtr migParams)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virJSONValuePtr tlsProps = NULL; g_autoptr(virJSONValue) tlsProps = NULL;
virJSONValuePtr secProps = NULL; g_autoptr(virJSONValue) secProps = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
const char *secAlias = NULL; const char *secAlias = NULL;
int ret = -1;
if (!cfg->migrateTLSx509certdir) { if (!cfg->migrateTLSx509certdir) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("host migration TLS directory not configured")); _("host migration TLS directory not configured"));
goto error; return -1;
} }
if (!priv->job.migParams->params[QEMU_MIGRATION_PARAM_TLS_CREDS].set) { if (!priv->job.migParams->params[QEMU_MIGRATION_PARAM_TLS_CREDS].set) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("TLS migration is not supported with this " _("TLS migration is not supported with this "
"QEMU binary")); "QEMU binary"));
goto error; return -1;
} }
/* If there's a secret, then grab/store it now using the connection */ /* If there's a secret, then grab/store it now using the connection */
@ -977,18 +976,18 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
if (!(priv->migSecinfo = if (!(priv->migSecinfo =
qemuDomainSecretInfoTLSNew(priv, QEMU_MIGRATION_TLS_ALIAS_BASE, qemuDomainSecretInfoTLSNew(priv, QEMU_MIGRATION_TLS_ALIAS_BASE,
cfg->migrateTLSx509secretUUID))) cfg->migrateTLSx509secretUUID)))
goto error; return -1;
secAlias = priv->migSecinfo->s.aes.alias; secAlias = priv->migSecinfo->s.aes.alias;
} }
if (!(*tlsAlias = qemuAliasTLSObjFromSrcAlias(QEMU_MIGRATION_TLS_ALIAS_BASE))) if (!(*tlsAlias = qemuAliasTLSObjFromSrcAlias(QEMU_MIGRATION_TLS_ALIAS_BASE)))
goto error; return -1;
if (qemuDomainGetTLSObjects(priv->qemuCaps, priv->migSecinfo, if (qemuDomainGetTLSObjects(priv->qemuCaps, priv->migSecinfo,
cfg->migrateTLSx509certdir, tlsListen, cfg->migrateTLSx509certdir, tlsListen,
cfg->migrateTLSx509verify, cfg->migrateTLSx509verify,
*tlsAlias, &tlsProps, &secProps) < 0) *tlsAlias, &tlsProps, &secProps) < 0)
goto error; return -1;
/* Ensure the domain doesn't already have the TLS objects defined... /* Ensure the domain doesn't already have the TLS objects defined...
* This should prevent any issues just in case some cleanup wasn't * This should prevent any issues just in case some cleanup wasn't
@ -997,29 +996,20 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, *tlsAlias); qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, *tlsAlias);
if (qemuDomainAddTLSObjects(driver, vm, asyncJob, &secProps, &tlsProps) < 0) if (qemuDomainAddTLSObjects(driver, vm, asyncJob, &secProps, &tlsProps) < 0)
goto error; return -1;
if (qemuMigrationParamsSetString(migParams, if (qemuMigrationParamsSetString(migParams,
QEMU_MIGRATION_PARAM_TLS_CREDS, QEMU_MIGRATION_PARAM_TLS_CREDS,
*tlsAlias) < 0) *tlsAlias) < 0)
goto error; return -1;
if (!migParams->params[QEMU_MIGRATION_PARAM_TLS_HOSTNAME].set && if (!migParams->params[QEMU_MIGRATION_PARAM_TLS_HOSTNAME].set &&
qemuMigrationParamsSetString(migParams, qemuMigrationParamsSetString(migParams,
QEMU_MIGRATION_PARAM_TLS_HOSTNAME, QEMU_MIGRATION_PARAM_TLS_HOSTNAME,
NULLSTR_EMPTY(hostname)) < 0) NULLSTR_EMPTY(hostname)) < 0)
goto error; return -1;
ret = 0; return 0;
cleanup:
virObjectUnref(cfg);
return ret;
error:
virJSONValueFree(tlsProps);
virJSONValueFree(secProps);
goto cleanup;
} }