From nobody Fri Apr 26 12:18:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1584711640; cv=none; d=zohomail.com; s=zohoarc; b=UdlWvm6B4DJnM+2zhWVdF0AMlfTXXtCRZsKfmEYr6X4LRfMTsL47sFBBwmyw5rNfPhJpb1jXjb5WpCeQMrmLnPKPjXbaniqiTHOS2KFEqOINx7/r8p8AFgJTWIxGQ3Uuw39qMPVQHqcpO2tZCs9cNd6n+upmjKaypMdsqB2QQQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584711640; 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=BQWJygJNP6t3/GxFGJBrcQP8vhrXqoo6XfDgMo7fkBA=; b=fV+aWCQd8aYtEAUeAuYQsdLZqzmYYZrXvRxvtpz7q5d0E+8zhhYR46YlbqJgW3TNf8ZuIJiwXCVsNkM8q43Ju0t0T2oux3UklTzv0VTQ1+LvOlIVXb+T+KblXLgT05MaVoyFnsuL3n525krniwWK/SejMItNvkDSdrXuS/K3FFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584711640301378.96773144058193; Fri, 20 Mar 2020 06:40:40 -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-72-MybwJSeeOoGL8TE7_18XYQ-1; Fri, 20 Mar 2020 09:40:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C72318FF661; Fri, 20 Mar 2020 13:40:30 +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 BF2405C1D8; Fri, 20 Mar 2020 13:40:28 +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 B651018089CF; Fri, 20 Mar 2020 13:40:25 +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 02KDeOgJ020331 for ; Fri, 20 Mar 2020 09:40:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78FB46EFB0; Fri, 20 Mar 2020 13:40:24 +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 794D062937; Fri, 20 Mar 2020 13:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584711638; 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=BQWJygJNP6t3/GxFGJBrcQP8vhrXqoo6XfDgMo7fkBA=; b=NUiVPmQ2D+tgHjVgfRRoXLXVtgd4vK88mfhdrbihGL0Tm06Gn64mhRVwIWwg3/qX/BHmJz hOWuJ5Jrgjf1dOC40Anc1CtKL6/SiQD/+U8vDTd+oFWbIu6bdcD++nN8HtktKWRHE3eRxR B+5l/f6ltJ7DuO7oVMhUlLeEWE52Gw8= X-MC-Unique: MybwJSeeOoGL8TE7_18XYQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] conf: allow different resource registration modes Date: Fri, 20 Mar 2020 13:40:11 +0000 Message-Id: <20200320134014.3123811-2-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.16 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" From: "Daniel P. Berrange" Currently the QEMU driver has three ways of setting up cgroups. It either skips them entirely (if non-root), or uses systemd-machined, or uses cgroups directly. This change adds ability to configure the mechanism for registering resources between all these options explicitly. via It is further possible to register directly with systemd and bypass machined. We don't support this but systemd-nsspawn does and we ought to consider this at some point. This would involve a new "systemd" backend type alongside "machined". Signed-off-by: Daniel P. Berrange --- docs/formatdomain.html.in | 24 +++++++++++- docs/schemas/domaincommon.rng | 17 +++++++-- src/conf/domain_conf.c | 46 ++++++++++++++++++----- src/conf/domain_conf.h | 13 +++++++ src/libvirt_private.syms | 2 + src/lxc/lxc_cgroup.c | 8 ++++ src/lxc/lxc_process.c | 1 + src/qemu/qemu_cgroup.c | 14 +++++++ tests/lxcxml2xmldata/lxc-capabilities.xml | 2 +- tests/lxcxml2xmldata/lxc-idmap.xml | 2 +- 10 files changed, 113 insertions(+), 16 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0d229386eb..a016e789f1 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1445,7 +1445,7 @@

 ...
-<resource>
+<resource backend=3D'none|cgroupfs|machined'>
   <partition>/virtualmachines/production</partition>
 </resource>
 ...
@@ -1455,8 +1455,30 @@
       Resource partitions are currently supported by the QEMU and
       LXC drivers, which map partition paths to cgroups directories,
       in all mounted controllers. Since 1.0.5
+      There is a choice of implementations to use for resource partitions
+      controlled via the optional backend attribute.
+      Since 6.2.0. It accepts the values
     

