From nobody Wed May 14 07:20:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527700032555381.56854322058916; Wed, 30 May 2018 10:07:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5B21E329D; Wed, 30 May 2018 17:07:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBD48608F2; Wed, 30 May 2018 17:07:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 181D44CA82; Wed, 30 May 2018 17:07:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4UH6tjm007328 for ; Wed, 30 May 2018 13:06:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 53D5E2026DEF; Wed, 30 May 2018 17:06:55 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED2E22026DFD for ; Wed, 30 May 2018 17:06:54 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 30 May 2018 19:06:32 +0200 Message-Id: <8ad1fcb31170100488053ca69a800f2e1c7d8afd.1527699462.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/13] qemu: hotplug: Refactor memory props formatting to qemuMonitorCreateObjectProps X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 30 May 2018 17:07:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- 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 *backendP= rops, virBitmapPtr autoNodeset, bool force) { + const char *backendType =3D "memory-backend-file"; virDomainNumatuneMemMode mode; const long system_page_size =3D virGetSystemPageSizeKB(); virDomainMemoryAccess memAccess =3D mem->access; @@ -2998,7 +2999,6 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, * @useHugepage. */ *backendProps =3D NULL; - *backendType =3D NULL; if (mem->targetNode >=3D 0) { /* memory devices could provide a invalid guest node */ @@ -3087,7 +3087,6 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, if (useHugepage || mem->nvdimmPath || memAccess || def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { - *backendType =3D "memory-backend-file"; if (useHugepage) { if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) <= 0) @@ -3140,7 +3139,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, break; } } else { - *backendType =3D "memory-backend-ram"; + backendType =3D "memory-backend-ram"; } if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) @@ -3174,13 +3173,13 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, ret =3D 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 *backendP= rops, ret =3D 0; } - *backendProps =3D props; - props =3D NULL; + if (!(*backendProps =3D qemuMonitorCreateObjectPropsWrap(backendType, = alias, + &props))) + ret =3D -1; cleanup: virJSONValueFree(props); @@ -3206,11 +3206,10 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, virQEMUDriverConfigPtr cfg, size_t cell, qemuDomainObjPrivatePtr priv, - char **backendStr) + virBufferPtr buf) { virJSONValuePtr props =3D NULL; char *alias =3D NULL; - const char *backendType; int ret =3D -1; int rc; virDomainMemoryDef mem =3D { 0 }; @@ -3220,18 +3219,15 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, if (virAsprintf(&alias, "ram-node%zu", cell) < 0) goto cleanup; - *backendStr =3D NULL; mem.size =3D memsize; mem.targetNode =3D cell; mem.info.alias =3D alias; - if ((rc =3D qemuBuildMemoryBackendProps(&props, &backendType, cfg, pri= v->qemuCaps, + if ((rc =3D qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemu= Caps, def, &mem, priv->autoNodeset, fa= lse)) < 0) goto cleanup; - if (!(*backendStr =3D virQEMUBuildObjectCommandlineFromJSONType(backen= dType, - alias, - props))) + if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) goto cleanup; ret =3D 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 =3D NULL; char *alias =3D NULL; - const char *backendType; - char *ret =3D NULL; + int ret =3D -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->qemuC= aps, + if (qemuBuildMemoryBackendProps(&props, alias, cfg, priv->qemuCaps, def, mem, priv->autoNodeset, true) < 0) goto cleanup; - ret =3D virQEMUBuildObjectCommandlineFromJSONType(backendType, alias, = props); + if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0) + goto cleanup; + + ret =3D 0; cleanup: VIR_FREE(alias); @@ -7397,7 +7396,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, virQEMUCapsPtr qemuCaps =3D priv->qemuCaps; virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *cpumask =3D NULL, *tmpmask =3D NULL, *next =3D NULL; - char **nodeBackends =3D NULL; + virBufferPtr *nodeBackends =3D NULL; bool needBackend =3D false; int rc; int ret =3D -1; @@ -7458,8 +7457,12 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, for (i =3D 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 =3D qemuBuildMemoryCellBackendStr(def, cfg, i, priv, - &nodeBackends[i])) < 0) + nodeBackends[i])) < 0) goto cleanup; if (rc =3D=3D 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=3D%zu", i); @@ -7555,7 +7560,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, if (nodeBackends) { for (i =3D 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 =3D 0; i < def->nmems; i++) { - char *backStr; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *dimmStr; - if (!(backStr =3D qemuBuildMemoryDimmBackendStr(def->mems[i], def, - cfg, priv))) + if (qemuBuildMemoryDimmBackendStr(&buf, def->mems[i], def, cfg, pr= iv) < 0) return -1; - if (!(dimmStr =3D qemuBuildMemoryDeviceStr(def->mems[i]))) { - VIR_FREE(backStr); + virCommandAddArg(cmd, "-object"); + virCommandAddArgBuffer(cmd, &buf); + + if (!(dimmStr =3D 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 *domai= nDef, 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 =3D oldmem + mem->size; char *devstr =3D NULL; char *objalias =3D NULL; - const char *backendType; bool objAdded =3D false; bool teardownlabel =3D false; bool teardowncgroup =3D false; @@ -2107,7 +2106,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, virObjectEventPtr event; int id; int ret =3D -1; - int rv; qemuDomainMemoryDeviceAlignSize(vm->def, mem); @@ -2128,7 +2126,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (!(devstr =3D qemuBuildMemoryDeviceStr(mem))) goto cleanup; - if (qemuBuildMemoryBackendProps(&props, &backendType, cfg, + if (qemuBuildMemoryBackendProps(&props, objalias, cfg, priv->qemuCaps, vm->def, mem, NULL, tr= ue) < 0) goto cleanup; @@ -2154,9 +2152,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, goto removedef; qemuDomainObjEnterMonitor(driver, vm); - rv =3D qemuMonitorAddObjectType(priv->mon, backendType, objalias, prop= s); - props =3D NULL; /* qemuMonitorAddObjectType consumes */ - if (rv < 0) + if (qemuMonitorAddObject(priv->mon, &props, NULL) < 0) goto exit_monitor; objAdded =3D true; --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list