From nobody Sat Jul 12 09:29:58 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510069885424873.1773150092192; Tue, 7 Nov 2017 07:51:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D11C882109; Tue, 7 Nov 2017 15:51:23 +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 AD2015D976; Tue, 7 Nov 2017 15:51:23 +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 722083FCFC; Tue, 7 Nov 2017 15:51:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7FpF9Q031877 for ; Tue, 7 Nov 2017 10:51:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 98A6A5D6A9; Tue, 7 Nov 2017 15:51:15 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20A785EDEA for ; Tue, 7 Nov 2017 15:51:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D11C882109 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 7 Nov 2017 16:51:03 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 4/5] qemu: Use predictable file names for memory-backend-file 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 07 Nov 2017 15:51:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case: $memoryBackingDir/libvirt/qemu/$shortName/$alias where $shortName is result of virDomainObjGetShortName(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_conf.c | 55 +++++++++++++++++- src/qemu/qemu_conf.h | 9 ++- src/qemu/qemu_driver.c | 17 ++++++ src/qemu/qemu_process.c | 65 ++++++++++++++++++= ---- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 ++- .../qemuxml2argv-hugepages-memaccess2.args | 9 ++- 10 files changed, 155 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c949afe90..c12cfec7a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3419,7 +3419,7 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPro= ps, } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ - if (qemuGetMemoryBackingPath(cfg, &memPath) < 0) + if (qemuGetMemoryBackingPath(def, cfg, mem->info.alias, &memPa= th) < 0) goto cleanup; } =20 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f3cff1503..af503d31c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1750,9 +1750,41 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, } =20 =20 +int +qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path) +{ + return virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir); +} + + +int +qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path) +{ + char *shortName =3D NULL; + char *base =3D NULL; + int ret =3D -1; + + if (!(shortName =3D virDomainDefGetShortName(def)) || + qemuGetMemoryBackingBasePath(cfg, &base) < 0 || + virAsprintf(path, "%s/%s", base, shortName) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_FREE(base); + VIR_FREE(shortName); + return ret; +} + + /** * qemuGetMemoryBackingPath: + * @def: domain definition * @cfg: the driver config + * @alias: memory object alias * @memPath: constructed path * * Constructs path to memory backing dir and stores it at @memPath. @@ -1761,8 +1793,27 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, * -1 otherwise (with error reported). */ int -qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath) { - return VIR_STRDUP(*memPath, cfg->memoryBackingDir); + char *domainPath =3D NULL; + int ret =3D -1; + + if (!alias) { + /* This should never happen (TM) */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("memory device alias is not assigned")); + goto cleanup; + } + + if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 || + virAsprintf(memPath, "%s/%s", domainPath, alias) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_FREE(domainPath); + return ret; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 9d6866816..a553e30e2 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -364,6 +364,13 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def, unsigned long long pagesize, char **memPath); =20 -int qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath); #endif /* __QEMUD_CONF_H */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bb53d78ea..47f85b9bf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -631,6 +631,7 @@ qemuStateInitialize(bool privileged, uid_t run_uid =3D -1; gid_t run_gid =3D -1; char *hugepagePath =3D NULL; + char *memoryBackingPath =3D NULL; size_t i; =20 if (VIR_ALLOC(qemu_driver) < 0) @@ -889,6 +890,21 @@ qemuStateInitialize(bool privileged, VIR_FREE(hugepagePath); } =20 + if (qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath) < 0) + goto error; + + if (virFileMakePath(memoryBackingPath) < 0) { + virReportSystemError(errno, + _("unable to create memory backing path %s"), + memoryBackingPath); + goto error; + } + + if (privileged && + virFileUpdatePerm(memoryBackingPath, + 0, S_IXGRP | S_IXOTH) < 0) + goto error; + if (!(qemu_driver->closeCallbacks =3D virCloseCallbacksNew())) goto error; =20 @@ -946,6 +962,7 @@ qemuStateInitialize(bool privileged, virObjectUnref(conn); VIR_FREE(driverConf); VIR_FREE(hugepagePath); + VIR_FREE(memoryBackingPath); qemuStateCleanup(); return -1; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8eef2794e..eca41261a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3324,6 +3324,36 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, } =20 =20 +static bool +qemuProcessNeedMemoryBackingPath(virDomainDefPtr def, + virDomainMemoryDefPtr mem) +{ + size_t i; + size_t numaNodes; + + if (def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE || + def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + + numaNodes =3D virDomainNumaGetNodeCount(def->numa); + for (i =3D 0; i < numaNodes; i++) { + if (virDomainNumaGetNodeMemoryAccessMode(def->numa, i) + !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + } + + if (mem && + mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && + (mem->access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT || + (mem->targetNode >=3D 0 && + virDomainNumaGetNodeMemoryAccessMode(def->numa, mem->targetNode) + !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT))) + return true; + + return false; +} + + static int qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, virDomainDefPtr def, @@ -3365,33 +3395,46 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr= driver, bool build) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - char *hugepagePath =3D NULL; + char *path =3D NULL; size_t i; - bool shouldBuild =3D false; + bool shouldBuildHP =3D false; + bool shouldBuildMB =3D false; int ret =3D -1; =20 - if (build) - shouldBuild =3D qemuProcessNeedHugepagesPath(vm->def, mem); + if (build) { + shouldBuildHP =3D qemuProcessNeedHugepagesPath(vm->def, mem); + shouldBuildMB =3D qemuProcessNeedMemoryBackingPath(vm->def, mem); + } =20 - if (!build || shouldBuild) { + if (!build || shouldBuildHP) { for (i =3D 0; i < cfg->nhugetlbfs; i++) { - VIR_FREE(hugepagePath); - hugepagePath =3D qemuGetDomainHugepagePath(vm->def, &cfg->huge= tlbfs[i]); + path =3D qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]= ); =20 - if (!hugepagePath) + if (!path) goto cleanup; =20 if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, - hugepagePath, build= ) < 0) + path, build) < 0) goto cleanup; =20 - VIR_FREE(hugepagePath); + VIR_FREE(path); } } =20 + if (!build || shouldBuildMB) { + if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0) + goto cleanup; + + if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, + path, build) < 0) + goto cleanup; + + VIR_FREE(path); + } + ret =3D 0; cleanup: - VIR_FREE(hugepagePath); + VIR_FREE(path); virObjectUnref(cfg); return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/= tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=3Dnone \ -M pc \ -m 214 \ -smp 16,sockets=3D2,cores=3D4,threads=3D2 \ --object memory-backend-file,id=3Dram-node0,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node0,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=3Dyes,size=3D112197632 \ -numa node,nodeid=3D0,cpus=3D0-7,memdev=3Dram-node0 \ --object memory-backend-file,id=3Dram-node1,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node1,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node1,\ share=3Dno,size=3D112197632 \ -numa node,nodeid=3D1,cpus=3D8-15,memdev=3Dram-node1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.ar= gs b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args index 12f3d8ab8..fa1353259 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args @@ -11,7 +11,8 @@ QEMU_AUDIO_DRV=3Dnone \ -m 14336 \ -mem-prealloc \ -smp 8,sockets=3D1,cores=3D8,threads=3D1 \ --object memory-backend-file,id=3Dram-node0,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node0,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node0,\ share=3Dyes,size=3D15032385536 \ -numa node,nodeid=3D0,cpus=3D0-7,memdev=3Dram-node0 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.a= rgs b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args index 585e4d506..6f73a1b99 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args @@ -11,10 +11,12 @@ QEMU_AUDIO_DRV=3Dnone \ -m 28672 \ -mem-prealloc \ -smp 20,sockets=3D1,cores=3D8,threads=3D1 \ --object memory-backend-file,id=3Dram-node0,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node0,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node0,\ share=3Dno,size=3D15032385536 \ -numa node,nodeid=3D0,cpus=3D0-7,memdev=3Dram-node0 \ --object memory-backend-file,id=3Dram-node1,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node1,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node1,\ share=3Dyes,size=3D15032385536 \ -numa node,nodeid=3D1,cpus=3D8-15,memdev=3Dram-node1 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.a= rgs b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args index e9a57a69e..3c352fe03 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args @@ -11,13 +11,16 @@ QEMU_AUDIO_DRV=3Dnone \ -m 43008 \ -mem-prealloc \ -smp 32,sockets=3D1,cores=3D24,threads=3D1 \ --object memory-backend-file,id=3Dram-node0,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node0,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node0,\ share=3Dyes,size=3D15032385536 \ -numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ --object memory-backend-file,id=3Dram-node1,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node1,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node1,\ share=3Dyes,size=3D15032385536 \ -numa node,nodeid=3D1,cpus=3D2-3,memdev=3Dram-node1 \ --object memory-backend-file,id=3Dram-node2,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node2,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node2,\ share=3Dno,size=3D15032385536 \ -numa node,nodeid=3D2,cpus=3D4-5,memdev=3Dram-node2 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args = b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args index 55db49171..d8e506c19 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args @@ -10,17 +10,20 @@ QEMU_AUDIO_DRV=3Dnone \ -M pc \ -m size=3D4194304k,slots=3D16,maxmem=3D8388608k \ -smp 4,sockets=3D4,cores=3D1,threads=3D1 \ --object memory-backend-file,id=3Dram-node0,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node0,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=3Dno,size=3D1073741824,host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D0,cpus=3D0,memdev=3Dram-node0 \ -object memory-backend-file,id=3Dram-node1,prealloc=3Dyes,\ mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=3Dyes,size=3D= 1073741824,\ host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D1,cpus=3D1,memdev=3Dram-node1 \ --object memory-backend-file,id=3Dram-node2,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node2,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node2,\ share=3Dno,size=3D1073741824,host-nodes=3D0-3,policy=3Dbind \ -numa node,nodeid=3D2,cpus=3D2,memdev=3Dram-node2 \ --object memory-backend-file,id=3Dram-node3,mem-path=3D/var/lib/libvirt/qem= u/ram,\ +-object memory-backend-file,id=3Dram-node3,\ +mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node3,\ share=3Dno,size=3D1073741824,host-nodes=3D3,policy=3Dbind \ -numa node,nodeid=3D3,cpus=3D3,memdev=3Dram-node3 \ -object memory-backend-file,id=3Dmemdimm0,prealloc=3Dyes,\ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list