Signed-off-by: Peter Krempa <pkre...@redhat.com> --- src/qemu/qemu_command.c | 76 ++++++++++++++++++++++++++----------------------- src/qemu/qemu_command.h | 2 +- src/qemu/qemu_hotplug.c | 8 ++---- 3 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c3573982d6..f728b59659 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2943,7 +2943,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, /** * qemuBuildMemoryBackendProps: * @backendProps: [out] constructed object - * @backendType: [out] type of the backennd used + * @alias: alias of the device * @cfg: qemu driver config object * @qemuCaps: qemu capabilities object * @def: domain definition object @@ -2968,7 +2968,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, */ int qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, - const char **backendType, + const char *alias, virQEMUDriverConfigPtr cfg, virQEMUCapsPtr qemuCaps, virDomainDefPtr def, @@ -2976,6 +2976,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, virBitmapPtr autoNodeset, bool force) { + const char *backendType = "memory-backend-file"; virDomainNumatuneMemMode mode; const long system_page_size = virGetSystemPageSizeKB(); virDomainMemoryAccess memAccess = mem->access; @@ -2998,7 +2999,6 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, * @useHugepage. */ *backendProps = NULL; - *backendType = NULL; if (mem->targetNode >= 0) { /* memory devices could provide a invalid guest node */ @@ -3087,7 +3087,6 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, if (useHugepage || mem->nvdimmPath || memAccess || def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) { - *backendType = "memory-backend-file"; if (useHugepage) { if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) < 0) @@ -3140,7 +3139,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, break; } } else { - *backendType = "memory-backend-ram"; + backendType = "memory-backend-ram"; } if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) @@ -3174,13 +3173,13 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, ret = 1; } else { /* otherwise check the required capability */ - if (STREQ(*backendType, "memory-backend-file") && + if (STREQ(backendType, "memory-backend-file") && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this qemu doesn't support the " "memory-backend-file object")); goto cleanup; - } else if (STREQ(*backendType, "memory-backend-ram") && + } else if (STREQ(backendType, "memory-backend-ram") && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this qemu doesn't support the " @@ -3191,8 +3190,9 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, ret = 0; } - *backendProps = props; - props = NULL; + if (!(*backendProps = qemuMonitorCreateObjectPropsWrap(backendType, alias, + &props))) + ret = -1; cleanup: virJSONValueFree(props); @@ -3206,11 +3206,10 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, virQEMUDriverConfigPtr cfg, size_t cell, qemuDomainObjPrivatePtr priv, - char **backendStr) + virBufferPtr buf) { virJSONValuePtr props = NULL; char *alias = NULL; - const char *backendType; int ret = -1; int rc; virDomainMemoryDef mem = { 0 }; @@ -3220,18 +3219,15 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, if (virAsprintf(&alias, "ram-node%zu", cell) < 0) goto cleanup; - *backendStr = NULL; mem.size = memsize; mem.targetNode = cell; mem.info.alias = alias; - if ((rc = qemuBuildMemoryBackendProps(&props, &backendType, cfg, priv->qemuCaps, + if ((rc = qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemuCaps, def, &mem, priv->autoNodeset, false)) < 0) goto cleanup; - if (!(*backendStr = virQEMUBuildObjectCommandlineFromJSONType(backendType, - alias, - props))) + if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) goto cleanup; ret = rc; @@ -3244,31 +3240,34 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, } -static char * -qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem, +static int +qemuBuildMemoryDimmBackendStr(virBufferPtr buf, + virDomainMemoryDefPtr mem, virDomainDefPtr def, virQEMUDriverConfigPtr cfg, qemuDomainObjPrivatePtr priv) { virJSONValuePtr props = NULL; char *alias = NULL; - const char *backendType; - char *ret = NULL; + int ret = -1; if (!mem->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("memory device alias is not assigned")); - return NULL; + return -1; } if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0) goto cleanup; - if (qemuBuildMemoryBackendProps(&props, &backendType, cfg, priv->qemuCaps, + if (qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemuCaps, def, mem, priv->autoNodeset, true) < 0) goto cleanup; - ret = virQEMUBuildObjectCommandlineFromJSONType(backendType, alias, props); + if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) + goto cleanup; + + ret = 0; cleanup: VIR_FREE(alias); @@ -7397,7 +7396,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, virQEMUCapsPtr qemuCaps = priv->qemuCaps; virBuffer buf = VIR_BUFFER_INITIALIZER; char *cpumask = NULL, *tmpmask = NULL, *next = NULL; - char **nodeBackends = NULL; + virBufferPtr *nodeBackends = NULL; bool needBackend = false; int rc; int ret = -1; @@ -7458,8 +7457,12 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, for (i = 0; i < ncells; i++) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) || virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) { + + if (VIR_ALLOC(nodeBackends[i]) < 0) + goto cleanup; + if ((rc = qemuBuildMemoryCellBackendStr(def, cfg, i, priv, - &nodeBackends[i])) < 0) + nodeBackends[i])) < 0) goto cleanup; if (rc == 0) @@ -7491,8 +7494,10 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, goto cleanup; } - if (needBackend) - virCommandAddArgList(cmd, "-object", nodeBackends[i], NULL); + if (needBackend) { + virCommandAddArg(cmd, "-object"); + virCommandAddArgBuffer(cmd, nodeBackends[i]); + } virCommandAddArg(cmd, "-numa"); virBufferAsprintf(&buf, "node,nodeid=%zu", i); @@ -7555,7 +7560,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, if (nodeBackends) { for (i = 0; i < ncells; i++) - VIR_FREE(nodeBackends[i]); + virBufferFreeAndReset(nodeBackends[i]); VIR_FREE(nodeBackends); } @@ -7576,21 +7581,20 @@ qemuBuildMemoryDeviceCommandLine(virCommandPtr 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 *backStr; + virBuffer buf = VIR_BUFFER_INITIALIZER; char *dimmStr; - if (!(backStr = qemuBuildMemoryDimmBackendStr(def->mems[i], def, - cfg, priv))) + if (qemuBuildMemoryDimmBackendStr(&buf, def->mems[i], def, cfg, priv) < 0) return -1; - if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i]))) { - VIR_FREE(backStr); + virCommandAddArg(cmd, "-object"); + virCommandAddArgBuffer(cmd, &buf); + + if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i]))) return -1; - } - virCommandAddArgList(cmd, "-object", backStr, "-device", dimmStr, NULL); + virCommandAddArgList(cmd, "-device", dimmStr, NULL); - VIR_FREE(backStr); VIR_FREE(dimmStr); } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index d2ee01e810..e4f56cf89d 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -120,7 +120,7 @@ int qemuBuildControllerDevStr(const virDomainDef *domainDef, int *nusbcontroller); int qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, - const char **backendType, + const char *alias, virQEMUDriverConfigPtr cfg, virQEMUCapsPtr qemuCaps, virDomainDefPtr def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 238d4b9cc5..f8358a8b0b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2098,7 +2098,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, unsigned long long newmem = oldmem + mem->size; char *devstr = NULL; char *objalias = NULL; - const char *backendType; bool objAdded = false; bool teardownlabel = false; bool teardowncgroup = false; @@ -2107,7 +2106,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, virObjectEventPtr event; int id; int ret = -1; - int rv; qemuDomainMemoryDeviceAlignSize(vm->def, mem); @@ -2128,7 +2126,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (!(devstr = qemuBuildMemoryDeviceStr(mem))) goto cleanup; - if (qemuBuildMemoryBackendProps(&props, &backendType, cfg, + if (qemuBuildMemoryBackendProps(&props, objalias, cfg, priv->qemuCaps, vm->def, mem, NULL, true) < 0) goto cleanup; @@ -2154,9 +2152,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, goto removedef; qemuDomainObjEnterMonitor(driver, vm); - rv = qemuMonitorAddObjectType(priv->mon, backendType, objalias, props); - props = NULL; /* qemuMonitorAddObjectType consumes */ - if (rv < 0) + if (qemuMonitorAddObject(priv->mon, &props, NULL) < 0) goto exit_monitor; objAdded = true; -- 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list