From nobody Sun Feb 8 11:45:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584711666; cv=none; d=zohomail.com; s=zohoarc; b=KnYdISqqA4cKvttgRSmoOOgQB159cmIZpVdHYqyTj/dWQXPEQxQD6eJLYReC2+mApcxFQ0Zenf/R7K7A5UIvym1TCgYx4uYW2ewkIlJmdQupb2ytpesPYOR91qm4RhUqAv/SGrYA4/jDHurIxkEB1FFgtaaxvj2EAlFAPNKpZUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584711666; 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=rZLhg+lw+Q1hFaEow9BKwP6W6aMXY1q8Fp8iJAinsEM=; b=By2beOEckU8XmNbfCqnJMedAICrOh+ChFp9IOt1VkGSwASwjsJlCcwwdog6viEFFqnxcvH7ikD9Ow8WdnUg7OitMd2WXl9VAgmMfqHtlC1cgQP7f/UkKsmDVN7d5ADhw7UHvEi63rFmOKPlenXuG+iuAy8FbaUZQ/rHz2gcJjlQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584711666820688.1996369492588; Fri, 20 Mar 2020 06:41:06 -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-373-pjVlpZYoN2GZaJiISGLZzg-1; Fri, 20 Mar 2020 09:40:51 -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 99C67A0CC0; Fri, 20 Mar 2020 13:40:44 +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 6AA1760C18; Fri, 20 Mar 2020 13:40:44 +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 18354942A8; Fri, 20 Mar 2020 13:40:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02KDeQTr020348 for ; Fri, 20 Mar 2020 09:40:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id E6DAF6EFA3; Fri, 20 Mar 2020 13:40:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-3.ams2.redhat.com [10.36.114.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C5EE62937; Fri, 20 Mar 2020 13:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584711665; 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=rZLhg+lw+Q1hFaEow9BKwP6W6aMXY1q8Fp8iJAinsEM=; b=a2QzAYAsMFutBFWHOPcBqKMN9OsNWlKcUSVeAMdRvtOSoe20MvI2Ei4zml5Rda56gIJ0Nb bDulgKT2w4Z+UzJ2Bt0/kI/OXac0d7nRGJzVjrNF5LIAnD/89dheXbzrFGGzFO5m0VW3Rd apLovJk0+2ZEAqkG5eC1Iky0XTFEQtE= X-MC-Unique: pjVlpZYoN2GZaJiISGLZzg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] qemu: wire up support for controlling use of cgroups backend Date: Fri, 20 Mar 2020 13:40:13 +0000 Message-Id: <20200320134014.3123811-4-berrange@redhat.com> In-Reply-To: <20200320134014.3123811-1-berrange@redhat.com> References: <20200320134014.3123811-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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" Currently the QEMU driver chooses between systemd machined and direct cgroups usage of privileged, and does not use either when unprivileged. This wires up support for the new backend choice introduced by the earlier commits, allowing apps to override the default logic in the driver when privileged. This reverts commit c32a7de7d8f81384b17dbe529c6d3b3ac13c631d. --- src/qemu/qemu_cgroup.c | 68 ++++++++++++++++++++++++++++++++--------- src/qemu/qemu_command.c | 9 +++--- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index cd7c381185..a1b53f6628 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -917,6 +917,46 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) } =20 =20 +static int qemuGetCgroupMode(virDomainObjPtr vm, + virDomainResourceBackend backend, + virCgroupRegister *cgreg) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + bool avail =3D virQEMUDriverIsPrivileged(priv->driver) && + virCgroupAvailable(); + + switch (backend) { + case VIR_DOMAIN_RESOURCE_BACKEND_NONE: + return 0; + case VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT: + if (!avail) + return 0; + *cgreg =3D VIR_CGROUP_REGISTER_DEFAULT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_MACHINED: + if (!avail) + goto unsupported; + *cgreg =3D VIR_CGROUP_REGISTER_MACHINED; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_CGROUPFS: + if (!avail) + goto unsupported; + *cgreg =3D VIR_CGROUP_REGISTER_DIRECT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_LAST: + default: + virReportEnumRangeError(virDomainResourceBackend, backend); + } + + return 1; + + unsupported: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Resource backend '%s' not available"), + virDomainResourceBackendTypeToString(backend)); + return -1; +} + static int qemuInitCgroup(virDomainObjPtr vm, size_t nnicindexes, @@ -925,11 +965,17 @@ qemuInitCgroup(virDomainObjPtr vm, int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(priv->driver); + virCgroupRegister reg; + int rv; =20 - if (!virQEMUDriverIsPrivileged(priv->driver)) - goto done; - - if (!virCgroupAvailable()) + rv =3D qemuGetCgroupMode(vm, + vm->def->resource ? + vm->def->resource->backend : + VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT, + ®); + if (rv < 0) + goto cleanup; + if (rv =3D=3D 0) goto done; =20 virCgroupFree(&priv->cgroup); @@ -941,18 +987,12 @@ qemuInitCgroup(virDomainObjPtr vm, goto cleanup; =20 res->backend =3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT; - res->partition =3D g_strdup("/machine"); - vm->def->resource =3D res; } =20 - if (vm->def->resource->backend !=3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAUL= T) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Resource backend '%s' not available"), - virDomainResourceBackendTypeToString( - vm->def->resource->backend)); - goto cleanup; - } + if (vm->def->resource->backend !=3D VIR_DOMAIN_RESOURCE_BACKEND_NONE && + !vm->def->resource->partition) + vm->def->resource->partition =3D g_strdup("/machine"); =20 if (vm->def->resource->partition[0] !=3D '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -968,7 +1008,7 @@ qemuInitCgroup(virDomainObjPtr vm, vm->pid, false, nnicindexes, nicindexes, - VIR_CGROUP_REGISTER_DEFAULT, + ®, vm->def->resource->partition, cfg->cgroupControllers, cfg->maxThreadsPerProc, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9790c92cf8..eb1c3f6e12 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9662,7 +9662,8 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, int spice =3D 0; int egl_headless =3D 0; =20 - if (!virQEMUDriverIsPrivileged(driver)) { + if (!virQEMUDriverIsPrivileged(driver) || + (def->resource && def->resource->backend =3D=3D VIR_DOMAIN_RESOURC= E_BACKEND_NONE)) { /* If we have no cgroups then we can have no tunings that * require them */ =20 @@ -9670,13 +9671,13 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr drive= r, virMemoryLimitIsSet(def->mem.soft_limit) || virMemoryLimitIsSet(def->mem.swap_hard_limit)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Memory tuning is not available in session mo= de")); + _("Memory tuning is not available without cgrou= ps")); return -1; } =20 if (def->blkio.weight) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Block I/O tuning is not available in session= mode")); + _("Block I/O tuning is not available without cg= roups")); return -1; } =20 @@ -9686,7 +9687,7 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, def->cputune.emulator_quota || def->cputune.iothread_period || def->cputune.iothread_quota) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("CPU tuning is not available in session mode"= )); + _("CPU tuning is not available without cgroups"= )); return -1; } } --=20 2.24.1