=20 +
    +
    none
    +
    Resource management in libvirt is disabled, with the APIs + returning an error indicating the functionality is not available. + The QEMU will will remain in whatever cgroup the libvirt daemon + was in. On systemd hosts, this will result in QEMU being + terminated at the same time as the privileged libvirt management + daemon which launched them.
    +
    cgroupfs
    +
    Cgroups will be directly created via the cgroups virtual filesys= tem. + This is not recommended for use in scenarios where systemd is in + charge of the cgroup hierarchy, unless the resource partition poin= ts + to a subtree that systemd has delegated administrative for.
    +
    machined
    +
    Systemd machined will be called to indirectly create cgroups. + This is recommended for any host where systemd is managing the + cgroup hierarchy.
    +
+

CPU model and topology

=20

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 6805420451..29ffc3a3cf 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1126,9 +1126,20 @@ =20 - - - + + + + none + cgroupfs + machined + + + + + + + + =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e0432fc47d..ae512283d0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1244,6 +1244,13 @@ VIR_ENUM_IMPL(virDomainOsDefFirmware, "efi", ); =20 +VIR_ENUM_IMPL(virDomainResourceBackend, + VIR_DOMAIN_RESOURCE_BACKEND_LAST, + "default", + "none", + "cgroupfs", + "machined"); + /* Internal mapping: subset of block job types that can be present in * XML (remaining types are not two-phase). */ VIR_ENUM_DECL(virDomainBlockJob); @@ -19100,17 +19107,24 @@ virDomainResourceDefParse(xmlNodePtr node, { VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResourceDefPtr def =3D NULL; + g_autofree char *reg =3D NULL; =20 ctxt->node =3D node; =20 if (VIR_ALLOC(def) < 0) goto error; =20 - /* Find out what type of virtualization to use */ - if (!(def->partition =3D virXPathString("string(./partition)", ctxt)))= { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing resource partition attribute")); - goto error; + def->partition =3D virXPathString("string(./partition)", ctxt); + + reg =3D virXMLPropString(node, "backend"); + if (reg !=3D NULL) { + if ((def->backend =3D virDomainResourceBackendTypeFromString(reg))= <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("Invalid backend attribute")); + goto error; + } + } else { + def->backend =3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT; } =20 return def; @@ -27983,11 +27997,23 @@ static void virDomainResourceDefFormat(virBufferPtr buf, virDomainResourceDefPtr def) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "%s\n", def->partiti= on); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + if (def->backend =3D=3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT && + def->partition =3D=3D NULL) + return; + + virBufferAddLit(buf, "backend !=3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT) + virBufferAsprintf(buf, " backend=3D'%s'", virDomainResourceBackend= TypeToString(def->backend)); + + if (def->partition) { + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", def->par= tition); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } } =20 =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 73bd097cf8..4bfda29dee 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2228,7 +2228,19 @@ struct _virDomainPanicDef { void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights, int ndevices); =20 +typedef enum { + VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT, + VIR_DOMAIN_RESOURCE_BACKEND_NONE, + VIR_DOMAIN_RESOURCE_BACKEND_CGROUPFS, + VIR_DOMAIN_RESOURCE_BACKEND_MACHINED, + + VIR_DOMAIN_RESOURCE_BACKEND_LAST, +} virDomainResourceBackend; + +typedef struct _virDomainResourceDef virDomainResourceDef; +typedef virDomainResourceDef *virDomainResourceDefPtr; struct _virDomainResourceDef { + int backend; /* enum virDomainResourceBackend */ char *partition; }; =20 @@ -3525,6 +3537,7 @@ VIR_ENUM_DECL(virDomainIOMMUModel); VIR_ENUM_DECL(virDomainVsockModel); VIR_ENUM_DECL(virDomainShmemModel); VIR_ENUM_DECL(virDomainLaunchSecurity); +VIR_ENUM_DECL(virDomainResourceBackend); /* from libvirt.h */ VIR_ENUM_DECL(virDomainState); VIR_ENUM_DECL(virDomainNostateReason); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6b305bdd0e..6e5cc201ff 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -575,6 +575,8 @@ virDomainRedirdevBusTypeToString; virDomainRedirdevDefFind; virDomainRedirdevDefFree; virDomainRedirdevDefRemove; +virDomainResourceBackendTypeFromString; +virDomainResourceBackendTypeToString; virDomainRNGBackendTypeToString; virDomainRNGDefFree; virDomainRNGFind; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7df723a4da..326d33981c 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -392,6 +392,14 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, if (!machineName) goto cleanup; =20 + if (def->resource->backend !=3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Resource backend '%s' not available"), + virDomainResourceBackendTypeToString( + def->resource->backend)); + goto cleanup; + } + if (def->resource->partition[0] !=3D '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Resource partition '%s' must start with '/'"), diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 5199f3806e..4ec3cc5619 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1260,6 +1260,7 @@ int virLXCProcessStart(virConnectPtr conn, if (VIR_ALLOC(res) < 0) goto cleanup; =20 + res->backend =3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT; res->partition =3D g_strdup("/machine"); =20 vm->def->resource =3D res; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index c0e30f6152..c407431f6b 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -940,11 +940,20 @@ qemuInitCgroup(virDomainObjPtr vm, if (VIR_ALLOC(res) < 0) goto cleanup; =20 + res->backend =3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT; res->partition =3D g_strdup("/machine"); =20 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->partition[0] !=3D '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Resource partition '%s' must start with '/'"), @@ -1061,6 +1070,11 @@ qemuConnectCgroup(virDomainObjPtr vm) virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(priv->driver); int ret =3D -1; =20 + if (vm->def->resource && + vm->def->resource->backend =3D=3D VIR_DOMAIN_RESOURCE_BACKEND_NONE= ) { + goto done; + } + if (!virQEMUDriverIsPrivileged(priv->driver)) goto done; =20 diff --git a/tests/lxcxml2xmldata/lxc-capabilities.xml b/tests/lxcxml2xmlda= ta/lxc-capabilities.xml index 04d64e3e41..335fdf8b91 100644 --- a/tests/lxcxml2xmldata/lxc-capabilities.xml +++ b/tests/lxcxml2xmldata/lxc-capabilities.xml @@ -4,7 +4,7 @@ 1048576 1048576 1 - + /machine diff --git a/tests/lxcxml2xmldata/lxc-idmap.xml b/tests/lxcxml2xmldata/lxc-= idmap.xml index b477636c30..d618d69706 100644 --- a/tests/lxcxml2xmldata/lxc-idmap.xml +++ b/tests/lxcxml2xmldata/lxc-idmap.xml @@ -4,7 +4,7 @@ 1048576 1048576 1 - + /machine --=20 2.24.1 From nobody Fri Apr 26 12:18:14 2024 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=1584711641; cv=none; d=zohomail.com; s=zohoarc; b=g6UQ3BD47zYisV+TS7lGX1fuSmKd1mGm8ZfI7rdT8FdI47wVZ4dXnuF85ew3fW2LrOt1sHNFqJPwqFC1tb/OekjL8LP0xcbhFcitIQAXFDttiCXR5YlbhuzweNkrjxOrrKHQs9YaHSlN7InS4wnm6XjOP1m+Km0U7IyRMES7RWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584711641; 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=SXgVZMJg2tUfZxwFXrky/SVQ3kDYmWuOdK9EkKgoFiA=; b=dpqsiR5F/HX2uHiRocqOfInCkYej+ZASTDcmqr1tmZsGZOfC9hSYSK9c4XNlepaAHUbtvfMsI3T4xvt31tq+BszZH6qbNRIxZWKITkk7wjuLOIoXydJXXNXq61UUTT6HD2KYqP3ZKIJFd06mpPmdziaRGKM00XdWrWWedjOBmnk= 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 1584711641909365.61289403078945; Fri, 20 Mar 2020 06:40:41 -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-69-d-vyMXl4PYW2ByfRxjQH4A-1; Fri, 20 Mar 2020 09:40:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AF30A0CC2; Fri, 20 Mar 2020 13:40:32 +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 30902BBBE8; Fri, 20 Mar 2020 13:40:32 +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 CFE2918089D7; Fri, 20 Mar 2020 13:40:31 +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 02KDeP6p020339 for ; Fri, 20 Mar 2020 09:40:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD0C66EFB0; Fri, 20 Mar 2020 13:40:25 +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 DF86062937; Fri, 20 Mar 2020 13:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584711640; 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=SXgVZMJg2tUfZxwFXrky/SVQ3kDYmWuOdK9EkKgoFiA=; b=i4LqpQ/vJV89Z98CJOfsonFI1G3iTlR5R4s1twJ5MqVLyUXOoPhNarDM8zH0r0OANNoJM0 efJllCNoyBp7HvXBRQxrigNJ39aFJaC70NlJ46lzX8sCAS7NW9EcsNdCzMfH51tzMbtRyr PPQDRc3+Imm9TROoXoTRMyopKY2cbgU= X-MC-Unique: d-vyMXl4PYW2ByfRxjQH4A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] util: allow choice between machined or direct cgroups filesystem Date: Fri, 20 Mar 2020 13:40:12 +0000 Message-Id: <20200320134014.3123811-3-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.13 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 cgroups code currently tries to use machined and then falls back to using the cgroups filesystem directly. This introduces a new enum that allows callers to have explicit control over which impl is used. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/lxc/lxc_cgroup.c | 1 + src/qemu/qemu_cgroup.c | 1 + src/util/vircgroup.c | 57 ++++++++++++++++++++++++++---------------- src/util/vircgroup.h | 7 ++++++ 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 326d33981c..629f9eca1c 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -414,6 +414,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, initpid, true, nnicindexes, nicindexes, + VIR_CGROUP_REGISTER_DEFAULT, def->resource->partition, -1, 0, diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index c407431f6b..cd7c381185 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -968,6 +968,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/util/vircgroup.c b/src/util/vircgroup.c index 70d85200cb..0128c8bb60 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1228,6 +1228,7 @@ virCgroupNewMachine(const char *name, bool isContainer, size_t nnicindexes, int *nicindexes, + virCgroupRegister *reg, const char *partition, int controllers, unsigned int maxthreads, @@ -1237,29 +1238,43 @@ virCgroupNewMachine(const char *name, =20 *group =3D NULL; =20 - if ((rv =3D virCgroupNewMachineSystemd(name, - drivername, - uuid, - rootdir, - pidleader, - isContainer, - nnicindexes, - nicindexes, - partition, - controllers, - maxthreads, - group)) =3D=3D 0) - return 0; + if (*reg =3D=3D VIR_CGROUP_REGISTER_DEFAULT || + *reg =3D=3D VIR_CGROUP_REGISTER_MACHINED) { + if ((rv =3D virCgroupNewMachineSystemd(name, + drivername, + uuid, + rootdir, + pidleader, + isContainer, + nnicindexes, + nicindexes, + partition, + controllers, + maxthreads, + group)) =3D=3D 0) { + *reg =3D VIR_CGROUP_REGISTER_MACHINED; + return 0; + } =20 - if (rv =3D=3D -1) - return -1; + if (rv =3D=3D -1) + return -1; + + if (*reg =3D=3D VIR_CGROUP_REGISTER_MACHINED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("Systemd machined requested, but not av= ailable")); + return -1; + } + } =20 - return virCgroupNewMachineManual(name, - drivername, - pidleader, - partition, - controllers, - group); + rv =3D virCgroupNewMachineManual(name, + drivername, + pidleader, + partition, + controllers, + group); + if (rv =3D=3D 0) + *reg =3D VIR_CGROUP_REGISTER_DIRECT; + return rv; } =20 =20 diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 1dcd0688f1..b725bc4c94 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -87,6 +87,12 @@ virCgroupNewDetectMachine(const char *name, virCgroupPtr *group) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +typedef enum { + VIR_CGROUP_REGISTER_DEFAULT, + VIR_CGROUP_REGISTER_DIRECT, + VIR_CGROUP_REGISTER_MACHINED, +} virCgroupRegister; + int virCgroupNewMachine(const char *name, const char *drivername, const unsigned char *uuid, @@ -95,6 +101,7 @@ int virCgroupNewMachine(const char *name, bool isContainer, size_t nnicindexes, int *nicindexes, + virCgroupRegister *reg, const char *partition, int controllers, unsigned int maxthreads, --=20 2.24.1 From nobody Fri Apr 26 12:18:14 2024 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 From nobody Fri Apr 26 12:18:14 2024 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=1584711732; cv=none; d=zohomail.com; s=zohoarc; b=icvCzY+cdEDNQahswSxBfjewmF7Z2loWD4iPYDqzun/8MsCxFJfcn7nKyVto2WDQWSyC31cB6tKIsQUcnkd1l+tSPtNwaOor3P88QEB7X/HzczNCRBnhntePn8ixN8ICJPAIiqD3b8xkVlF9tLTKV1sVG1i9f3wuy5l3l9zMzI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584711732; 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=6Mh1DxHbJnqKgqEPInVAPsCr7ZufnTHegv2F6Ym9uJ4=; b=SwcCugcoVXnl0wjjAaJdq4uGHQK4yOCmMfA/xwqFCzExgeYAFLe+NKWvtBed+Z/I3hOetCwVpuYA2WO5TqfRfS723LNyB1LtPKhY9y+/zh3ixfER4yd/ZLSCGCESGa1RLAJwTBawhvoX3w6U0kqbFJvAFneU5QfYQ0kbR1Oo3hU= 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 1584711732722194.41583197146292; Fri, 20 Mar 2020 06:42: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-490-wLhUX6TCPtiyQiW7t-MQjA-1; Fri, 20 Mar 2020 09:40:53 -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 2AEE9A0CBF; Fri, 20 Mar 2020 13:40: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 000E419756; Fri, 20 Mar 2020 13:40:47 +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 A5507942AD; Fri, 20 Mar 2020 13:40:47 +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 02KDeS0W020359 for ; Fri, 20 Mar 2020 09:40:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 74F256EFA3; Fri, 20 Mar 2020 13:40:28 +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 53BD96EFB5; Fri, 20 Mar 2020 13:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584711731; 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=6Mh1DxHbJnqKgqEPInVAPsCr7ZufnTHegv2F6Ym9uJ4=; b=G0A8SCohTSkjkhy8jzbyRQNoxVEBypcJ3++flCE+NAvJn3NMEL19d1A8UwjOo37lPqv2sp Di/xweAf3ZpekxRQp0GmerlUn5KT0ZJJzCAuR53JJ94vNN+c9m341zt+C5sCZ50Ic6mtUa 91wYm6+VrY6u6ZUSZRG9hqxK03Nxg7E= X-MC-Unique: wLhUX6TCPtiyQiW7t-MQjA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] lxc: wire up support for controlling use of cgroups backend Date: Fri, 20 Mar 2020 13:40:14 +0000 Message-Id: <20200320134014.3123811-5-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.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" Currently the LXC driver chooses between systemd machined and direct cgroups usage. This wires up support for the new backend choice introduced by the earlier commits, allowing apps to override the default logic in the driver. This reverts commit c32a7de7d8f81384b17dbe529c6d3b3ac13c631d. --- src/lxc/lxc_cgroup.c | 37 ++++++++++++++++++++++++++++++------- src/lxc/lxc_cgroup.h | 3 +++ src/lxc/lxc_process.c | 6 ++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 629f9eca1c..1cfa831f2b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -380,6 +380,33 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr = def, return 0; } =20 +int virLXCCgroupMode(virDomainResourceBackend backend, + virCgroupRegister *cgreg) +{ + switch (backend) { + case VIR_DOMAIN_RESOURCE_BACKEND_NONE: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Resource backend '%s' not available"), + virDomainResourceBackendTypeToString(backend)); + return -1; + case VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT: + *cgreg =3D VIR_CGROUP_REGISTER_DEFAULT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_MACHINED: + *cgreg =3D VIR_CGROUP_REGISTER_MACHINED; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_CGROUPFS: + *cgreg =3D VIR_CGROUP_REGISTER_DIRECT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_LAST: + default: + virReportEnumRangeError(virDomainResourceBackend, backend); + return -1; + } + + return 0; +} + =20 virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, pid_t initpid, @@ -387,18 +414,14 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, int *nicindexes) { virCgroupPtr cgroup =3D NULL; + virCgroupRegister reg; char *machineName =3D virLXCDomainGetMachineName(def, 0); =20 if (!machineName) goto cleanup; =20 - if (def->resource->backend !=3D VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Resource backend '%s' not available"), - virDomainResourceBackendTypeToString( - def->resource->backend)); + if (virLXCCgroupMode(def->resource->backend, ®) < 0) goto cleanup; - } =20 if (def->resource->partition[0] !=3D '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -414,7 +437,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, initpid, true, nnicindexes, nicindexes, - VIR_CGROUP_REGISTER_DEFAULT, + ®, def->resource->partition, -1, 0, diff --git a/src/lxc/lxc_cgroup.h b/src/lxc/lxc_cgroup.h index 63e9e837b0..df799b2720 100644 --- a/src/lxc/lxc_cgroup.h +++ b/src/lxc/lxc_cgroup.h @@ -26,6 +26,9 @@ #include "lxc_fuse.h" #include "virusb.h" =20 +int virLXCCgroupMode(virDomainResourceBackend backend, + virCgroupRegister *cgreg); + virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, pid_t initpid, size_t nnicindexes, diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 4ec3cc5619..ead27c17c0 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1261,11 +1261,13 @@ int virLXCProcessStart(virConnectPtr conn, 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_NONE && + !vm->def->resource->partition) + vm->def->resource->partition =3D g_strdup("/machine"); + logfile =3D g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name); =20 if (!(pidfile =3D virPidFileBuildPath(cfg->stateDir, vm->def->name))) --=20 2.24.1