Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 61 +++++++++++++++++++------------------------------
src/qemu/qemu_command.h | 1 -
src/qemu/qemu_hotplug.c | 15 +++---------
3 files changed, 27 insertions(+), 50 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 00fb1a3b32..c3573982d6 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5495,12 +5495,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)) {
@@ -5510,11 +5513,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:
@@ -5525,13 +5528,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;
@@ -5545,35 +5547,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,
@@ -5641,8 +5620,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",
@@ -5661,12 +5643,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)))
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 2b2168d1ee..d2ee01e810 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -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);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5892c18e5e..238d4b9cc5 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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));
--
2.16.2