From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469890898727.2570486347716; Tue, 2 Oct 2018 01:44:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72D64C04AC4C; Tue, 2 Oct 2018 08:44: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 2266E308BDA2; Tue, 2 Oct 2018 08:44: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 E5009181A12E; Tue, 2 Oct 2018 08:44:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ig9n031183 for ; Tue, 2 Oct 2018 04:44:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C0DE10016DC; Tue, 2 Oct 2018 08:44:42 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8300A100194A for ; Tue, 2 Oct 2018 08:44:41 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:45 +0200 Message-Id: <4ef728701a06c1d497135baf0af0aa36a39d5b55.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/53] util: introduce cgroup v2 files X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:44:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Place cgroup v2 backend type before cgroup v1 to make it obvious that cgroup v2 is preferred implementation. Following patches will introduce support for hybrid configuration which will allow us to use both at the same time, but we should prefer cgroup v2 regardless. Signed-off-by: Pavel Hrdina --- src/Makefile.am | 1 + src/libvirt_private.syms | 3 ++ src/util/Makefile.inc.am | 2 ++ src/util/vircgroup.c | 3 ++ src/util/vircgroupbackend.c | 2 ++ src/util/vircgroupbackend.h | 3 +- src/util/vircgrouppriv.h | 9 ++++++ src/util/vircgroupv2.c | 63 +++++++++++++++++++++++++++++++++++++ src/util/vircgroupv2.h | 27 ++++++++++++++++ 9 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/util/vircgroupv2.c create mode 100644 src/util/vircgroupv2.h diff --git a/src/Makefile.am b/src/Makefile.am index f515569fd5..33ff280d78 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -675,6 +675,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ util/vircgroup.c \ util/vircgroupbackend.c \ util/vircgroupv1.c \ + util/vircgroupv2.c \ util/vircommand.c \ util/virconf.c \ util/virdbus.c \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92363913e3..335210c31d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1583,6 +1583,9 @@ virCgroupBackendRegister; # util/vircgroupv1.h virCgroupV1Register; =20 +# util/vircgroupv2.h +virCgroupV2Register; + # util/virclosecallbacks.h virCloseCallbacksGet; virCloseCallbacksGetConn; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index ad3be91867..cffbb357bc 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -27,6 +27,8 @@ UTIL_SOURCES =3D \ util/vircgroupbackend.h \ util/vircgroupv1.c \ util/vircgroupv1.h \ + util/vircgroupv2.c \ + util/vircgroupv2.h \ util/virclosecallbacks.c \ util/virclosecallbacks.h \ util/vircommand.c \ diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 548c873da8..1097b1f998 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1236,6 +1236,9 @@ virCgroupFree(virCgroupPtr *group) VIR_FREE((*group)->legacy[i].placement); } =20 + VIR_FREE((*group)->unified.mountPoint); + VIR_FREE((*group)->unified.placement); + VIR_FREE((*group)->path); VIR_FREE(*group); } diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c index d854c9711d..79fe6cb73d 100644 --- a/src/util/vircgroupbackend.c +++ b/src/util/vircgroupbackend.c @@ -21,6 +21,7 @@ =20 #include "vircgroupbackend.h" #include "vircgroupv1.h" +#include "vircgroupv2.h" #include "virerror.h" #include "virthread.h" =20 @@ -28,6 +29,7 @@ =20 VIR_ENUM_DECL(virCgroupBackend); VIR_ENUM_IMPL(virCgroupBackend, VIR_CGROUP_BACKEND_TYPE_LAST, + "cgroup V2", "cgroup V1"); =20 static virOnceControl virCgroupBackendOnce =3D VIR_ONCE_CONTROL_INITIALIZE= R; diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 1c5744ef76..b1f19233e4 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -50,7 +50,8 @@ typedef enum { } virCgroupBackendTaskFlags; =20 typedef enum { - VIR_CGROUP_BACKEND_TYPE_V1 =3D 0, + VIR_CGROUP_BACKEND_TYPE_V2 =3D 0, + VIR_CGROUP_BACKEND_TYPE_V1, VIR_CGROUP_BACKEND_TYPE_LAST, } virCgroupBackendType; =20 diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index c50a25f195..4a0d75ddbc 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -45,12 +45,21 @@ struct _virCgroupV1Controller { typedef struct _virCgroupV1Controller virCgroupV1Controller; typedef virCgroupV1Controller *virCgroupV1ControllerPtr; =20 +struct _virCgroupV2Controller { + int controllers; + char *mountPoint; + char *placement; +}; +typedef struct _virCgroupV2Controller virCgroupV2Controller; +typedef virCgroupV2Controller *virCgroupV2ControllerPtr; + struct _virCgroup { char *path; =20 virCgroupBackendPtr backend; =20 virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST]; + virCgroupV2Controller unified; }; =20 int virCgroupSetValueStr(virCgroupPtr group, diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c new file mode 100644 index 0000000000..23bf81dae2 --- /dev/null +++ b/src/util/vircgroupv2.c @@ -0,0 +1,63 @@ +/* + * vircgroupv2.c: methods for cgroups v2 backend + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ +#include + +#include "internal.h" + +#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ +#include "vircgrouppriv.h" +#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ + +#include "vircgroup.h" +#include "vircgroupbackend.h" +#include "vircgroupv2.h" +#include "virlog.h" + +VIR_LOG_INIT("util.cgroup"); + +#define VIR_FROM_THIS VIR_FROM_CGROUP + +VIR_ENUM_DECL(virCgroupV2Controller); +VIR_ENUM_IMPL(virCgroupV2Controller, VIR_CGROUP_CONTROLLER_LAST, + "cpu", "cpuacct", "cpuset", "memory", "devices", + "freezer", "io", "net_cls", "perf_event", "name=3Dsystemd"); + +#ifdef __linux__ + +virCgroupBackend virCgroupV2Backend =3D { + .type =3D VIR_CGROUP_BACKEND_TYPE_V2, +}; + + +void +virCgroupV2Register(void) +{ + virCgroupBackendRegister(&virCgroupV2Backend); +} + +#else /* !__linux__ */ + +void +virCgroupV2Register(void) +{ + VIR_INFO("Control groups not supported on this platform"); +} + +#endif /* !__linux__ */ diff --git a/src/util/vircgroupv2.h b/src/util/vircgroupv2.h new file mode 100644 index 0000000000..a5d0bd0978 --- /dev/null +++ b/src/util/vircgroupv2.h @@ -0,0 +1,27 @@ +/* + * vircgroupv2.h: methods for cgroups v2 backend + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef __VIR_CGROUP_V2_H__ +# define __VIR_CGROUP_V2_H__ + +void +virCgroupV2Register(void); + +#endif /* __VIR_CGROUP_V2_H__ */ --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846990961492.07140515081562; Tue, 2 Oct 2018 01:45:09 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6F95F307D861; Tue, 2 Oct 2018 08:45:07 +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 2B6B13DE5; Tue, 2 Oct 2018 08:45:07 +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 B36904A465; Tue, 2 Oct 2018 08:45:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928igr3031193 for ; Tue, 2 Oct 2018 04:44:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id D4889100194A; Tue, 2 Oct 2018 08:44:42 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A1951001903 for ; Tue, 2 Oct 2018 08:44:42 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:46 +0200 Message-Id: <6b5c4611b2ddd26e6e7b107f697bda23c45bcbb9.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/53] vircgroup: introduce virCgroupV2Available X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 02 Oct 2018 08:45:08 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We cannot detect only mount points to figure out whether cgroup v2 is available because systemd uses cgroup v2 for process tracking and all controllers are mounted as cgroup v1 controllers. To make sure that this is no the situation we need to check 'cgroup.controllers' file if it's not empty to make sure that cgroup v2 is not mounted only for process tracking. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 23bf81dae2..78497bd31d 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -19,6 +19,10 @@ */ #include =20 +#ifdef __linux__ +# include +#endif /* __linux__ */ + #include "internal.h" =20 #define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ @@ -28,7 +32,9 @@ #include "vircgroup.h" #include "vircgroupbackend.h" #include "vircgroupv2.h" +#include "virfile.h" #include "virlog.h" +#include "virstring.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -41,8 +47,54 @@ VIR_ENUM_IMPL(virCgroupV2Controller, VIR_CGROUP_CONTROLL= ER_LAST, =20 #ifdef __linux__ =20 +/* We're looking for one 'cgroup2' fs mount which has some + * controllers enabled. */ +static bool +virCgroupV2Available(void) +{ + bool ret =3D false; + FILE *mounts =3D NULL; + struct mntent entry; + char buf[CGROUP_MAX_VAL]; + + if (!(mounts =3D fopen("/proc/mounts", "r"))) + return false; + + while (getmntent_r(mounts, &entry, buf, sizeof(buf)) !=3D NULL) { + if (STREQ(entry.mnt_type, "cgroup2")) { + ret =3D true; + break; + } + } + + /* Systemd uses cgroup v2 for process tracking but no controller is + * available. We should consider this configuration as cgroup v2 is + * not available. */ + if (ret) { + int rc; + VIR_AUTOFREE(char *) contFile =3D NULL; + VIR_AUTOFREE(char *) contStr =3D NULL; + + if (virAsprintf(&contFile, "%s/cgroup.controllers", entry.mnt_dir)= < 0) + return false; + + rc =3D virFileReadAll(contFile, 1024 * 1024, &contStr); + if (rc < 0) + return false; + + if (STREQ(contStr, "")) + return false; + } + + VIR_FORCE_FCLOSE(mounts); + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, + + .available =3D virCgroupV2Available, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469909339893.2507568191048; Tue, 2 Oct 2018 01:45:09 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 28420C049D66; Tue, 2 Oct 2018 08:45:07 +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 C792B6CA57; Tue, 2 Oct 2018 08:45:06 +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 5F0024A464; Tue, 2 Oct 2018 08:45:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ihuH031201 for ; Tue, 2 Oct 2018 04:44:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA1B0100034B; Tue, 2 Oct 2018 08:44:43 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F99E100194A for ; Tue, 2 Oct 2018 08:44:43 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:47 +0200 Message-Id: <10b0b7dd24eb95ed59c428feaa0ef135b11f5dfe.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/53] vircgroup: introduce virCgroupV2ValidateMachineGroup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:45:08 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When reconnecting to a domain we are validating the cgroup name. In case of cgroup v2 we need to validate only the new format for host without systemd '{machinename}.libvirt-{drivername}' or scope name generated by systemd. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 78497bd31d..17096e52fa 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -35,6 +35,7 @@ #include "virfile.h" #include "virlog.h" #include "virstring.h" +#include "virsystemd.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -91,10 +92,52 @@ virCgroupV2Available(void) } =20 =20 +static bool +virCgroupV2ValidateMachineGroup(virCgroupPtr group, + const char *name ATTRIBUTE_UNUSED, + const char *drivername, + const char *machinename) +{ + VIR_AUTOFREE(char *) partmachinename =3D NULL; + VIR_AUTOFREE(char *) scopename =3D NULL; + char *tmp; + + if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename, + drivername) < 0) { + return false; + } + + if (virCgroupPartitionEscape(&partmachinename) < 0) + return false; + + if (!(scopename =3D virSystemdMakeScopeName(machinename, drivername, + false))) { + return false; + } + + if (virCgroupPartitionEscape(&scopename) < 0) + return false; + + if (!(tmp =3D strrchr(group->unified.placement, '/'))) + return false; + tmp++; + + if (STRNEQ(tmp, partmachinename) && + STRNEQ(tmp, scopename)) { + VIR_DEBUG("Name '%s' for unified does not match '%s' or '%s'", + tmp, partmachinename, scopename); + return false; + } + + return true; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 .available =3D virCgroupV2Available, + .validateMachineGroup =3D virCgroupV2ValidateMachineGroup, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469915480451.83541506624; Tue, 2 Oct 2018 01:45:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C88C1356E7; Tue, 2 Oct 2018 08:45:12 +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 7D0C7309136B; Tue, 2 Oct 2018 08:45:12 +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 1A3F04A46E; Tue, 2 Oct 2018 08:45:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928iicU031208 for ; Tue, 2 Oct 2018 04:44:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82601100194A; Tue, 2 Oct 2018 08:44:44 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0647B100034B for ; Tue, 2 Oct 2018 08:44:43 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:48 +0200 Message-Id: <232357f68a0db07fa3009fc76de0cf82aef7641d.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/53] vircgroup: introduce virCgroupV2CopyMounts X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:45:13 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 17096e52fa..d3f72b9006 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -133,11 +133,20 @@ virCgroupV2ValidateMachineGroup(virCgroupPtr group, } =20 =20 +static int +virCgroupV2CopyMounts(virCgroupPtr group, + virCgroupPtr parent) +{ + return VIR_STRDUP(group->unified.mountPoint, parent->unified.mountPoin= t); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 .available =3D virCgroupV2Available, .validateMachineGroup =3D virCgroupV2ValidateMachineGroup, + .copyMounts =3D virCgroupV2CopyMounts, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469919790808.5293094534666; Tue, 2 Oct 2018 01:45:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D72583078A2F; Tue, 2 Oct 2018 08:45:17 +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 97EAF1837C; Tue, 2 Oct 2018 08:45:17 +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 421454A474; Tue, 2 Oct 2018 08:45:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ijba031223 for ; Tue, 2 Oct 2018 04:44:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 58ABA100034B; Tue, 2 Oct 2018 08:44:45 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1EB7100194A for ; Tue, 2 Oct 2018 08:44:44 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:49 +0200 Message-Id: <4fc0bfa2e492a36d905bc7c00da09e3b9aec640f.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/53] vircgroup: introduce virCgroupV2CopyPlacement X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 02 Oct 2018 08:45:18 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index d3f72b9006..11d9876d36 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -141,12 +141,39 @@ virCgroupV2CopyMounts(virCgroupPtr group, } =20 =20 +static int +virCgroupV2CopyPlacement(virCgroupPtr group, + const char *path, + virCgroupPtr parent) +{ + if (path[0] =3D=3D '/') { + if (VIR_STRDUP(group->unified.placement, path) < 0) + return -1; + } else { + /* + * parent =3D=3D "/" + path=3D"" =3D> "/" + * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/libvir= t.service" + * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "/lib= virt.service/foo" + */ + if (virAsprintf(&group->unified.placement, "%s%s%s", + parent->unified.placement, + (STREQ(parent->unified.placement, "/") || + STREQ(path, "") ? "" : "/"), + path) < 0) + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 .available =3D virCgroupV2Available, .validateMachineGroup =3D virCgroupV2ValidateMachineGroup, .copyMounts =3D virCgroupV2CopyMounts, + .copyPlacement =3D virCgroupV2CopyPlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469891895526.9592088267013; Tue, 2 Oct 2018 01:44:51 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id CC81F81DEB; Tue, 2 Oct 2018 08:44:49 +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 9DC696A224; Tue, 2 Oct 2018 08:44:49 +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 39084181A139; Tue, 2 Oct 2018 08:44:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ikGo031228 for ; Tue, 2 Oct 2018 04:44:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2ECEE100034B; Tue, 2 Oct 2018 08:44:46 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A72DE100194A for ; Tue, 2 Oct 2018 08:44:45 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:50 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/53] vircgroup: introduce virCgroupV2DetectMounts X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 02 Oct 2018 08:44:50 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 11d9876d36..eaf07397d5 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -167,6 +167,21 @@ virCgroupV2CopyPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupV2DetectMounts(virCgroupPtr group, + const char *mntType, + const char *mntOpts ATTRIBUTE_UNUSED, + const char *mntDir) +{ + if (STRNEQ(mntType, "cgroup2")) + return 0; + + VIR_FREE(group->unified.mountPoint); + + return VIR_STRDUP(group->unified.mountPoint, mntDir); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -174,6 +189,7 @@ virCgroupBackend virCgroupV2Backend =3D { .validateMachineGroup =3D virCgroupV2ValidateMachineGroup, .copyMounts =3D virCgroupV2CopyMounts, .copyPlacement =3D virCgroupV2CopyPlacement, + .detectMounts =3D virCgroupV2DetectMounts, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469925024256.68256561166254; Tue, 2 Oct 2018 01:45:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 147C3C05000D; Tue, 2 Oct 2018 08:45:23 +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 C871269CBD; Tue, 2 Oct 2018 08:45:22 +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 65B25181A71E; Tue, 2 Oct 2018 08:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ilfk031233 for ; Tue, 2 Oct 2018 04:44:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 056BF100194A; Tue, 2 Oct 2018 08:44:47 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D5D0100034B for ; Tue, 2 Oct 2018 08:44:46 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:51 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/53] vircgroup: introduce virCgroupV2DetectPlacement X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:45:23 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the placement was copied from parent or set to absolute path there is nothing to do, otherwise set the placement based on process placement from /proc/self/cgroup or /proc/{pid}/cgroup. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index eaf07397d5..ed94d5da17 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -182,6 +182,31 @@ virCgroupV2DetectMounts(virCgroupPtr group, } =20 =20 +static int +virCgroupV2DetectPlacement(virCgroupPtr group, + const char *path, + const char *controllers ATTRIBUTE_UNUSED, + const char *selfpath) +{ + if (group->unified.placement) + return 0; + + /* + * selfpath =3D=3D "/" + path=3D"" -> "/" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/libvirt.se= rvice" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "/libvirt= .service/foo" + */ + if (virAsprintf(&group->unified.placement, + "%s%s%s", selfpath, + (STREQ(selfpath, "/") || + STREQ(path, "") ? "" : "/"), + path) < 0) + return -1; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -190,6 +215,7 @@ virCgroupBackend virCgroupV2Backend =3D { .copyMounts =3D virCgroupV2CopyMounts, .copyPlacement =3D virCgroupV2CopyPlacement, .detectMounts =3D virCgroupV2DetectMounts, + .detectPlacement =3D virCgroupV2DetectPlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469909002527.2385674548882; Tue, 2 Oct 2018 01:45:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16CB43082B05; Tue, 2 Oct 2018 08:45:07 +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 CAC2417B4F; Tue, 2 Oct 2018 08:45:06 +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 6241A181A130; Tue, 2 Oct 2018 08:45:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ilIV031251 for ; Tue, 2 Oct 2018 04:44:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF526100034B; Tue, 2 Oct 2018 08:44:47 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544E1100194A for ; Tue, 2 Oct 2018 08:44:47 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:52 +0200 Message-Id: <7eed15da4c32cc7836562265665473775b144f23.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/53] vircgroup: introduce virCgroupV2ValidatePlacement X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 02 Oct 2018 08:45:07 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index ed94d5da17..23443abfbb 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -207,6 +207,20 @@ virCgroupV2DetectPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupV2ValidatePlacement(virCgroupPtr group, + pid_t pid ATTRIBUTE_UNUSED) +{ + if (!group->unified.placement) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find placement for v2 controller")); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -216,6 +230,7 @@ virCgroupBackend virCgroupV2Backend =3D { .copyPlacement =3D virCgroupV2CopyPlacement, .detectMounts =3D virCgroupV2DetectMounts, .detectPlacement =3D virCgroupV2DetectPlacement, + .validatePlacement =3D virCgroupV2ValidatePlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469930036523.9032992117932; Tue, 2 Oct 2018 01:45:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0E75730B24DC; Tue, 2 Oct 2018 08:45:28 +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 BF55570C24; Tue, 2 Oct 2018 08:45:27 +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 63D984A47C; Tue, 2 Oct 2018 08:45:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928imIw031258 for ; Tue, 2 Oct 2018 04:44:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id A6977106A784; Tue, 2 Oct 2018 08:44:48 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ABB4106A78F for ; Tue, 2 Oct 2018 08:44:47 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:53 +0200 Message-Id: <2c2d24d7ad43f5bf6a1e29f7f16fcf61b50314c8.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/53] vircgroup: introduce virCgroupV2StealPlacement X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 02 Oct 2018 08:45:28 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 23443abfbb..d4e0366780 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -221,6 +221,17 @@ virCgroupV2ValidatePlacement(virCgroupPtr group, } =20 =20 +static char * +virCgroupV2StealPlacement(virCgroupPtr group) +{ + char *ret; + + VIR_STEAL_PTR(ret, group->unified.placement); + + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -231,6 +242,7 @@ virCgroupBackend virCgroupV2Backend =3D { .detectMounts =3D virCgroupV2DetectMounts, .detectPlacement =3D virCgroupV2DetectPlacement, .validatePlacement =3D virCgroupV2ValidatePlacement, + .stealPlacement =3D virCgroupV2StealPlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469934637393.6383283862184; Tue, 2 Oct 2018 01:45:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A688930C6D66; Tue, 2 Oct 2018 08:45: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 748A670C4F; Tue, 2 Oct 2018 08:45: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 1B66F181A72C; Tue, 2 Oct 2018 08:45:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928inup031264 for ; Tue, 2 Oct 2018 04:44:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DC39106A786; Tue, 2 Oct 2018 08:44:49 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0203C106A784 for ; Tue, 2 Oct 2018 08:44:48 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:54 +0200 Message-Id: <4a9df3066a865cc72cc0e5cc6b585aa5724b3dab.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/53] vircgroup: introduce virCgroupV2DetectControllers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:45:33 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cgroup v2 has only single mount point for all controllers. The list of controllers is stored in cgroup.controllers file, name of controllers are separated by space. In cgroup v2 there is no cpuacct controller, the cpu.stat file always exists with usage stats. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index d4e0366780..3200338fe3 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -32,6 +32,7 @@ #include "vircgroup.h" #include "vircgroupbackend.h" #include "vircgroupv2.h" +#include "virerror.h" #include "virfile.h" #include "virlog.h" #include "virstring.h" @@ -232,6 +233,71 @@ virCgroupV2StealPlacement(virCgroupPtr group) } =20 =20 +static int +virCgroupV2ParseControllersFile(virCgroupPtr group) +{ + int rc; + VIR_AUTOFREE(char *) contStr =3D NULL; + VIR_AUTOFREE(char *) contFile =3D NULL; + char **contList =3D NULL; + char **tmp; + + if (virAsprintf(&contFile, "%s/cgroup.controllers", + group->unified.mountPoint) < 0) + return -1; + + rc =3D virFileReadAll(contFile, 1024 * 1024, &contStr); + if (rc < 0) { + virReportSystemError(errno, _("Unable to read from '%s'"), contFil= e); + return -1; + } + + virTrimSpaces(contStr, NULL); + + contList =3D virStringSplit(contStr, " ", 20); + if (!contList) + return -1; + + tmp =3D contList; + + while (*tmp) { + int type =3D virCgroupV2ControllerTypeFromString(*tmp); + + if (type >=3D 0) + group->unified.controllers |=3D 1 << type; + + tmp++; + } + + virStringListFree(contList); + + return 0; +} + + +static int +virCgroupV2DetectControllers(virCgroupPtr group, + int controllers) +{ + size_t i; + + if (virCgroupV2ParseControllersFile(group) < 0) + return -1; + + group->unified.controllers |=3D 1 << VIR_CGROUP_CONTROLLER_CPUACCT; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) + VIR_DEBUG("Controller '%s' present=3D%s", + virCgroupV2ControllerTypeToString(i), + (group->unified.controllers & 1 << i) ? "yes" : "no"); + + if (controllers >=3D 0) + return controllers & group->unified.controllers; + else + return group->unified.controllers; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -243,6 +309,7 @@ virCgroupBackend virCgroupV2Backend =3D { .detectPlacement =3D virCgroupV2DetectPlacement, .validatePlacement =3D virCgroupV2ValidatePlacement, .stealPlacement =3D virCgroupV2StealPlacement, + .detectControllers =3D virCgroupV2DetectControllers, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846991481518.28021116101911; Tue, 2 Oct 2018 01:45:14 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3AFCA30917B0; Tue, 2 Oct 2018 08:45:12 +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 F101B6A226; Tue, 2 Oct 2018 08:45:11 +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 92F31181A13B; Tue, 2 Oct 2018 08:45:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928io7Q031277 for ; Tue, 2 Oct 2018 04:44:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 545F71001903; Tue, 2 Oct 2018 08:44:50 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCAB410016DC for ; Tue, 2 Oct 2018 08:44:49 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:55 +0200 Message-Id: <9c4e19954be348a96b8be9f4debc9143bc82995f.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/53] vircgroup: introduce virCgroupV2HasController X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 02 Oct 2018 08:45:13 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3200338fe3..5cd8e86b97 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -298,6 +298,14 @@ virCgroupV2DetectControllers(virCgroupPtr group, } =20 =20 +static bool +virCgroupV2HasController(virCgroupPtr group, + int controller) +{ + return group->unified.controllers & (1 << controller); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -310,6 +318,7 @@ virCgroupBackend virCgroupV2Backend =3D { .validatePlacement =3D virCgroupV2ValidatePlacement, .stealPlacement =3D virCgroupV2StealPlacement, .detectControllers =3D virCgroupV2DetectControllers, + .hasController =3D virCgroupV2HasController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469939360784.3241979194839; Tue, 2 Oct 2018 01:45:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79C33356EC; Tue, 2 Oct 2018 08:45:37 +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 409F82010CEC; Tue, 2 Oct 2018 08:45:37 +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 D535A41F69; Tue, 2 Oct 2018 08:45:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ippS031294 for ; Tue, 2 Oct 2018 04:44:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29F471001903; Tue, 2 Oct 2018 08:44:51 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A293210016DC for ; Tue, 2 Oct 2018 08:44:50 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:56 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/53] vircgroup: introduce virCgroupV2GetAnyController X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:45:38 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 5cd8e86b97..57be0b92c9 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -306,6 +306,13 @@ virCgroupV2HasController(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetAnyController(virCgroupPtr group) +{ + return ffs(group->unified.controllers) - 1; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -319,6 +326,7 @@ virCgroupBackend virCgroupV2Backend =3D { .stealPlacement =3D virCgroupV2StealPlacement, .detectControllers =3D virCgroupV2DetectControllers, .hasController =3D virCgroupV2HasController, + .getAnyController =3D virCgroupV2GetAnyController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469945188359.6767825642356; Tue, 2 Oct 2018 01:45:45 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7A63E30B8F9E; Tue, 2 Oct 2018 08:45:42 +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 3680A69CBD; Tue, 2 Oct 2018 08:45:42 +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 D9CC6181A13C; Tue, 2 Oct 2018 08:45:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928iqNe031299 for ; Tue, 2 Oct 2018 04:44:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0098D100194A; Tue, 2 Oct 2018 08:44:52 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A10A1001903 for ; Tue, 2 Oct 2018 08:44:51 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:57 +0200 Message-Id: <421b6dfcaef8ec9c9f18b81517a31bbd96d8bcdf.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/53] vircgroup: introduce virCgroupV2PathOfController X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 02 Oct 2018 08:45:43 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 57be0b92c9..3ca463e4c2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -313,6 +313,29 @@ virCgroupV2GetAnyController(virCgroupPtr group) } =20 =20 +static int +virCgroupV2PathOfController(virCgroupPtr group, + int controller, + const char *key, + char **path) +{ + if (!virCgroupV2HasController(group, controller)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("v2 controller '%s' is not available"), + virCgroupV2ControllerTypeToString(controller)); + return -1; + } + + if (virAsprintf(path, "%s%s/%s", + group->unified.mountPoint, + group->unified.placement, + key ? key : "") < 0) + return -1; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -327,6 +350,7 @@ virCgroupBackend virCgroupV2Backend =3D { .detectControllers =3D virCgroupV2DetectControllers, .hasController =3D virCgroupV2HasController, .getAnyController =3D virCgroupV2GetAnyController, + .pathOfController =3D virCgroupV2PathOfController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469919671386.5352080523014; Tue, 2 Oct 2018 01:45:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5582F3002F8A; Tue, 2 Oct 2018 08:45:17 +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 096C32010CBA; Tue, 2 Oct 2018 08:45:17 +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 9A1E44A471; Tue, 2 Oct 2018 08:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928iqFN031309 for ; Tue, 2 Oct 2018 04:44:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD64410016DC; Tue, 2 Oct 2018 08:44:52 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 510B2100034B for ; Tue, 2 Oct 2018 08:44:52 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:58 +0200 Message-Id: <32e3c23e4477938ea08852f1c9eda79deb92ad2f.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/53] vircgroup: introduce virCgroupV2MakeGroup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Oct 2018 08:45:18 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When creating cgroup hierarchy we need to enable controllers in the parent cgroup in order to be usable. That means writing "+{controller}" into cgroup.subtree_control file. We can enable only controllers that are enabled for parent cgroup, that means we need to do that for the whole cgroup tree. Cgroups for threads needs to be handled differently in cgroup v2. There are two types of controllers: - domain controllers: these cannot be enabled for threads - threaded controllers: these can be enabled for threads In addition there are multiple types of cgroups: - domain: normal cgroup - domain threaded: a domain cgroup that serves as root for threaded cgroups - domain invalid: invalid cgroup, can be changed into threaded, this is the default state if you create subgroup inside domain threaded group or threaded group - threaded: threaded cgroup which can have domain threaded or threaded as parent group In order to create threaded cgroup it's sufficient to write "threaded" into cgroup.type file, it will automatically make parent cgroup "domain threaded" if it was only "domain". In case the parent cgroup is already "domain threaded" or "threaded" it will modify only the type of current cgroup. After that we can enable threaded controllers. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 2 +- src/util/vircgroupbackend.h | 1 + src/util/vircgroupv2.c | 78 +++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 1097b1f998..dc249bfe33 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -938,7 +938,7 @@ virCgroupNewThread(virCgroupPtr domain, if (virCgroupNew(-1, name, domain, controllers, group) < 0) return -1; =20 - if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) { + if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_THREAD) < 0)= { virCgroupFree(group); return -1; } diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index b1f19233e4..86d1539e07 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -33,6 +33,7 @@ typedef enum { * before creating subcgroups and * attaching tasks */ + VIR_CGROUP_THREAD =3D 1 << 1, /* cgroup v2 handles threads differently= */ } virCgroupBackendFlags; =20 typedef enum { diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3ca463e4c2..8fb9ace474 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -336,6 +336,83 @@ virCgroupV2PathOfController(virCgroupPtr group, } =20 =20 +static int +virCgroupV2EnableController(virCgroupPtr parent, + int controller) +{ + VIR_AUTOFREE(char *) val =3D NULL; + + if (virAsprintf(&val, "+%s", + virCgroupV2ControllerTypeToString(controller)) < 0) { + return -1; + } + + if (virCgroupSetValueStr(parent, controller, + "cgroup.subtree_control", val) < 0) { + return -1; + } + + return 0; +} + + +static int +virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNUSED, + virCgroupPtr group, + bool create, + unsigned int flags) +{ + VIR_AUTOFREE(char *) path =3D NULL; + int controller; + + VIR_DEBUG("Make group %s", group->path); + + controller =3D virCgroupV2GetAnyController(group); + if (virCgroupV2PathOfController(group, controller, "", &path) < 0) + return -1; + + VIR_DEBUG("Make controller %s", path); + + if (!virFileExists(path)) { + if (!create || mkdir(path, 0755 || errno =3D=3D EEXIST) < 0) { + virReportSystemError(errno, + _("Failed to create v2 cgroup '%s'"), + group->path); + return -1; + } + } + + if (create) { + if (flags & VIR_CGROUP_THREAD) { + if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, + "cgroup.type", "threaded") < 0) { + return -1; + } + + if (virCgroupV2EnableController(parent, + VIR_CGROUP_CONTROLLER_CPU) < 0= ) { + return -1; + } + } else { + size_t i; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!virCgroupV2HasController(parent, i)) + continue; + + /* Controllers that are implicitly enabled if available. */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUACCT) + continue; + + if (virCgroupV2EnableController(parent, i) < 0) + return -1; + } + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -351,6 +428,7 @@ virCgroupBackend virCgroupV2Backend =3D { .hasController =3D virCgroupV2HasController, .getAnyController =3D virCgroupV2GetAnyController, .pathOfController =3D virCgroupV2PathOfController, + .makeGroup =3D virCgroupV2MakeGroup, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469917772661.5916158984442; Tue, 2 Oct 2018 01:45:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A25C281F0E; Tue, 2 Oct 2018 08:45:15 +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 64BB53091342; Tue, 2 Oct 2018 08:45:15 +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 0A3AA4A46D; Tue, 2 Oct 2018 08:45:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928ir9i031322 for ; Tue, 2 Oct 2018 04:44:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3507100194A; Tue, 2 Oct 2018 08:44:53 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27A531001903 for ; Tue, 2 Oct 2018 08:44:52 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:43:59 +0200 Message-Id: <81ed07b1c84aae03c7bf37a65c48c55c8bc71a7e.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/53] vircgroup: introduce virCgroupV2Remove X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 02 Oct 2018 08:45:16 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8fb9ace474..103f37fe91 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -413,6 +413,25 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNU= SED, } =20 =20 +static int +virCgroupV2Remove(virCgroupPtr group) +{ + VIR_AUTOFREE(char *) grppath =3D NULL; + int controller; + + /* Don't delete the root group, if we accidentally + ended up in it for some reason */ + if (STREQ(group->unified.placement, "/")) + return 0; + + controller =3D virCgroupV2GetAnyController(group); + if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0) + return 0; + + return virCgroupRemoveRecursively(grppath); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -429,6 +448,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getAnyController =3D virCgroupV2GetAnyController, .pathOfController =3D virCgroupV2PathOfController, .makeGroup =3D virCgroupV2MakeGroup, + .remove =3D virCgroupV2Remove, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469949079182.06181506866835; Tue, 2 Oct 2018 01:45:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 055B930016F1; Tue, 2 Oct 2018 08:45:47 +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 BCB8817B4F; Tue, 2 Oct 2018 08:45:46 +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 5822D41F79; Tue, 2 Oct 2018 08:45:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928isZK031329 for ; Tue, 2 Oct 2018 04:44:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7942D10016DC; Tue, 2 Oct 2018 08:44:54 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2795100194A for ; Tue, 2 Oct 2018 08:44:53 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:00 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/53] vircgroup: introduce virCgroupV2AddTask X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 02 Oct 2018 08:45:47 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In cgroups v2 we need to handle threads and processes differently. If you need to move a process you need to write its pid into cgrou.procs file and it will move the process with all its threads as well. The whole process will be moved if you use tid of any thread. In order to move only threads at first we need to create threaded group and after that we can write the relevant thread tids into cgroup.threads file. Threads can be moved only into cgroups that are children of cgroup of its process. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 103f37fe91..e7dbace42b 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -432,6 +432,20 @@ virCgroupV2Remove(virCgroupPtr group) } =20 =20 +static int +virCgroupV2AddTask(virCgroupPtr group, + pid_t pid, + unsigned int flags) +{ + int controller =3D virCgroupV2GetAnyController(group); + + if (flags & VIR_CGROUP_TASK_THREAD) + return virCgroupSetValueI64(group, controller, "cgroup.threads", p= id); + else + return virCgroupSetValueI64(group, controller, "cgroup.procs", pid= ); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -449,6 +463,7 @@ virCgroupBackend virCgroupV2Backend =3D { .pathOfController =3D virCgroupV2PathOfController, .makeGroup =3D virCgroupV2MakeGroup, .remove =3D virCgroupV2Remove, + .addTask =3D virCgroupV2AddTask, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469923534297.0746201018824; Tue, 2 Oct 2018 01:45:23 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id BDB69307D96E; Tue, 2 Oct 2018 08:45:21 +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 82BCA17B73; Tue, 2 Oct 2018 08:45:21 +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 20EF6181A369; Tue, 2 Oct 2018 08:45:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928itDw031344 for ; Tue, 2 Oct 2018 04:44:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50F6D100194A; Tue, 2 Oct 2018 08:44:55 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9F4810016DC for ; Tue, 2 Oct 2018 08:44:54 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:01 +0200 Message-Id: <956b02f02139bc7770663d86f5c7c5360c3c1cd3.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 02 Oct 2018 08:45:22 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index e7dbace42b..c6a9e0a7df 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -446,6 +446,22 @@ virCgroupV2AddTask(virCgroupPtr group, } =20 =20 +static int +virCgroupV2HasEmptyTasks(virCgroupPtr cgroup, + int controller) +{ + int ret =3D -1; + VIR_AUTOFREE(char *) content =3D NULL; + + ret =3D virCgroupGetValueStr(cgroup, controller, "cgroup.procs", &cont= ent); + + if (ret =3D=3D 0 && content[0] =3D=3D '\0') + ret =3D 1; + + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -464,6 +480,7 @@ virCgroupBackend virCgroupV2Backend =3D { .makeGroup =3D virCgroupV2MakeGroup, .remove =3D virCgroupV2Remove, .addTask =3D virCgroupV2AddTask, + .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469929414148.75220599937586; Tue, 2 Oct 2018 01:45:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F2D73AC2D5; Tue, 2 Oct 2018 08:45:26 +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 AC22317F46; Tue, 2 Oct 2018 08:45:26 +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 5333E4A46D; Tue, 2 Oct 2018 08:45:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928iumc031349 for ; Tue, 2 Oct 2018 04:44:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 256ED100034B; Tue, 2 Oct 2018 08:44:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F724100194A for ; Tue, 2 Oct 2018 08:44:55 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:02 +0200 Message-Id: <1f62e23ab1dc9a020fb01bfdd84c166896546c11.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/53] vircgroup: introduce virCgroupV2BindMount X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 02 Oct 2018 08:45:27 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index c6a9e0a7df..e30f438015 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -21,6 +21,7 @@ =20 #ifdef __linux__ # include +# include #endif /* __linux__ */ =20 #include "internal.h" @@ -462,6 +463,38 @@ virCgroupV2HasEmptyTasks(virCgroupPtr cgroup, } =20 =20 +static int +virCgroupV2BindMount(virCgroupPtr group, + const char *oldroot, + const char *mountopts) +{ + VIR_AUTOFREE(char *) opts =3D NULL; + VIR_AUTOFREE(char *) src =3D NULL; + + VIR_DEBUG("Mounting cgroups at '%s'", group->unified.mountPoint); + + if (virFileMakePath(group->unified.mountPoint) < 0) { + virReportSystemError(errno, _("Unable to create directory %s"), + group->unified.mountPoint); + return -1; + } + + if (virAsprintf(&opts, "mode=3D755,size=3D65536%s", mountopts) < 0) + return -1; + + if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint) < 0) + return -1; + + if (mount(src, group->unified.mountPoint, "none", MS_BIND, NULL) < 0) { + virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"= ), + src, group->unified.mountPoint); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -481,6 +514,7 @@ virCgroupBackend virCgroupV2Backend =3D { .remove =3D virCgroupV2Remove, .addTask =3D virCgroupV2AddTask, .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, + .bindMount =3D virCgroupV2BindMount, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469933847380.21464450529345; Tue, 2 Oct 2018 01:45:33 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7A64F86670; Tue, 2 Oct 2018 08:45:31 +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 32CE41C927; Tue, 2 Oct 2018 08:45:31 +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 D15EB181A71E; Tue, 2 Oct 2018 08:45:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j1E1031370 for ; Tue, 2 Oct 2018 04:45:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 09D2F10016DC; Tue, 2 Oct 2018 08:45:01 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F7F71001903 for ; Tue, 2 Oct 2018 08:44:56 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:03 +0200 Message-Id: <98e86dd36736e0b4db2192de0751fcca789e5b78.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/53] vircgroup: introduce virCgroupV2SetOwner X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 02 Oct 2018 08:45:32 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index e30f438015..fec5d28835 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -495,6 +495,57 @@ virCgroupV2BindMount(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetOwner(virCgroupPtr cgroup, + uid_t uid, + gid_t gid, + int controllers ATTRIBUTE_UNUSED) +{ + int ret =3D -1; + VIR_AUTOFREE(char *) base =3D NULL; + DIR *dh =3D NULL; + int direrr; + + struct dirent *de; + + if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint, + cgroup->unified.placement) < 0) { + goto cleanup; + } + + if (virDirOpen(&dh, base) < 0) + goto cleanup; + + while ((direrr =3D virDirRead(dh, &de, base)) > 0) { + VIR_AUTOFREE(char *) entry =3D NULL; + + if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0) + goto cleanup; + + if (chown(entry, uid, gid) < 0) { + virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"), + entry, uid, gid); + goto cleanup; + } + } + + if (direrr < 0) + goto cleanup; + + if (chown(base, uid, gid) < 0) { + virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"), + base, uid, gid); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_DIR_CLOSE(dh); + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -515,6 +566,7 @@ virCgroupBackend virCgroupV2Backend =3D { .addTask =3D virCgroupV2AddTask, .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, .bindMount =3D virCgroupV2BindMount, + .setOwner =3D virCgroupV2SetOwner, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469938308214.69957371968246; Tue, 2 Oct 2018 01:45:38 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 18895C04FFE0; Tue, 2 Oct 2018 08:45:36 +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 BF44F17F49; Tue, 2 Oct 2018 08:45:35 +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 5D2534A49E; Tue, 2 Oct 2018 08:45:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j1bK031376 for ; Tue, 2 Oct 2018 04:45:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id D494D100194A; Tue, 2 Oct 2018 08:45:01 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58BC51001903 for ; Tue, 2 Oct 2018 08:45:01 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:04 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 20/53] vircgroup: register cgroup v2 backend X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:45:37 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" All mandatory callbacks are implemented for cgroup v2 backend so we can register it now. Signed-off-by: Pavel Hrdina --- src/util/vircgroupbackend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c index 79fe6cb73d..7ee39ac8ca 100644 --- a/src/util/vircgroupbackend.c +++ b/src/util/vircgroupbackend.c @@ -52,6 +52,7 @@ virCgroupBackendRegister(virCgroupBackendPtr backend) static void virCgroupBackendOnceInit(void) { + virCgroupV2Register(); virCgroupV1Register(); } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846992526156.44946722527004; Tue, 2 Oct 2018 01:45:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45F6280F9A; Tue, 2 Oct 2018 08:45:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 058FD9D7D6; Tue, 2 Oct 2018 08:45:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F32E4A477; Tue, 2 Oct 2018 08:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j22V031387 for ; Tue, 2 Oct 2018 04:45:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC9AD10016DC; Tue, 2 Oct 2018 08:45:02 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 302E21001903 for ; Tue, 2 Oct 2018 08:45:02 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:05 +0200 Message-Id: <3e2af944582e0b49653c78732f9cdf53e48f25e5.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 21/53] vircgroup: introduce virCgroupV2SetBlkioWeight X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 02 Oct 2018 08:45:24 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index fec5d28835..3e2cd16335 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -546,6 +546,52 @@ virCgroupV2SetOwner(virCgroupPtr cgroup, } =20 =20 +static int +virCgroupV2SetBlkioWeight(virCgroupPtr group, + unsigned int weight) +{ + VIR_AUTOFREE(char *) value =3D NULL; + + if (virAsprintf(&value, "default %u", weight) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", + value); +} + + +static int +virCgroupV2GetBlkioWeight(virCgroupPtr group, + unsigned int *weight) +{ + VIR_AUTOFREE(char *) value =3D NULL; + char *tmp; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", &value) < 0) { + return -1; + } + + if (!(tmp =3D strstr(value, "default "))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot find default io weight.")); + return -1; + } + tmp +=3D strlen("default "); + + if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + tmp); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -567,6 +613,9 @@ virCgroupBackend virCgroupV2Backend =3D { .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, .bindMount =3D virCgroupV2BindMount, .setOwner =3D virCgroupV2SetOwner, + + .setBlkioWeight =3D virCgroupV2SetBlkioWeight, + .getBlkioWeight =3D virCgroupV2GetBlkioWeight, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469929905824.5420868394602; Tue, 2 Oct 2018 01:45:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1F94619D058; Tue, 2 Oct 2018 08:45:28 +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 C2D76795AD; Tue, 2 Oct 2018 08:45:27 +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 66FF14A48C; Tue, 2 Oct 2018 08:45:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j33O031398 for ; Tue, 2 Oct 2018 04:45:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 898241001903; Tue, 2 Oct 2018 08:45:03 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B10210016DC for ; Tue, 2 Oct 2018 08:45:02 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:06 +0200 Message-Id: <5db11c0380059642e4a7cbfe553f0c8d7b444e0c.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 22/53] vircgroup: introduce virCgroupV2GetBlkioIoServiced X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 02 Oct 2018 08:45:28 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3e2cd16335..30c400f129 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -592,6 +592,71 @@ virCgroupV2GetBlkioWeight(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetBlkioIoServiced(virCgroupPtr group, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write) +{ + long long stats_val; + VIR_AUTOFREE(char *) str1 =3D NULL; + char *p1; + size_t i; + + const char *value_names[] =3D { + "rbytes=3D", + "wbytes=3D", + "rios=3D", + "wios=3D", + }; + long long *value_ptrs[] =3D { + bytes_read, + bytes_write, + requests_read, + requests_write + }; + + *bytes_read =3D 0; + *bytes_write =3D 0; + *requests_read =3D 0; + *requests_write =3D 0; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.stat", &str1) < 0) { + return -1; + } + + /* sum up all entries of the same kind, from all devices */ + for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { + p1 =3D str1; + + while ((p1 =3D strstr(p1, value_names[i]))) { + p1 +=3D strlen(value_names[i]); + if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse byte %sstat '%s'"), + value_names[i], + p1); + return -1; + } + + if (stats_val < 0 || + (stats_val > 0 && *value_ptrs[i] > (LLONG_MAX - stats_val)= )) { + virReportError(VIR_ERR_OVERFLOW, + _("Sum of byte %sstat overflows"), + value_names[i]); + return -1; + } + *value_ptrs[i] +=3D stats_val; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -616,6 +681,7 @@ virCgroupBackend virCgroupV2Backend =3D { =20 .setBlkioWeight =3D virCgroupV2SetBlkioWeight, .getBlkioWeight =3D virCgroupV2GetBlkioWeight, + .getBlkioIoServiced =3D virCgroupV2GetBlkioIoServiced, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15384699430891009.7959704007069; Tue, 2 Oct 2018 01:45:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DAD087652; Tue, 2 Oct 2018 08:45:41 +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 C965020165DD; Tue, 2 Oct 2018 08:45:40 +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 72ADC181A870; Tue, 2 Oct 2018 08:45:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j4oF031407 for ; Tue, 2 Oct 2018 04:45:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6FB371001903; Tue, 2 Oct 2018 08:45:04 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE48D10016DC for ; Tue, 2 Oct 2018 08:45:03 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:07 +0200 Message-Id: <960169baa0831bafe6cec35e535cc3bd6f85d23a.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 23/53] vircgroup: introduce virCgroupV2GetBlkioIoDeviceServiced X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 02 Oct 2018 08:45:41 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 30c400f129..eff410258c 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -657,6 +657,69 @@ virCgroupV2GetBlkioIoServiced(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group, + const char *path, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write) +{ + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + char *p1; + size_t i; + + const char *value_names[] =3D { + "rbytes=3D", + "wbytes=3D", + "rios=3D", + "wios=3D", + }; + long long *value_ptrs[] =3D { + bytes_read, + bytes_write, + requests_read, + requests_write + }; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.stat", &str1) < 0) { + return -1; + } + + if (!(str2 =3D virCgroupGetBlockDevString(path))) + return -1; + + if (!(p1 =3D strstr(str1, str2))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte stats for block device '%s'"), + str2); + return -1; + } + + for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { + if (!(p1 =3D strstr(p1, value_names[i]))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte %sstats for block device '%= s'"), + value_names[i], str2); + return -1; + } + + if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, + 10, value_ptrs[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %sstat '%s'"), + value_names[i], p1 + strlen(value_names[i])); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -682,6 +745,7 @@ virCgroupBackend virCgroupV2Backend =3D { .setBlkioWeight =3D virCgroupV2SetBlkioWeight, .getBlkioWeight =3D virCgroupV2GetBlkioWeight, .getBlkioIoServiced =3D virCgroupV2GetBlkioIoServiced, + .getBlkioIoDeviceServiced =3D virCgroupV2GetBlkioIoDeviceServiced, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469953687305.09078892614457; Tue, 2 Oct 2018 01:45:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBD9480473; Tue, 2 Oct 2018 08:45:51 +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 720C3309136D; Tue, 2 Oct 2018 08:45: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 1E696181AC31; Tue, 2 Oct 2018 08:45:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j5Vx031417 for ; Tue, 2 Oct 2018 04:45:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E5F21001903; Tue, 2 Oct 2018 08:45:05 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C49CE10016DC for ; Tue, 2 Oct 2018 08:45:04 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:08 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 24/53] vircgroup: introduce virCgroupV2SetBlkioDeviceWeight X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 02 Oct 2018 08:45:52 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index eff410258c..b7e4db9f41 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -720,6 +720,55 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, + const char *path, + unsigned int weight) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", + str); +} + + +static int +virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, + const char *path, + unsigned int *weight) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *weight =3D 0; + } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -746,6 +795,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioWeight =3D virCgroupV2GetBlkioWeight, .getBlkioIoServiced =3D virCgroupV2GetBlkioIoServiced, .getBlkioIoDeviceServiced =3D virCgroupV2GetBlkioIoDeviceServiced, + .setBlkioDeviceWeight =3D virCgroupV2SetBlkioDeviceWeight, + .getBlkioDeviceWeight =3D virCgroupV2GetBlkioDeviceWeight, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469960142908.214733013334; Tue, 2 Oct 2018 01:46:00 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4360730CF5DF; Tue, 2 Oct 2018 08:45:57 +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 DA9436D021; Tue, 2 Oct 2018 08:45:56 +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 800AF41F36; Tue, 2 Oct 2018 08:45:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j60S031425 for ; Tue, 2 Oct 2018 04:45:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B8C51001903; Tue, 2 Oct 2018 08:45:06 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3D7A10016DC for ; Tue, 2 Oct 2018 08:45:05 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:09 +0200 Message-Id: <11045846cfdffe09d5d3b97771770930e62204b3.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Oct 2018 08:45:58 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index b7e4db9f41..408f7e3eeb 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -769,6 +769,68 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group, + const char *path, + unsigned int riops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (riops =3D=3D 0) { + if (virAsprintf(&str, "%sriops=3Dmax", blkstr) < 0) + return -1; + } else { + if (virAsprintf(&str, "%sriops=3D%u", blkstr, riops) < 0) + return -1; + } + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + str); +} + + +static int +virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, + const char *path, + unsigned int *riops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *riops =3D 0; + } else { + tmp =3D strstr(str, "riops=3D"); + tmp +=3D strlen("riops=3D"); + + if (STREQLEN(tmp, "max", 3)) { + *riops =3D 0; + } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -797,6 +859,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioIoDeviceServiced =3D virCgroupV2GetBlkioIoDeviceServiced, .setBlkioDeviceWeight =3D virCgroupV2SetBlkioDeviceWeight, .getBlkioDeviceWeight =3D virCgroupV2GetBlkioDeviceWeight, + .setBlkioDeviceReadIops =3D virCgroupV2SetBlkioDeviceReadIops, + .getBlkioDeviceReadIops =3D virCgroupV2GetBlkioDeviceReadIops, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469947497127.30689626541414; Tue, 2 Oct 2018 01:45:47 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B111980470; Tue, 2 Oct 2018 08:45:45 +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 713ED17F42; Tue, 2 Oct 2018 08:45:45 +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 19F6741F73; Tue, 2 Oct 2018 08:45:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j7ZB031432 for ; Tue, 2 Oct 2018 04:45:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A07F10016DC; Tue, 2 Oct 2018 08:45:07 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8042B103BAB3 for ; Tue, 2 Oct 2018 08:45:06 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:10 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 26/53] vircgroup: introduce virCgroupV2SetBlkioDeviceWriteIops X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 02 Oct 2018 08:45:46 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 408f7e3eeb..6279072aab 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -831,6 +831,68 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int wiops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (wiops =3D=3D 0) { + if (virAsprintf(&str, "%swiops=3Dmax", blkstr) < 0) + return -1; + } else { + if (virAsprintf(&str, "%swiops=3D%u", blkstr, wiops) < 0) + return -1; + } + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + str); +} + + +static int +virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int *wiops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *wiops =3D 0; + } else { + tmp =3D strstr(str, "wiops=3D"); + tmp +=3D strlen("wiops=3D"); + + if (STREQLEN(tmp, "max", 3)) { + *wiops =3D 0; + } else if (virStrToLong_ui(tmp, NULL, 10, wiops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -861,6 +923,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceWeight =3D virCgroupV2GetBlkioDeviceWeight, .setBlkioDeviceReadIops =3D virCgroupV2SetBlkioDeviceReadIops, .getBlkioDeviceReadIops =3D virCgroupV2GetBlkioDeviceReadIops, + .setBlkioDeviceWriteIops =3D virCgroupV2SetBlkioDeviceWriteIops, + .getBlkioDeviceWriteIops =3D virCgroupV2GetBlkioDeviceWriteIops, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469966637413.7475785082793; Tue, 2 Oct 2018 01:46:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D443308ED4D; Tue, 2 Oct 2018 08:46:04 +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 2BC053091327; Tue, 2 Oct 2018 08:46:04 +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 A0275181D0A4; Tue, 2 Oct 2018 08:46:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j7fU031437 for ; Tue, 2 Oct 2018 04:45:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9D8010016DC; Tue, 2 Oct 2018 08:45:07 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CE51106224C for ; Tue, 2 Oct 2018 08:45:07 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:11 +0200 Message-Id: <5ae4e3848a80b19dae544c461b381abf08d8a2fe.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 27/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadBps X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 02 Oct 2018 08:46:05 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 6279072aab..88bd9fb37c 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -893,6 +893,68 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group, + const char *path, + unsigned long long rbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (rbps =3D=3D 0) { + if (virAsprintf(&str, "%srbps=3Dmax", blkstr) < 0) + return -1; + } else { + if (virAsprintf(&str, "%srbps=3D%llu", blkstr, rbps) < 0) + return -1; + } + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + str); +} + + +static int +virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, + const char *path, + unsigned long long *rbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *rbps =3D 0; + } else { + tmp =3D strstr(str, "rbps=3D"); + tmp +=3D strlen("rbps=3D"); + + if (STREQLEN(tmp, "max", 3)) { + *rbps =3D 0; + } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -925,6 +987,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceReadIops =3D virCgroupV2GetBlkioDeviceReadIops, .setBlkioDeviceWriteIops =3D virCgroupV2SetBlkioDeviceWriteIops, .getBlkioDeviceWriteIops =3D virCgroupV2GetBlkioDeviceWriteIops, + .setBlkioDeviceReadBps =3D virCgroupV2SetBlkioDeviceReadBps, + .getBlkioDeviceReadBps =3D virCgroupV2GetBlkioDeviceReadBps, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469952192725.109118121031; Tue, 2 Oct 2018 01:45:52 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 587CF30C6D6C; Tue, 2 Oct 2018 08:45:50 +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 177BE70C20; Tue, 2 Oct 2018 08:45: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 B40DD41F7D; Tue, 2 Oct 2018 08:45:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j8wE031460 for ; Tue, 2 Oct 2018 04:45:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2981100194A; Tue, 2 Oct 2018 08:45:08 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 379D91001903 for ; Tue, 2 Oct 2018 08:45:08 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:12 +0200 Message-Id: <3545f8b28817d1cc00c93d6ffbed82215b17ee3c.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 28/53] vircgroup: introduce virCgroupV2SetBlkioDeviceWriteBps X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:45:51 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 88bd9fb37c..d48e9db559 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -955,6 +955,68 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (wbps =3D=3D 0) { + if (virAsprintf(&str, "%swbps=3Dmax", blkstr) < 0) + return -1; + } else { + if (virAsprintf(&str, "%swbps=3D%llu", blkstr, wbps) < 0) + return -1; + } + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + str); +} + + +static int +virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long *wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *wbps =3D 0; + } else { + tmp =3D strstr(str, "wbps=3D"); + tmp +=3D strlen("wbps=3D"); + + if (STREQLEN(tmp, "max", 3)) { + *wbps =3D 0; + } else if (virStrToLong_ull(tmp, NULL, 10, wbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -989,6 +1051,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceWriteIops =3D virCgroupV2GetBlkioDeviceWriteIops, .setBlkioDeviceReadBps =3D virCgroupV2SetBlkioDeviceReadBps, .getBlkioDeviceReadBps =3D virCgroupV2GetBlkioDeviceReadBps, + .setBlkioDeviceWriteBps =3D virCgroupV2SetBlkioDeviceWriteBps, + .getBlkioDeviceWriteBps =3D virCgroupV2GetBlkioDeviceWriteBps, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469934718574.6089301026431; Tue, 2 Oct 2018 01:45:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D19C8C03D477; Tue, 2 Oct 2018 08:45:32 +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 9394970C50; Tue, 2 Oct 2018 08:45: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 2FCFC4A497; Tue, 2 Oct 2018 08:45:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j9nP031473 for ; Tue, 2 Oct 2018 04:45:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90058100194A; Tue, 2 Oct 2018 08:45:09 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 109341001903 for ; Tue, 2 Oct 2018 08:45:08 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:13 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 29/53] vircgroup: introduce virCgroupV2SetMemory X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:45:33 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index d48e9db559..32d20f2ff6 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1017,6 +1017,33 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetMemory(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) { + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.max", + "max"); + } else { + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.max", + kb << 10); + } +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1053,6 +1080,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceReadBps =3D virCgroupV2GetBlkioDeviceReadBps, .setBlkioDeviceWriteBps =3D virCgroupV2SetBlkioDeviceWriteBps, .getBlkioDeviceWriteBps =3D virCgroupV2GetBlkioDeviceWriteBps, + + .setMemory =3D virCgroupV2SetMemory, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469957886554.864163184837; Tue, 2 Oct 2018 01:45:57 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 940BE804E2; Tue, 2 Oct 2018 08:45:55 +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 5763D6D01C; Tue, 2 Oct 2018 08:45:55 +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 E4F39181B9FC; Tue, 2 Oct 2018 08:45:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jAb9031489 for ; Tue, 2 Oct 2018 04:45:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 69EE91001903; Tue, 2 Oct 2018 08:45:10 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E064810016DC for ; Tue, 2 Oct 2018 08:45:09 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:14 +0200 Message-Id: <432b8045335af410a12936bc075f17e77893ec1a.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 30/53] vircgroup: introduce virCgroupV2GetMemoryStat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 02 Oct 2018 08:45:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 32d20f2ff6..da3b3a984c 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1044,6 +1044,80 @@ virCgroupV2SetMemory(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetMemoryStat(virCgroupPtr group, + unsigned long long *cache, + unsigned long long *activeAnon, + unsigned long long *inactiveAnon, + unsigned long long *activeFile, + unsigned long long *inactiveFile, + unsigned long long *unevictable) +{ + VIR_AUTOFREE(char *) stat =3D NULL; + char *line =3D NULL; + unsigned long long cacheVal =3D 0; + unsigned long long activeAnonVal =3D 0; + unsigned long long inactiveAnonVal =3D 0; + unsigned long long activeFileVal =3D 0; + unsigned long long inactiveFileVal =3D 0; + unsigned long long unevictableVal =3D 0; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.stat", + &stat) < 0) { + return -1; + } + + line =3D stat; + + while (line) { + char *newLine =3D strchr(line, '\n'); + char *valueStr =3D strchr(line, ' '); + unsigned long long value; + + if (newLine) + *newLine =3D '\0'; + + if (!valueStr) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'memory.stat' cgroup file.")); + return -1; + } + *valueStr =3D '\0'; + + if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + valueStr + 1); + return -1; + } + + if (STREQ(line, "file")) + cacheVal =3D value >> 10; + else if (STREQ(line, "active_anon")) + activeAnonVal =3D value >> 10; + else if (STREQ(line, "inactive_anon")) + inactiveAnonVal =3D value >> 10; + else if (STREQ(line, "active_file")) + activeFileVal =3D value >> 10; + else if (STREQ(line, "inactive_file")) + inactiveFileVal =3D value >> 10; + else if (STREQ(line, "unevictable")) + unevictableVal =3D value >> 10; + } + + *cache =3D cacheVal; + *activeAnon =3D activeAnonVal; + *inactiveAnon =3D inactiveAnonVal; + *activeFile =3D activeFileVal; + *inactiveFile =3D inactiveFileVal; + *unevictable =3D unevictableVal; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1082,6 +1156,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceWriteBps =3D virCgroupV2GetBlkioDeviceWriteBps, =20 .setMemory =3D virCgroupV2SetMemory, + .getMemoryStat =3D virCgroupV2GetMemoryStat, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469963590400.1945273555765; Tue, 2 Oct 2018 01:46:03 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A3B091E2C7; Tue, 2 Oct 2018 08:46:00 +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 5C2B369C9D; Tue, 2 Oct 2018 08:46:00 +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 BF2DE3FCC1; Tue, 2 Oct 2018 08:45:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jBVY031501 for ; Tue, 2 Oct 2018 04:45:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 485D8103BAB3; Tue, 2 Oct 2018 08:45:11 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE9B81001903 for ; Tue, 2 Oct 2018 08:45:10 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:15 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 31/53] vircgroup: introduce virCgroupV2GetMemoryUsage X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:46:02 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index da3b3a984c..9f37ff5be5 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1118,6 +1118,20 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetMemoryUsage(virCgroupPtr group, + unsigned long *kb) +{ + long long unsigned int usage_in_bytes; + int ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.current", &usage_in_bytes); + if (ret =3D=3D 0) + *kb =3D (unsigned long) usage_in_bytes >> 10; + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1157,6 +1171,7 @@ virCgroupBackend virCgroupV2Backend =3D { =20 .setMemory =3D virCgroupV2SetMemory, .getMemoryStat =3D virCgroupV2GetMemoryStat, + .getMemoryUsage =3D virCgroupV2GetMemoryUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469969834583.7438212988142; Tue, 2 Oct 2018 01:46:09 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7680130014DB; Tue, 2 Oct 2018 08:46:07 +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 2B38E79588; Tue, 2 Oct 2018 08:46:07 +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 B0077181D0AB; Tue, 2 Oct 2018 08:46:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jC9Y031511 for ; Tue, 2 Oct 2018 04:45:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 256B0100194A; Tue, 2 Oct 2018 08:45:12 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B29410016DC for ; Tue, 2 Oct 2018 08:45:11 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:16 +0200 Message-Id: <479f7a945528b72d23d2f7b0446539f995266323.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 32/53] vircgroup: introduce virCgroupV2SetMemoryHardLimit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 02 Oct 2018 08:46:08 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 9f37ff5be5..06522498f2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1132,6 +1132,47 @@ virCgroupV2GetMemoryUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetMemoryHardLimit(virCgroupPtr group, + unsigned long long kb) +{ + return virCgroupV2SetMemory(group, kb); +} + + +static int +virCgroupV2GetMemoryHardLimit(virCgroupPtr group, + unsigned long long *kb) +{ + VIR_AUTOFREE(char *) value =3D NULL; + unsigned long long max; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.max", &value) < 0) { + return -1; + } + + if (STREQ(value, "max")) { + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + return 0; + } + + if (virStrToLong_ull(value, NULL, 10, &max) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), + value); + return -1; + } + + *kb =3D max >> 10; + if (*kb >=3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1172,6 +1213,8 @@ virCgroupBackend virCgroupV2Backend =3D { .setMemory =3D virCgroupV2SetMemory, .getMemoryStat =3D virCgroupV2GetMemoryStat, .getMemoryUsage =3D virCgroupV2GetMemoryUsage, + .setMemoryHardLimit =3D virCgroupV2SetMemoryHardLimit, + .getMemoryHardLimit =3D virCgroupV2GetMemoryHardLimit, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469940819783.01827405237; Tue, 2 Oct 2018 01:45:40 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D49F9C05D406; Tue, 2 Oct 2018 08:45:37 +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 93CAC3DE5; Tue, 2 Oct 2018 08:45:37 +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 3BEF341F6B; Tue, 2 Oct 2018 08:45:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jCEj031516 for ; Tue, 2 Oct 2018 04:45:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id F11FC100194A; Tue, 2 Oct 2018 08:45:12 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7554C10016DC for ; Tue, 2 Oct 2018 08:45:12 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:17 +0200 Message-Id: <320604415187b23b8d304ea7d9f95f909bb24e7e.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 33/53] vircgroup: introduce virCgroupV2SetMemorySoftLimit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Oct 2018 08:45:39 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 06522498f2..b5cc5f8f2e 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1173,6 +1173,65 @@ virCgroupV2GetMemoryHardLimit(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetMemorySoftLimit(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) { + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.high", + "max"); + } else { + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.high", + kb << 10); + } +} + + +static int +virCgroupV2GetMemorySoftLimit(virCgroupPtr group, + unsigned long long *kb) +{ + VIR_AUTOFREE(char *) value =3D NULL; + unsigned long long high; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.high", &value) < 0) + return -1; + + if (STREQ(value, "max")) { + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + return 0; + } + + if (virStrToLong_ull(value, NULL, 10, &high) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), + value); + return -1; + } + + *kb =3D high >> 10; + if (*kb >=3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1215,6 +1274,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getMemoryUsage =3D virCgroupV2GetMemoryUsage, .setMemoryHardLimit =3D virCgroupV2SetMemoryHardLimit, .getMemoryHardLimit =3D virCgroupV2GetMemoryHardLimit, + .setMemorySoftLimit =3D virCgroupV2SetMemorySoftLimit, + .getMemorySoftLimit =3D virCgroupV2GetMemorySoftLimit, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846997279569.23690874401177; Tue, 2 Oct 2018 01:46:12 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 24BF913A8F; Tue, 2 Oct 2018 08:46:10 +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 D47296A224; Tue, 2 Oct 2018 08:46:09 +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 7A4C6181D0B0; Tue, 2 Oct 2018 08:46:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jDmP031529 for ; Tue, 2 Oct 2018 04:45:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id C984910016DC; Tue, 2 Oct 2018 08:45:13 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E02A100194A for ; Tue, 2 Oct 2018 08:45:13 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:18 +0200 Message-Id: <279e8004f43dc869fe071b2994671034f3c9d7b7.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 34/53] vircgroup: introduce virCgroupV2SetMemSwapHardLimit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 02 Oct 2018 08:46:11 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index b5cc5f8f2e..ae352f0212 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1232,6 +1232,66 @@ virCgroupV2GetMemorySoftLimit(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetMemSwapHardLimit(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) { + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.swap.max", + "max"); + } else { + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.swap.max", + kb << 10); + } +} + + +static int +virCgroupV2GetMemSwapHardLimit(virCgroupPtr group, + unsigned long long *kb) +{ + VIR_AUTOFREE(char *) value =3D NULL; + unsigned long long max; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.swap.max", &value) < 0) { + return -1; + } + + if (STREQ(value, "max")) { + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + return 0; + } + + if (virStrToLong_ull(value, NULL, 10, &max) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), + value); + return -1; + } + + *kb =3D max >> 10; + if (*kb >=3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1276,6 +1336,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getMemoryHardLimit =3D virCgroupV2GetMemoryHardLimit, .setMemorySoftLimit =3D virCgroupV2SetMemorySoftLimit, .getMemorySoftLimit =3D virCgroupV2GetMemorySoftLimit, + .setMemSwapHardLimit =3D virCgroupV2SetMemSwapHardLimit, + .getMemSwapHardLimit =3D virCgroupV2GetMemSwapHardLimit, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469976892674.237787481042; Tue, 2 Oct 2018 01:46:16 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B79EF30B94FB; Tue, 2 Oct 2018 08:46:13 +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 7ACDB60469; Tue, 2 Oct 2018 08:46:13 +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 BCA8E3FCE4; Tue, 2 Oct 2018 08:46:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jEbC031541 for ; Tue, 2 Oct 2018 04:45:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id A5BF510016DC; Tue, 2 Oct 2018 08:45:14 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26CC21001903 for ; Tue, 2 Oct 2018 08:45:13 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:19 +0200 Message-Id: <12ea802aa4045615e6d29189b8271a9b8c1a5648.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 35/53] vircgroup: introduce virCgroupV2GetMemSwapUsage X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:46:15 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index ae352f0212..3d1d68ded5 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1292,6 +1292,21 @@ virCgroupV2GetMemSwapHardLimit(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetMemSwapUsage(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int usage_in_bytes; + int ret; + ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.swap.current", &usage_in_bytes); + if (ret =3D=3D 0) + *kb =3D (unsigned long) usage_in_bytes >> 10; + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1338,6 +1353,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getMemorySoftLimit =3D virCgroupV2GetMemorySoftLimit, .setMemSwapHardLimit =3D virCgroupV2SetMemSwapHardLimit, .getMemSwapHardLimit =3D virCgroupV2GetMemSwapHardLimit, + .getMemSwapUsage =3D virCgroupV2GetMemSwapUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846997955956.40033962376231; Tue, 2 Oct 2018 01:46:19 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 180F4317C3F3; Tue, 2 Oct 2018 08:46:17 +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 CC6BC6A22D; Tue, 2 Oct 2018 08:46:16 +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 EAD783FCE7; Tue, 2 Oct 2018 08:46:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jFJ8031551 for ; Tue, 2 Oct 2018 04:45:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8050D1001903; Tue, 2 Oct 2018 08:45:15 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03CCA10016DC for ; Tue, 2 Oct 2018 08:45:14 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:20 +0200 Message-Id: <544e997ec61a8dcf7a95974dedb1e70a86616683.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 36/53] vircgroup: introduce virCgroupV2SetCpuShares X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 02 Oct 2018 08:46:18 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3d1d68ded5..6cecfb9741 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1307,6 +1307,26 @@ virCgroupV2GetMemSwapUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetCpuShares(virCgroupPtr group, + unsigned long long shares) +{ + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.weight", shares); +} + + +static int +virCgroupV2GetCpuShares(virCgroupPtr group, + unsigned long long *shares) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.weight", shares); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1354,6 +1374,9 @@ virCgroupBackend virCgroupV2Backend =3D { .setMemSwapHardLimit =3D virCgroupV2SetMemSwapHardLimit, .getMemSwapHardLimit =3D virCgroupV2GetMemSwapHardLimit, .getMemSwapUsage =3D virCgroupV2GetMemSwapUsage, + + .setCpuShares =3D virCgroupV2SetCpuShares, + .getCpuShares =3D virCgroupV2GetCpuShares, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846994598229.98586395098357; Tue, 2 Oct 2018 01:45:45 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B0730127AD; Tue, 2 Oct 2018 08:45: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 688CB6D01E; Tue, 2 Oct 2018 08:45: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 E880B181AC20; Tue, 2 Oct 2018 08:45:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jGrF031556 for ; Tue, 2 Oct 2018 04:45:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5D66410016DC; Tue, 2 Oct 2018 08:45:16 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0F501001903 for ; Tue, 2 Oct 2018 08:45:15 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:21 +0200 Message-Id: <06d4a2995cefe4ca3e2d8dd9b06991dbed2ca6cc.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 37/53] vircgroup: introduce virCgroupV2SetCpuCfsPeriod X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:45:44 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In order to set CPU cfs period using cgroup v2 'cpu.max' interface we need to load the current value of CPU cfs quota first because format of 'cpu.max' interface is '$quota $period' and in order to change 'period' we need to write 'quota' as well. Writing only one number changes only 'quota'. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 6cecfb9741..92fe825795 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1327,6 +1327,72 @@ virCgroupV2GetCpuShares(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetCpuCfsPeriod(virCgroupPtr group, + unsigned long long cfs_period) +{ + VIR_AUTOFREE(char *) value =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + /* The cfs_period should be greater or equal than 1ms, and less or equ= al + * than 1s. + */ + if (cfs_period < 1000 || cfs_period > 1000000) { + virReportError(VIR_ERR_INVALID_ARG, + _("cfs_period '%llu' must be in range (1000, 100000= 0)"), + cfs_period); + return -1; + } + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", &str) < 0) { + return -1; + } + + if (!(tmp =3D strchr(str, ' '))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid 'cpu.max' data.")); + return -1; + } + *tmp =3D '\n'; + + if (virAsprintf(&value, "%s %llu", str, cfs_period) < 0) + return -1; + + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", value); +} + + +static int +virCgroupV2GetCpuCfsPeriod(virCgroupPtr group, + unsigned long long *cfs_period) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", &str) < 0) { + return -1; + } + + if (!(tmp =3D strchr(str, ' '))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid 'cpu.max' data.")); + return -1; + } + + if (virStrToLong_ull(tmp, NULL, 10, cfs_period) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' from cpu.max."), str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1377,6 +1443,8 @@ virCgroupBackend virCgroupV2Backend =3D { =20 .setCpuShares =3D virCgroupV2SetCpuShares, .getCpuShares =3D virCgroupV2GetCpuShares, + .setCpuCfsPeriod =3D virCgroupV2SetCpuCfsPeriod, + .getCpuCfsPeriod =3D virCgroupV2GetCpuCfsPeriod, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469950812713.3542263546112; Tue, 2 Oct 2018 01:45:50 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3A8DC3F731; Tue, 2 Oct 2018 08:45: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 00E681C931; Tue, 2 Oct 2018 08:45: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 9C445181AC2B; Tue, 2 Oct 2018 08:45:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jMhZ031586 for ; Tue, 2 Oct 2018 04:45:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2DF40106224C; Tue, 2 Oct 2018 08:45:22 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7953104C456 for ; Tue, 2 Oct 2018 08:45:16 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:22 +0200 Message-Id: <86e10857e405cc6f33dcdd838768f4be97936f72.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 38/53] vircgroup: introduce virCgroupV2SetCpuCfsQuota X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:45:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 92fe825795..d52e065685 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1393,6 +1393,56 @@ virCgroupV2GetCpuCfsPeriod(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetCpuCfsQuota(virCgroupPtr group, + long long cfs_quota) +{ + /* The cfs_quota should be greater or equal than 1ms */ + if (cfs_quota >=3D 0 && + (cfs_quota < 1000 || + cfs_quota > ULLONG_MAX / 1000)) { + virReportError(VIR_ERR_INVALID_ARG, + _("cfs_quota '%lld' must be in range (1000, %llu)"), + cfs_quota, ULLONG_MAX / 1000); + return -1; + } + + if (cfs_quota =3D=3D ULLONG_MAX / 1000) { + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", "max"); + } + + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", cfs_quota); +} + + +static int +virCgroupV2GetCpuCfsQuota(virCgroupPtr group, + long long *cfs_quota) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", &str) < 0) { + return -1; + } + + if (STREQLEN(str, "max", 3)) + *cfs_quota =3D ULLONG_MAX / 1000; + + if (virStrToLong_ll(str, NULL, 10, cfs_quota) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' from cpu.max."), str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1445,6 +1495,8 @@ virCgroupBackend virCgroupV2Backend =3D { .getCpuShares =3D virCgroupV2GetCpuShares, .setCpuCfsPeriod =3D virCgroupV2SetCpuCfsPeriod, .getCpuCfsPeriod =3D virCgroupV2GetCpuCfsPeriod, + .setCpuCfsQuota =3D virCgroupV2SetCpuCfsQuota, + .getCpuCfsQuota =3D virCgroupV2GetCpuCfsQuota, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469954608596.9521150876083; Tue, 2 Oct 2018 01:45:54 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B4BF730013D3; Tue, 2 Oct 2018 08:45: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 7776A60C60; Tue, 2 Oct 2018 08:45: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 2226E181B9F3; Tue, 2 Oct 2018 08:45:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jNeK031597 for ; Tue, 2 Oct 2018 04:45:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0996610016DC; Tue, 2 Oct 2018 08:45:23 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EF91104C456 for ; Tue, 2 Oct 2018 08:45:22 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:23 +0200 Message-Id: <2cc1124b53aa4e88c31dcd3e2b29fdd157e8a741.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 39/53] vircgroup: introduce virCgroupV2SupportsCpuBW X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 02 Oct 2018 08:45:53 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index d52e065685..61c881f7e2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1443,6 +1443,21 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group, } =20 =20 +static bool +virCgroupV2SupportsCpuBW(virCgroupPtr cgroup) +{ + VIR_AUTOFREE(char *) path =3D NULL; + + if (virCgroupV2PathOfController(cgroup, VIR_CGROUP_CONTROLLER_CPU, + "cpu.max", &path) < 0) { + virResetLastError(); + return false; + } + + return virFileExists(path); +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1497,6 +1512,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getCpuCfsPeriod =3D virCgroupV2GetCpuCfsPeriod, .setCpuCfsQuota =3D virCgroupV2SetCpuCfsQuota, .getCpuCfsQuota =3D virCgroupV2GetCpuCfsQuota, + .supportsCpuBW =3D virCgroupV2SupportsCpuBW, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469959958638.0899481564587; Tue, 2 Oct 2018 01:45:59 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1447FC05D3F6; Tue, 2 Oct 2018 08:45:58 +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 CF9C91C945; Tue, 2 Oct 2018 08:45:57 +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 6DB3241090; Tue, 2 Oct 2018 08:45:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jN4l031607 for ; Tue, 2 Oct 2018 04:45:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D5B281062249; Tue, 2 Oct 2018 08:45:23 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 596E610016DC for ; Tue, 2 Oct 2018 08:45:23 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:24 +0200 Message-Id: <97285465ea1d1172af79404f5d75491caaf35733.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 40/53] vircgroup: introduce virCgroupV2GetCpuacctUsage X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Oct 2018 08:45:58 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 61c881f7e2..c6e66189bb 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1458,6 +1458,37 @@ virCgroupV2SupportsCpuBW(virCgroupPtr cgroup) } =20 =20 +static int +virCgroupV2GetCpuacctUsage(virCgroupPtr group, + unsigned long long *usage) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpu.stat", &str) < 0) { + return -1; + } + + if (!(tmp =3D strstr(str, "usage_usec "))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse cpu usage stat '%s'"), str); + return -1; + } + tmp +=3D strlen("usage_usec "); + + if (virStrToLong_ull(tmp, &tmp, 10, usage) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), tmp); + return -1; + } + + *usage *=3D 1000; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1513,6 +1544,8 @@ virCgroupBackend virCgroupV2Backend =3D { .setCpuCfsQuota =3D virCgroupV2SetCpuCfsQuota, .getCpuCfsQuota =3D virCgroupV2GetCpuCfsQuota, .supportsCpuBW =3D virCgroupV2SupportsCpuBW, + + .getCpuacctUsage =3D virCgroupV2GetCpuacctUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153846996704674.3717334489935; Tue, 2 Oct 2018 01:46:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDBB0C05D41D; Tue, 2 Oct 2018 08:46:04 +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 66B69309136E; Tue, 2 Oct 2018 08:46:04 +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 D8117181D0A6; Tue, 2 Oct 2018 08:46:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jOEo031618 for ; Tue, 2 Oct 2018 04:45:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id B24B7106224C; Tue, 2 Oct 2018 08:45:24 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32DAE106224B for ; Tue, 2 Oct 2018 08:45:24 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:25 +0200 Message-Id: <3e523b25e4e457d8a48ffaf587f7a3bc5e4c132f.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 41/53] vircgroup: introduce virCgroupV2GetCpuacctStat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Oct 2018 08:46:05 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index c6e66189bb..c7248c1145 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1489,6 +1489,54 @@ virCgroupV2GetCpuacctUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetCpuacctStat(virCgroupPtr group, + unsigned long long *user, + unsigned long long *sys) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *tmp; + unsigned long long userVal =3D 0; + unsigned long long sysVal =3D 0; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpu.stat", &str) < 0) { + return -1; + } + + if (!(tmp =3D strstr(str, "user_usec "))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse cpu user stat '%s'"), str); + return -1; + } + tmp +=3D strlen("user_usec "); + + if (virStrToLong_ull(tmp, &tmp, 10, &userVal) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), tmp); + return -1; + } + + if (!(tmp =3D strstr(str, "system_usec "))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse cpu sys stat '%s'"), str); + return -1; + } + tmp +=3D strlen("system_usec "); + + if (virStrToLong_ull(tmp, &tmp, 10, &sysVal) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse value '%s' as number."), tmp); + return -1; + } + + *user =3D userVal * 1000; + *sys =3D sysVal * 1000; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1546,6 +1594,7 @@ virCgroupBackend virCgroupV2Backend =3D { .supportsCpuBW =3D virCgroupV2SupportsCpuBW, =20 .getCpuacctUsage =3D virCgroupV2GetCpuacctUsage, + .getCpuacctStat =3D virCgroupV2GetCpuacctStat, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469983072698.6272486260366; Tue, 2 Oct 2018 01:46:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E300330C679B; Tue, 2 Oct 2018 08:46:20 +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 B04369D7D8; Tue, 2 Oct 2018 08:46:20 +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 4820E181A13C; Tue, 2 Oct 2018 08:46:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jPJ8031633 for ; Tue, 2 Oct 2018 04:45:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id C23BF1062252; Tue, 2 Oct 2018 08:45:25 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DC7E106224B for ; Tue, 2 Oct 2018 08:45:24 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:26 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 42/53] vircgroup: add support for hybrid configuration X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:46:21 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This enables to use both cgroup v1 and v2 at the same time together with libvirt. It is supported by kernel and there is valid use-case, not all controllers are implemented in cgroup v2 so there might be configurations where administrator would enable these missing controllers in cgroup v1. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 351 ++++++++++++++++++++++++++---------- src/util/vircgroupbackend.c | 20 ++ src/util/vircgroupbackend.h | 16 +- src/util/vircgrouppriv.h | 2 +- 4 files changed, 291 insertions(+), 98 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dc249bfe33..4aec5f1bcf 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -228,6 +228,7 @@ virCgroupDetectMounts(virCgroupPtr group) struct mntent entry; char buf[CGROUP_MAX_VAL]; int ret =3D -1; + size_t i; =20 mounts =3D fopen("/proc/mounts", "r"); if (mounts =3D=3D NULL) { @@ -236,11 +237,14 @@ virCgroupDetectMounts(virCgroupPtr group) } =20 while (getmntent_r(mounts, &entry, buf, sizeof(buf)) !=3D NULL) { - if (group->backend->detectMounts(group, - entry.mnt_type, - entry.mnt_opts, - entry.mnt_dir) < 0) { - goto cleanup; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->detectMounts(group, + entry.mnt_type, + entry.mnt_opts, + entry.mnt_dir) < 0) { + goto cleanup; + } } } =20 @@ -303,6 +307,7 @@ virCgroupDetectPlacement(virCgroupPtr group, } =20 while (fgets(line, sizeof(line), mapping) !=3D NULL) { + size_t i; char *controllers =3D strchr(line, ':'); char *selfpath =3D controllers ? strchr(controllers + 1, ':') : NU= LL; char *nl =3D selfpath ? strchr(selfpath, '\n') : NULL; @@ -317,9 +322,12 @@ virCgroupDetectPlacement(virCgroupPtr group, controllers++; selfpath++; =20 - if (group->backend->detectPlacement(group, path, controllers, - selfpath) < 0) { - goto cleanup; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->detectPlacement(group, path, controlle= rs, + selfpath) < 0) { + goto cleanup; + } } } =20 @@ -338,8 +346,9 @@ virCgroupDetect(virCgroupPtr group, const char *path, virCgroupPtr parent) { - int rc; size_t i; + bool backendAvailable =3D false; + int controllersAvailable =3D 0; virCgroupBackendPtr *backends =3D virCgroupBackendGetAll(); =20 VIR_DEBUG("group=3D%p controllers=3D%d path=3D%s parent=3D%p", @@ -350,31 +359,40 @@ virCgroupDetect(virCgroupPtr group, =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { if (backends[i] && backends[i]->available()) { - group->backend =3D backends[i]; - break; + group->backends[i] =3D backends[i]; + backendAvailable =3D true; } } =20 - if (!group->backend) { + if (!backendAvailable) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no cgroup backend available")); return -1; } =20 if (parent) { - if (group->backend->copyMounts(group, parent) < 0) - return -1; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->copyMounts(group, parent) < 0) { + return -1; + } + } } else { if (virCgroupDetectMounts(group) < 0) return -1; } =20 - rc =3D group->backend->detectControllers(group, controllers); - if (rc < 0) - return -1; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i]) { + int rc =3D group->backends[i]->detectControllers(group, contro= llers); + if (rc < 0) + return -1; + controllersAvailable |=3D rc; + } + } =20 /* Check that at least 1 controller is available */ - if (rc =3D=3D 0) { + if (controllersAvailable =3D=3D 0) { virReportSystemError(ENXIO, "%s", _("At least one cgroup controller is required= ")); return -1; @@ -383,17 +401,26 @@ virCgroupDetect(virCgroupPtr group, /* In some cases we can copy part of the placement info * based on the parent cgroup... */ - if ((parent || path[0] =3D=3D '/') && - group->backend->copyPlacement(group, path, parent) < 0) - return -1; + if (parent || path[0] =3D=3D '/') { + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->copyPlacement(group, path, parent) < 0= ) { + return -1; + } + } + } =20 /* ... but use /proc/cgroups to fill in the rest */ if (virCgroupDetectPlacement(group, pid, path) < 0) return -1; =20 /* Check that for every mounted controller, we found our placement */ - if (group->backend->validatePlacement(group, pid) < 0) - return -1; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->validatePlacement(group, pid) < 0) { + return -1; + } + } =20 return 0; } @@ -599,9 +626,14 @@ virCgroupMakeGroup(virCgroupPtr parent, bool create, unsigned int flags) { - if (group->backend->makeGroup(parent, group, create, flags) < 0) { - virCgroupRemove(group); - return -1; + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->makeGroup(parent, group, create, flags) < = 0) { + virCgroupRemove(group); + return -1; + } } =20 return 0; @@ -662,6 +694,24 @@ virCgroupNew(pid_t pid, } =20 =20 +static int +virCgroupAddTaskInternal(virCgroupPtr group, + pid_t pid, + unsigned int flags) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->addTask(group, pid, flags) < 0) { + return -1; + } + } + + return 0; +} + + /** * virCgroupAddProcess: * @@ -676,7 +726,7 @@ virCgroupNew(pid_t pid, int virCgroupAddProcess(virCgroupPtr group, pid_t pid) { - return group->backend->addTask(group, pid, VIR_CGROUP_TASK_PROCESS); + return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS); } =20 /** @@ -693,9 +743,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid) int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid) { - return group->backend->addTask(group, pid, - VIR_CGROUP_TASK_PROCESS | - VIR_CGROUP_TASK_SYSTEMD); + return virCgroupAddTaskInternal(group, pid, + VIR_CGROUP_TASK_PROCESS | + VIR_CGROUP_TASK_SYSTEMD); } =20 /** @@ -713,7 +763,7 @@ int virCgroupAddThread(virCgroupPtr group, pid_t pid) { - return group->backend->addTask(group, pid, VIR_CGROUP_TASK_THREAD); + return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD); } =20 =20 @@ -967,17 +1017,24 @@ virCgroupNewDetectMachine(const char *name, char *machinename, virCgroupPtr *group) { + size_t i; + if (virCgroupNewDetect(pid, controllers, group) < 0) { if (virCgroupNewIgnoreError()) return 0; return -1; } =20 - if (!(*group)->backend->validateMachineGroup(*group, name, drivername,= machinename)) { - VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", - name, drivername); - virCgroupFree(group); - return 0; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if ((*group)->backends[i] && + !(*group)->backends[i]->validateMachineGroup(*group, name, + drivername, + machinename)) { + VIR_DEBUG("Failed to validate machine name for '%s' driver '%s= '", + name, drivername); + virCgroupFree(group); + return 0; + } } =20 return 0; @@ -1055,6 +1112,7 @@ virCgroupNewMachineSystemd(const char *name, int rv; virCgroupPtr init; VIR_AUTOFREE(char *) path =3D NULL; + size_t i; =20 VIR_DEBUG("Trying to setup machine '%s' via systemd", name); if ((rv =3D virSystemdCreateMachine(name, @@ -1077,7 +1135,12 @@ virCgroupNewMachineSystemd(const char *name, &init) < 0) return -1; =20 - path =3D init->backend->stealPlacement(init); + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (init->backends[i] && + (path =3D init->backends[i]->stealPlacement(init))) { + break; + } + } virCgroupFree(&init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { @@ -1256,12 +1319,21 @@ virCgroupFree(virCgroupPtr *group) bool virCgroupHasController(virCgroupPtr cgroup, int controller) { + size_t i; + if (!cgroup) return false; if (controller < 0 || controller >=3D VIR_CGROUP_CONTROLLER_LAST) return false; =20 - return cgroup->backend->hasController(cgroup, controller); + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (cgroup->backends[i] && + cgroup->backends[i]->hasController(cgroup, controller)) { + return true; + } + } + + return false; } =20 =20 @@ -1277,7 +1349,8 @@ virCgroupPathOfController(virCgroupPtr group, return -1; } =20 - return group->backend->pathOfController(group, controller, key, path); + VIR_CGROUP_BACKEND_CALL(group, controller, pathOfController, -1, + controller, key, path); } =20 =20 @@ -1299,7 +1372,8 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioIoServiced, -1, + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioIoServiced, -1, bytes_read, bytes_write, requests_read, requests_write); } @@ -1325,7 +1399,8 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioIoDeviceServiced, -1, + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioIoDeviceServiced, -1, path, bytes_read, bytes_write, requests_read, requests_write); } @@ -1342,7 +1417,8 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioWeight, -1, weight); } =20 =20 @@ -1357,7 +1433,8 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned = int weight) int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioWeight, -1, weight); } =20 /** @@ -1373,7 +1450,8 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path, riops= ); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioDeviceReadIops, -1, path, riops); } =20 =20 @@ -1390,7 +1468,8 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiop= s); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioDeviceWriteIops, -1, path, wiops); } =20 =20 @@ -1407,7 +1486,8 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioDeviceReadBps, -1, path, rbps); } =20 /** @@ -1423,7 +1503,8 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioDeviceWriteBps, -1, path, wbps); } =20 =20 @@ -1441,7 +1522,8 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) { - VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + setBlkioDeviceWeight, -1, path, weight); } =20 /** @@ -1457,7 +1539,8 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path, riops= ); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioDeviceReadIops, -1, path, riops); } =20 /** @@ -1473,7 +1556,8 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteIops, -1, path, wiop= s); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioDeviceWriteIops, -1, path, wiops); } =20 /** @@ -1489,7 +1573,8 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadBps, -1, path, rbps); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioDeviceReadBps, -1, path, rbps); } =20 /** @@ -1505,7 +1590,8 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteBps, -1, path, wbps); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioDeviceWriteBps, -1, path, wbps); } =20 /** @@ -1521,7 +1607,8 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) { - VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + getBlkioDeviceWeight, -1, path, weight); } =20 =20 @@ -1536,7 +1623,8 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + setMemory, -1, kb); } =20 =20 @@ -1562,7 +1650,8 @@ virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *inactiveFile, unsigned long long *unevictable) { - VIR_CGROUP_BACKEND_CALL(group, getMemoryStat, -1, cache, + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemoryStat, -1, cache, activeAnon, inactiveAnon, activeFile, inactiveFile, unevictable); @@ -1580,7 +1669,8 @@ virCgroupGetMemoryStat(virCgroupPtr group, int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) { - VIR_CGROUP_BACKEND_CALL(group, getMemoryUsage, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemoryUsage, -1, kb); } =20 =20 @@ -1595,7 +1685,8 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned = long *kb) int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, setMemoryHardLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + setMemoryHardLimit, -1, kb); } =20 =20 @@ -1610,7 +1701,8 @@ virCgroupSetMemoryHardLimit(virCgroupPtr group, unsig= ned long long kb) int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, getMemoryHardLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemoryHardLimit, -1, kb); } =20 =20 @@ -1625,7 +1717,8 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsig= ned long long *kb) int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, setMemorySoftLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + setMemorySoftLimit, -1, kb); } =20 =20 @@ -1640,7 +1733,8 @@ virCgroupSetMemorySoftLimit(virCgroupPtr group, unsig= ned long long kb) int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, getMemorySoftLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemorySoftLimit, -1, kb); } =20 =20 @@ -1655,7 +1749,8 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsig= ned long long *kb) int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, setMemSwapHardLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + setMemSwapHardLimit, -1, kb); } =20 =20 @@ -1670,7 +1765,8 @@ virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsi= gned long long kb) int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, getMemSwapHardLimit, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemSwapHardLimit, -1, kb); } =20 =20 @@ -1685,7 +1781,8 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsi= gned long long *kb) int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, getMemSwapUsage, -1, kb); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + getMemSwapUsage, -1, kb); } =20 =20 @@ -1700,7 +1797,8 @@ virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned= long long *kb) int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) { - VIR_CGROUP_BACKEND_CALL(group, setCpusetMems, -1, mems); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + setCpusetMems, -1, mems); } =20 =20 @@ -1715,7 +1813,8 @@ virCgroupSetCpusetMems(virCgroupPtr group, const char= *mems) int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) { - VIR_CGROUP_BACKEND_CALL(group, getCpusetMems, -1, mems); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + getCpusetMems, -1, mems); } =20 =20 @@ -1730,7 +1829,8 @@ virCgroupGetCpusetMems(virCgroupPtr group, char **mem= s) int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate) { - VIR_CGROUP_BACKEND_CALL(group, setCpusetMemoryMigrate, -1, migrate); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + setCpusetMemoryMigrate, -1, migrate); } =20 =20 @@ -1745,7 +1845,8 @@ virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, b= ool migrate) int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate) { - VIR_CGROUP_BACKEND_CALL(group, getCpusetMemoryMigrate, -1, migrate); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + getCpusetMemoryMigrate, -1, migrate); } =20 =20 @@ -1760,7 +1861,8 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, b= ool *migrate) int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { - VIR_CGROUP_BACKEND_CALL(group, setCpusetCpus, -1, cpus); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + setCpusetCpus, -1, cpus); } =20 =20 @@ -1775,7 +1877,8 @@ virCgroupSetCpusetCpus(virCgroupPtr group, const char= *cpus) int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) { - VIR_CGROUP_BACKEND_CALL(group, getCpusetCpus, -1, cpus); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + getCpusetCpus, -1, cpus); } =20 =20 @@ -1789,7 +1892,8 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cpu= s) int virCgroupDenyAllDevices(virCgroupPtr group) { - VIR_CGROUP_BACKEND_CALL(group, denyAllDevices, -1); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + denyAllDevices, -1); } =20 /** @@ -1809,7 +1913,8 @@ virCgroupDenyAllDevices(virCgroupPtr group) int virCgroupAllowAllDevices(virCgroupPtr group, int perms) { - VIR_CGROUP_BACKEND_CALL(group, allowAllDevices, -1, perms); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + allowAllDevices, -1, perms); } =20 =20 @@ -1828,7 +1933,8 @@ int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, type, major, minor, pe= rms); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + allowDevice, -1, type, major, minor, perms); } =20 =20 @@ -1867,7 +1973,8 @@ virCgroupAllowDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + allowDevice, -1, S_ISCHR(sb.st_mode) ? 'c' : 'b', major(sb.st_rdev), minor(sb.st_rdev), @@ -1890,7 +1997,8 @@ int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, type, major, minor, per= ms); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + denyDevice, -1, type, major, minor, perms); } =20 =20 @@ -1929,7 +2037,8 @@ virCgroupDenyDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + denyDevice, -1, S_ISCHR(sb.st_mode) ? 'c' : 'b', major(sb.st_rdev), minor(sb.st_rdev), @@ -2172,14 +2281,16 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { - VIR_CGROUP_BACKEND_CALL(group, setCpuShares, -1, shares); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + setCpuShares, -1, shares); } =20 =20 int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) { - VIR_CGROUP_BACKEND_CALL(group, getCpuShares, -1, shares); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + getCpuShares, -1, shares); } =20 =20 @@ -2194,7 +2305,8 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned lo= ng long *shares) int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { - VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + setCpuCfsPeriod, -1, cfs_period); } =20 =20 @@ -2209,7 +2321,8 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned= long long cfs_period) int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_perio= d) { - VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + getCpuCfsPeriod, -1, cfs_period); } =20 =20 @@ -2225,14 +2338,16 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsign= ed long long *cfs_period) int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { - VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + setCpuCfsQuota, -1, cfs_quota); } =20 =20 int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) { - VIR_CGROUP_BACKEND_CALL(group, getCpuacctPercpuUsage, -1, usage); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + getCpuacctPercpuUsage, -1, usage); } =20 =20 @@ -2299,7 +2414,16 @@ virCgroupRemoveRecursively(char *grppath) int virCgroupRemove(virCgroupPtr group) { - return group->backend->remove(group); + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->remove(group) < 0) { + return -1; + } + } + + return 0; } =20 =20 @@ -2308,11 +2432,16 @@ virCgroupPathOfAnyController(virCgroupPtr group, const char *name, char **keypath) { + size_t i; int controller; =20 - controller =3D group->backend->getAnyController(group); - if (controller >=3D 0) - return virCgroupPathOfController(group, controller, name, keypath); + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i]) { + controller =3D group->backends[i]->getAnyController(group); + if (controller >=3D 0) + return virCgroupPathOfController(group, controller, name, = keypath); + } + } =20 virReportSystemError(ENOSYS, "%s", _("No controllers are mounted")); @@ -2548,14 +2677,16 @@ virCgroupKillPainfully(virCgroupPtr group) int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { - VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + getCpuCfsQuota, -1, cfs_quota); } =20 =20 int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) { - VIR_CGROUP_BACKEND_CALL(group, getCpuacctUsage, -1, usage); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + getCpuacctUsage, -1, usage); } =20 =20 @@ -2563,21 +2694,24 @@ int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, unsigned long long *sys) { - VIR_CGROUP_BACKEND_CALL(group, getCpuacctStat, -1, user, sys); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + getCpuacctStat, -1, user, sys); } =20 =20 int virCgroupSetFreezerState(virCgroupPtr group, const char *state) { - VIR_CGROUP_BACKEND_CALL(group, setFreezerState, -1, state); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER, + setFreezerState, -1, state); } =20 =20 int virCgroupGetFreezerState(virCgroupPtr group, char **state) { - VIR_CGROUP_BACKEND_CALL(group, getFreezerState, -1, state); + VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER, + getFreezerState, -1, state); } =20 =20 @@ -2585,7 +2719,16 @@ int virCgroupBindMount(virCgroupPtr group, const char *oldroot, const char *mountopts) { - return group->backend->bindMount(group, oldroot, mountopts); + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->bindMount(group, oldroot, mountopts) < 0) { + return -1; + } + } + + return 0; } =20 =20 @@ -2594,7 +2737,16 @@ int virCgroupSetOwner(virCgroupPtr cgroup, gid_t gid, int controllers) { - return cgroup->backend->setOwner(cgroup, uid, gid, controllers); + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (cgroup->backends[i] && + cgroup->backends[i]->setOwner(cgroup, uid, gid, controllers) <= 0) { + return -1; + } + } + + return 0; } =20 =20 @@ -2608,13 +2760,24 @@ int virCgroupSetOwner(virCgroupPtr cgroup, bool virCgroupSupportsCpuBW(virCgroupPtr cgroup) { - VIR_CGROUP_BACKEND_CALL(cgroup, supportsCpuBW, false); + VIR_CGROUP_BACKEND_CALL(cgroup, VIR_CGROUP_CONTROLLER_CPU, + supportsCpuBW, false); } =20 int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller) { - return cgroup->backend->hasEmptyTasks(cgroup, controller); + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (cgroup->backends[i]) { + int rc =3D cgroup->backends[i]->hasEmptyTasks(cgroup, controll= er); + if (rc <=3D 0) + return rc; + } + } + + return 1; } =20 bool diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c index 7ee39ac8ca..2e90781dc3 100644 --- a/src/util/vircgroupbackend.c +++ b/src/util/vircgroupbackend.c @@ -20,6 +20,9 @@ #include =20 #include "vircgroupbackend.h" +#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ +#include "vircgrouppriv.h" +#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ #include "vircgroupv1.h" #include "vircgroupv2.h" #include "virerror.h" @@ -67,3 +70,20 @@ virCgroupBackendGetAll(void) } return virCgroupBackends; } + + +virCgroupBackendPtr +virCgroupBackendForController(virCgroupPtr group, + unsigned int controller) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->hasController(group, controller)) { + return group->backends[i]; + } + } + + return NULL; +} diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 86d1539e07..bc60b44643 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -436,12 +436,22 @@ virCgroupBackendRegister(virCgroupBackendPtr backend); virCgroupBackendPtr * virCgroupBackendGetAll(void); =20 -# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \ - if (!group->backend->func) { \ +virCgroupBackendPtr +virCgroupBackendForController(virCgroupPtr group, + unsigned int controller); + +# define VIR_CGROUP_BACKEND_CALL(group, controller, func, ret, ...) \ + virCgroupBackendPtr backend =3D virCgroupBackendForController(group, c= ontroller); \ + if (!backend) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, \ + _("failed to get cgroup backend for '%s'"), #func);= \ + return ret; \ + } \ + if (!backend->func) { \ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \ _("operation '%s' not supported"), #func); \ return ret; \ } \ - return group->backend->func(group, ##__VA_ARGS__); + return backend->func(group, ##__VA_ARGS__); =20 #endif /* __VIR_CGROUP_BACKEND_H__ */ diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 4a0d75ddbc..8f24b0891e 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -56,7 +56,7 @@ typedef virCgroupV2Controller *virCgroupV2ControllerPtr; struct _virCgroup { char *path; =20 - virCgroupBackendPtr backend; + virCgroupBackendPtr backends[VIR_CGROUP_BACKEND_TYPE_LAST]; =20 virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST]; virCgroupV2Controller unified; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469988988832.8107754922528; Tue, 2 Oct 2018 01:46:28 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id ADFAC30C6D63; Tue, 2 Oct 2018 08:46:26 +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 625B617964; Tue, 2 Oct 2018 08:46:26 +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 F130E3FCF1; Tue, 2 Oct 2018 08:46:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jQ3D031643 for ; Tue, 2 Oct 2018 04:45:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E8861001903; Tue, 2 Oct 2018 08:45:26 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 231A5100034B for ; Tue, 2 Oct 2018 08:45:25 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:27 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 43/53] vircgroupmock: change cgroup prefix X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:46:27 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Remove the trailing '/' from prefix. This change is required in order to introduce tests for unified cgroups. They are usually mounted in '/sys/fs/cgroup'. Signed-off-by: Pavel Hrdina --- tests/vircgroupmock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index cfff1f0b7a..5c48ef012a 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -56,7 +56,7 @@ const char *fakedevicedir0 =3D FAKEDEVDIR0; const char *fakedevicedir1 =3D FAKEDEVDIR1; =20 =20 -# define SYSFS_CGROUP_PREFIX "/not/really/sys/fs/cgroup/" +# define SYSFS_CGROUP_PREFIX "/not/really/sys/fs/cgroup" # define SYSFS_CPU_PRESENT "/sys/devices/system/cpu/present" # define SYSFS_CPU_PRESENT_MOCKED "devices_system_cpu_present" =20 @@ -354,7 +354,7 @@ int access(const char *path, int mode) if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); char *newpath; - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -386,7 +386,7 @@ int __lxstat(int ver, const char *path, struct stat *sb) if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); char *newpath; - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -417,7 +417,7 @@ int lstat(const char *path, struct stat *sb) if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); char *newpath; - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -448,7 +448,7 @@ int __xstat(int ver, const char *path, struct stat *sb) if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); char *newpath; - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -487,7 +487,7 @@ int stat(const char *path, struct stat *sb) } } else if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -519,7 +519,7 @@ int mkdir(const char *path, mode_t mode) if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); char *newpath; - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; @@ -552,7 +552,7 @@ int open(const char *path, int flags, ...) =20 if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) { init_sysfs(); - if (asprintf(&newpath, "%s/%s", + if (asprintf(&newpath, "%s%s", fakesysfscgroupdir, path + strlen(SYSFS_CGROUP_PREFIX)) < 0) { errno =3D ENOMEM; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469996707825.7051672418518; Tue, 2 Oct 2018 01:46:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4962CCF78; Tue, 2 Oct 2018 08:46:32 +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 EF9D354181; Tue, 2 Oct 2018 08:46:31 +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 8040D3FCF4; Tue, 2 Oct 2018 08:46:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jR84031648 for ; Tue, 2 Oct 2018 04:45:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 79859103BAB3; Tue, 2 Oct 2018 08:45:27 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF631100034B for ; Tue, 2 Oct 2018 08:45:26 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:28 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 44/53] vircgroupmock: add support to test cgroup v2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Oct 2018 08:46:35 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We need to create the cgroup v2 sysfs the same way as we do for cgroup v1. This introduces new VIR_CGROUP_MOCK_MODE env variable which will configure which cgroup mode each test requires. There are three different modes: - legacy: only cgroup v1 is available and it's the default mode - hybrid: both cgroup v1 and cgroup v2 are available and have some controllers - unified: only cgroup v2 is available Signed-off-by: Pavel Hrdina --- tests/vircgroupmock.c | 153 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 138 insertions(+), 15 deletions(-) diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index 5c48ef012a..1ed00ea91c 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -105,7 +105,8 @@ static int make_file(const char *path, return ret; } =20 -static int make_controller(const char *path, mode_t mode) + +static int make_controller_v1(const char *path, mode_t mode) { int ret =3D -1; const char *controller; @@ -231,11 +232,86 @@ static int make_controller(const char *path, mode_t m= ode) goto cleanup; } =20 +# undef MAKE_FILE + ret =3D 0; cleanup: return ret; } =20 + +static int make_controller_v2(const char *path, mode_t mode) +{ + if (!STRPREFIX(path, fakesysfscgroupdir)) { + errno =3D EINVAL; + return -1; + } + + if (real_mkdir(path, mode) < 0 && errno !=3D EEXIST) + return -1; + +# define MAKE_FILE(name, value) \ + do { \ + if (make_file(path, name, value) < 0) \ + return -1; \ + } while (0) + + MAKE_FILE("cgroup.controllers", "cpu io memory\n"); + MAKE_FILE("cgroup.subtree_control", ""); + MAKE_FILE("cgroup.type", "domain\n"); + MAKE_FILE("cpu.max", "max 100000\n"); + MAKE_FILE("cpu.stat", + "usage_usec 0\n" + "user_usec 0\n" + "system_usec 0\n" + "nr_periods 0\n" + "nr_throttled 0\n" + "throttled_usec 0\n"); + MAKE_FILE("cpu.weight", "100\n"); + MAKE_FILE("memory.current", "1455321088\n"); + MAKE_FILE("memory.high", "max\n"); + MAKE_FILE("memory.max", "max\n"); + MAKE_FILE("memory.stat", + "anon 0\n" + "file 0\n" + "kernel_stack 0\n" + "slab 0\n" + "sock 0\n" + "shmem 0\n" + "file_mapped 0\n" + "file_dirty 0\n" + "file_writeback 0\n" + "inactive_anon 0\n" + "active_anon 0\n" + "inactive_file 0\n" + "active_file 0\n" + "unevictable 0\n" + "slab_reclaimable 0\n" + "slab_unreclaimable 0\n" + "pgfault 0\n" + "pgmajfault 0\n" + "pgrefill 0\n" + "pgscan 0\n" + "pgsteal 0\n" + "pgactivate 0\n" + "pgdeactivate 0\n" + "pglazyfree 0\n" + "pglazyfreed 0\n" + "workingset_refault 0\n" + "workingset_activate 0\n" + "workingset_nodereclaim 0\n"); + MAKE_FILE("memory.swap.current", "0\n"); + MAKE_FILE("memory.swap.max", "max\n"); + MAKE_FILE("io.stat", "8:0 rbytes=3D26828800 wbytes=3D77062144 rios=3D2= 256 wios=3D7849 dbytes=3D0 dios=3D0\n"); + MAKE_FILE("io.max", ""); + MAKE_FILE("io.weight", "default 100\n"); + +# undef MAKE_FILE + + return 0; +} + + static void init_syms(void) { if (real_fopen) @@ -249,16 +325,56 @@ static void init_syms(void) VIR_MOCK_REAL_INIT(open); } =20 + +static int make_controller(const char *path, mode_t mode) +{ + const char *mock; + bool unified =3D false; + bool hybrid =3D false; + + mock =3D getenv("VIR_CGROUP_MOCK_MODE"); + if (mock) { + if (STREQ(mock, "unified")) + unified =3D true; + else if (STREQ(mock, "hybrid")) + hybrid =3D true; + } + + if (unified || (hybrid && strstr(path, "unified"))) { + return make_controller_v2(path, mode); + } else { + return make_controller_v1(path, mode); + } +} + + static void init_sysfs(void) { - if (fakerootdir && fakesysfscgroupdir) - return; + const char *mock; + char *newfakerootdir; + bool unified =3D false; + bool hybrid =3D false; =20 - if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) { + if (!(newfakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) { fprintf(stderr, "Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); abort(); } =20 + if (fakerootdir && STREQ(fakerootdir, newfakerootdir)) + return; + + fakerootdir =3D newfakerootdir; + + mock =3D getenv("VIR_CGROUP_MOCK_MODE"); + if (mock) { + if (STREQ(mock, "unified")) + unified =3D true; + else if (STREQ(mock, "hybrid")) + hybrid =3D true; + } + + VIR_FREE(fakesysfscgroupdir); + if (virAsprintfQuiet(&fakesysfscgroupdir, "%s%s", fakerootdir, SYSFS_CGROUP_PREFIX) < 0) abort(); @@ -281,18 +397,25 @@ static void init_sysfs(void) free(path); \ } while (0) =20 - MAKE_CONTROLLER("cpu"); - MAKE_CONTROLLER("cpuacct"); - MAKE_CONTROLLER("cpu,cpuacct"); - MAKE_CONTROLLER("cpu,cpuacct/system"); - MAKE_CONTROLLER("cpuset"); - MAKE_CONTROLLER("blkio"); - MAKE_CONTROLLER("memory"); - MAKE_CONTROLLER("freezer"); + if (unified) { + MAKE_CONTROLLER(""); + } else if (hybrid) { + MAKE_CONTROLLER("unified"); + MAKE_CONTROLLER("cpuset"); + MAKE_CONTROLLER("freezer"); + } else { + MAKE_CONTROLLER("cpu"); + MAKE_CONTROLLER("cpuacct"); + MAKE_CONTROLLER("cpu,cpuacct"); + MAKE_CONTROLLER("cpuset"); + MAKE_CONTROLLER("blkio"); + MAKE_CONTROLLER("memory"); + MAKE_CONTROLLER("freezer"); =20 - if (make_file(fakesysfscgroupdir, - SYSFS_CPU_PRESENT_MOCKED, "8-23,48-159\n") < 0) - abort(); + if (make_file(fakesysfscgroupdir, + SYSFS_CPU_PRESENT_MOCKED, "8-23,48-159\n") < 0) + abort(); + } } =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469985350581.16745406719; Tue, 2 Oct 2018 01:46:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id EC3BE300207D; Tue, 2 Oct 2018 08:46:22 +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 B0EAC6A231; Tue, 2 Oct 2018 08:46:22 +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 566843FCEE; Tue, 2 Oct 2018 08:46:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jSGI031662 for ; Tue, 2 Oct 2018 04:45:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 514C6103BAB3; Tue, 2 Oct 2018 08:45:28 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9009100034B for ; Tue, 2 Oct 2018 08:45:27 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:29 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 45/53] vircgrouptest: introduce initFakeFS and cleanupFakeFS helpers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Oct 2018 08:46:24 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We need to configure multiple env variables for each set of tests so create helper functions to do that. Signed-off-by: Pavel Hrdina --- tests/vircgrouptest.c | 48 ++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 4f62014ead..3e8793a6c3 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -830,10 +830,10 @@ static int testCgroupGetBlkioIoDeviceServiced(const v= oid *args ATTRIBUTE_UNUSED) =20 # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" =20 -static int -mymain(void) +static char * +initFakeFS(const char *mode, + const char *filename) { - int ret =3D 0; char *fakerootdir; =20 if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { @@ -848,6 +848,33 @@ mymain(void) =20 setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); =20 + if (mode) + setenv("VIR_CGROUP_MOCK_MODE", mode, 1); + + if (filename) + setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1); + + return fakerootdir; +} + +static void +cleanupFakeFS(char *fakerootdir) +{ + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) + virFileDeleteTree(fakerootdir); + + VIR_FREE(fakerootdir); + unsetenv("LIBVIRT_FAKE_ROOT_DIR"); + unsetenv("VIR_CGROUP_MOCK_MODE"); + unsetenv("VIR_CGROUP_MOCK_FILENAME"); +} + +static int +mymain(void) +{ + int ret =3D 0; + char *fakerootdir; + # define DETECT_MOUNTS_FULL(file, fail) \ do { \ struct _detectMountsData data =3D { file, fail }; \ @@ -871,7 +898,7 @@ mymain(void) DETECT_MOUNTS_FAIL("no-cgroups"); DETECT_MOUNTS("kubevirt"); =20 - setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1); + fakerootdir =3D initFakeFS(NULL, "systemd"); if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0) ret =3D -1; =20 @@ -907,26 +934,23 @@ mymain(void) =20 if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuSta= ts, NULL) < 0) ret =3D -1; - unsetenv("VIR_CGROUP_MOCK_FILENAME"); + cleanupFakeFS(fakerootdir); =20 - setenv("VIR_CGROUP_MOCK_FILENAME", "all-in-one", 1); + fakerootdir =3D initFakeFS(NULL, "all-in-one"); if (virTestRun("New cgroup for self (allinone)", testCgroupNewForSelfA= llInOne, NULL) < 0) ret =3D -1; if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < = 0) ret =3D -1; - unsetenv("VIR_CGROUP_MOCK_FILENAME"); + cleanupFakeFS(fakerootdir); =20 - setenv("VIR_CGROUP_MOCK_FILENAME", "logind", 1); + fakerootdir =3D initFakeFS(NULL, "logind"); if (virTestRun("New cgroup for self (logind)", testCgroupNewForSelfLog= ind, NULL) < 0) ret =3D -1; if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x0) < = 0) ret =3D -1; - unsetenv("VIR_CGROUP_MOCK_FILENAME"); + cleanupFakeFS(fakerootdir); =20 - if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) - virFileDeleteTree(fakerootdir); =20 - VIR_FREE(fakerootdir); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538470001234203.0088995270239; Tue, 2 Oct 2018 01:46:41 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 06FFA30001E6; Tue, 2 Oct 2018 08:46:39 +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 B37ED69C9D; Tue, 2 Oct 2018 08:46: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 2F2E13FCF6; Tue, 2 Oct 2018 08:46:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jTpf031689 for ; Tue, 2 Oct 2018 04:45:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D0C7103BAB3; Tue, 2 Oct 2018 08:45:29 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6842100034B for ; Tue, 2 Oct 2018 08:45:28 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:30 +0200 Message-Id: <5d51cae4ee11c98fddc239ff02daad22ac8fbc7b.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 46/53] vircgrouptest: prepare testCgroupDetectMounts for cgroup v2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 02 Oct 2018 08:46:40 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgroupdata/all-in-one.parsed | 1 + tests/vircgroupdata/cgroups1.parsed | 1 + tests/vircgroupdata/cgroups2.parsed | 1 + tests/vircgroupdata/cgroups3.parsed | 1 + tests/vircgroupdata/fedora-18.parsed | 1 + tests/vircgroupdata/fedora-21.parsed | 1 + tests/vircgroupdata/kubevirt.parsed | 1 + tests/vircgroupdata/ovirt-node-6.6.parsed | 1 + tests/vircgroupdata/ovirt-node-7.1.parsed | 1 + tests/vircgroupdata/rhel-7.1.parsed | 1 + tests/vircgrouptest.c | 2 ++ 11 files changed, 12 insertions(+) diff --git a/tests/vircgroupdata/all-in-one.parsed b/tests/vircgroupdata/al= l-in-one.parsed index d703d08fb9..97c96e8ecd 100644 --- a/tests/vircgroupdata/all-in-one.parsed +++ b/tests/vircgroupdata/all-in-one.parsed @@ -8,3 +8,4 @@ blkio /not/really/sys/fs/cgroup net_cls perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/cgroups1.parsed b/tests/vircgroupdata/cgro= ups1.parsed index b6916f17a1..16431aa006 100644 --- a/tests/vircgroupdata/cgroups1.parsed +++ b/tests/vircgroupdata/cgroups1.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/cgroups2.parsed b/tests/vircgroupdata/cgro= ups2.parsed index 5eb2bc7bb2..d1bb0dcb7c 100644 --- a/tests/vircgroupdata/cgroups2.parsed +++ b/tests/vircgroupdata/cgroups2.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/cgroups3.parsed b/tests/vircgroupdata/cgro= ups3.parsed index 2b1f3825c1..44e475c9d2 100644 --- a/tests/vircgroupdata/cgroups3.parsed +++ b/tests/vircgroupdata/cgroups3.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/fedora-18.parsed b/tests/vircgroupdata/fed= ora-18.parsed index 8d5ba75c7e..662a38a9e8 100644 --- a/tests/vircgroupdata/fedora-18.parsed +++ b/tests/vircgroupdata/fedora-18.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd /sys/fs/cgroup/systemd +unified diff --git a/tests/vircgroupdata/fedora-21.parsed b/tests/vircgroupdata/fed= ora-21.parsed index 3377af0382..4e447fd7bd 100644 --- a/tests/vircgroupdata/fedora-21.parsed +++ b/tests/vircgroupdata/fedora-21.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls,net_prio perf_event /sys/fs/cgroup/perf_event name=3Dsystemd /sys/fs/cgroup/systemd +unified diff --git a/tests/vircgroupdata/kubevirt.parsed b/tests/vircgroupdata/kube= virt.parsed index 6948707238..bf977f8363 100644 --- a/tests/vircgroupdata/kubevirt.parsed +++ b/tests/vircgroupdata/kubevirt.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/ovirt-node-6.6.parsed b/tests/vircgroupdat= a/ovirt-node-6.6.parsed index 01bf466be6..9d10813d8c 100644 --- a/tests/vircgroupdata/ovirt-node-6.6.parsed +++ b/tests/vircgroupdata/ovirt-node-6.6.parsed @@ -8,3 +8,4 @@ blkio /cgroup/blkio net_cls /cgroup/net_cls perf_event name=3Dsystemd +unified diff --git a/tests/vircgroupdata/ovirt-node-7.1.parsed b/tests/vircgroupdat= a/ovirt-node-7.1.parsed index 8d5ba75c7e..662a38a9e8 100644 --- a/tests/vircgroupdata/ovirt-node-7.1.parsed +++ b/tests/vircgroupdata/ovirt-node-7.1.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd /sys/fs/cgroup/systemd +unified diff --git a/tests/vircgroupdata/rhel-7.1.parsed b/tests/vircgroupdata/rhel= -7.1.parsed index 8d5ba75c7e..662a38a9e8 100644 --- a/tests/vircgroupdata/rhel-7.1.parsed +++ b/tests/vircgroupdata/rhel-7.1.parsed @@ -8,3 +8,4 @@ blkio /sys/fs/cgroup/blkio net_cls /sys/fs/cgroup/net_cls perf_event /sys/fs/cgroup/perf_event name=3Dsystemd /sys/fs/cgroup/systemd +unified diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 3e8793a6c3..75187216d9 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -175,6 +175,8 @@ testCgroupDetectMounts(const void *args) virCgroupControllerTypeToString(i), NULLSTR(group->legacy[i].mountPoint)); } + virBufferAsprintf(&buf, "%-12s %s\n", + "unified", NULLSTR(group->unified.mountPoint)); if (virBufferCheckError(&buf) < 0) goto cleanup; =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469972632753.0347505908953; Tue, 2 Oct 2018 01:46:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 802B7307C715; Tue, 2 Oct 2018 08:46:10 +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 3B6867B8DC; Tue, 2 Oct 2018 08:46:10 +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 C5D6F3FCDF; Tue, 2 Oct 2018 08:46:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jUcS031697 for ; Tue, 2 Oct 2018 04:45:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0CE70100194A; Tue, 2 Oct 2018 08:45:30 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82D00100034B for ; Tue, 2 Oct 2018 08:45:29 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:31 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 47/53] vircgrouptest: add detect mounts test for cgroup v2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 02 Oct 2018 08:46:11 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgroupdata/unified.cgroups | 13 +++++++++++++ tests/vircgroupdata/unified.mounts | 20 ++++++++++++++++++++ tests/vircgroupdata/unified.parsed | 11 +++++++++++ tests/vircgroupdata/unified.self.cgroup | 1 + tests/vircgrouptest.c | 3 +++ 5 files changed, 48 insertions(+) create mode 100644 tests/vircgroupdata/unified.cgroups create mode 100644 tests/vircgroupdata/unified.mounts create mode 100644 tests/vircgroupdata/unified.parsed create mode 100644 tests/vircgroupdata/unified.self.cgroup diff --git a/tests/vircgroupdata/unified.cgroups b/tests/vircgroupdata/unif= ied.cgroups new file mode 100644 index 0000000000..e0d8a3561c --- /dev/null +++ b/tests/vircgroupdata/unified.cgroups @@ -0,0 +1,13 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 0 1 1 +cpu 0 1 1 +cpuacct 0 1 1 +blkio 0 1 1 +memory 0 1 1 +devices 0 1 1 +freezer 0 1 1 +net_cls 0 1 1 +perf_event 0 1 1 +net_prio 0 1 1 +hugetlb 0 1 1 +pids 0 1 1 diff --git a/tests/vircgroupdata/unified.mounts b/tests/vircgroupdata/unifi= ed.mounts new file mode 100644 index 0000000000..b4ab94a2c3 --- /dev/null +++ b/tests/vircgroupdata/unified.mounts @@ -0,0 +1,20 @@ +sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0 +proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 +devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=3D1009844k,nr_inodes=3D2524= 61,mode=3D755 0 0 +securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime= 0 0 +tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0 +devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=3D5,mode=3D6= 20,ptmxmode=3D000 0 0 +tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=3D755 0 0 +cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,= relatime,nsdelegate 0 0 +pstore /sys/fs/pstore pstore rw,seclabel,nosuid,nodev,noexec,relatime 0 0 +bpf /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=3D700 0 0 +configfs /sys/kernel/config configfs rw,relatime 0 0 +/dev/vda2 / ext4 rw,seclabel,relatime 0 0 +selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0 +debugfs /sys/kernel/debug debugfs rw,seclabel,relatime 0 0 +hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime,pagesize=3D2M 0 0 +systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=3D40,pgrp=3D1,tim= eout=3D0,minproto=3D5,maxproto=3D5,direct,pipe_ino=3D14586 0 0 +mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 +tmpfs /tmp tmpfs rw,seclabel,nosuid,nodev 0 0 +sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0 +tmpfs /run/user/0 tmpfs rw,seclabel,nosuid,nodev,relatime,size=3D204000k,m= ode=3D700 0 0 diff --git a/tests/vircgroupdata/unified.parsed b/tests/vircgroupdata/unifi= ed.parsed new file mode 100644 index 0000000000..3de0fc643d --- /dev/null +++ b/tests/vircgroupdata/unified.parsed @@ -0,0 +1,11 @@ +cpu +cpuacct +cpuset +memory +devices +freezer +blkio +net_cls +perf_event +name=3Dsystemd +unified /not/really/sys/fs/cgroup diff --git a/tests/vircgroupdata/unified.self.cgroup b/tests/vircgroupdata/= unified.self.cgroup new file mode 100644 index 0000000000..1e027b2a3c --- /dev/null +++ b/tests/vircgroupdata/unified.self.cgroup @@ -0,0 +1 @@ +0::/ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 75187216d9..800522e311 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -899,6 +899,9 @@ mymain(void) DETECT_MOUNTS("all-in-one"); DETECT_MOUNTS_FAIL("no-cgroups"); DETECT_MOUNTS("kubevirt"); + fakerootdir =3D initFakeFS("unified", NULL); + DETECT_MOUNTS("unified"); + cleanupFakeFS(fakerootdir); =20 fakerootdir =3D initFakeFS(NULL, "systemd"); if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469980726571.9330013887695; Tue, 2 Oct 2018 01:46:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C63273082B22; Tue, 2 Oct 2018 08:46:18 +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 835C026FAD; Tue, 2 Oct 2018 08:46:18 +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 030D53FCEA; Tue, 2 Oct 2018 08:46:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jUMj031702 for ; Tue, 2 Oct 2018 04:45:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id DCF5D103BAB3; Tue, 2 Oct 2018 08:45:30 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6106D100194A for ; Tue, 2 Oct 2018 08:45:30 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:32 +0200 Message-Id: <659a324b202bd3306476f6c61481f0dce714374d.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 48/53] vircgrouptest: add detect mounts test for hybrid cgroups X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 02 Oct 2018 08:46:19 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgroupdata/hybrid.cgroups | 12 ++++++++++++ tests/vircgroupdata/hybrid.mounts | 23 +++++++++++++++++++++++ tests/vircgroupdata/hybrid.parsed | 11 +++++++++++ tests/vircgroupdata/hybrid.self.cgroup | 9 +++++++++ tests/vircgrouptest.c | 3 +++ 5 files changed, 58 insertions(+) create mode 100644 tests/vircgroupdata/hybrid.cgroups create mode 100644 tests/vircgroupdata/hybrid.mounts create mode 100644 tests/vircgroupdata/hybrid.parsed create mode 100644 tests/vircgroupdata/hybrid.self.cgroup diff --git a/tests/vircgroupdata/hybrid.cgroups b/tests/vircgroupdata/hybri= d.cgroups new file mode 100644 index 0000000000..7f3bc7b8cb --- /dev/null +++ b/tests/vircgroupdata/hybrid.cgroups @@ -0,0 +1,12 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 2 1 1 +cpu 0 1 1 +cpuacct 0 1 1 +blkio 0 1 1 +memory 0 1 1 +devices 3 1 1 +freezer 5 1 1 +net_cls 4 1 1 +perf_event 6 1 1 +hugetlb 7 1 1 +pids 8 1 1 diff --git a/tests/vircgroupdata/hybrid.mounts b/tests/vircgroupdata/hybrid= .mounts new file mode 100644 index 0000000000..d6f5f82115 --- /dev/null +++ b/tests/vircgroupdata/hybrid.mounts @@ -0,0 +1,23 @@ +proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 +sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 +devtmpfs /dev devtmpfs rw,nosuid,size=3D10240k,nr_inodes=3D502705,mode=3D7= 55 0 0 +devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=3D5,mode=3D620,ptmxmo= de=3D000 0 0 +tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0 +tmpfs /run tmpfs rw,nosuid,nodev,noexec,mode=3D755 0 0 +mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0 +securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime= 0 0 +debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0 +configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0 +fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0= 0 +selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0 +pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 +cgroup_root /not/really/sys/fs/cgroup tmpfs rw,nosuid,nodev,noexec,relatim= e,size=3D10240k,mode=3D755 0 0 +openrc /not/really/sys/fs/cgroup/openrc cgroup rw,nosuid,nodev,noexec,rela= time,release_agent=3D/lib64/rc/sh/cgroup-release-agent.sh,name=3Dopenrc 0 0 +none /not/really/sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,rela= time,nsdelegate 0 0 +cpuset /not/really/sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,rela= time,cpuset 0 0 +devices /not/really/sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,re= latime,devices 0 0 +net_cls /not/really/sys/fs/cgroup/net_cls cgroup rw,nosuid,nodev,noexec,re= latime,net_cls 0 0 +freezer /not/really/sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,re= latime,freezer 0 0 +perf_event /not/really/sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noe= xec,relatime,perf_event 0 0 +hugetlb /not/really/sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,re= latime,hugetlb 0 0 +pids /not/really/sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime= ,pids 0 0 diff --git a/tests/vircgroupdata/hybrid.parsed b/tests/vircgroupdata/hybrid= .parsed new file mode 100644 index 0000000000..7600de5f45 --- /dev/null +++ b/tests/vircgroupdata/hybrid.parsed @@ -0,0 +1,11 @@ +cpu +cpuacct +cpuset /not/really/sys/fs/cgroup/cpuset +memory +devices /not/really/sys/fs/cgroup/devices +freezer /not/really/sys/fs/cgroup/freezer +blkio +net_cls /not/really/sys/fs/cgroup/net_cls +perf_event /not/really/sys/fs/cgroup/perf_event +name=3Dsystemd +unified /not/really/sys/fs/cgroup/unified diff --git a/tests/vircgroupdata/hybrid.self.cgroup b/tests/vircgroupdata/h= ybrid.self.cgroup new file mode 100644 index 0000000000..2a08905c91 --- /dev/null +++ b/tests/vircgroupdata/hybrid.self.cgroup @@ -0,0 +1,9 @@ +8:pids:/ +7:hugetlb:/ +6:perf_event:/ +5:freezer:/ +4:net_cls:/ +3:devices:/ +2:cpuset:/ +1:name=3Dopenrc:/ +0::/ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 800522e311..e766ad7cbe 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -902,6 +902,9 @@ mymain(void) fakerootdir =3D initFakeFS("unified", NULL); DETECT_MOUNTS("unified"); cleanupFakeFS(fakerootdir); + fakerootdir =3D initFakeFS("hybrid", NULL); + DETECT_MOUNTS("hybrid"); + cleanupFakeFS(fakerootdir); =20 fakerootdir =3D initFakeFS(NULL, "systemd"); if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469990671905.2940076906342; Tue, 2 Oct 2018 01:46:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1EE080490; Tue, 2 Oct 2018 08:46:28 +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 97CCE3094647; Tue, 2 Oct 2018 08:46: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 0BAE3181D0B2; Tue, 2 Oct 2018 08:46:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jVA3031722 for ; Tue, 2 Oct 2018 04:45:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id B5CEB106224E; Tue, 2 Oct 2018 08:45:31 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A81E100194A for ; Tue, 2 Oct 2018 08:45:31 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:33 +0200 Message-Id: <243a0374df769a14fcda2e37bf8f4bd45b3bf753.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 49/53] vircgrouptest: prepare validateCgroup for cgroupv2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 02 Oct 2018 08:46:29 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgrouptest.c | 53 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index e766ad7cbe..ead5046600 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -43,7 +43,10 @@ static int validateCgroup(virCgroupPtr cgroup, const char *expectPath, const char **expectMountPoint, const char **expectLinkPoint, - const char **expectPlacement) + const char **expectPlacement, + const char *expectUnifiedMountPoint, + const char *expectUnifiedPlacement, + unsigned int expectUnifiedControllers) { size_t i; =20 @@ -80,6 +83,38 @@ static int validateCgroup(virCgroupPtr cgroup, } } =20 + if (STRNEQ_NULLABLE(expectUnifiedMountPoint, + cgroup->unified.mountPoint)) { + fprintf(stderr, "Wrong mount '%s', expected '%s' for 'unified'\n", + cgroup->unified.mountPoint, + expectUnifiedMountPoint); + return -1; + } + if (STRNEQ_NULLABLE(expectUnifiedPlacement, + cgroup->unified.placement)) { + fprintf(stderr, "Wrong placement '%s', expected '%s' for 'unified'= \n", + cgroup->unified.placement, + expectUnifiedPlacement); + return -1; + } + if (expectUnifiedControllers !=3D cgroup->unified.controllers) { + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + int type =3D 1 << i; + if ((expectUnifiedControllers & type) !=3D (cgroup->unified.co= ntrollers & type)) { + const char *typeStr =3D virCgroupControllerTypeToString(i); + if (expectUnifiedControllers & type) { + fprintf(stderr, "expected controller '%s' for 'unified= ', " + "but it's missing\n", typeStr); + } else { + fprintf(stderr, "existing controller '%s' for 'unified= ', " + "but it's not expected\n", typeStr); + } + } + + } + return -1; + } + return 0; } =20 @@ -215,7 +250,7 @@ static int testCgroupNewForSelf(const void *args ATTRIB= UTE_UNUSED) goto cleanup; } =20 - ret =3D validateCgroup(cgroup, "", mountsFull, links, placement); + ret =3D validateCgroup(cgroup, "", mountsFull, links, placement, NULL,= NULL, 0); =20 cleanup: virCgroupFree(&cgroup); @@ -294,14 +329,14 @@ static int testCgroupNewForPartition(const void *args= ATTRIBUTE_UNUSED) fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); goto cleanup; } - ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSma= ll, links, placementSmall); + ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSma= ll, links, placementSmall, NULL, NULL, 0); virCgroupFree(&cgroup); =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", true, -1, &cgrou= p)) !=3D 0) { fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); goto cleanup; } - ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsFul= l, links, placementFull); + ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsFul= l, links, placementFull, NULL, NULL, 0); =20 cleanup: virCgroupFree(&cgroup); @@ -351,7 +386,7 @@ static int testCgroupNewForPartitionNested(const void *= args ATTRIBUTE_UNUSED) } =20 ret =3D validateCgroup(cgroup, "/deployment.partition/production.parti= tion", - mountsFull, links, placementFull); + mountsFull, links, placementFull, NULL, NULL, 0); =20 cleanup: virCgroupFree(&cgroup); @@ -407,7 +442,7 @@ static int testCgroupNewForPartitionNestedDeep(const vo= id *args ATTRIBUTE_UNUSED } =20 ret =3D validateCgroup(cgroup, "/user/berrange.user/production.partiti= on", - mountsFull, links, placementFull); + mountsFull, links, placementFull, NULL, NULL, 0); =20 cleanup: virCgroupFree(&cgroup); @@ -443,7 +478,7 @@ static int testCgroupNewForPartitionDomain(const void *= args ATTRIBUTE_UNUSED) goto cleanup; } =20 - ret =3D validateCgroup(domaincgroup, "/production.partition/foo.libvir= t-lxc", mountsFull, links, placement); + ret =3D validateCgroup(domaincgroup, "/production.partition/foo.libvir= t-lxc", mountsFull, links, placement, NULL, NULL, 0); =20 cleanup: virCgroupFree(&partitioncgroup); @@ -494,7 +529,7 @@ static int testCgroupNewForPartitionDomainEscaped(const= void *args ATTRIBUTE_UNU * since our fake /proc/cgroups pretends this controller * isn't compiled into the kernel */ - ret =3D validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evi= l.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement); + ret =3D validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evi= l.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0); =20 cleanup: virCgroupFree(&partitioncgroup3); @@ -523,7 +558,7 @@ static int testCgroupNewForSelfAllInOne(const void *arg= s ATTRIBUTE_UNUSED) goto cleanup; } =20 - ret =3D validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, plac= ement); + ret =3D validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, plac= ement, NULL, NULL, 0); =20 cleanup: virCgroupFree(&cgroup); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153847001235990.77710011238617; Tue, 2 Oct 2018 01:46:52 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E90C930B24DD; Tue, 2 Oct 2018 08:46:49 +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 56FB6108418A; Tue, 2 Oct 2018 08:46:46 +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 82145181A12F; Tue, 2 Oct 2018 08:46:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jWfF031740 for ; Tue, 2 Oct 2018 04:45:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 932EA1062250; Tue, 2 Oct 2018 08:45:32 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14C6E106224F for ; Tue, 2 Oct 2018 08:45:31 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:34 +0200 Message-Id: <2b3811181d8cc0ed5d97859d7ebed4b26e49d0f3.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 50/53] vircgrouptest: add cgroup v2 tests X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 02 Oct 2018 08:46:51 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgrouptest.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index ead5046600..fe0cb9585a 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -567,16 +567,37 @@ static int testCgroupNewForSelfAllInOne(const void *a= rgs ATTRIBUTE_UNUSED) =20 =20 static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED) +{ + virCgroupPtr cgroup =3D NULL; + + if (virCgroupNewSelf(&cgroup) >=3D 0) { + fprintf(stderr, "Expected to fail, only systemd cgroup available.\= n"); + virCgroupFree(&cgroup); + return -1; + } + + return 0; +} + + +static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_UNUSED) { virCgroupPtr cgroup =3D NULL; int ret =3D -1; + const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; + unsigned int controllers =3D + (1 << VIR_CGROUP_CONTROLLER_CPU) | + (1 << VIR_CGROUP_CONTROLLER_CPUACCT) | + (1 << VIR_CGROUP_CONTROLLER_MEMORY) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO); =20 - if (virCgroupNewSelf(&cgroup) =3D=3D 0) { - fprintf(stderr, "Expected cgroup creation to fail.\n"); + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); goto cleanup; } =20 - ret =3D 0; + ret =3D validateCgroup(cgroup, "", empty, empty, empty, + "/not/really/sys/fs/cgroup", "/", controllers); cleanup: virCgroupFree(&cgroup); return ret; @@ -993,7 +1014,14 @@ mymain(void) ret =3D -1; cleanupFakeFS(fakerootdir); =20 + /* cgroup unified */ =20 + fakerootdir =3D initFakeFS("unified", "unified"); + if (virTestRun("New cgroup for self (unified)", testCgroupNewForSelfUn= ified, NULL) < 0) + ret =3D -1; + if (virTestRun("Cgroup available (unified)", testCgroupAvailable, (voi= d*)0x1) < 0) + ret =3D -1; + cleanupFakeFS(fakerootdir); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469988311615.9796652136195; Tue, 2 Oct 2018 01:46:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3718630C6D68; Tue, 2 Oct 2018 08:46:26 +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 D63213091380; Tue, 2 Oct 2018 08:46:25 +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 4EC89181AC20; Tue, 2 Oct 2018 08:46:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jXs2031757 for ; Tue, 2 Oct 2018 04:45:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6D8C5100194A; Tue, 2 Oct 2018 08:45:33 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E42D9103BAB3 for ; Tue, 2 Oct 2018 08:45:32 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:35 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 51/53] vircgrouptest: add hybrid tests X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 02 Oct 2018 08:46:27 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgrouptest.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index fe0cb9585a..8fcee21bb2 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -604,6 +604,45 @@ static int testCgroupNewForSelfUnified(const void *arg= s ATTRIBUTE_UNUSED) } =20 =20 +static int testCgroupNewForSelfHybrid(const void *args ATTRIBUTE_UNUSED) +{ + virCgroupPtr cgroup =3D NULL; + int ret =3D -1; + const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; + const char *mounts[VIR_CGROUP_CONTROLLER_LAST] =3D { + [VIR_CGROUP_CONTROLLER_CPUSET] =3D "/not/really/sys/fs/cgroup/cpus= et", + [VIR_CGROUP_CONTROLLER_DEVICES] =3D "/not/really/sys/fs/cgroup/dev= ices", + [VIR_CGROUP_CONTROLLER_FREEZER] =3D "/not/really/sys/fs/cgroup/fre= ezer", + [VIR_CGROUP_CONTROLLER_NET_CLS] =3D "/not/really/sys/fs/cgroup/net= _cls", + [VIR_CGROUP_CONTROLLER_PERF_EVENT] =3D "/not/really/sys/fs/cgroup/= perf_event", + }; + const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { + [VIR_CGROUP_CONTROLLER_CPUSET] =3D "/", + [VIR_CGROUP_CONTROLLER_DEVICES] =3D "/", + [VIR_CGROUP_CONTROLLER_FREEZER] =3D "/", + [VIR_CGROUP_CONTROLLER_NET_CLS] =3D "/", + [VIR_CGROUP_CONTROLLER_PERF_EVENT] =3D "/", + }; + unsigned int controllers =3D + (1 << VIR_CGROUP_CONTROLLER_CPU) | + (1 << VIR_CGROUP_CONTROLLER_CPUACCT) | + (1 << VIR_CGROUP_CONTROLLER_MEMORY) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO); + + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); + goto cleanup; + } + + ret =3D validateCgroup(cgroup, "", mounts, empty, placement, + "/not/really/sys/fs/cgroup/unified", "/", control= lers); + + cleanup: + virCgroupFree(&cgroup); + return ret; +} + + static int testCgroupAvailable(const void *args) { bool got =3D virCgroupAvailable(); @@ -1023,6 +1062,15 @@ mymain(void) ret =3D -1; cleanupFakeFS(fakerootdir); =20 + /* cgroup hybrid */ + + fakerootdir =3D initFakeFS("hybrid", "hybrid"); + if (virTestRun("New cgroup for self (hybrid)", testCgroupNewForSelfHyb= rid, NULL) < 0) + ret =3D -1; + if (virTestRun("Cgroup available (hybrid)", testCgroupAvailable, (void= *)0x1) < 0) + ret =3D -1; + cleanupFakeFS(fakerootdir); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469997524890.0372004915997; Tue, 2 Oct 2018 01:46:37 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A001C7F3EC; Tue, 2 Oct 2018 08:46:34 +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 625723DE5; Tue, 2 Oct 2018 08:46:34 +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 E801D181D0B8; Tue, 2 Oct 2018 08:46:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jY9j031771 for ; Tue, 2 Oct 2018 04:45:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4B3FA103BAB3; Tue, 2 Oct 2018 08:45:34 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1AB6100194A for ; Tue, 2 Oct 2018 08:45:33 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:36 +0200 Message-Id: <35fae869ae214e2cb6cd87b8fe5a122a449506c0.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 52/53] virt-host-validate: rewrite cgroup detection to use util/vircgroup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 02 Oct 2018 08:46:36 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This removes code duplication and simplifies cgroup detection. As a drawback we will not have separate messages to enable cgroup controller in kernel or to mount it. On the other side the rewrite adds support for cgroup v2. The kernel config support was wrong because it was parsing '/proc/self/cgroup' instead of '/proc/cgroups/' file. The mount suggestion is removed as well because it will not work with cgroup v2. Signed-off-by: Pavel Hrdina --- tools/virt-host-validate-common.c | 162 ++++++------------------------ tools/virt-host-validate-common.h | 7 +- tools/virt-host-validate-lxc.c | 40 ++------ tools/virt-host-validate-qemu.c | 40 ++------ 4 files changed, 54 insertions(+), 195 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index ccbd764c84..4e70fe9e9c 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -24,12 +24,10 @@ #include #include #include -#ifdef HAVE_MNTENT_H -# include -#endif /* HAVE_MNTENT_H */ #include =20 #include "viralloc.h" +#include "vircgroup.h" #include "virfile.h" #include "virt-host-validate-common.h" #include "virstring.h" @@ -288,152 +286,50 @@ int virHostValidateLinuxKernel(const char *hvname, } } =20 - -static int virHostValidateCGroupSupport(const char *hvname, - const char *cg_name, - virHostValidateLevel level, - const char *config_name) -{ - virHostMsgCheck(hvname, "for cgroup '%s' controller support", cg_name); - FILE *fp =3D fopen("/proc/self/cgroup", "r"); - size_t len =3D 0; - char *line =3D NULL; - ssize_t ret; - bool matched =3D false; - - if (!fp) - goto error; - - while ((ret =3D getline(&line, &len, fp)) >=3D 0 && !matched) { - char **cgroups; - char *start; - char *end; - size_t ncgroups; - size_t i; - - /* Each line in this file looks like - * - * 4:cpu,cpuacct:/machine.slice/machine-qemu\x2dtest.scope/emula= tor - * - * Since multiple cgroups can be part of the same line and some cg= roup - * names can appear as part of other cgroup names (eg. 'cpu' is a - * prefix for both 'cpuacct' and 'cpuset'), it's not enough to sim= ply - * check whether the cgroup name is present somewhere inside the f= ile. - * - * Moreover, there's nothing stopping the cgroup name from appeari= ng - * in an unrelated mount point name as well */ - - /* Look for the first colon. - * The part we're interested in starts right after it */ - if (!(start =3D strchr(line, ':'))) - continue; - start++; - - /* Look for the second colon. - * The part we're interested in ends exactly there */ - if (!(end =3D strchr(start, ':'))) - continue; - *end =3D '\0'; - - if (!(cgroups =3D virStringSplitCount(start, ",", 0, &ncgroups))) - continue; - - /* Look for the matching cgroup */ - for (i =3D 0; i < ncgroups; i++) { - if (STREQ(cgroups[i], cg_name)) - matched =3D true; - } - - virStringListFreeCount(cgroups, ncgroups); - } - - VIR_FREE(line); - VIR_FORCE_FCLOSE(fp); - if (!matched) - goto error; - - virHostMsgPass(); - return 0; - - error: - VIR_FREE(line); - virHostMsgFail(level, "Enable CONFIG_%s in kernel Kconfig file", confi= g_name); - return -1; -} - -#ifdef HAVE_MNTENT_H -static int virHostValidateCGroupMount(const char *hvname, - const char *cg_name, - virHostValidateLevel level) +#ifdef __linux__ +int virHostValidateCGroupControllers(const char *hvname, + int controllers, + virHostValidateLevel level) { - virHostMsgCheck(hvname, "for cgroup '%s' controller mount-point", cg_n= ame); - FILE *fp =3D setmntent("/proc/mounts", "r"); - struct mntent ent; - char mntbuf[1024]; - bool matched =3D false; + virCgroupPtr group =3D NULL; + int ret =3D 0; + size_t i; =20 - if (!fp) - goto error; + if (virCgroupNewSelf(&group) < 0) + return -1; =20 - while (getmntent_r(fp, &ent, mntbuf, sizeof(mntbuf)) && !matched) { - char **opts; - size_t nopts; - size_t i; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + int flag =3D 1 << i; + const char *cg_name =3D virCgroupControllerTypeToString(i); =20 - /* Ignore non-cgroup mounts */ - if (STRNEQ(ent.mnt_type, "cgroup")) + if (!(controllers & flag)) continue; =20 - if (!(opts =3D virStringSplitCount(ent.mnt_opts, ",", 0, &nopts))) - continue; + virHostMsgCheck(hvname, "for cgroup '%s' controller support", cg_n= ame); =20 - /* Look for a mount option matching the cgroup name */ - for (i =3D 0; i < nopts; i++) { - if (STREQ(opts[i], cg_name)) - matched =3D true; + if (!virCgroupHasController(group, i)) { + ret =3D -1; + virHostMsgFail(level, "Enable '%s' in kernel Kconfig file or " + "mount/enable cgroup controller in your system", + cg_name); + } else { + virHostMsgPass(); } - - virStringListFreeCount(opts, nopts); } - endmntent(fp); - if (!matched) - goto error; =20 - virHostMsgPass(); - return 0; + virCgroupFree(&group); =20 - error: - virHostMsgFail(level, "Mount '%s' cgroup controller (suggested at /sys= /fs/cgroup/%s)", - cg_name, cg_name); - return -1; + return ret; } -#else /* ! HAVE_MNTENT_H */ -static int virHostValidateCGroupMount(const char *hvname, - const char *cg_name, - virHostValidateLevel level) +#else /* !__linux__ */ +int virHostValidateCGroupControllers(const char *hvname, + int controllers, + virHostValidateLevel level) { - virHostMsgCheck(hvname, "for cgroup '%s' controller mount-point", cg_n= ame); virHostMsgFail(level, "%s", "This platform does not support cgroups"); return -1; } -#endif /* ! HAVE_MNTENT_H */ - -int virHostValidateCGroupController(const char *hvname, - const char *cg_name, - virHostValidateLevel level, - const char *config_name) -{ - if (virHostValidateCGroupSupport(hvname, - cg_name, - level, - config_name) < 0) - return -1; - if (virHostValidateCGroupMount(hvname, - cg_name, - level) < 0) - return -1; - return 0; -} +#endif /* !__linux__ */ =20 int virHostValidateIOMMU(const char *hvname, virHostValidateLevel level) diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-c= ommon.h index b6fe17daa7..b23dd7cdbe 100644 --- a/tools/virt-host-validate-common.h +++ b/tools/virt-host-validate-common.h @@ -77,10 +77,9 @@ int virHostValidateNamespace(const char *hvname, virHostValidateLevel level, const char *hint); =20 -int virHostValidateCGroupController(const char *hvname, - const char *cg_name, - virHostValidateLevel level, - const char *config_name); +int virHostValidateCGroupControllers(const char *hvname, + int controllers, + virHostValidateLevel level); =20 int virHostValidateIOMMU(const char *hvname, virHostValidateLevel level); diff --git a/tools/virt-host-validate-lxc.c b/tools/virt-host-validate-lxc.c index 64d9279c30..3c55b1b26d 100644 --- a/tools/virt-host-validate-lxc.c +++ b/tools/virt-host-validate-lxc.c @@ -23,6 +23,7 @@ =20 #include "virt-host-validate-lxc.h" #include "virt-host-validate-common.h" +#include "vircgroup.h" =20 int virHostValidateLXC(void) { @@ -63,35 +64,16 @@ int virHostValidateLXC(void) _("User namespace support is recommended"= )) < 0) ret =3D -1; =20 - if (virHostValidateCGroupController("LXC", "memory", - VIR_HOST_VALIDATE_FAIL, - "MEMCG") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("LXC", "cpu", - VIR_HOST_VALIDATE_FAIL, - "CGROUP_CPU") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("LXC", "cpuacct", - VIR_HOST_VALIDATE_FAIL, - "CGROUP_CPUACCT") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("LXC", "cpuset", - VIR_HOST_VALIDATE_FAIL, - "CPUSETS") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("LXC", "devices", - VIR_HOST_VALIDATE_FAIL, - "CGROUP_DEVICE") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("LXC", "blkio", - VIR_HOST_VALIDATE_FAIL, - "BLK_CGROUP") < 0) - ret =3D -1; + if (virHostValidateCGroupControllers("LXC", + (1 << VIR_CGROUP_CONTROLLER_MEMOR= Y) | + (1 << VIR_CGROUP_CONTROLLER_CPU) | + (1 << VIR_CGROUP_CONTROLLER_CPUAC= CT) | + (1 << VIR_CGROUP_CONTROLLER_CPUSE= T) | + (1 << VIR_CGROUP_CONTROLLER_DEVIC= ES) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO= ), + VIR_HOST_VALIDATE_FAIL) < 0) { + ret =3D -1; + } =20 #if WITH_FUSE if (virHostValidateDeviceExists("LXC", "/sys/fs/fuse/connections", diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qem= u.c index d7573ea8b3..ff3c1f0231 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -26,6 +26,7 @@ #include "virt-host-validate-common.h" #include "virarch.h" #include "virbitmap.h" +#include "vircgroup.h" =20 int virHostValidateQEMU(void) { @@ -96,35 +97,16 @@ int virHostValidateQEMU(void) _("Load the 'tun' module to enable net= working for QEMU guests")) < 0) ret =3D -1; =20 - if (virHostValidateCGroupController("QEMU", "memory", - VIR_HOST_VALIDATE_WARN, - "MEMCG") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("QEMU", "cpu", - VIR_HOST_VALIDATE_WARN, - "CGROUP_CPU") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("QEMU", "cpuacct", - VIR_HOST_VALIDATE_WARN, - "CGROUP_CPUACCT") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("QEMU", "cpuset", - VIR_HOST_VALIDATE_WARN, - "CPUSETS") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("QEMU", "devices", - VIR_HOST_VALIDATE_WARN, - "CGROUP_DEVICES") < 0) - ret =3D -1; - - if (virHostValidateCGroupController("QEMU", "blkio", - VIR_HOST_VALIDATE_WARN, - "BLK_CGROUP") < 0) - ret =3D -1; + if (virHostValidateCGroupControllers("QEMU", + (1 << VIR_CGROUP_CONTROLLER_MEMOR= Y) | + (1 << VIR_CGROUP_CONTROLLER_CPU) | + (1 << VIR_CGROUP_CONTROLLER_CPUAC= CT) | + (1 << VIR_CGROUP_CONTROLLER_CPUSE= T) | + (1 << VIR_CGROUP_CONTROLLER_DEVIC= ES) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO= ), + VIR_HOST_VALIDATE_WARN) < 0) { + ret =3D -1; + } =20 if (virHostValidateIOMMU("QEMU", VIR_HOST_VALIDATE_WARN) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 13 10:40:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538470003207305.1803742423941; Tue, 2 Oct 2018 01:46:43 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3786CC070148; Tue, 2 Oct 2018 08:46:40 +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 D7F8E7981A; Tue, 2 Oct 2018 08:46:39 +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 5527C181D0BA; Tue, 2 Oct 2018 08:46:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jZKE031790 for ; Tue, 2 Oct 2018 04:45:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27C631062252; Tue, 2 Oct 2018 08:45:35 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E694100194A for ; Tue, 2 Oct 2018 08:45:34 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:37 +0200 Message-Id: <29f67fc56c434b33171e6ae2a1251eb929f7b7a4.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 53/53] virt-host-validate: require freezer for LXC X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 02 Oct 2018 08:46:42 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cgroup freezer support for LXC was added in libvirt-0.7.2. Signed-off-by: Pavel Hrdina --- tools/virt-host-validate-lxc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virt-host-validate-lxc.c b/tools/virt-host-validate-lxc.c index 3c55b1b26d..8613f37cc7 100644 --- a/tools/virt-host-validate-lxc.c +++ b/tools/virt-host-validate-lxc.c @@ -70,6 +70,7 @@ int virHostValidateLXC(void) (1 << VIR_CGROUP_CONTROLLER_CPUAC= CT) | (1 << VIR_CGROUP_CONTROLLER_CPUSE= T) | (1 << VIR_CGROUP_CONTROLLER_DEVIC= ES) | + (1 << VIR_CGROUP_CONTROLLER_FREEZ= ER) | (1 << VIR_CGROUP_CONTROLLER_BLKIO= ), VIR_HOST_VALIDATE_FAIL) < 0) { ret =3D -1; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list