From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1585671888; cv=none; d=zohomail.com; s=zohoarc; b=Yeg2vJUzbwml2DdXzzHkqeiKaz0uD1U4Lv+cW9+7sHF61tOrvaduiJV+OXCVKIZk3MJ73fhaFfdx/q5MzxzJ5SsnF71Jahxgc1/8Y785GtEgfDhCZ0aSb86qkUKJMd7qLVb2MALvbv3JTfsLVWatOY9sJVL+0J+s6fTYKHZ16vQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671888; 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=cDIz1QpQugRhIfo4sYuOnkIYccYT3DSmueLNw0rmrOw=; b=lBnuKjH2sa10Et2eERvII70eKy8KLTvgKI5cQ7Kv2k6iB0NA+05rPBrLrA9ccqjV8nlKHS+k2f+qq9lCgt3RaH28B5n7AZuTGt/SdMLstwcHosV9vbd/wJtT+FDeecQJt5X8PjyobugGSQDadeeWEfuqUMqzMKmwRM/w0TiJb8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1585671888344675.8973191738567; Tue, 31 Mar 2020 09:24:48 -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-290-AhhxOzs7P1uMaxYo9iNVEQ-1; Tue, 31 Mar 2020 12:24:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15E0D107ACC9; Tue, 31 Mar 2020 16:24:39 +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 C5626D7660; Tue, 31 Mar 2020 16:24:38 +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 5D8511809567; Tue, 31 Mar 2020 16:24:38 +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 02VGOYZd023030 for ; Tue, 31 Mar 2020 12:24:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA93E5D9E2; Tue, 31 Mar 2020 16:24:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67B7F5D9C5 for ; Tue, 31 Mar 2020 16:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671887; 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=cDIz1QpQugRhIfo4sYuOnkIYccYT3DSmueLNw0rmrOw=; b=UZkqG5lyzcrSf1P9Z0NCMKyPBhcPfN7QiqaASUVn/nXStyigwOet45XkF32elnM4rzHpbU WYcbaVRTj/0x1nNozOF7m1oAwB5P5d9tVMffgz4/DdJSLrOQUnHA7l5q+geGKgZ3sKIbvo cf59+ysybxq/e/7fsXltL3mHJfPgiIE= X-MC-Unique: AhhxOzs7P1uMaxYo9iNVEQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 01/10] tests: Fix virQEMUDriverConfigNew() calling with respect to @root Date: Tue, 31 Mar 2020 18:24:13 +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.11 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" The virQEMUDriverConfigNew() accepts path to root directory for embed mode as an argument. If the argument is not NULL it uses the passed value as prefix for some internal paths (e.g. cfg->libDir). If it is NULL though, it looks if the other argument, @privileged is true or false and generates internal paths accordingly. But when calling the function from the test suite, instead of passing NULL for @root, an empty string is passed. Fortunately, this doesn't create a problem because in both problematic cases the generated paths are "fixed" to point somewhere into build dir or the code which is tested doesn't access them. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/domaincapstest.c | 2 +- tests/testutilsqemu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index fb803eaa47..c3a9f4ef91 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -369,7 +369,7 @@ mymain(void) #endif =20 #if WITH_QEMU - virQEMUDriverConfigPtr cfg =3D virQEMUDriverConfigNew(false, ""); + virQEMUDriverConfigPtr cfg =3D virQEMUDriverConfigNew(false, NULL); =20 if (!cfg) return EXIT_FAILURE; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index f3b4e2b3b2..cb68ac0488 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -390,7 +390,7 @@ int qemuTestDriverInit(virQEMUDriver *driver) return -1; =20 driver->hostarch =3D virArchFromHost(); - driver->config =3D virQEMUDriverConfigNew(false, ""); + driver->config =3D virQEMUDriverConfigNew(false, NULL); if (!driver->config) goto error; =20 --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 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=1585671897; cv=none; d=zohomail.com; s=zohoarc; b=CzoXlFN9ApoyZBeLRcAAu+ElThGi5SbL288mBnghTGfnxwDKFhQjGz1yRGJGeBWyUVM+2ZH+kJy80s6wCxNv5ro+ML/0C7OFKMdI8B83tz3PwXEx6Ie5KWiVrj36fCJQPqbHWBWnvSiq9NioKvQDnHbP0p9roG3dZy86QdRT/jA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671897; 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=JemBQcetzOvfmeW8jtmuj32SdcvWNb7pr9ycknNIKTU=; b=e0NyVKLDmxv7qnPOz6R5/j7ozv1nYtYT426nD+cmSR8efzyjX/vggaYR0OLfxab69SUU/RJOxARbhlwCNd5l6RsjHGFYuShQcVgq/z1QYGEAQYNyZeHFEBzG77YFGAV10AxDln3uuc5tQsQi1Y6sqnmTmpVAz9Tcr5F01PYa0DQ= 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 158567189788292.49842839230257; Tue, 31 Mar 2020 09:24:57 -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-352-8mxLnizfMICQhcSvQpCQ3Q-1; Tue, 31 Mar 2020 12:24:53 -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 87A48801E77; Tue, 31 Mar 2020 16:24:48 +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 5DFAB60C05; Tue, 31 Mar 2020 16:24:48 +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 1996818089CF; Tue, 31 Mar 2020 16:24:48 +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 02VGOaIC023039 for ; Tue, 31 Mar 2020 12:24:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0455A5D9E2; Tue, 31 Mar 2020 16:24:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C3A65D9C5 for ; Tue, 31 Mar 2020 16:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671896; 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=JemBQcetzOvfmeW8jtmuj32SdcvWNb7pr9ycknNIKTU=; b=VJPaKhLa5gcAxWaA4McEc43tV43xc8h+IiF5+v58v8fEcJB36NUJdkXUK/zJovXOM64rfz tnZqwVqSqy6S50tAftX0RtZKSP5rEo0eLv1QpRoaVKit2R7WUDzatz8kXViPDDdbFOgKfO ihjGnLjEjVRgQI7DdZButuJzwxdl71s= X-MC-Unique: 8mxLnizfMICQhcSvQpCQ3Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 02/10] qemu: Drop virQEMUDriverIsPrivileged() Date: Tue, 31 Mar 2020 18:24:14 +0200 Message-Id: <83bf2292fa463596c6efa089611efa7c7c8de160.1585671623.git.mprivozn@redhat.com> 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" Introduced in v1.2.17-rc1~121, the assumption was that the driver->privileged is immutable at the time but it might change in the future. Well, it did not ever since. It is still immutable variable. Drop the needless accessor then. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani --- src/qemu/qemu_cgroup.c | 4 ++-- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_conf.c | 6 ------ src/qemu/qemu_conf.h | 1 - src/qemu/qemu_domain.c | 12 ++++++------ src/qemu/qemu_driver.c | 22 +++++++++++----------- src/qemu/qemu_interface.c | 6 +++--- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index c0e30f6152..f1564141b6 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -926,7 +926,7 @@ qemuInitCgroup(virDomainObjPtr vm, qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(priv->driver); =20 - if (!virQEMUDriverIsPrivileged(priv->driver)) + if (!priv->driver->privileged) goto done; =20 if (!virCgroupAvailable()) @@ -1061,7 +1061,7 @@ qemuConnectCgroup(virDomainObjPtr vm) virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(priv->driver); int ret =3D -1; =20 - if (!virQEMUDriverIsPrivileged(priv->driver)) + if (!priv->driver->privileged) goto done; =20 if (!virCgroupAvailable()) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d1b689dfd3..9a0a96bdea 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8102,7 +8102,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, /* network and bridge use a tap device, and direct uses a * macvtap device */ - if (virQEMUDriverIsPrivileged(driver) && nicindexes && nnicindexes= && + if (driver->privileged && nicindexes && nnicindexes && net->ifname) { if (virNetDevGetIndex(net->ifname, &nicindex) < 0 || VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex) < = 0) @@ -9642,7 +9642,7 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, int spice =3D 0; int egl_headless =3D 0; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { /* If we have no cgroups then we can have no tunings that * require them */ =20 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 15837cece4..5ac316ec77 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1224,12 +1224,6 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEM= UDriverPtr driver) return conf; } =20 -bool -virQEMUDriverIsPrivileged(virQEMUDriverPtr driver) -{ - return driver->privileged; -} - virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver, const char *defsecmodel) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 14f9b9e81e..10bc7e4a52 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -333,7 +333,6 @@ int virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg); =20 virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver); -bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver); =20 virCapsHostNUMAPtr virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver); virCPUDefPtr virQEMUDriverGetHostCPU(virQEMUDriverPtr driver); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index dd48b6fff3..e54eeae58f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8600,7 +8600,7 @@ qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs, return -1; =20 case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS: - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("virtiofs is not yet supported in session mod= e")); return -1; @@ -10718,7 +10718,7 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr drive= r, qemuDomainObjPrivatePtr priv =3D obj->privateData; bool custom_hypervisor_feat =3D false; =20 - if (virQEMUDriverIsPrivileged(driver) && + if (driver->privileged && (cfg->user =3D=3D 0 || cfg->group =3D=3D 0)) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, = logCtxt); @@ -10817,7 +10817,7 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(vir= QEMUDriverPtr driver, ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name= ); =20 if (cfg->stdioLogD) { - ctxt->manager =3D virLogManagerNew(virQEMUDriverIsPrivileged(drive= r)); + ctxt->manager =3D virLogManagerNew(driver->privileged); if (!ctxt->manager) goto error; =20 @@ -10847,7 +10847,7 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(vir= QEMUDriverPtr driver, * we can't rely on logrotate. We don't use O_TRUNC since * it is better for SELinux policy if we truncate afterwards */ if (mode =3D=3D QEMU_DOMAIN_LOG_CONTEXT_MODE_START && - !virQEMUDriverIsPrivileged(driver) && + !driver->privileged && ftruncate(ctxt->writefd, 0) < 0) { virReportSystemError(errno, _("failed to truncate %s"), ctxt->path); @@ -10991,7 +10991,7 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver, path =3D g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name); =20 if (cfg->stdioLogD) { - if (!(manager =3D virLogManagerNew(virQEMUDriverIsPrivileged(drive= r)))) + if (!(manager =3D virLogManagerNew(driver->privileged))) goto cleanup; =20 if (virLogManagerDomainAppendMessage(manager, "qemu", vm->def->uui= d, @@ -16546,7 +16546,7 @@ qemuDomainGetMachineName(virDomainObjPtr vm) if (!ret) ret =3D virDomainGenerateMachineName("qemu", cfg->root, vm->def->id, vm->def->name, - virQEMUDriverIsPrivileged(drive= r)); + driver->privileged); =20 return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 78024614cf..49dcd0e82d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -307,7 +307,7 @@ qemuSecurityInit(virQEMUDriverPtr driver) flags |=3D VIR_SECURITY_MANAGER_DEFAULT_CONFINED; if (cfg->securityRequireConfined) flags |=3D VIR_SECURITY_MANAGER_REQUIRE_CONFINED; - if (virQEMUDriverIsPrivileged(driver)) + if (driver->privileged) flags |=3D VIR_SECURITY_MANAGER_PRIVILEGED; =20 if (cfg->securityDriverNames && @@ -338,7 +338,7 @@ qemuSecurityInit(virQEMUDriverPtr driver) mgr =3D NULL; } =20 - if (virQEMUDriverIsPrivileged(driver)) { + if (driver->privileged) { if (cfg->dynamicOwnership) flags |=3D VIR_SECURITY_MANAGER_DYNAMIC_OWNERSHIP; if (virBitmapIsBitSet(cfg->namespaces, QEMU_DOMAIN_NS_MOUNT)) @@ -1204,7 +1204,7 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr= conn, } else { if (!virConnectValidateURIPath(conn->uri->path, "qemu", - virQEMUDriverIsPrivileged(qemu_driv= er))) + qemu_driver->privileged)) return VIR_DRV_OPEN_ERROR; } =20 @@ -9279,7 +9279,7 @@ static char *qemuDomainGetSchedulerType(virDomainPtr = dom, if (virDomainGetSchedulerTypeEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("CPU tuning is not available in session mode")); goto cleanup; @@ -9355,7 +9355,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (virDomainSetBlkioParametersEnsureACL(dom->conn, vm->def, flags) < = 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Block I/O tuning is not available in session mod= e")); goto cleanup; @@ -9435,7 +9435,7 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, if (virDomainGetBlkioParametersEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Block I/O tuning is not available in session mod= e")); goto cleanup; @@ -9531,7 +9531,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, if (virDomainSetMemoryParametersEnsureACL(dom->conn, vm->def, flags) <= 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("Memory tuning is not available in session mode")= ); goto cleanup; @@ -9607,7 +9607,7 @@ qemuDomainGetMemoryParameters(virDomainPtr dom, if (virDomainGetMemoryParametersEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("Memory tuning is not available in session mode")= ); goto cleanup; @@ -9794,7 +9794,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, goto endjob; =20 if (def) { - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("NUMA tuning is not available in session mode= ")); goto endjob; @@ -10268,7 +10268,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr = dom, if (virDomainSetSchedulerParametersFlagsEnsureACL(dom->conn, vm->def, = flags) < 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("CPU tuning is not available in session mode")); goto cleanup; @@ -10675,7 +10675,7 @@ qemuDomainGetSchedulerParametersFlags(virDomainPtr = dom, if (virDomainGetSchedulerParametersFlagsEnsureACL(dom->conn, vm->def) = < 0) goto cleanup; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("CPU tuning is not available in session mode")); goto cleanup; diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 2b24c73d65..ffec992596 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -410,7 +410,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, =20 if (net->backend.tap) { tunpath =3D net->backend.tap; - if (!virQEMUDriverIsPrivileged(driver)) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("cannot use custom tap device in session mode= ")); goto cleanup; @@ -538,7 +538,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, =20 if (net->backend.tap) { tunpath =3D net->backend.tap; - if (!(virQEMUDriverIsPrivileged(driver))) { + if (!driver->privileged) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("cannot use custom tap device in session mode= ")); goto cleanup; @@ -562,7 +562,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, if (virDomainNetIsVirtioModel(net)) tap_create_flags |=3D VIR_NETDEV_TAP_CREATE_VNET_HDR; =20 - if (virQEMUDriverIsPrivileged(driver)) { + if (driver->privileged) { if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac, def->uuid, tunpath, tapfd, *tap= fdSize, virDomainNetGetActualVirtPortPr= ofile(net), --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1585671903; cv=none; d=zohomail.com; s=zohoarc; b=Kxpq7JZfOvMaXduprRU9KxthPyGZ4Stf6uiJEvILh+OPpiusLX5pU6BxFlQLVhKlIe9vOKIlbZKj9UHtzXOYIZ2GBNaTDkV52q9562G+mo2ZkPiSX1hWmDzSb/DApeVgFMN6OovKOhfC5RpRg/Pm6RiVjyRz/QS5qc7hWYxyp1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671903; 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=dm91GskQVoVAGpfbrJhbheHzUrTAJKuxC6k8pGAsMGw=; b=NVITleOEm0tdDZTFms+F/0GOemX6n33a6MSsn3/PIJdeZJ92W/6rsRrnBkXbW3wJdjZSCP5++sUQv714pa6mdxLqWz3kRy7RkiJ9CNUxYkj7A7R5XEkiNpykU3JXeaxVo9f5NEtdbandJRl39mxeFeMFn2b9gs721BQ0Tj5Li80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1585671903149341.75263276397754; Tue, 31 Mar 2020 09:25:03 -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-245-Qu5ErwRnM-e-yfnNTflR3Q-1; Tue, 31 Mar 2020 12:24:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23DED8018A1; Tue, 31 Mar 2020 16:24:52 +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 EDA8718A85; Tue, 31 Mar 2020 16:24:51 +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 A1CEF86C13; 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 02VGOatw023052 for ; Tue, 31 Mar 2020 12:24:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id DEC565D9E2; Tue, 31 Mar 2020 16:24:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A1285D9C5 for ; Tue, 31 Mar 2020 16:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671901; 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=dm91GskQVoVAGpfbrJhbheHzUrTAJKuxC6k8pGAsMGw=; b=E41IvXJCzTG0GImZhFkQ4u/fi26Y/+REqYozX1WZn0k9C2qPNMVRAAGZehrXwrVajKooyA ylaBgNTKRWoaajpKAfxXealJ+E2DNltzUs4h8j9jWFcjDHTTs4SYKonL8pfkj0A868hjww v0oqYIjth8XNgT4U4sEaqqqZabbVih8= X-MC-Unique: Qu5ErwRnM-e-yfnNTflR3Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 03/10] qemu: Drop two layers of nesting of memoryBackingDir Date: Tue, 31 Mar 2020 18:24:15 +0200 Message-Id: <656420b9f18a5782129f703115e36cd66b287826.1585671623.git.mprivozn@redhat.com> 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.11 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" Initially introduced in v3.10.0-rc1~172. When generating a path for memory-backend-file or -mem-path, qemu driver will use the following pattern: $memoryBackingDir/libvirt/qemu/$id-$shortName where $memoryBackingDir defaults to /var/lib/libvirt/qemu/ram but can be overridden in qemu.conf. Anyway, the "/libvirt/qemu/" part looks redundant, because it's already contained in the default, or creates unnecessary nesting if overridden in qemu.conf. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani --- src/qemu/qemu_conf.c | 25 ++++++++++--------- src/qemu/qemu_conf.h | 2 -- src/qemu/qemu_driver.c | 12 +-------- .../qemuxml2argvdata/cpu-numa-memshared.args | 8 +++--- .../fd-memory-no-numa-topology.args | 2 +- .../fd-memory-numa-topology.args | 4 +-- .../fd-memory-numa-topology2.args | 8 +++--- .../fd-memory-numa-topology3.args | 12 ++++----- .../hugepages-memaccess2.args | 12 ++++----- .../qemuxml2argvdata/pages-dimm-discard.args | 4 +-- ...vhost-user-fs-fd-memory.x86_64-latest.args | 2 +- 11 files changed, 40 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 5ac316ec77..5339c5fc04 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -970,7 +970,18 @@ static int virQEMUDriverConfigLoadMemoryEntry(virQEMUDriverConfigPtr cfg, virConfPtr conf) { - return virConfGetValueString(conf, "memory_backing_dir", &cfg->memoryB= ackingDir); + char *dir =3D NULL; + int rc; + + if ((rc =3D virConfGetValueString(conf, "memory_backing_dir", &dir)) <= 0) { + return -1; + } else if (rc > 0) { + VIR_FREE(cfg->memoryBackingDir); + cfg->memoryBackingDir =3D g_strdup_printf("%s/libvirt/qemu", dir); + return 1; + } + + return 0; } =20 =20 @@ -1945,27 +1956,17 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, } =20 =20 -void -qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, - char **path) -{ - *path =3D g_strdup_printf("%s/libvirt/qemu", cfg->memoryBackingDir); -} - - int qemuGetMemoryBackingDomainPath(const virDomainDef *def, virQEMUDriverConfigPtr cfg, char **path) { g_autofree char *shortName =3D NULL; - g_autofree char *base =3D NULL; =20 if (!(shortName =3D virDomainDefGetShortName(def))) return -1; =20 - qemuGetMemoryBackingBasePath(cfg, &base); - *path =3D g_strdup_printf("%s/%s", base, shortName); + *path =3D g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortName); =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 10bc7e4a52..89332eeb73 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -397,8 +397,6 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def, unsigned long long pagesize, char **memPath); =20 -void qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, - char **path); int qemuGetMemoryBackingDomainPath(const virDomainDef *def, virQEMUDriverConfigPtr cfg, char **path); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 49dcd0e82d..716b82f8f2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -640,7 +640,6 @@ qemuStateInitialize(bool privileged, virQEMUDriverConfigPtr cfg; uid_t run_uid =3D -1; gid_t run_gid =3D -1; - g_autofree char *memoryBackingPath =3D NULL; bool autostart =3D true; size_t i; const char *defsecmodel =3D NULL; @@ -935,17 +934,8 @@ qemuStateInitialize(bool privileged, goto error; } =20 - qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath); - - if (virFileMakePath(memoryBackingPath) < 0) { - virReportSystemError(errno, - _("unable to create memory backing path %s"), - memoryBackingPath); - goto error; - } - if (privileged && - virFileUpdatePerm(memoryBackingPath, + virFileUpdatePerm(cfg->memoryBackingDir, 0, S_IXGRP | S_IXOTH) < 0) goto error; =20 diff --git a/tests/qemuxml2argvdata/cpu-numa-memshared.args b/tests/qemuxml= 2argvdata/cpu-numa-memshared.args index 752eed8d13..8e214189db 100644 --- a/tests/qemuxml2argvdata/cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/cpu-numa-memshared.args @@ -15,12 +15,12 @@ QEMU_AUDIO_DRV=3Dnone \ -realtime mlock=3Doff \ -smp 16,sockets=3D2,cores=3D4,threads=3D2 \ -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 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node1,\ -share=3Dno,size=3D112197632 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node1,share=3Dno,\ +size=3D112197632 \ -numa node,nodeid=3D1,cpus=3D8-15,memdev=3Dram-node1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -display none \ diff --git a/tests/qemuxml2argvdata/fd-memory-no-numa-topology.args b/tests= /qemuxml2argvdata/fd-memory-no-numa-topology.args index d23c575553..dec35cc10a 100644 --- a/tests/qemuxml2argvdata/fd-memory-no-numa-topology.args +++ b/tests/qemuxml2argvdata/fd-memory-no-numa-topology.args @@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=3Dnone \ -machine pc-i440fx-2.3,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ -m 14336 \ -mem-prealloc \ --mem-path /var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram \ +-mem-path /var/lib/libvirt/qemu/ram/-1-instance-00000092/ram \ -realtime mlock=3Doff \ -smp 8,sockets=3D8,cores=3D1,threads=3D1 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology.args b/tests/qe= muxml2argvdata/fd-memory-numa-topology.args index 4fbbc8185b..2d3e90ff7a 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology.args +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology.args @@ -16,8 +16,8 @@ QEMU_AUDIO_DRV=3Dnone \ -realtime mlock=3Doff \ -smp 8,sockets=3D1,cores=3D8,threads=3D1 \ -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 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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 \ -display none \ diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology2.args b/tests/q= emuxml2argvdata/fd-memory-numa-topology2.args index 1eeeaec0ce..6b1695feb1 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology2.args +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology2.args @@ -16,12 +16,12 @@ QEMU_AUDIO_DRV=3Dnone \ -realtime mlock=3Doff \ -smp 20,sockets=3D1,cores=3D8,threads=3D1 \ -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 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node1,\ -share=3Dyes,size=3D15032385536 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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 \ -display none \ diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology3.args b/tests/q= emuxml2argvdata/fd-memory-numa-topology3.args index d75b67916c..205d14a7db 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology3.args +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology3.args @@ -16,16 +16,16 @@ QEMU_AUDIO_DRV=3Dnone \ -realtime mlock=3Doff \ -smp 32,sockets=3D1,cores=3D24,threads=3D1 \ -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 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node1,\ -share=3Dyes,size=3D15032385536 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-instance-00000092/ram= -node2,\ -share=3Dno,size=3D15032385536 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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 \ -display none \ diff --git a/tests/qemuxml2argvdata/hugepages-memaccess2.args b/tests/qemux= ml2argvdata/hugepages-memaccess2.args index 654baebf9f..c1560e63c3 100644 --- a/tests/qemuxml2argvdata/hugepages-memaccess2.args +++ b/tests/qemuxml2argvdata/hugepages-memaccess2.args @@ -15,20 +15,20 @@ QEMU_AUDIO_DRV=3Dnone \ -realtime mlock=3Doff \ -smp 4,sockets=3D4,cores=3D1,threads=3D1 \ -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 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node2,\ -share=3Dno,size=3D1073741824,host-nodes=3D0-3,policy=3Dbind \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node3,\ -share=3Dno,size=3D1073741824,host-nodes=3D3,policy=3Dbind \ +mem-path=3D/var/lib/libvirt/qemu/ram/-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,\ mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=3Dyes,size=3D= 536870912,\ diff --git a/tests/qemuxml2argvdata/pages-dimm-discard.args b/tests/qemuxml= 2argvdata/pages-dimm-discard.args index fefa205597..96e9ffdec3 100644 --- a/tests/qemuxml2argvdata/pages-dimm-discard.args +++ b/tests/qemuxml2argvdata/pages-dimm-discard.args @@ -20,8 +20,8 @@ mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-fedora,size= =3D1073741824,\ host-nodes=3D1-3,policy=3Dbind \ -device pc-dimm,node=3D0,memdev=3Dmemdimm0,id=3Ddimm0,slot=3D0 \ -object memory-backend-file,id=3Dmemdimm1,\ -mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-fedora/dimm1,\ -discard-data=3Dyes,share=3Dno,size=3D536870912 \ +mem-path=3D/var/lib/libvirt/qemu/ram/-1-fedora/dimm1,discard-data=3Dyes,sh= are=3Dno,\ +size=3D536870912 \ -device pc-dimm,node=3D0,memdev=3Dmemdimm1,id=3Ddimm1,slot=3D1 \ -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ -display none \ diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.x86_64-latest.a= rgs b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.x86_64-latest.args index a7df45a7f0..dd5f68abc5 100644 --- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.x86_64-latest.args +++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.x86_64-latest.args @@ -18,7 +18,7 @@ file=3D/tmp/lib/domain--1-guest/master-key.aes \ -overcommit mem-lock=3Doff \ -smp 2,sockets=3D2,cores=3D1,threads=3D1 \ -object memory-backend-file,id=3Dram-node0,\ -mem-path=3D/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-guest/ram-node0,share= =3Dyes,\ +mem-path=3D/var/lib/libvirt/qemu/ram/-1-guest/ram-node0,share=3Dyes,\ size=3D15032385536 \ -numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1585671908; cv=none; d=zohomail.com; s=zohoarc; b=U2fb40DOM3mz+kQUxoiJdSgDvjjKZyFTyzEkSnLI2l9ZCYqYbHiTLjloAUFxzvGeYe+Hc3la8y1HKAyYcXZGan5Vxytj4NEILbZT2ele45ddT874yXNxYEbME67Tzyv8MwPzlGEFuNsAvhx/157TgPb3ztEzr7Wwd65Y7yy13dQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671908; 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=5/E2+lEjzuGWX0g4fLiifEVMYGnWHMU0PGDe1DIZrdY=; b=gQEn2FLLg3MyigKy9DDkfWKTIRH1AUw0TviMj4hPiMrmCYfMzO4g0NKT431YN5kOhwe3YzNce+Mnk6nT2yOrX/O8hfllHJ24L95Av0XSSxVcX0fTMzs06m4Yh79B8Kx5BNCBJ8gTrNfs7k1TKv5Wq2F0N/rlpVwh0kQITyZOaWk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1585671908949872.4994777191605; Tue, 31 Mar 2020 09:25:08 -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-105-a9egWSNtM-yrJFNGy9bv6w-1; Tue, 31 Mar 2020 12:25:05 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 477CF106BBDE; Tue, 31 Mar 2020 16:24:58 +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 1D34510002B5; Tue, 31 Mar 2020 16:24:58 +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 BE4AF1803C41; Tue, 31 Mar 2020 16:24:57 +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 02VGOeZe023066 for ; Tue, 31 Mar 2020 12:24:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38F6F5D9E2; Tue, 31 Mar 2020 16:24:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9E0C5D9C5 for ; Tue, 31 Mar 2020 16:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671907; 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=5/E2+lEjzuGWX0g4fLiifEVMYGnWHMU0PGDe1DIZrdY=; b=BdKWuIaGFrcYkXi3coznBuPlRwwCL/0Lv89yEdGOMN4B7QtvJM/Dp01vRnXUbg2QWvAgGx nB3Kmrfxq7zgPeSNzhGlRjJ/IPzkvDUxcOXNIkFTP6L8QlgVef7ZFzi2sCc8YzSDWtMSFi iDUKwvcBfKuRB68wZ3VIXnf+W4/Txt4= X-MC-Unique: a9egWSNtM-yrJFNGy9bv6w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 04/10] conf: Move virDomainGenerateMachineName to hypervisor/ Date: Tue, 31 Mar 2020 18:24:16 +0200 Message-Id: <26958b0c7e09be68f55c00156bbb4d3549f0aedb.1585671623.git.mprivozn@redhat.com> 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.84 on 10.5.11.22 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" The virDomainGenerateMachineName() function doesn't belong in src/conf/ really, because it has nothing to do with domain XML parsing. It landed there because of lack of better place in the past. But now that we have src/hypervisor/ the function should live there. At the same time, the function name is changed to match new location. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 72 --------------------------------- src/conf/domain_conf.h | 7 ---- src/hypervisor/domain_driver.c | 74 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 7 ++++ src/libvirt_private.syms | 2 +- src/lxc/lxc_domain.c | 3 +- src/qemu/qemu_domain.c | 7 ++-- tests/virsystemdtest.c | 5 ++- 8 files changed, 91 insertions(+), 86 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 914e03c705..efb9a61243 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -62,7 +62,6 @@ #include "virdomainsnapshotobjlist.h" #include "virdomaincheckpointobjlist.h" #include "virutil.h" -#include "vircrypto.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -31037,77 +31036,6 @@ virDomainDiskSetBlockIOTune(virDomainDiskDefPtr di= sk, return 0; } =20 -#define HOSTNAME_CHARS \ - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" - -static void -virDomainMachineNameAppendValid(virBufferPtr buf, - const char *name) -{ - bool skip =3D true; - - for (; *name; name++) { - if (strlen(virBufferCurrentContent(buf)) >=3D 64) - break; - - if (*name =3D=3D '.' || *name =3D=3D '-') { - if (!skip) - virBufferAddChar(buf, *name); - skip =3D true; - continue; - } - - skip =3D false; - - if (!strchr(HOSTNAME_CHARS, *name)) - continue; - - virBufferAddChar(buf, *name); - } - - /* trailing dashes or dots are not allowed */ - virBufferTrimChars(buf, "-."); -} - -#undef HOSTNAME_CHARS - -char * -virDomainGenerateMachineName(const char *drivername, - const char *root, - int id, - const char *name, - bool privileged) -{ - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, "%s-", drivername); - - if (root) { - g_autofree char *hash =3D NULL; - - /* When two embed drivers start two domains with the same @name an= d @id - * we would generate a non-unique name. Include parts of hashed @r= oot - * which guarantees uniqueness. The first 8 characters of SHA256 o= ught - * to be enough for anybody. */ - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) - return NULL; - - virBufferAsprintf(&buf, "embed-%.8s-", hash); - } else if (!privileged) { - g_autofree char *username =3D NULL; - if (!(username =3D virGetUserName(geteuid()))) { - virBufferFreeAndReset(&buf); - return NULL; - } - virBufferAsprintf(&buf, "%s-", username); - } - - virBufferAsprintf(&buf, "%d-", id); - virDomainMachineNameAppendValid(&buf, name); - - return virBufferContentAndReset(&buf); -} - =20 /** * virDomainNetTypeSharesHostView: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 33875d942f..575290a6ac 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3649,13 +3649,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDe= fPtr def, int virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk, virDomainBlockIoTuneInfo *info); =20 -char * -virDomainGenerateMachineName(const char *drivername, - const char *root, - int id, - const char *name, - bool privileged); - bool virDomainNetTypeSharesHostView(const virDomainNetDef *net); =20 diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index fc5b6eeefe..7bf0fb3f98 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -23,10 +23,84 @@ #include "domain_driver.h" #include "viralloc.h" #include "virstring.h" +#include "vircrypto.h" +#include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 =20 +#define HOSTNAME_CHARS \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" + +static void +virDomainMachineNameAppendValid(virBufferPtr buf, + const char *name) +{ + bool skip =3D true; + + for (; *name; name++) { + if (strlen(virBufferCurrentContent(buf)) >=3D 64) + break; + + if (*name =3D=3D '.' || *name =3D=3D '-') { + if (!skip) + virBufferAddChar(buf, *name); + skip =3D true; + continue; + } + + skip =3D false; + + if (!strchr(HOSTNAME_CHARS, *name)) + continue; + + virBufferAddChar(buf, *name); + } + + /* trailing dashes or dots are not allowed */ + virBufferTrimChars(buf, "-."); +} + +#undef HOSTNAME_CHARS + +char * +virDomainDriverGenerateMachineName(const char *drivername, + const char *root, + int id, + const char *name, + bool privileged) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s-", drivername); + + if (root) { + g_autofree char *hash =3D NULL; + + /* When two embed drivers start two domains with the same @name an= d @id + * we would generate a non-unique name. Include parts of hashed @r= oot + * which guarantees uniqueness. The first 8 characters of SHA256 o= ught + * to be enough for anybody. */ + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) + return NULL; + + virBufferAsprintf(&buf, "embed-%.8s-", hash); + } else if (!privileged) { + g_autofree char *username =3D NULL; + if (!(username =3D virGetUserName(geteuid()))) { + virBufferFreeAndReset(&buf); + return NULL; + } + virBufferAsprintf(&buf, "%s-", username); + } + + virBufferAsprintf(&buf, "%d-", id); + virDomainMachineNameAppendValid(&buf, name); + + return virBufferContentAndReset(&buf); +} + + /* Modify dest_array to reflect all blkio device changes described in * src_array. */ int diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index b6d5e66bba..c52e37f038 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -22,6 +22,13 @@ =20 #include "domain_conf.h" =20 +char * +virDomainDriverGenerateMachineName(const char *drivername, + const char *root, + int id, + const char *name, + bool privileged); + int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array, size_t *dest_size, virBlkioDevicePtr src_array, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e276f55bb1..b02b6380ed 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -406,7 +406,6 @@ virDomainFSTypeFromString; virDomainFSTypeToString; virDomainFSWrpolicyTypeFromString; virDomainFSWrpolicyTypeToString; -virDomainGenerateMachineName; virDomainGetBlkioParametersAssignFromDef; virDomainGetFilesystemForTarget; virDomainGraphicsAuthConnectedTypeFromString; @@ -1403,6 +1402,7 @@ virDomainCgroupSetupMemtune; =20 =20 # hypervisor/domain_driver.h +virDomainDriverGenerateMachineName; virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index ebd2c2b56e..59f803837a 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -31,6 +31,7 @@ #include "virtime.h" #include "virsystemd.h" #include "virinitctl.h" +#include "domain_driver.h" =20 #define VIR_FROM_THIS VIR_FROM_LXC =20 @@ -406,7 +407,7 @@ virLXCDomainGetMachineName(virDomainDefPtr def, pid_t p= id) } =20 if (!ret) - ret =3D virDomainGenerateMachineName("lxc", NULL, def->id, def->na= me, true); + ret =3D virDomainDriverGenerateMachineName("lxc", NULL, def->id, d= ef->name, true); =20 return ret; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e54eeae58f..25ee46fe34 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -44,6 +44,7 @@ #include "virfile.h" #include "domain_addr.h" #include "domain_capabilities.h" +#include "domain_driver.h" #include "domain_event.h" #include "virtime.h" #include "virnetdevopenvswitch.h" @@ -16544,9 +16545,9 @@ qemuDomainGetMachineName(virDomainObjPtr vm) } =20 if (!ret) - ret =3D virDomainGenerateMachineName("qemu", cfg->root, - vm->def->id, vm->def->name, - driver->privileged); + ret =3D virDomainDriverGenerateMachineName("qemu", cfg->root, + vm->def->id, vm->def->nam= e, + driver->privileged); =20 return ret; } diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 050941dce8..e7dcdea8e9 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -34,6 +34,7 @@ # include "virlog.h" # include "virmock.h" # include "rpc/virnetsocket.h" +# include "domain_driver.h" # define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("tests.systemdtest"); @@ -414,8 +415,8 @@ testMachineName(const void *opaque) int ret =3D -1; char *actual =3D NULL; =20 - if (!(actual =3D virDomainGenerateMachineName("qemu", data->root, - data->id, data->name, true= ))) + if (!(actual =3D virDomainDriverGenerateMachineName("qemu", data->root, + data->id, data->name= , true))) goto cleanup; =20 if (STRNEQ(actual, data->expected)) { --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1585671892; cv=none; d=zohomail.com; s=zohoarc; b=hxUwZFpbqMUGDvHdWNHGceklsTJENueYJIr+kWXiHF6cVFx09Tuo42gVGVgfFuW9LFdVQKCZMEfhGlXBwTrJ/aqXctyy8EFYuMscAEg/L1bjS9c6CC2oEhz2RIPB/UrccBoCUk9/NXywGFWs76WANAujqn+USq10+xL9nOipIOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671892; 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=gWqQbr9/Tn709OXZklT27PsuXavr75JQ1k+NcqHPDKk=; b=KSUV13TT7fnwIi5wP7fNZX+7TYUd8mIs033wzhe+RyCCVTlJpHCrPnkZY5ANQ0QdFCg0sm7KafScUJAXbFu5Js245Yu7bE2u5iCTs4dsOQ94IebPG4MHsdf+NT4tpXyRrM5L/FeUqknQEzIR0+S6SogFcGNaLYEXvVhkCO93zCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1585671892940142.1263442853301; Tue, 31 Mar 2020 09:24:52 -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-28-AXYGxw6oN4uan51-Q4pmTw-1; Tue, 31 Mar 2020 12:24:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE01C477; Tue, 31 Mar 2020 16:24:43 +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 8DDEE19C58; Tue, 31 Mar 2020 16:24:43 +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 29A8018089C8; Tue, 31 Mar 2020 16:24:43 +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 02VGOfva023077 for ; Tue, 31 Mar 2020 12:24:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D37F5D9E2; Tue, 31 Mar 2020 16:24:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DBF85D9C5 for ; Tue, 31 Mar 2020 16:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671891; 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=gWqQbr9/Tn709OXZklT27PsuXavr75JQ1k+NcqHPDKk=; b=YJWQrZNdzVNDxR6dyZlboT1snxr9RFrX0YcgHDks8ELGrljmpE4Fz5Sl27ysdG7SWAZduq zASZn9pMyJkxVr/ZFz2jzpOyGzLcUFWWpH7JWhxyddaUHFHkjSRWy/wY8gq0srV6N81z+s XNHcB+H+jQRCPvUE0a2ncJv6TqPagt0= X-MC-Unique: AXYGxw6oN4uan51-Q4pmTw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 05/10] virDomainDriverGenerateMachineName: Factor out embed path hashing Date: Tue, 31 Mar 2020 18:24:17 +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.84 on 10.5.11.23 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" The code that generates "qemu-embed-$hash" is going to be useful in more places. Separate it out into a function. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 42 ++++++++++++++++++++++------------ src/hypervisor/domain_driver.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 7bf0fb3f98..31821fc712 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -28,6 +28,22 @@ =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 +char * +virDomainDriverGenerateRootHash(const char *drivername, + const char *root) +{ + g_autofree char *hash =3D NULL; + + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) + return NULL; + + /* When two embed drivers start two domains with the same @name and @id + * we would generate a non-unique name. Include parts of hashed @root + * which guarantees uniqueness. The first 8 characters of SHA256 ought + * to be enough for anybody. */ + return g_strdup_printf("%s-embed-%.8s", drivername, hash); +} + =20 #define HOSTNAME_CHARS \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" @@ -72,26 +88,24 @@ virDomainDriverGenerateMachineName(const char *driverna= me, { virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 - virBufferAsprintf(&buf, "%s-", drivername); - if (root) { g_autofree char *hash =3D NULL; =20 - /* When two embed drivers start two domains with the same @name an= d @id - * we would generate a non-unique name. Include parts of hashed @r= oot - * which guarantees uniqueness. The first 8 characters of SHA256 o= ught - * to be enough for anybody. */ - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) + if (!(hash =3D virDomainDriverGenerateRootHash(drivername, root))) return NULL; =20 - virBufferAsprintf(&buf, "embed-%.8s-", hash); - } else if (!privileged) { - g_autofree char *username =3D NULL; - if (!(username =3D virGetUserName(geteuid()))) { - virBufferFreeAndReset(&buf); - return NULL; + virBufferAsprintf(&buf, "%s-", hash); + } else { + virBufferAsprintf(&buf, "%s-", drivername); + if (!privileged) { + + g_autofree char *username =3D NULL; + if (!(username =3D virGetUserName(geteuid()))) { + virBufferFreeAndReset(&buf); + return NULL; + } + virBufferAsprintf(&buf, "%s-", username); } - virBufferAsprintf(&buf, "%s-", username); } =20 virBufferAsprintf(&buf, "%d-", id); diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index c52e37f038..b66ae2d421 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -22,6 +22,10 @@ =20 #include "domain_conf.h" =20 +char * +virDomainDriverGenerateRootHash(const char *drivername, + const char *root); + char * virDomainDriverGenerateMachineName(const char *drivername, const char *root, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b02b6380ed..ec367653d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1403,6 +1403,7 @@ virDomainCgroupSetupMemtune; =20 # hypervisor/domain_driver.h virDomainDriverGenerateMachineName; +virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1585671898; cv=none; d=zohomail.com; s=zohoarc; b=TAG4rbfdVjt5GEmfpgyftttUOuijv3BRldi1ippqFL1K6dw3eq0SwnallHQMqndFP0kg62a6B9lf7H0nVVCc780YFBEOFbJeIoMJK3/oExhq/Cgc4lBAC9Iat2kp+iKNK3gpKdO3PCwB2YoDsofoLh7aMmqA9AjcRzrO16xRT98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671898; 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=BtPK53em8vIC8NI/lxTrEuV8ej1wUT38BfLE7basxOo=; b=C6XksaNeT/D4WNLAn8wiXWA0cmZ7C4Wcp+D6RyDHwf7hlNJnPEJnPuQctex8cwVU9HJWBnWJuxgRdTZDY0paieGg8/uksFju79CpQk/38IFnkUTs5fRl69f0Tx/1Wdv4KjItM1zdkmxUR5Y1nDPU7M1pGZ4ERdcLH/k3+nlN1+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1585671898562500.5717024728798; Tue, 31 Mar 2020 09:24:58 -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-349-7eqFyJcjNsSiqmdbWYvgow-1; Tue, 31 Mar 2020 12:24:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C079D13F8; Tue, 31 Mar 2020 16:24:48 +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 93F54DA0E7; Tue, 31 Mar 2020 16:24:48 +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 54E2F86C11; Tue, 31 Mar 2020 16:24:48 +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 02VGOgjl023089 for ; Tue, 31 Mar 2020 12:24:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3B5E5D9E2; Tue, 31 Mar 2020 16:24:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7177F5D9C5 for ; Tue, 31 Mar 2020 16:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671897; 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=BtPK53em8vIC8NI/lxTrEuV8ej1wUT38BfLE7basxOo=; b=g6LVA/pz0r4u9ySF7v5AXe3e7grdZ+uwtcC6Y3cVEErc8WWQo+ygsp6/+gJF2MnOe9+I1Q w1KAiHSN0eUWdkkbDRU+e5X0NJ6SkUpgvxBiq9ziT8UCPHPFt6DBsuq6c7KcUwGmRrTRf0 jZ3VXKZOzGS48n7sLbRkd2C5wSLYXP0= X-MC-Unique: 7eqFyJcjNsSiqmdbWYvgow-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 06/10] qemuDomainGetMachineName: Access embeddedRoot from driver rather than cfg Date: Tue, 31 Mar 2020 18:24:18 +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.11 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" The cfg->root is going away, therefore get the info right from the driver structure. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 25ee46fe34..cba11b9e1e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -16535,7 +16535,6 @@ qemuDomainGetMachineName(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverPtr driver =3D priv->driver; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); char *ret =3D NULL; =20 if (vm->pid > 0) { @@ -16545,7 +16544,8 @@ qemuDomainGetMachineName(virDomainObjPtr vm) } =20 if (!ret) - ret =3D virDomainDriverGenerateMachineName("qemu", cfg->root, + ret =3D virDomainDriverGenerateMachineName("qemu", + driver->embeddedRoot, vm->def->id, vm->def->nam= e, driver->privileged); =20 --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1585671912; cv=none; d=zohomail.com; s=zohoarc; b=FygBK0/IctUG+u0Q6gZJBjj+UPUBPQLa4PmjvaQ8Mwy4ByKyATfcvDlcSk5qmiZayFz2Qt/EE6fHYDrKk8Ej2nthL7rGWgnjhCYvkANOYPCBu5NFAbR9HDrvOPkSw6oPAka23i9J0AePeaN/NHvyDk/SHUwnmzPUSyReSh6yCi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671912; 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=RYaK4ppQiyuAp04lQjoktxD7ySJl5irFKhLKw+QIiZk=; b=YsRIWYu2G5PPi9t6opQmmpG3iNlJ3o1XXy7jfNv/vhY+MpUpg0v2o4oZBd97oedmSxRjqCe/H0sLwzSjEgz+F8VGqIYmebHtcLnup3ubF/DofeGjWo5VnUzGmrksgffvUS51HeX9L1h/ggnBojkQFSEQWG7CVNZU/gXqp573mYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 158567191222156.90216326320581; Tue, 31 Mar 2020 09:25:12 -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-485-LJFA2M4JMmqo4gUnWMJVww-1; Tue, 31 Mar 2020 12:25:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16284107ACC9; Tue, 31 Mar 2020 16:25:03 +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 CC4E9DA0E2; Tue, 31 Mar 2020 16:25:02 +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 5772A86BE5; Tue, 31 Mar 2020 16:25:02 +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 02VGOgwi023097 for ; Tue, 31 Mar 2020 12:24:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id D70795D9E2; Tue, 31 Mar 2020 16:24:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 543D75D9C5 for ; Tue, 31 Mar 2020 16:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671911; 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=RYaK4ppQiyuAp04lQjoktxD7ySJl5irFKhLKw+QIiZk=; b=Hz4fPwVnn0RTnbNMTyvhAp4qTwQz0DEwz4mAA5lE+HljMOyFCCxohCMOjN4t+UzhCGzOjg a77EasmFWGhNyzkFbF72qajOnzxtW9UJyLCWIKXF+Z/uBjX8L1ngpG/KzzxfjGksC17Bdg ze8iYGJ+2CJFluurTDXWynbZlYe5sB0= X-MC-Unique: LJFA2M4JMmqo4gUnWMJVww-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 07/10] Revert "qemu_conf: Track embed root dir" Date: Tue, 31 Mar 2020 18:24:19 +0200 Message-Id: <7f79e05709bf0066bca6ac5f9bcb042d4da732c6.1585671623.git.mprivozn@redhat.com> 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.11 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" This reverts commit 06a19921b6a522cd7b4d352c9320909752947de3. What I haven't realized when writing this ^^ commit is that the virQEMUDriver structure already stores the root directory path. And since the pointer is immutable it can be accessed right from the structure and thus there is no need to duplicate it in the driver config. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_conf.c | 2 -- src/qemu/qemu_conf.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 5339c5fc04..da2abb6188 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -115,7 +115,6 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged, =20 if (root) { cfg->uri =3D g_strdup_printf("qemu:///embed?root=3D%s", root); - cfg->root =3D g_strdup(root); } else { cfg->uri =3D g_strdup(privileged ? "qemu:///system" : "qemu:///ses= sion"); } @@ -302,7 +301,6 @@ static void virQEMUDriverConfigDispose(void *obj) =20 virStringListFree(cfg->cgroupDeviceACL); VIR_FREE(cfg->uri); - VIR_FREE(cfg->root); =20 VIR_FREE(cfg->configBaseDir); VIR_FREE(cfg->configDir); diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 89332eeb73..8a0d220ce7 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -76,8 +76,6 @@ struct _virQEMUDriverConfig { virObject parent; =20 char *uri; - char *root; /* The root directory for embed driver, - NULL for system/session connections */ =20 uid_t user; gid_t group; --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1585671900; cv=none; d=zohomail.com; s=zohoarc; b=n/lFP8ky4rqscgFNFPFEcwvQhA8DUQTErZGOpd8meiQXzO0itLaDHPHvuXsaHL0cOEN/FpAOBsq7eEa8g5RYF+0m09Pl67Zdej+kPT8HSKYsw3g7VMQxY911qP4g5GxT7NLXuGuCqu7QBy8oL0l19F5GL1tBvMdoNB7stlpSBoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671900; 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=F+X44C3RXz+j7LQ6kIHe3cPUilWGZnOScTWqTy+H5Vg=; b=NKa5Zjjj7HKULaDv/heiC2LW0xQL7wa1UfV6oAPGbi1VF2/N0ghSwQVbNzpevXvcZb0OkzqR5IX58oVWhnU61ZcD7x2noflcUNSYuw96aBB1tFfYgiBAa1sBTtPZ55jTGM2n5hGJgOcf9ATbMFTG58DVDY5R7D0H00TU1+UCIVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1585671900928931.2875455077581; Tue, 31 Mar 2020 09:25:00 -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-369-_N7KWrTdPvS2LF30goVLKw-1; Tue, 31 Mar 2020 12:24:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BDD2C477; Tue, 31 Mar 2020 16:24:50 +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 948C91001DC2; Tue, 31 Mar 2020 16:24:50 +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 4945D18089D6; Tue, 31 Mar 2020 16:24:50 +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 02VGOhKH023104 for ; Tue, 31 Mar 2020 12:24:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB6315D9C5; Tue, 31 Mar 2020 16:24:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 381075D9E2 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=1585671899; 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=F+X44C3RXz+j7LQ6kIHe3cPUilWGZnOScTWqTy+H5Vg=; b=FM0ZurZevPugffJwsX4dR6pARIMgRgXmlI7l7zI3hebtOTCA0qzYVYyWNqPaie15I9It4T p+D8b74oacRr1pa2mkd8T+izIkv9if/dBPc0Ra/yjcqxCMbBX0H26nf7K6wcMzalB5hjVE TUTsmDEjXCi0DwR9d5xjFmWL7JE4CcQ= X-MC-Unique: _N7KWrTdPvS2LF30goVLKw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 08/10] qemu: Make hugepages path generation embed driver aware Date: Tue, 31 Mar 2020 18:24:20 +0200 Message-Id: <8c933d2eec7e57c15eef52a03952d9e4bf140da5.1585671623.git.mprivozn@redhat.com> 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.84 on 10.5.11.22 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 hugepages: $mnt/libvirt/qemu/$id-$shortName where $mnt is the mount point of hugetlbfs corresponding to hugepages of desired size (e.g. /dev/hugepages), $id is domain ID and $shortName is shortened version of domain name. So for instance, the generated path may look something like this: /dev/hugepages/libvirt/qemu/1-QEMUGuest But this won't work with embed driver really, because if there are two instances of embed driver, and they both want to start a domain with the same name and with hugepages, both drivers will generate the same path which is not desired. 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 qemuGetBaseHugepagePath(). 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 Reviewed-by: Andrea Bolognani --- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_conf.c | 24 +++++++++++++++++------- src/qemu/qemu_conf.h | 10 ++++++---- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_process.c | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9a0a96bdea..689796a92b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3465,7 +3465,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, if (!priv->memPrealloc) prealloc =3D true; } else if (useHugepage) { - if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) <= 0) + if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) return -1; if (!priv->memPrealloc) prealloc =3D true; @@ -7251,7 +7251,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, if (!pagesize && qemuBuildMemoryGetDefaultPagesize(cfg, &pagesize) < 0) return -1; - if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &mem_path) < 0) + 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) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index da2abb6188..713542f8cd 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -40,6 +40,7 @@ #include "virxml.h" #include "virlog.h" #include "cpu/cpu.h" +#include "domain_driver.h" #include "domain_nwfilter.h" #include "virfile.h" #include "virsocket.h" @@ -1887,21 +1888,29 @@ qemuTranslateSnapshotDiskSourcePool(virDomainSnapsh= otDiskDefPtr def) } =20 char * -qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage) +qemuGetBaseHugepagePath(virQEMUDriverPtr driver, + virHugeTLBFSPtr hugepage) { + const char *root =3D driver->embeddedRoot; char *ret; =20 - ret =3D g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir); + if (root && !STRPREFIX(hugepage->mnt_dir, root)) { + g_autofree char * hash =3D virDomainDriverGenerateRootHash("qemu",= root); + ret =3D g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash); + } else { + ret =3D g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir); + } =20 return ret; } =20 =20 char * -qemuGetDomainHugepagePath(const virDomainDef *def, +qemuGetDomainHugepagePath(virQEMUDriverPtr driver, + const virDomainDef *def, virHugeTLBFSPtr hugepage) { - g_autofree char *base =3D qemuGetBaseHugepagePath(hugepage); + g_autofree char *base =3D qemuGetBaseHugepagePath(driver, hugepage); g_autofree char *domPath =3D virDomainDefGetShortName(def); char *ret =3D NULL; =20 @@ -1920,11 +1929,12 @@ qemuGetDomainHugepagePath(const virDomainDef *def, * -1 otherwise. */ int -qemuGetDomainHupageMemPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +qemuGetDomainHupageMemPath(virQEMUDriverPtr driver, + const virDomainDef *def, unsigned long long pagesize, char **memPath) { + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); size_t i =3D 0; =20 if (!cfg->nhugetlbfs) { @@ -1947,7 +1957,7 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, return -1; } =20 - if (!(*memPath =3D qemuGetDomainHugepagePath(def, &cfg->hugetlbfs[i]))) + if (!(*memPath =3D qemuGetDomainHugepagePath(driver, def, &cfg->hugetl= bfs[i]))) return -1; =20 return 0; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8a0d220ce7..b85a9497b7 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -386,12 +386,14 @@ virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQ= EMUDriverPtr driver, =20 int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def); =20 -char * qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage); -char * qemuGetDomainHugepagePath(const virDomainDef *def, +char * qemuGetBaseHugepagePath(virQEMUDriverPtr driver, + virHugeTLBFSPtr hugepage); +char * qemuGetDomainHugepagePath(virQEMUDriverPtr driver, + const virDomainDef *def, virHugeTLBFSPtr hugepage); =20 -int qemuGetDomainHupageMemPath(const virDomainDef *def, - virQEMUDriverConfigPtr cfg, +int qemuGetDomainHupageMemPath(virQEMUDriverPtr driver, + const virDomainDef *def, unsigned long long pagesize, char **memPath); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 716b82f8f2..33f177adbd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -917,7 +917,7 @@ qemuStateInitialize(bool privileged, for (i =3D 0; i < cfg->nhugetlbfs; i++) { g_autofree char *hugepagePath =3D NULL; =20 - hugepagePath =3D qemuGetBaseHugepagePath(&cfg->hugetlbfs[i]); + hugepagePath =3D qemuGetBaseHugepagePath(qemu_driver, &cfg->hugetl= bfs[i]); =20 if (!hugepagePath) goto error; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6b9f6fb860..f9c400059f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3881,7 +3881,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr d= river, if (!build || shouldBuildHP) { for (i =3D 0; i < cfg->nhugetlbfs; i++) { g_autofree char *path =3D NULL; - path =3D qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]= ); + path =3D qemuGetDomainHugepagePath(driver, vm->def, &cfg->huge= tlbfs[i]); =20 if (!path) return -1; --=20 2.24.1 From nobody Sat May 4 23:06:56 2024 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 Reviewed-by: Andrea Bolognani --- 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 From nobody Sat May 4 23:06:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1585671921; cv=none; d=zohomail.com; s=zohoarc; b=bypbHc5+Lpzsf+l0PaYTI95wjoxfxX9Vn3vVS31OWXJaq276mwNA4eySn9atzcdBBiBMD9RaCyYC1CQZLwnn570R8YghfbXZ0ONUlhB6Zsw/Menp2D+oQwneM4bnkjZyVJG0rb8JduRkXg1DZPN9NxP5dYvPHeLCHVTP5Y7Q7lQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671921; 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=xKWfwc76YtKTmEt3hyigP1WwkAAtlMJlDZnPMRbq/jo=; b=h8aHa+vsQHS5K1zXzxUAWpICvQURAIhoJaT6SiVdtuYHPigyBkg4dVWVc1oa17nDzCvszX3izitlukHEpEcw4i06hCParY2bbitUWfWkZW0u6bl5eOkMA1G0XpXhdGKGum8OLq4lH2mkVDiTtMN4iwqOjACwBHIj1hU/0oq3Fao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1585671921894885.8616167875331; Tue, 31 Mar 2020 09:25:21 -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-189-FxV53HzQPe6yBtsTHqGfSg-1; Tue, 31 Mar 2020 12:25:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 854BB18FF661; Tue, 31 Mar 2020 16:25:08 +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 485BE5E009; Tue, 31 Mar 2020 16:25:08 +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 DED1986C0E; Tue, 31 Mar 2020 16:25:07 +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 02VGOjLj023128 for ; Tue, 31 Mar 2020 12:24:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 829B35DA60; Tue, 31 Mar 2020 16:24:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 003C15D9E2 for ; Tue, 31 Mar 2020 16:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671920; 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=xKWfwc76YtKTmEt3hyigP1WwkAAtlMJlDZnPMRbq/jo=; b=W/0FBmQxx8yVlPU/XijL0EEN4VQO9dL/C4G9hRYElrsxN1QDARC4PFcmSsA9NwmpiM886I GFguPTFryzx0cZ2M/lNZKKLBlBJ8kTl+fQ4Fu/DptSgoezWWDHpgLkyPdMswYHGMJns/2/ Su13MHyIj98JagbOB2ObK6Qj5hSWEL4= X-MC-Unique: FxV53HzQPe6yBtsTHqGfSg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 10/10] qemu: Make auto dump path generation embed driver aware Date: Tue, 31 Mar 2020 18:24:22 +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.15 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 automatic dumps: $autoDumpPath/$id-$shortName-$timestamp where $autoDumpPath is where libvirt stores dumps of guests (e.g. /var/lib/libvirt/qemu/dump), $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/dump/1-QEMUGuest-2020-03-25-10:40:50 While in case of embed driver the following path would be generated by default: $root/lib/libvirt/qemu/dump/1-QEMUGuest-2020-03-25-10:40:50 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. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Andrea Bolognani --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 33f177adbd..1746c85be4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4104,6 +4104,7 @@ static char * getAutoDumpPath(virQEMUDriverPtr driver, virDomainObjPtr vm) { + const char *root =3D driver->embeddedRoot; g_autofree char *domname =3D virDomainDefGetShortName(vm->def); g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); g_autofree char *nowstr =3D NULL; @@ -4116,6 +4117,11 @@ getAutoDumpPath(virQEMUDriverPtr driver, =20 nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 + if (root && !STRPREFIX(cfg->autoDumpPath, root)) { + g_autofree char * hash =3D virDomainDriverGenerateRootHash(QEMU_DR= IVER_NAME, root); + return g_strdup_printf("%s/%s-%s-%s", cfg->autoDumpPath, hash, dom= name, nowstr); + } + return g_strdup_printf("%s/%s-%s", cfg->autoDumpPath, domname, nowstr); } =20 --=20 2.24.1