提交 6ab7fd16 编写于 作者: P Peter Krempa

qemu: hotplug: Refactor RNG props formatting to use qemuMonitorCreateObjectProps

Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 e4a2bfe2
......@@ -5490,12 +5490,15 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
int
qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
virQEMUCapsPtr qemuCaps,
const char **type,
virJSONValuePtr *props)
{
char *objAlias = NULL;
char *charBackendAlias = NULL;
int ret = -1;
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
goto cleanup;
switch ((virDomainRNGBackend) rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) {
......@@ -5505,11 +5508,11 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
goto cleanup;
}
*type = "rng-random";
if (virJSONValueObjectCreate(props, "s:filename", rng->source.file,
NULL) < 0)
if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias,
"s:filename", rng->source.file,
NULL) < 0)
goto cleanup;
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
......@@ -5520,13 +5523,12 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
goto cleanup;
}
*type = "rng-egd";
if (!(charBackendAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
goto cleanup;
if (virJSONValueObjectCreate(props, "s:chardev", charBackendAlias,
NULL) < 0)
if (qemuMonitorCreateObjectProps(props, "rng-egd", objAlias,
"s:chardev", charBackendAlias,
NULL) < 0)
goto cleanup;
break;
......@@ -5540,35 +5542,12 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
ret = 0;
cleanup:
VIR_FREE(objAlias);
VIR_FREE(charBackendAlias);
return ret;
}
static char *
qemuBuildRNGBackendStr(virDomainRNGDefPtr rng,
virQEMUCapsPtr qemuCaps)
{
const char *type = NULL;
char *alias = NULL;
virJSONValuePtr props = NULL;
char *ret = NULL;
if (virAsprintf(&alias, "obj%s", rng->info.alias) < 0)
goto cleanup;
if (qemuBuildRNGBackendProps(rng, qemuCaps, &type, &props) < 0)
goto cleanup;
ret = virQEMUBuildObjectCommandlineFromJSONType(type, alias, props);
cleanup:
VIR_FREE(alias);
virJSONValueFree(props);
return ret;
}
char *
qemuBuildRNGDevStr(const virDomainDef *def,
virDomainRNGDefPtr dev,
......@@ -5636,8 +5615,11 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager,
size_t i;
for (i = 0; i < def->nrngs; i++) {
virJSONValuePtr props;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainRNGDefPtr rng = def->rngs[i];
char *tmp;
int rc;
if (!rng->info.alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -5656,12 +5638,17 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager,
VIR_FREE(tmp);
}
/* add the RNG source backend */
if (!(tmp = qemuBuildRNGBackendStr(rng, qemuCaps)))
if (qemuBuildRNGBackendProps(rng, qemuCaps, &props) < 0)
return -1;
virCommandAddArgList(cmd, "-object", tmp, NULL);
VIR_FREE(tmp);
rc = virQEMUBuildObjectCommandlineFromJSON(&buf, props);
virJSONValueFree(props);
if (rc < 0)
return -1;
virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
/* add the device */
if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps)))
......
......@@ -142,7 +142,6 @@ char *qemuBuildRNGDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps);
int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
virQEMUCapsPtr qemuCaps,
const char **type,
virJSONValuePtr *props);
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);
......
......@@ -1979,11 +1979,8 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
bool teardowncgroup = false;
bool teardowndevice = false;
bool chardevAdded = false;
bool objAdded = false;
virJSONValuePtr props = NULL;
const char *type;
int ret = -1;
int rv;
if (qemuAssignDeviceRNGAlias(vm->def, rng) < 0)
goto cleanup;
......@@ -2007,10 +2004,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps)))
goto cleanup;
if (qemuBuildRNGBackendProps(rng, priv->qemuCaps, &type, &props) < 0)
goto cleanup;
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
if (qemuBuildRNGBackendProps(rng, priv->qemuCaps, &props) < 0)
goto cleanup;
if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
......@@ -2032,11 +2026,8 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
goto exit_monitor;
chardevAdded = true;
rv = qemuMonitorAddObjectType(priv->mon, type, objAlias, props);
props = NULL; /* qemuMonitorAddObjectType consumes */
if (rv < 0)
if (qemuMonitorAddObject(priv->mon, &props, &objAlias) < 0)
goto exit_monitor;
objAdded = true;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
goto exit_monitor;
......@@ -2071,7 +2062,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
exit_monitor:
virErrorPreserveLast(&orig_err);
if (objAdded)
if (objAlias)
ignore_value(qemuMonitorDelObject(priv->mon, objAlias));
if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD && chardevAdded)
ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册