Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 53 ++++++++++++++++++++-----------------------------
src/qemu/qemu_hotplug.c | 8 +-------
2 files changed, 23 insertions(+), 38 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f728b59659..f604a9e8aa 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8792,43 +8792,25 @@ qemuBuildShmemDevStr(virDomainDefPtr def,
virJSONValuePtr
qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem)
{
+ char *mem_alias = NULL;
char *mem_path = NULL;
virJSONValuePtr ret = NULL;
if (virAsprintf(&mem_path, "/dev/shm/%s", shmem->name) < 0)
return NULL;
- virJSONValueObjectCreate(&ret,
- "s:mem-path", mem_path,
- "U:size", shmem->size,
- "b:share", true,
- NULL);
-
- VIR_FREE(mem_path);
- return ret;
-}
-
-
-static char *
-qemuBuildShmemBackendMemStr(virDomainShmemDefPtr shmem)
-{
- char *ret = NULL;
- char *alias = NULL;
- virJSONValuePtr props = qemuBuildShmemBackendMemProps(shmem);
-
- if (!props)
- return NULL;
-
- if (virAsprintf(&alias, "shmmem-%s", shmem->info.alias) < 0)
+ if (virAsprintf(&mem_alias, "shmmem-%s", shmem->info.alias) < 0)
goto cleanup;
- ret = virQEMUBuildObjectCommandlineFromJSONType("memory-backend-file",
- alias,
- props);
- cleanup:
- VIR_FREE(alias);
- virJSONValueFree(props);
+ qemuMonitorCreateObjectProps(&ret, "memory-backend-file", mem_alias,
+ "s:mem-path", mem_path,
+ "U:size", shmem->size,
+ "b:share", true,
+ NULL);
+ cleanup:
+ VIR_FREE(mem_alias);
+ VIR_FREE(mem_path);
return ret;
}
@@ -8842,7 +8824,10 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
virQEMUCapsPtr qemuCaps,
bool chardevStdioLogd)
{
+ virJSONValuePtr memProps = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
char *devstr = NULL;
+ int rc;
if (shmem->size) {
/*
@@ -8876,11 +8861,17 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
break;
case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN:
- if (!(devstr = qemuBuildShmemBackendMemStr(shmem)))
+ if (!(memProps = qemuBuildShmemBackendMemProps(shmem)))
return -1;
- virCommandAddArgList(cmd, "-object", devstr, NULL);
- VIR_FREE(devstr);
+ rc = virQEMUBuildObjectCommandlineFromJSON(&buf, memProps);
+ virJSONValueFree(memProps);
+
+ if (rc < 0)
+ return -1;
+
+ virCommandAddArg(cmd, "-object");
+ virCommandAddArgBuffer(cmd, &buf);
ATTRIBUTE_FALLTHROUGH;
case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f8358a8b0b..02bc88f863 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2751,8 +2751,6 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
if (!(props = qemuBuildShmemBackendMemProps(shmem)))
goto cleanup;
- if (virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias) <
0)
- goto cleanup;
}
qemuDomainObjEnterMonitor(driver, vm);
@@ -2762,12 +2760,8 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
&shmem->server.chr) < 0)
goto exit_monitor;
} else {
- if (qemuMonitorAddObjectType(priv->mon, "memory-backend-file",
- memAlias, props) < 0) {
- props = NULL;
+ if (qemuMonitorAddObject(priv->mon, &props, &memAlias) < 0)
goto exit_monitor;
- }
- props = NULL;
}
release_backing = true;
--
2.16.2