From nobody Mon Feb 9 00:07:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585671913; cv=none; d=zohomail.com; s=zohoarc; b=GoyWi8rD4uH/7WhpsYpCD3FlRdqXYcWy2xBzMFXk0VrYfqUjmUQhTvSIUpcdaiaOy3zRduqdSBZlHBwua7qIXYHQRW/UaG1aW3N2Dp7kJ8yOlUIQIpv11hmRWbnLq73yE9ifjssC/NT91sMoohoo9W3BjxQy595P8DHu31gGKHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671913; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EvQ79naAhy4y/ANHCVoPkkagmTnv6R5RRssJLvzmBnk=; b=WnQsclnzbG0I/py5Uvjbboj9b53ntIemdvCnsNI/mrQwgeE8hbYUnq9xsFjq1OhjpL9O3nogMhZOU/5H4GY6JZcHCdIHION3Kz+HQ5nMTqQZcsEh3T8pVJhjBm+bU4sEnupUqKUhhECX6492C6psGN1wpgb+OqMBHVpPvA6Ed+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1585671913754854.4991864383044; Tue, 31 Mar 2020 09:25:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-oRNU3bY_MdOhu-BT10qexg-1; Tue, 31 Mar 2020 12:24:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 616161137848; Tue, 31 Mar 2020 16:24:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3243A60BEC; Tue, 31 Mar 2020 16:24:52 +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 D9EDC180880D; Tue, 31 Mar 2020 16:24:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02VGOipQ023113 for ; Tue, 31 Mar 2020 12:24:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9FAF95DA60; Tue, 31 Mar 2020 16:24:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D10A5D9C5 for ; Tue, 31 Mar 2020 16:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671912; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EvQ79naAhy4y/ANHCVoPkkagmTnv6R5RRssJLvzmBnk=; b=FiXfANr+2Z4cTSBE1SDUxWsCv+vu835a7CNlSAbtCjefDi+hhVrbx9tJuYpLk5P6G2i823 dV3s4qaPJFCvqtqDK6IoG6RgK+RrgcthtGCGtOueqMtPqY9LB6KKSaWndNpO29hSTvlOVK P6BXNKGWdILcrX3xPsHONWSeG0yNk6I= X-MC-Unique: oRNU3bY_MdOhu-BT10qexg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 09/10] qemu: Make memory path generation embed driver aware Date: Tue, 31 Mar 2020 18:24:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" So far, libvirt generates the following path for memory: $memoryBackingDir/$id-$shortName/ram-nodeN where $memoryBackingDir is the path where QEMU mmaps() memory for the guest (e.g. /var/lib/libvirt/qemu/ram), $id is domain ID and $shortName is shortened version of domain name. So for instance, the generated path may look something like this: /var/lib/libvirt/qemu/ram/1-QEMUGuest/ram-node0 While in case of embed driver the following path would be generated by default: $root/lib/qemu/ram/1-QEMUGuest/ram-node0 which is not clashing with other embed drivers, we allow users to override the default and have all embed drivers use the same prefix. This can create clashing paths. Fortunately, we can reuse the approach for machined name generation (v6.1.0-178-gc9bd08ee35) and include part of hash of the root in the generated path. Note, the important change is in qemuGetMemoryBackingBasePath(). The rest is needed to pass driver around. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_command.c | 15 +++++++-------- src/qemu/qemu_conf.c | 21 ++++++++++++++------- src/qemu/qemu_conf.h | 8 ++++---- src/qemu/qemu_process.c | 5 ++--- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 689796a92b..7ffe59643b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3472,7 +3472,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ - if (qemuGetMemoryBackingPath(def, cfg, mem->info.alias, &memPa= th) < 0) + if (qemuGetMemoryBackingPath(priv->driver, def, mem->info.alia= s, &memPath) < 0) return -1; } =20 @@ -7233,11 +7233,11 @@ qemuBuildSmpCommandLine(virCommandPtr cmd, =20 =20 static int -qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, - const virDomainDef *def, +qemuBuildMemPathStr(const virDomainDef *def, virCommandPtr cmd, qemuDomainObjPrivatePtr priv) { + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); const long system_page_size =3D virGetSystemPageSizeKB(); g_autofree char *mem_path =3D NULL; =20 @@ -7254,7 +7254,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &mem_p= ath) < 0) return -1; } else if (def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { - if (qemuGetMemoryBackingPath(def, cfg, "ram", &mem_path) < 0) + if (qemuGetMemoryBackingPath(priv->driver, def, "ram", &mem_path) = < 0) return -1; } else { return 0; @@ -7273,7 +7273,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, =20 static int qemuBuildMemCommandLine(virCommandPtr cmd, - virQEMUDriverConfigPtr cfg, const virDomainDef *def, virQEMUCapsPtr qemuCaps, qemuDomainObjPrivatePtr priv) @@ -7305,7 +7304,7 @@ qemuBuildMemCommandLine(virCommandPtr cmd, * the hugepages and no numa node is specified. */ if (!virDomainNumaGetNodeCount(def->numa) && - qemuBuildMemPathStr(cfg, def, cmd, priv) < 0) + qemuBuildMemPathStr(def, cmd, priv) < 0) return -1; =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OVERCOMMIT)) { @@ -7386,7 +7385,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, } =20 if (!needBackend && - qemuBuildMemPathStr(cfg, def, cmd, priv) < 0) + qemuBuildMemPathStr(def, cmd, priv) < 0) goto cleanup; =20 for (i =3D 0; i < ncells; i++) { @@ -9879,7 +9878,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0) return NULL; =20 - if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps, priv) < 0) + if (qemuBuildMemCommandLine(cmd, def, qemuCaps, priv) < 0) return NULL; =20 if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 713542f8cd..c59824006c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1965,16 +1965,23 @@ qemuGetDomainHupageMemPath(virQEMUDriverPtr driver, =20 =20 int -qemuGetMemoryBackingDomainPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver, + const virDomainDef *def, char **path) { + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + const char *root =3D driver->embeddedRoot; g_autofree char *shortName =3D NULL; =20 if (!(shortName =3D virDomainDefGetShortName(def))) return -1; =20 - *path =3D g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortName); + if (root && !STRPREFIX(cfg->memoryBackingDir, root)) { + g_autofree char * hash =3D virDomainDriverGenerateRootHash("qemu",= root); + *path =3D g_strdup_printf("%s/%s-%s", cfg->memoryBackingDir, hash,= shortName); + } else { + *path =3D g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortNam= e); + } =20 return 0; } @@ -1982,8 +1989,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *de= f, =20 /** * qemuGetMemoryBackingPath: + * @driver: the qemu driver * @def: domain definition - * @cfg: the driver config * @alias: memory object alias * @memPath: constructed path * @@ -1993,8 +2000,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *de= f, * -1 otherwise (with error reported). */ int -qemuGetMemoryBackingPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +qemuGetMemoryBackingPath(virQEMUDriverPtr driver, + const virDomainDef *def, const char *alias, char **memPath) { @@ -2007,7 +2014,7 @@ qemuGetMemoryBackingPath(const virDomainDef *def, return -1; } =20 - if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0) + if (qemuGetMemoryBackingDomainPath(driver, def, &domainPath) < 0) return -1; =20 *memPath =3D g_strdup_printf("%s/%s", domainPath, alias); diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index b85a9497b7..b9ef4551a3 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -397,10 +397,10 @@ int qemuGetDomainHupageMemPath(virQEMUDriverPtr drive= r, unsigned long long pagesize, char **memPath); =20 -int qemuGetMemoryBackingDomainPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +int qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver, + const virDomainDef *def, char **path); -int qemuGetMemoryBackingPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +int qemuGetMemoryBackingPath(virQEMUDriverPtr driver, + const virDomainDef *def, const char *alias, char **memPath); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f9c400059f..8ea470f75f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3894,7 +3894,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr d= river, =20 if (!build || shouldBuildMB) { g_autofree char *path =3D NULL; - if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0) + if (qemuGetMemoryBackingDomainPath(driver, vm->def, &path) < 0) return -1; =20 if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm, @@ -3911,10 +3911,9 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr= driver, virDomainObjPtr vm, virDomainMemoryDefPtr mem) { - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); g_autofree char *path =3D NULL; =20 - if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0) + if (qemuGetMemoryBackingPath(driver, vm->def, mem->info.alias, &path) = < 0) return -1; =20 if (unlink(path) < 0 && --=20 2.24.1