提交 9374c6e0 编写于 作者: P Peter Krempa

qemu: hotplug: Refactor tls-credential props formatting to qemuMonitorCreateObjectProps

Note that it's okay to pass NULL to qemuDomainDelTLSObjects in
qemuDomainAddTLSObjects as the tls-creds-x509 object was either not
created or qemu crashed.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 80e301cd
...@@ -684,6 +684,7 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf, ...@@ -684,6 +684,7 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf,
* @tlspath: path to the TLS credentials * @tlspath: path to the TLS credentials
* @listen: boolen listen for client or server setting * @listen: boolen listen for client or server setting
* @verifypeer: boolean to enable peer verification (form of authorization) * @verifypeer: boolean to enable peer verification (form of authorization)
* @alias: alias for the TLS credentials object
* @secalias: if one exists, the alias of the security object for passwordid * @secalias: if one exists, the alias of the security object for passwordid
* @qemuCaps: capabilities * @qemuCaps: capabilities
* @propsret: json properties to return * @propsret: json properties to return
...@@ -696,6 +697,7 @@ int ...@@ -696,6 +697,7 @@ int
qemuBuildTLSx509BackendProps(const char *tlspath, qemuBuildTLSx509BackendProps(const char *tlspath,
bool isListen, bool isListen,
bool verifypeer, bool verifypeer,
const char *alias,
const char *secalias, const char *secalias,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virJSONValuePtr *propsret) virJSONValuePtr *propsret)
...@@ -706,7 +708,7 @@ qemuBuildTLSx509BackendProps(const char *tlspath, ...@@ -706,7 +708,7 @@ qemuBuildTLSx509BackendProps(const char *tlspath,
return -1; return -1;
} }
if (virJSONValueObjectCreate(propsret, if (qemuMonitorCreateObjectProps(propsret, "tls-creds-x509", alias,
"s:dir", tlspath, "s:dir", tlspath,
"s:endpoint", (isListen ? "server": "client"), "s:endpoint", (isListen ? "server": "client"),
"b:verify-peer", (isListen ? verifypeer : true), "b:verify-peer", (isListen ? verifypeer : true),
...@@ -741,26 +743,25 @@ qemuBuildTLSx509CommandLine(virCommandPtr cmd, ...@@ -741,26 +743,25 @@ qemuBuildTLSx509CommandLine(virCommandPtr cmd,
const char *alias, const char *alias,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER;
int ret = -1; int ret = -1;
virJSONValuePtr props = NULL; virJSONValuePtr props = NULL;
char *tmp = NULL;
if (qemuBuildTLSx509BackendProps(tlspath, isListen, verifypeer, if (qemuBuildTLSx509BackendProps(tlspath, isListen, verifypeer, alias,
certEncSecretAlias, certEncSecretAlias, qemuCaps, &props) < 0)
qemuCaps, &props) < 0)
goto cleanup; goto cleanup;
if (!(tmp = virQEMUBuildObjectCommandlineFromJSONType("tls-creds-x509", if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
alias, props)))
goto cleanup; goto cleanup;
virCommandAddArgList(cmd, "-object", tmp, NULL); virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
ret = 0; ret = 0;
cleanup: cleanup:
virBufferFreeAndReset(&buf);
virJSONValueFree(props); virJSONValueFree(props);
VIR_FREE(tmp);
return ret; return ret;
} }
......
...@@ -66,6 +66,7 @@ int qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo, ...@@ -66,6 +66,7 @@ int qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
int qemuBuildTLSx509BackendProps(const char *tlspath, int qemuBuildTLSx509BackendProps(const char *tlspath,
bool isListen, bool isListen,
bool verifypeer, bool verifypeer,
const char *alias,
const char *secalias, const char *secalias,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virJSONValuePtr *propsret); virJSONValuePtr *propsret);
......
...@@ -166,11 +166,12 @@ qemuDomainAddDiskSrcTLSObject(virQEMUDriverPtr driver, ...@@ -166,11 +166,12 @@ qemuDomainAddDiskSrcTLSObject(virQEMUDriverPtr driver,
src->tlsCertdir, src->tlsCertdir,
false, false,
src->tlsVerify, src->tlsVerify,
src->tlsAlias,
&tlsProps, NULL) < 0) &tlsProps, NULL) < 0)
goto cleanup; goto cleanup;
if (qemuDomainAddTLSObjects(driver, vm, QEMU_ASYNC_JOB_NONE, if (qemuDomainAddTLSObjects(driver, vm, QEMU_ASYNC_JOB_NONE,
NULL, NULL, src->tlsAlias, &tlsProps) < 0) NULL, NULL, &tlsProps) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -1446,14 +1447,13 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver, ...@@ -1446,14 +1447,13 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
qemuDomainAsyncJob asyncJob, qemuDomainAsyncJob asyncJob,
const char *secAlias, const char *secAlias,
virJSONValuePtr *secProps, virJSONValuePtr *secProps,
const char *tlsAlias,
virJSONValuePtr *tlsProps) virJSONValuePtr *tlsProps)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int rc; int rc;
virErrorPtr orig_err; virErrorPtr orig_err;
if (!tlsAlias && !secAlias) if (!tlsProps && !secAlias)
return 0; return 0;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
...@@ -1467,13 +1467,9 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver, ...@@ -1467,13 +1467,9 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
goto error; goto error;
} }
if (tlsAlias) { if (tlsProps &&
rc = qemuMonitorAddObjectType(priv->mon, "tls-creds-x509", qemuMonitorAddObject(priv->mon, tlsProps, NULL) < 0)
tlsAlias, *tlsProps);
*tlsProps = NULL; /* qemuMonitorAddObjectType consumes */
if (rc < 0)
goto error; goto error;
}
return qemuDomainObjExitMonitor(driver, vm); return qemuDomainObjExitMonitor(driver, vm);
...@@ -1481,7 +1477,7 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver, ...@@ -1481,7 +1477,7 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
virErrorPreserveLast(&orig_err); virErrorPreserveLast(&orig_err);
ignore_value(qemuDomainObjExitMonitor(driver, vm)); ignore_value(qemuDomainObjExitMonitor(driver, vm));
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, tlsAlias); qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, NULL);
return -1; return -1;
} }
...@@ -1493,6 +1489,7 @@ qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps, ...@@ -1493,6 +1489,7 @@ qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps,
const char *tlsCertdir, const char *tlsCertdir,
bool tlsListen, bool tlsListen,
bool tlsVerify, bool tlsVerify,
const char *alias,
virJSONValuePtr *tlsProps, virJSONValuePtr *tlsProps,
virJSONValuePtr *secProps) virJSONValuePtr *secProps)
{ {
...@@ -1506,7 +1503,7 @@ qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps, ...@@ -1506,7 +1503,7 @@ qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps,
} }
if (qemuBuildTLSx509BackendProps(tlsCertdir, tlsListen, tlsVerify, if (qemuBuildTLSx509BackendProps(tlsCertdir, tlsListen, tlsVerify,
secAlias, qemuCaps, tlsProps) < 0) alias, secAlias, qemuCaps, tlsProps) < 0)
return -1; return -1;
return 0; return 0;
...@@ -1555,12 +1552,12 @@ qemuDomainAddChardevTLSObjects(virQEMUDriverPtr driver, ...@@ -1555,12 +1552,12 @@ qemuDomainAddChardevTLSObjects(virQEMUDriverPtr driver,
cfg->chardevTLSx509certdir, cfg->chardevTLSx509certdir,
dev->data.tcp.listen, dev->data.tcp.listen,
cfg->chardevTLSx509verify, cfg->chardevTLSx509verify,
&tlsProps, &secProps) < 0) *tlsAlias, &tlsProps, &secProps) < 0)
goto cleanup; goto cleanup;
dev->data.tcp.tlscreds = true; dev->data.tcp.tlscreds = true;
if (qemuDomainAddTLSObjects(driver, vm, QEMU_ASYNC_JOB_NONE, if (qemuDomainAddTLSObjects(driver, vm, QEMU_ASYNC_JOB_NONE,
*secAlias, &secProps, *tlsAlias, &tlsProps) < 0) *secAlias, &secProps, &tlsProps) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
......
...@@ -45,7 +45,6 @@ int qemuDomainAddTLSObjects(virQEMUDriverPtr driver, ...@@ -45,7 +45,6 @@ int qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
qemuDomainAsyncJob asyncJob, qemuDomainAsyncJob asyncJob,
const char *secAlias, const char *secAlias,
virJSONValuePtr *secProps, virJSONValuePtr *secProps,
const char *tlsAlias,
virJSONValuePtr *tlsProps); virJSONValuePtr *tlsProps);
int qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps, int qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps,
...@@ -53,6 +52,7 @@ int qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps, ...@@ -53,6 +52,7 @@ int qemuDomainGetTLSObjects(virQEMUCapsPtr qemuCaps,
const char *tlsCertdir, const char *tlsCertdir,
bool tlsListen, bool tlsListen,
bool tlsVerify, bool tlsVerify,
const char *alias,
virJSONValuePtr *tlsProps, virJSONValuePtr *tlsProps,
virJSONValuePtr *secProps); virJSONValuePtr *secProps);
......
...@@ -862,7 +862,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver, ...@@ -862,7 +862,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
if (qemuDomainGetTLSObjects(priv->qemuCaps, priv->migSecinfo, if (qemuDomainGetTLSObjects(priv->qemuCaps, priv->migSecinfo,
cfg->migrateTLSx509certdir, tlsListen, cfg->migrateTLSx509certdir, tlsListen,
cfg->migrateTLSx509verify, cfg->migrateTLSx509verify,
&tlsProps, &secProps) < 0) *tlsAlias, &tlsProps, &secProps) < 0)
goto error; goto error;
/* Ensure the domain doesn't already have the TLS objects defined... /* Ensure the domain doesn't already have the TLS objects defined...
...@@ -872,7 +872,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver, ...@@ -872,7 +872,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, *tlsAlias); qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, *tlsAlias);
if (qemuDomainAddTLSObjects(driver, vm, asyncJob, secAlias, &secProps, if (qemuDomainAddTLSObjects(driver, vm, asyncJob, secAlias, &secProps,
*tlsAlias, &tlsProps) < 0) &tlsProps) < 0)
goto error; goto error;
if (qemuMigrationParamsSetString(migParams, if (qemuMigrationParamsSetString(migParams,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册