This includes the 'pc-dimm', 'nvdimm', 'virtio-pmem-pci' and
'virtio-mem-pci' devices.
The value types according to QEMU are:
'pc-dimm'
node=<uint32> - (default: 0)
memdev=<link<memory-backend>>
'nvdimm'
label-size=<int>
memdev=<link<memory-backend>>
node=<uint32> - (default: 0)
unarmed=<bool> - (default: false)
uuid=<QemuUUID>
'virtio-pmem-pci'
memdev=<link<memory-backend>>
'virtio-mem-pci'
block-size=<size>
memdev=<link<memory-backend>>
node=<uint32> - (default: 0)
requested-size=<size>
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 60 +++++++++++++++++++----------------------
src/qemu/qemu_command.h | 7 +++--
src/qemu/qemu_hotplug.c | 6 ++---
3 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6fa804f7d8..794119a58c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3723,13 +3723,14 @@ qemuBuildMemoryDimmBackendStr(virCommand *cmd,
}
-char *
-qemuBuildMemoryDeviceStr(const virDomainDef *def,
- virDomainMemoryDef *mem,
- virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+virJSONValue *
+qemuBuildMemoryDeviceProps(const virDomainDef *def,
+ virDomainMemoryDef *mem)
{
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_autoptr(virJSONValue) props = NULL;
const char *device = NULL;
+ g_autofree char *uuidstr = NULL;
+ virTristateBool unarmed = VIR_TRISTATE_BOOL_ABSENT;
if (!mem->info.alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3761,37 +3762,31 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def,
break;
}
- virBufferAsprintf(&buf, "%s,", device);
-
- if (mem->targetNode >= 0)
- virBufferAsprintf(&buf, "node=%d,", mem->targetNode);
-
- if (mem->labelsize)
- virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize *
1024);
-
- if (mem->blocksize) {
- virBufferAsprintf(&buf, "block-size=%llu,", mem->blocksize *
1024);
- virBufferAsprintf(&buf, "requested-size=%llu,",
mem->requestedsize * 1024);
- }
+ if (mem->readonly)
+ unarmed = VIR_TRISTATE_BOOL_YES;
if (mem->uuid) {
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
+ uuidstr = g_new0(char, VIR_UUID_STRING_BUFLEN);
virUUIDFormat(mem->uuid, uuidstr);
- virBufferAsprintf(&buf, "uuid=%s,", uuidstr);
}
- if (mem->readonly) {
- virBufferAddLit(&buf, "unarmed=on,");
- }
-
- virBufferAsprintf(&buf, "memdev=mem%s,id=%s",
- mem->info.alias, mem->info.alias);
+ if (virJSONValueObjectCreate(&props,
+ "s:driver", device,
+ "k:node", mem->targetNode,
+ "P:label-size", mem->labelsize * 1024,
+ "P:block-size", mem->blocksize * 1024,
+ "P:requested-size", mem->requestedsize *
1024,
+ "S:uuid", uuidstr,
+ "T:unarmed", unarmed,
+ "f:memdev", g_strdup_printf("mem%s",
mem->info.alias),
+ "s:id", mem->info.alias,
+ NULL) < 0)
+ return NULL;
- if (qemuBuildDeviceAddressStr(&buf, def, &mem->info) < 0)
+ if (qemuBuildDeviceAddressProps(props, def, &mem->info) < 0)
return NULL;
- return virBufferContentAndReset(&buf);
+ return g_steal_pointer(&props);
}
@@ -7837,17 +7832,16 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd,
/* memory hotplug requires NUMA to be enabled - we already checked
* that memory devices are present only when NUMA is */
for (i = 0; i < def->nmems; i++) {
- char *dimmStr;
+ g_autoptr(virJSONValue) props = NULL;
if (qemuBuildMemoryDimmBackendStr(cmd, def->mems[i], def, cfg, priv) < 0)
return -1;
- if (!(dimmStr = qemuBuildMemoryDeviceStr(def, def->mems[i],
priv->qemuCaps)))
+ if (!(props = qemuBuildMemoryDeviceProps(def, def->mems[i])))
return -1;
- virCommandAddArgList(cmd, "-device", dimmStr, NULL);
-
- VIR_FREE(dimmStr);
+ if (qemuBuildDeviceCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0)
+ return -1;
}
return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 6ce151d8d9..86df734c57 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -160,10 +160,9 @@ int qemuBuildMemoryBackendProps(virJSONValue **backendProps,
bool force,
bool systemMemory);
-char *
-qemuBuildMemoryDeviceStr(const virDomainDef *def,
- virDomainMemoryDef *mem,
- virQEMUCaps *qemuCaps);
+virJSONValue *
+qemuBuildMemoryDeviceProps(const virDomainDef *def,
+ virDomainMemoryDef *mem);
/* Current, best practice */
char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f833a619a7..3e0c9cf981 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2434,7 +2434,7 @@ qemuDomainAttachMemory(virQEMUDriver *driver,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
unsigned long long oldmem = virDomainDefGetMemoryTotal(vm->def);
unsigned long long newmem = oldmem + mem->size;
- g_autofree char *devstr = NULL;
+ g_autoptr(virJSONValue) devprops = NULL;
g_autofree char *objalias = NULL;
bool objAdded = false;
bool releaseaddr = false;
@@ -2463,7 +2463,7 @@ qemuDomainAttachMemory(virQEMUDriver *driver,
objalias = g_strdup_printf("mem%s", mem->info.alias);
- if (!(devstr = qemuBuildMemoryDeviceStr(vm->def, mem, priv->qemuCaps)))
+ if (!(devprops = qemuBuildMemoryDeviceProps(vm->def, mem)))
goto cleanup;
if (qemuBuildMemoryBackendProps(&props, objalias, cfg,
@@ -2495,7 +2495,7 @@ qemuDomainAttachMemory(virQEMUDriver *driver,
goto exit_monitor;
objAdded = true;
- if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+ if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0)
goto exit_monitor;
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
--
2.31.1