[PATCH 058/103] qemuBuildMemoryDeviceCommandLine: Generate via JSON
Ján Tomko
jtomko at redhat.com
Fri Oct 8 12:42:32 UTC 2021
On a Thursday in 2021, Peter Krempa wrote:
>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 at 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),
One more usage of 'f'.
Also, I'm really glad these keys use letters, instead of, let's say,
Morse code.
>+ "s:id", mem->info.alias,
>+ NULL) < 0)
>+ return NULL;
>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20211008/ce704bd4/attachment-0001.sig>
More information about the libvir-list
mailing list