From nobody Thu May 2 13:52:21 2024 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 1537433686213253.45546726801967; Thu, 20 Sep 2018 01:54:46 -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 4001B8CDD; Thu, 20 Sep 2018 08:54:44 +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 0C6C2308BDA4; Thu, 20 Sep 2018 08:54:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B0B90181A12F; Thu, 20 Sep 2018 08:54:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8sgV6002103 for ; Thu, 20 Sep 2018 04:54:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8269D808C7; Thu, 20 Sep 2018 08:54:42 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id F401D60851 for ; Thu, 20 Sep 2018 08:54:41 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:30 +0200 Message-Id: <9c343c52e366e9cd2dbcb329360dfc90598c83b9.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/9] vircgroup: cleanup controllers not managed by systemd on error 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: , Content-Type: text/plain; charset="utf-8" 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.38]); Thu, 20 Sep 2018 08:54:44 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 If virCgroupEnableMissingControllers() fails it could already create some directories, we should clean it up as well. Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index c825f7c77e..f9e387c86d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1551,6 +1551,7 @@ virCgroupNewMachineSystemd(const char *name, int rv; virCgroupPtr init; VIR_AUTOFREE(char *) path =3D NULL; + virErrorPtr saved =3D NULL; =20 VIR_DEBUG("Trying to setup machine '%s' via systemd", name); if ((rv =3D virSystemdCreateMachine(name, @@ -1584,20 +1585,24 @@ virCgroupNewMachineSystemd(const char *name, =20 if (virCgroupEnableMissingControllers(path, pidleader, controllers, group) < 0) { - return -1; + goto error; } =20 - if (virCgroupAddTask(*group, pidleader) < 0) { - virErrorPtr saved =3D virSaveLastError(); - virCgroupRemove(*group); - virCgroupFree(group); - if (saved) { - virSetError(saved); - virFreeError(saved); - } - } + if (virCgroupAddTask(*group, pidleader) < 0) + goto error; =20 return 0; + + error: + saved =3D virSaveLastError(); + virCgroupRemove(*group); + virCgroupFree(group); + if (saved) { + virSetError(saved); + virFreeError(saved); + } + + return -1; } =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 153743368934853.104904926171685; Thu, 20 Sep 2018 01:54:49 -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 689F46B; Thu, 20 Sep 2018 08:54: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 2E8227EA2D; Thu, 20 Sep 2018 08:54: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 D38E64BB75; Thu, 20 Sep 2018 08:54:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8shIv002116 for ; Thu, 20 Sep 2018 04:54:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 571B317DD7; Thu, 20 Sep 2018 08:54:43 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE51460851 for ; Thu, 20 Sep 2018 08:54:42 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:31 +0200 Message-Id: <2b0a72aea97b78def036b450e79a5d2859a3e266.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/9] vircgroup: fix bug in virCgroupEnableMissingControllers 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: , Content-Type: text/plain; charset="utf-8" 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]); Thu, 20 Sep 2018 08:54:48 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 If we are on host with systemd we need to build cgroup hierarchy ourselves for controllers that are not managed by systemd. As a starting parent we need to force root group because virCgroupMakeGroup() takes that parent in order to inherit values for cpuset controller. By default cpuset controller is managed by systemd so we will never hit the issue but for v2 cgroups we need to use parent cgroup every time. Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f9e387c86d..13f5e0d83a 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1491,7 +1491,7 @@ virCgroupEnableMissingControllers(char *path, int ret =3D -1; =20 if (virCgroupNew(pidleader, - "", + "/", NULL, controllers, &parent) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433691088705.3983138908605; Thu, 20 Sep 2018 01:54:51 -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 16FC2308421C; Thu, 20 Sep 2018 08:54: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 D06317EBD8; Thu, 20 Sep 2018 08:54:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 89545181A13B; Thu, 20 Sep 2018 08:54:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8siCc002121 for ; Thu, 20 Sep 2018 04:54:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FF9460851; Thu, 20 Sep 2018 08:54:44 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6099808CB for ; Thu, 20 Sep 2018 08:54:43 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:32 +0200 Message-Id: <4663494c913aa6b055ae4bfebafbabd86a75843c.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/9] vircgroup: rename virCgroupAdd.*Task to virCgroupAdd.*Process 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: , Content-Type: text/plain; charset="utf-8" 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.40]); Thu, 20 Sep 2018 08:54:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 In cgroup v2 we need to handle processes and threads differently, following patch will introduce virCgroupAddThread. Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/libvirt-lxc.c | 2 +- src/libvirt_private.syms | 4 ++-- src/lxc/lxc_controller.c | 4 ++-- src/qemu/qemu_process.c | 4 ++-- src/qemu/qemu_tpm.c | 2 +- src/util/vircgroup.c | 32 ++++++++++++++++---------------- src/util/vircgroup.h | 4 ++-- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index c9f2146487..9bf0174b95 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -306,7 +306,7 @@ int virDomainLxcEnterCGroup(virDomainPtr domain, if (virCgroupNewDetect(domain->id, -1, &cgroup) < 0) goto error; =20 - if (virCgroupAddTask(cgroup, getpid()) < 0) + if (virCgroupAddProcess(cgroup, getpid()) < 0) goto error; =20 virCgroupFree(&cgroup); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b9dabfef1b..eac66b0174 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1498,8 +1498,8 @@ virBufferVasprintf; =20 =20 # util/vircgroup.h -virCgroupAddMachineTask; -virCgroupAddTask; +virCgroupAddMachineProcess; +virCgroupAddProcess; virCgroupAllowAllDevices; virCgroupAllowDevice; virCgroupAllowDevicePath; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index d81c8e946d..62dfd09473 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -874,12 +874,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCCo= ntrollerPtr ctrl) ctrl->nicindexes))) goto cleanup; =20 - if (virCgroupAddMachineTask(ctrl->cgroup, getpid()) < 0) + if (virCgroupAddMachineProcess(ctrl->cgroup, getpid()) < 0) goto cleanup; =20 /* Add all qemu-nbd tasks to the cgroup */ for (i =3D 0; i < ctrl->nnbdpids; i++) { - if (virCgroupAddMachineTask(ctrl->cgroup, ctrl->nbdpids[i]) < 0) + if (virCgroupAddMachineProcess(ctrl->cgroup, ctrl->nbdpids[i]) < 0) goto cleanup; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 72a59dec55..249dac39f2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2549,7 +2549,7 @@ qemuProcessSetupPid(virDomainObjPtr vm, goto cleanup; =20 /* Move the thread to the sub dir */ - if (virCgroupAddTask(cgroup, pid) < 0) + if (virCgroupAddProcess(cgroup, pid) < 0) goto cleanup; =20 } @@ -2787,7 +2787,7 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm) } =20 if (priv->cgroup && - virCgroupAddMachineTask(priv->cgroup, cpid) < 0) + virCgroupAddMachineProcess(priv->cgroup, cpid) < 0) goto cleanup; =20 if (qemuSecurityDomainSetPathLabel(driver, vm, socketPath, true) < 0) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 278b262c48..c64114feac 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -905,7 +905,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, _("Could not get process id of swtpm")); goto cleanup; } - if (virCgroupAddTask(cgroup, pid) < 0) + if (virCgroupAddProcess(cgroup, pid) < 0) goto cleanup; break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 13f5e0d83a..30ffb658d9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1179,35 +1179,35 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t = pid, bool withSystemd) } =20 /** - * virCgroupAddTask: + * virCgroupAddProcess: * - * @group: The cgroup to add a task to - * @pid: The pid of the task to add + * @group: The cgroup to add a process to + * @pid: The pid of the process to add * - * Will add the task to all controllers, except the + * Will add the process to all controllers, except the * systemd unit controller. * * Returns: 0 on success, -1 on error */ int -virCgroupAddTask(virCgroupPtr group, pid_t pid) +virCgroupAddProcess(virCgroupPtr group, pid_t pid) { return virCgroupAddTaskInternal(group, pid, false); } =20 /** - * virCgroupAddMachineTask: + * virCgroupAddMachineProcess: * - * @group: The cgroup to add a task to - * @pid: The pid of the task to add + * @group: The cgroup to add a process to + * @pid: The pid of the process to add * - * Will add the task to all controllers, including the + * Will add the process to all controllers, including the * systemd unit controller. * * Returns: 0 on success, -1 on error */ int -virCgroupAddMachineTask(virCgroupPtr group, pid_t pid) +virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid) { return virCgroupAddTaskInternal(group, pid, true); } @@ -1588,7 +1588,7 @@ virCgroupNewMachineSystemd(const char *name, goto error; } =20 - if (virCgroupAddTask(*group, pidleader) < 0) + if (virCgroupAddProcess(*group, pidleader) < 0) goto error; =20 return 0; @@ -1644,7 +1644,7 @@ virCgroupNewMachineManual(const char *name, group) < 0) goto cleanup; =20 - if (virCgroupAddTask(*group, pidleader) < 0) { + if (virCgroupAddProcess(*group, pidleader) < 0) { virErrorPtr saved =3D virSaveLastError(); virCgroupRemove(*group); virCgroupFree(group); @@ -4194,8 +4194,8 @@ virCgroupPathOfController(virCgroupPtr group ATTRIBUT= E_UNUSED, =20 =20 int -virCgroupAddTask(virCgroupPtr group ATTRIBUTE_UNUSED, - pid_t pid ATTRIBUTE_UNUSED) +virCgroupAddProcess(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform"= )); @@ -4204,8 +4204,8 @@ virCgroupAddTask(virCgroupPtr group ATTRIBUTE_UNUSED, =20 =20 int -virCgroupAddMachineTask(virCgroupPtr group ATTRIBUTE_UNUSED, - pid_t pid ATTRIBUTE_UNUSED) +virCgroupAddMachineProcess(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform"= )); diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index ee3b7c7222..bbd4c2ed57 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -118,8 +118,8 @@ int virCgroupPathOfController(virCgroupPtr group, const char *key, char **path); =20 -int virCgroupAddTask(virCgroupPtr group, pid_t pid); -int virCgroupAddMachineTask(virCgroupPtr group, pid_t pid); +int virCgroupAddProcess(virCgroupPtr group, pid_t pid); +int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid); =20 int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight); int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433693320306.17982745887014; Thu, 20 Sep 2018 01:54:53 -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 8F5CD6599B; Thu, 20 Sep 2018 08:54:51 +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 5C34D7FB7E; Thu, 20 Sep 2018 08:54: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 075DE4A464; Thu, 20 Sep 2018 08:54:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8sjaf002132 for ; Thu, 20 Sep 2018 04:54:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08099808C7; Thu, 20 Sep 2018 08:54:45 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E70B60851 for ; Thu, 20 Sep 2018 08:54:44 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:33 +0200 Message-Id: <2c4fb7437dd901c56d34ef3fbb9b686541867ed1.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/9] vircgroup: introduce virCgroupTaskFlags 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.38]); Thu, 20 Sep 2018 08:54:52 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use flags in virCgroupAddTaskInternal instead of boolean parameter. Following patch will add new flag to indicate thread instead of process. Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- Notes: changes in v2: - added comments for new flags src/util/vircgroup.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 30ffb658d9..490cbc03a0 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1152,8 +1152,21 @@ virCgroupNew(pid_t pid, } =20 =20 +typedef enum { + /* Adds a whole process with all threads to specific cgroup except + * to systemd named controller. */ + VIR_CGROUP_TASK_PROCESS =3D 0, + + /* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd + * named controller. */ + VIR_CGROUP_TASK_SYSTEMD =3D 1 << 0, +} virCgroupTaskFlags; + + static int -virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd) +virCgroupAddTaskInternal(virCgroupPtr group, + pid_t pid, + unsigned int flags) { int ret =3D -1; size_t i; @@ -1166,7 +1179,8 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pi= d, bool withSystemd) /* We must never add tasks in systemd's hierarchy * unless we're intentionally trying to move a * task into a systemd machine scope */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD && !withSystemd) + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD && + !(flags & VIR_CGROUP_TASK_SYSTEMD)) continue; =20 if (virCgroupSetValueI64(group, i, "tasks", pid) < 0) @@ -1192,7 +1206,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pi= d, bool withSystemd) int virCgroupAddProcess(virCgroupPtr group, pid_t pid) { - return virCgroupAddTaskInternal(group, pid, false); + return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS); } =20 /** @@ -1209,7 +1223,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid) int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid) { - return virCgroupAddTaskInternal(group, pid, true); + return virCgroupAddTaskInternal(group, pid, + VIR_CGROUP_TASK_PROCESS | + VIR_CGROUP_TASK_SYSTEMD); } =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433697533468.73551769363496; Thu, 20 Sep 2018 01:54:57 -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 BBBEECD193; Thu, 20 Sep 2018 08:54:55 +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 8A87C2010CF7; Thu, 20 Sep 2018 08:54: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 3B26F4A46D; Thu, 20 Sep 2018 08:54:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8sja6002137 for ; Thu, 20 Sep 2018 04:54:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id D203A60851; Thu, 20 Sep 2018 08:54:45 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5563C17DD7 for ; Thu, 20 Sep 2018 08:54:45 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:34 +0200 Message-Id: <763b66288943134bb4bc397596c05f5d5e2dae54.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/9] vircgroup: introduce virCgroupAddThread 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.38]); Thu, 20 Sep 2018 08:54:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Once we introduce cgroup v2 support we need to handle processes and threads differently. Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- Notes: changes in v2: - added comment for new flag src/libvirt_private.syms | 1 + src/qemu/qemu_process.c | 2 +- src/util/vircgroup.c | 32 ++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index eac66b0174..ad7ce57b65 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1500,6 +1500,7 @@ virBufferVasprintf; # util/vircgroup.h virCgroupAddMachineProcess; virCgroupAddProcess; +virCgroupAddThread; virCgroupAllowAllDevices; virCgroupAllowDevice; virCgroupAllowDevicePath; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 249dac39f2..00dcd5b580 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2549,7 +2549,7 @@ qemuProcessSetupPid(virDomainObjPtr vm, goto cleanup; =20 /* Move the thread to the sub dir */ - if (virCgroupAddProcess(cgroup, pid) < 0) + if (virCgroupAddThread(cgroup, pid) < 0) goto cleanup; =20 } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 490cbc03a0..ea83c5f5b2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1160,6 +1160,10 @@ typedef enum { /* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd * named controller. */ VIR_CGROUP_TASK_SYSTEMD =3D 1 << 0, + + /* Moves only specific thread into cgroup except to systemd + * named controller. */ + VIR_CGROUP_TASK_THREAD =3D 1 << 1, } virCgroupTaskFlags; =20 =20 @@ -1228,6 +1232,24 @@ virCgroupAddMachineProcess(virCgroupPtr group, pid_t= pid) VIR_CGROUP_TASK_SYSTEMD); } =20 +/** + * virCgroupAddThread: + * + * @group: The cgroup to add a thread to + * @pid: The pid of the thread to add + * + * Will add the thread to all controllers, except the + * systemd unit controller. + * + * Returns: 0 on success, -1 on error + */ +int +virCgroupAddThread(virCgroupPtr group, + pid_t pid) +{ + return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD); +} + =20 static int virCgroupSetPartitionSuffix(const char *path, char **res) @@ -4229,6 +4251,16 @@ virCgroupAddMachineProcess(virCgroupPtr group ATTRIB= UTE_UNUSED, } =20 =20 +int +virCgroupAddThread(virCgroupPtr group ATTRIBUTE_UNUSED, + pid_t pid ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENXIO, "%s", + _("Control groups not supported on this platform"= )); + return -1; +} + + int virCgroupGetBlkioIoServiced(virCgroupPtr group ATTRIBUTE_UNUSED, long long *bytes_read ATTRIBUTE_UNUSED, diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index bbd4c2ed57..1f676f21c3 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -120,6 +120,7 @@ int virCgroupPathOfController(virCgroupPtr group, =20 int virCgroupAddProcess(virCgroupPtr group, pid_t pid); int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid); +int virCgroupAddThread(virCgroupPtr group, pid_t pid); =20 int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight); int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433694268149.12877118252493; Thu, 20 Sep 2018 01:54:54 -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 91C849AE72; Thu, 20 Sep 2018 08:54:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B51D3782; Thu, 20 Sep 2018 08:54: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 079F34A465; Thu, 20 Sep 2018 08:54:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8skBx002144 for ; Thu, 20 Sep 2018 04:54:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id ADA9160851; Thu, 20 Sep 2018 08:54:46 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D43517DD7 for ; Thu, 20 Sep 2018 08:54:46 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:35 +0200 Message-Id: <77f8a8695b2d229698256774b722282d3f6e2422.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/9] vircgroupmock: cleanup unused cgroup 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: , Content-Type: text/plain; charset="utf-8" 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.39]); Thu, 20 Sep 2018 08:54:53 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- tests/vircgroupmock.c | 73 ------------------------------------------- 1 file changed, 73 deletions(-) diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index d512417789..73cf876645 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -212,13 +212,7 @@ static int make_controller(const char *path, mode_t mo= de) if (STRPREFIX(controller, "cpu,cpuacct")) { MAKE_FILE("cpu.cfs_period_us", "100000\n"); MAKE_FILE("cpu.cfs_quota_us", "-1\n"); - MAKE_FILE("cpu.rt_period_us", "1000000\n"); - MAKE_FILE("cpu.rt_runtime_us", "950000\n"); MAKE_FILE("cpu.shares", "1024\n"); - MAKE_FILE("cpu.stat", - "nr_periods 0\n" - "nr_throttled 0\n" - "throttled_time 0\n"); MAKE_FILE("cpuacct.stat", "user 216687025\n" "system 43421396\n"); @@ -233,46 +227,19 @@ static int make_controller(const char *path, mode_t m= ode) "709566900 0 0 0 0 0 0 0 444777342 0 0 0 0 0 0 0 " "5683512916 0 0 0 0 0 0 0 635751356 0 0 0 0 0 0 0\n"); } else if (STRPREFIX(controller, "cpuset")) { - MAKE_FILE("cpuset.cpu_exclusive", "1\n"); if (STREQ(controller, "cpuset")) MAKE_FILE("cpuset.cpus", "0-1"); else MAKE_FILE("cpuset.cpus", ""); /* Values don't inherit */ - MAKE_FILE("cpuset.mem_exclusive", "1\n"); - MAKE_FILE("cpuset.mem_hardwall", "0\n"); MAKE_FILE("cpuset.memory_migrate", "0\n"); - MAKE_FILE("cpuset.memory_pressure", "0\n"); - MAKE_FILE("cpuset.memory_pressure_enabled", "0\n"); - MAKE_FILE("cpuset.memory_spread_page", "0\n"); - MAKE_FILE("cpuset.memory_spread_slab", "0\n"); if (STREQ(controller, "cpuset")) MAKE_FILE("cpuset.mems", "0"); else MAKE_FILE("cpuset.mems", ""); /* Values don't inherit */ - MAKE_FILE("cpuset.sched_load_balance", "1\n"); - MAKE_FILE("cpuset.sched_relax_domain_level", "-1\n"); } else if (STRPREFIX(controller, "memory")) { - MAKE_FILE("memory.failcnt", "0\n"); - MAKE_FILE("memory.force_empty", ""); /* Write only */ - MAKE_FILE("memory.kmem.tcp.failcnt", "0\n"); - MAKE_FILE("memory.kmem.tcp.limit_in_bytes", "9223372036854775807\n= "); - MAKE_FILE("memory.kmem.tcp.max_usage_in_bytes", "0\n"); - MAKE_FILE("memory.kmem.tcp.usage_in_bytes", "16384\n"); MAKE_FILE("memory.limit_in_bytes", "9223372036854775807\n"); - MAKE_FILE("memory.max_usage_in_bytes", "0\n"); - MAKE_FILE("memory.memsw.failcnt", ""); /* Not supported */ MAKE_FILE("memory.memsw.limit_in_bytes", ""); /* Not supported */ - MAKE_FILE("memory.memsw.max_usage_in_bytes", ""); /* Not supported= */ MAKE_FILE("memory.memsw.usage_in_bytes", ""); /* Not supported */ - MAKE_FILE("memory.move_charge_at_immigrate", "0\n"); - MAKE_FILE("memory.numa_stat", - "total=3D367664 N0=3D367664\n" - "file=3D314764 N0=3D314764\n" - "anon=3D51999 N0=3D51999\n" - "unevictable=3D901 N0=3D901\n"); - MAKE_FILE("memory.oom_control", - "oom_kill_disable 0\n" - "under_oom 0\n"); MAKE_FILE("memory.soft_limit_in_bytes", "9223372036854775807\n"); MAKE_FILE("memory.stat", "cache 1336619008\n" @@ -304,50 +271,11 @@ static int make_controller(const char *path, mode_t m= ode) "recent_rotated_file 2547948\n" "recent_scanned_anon 113796164\n" "recent_scanned_file 8199863\n"); - MAKE_FILE("memory.swappiness", "60\n"); MAKE_FILE("memory.usage_in_bytes", "1455321088\n"); MAKE_FILE("memory.use_hierarchy", "0\n"); } else if (STRPREFIX(controller, "freezer")) { MAKE_FILE("freezer.state", "THAWED"); } else if (STRPREFIX(controller, "blkio")) { - MAKE_FILE("blkio.io_merged", - "8:0 Read 1100949\n" - "8:0 Write 2248076\n" - "8:0 Sync 63063\n" - "8:0 Async 3285962\n" - "8:0 Total 3349025\n"); - MAKE_FILE("blkio.io_queued", - "8:0 Read 0\n" - "8:0 Write 0\n" - "8:0 Sync 0\n" - "8:0 Async 0\n" - "8:0 Total 0\n"); - MAKE_FILE("blkio.io_service_bytes", - "8:0 Read 59542078464\n" - "8:0 Write 397369182208\n" - "8:0 Sync 234080922624\n" - "8:0 Async 222830338048\n" - "8:0 Total 456911260672\n"); - MAKE_FILE("blkio.io_serviced", - "8:0 Read 3402504\n" - "8:0 Write 14966516\n" - "8:0 Sync 12064031\n" - "8:0 Async 6304989\n" - "8:0 Total 18369020\n"); - MAKE_FILE("blkio.io_service_time", - "8:0 Read 10747537542349\n" - "8:0 Write 9200028590575\n" - "8:0 Sync 6449319855381\n" - "8:0 Async 13498246277543\n" - "8:0 Total 19947566132924\n"); - MAKE_FILE("blkio.io_wait_time", - "8:0 Read 14687514824889\n" - "8:0 Write 357748452187691\n" - "8:0 Sync 55296974349413\n" - "8:0 Async 317138992663167\n" - "8:0 Total 372435967012580\n"); - MAKE_FILE("blkio.reset_stats", ""); /* Write only */ - MAKE_FILE("blkio.sectors", "8:0 892404806\n"); MAKE_FILE("blkio.throttle.io_service_bytes", "8:0 Read 59542107136\n" "8:0 Write 411440480256\n" @@ -374,7 +302,6 @@ static int make_controller(const char *path, mode_t mod= e) MAKE_FILE("blkio.throttle.read_iops_device", ""); MAKE_FILE("blkio.throttle.write_bps_device", ""); MAKE_FILE("blkio.throttle.write_iops_device", ""); - MAKE_FILE("blkio.time", "8:0 61019089\n"); MAKE_FILE("blkio.weight", "1000\n"); MAKE_FILE("blkio.weight_device", ""); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433701677209.31129940690346; Thu, 20 Sep 2018 01:55:01 -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 BE606307D874; Thu, 20 Sep 2018 08:54:59 +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 800AB106A786; Thu, 20 Sep 2018 08:54:59 +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 316BC181A55B; Thu, 20 Sep 2018 08:54:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8slK3002152 for ; Thu, 20 Sep 2018 04:54:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id AAE96808EB; Thu, 20 Sep 2018 08:54:47 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06F4760851 for ; Thu, 20 Sep 2018 08:54:46 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:36 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 7/9] vircgroupmock: rewrite cgroup fopen mocking 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: , Content-Type: text/plain; charset="utf-8" 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.48]); Thu, 20 Sep 2018 08:55:00 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Move all the cgroup data into separate files out of vircgroupmock.c and rework the fopen function to load data from files. This will make it easier to add more test cases. Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina --- tests/vircgroupdata/all-in-one.cgroups | 7 ++ tests/vircgroupdata/all-in-one.mounts | 2 +- tests/vircgroupdata/all-in-one.parsed | 12 +- tests/vircgroupdata/all-in-one.self.cgroup | 1 + tests/vircgroupdata/logind.cgroups | 10 ++ tests/vircgroupdata/logind.mounts | 2 + tests/vircgroupdata/logind.self.cgroup | 1 + tests/vircgroupdata/systemd.cgroups | 8 ++ tests/vircgroupdata/systemd.mounts | 11 ++ tests/vircgroupdata/systemd.self.cgroup | 6 + tests/vircgroupmock.c | 133 ++++----------------- tests/vircgrouptest.c | 10 +- 12 files changed, 79 insertions(+), 124 deletions(-) create mode 100644 tests/vircgroupdata/all-in-one.cgroups create mode 100644 tests/vircgroupdata/all-in-one.self.cgroup create mode 100644 tests/vircgroupdata/logind.cgroups create mode 100644 tests/vircgroupdata/logind.mounts create mode 100644 tests/vircgroupdata/logind.self.cgroup create mode 100644 tests/vircgroupdata/systemd.cgroups create mode 100644 tests/vircgroupdata/systemd.mounts create mode 100644 tests/vircgroupdata/systemd.self.cgroup diff --git a/tests/vircgroupdata/all-in-one.cgroups b/tests/vircgroupdata/a= ll-in-one.cgroups new file mode 100644 index 0000000000..7208e5a0b6 --- /dev/null +++ b/tests/vircgroupdata/all-in-one.cgroups @@ -0,0 +1,7 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 6 1 1 +cpu 6 1 1 +cpuacct 6 1 1 +memory 6 1 1 +devices 6 1 1 +blkio 6 1 1 diff --git a/tests/vircgroupdata/all-in-one.mounts b/tests/vircgroupdata/al= l-in-one.mounts index 14093b961c..76c579ff69 100644 --- a/tests/vircgroupdata/all-in-one.mounts +++ b/tests/vircgroupdata/all-in-one.mounts @@ -4,4 +4,4 @@ proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 udev /dev devtmpfs rw,relatime,size=3D16458560k,nr_inodes=3D4114640,mode= =3D755 0 0 devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=3D5,mode=3D620,ptmxmo= de=3D000 0 0 nfsd /proc/fs/nfsd nfsd rw,relatime 0 0 -cgroup /sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,cpuacct,cpu,= cpuset 0 0 +cgroup /not/really/sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,c= puacct,cpu,cpuset 0 0 diff --git a/tests/vircgroupdata/all-in-one.parsed b/tests/vircgroupdata/al= l-in-one.parsed index 2701778fea..d703d08fb9 100644 --- a/tests/vircgroupdata/all-in-one.parsed +++ b/tests/vircgroupdata/all-in-one.parsed @@ -1,10 +1,10 @@ -cpu /sys/fs/cgroup -cpuacct /sys/fs/cgroup -cpuset /sys/fs/cgroup -memory /sys/fs/cgroup -devices /sys/fs/cgroup +cpu /not/really/sys/fs/cgroup +cpuacct /not/really/sys/fs/cgroup +cpuset /not/really/sys/fs/cgroup +memory /not/really/sys/fs/cgroup +devices /not/really/sys/fs/cgroup freezer -blkio /sys/fs/cgroup +blkio /not/really/sys/fs/cgroup net_cls perf_event name=3Dsystemd diff --git a/tests/vircgroupdata/all-in-one.self.cgroup b/tests/vircgroupda= ta/all-in-one.self.cgroup new file mode 100644 index 0000000000..cf237502e9 --- /dev/null +++ b/tests/vircgroupdata/all-in-one.self.cgroup @@ -0,0 +1 @@ +6:blkio,devices,memory,cpuacct,cpu,cpuset:/ diff --git a/tests/vircgroupdata/logind.cgroups b/tests/vircgroupdata/login= d.cgroups new file mode 100644 index 0000000000..9d46f130e0 --- /dev/null +++ b/tests/vircgroupdata/logind.cgroups @@ -0,0 +1,10 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 0 1 1 +cpu 0 1 1 +cpuacct 0 1 1 +memory 0 1 0 +devices 0 1 1 +freezer 0 1 1 +net_cls 0 1 1 +blkio 0 1 1 +perf_event 0 1 1 diff --git a/tests/vircgroupdata/logind.mounts b/tests/vircgroupdata/logind= .mounts new file mode 100644 index 0000000000..3ab908aee9 --- /dev/null +++ b/tests/vircgroupdata/logind.mounts @@ -0,0 +1,2 @@ +none /not/really/sys/fs/cgroup tmpfs rw,rootcontext=3Dsystem_u:object_r:sy= sfs_t:s0,seclabel,relatime,size=3D4k,mode=3D755 0 0 +systemd /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,re= latime,name=3Dsystemd 0 0 diff --git a/tests/vircgroupdata/logind.self.cgroup b/tests/vircgroupdata/l= ogind.self.cgroup new file mode 100644 index 0000000000..31e0cfe8eb --- /dev/null +++ b/tests/vircgroupdata/logind.self.cgroup @@ -0,0 +1 @@ +0:name=3Dsystemd:/ diff --git a/tests/vircgroupdata/systemd.cgroups b/tests/vircgroupdata/syst= emd.cgroups new file mode 100644 index 0000000000..d32dfab222 --- /dev/null +++ b/tests/vircgroupdata/systemd.cgroups @@ -0,0 +1,8 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 2 4 1 +cpu 3 48 1 +cpuacct 3 48 1 +memory 4 4 1 +devices 5 4 1 +freezer 6 4 1 +blkio 8 4 1 diff --git a/tests/vircgroupdata/systemd.mounts b/tests/vircgroupdata/syste= md.mounts new file mode 100644 index 0000000000..75572c86f7 --- /dev/null +++ b/tests/vircgroupdata/systemd.mounts @@ -0,0 +1,11 @@ +rootfs / rootfs rw 0 0 +tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=3D755 0 0 +tmpfs /not/really/sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,mode= =3D755 0 0 +cgroup /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,rel= atime,release_agent=3D/usr/lib/systemd/systemd-cgroups-agent,name=3Dsystemd= 0 0 +cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,rela= time,cpuset 0 0 +cgroup /not/really/sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec= ,relatime,cpuacct,cpu 0 0 +cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,rel= atime,freezer 0 0 +cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relat= ime,blkio 0 0 +cgroup /not/really/sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,rela= time,memory 0 0 +/dev/sda1 /boot ext4 rw,seclabel,relatime,data=3Dordered 0 0 +tmpfs /tmp tmpfs rw,seclabel,relatime,size=3D1024000k 0 0 diff --git a/tests/vircgroupdata/systemd.self.cgroup b/tests/vircgroupdata/= systemd.self.cgroup new file mode 100644 index 0000000000..2b95af79d2 --- /dev/null +++ b/tests/vircgroupdata/systemd.self.cgroup @@ -0,0 +1,6 @@ +115:memory:/ +8:blkio:/ +6:freezer:/ +3:cpuacct,cpu:/system +2:cpuset:/ +1:name=3Dsystemd:/user/berrange/123 diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index 73cf876645..cfff1f0b7a 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -79,85 +79,6 @@ const char *fakedevicedir1 =3D FAKEDEVDIR1; * of files beneath it */ =20 -/* - * Intentionally missing the 'devices' mount. - * Co-mounting cpu & cpuacct controllers - * An anonymous controller for systemd - */ -const char *procmounts =3D - "rootfs / rootfs rw 0 0\n" - "tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=3D755 0 0\n" - "tmpfs /not/really/sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec= ,mode=3D755 0 0\n" - "cgroup /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexe= c,relatime,release_agent=3D/usr/lib/systemd/systemd-cgroups-agent,name=3Dsy= stemd 0 0\n" - "cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec= ,relatime,cpuset 0 0\n" - "cgroup /not/really/sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,n= oexec,relatime,cpuacct,cpu 0 0\n" - "cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexe= c,relatime,freezer 0 0\n" - "cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,= relatime,blkio 0 0\n" - "cgroup /not/really/sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec= ,relatime,memory 0 0\n" - "/dev/sda1 /boot ext4 rw,seclabel,relatime,data=3Dordered 0 0\n" - "tmpfs /tmp tmpfs rw,seclabel,relatime,size=3D1024000k 0 0\n"; - -const char *procselfcgroups =3D - "115:memory:/\n" - "8:blkio:/\n" - "6:freezer:/\n" - "3:cpuacct,cpu:/system\n" - "2:cpuset:/\n" - "1:name=3Dsystemd:/user/berrange/123\n"; - -const char *proccgroups =3D - "#subsys_name hierarchy num_cgroups enabled\n" - "cpuset 2 4 1\n" - "cpu 3 48 1\n" - "cpuacct 3 48 1\n" - "memory 4 4 1\n" - "devices 5 4 1\n" - "freezer 6 4 1\n" - "blkio 8 4 1\n"; - - -const char *procmountsallinone =3D - "rootfs / rootfs rw 0 0\n" - "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" - "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0\n" - "udev /dev devtmpfs rw,relatime,size=3D16458560k,nr_inodes=3D4114640,m= ode=3D755 0 0\n" - "devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=3D5,mode=3D620,p= tmxmode=3D000 0 0\n" - "nfsd /proc/fs/nfsd nfsd rw,relatime 0 0\n" - "cgroup /not/really/sys/fs/cgroup cgroup rw,relatime,blkio,devices,mem= ory,cpuacct,cpu,cpuset 0 0\n"; - -const char *procselfcgroupsallinone =3D - "6:blkio,devices,memory,cpuacct,cpu,cpuset:/"; - -const char *proccgroupsallinone =3D - "#subsys_name hierarchy num_cgroups enabled\n" - "cpuset 6 1 1\n" - "cpu 6 1 1\n" - "cpuacct 6 1 1\n" - "memory 6 1 1\n" - "devices 6 1 1\n" - "blkio 6 1 1\n"; - -const char *procmountslogind =3D - "none /not/really/sys/fs/cgroup tmpfs rw,rootcontext=3Dsystem_u:object= _r:sysfs_t:s0,seclabel,relatime,size=3D4k,mode=3D755 0 0\n" - "systemd /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noex= ec,relatime,name=3Dsystemd 0 0\n"; - -const char *procselfcgroupslogind =3D - "1:name=3Dsystemd:/\n"; - -const char *proccgroupslogind =3D - "#subsys_name hierarchy num_cgroups enabled\n" - "cpuset 0 1 1\n" - "cpu 0 1 1\n" - "cpuacct 0 1 1\n" - "memory 0 1 0\n" - "devices 0 1 1\n" - "freezer 0 1 1\n" - "net_cls 0 1 1\n" - "blkio 0 1 1\n" - "perf_event 0 1 1\n"; - - - static int make_file(const char *path, const char *name, const char *value) @@ -377,28 +298,16 @@ static void init_sysfs(void) =20 FILE *fopen(const char *path, const char *mode) { - const char *mock; - bool allinone =3D false, logind =3D false; - init_syms(); + char *filepath =3D NULL; + const char *type =3D NULL; + FILE *rc =3D NULL; + const char *filename =3D getenv("VIR_CGROUP_MOCK_FILENAME"); =20 - mock =3D getenv("VIR_CGROUP_MOCK_MODE"); - if (mock) { - if (STREQ(mock, "allinone")) - allinone =3D true; - else if (STREQ(mock, "logind")) - logind =3D true; - } + init_syms(); =20 if (STREQ(path, "/proc/mounts")) { if (STREQ(mode, "r")) { - if (allinone) - return fmemopen((void *)procmountsallinone, - strlen(procmountsallinone), mode); - else if (logind) - return fmemopen((void *)procmountslogind, - strlen(procmountslogind), mode); - else - return fmemopen((void *)procmounts, strlen(procmounts), mo= de); + type =3D "mounts"; } else { errno =3D EACCES; return NULL; @@ -406,14 +315,7 @@ FILE *fopen(const char *path, const char *mode) } if (STREQ(path, "/proc/cgroups")) { if (STREQ(mode, "r")) { - if (allinone) - return fmemopen((void *)proccgroupsallinone, - strlen(proccgroupsallinone), mode); - else if (logind) - return fmemopen((void *)proccgroupslogind, - strlen(proccgroupslogind), mode); - else - return fmemopen((void *)proccgroups, strlen(proccgroups), = mode); + type =3D "cgroups"; } else { errno =3D EACCES; return NULL; @@ -421,20 +323,25 @@ FILE *fopen(const char *path, const char *mode) } if (STREQ(path, "/proc/self/cgroup")) { if (STREQ(mode, "r")) { - if (allinone) - return fmemopen((void *)procselfcgroupsallinone, - strlen(procselfcgroupsallinone), mode); - else if (logind) - return fmemopen((void *)procselfcgroupslogind, - strlen(procselfcgroupslogind), mode); - else - return fmemopen((void *)procselfcgroups, strlen(procselfcg= roups), mode); + type =3D "self.cgroup"; } else { errno =3D EACCES; return NULL; } } =20 + if (type) { + if (!filename) + abort(); + if (virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s", + abs_srcdir, filename, type) < 0) { + abort(); + } + rc =3D real_fopen(filepath, mode); + free(filepath); + return rc; + } + return real_fopen(path, mode); } =20 diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 6ab67dca78..d23ce2155b 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -889,6 +889,7 @@ mymain(void) DETECT_MOUNTS("no-cgroups"); DETECT_MOUNTS("kubevirt"); =20 + setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1); if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0) ret =3D -1; =20 @@ -924,20 +925,21 @@ mymain(void) =20 if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuSta= ts, NULL) < 0) ret =3D -1; + unsetenv("VIR_CGROUP_MOCK_FILENAME"); =20 - setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1); + setenv("VIR_CGROUP_MOCK_FILENAME", "all-in-one", 1); 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_MODE"); + unsetenv("VIR_CGROUP_MOCK_FILENAME"); =20 - setenv("VIR_CGROUP_MOCK_MODE", "logind", 1); + setenv("VIR_CGROUP_MOCK_FILENAME", "logind", 1); 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_MODE"); + unsetenv("VIR_CGROUP_MOCK_FILENAME"); =20 if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433695635321.6927808663369; Thu, 20 Sep 2018 01:54:55 -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 989A03086275; Thu, 20 Sep 2018 08:54:53 +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 647252010D78; Thu, 20 Sep 2018 08:54:53 +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 1AFCE181A530; Thu, 20 Sep 2018 08:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8sm4w002166 for ; Thu, 20 Sep 2018 04:54:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 829A781743; Thu, 20 Sep 2018 08:54:48 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05175808EB for ; Thu, 20 Sep 2018 08:54:47 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:37 +0200 Message-Id: <01397caba8269abb6c37edad5f10dddecbbad544.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 8/9] vircgrouptest: call virCgroupDetectMounts directly 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: , Content-Type: text/plain; charset="utf-8" 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.49]); Thu, 20 Sep 2018 08:54:54 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Because we can set which files to return for cgroup tests there is no need to have special function tailored to run tests. Reviewed-by: Fabiano Fid=C3=AAncio Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 2 +- src/util/vircgroup.c | 21 +++++---------------- src/util/vircgrouppriv.h | 4 +--- tests/vircgrouptest.c | 16 ++++++++-------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ad7ce57b65..7f3b5738c4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1513,7 +1513,7 @@ virCgroupDelThread; virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; -virCgroupDetectMountsFromFile; +virCgroupDetectMounts; virCgroupFree; virCgroupGetBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadIops; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index ea83c5f5b2..cc4c45b4fb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -426,9 +426,7 @@ virCgroupMountOptsMatchController(const char *mntOpts, * mounted and where */ int -virCgroupDetectMountsFromFile(virCgroupPtr group, - const char *path, - bool checkLinks) +virCgroupDetectMounts(virCgroupPtr group) { size_t i; FILE *mounts =3D NULL; @@ -436,9 +434,9 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, char buf[CGROUP_MAX_VAL]; int ret =3D -1; =20 - mounts =3D fopen(path, "r"); + mounts =3D fopen("/proc/mounts", "r"); if (mounts =3D=3D NULL) { - virReportSystemError(errno, _("Unable to open %s"), path); + virReportSystemError(errno, "%s", _("Unable to open /proc/mounts")= ); return -1; } =20 @@ -466,8 +464,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, =20 /* If it is a co-mount it has a filename like "cpu,cpuacct" * and we must identify the symlink path */ - if (checkLinks && - virCgroupResolveMountLink(entry.mnt_dir, typestr, + if (virCgroupResolveMountLink(entry.mnt_dir, typestr, controller) < 0) { goto cleanup; } @@ -481,12 +478,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, return ret; } =20 -static int -virCgroupDetectMounts(virCgroupPtr group) -{ - return virCgroupDetectMountsFromFile(group, "/proc/mounts", true); -} - =20 static int virCgroupCopyPlacement(virCgroupPtr group, @@ -4086,9 +4077,7 @@ virCgroupAvailable(void) =20 =20 int -virCgroupDetectMountsFromFile(virCgroupPtr group ATTRIBUTE_UNUSED, - const char *path ATTRIBUTE_UNUSED, - bool checkLinks ATTRIBUTE_UNUSED) +virCgroupDetectMounts(virCgroupPtr group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform"= )); diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index a0034f3889..f78fe8bb9c 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -50,9 +50,7 @@ struct _virCgroup { virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 -int virCgroupDetectMountsFromFile(virCgroupPtr group, - const char *path, - bool checkLinks); +int virCgroupDetectMounts(virCgroupPtr group); =20 int virCgroupNewPartition(const char *path, bool create, diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index d23ce2155b..54945eea2d 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -163,21 +163,21 @@ testCgroupDetectMounts(const void *args) { int result =3D -1; const char *file =3D args; - char *mounts =3D NULL; char *parsed =3D NULL; const char *actual; virCgroupPtr group =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 - if (virAsprintf(&mounts, "%s/vircgroupdata/%s.mounts", - abs_srcdir, file) < 0 || - virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", - abs_srcdir, file) < 0 || - VIR_ALLOC(group) < 0) + setenv("VIR_CGROUP_MOCK_FILENAME", file, 1); + + if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir, fil= e) < 0) + goto cleanup; + + if (VIR_ALLOC(group) < 0) goto cleanup; =20 - if (virCgroupDetectMountsFromFile(group, mounts, false) < 0) + if (virCgroupDetectMounts(group) < 0) goto cleanup; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -195,7 +195,7 @@ testCgroupDetectMounts(const void *args) result =3D 0; =20 cleanup: - VIR_FREE(mounts); + unsetenv("VIR_CGROUP_MOCK_FILENAME"); VIR_FREE(parsed); virCgroupFree(&group); virBufferFreeAndReset(&buf); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 13:52:21 2024 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 1537433706823752.1061768699617; Thu, 20 Sep 2018 01:55:06 -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 EDAFAD2164; Thu, 20 Sep 2018 08:55:04 +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 98ACB7E6B9; Thu, 20 Sep 2018 08:55: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 1AE744A46F; Thu, 20 Sep 2018 08:55:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8K8snuK002190 for ; Thu, 20 Sep 2018 04:54:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CA8960851; Thu, 20 Sep 2018 08:54:49 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0EE8808EB for ; Thu, 20 Sep 2018 08:54:48 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 10:54:38 +0200 Message-Id: <331d9e348e2b613a0597a9f42bb9eabdd17c84ce.1537433421.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 9/9] vircgrouptest: call virCgroupNewSelf instead virCgroupDetectMounts 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.38]); Thu, 20 Sep 2018 08:55:05 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will be required once cgroup v2 is introduced. The cgroup detection is not simple and we will have multiple backends so we should not just jump into the middle of the detection code. In order to use virCgroupNewSelf we need to create all the remaining data files: - {name}.cgroups represents /proc/cgroups, it is a list of cgroup controllers compiled into kernel - {name}.self.cgroup represents /proc/self/cgroup, it describes cgroups to which the process belongs For "no-cgroups" we need to modify the expected behavior because virCgroupNewSelf() will fail if there are no controllers available. Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- Notes: changes in v2: - no-cgroups detect test is now expected to fail src/libvirt_private.syms | 1 - src/util/vircgroup.c | 11 +------ src/util/vircgrouppriv.h | 2 -- tests/vircgroupdata/cgroups1.cgroups | 11 +++++++ tests/vircgroupdata/cgroups1.self.cgroup | 11 +++++++ tests/vircgroupdata/cgroups2.cgroups | 10 +++++++ tests/vircgroupdata/cgroups2.self.cgroup | 10 +++++++ tests/vircgroupdata/cgroups3.cgroups | 12 ++++++++ tests/vircgroupdata/cgroups3.self.cgroup | 12 ++++++++ tests/vircgroupdata/fedora-18.cgroups | 10 +++++++ tests/vircgroupdata/fedora-18.self.cgroup | 9 ++++++ tests/vircgroupdata/fedora-21.cgroups | 12 ++++++++ tests/vircgroupdata/fedora-21.self.cgroup | 10 +++++++ tests/vircgroupdata/kubevirt.cgroups | 10 +++++++ tests/vircgroupdata/kubevirt.self.cgroup | 10 +++++++ tests/vircgroupdata/no-cgroups.cgroups | 8 +++++ tests/vircgroupdata/no-cgroups.parsed | 10 ------- tests/vircgroupdata/no-cgroups.self.cgroup | 0 tests/vircgroupdata/ovirt-node-6.6.cgroups | 9 ++++++ .../vircgroupdata/ovirt-node-6.6.self.cgroup | 8 +++++ tests/vircgroupdata/ovirt-node-7.1.cgroups | 11 +++++++ .../vircgroupdata/ovirt-node-7.1.self.cgroup | 10 +++++++ tests/vircgroupdata/rhel-7.1.cgroups | 11 +++++++ tests/vircgroupdata/rhel-7.1.self.cgroup | 10 +++++++ tests/vircgrouptest.c | 30 ++++++++++++++----- 25 files changed, 217 insertions(+), 31 deletions(-) create mode 100644 tests/vircgroupdata/cgroups1.cgroups create mode 100644 tests/vircgroupdata/cgroups1.self.cgroup create mode 100644 tests/vircgroupdata/cgroups2.cgroups create mode 100644 tests/vircgroupdata/cgroups2.self.cgroup create mode 100644 tests/vircgroupdata/cgroups3.cgroups create mode 100644 tests/vircgroupdata/cgroups3.self.cgroup create mode 100644 tests/vircgroupdata/fedora-18.cgroups create mode 100644 tests/vircgroupdata/fedora-18.self.cgroup create mode 100644 tests/vircgroupdata/fedora-21.cgroups create mode 100644 tests/vircgroupdata/fedora-21.self.cgroup create mode 100644 tests/vircgroupdata/kubevirt.cgroups create mode 100644 tests/vircgroupdata/kubevirt.self.cgroup create mode 100644 tests/vircgroupdata/no-cgroups.cgroups delete mode 100644 tests/vircgroupdata/no-cgroups.parsed create mode 100644 tests/vircgroupdata/no-cgroups.self.cgroup create mode 100644 tests/vircgroupdata/ovirt-node-6.6.cgroups create mode 100644 tests/vircgroupdata/ovirt-node-6.6.self.cgroup create mode 100644 tests/vircgroupdata/ovirt-node-7.1.cgroups create mode 100644 tests/vircgroupdata/ovirt-node-7.1.self.cgroup create mode 100644 tests/vircgroupdata/rhel-7.1.cgroups create mode 100644 tests/vircgroupdata/rhel-7.1.self.cgroup diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7f3b5738c4..75c59fbf89 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1513,7 +1513,6 @@ virCgroupDelThread; virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; -virCgroupDetectMounts; virCgroupFree; virCgroupGetBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadIops; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cc4c45b4fb..38458de0a2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -425,7 +425,7 @@ virCgroupMountOptsMatchController(const char *mntOpts, * Process /proc/mounts figuring out what controllers are * mounted and where */ -int +static int virCgroupDetectMounts(virCgroupPtr group) { size_t i; @@ -4076,15 +4076,6 @@ virCgroupAvailable(void) } =20 =20 -int -virCgroupDetectMounts(virCgroupPtr group ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENXIO, "%s", - _("Control groups not supported on this platform"= )); - return -1; -} - - int virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED, bool create ATTRIBUTE_UNUSED, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index f78fe8bb9c..046c96c52c 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -50,8 +50,6 @@ struct _virCgroup { virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 -int virCgroupDetectMounts(virCgroupPtr group); - int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/tests/vircgroupdata/cgroups1.cgroups b/tests/vircgroupdata/cgr= oups1.cgroups new file mode 100644 index 0000000000..a03c290a98 --- /dev/null +++ b/tests/vircgroupdata/cgroups1.cgroups @@ -0,0 +1,11 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +blkio 8 1 1 +memory 4 1 1 +devices 5 1 1 +freezer 6 1 1 +net_cls 7 1 1 +net_prio 9 1 1 +hugetlb 10 1 1 diff --git a/tests/vircgroupdata/cgroups1.self.cgroup b/tests/vircgroupdata= /cgroups1.self.cgroup new file mode 100644 index 0000000000..181f0c22f8 --- /dev/null +++ b/tests/vircgroupdata/cgroups1.self.cgroup @@ -0,0 +1,11 @@ +10:hugetlb:/ +9:net_prio:/ +8:blkio:/ +7:net_cls:/ +6:freezer:/ +5:devices:/ +4:memory:/ +3:cpuacct:/ +2:cpu:/ +1:cpuset:/ +0:name=3Dopenrc:/ diff --git a/tests/vircgroupdata/cgroups2.cgroups b/tests/vircgroupdata/cgr= oups2.cgroups new file mode 100644 index 0000000000..f0a7699559 --- /dev/null +++ b/tests/vircgroupdata/cgroups2.cgroups @@ -0,0 +1,10 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +blkio 7 1 1 +memory 4 1 1 +devices 5 1 1 +freezer 6 1 1 +perf_event 8 1 1 +hugetlb 9 1 1 diff --git a/tests/vircgroupdata/cgroups2.self.cgroup b/tests/vircgroupdata= /cgroups2.self.cgroup new file mode 100644 index 0000000000..3d0e793e5a --- /dev/null +++ b/tests/vircgroupdata/cgroups2.self.cgroup @@ -0,0 +1,10 @@ +9:hugetlb:/ +8:perf_event:/ +7:blkio:/ +6:freezer:/ +5:devices:/ +4:memory:/ +3:cpuacct:/ +2:cpu:/ +1:cpuset:/ +0:name=3Dopenrc:/ diff --git a/tests/vircgroupdata/cgroups3.cgroups b/tests/vircgroupdata/cgr= oups3.cgroups new file mode 100644 index 0000000000..294d95dedf --- /dev/null +++ b/tests/vircgroupdata/cgroups3.cgroups @@ -0,0 +1,12 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +blkio 8 1 1 +memory 4 1 1 +devices 5 1 1 +freezer 6 1 1 +net_cls 7 1 1 +perf_event 9 1 1 +net_prio 10 1 1 +hugetlb 11 1 1 diff --git a/tests/vircgroupdata/cgroups3.self.cgroup b/tests/vircgroupdata= /cgroups3.self.cgroup new file mode 100644 index 0000000000..bf346abdf9 --- /dev/null +++ b/tests/vircgroupdata/cgroups3.self.cgroup @@ -0,0 +1,12 @@ +11:hugetlb:/ +10:net_prio:/ +9:perf_event:/ +8:blkio:/ +7:net_cls:/ +6:freezer:/ +5:devices:/ +4:memory:/ +3:cpuacct:/ +2:cpu:/ +1:cpuset:/ +0:name=3Dopenrc:/ diff --git a/tests/vircgroupdata/fedora-18.cgroups b/tests/vircgroupdata/fe= dora-18.cgroups new file mode 100644 index 0000000000..8eb41087f3 --- /dev/null +++ b/tests/vircgroupdata/fedora-18.cgroups @@ -0,0 +1,10 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 2 1 1 +blkio 7 1 1 +memory 3 1 1 +devices 4 1 1 +freezer 5 1 1 +net_cls 6 1 1 +perf_event 8 1 1 diff --git a/tests/vircgroupdata/fedora-18.self.cgroup b/tests/vircgroupdat= a/fedora-18.self.cgroup new file mode 100644 index 0000000000..da9ad8ad4d --- /dev/null +++ b/tests/vircgroupdata/fedora-18.self.cgroup @@ -0,0 +1,9 @@ +8:perf_event:/ +7:blkio:/ +6:net_cls:/ +5:freezer:/ +4:devices:/ +3:memory:/ +2:cpu,cpuacct:/ +1:cpuset:/ +0:name=3Dsystemd:/ diff --git a/tests/vircgroupdata/fedora-21.cgroups b/tests/vircgroupdata/fe= dora-21.cgroups new file mode 100644 index 0000000000..3e1401ee98 --- /dev/null +++ b/tests/vircgroupdata/fedora-21.cgroups @@ -0,0 +1,12 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 2 1 1 +blkio 7 1 1 +memory 3 1 1 +devices 4 1 1 +freezer 5 1 1 +net_cls 6 1 1 +perf_event 8 1 1 +net_prio 6 1 1 +hugetlb 9 1 1 diff --git a/tests/vircgroupdata/fedora-21.self.cgroup b/tests/vircgroupdat= a/fedora-21.self.cgroup new file mode 100644 index 0000000000..4c666bd59e --- /dev/null +++ b/tests/vircgroupdata/fedora-21.self.cgroup @@ -0,0 +1,10 @@ +9:hugetlb:/ +8:perf_event:/ +7:blkio:/ +6:net_cls,net_prio:/ +5:freezer:/ +4:devices:/ +3:memory:/ +2:cpu,cpuacct:/ +1:cpuset:/ +0:name=3Dsystemd:/ diff --git a/tests/vircgroupdata/kubevirt.cgroups b/tests/vircgroupdata/kub= evirt.cgroups new file mode 100644 index 0000000000..f0a7699559 --- /dev/null +++ b/tests/vircgroupdata/kubevirt.cgroups @@ -0,0 +1,10 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +blkio 7 1 1 +memory 4 1 1 +devices 5 1 1 +freezer 6 1 1 +perf_event 8 1 1 +hugetlb 9 1 1 diff --git a/tests/vircgroupdata/kubevirt.self.cgroup b/tests/vircgroupdata= /kubevirt.self.cgroup new file mode 100644 index 0000000000..3d0e793e5a --- /dev/null +++ b/tests/vircgroupdata/kubevirt.self.cgroup @@ -0,0 +1,10 @@ +9:hugetlb:/ +8:perf_event:/ +7:blkio:/ +6:freezer:/ +5:devices:/ +4:memory:/ +3:cpuacct:/ +2:cpu:/ +1:cpuset:/ +0:name=3Dopenrc:/ diff --git a/tests/vircgroupdata/no-cgroups.cgroups b/tests/vircgroupdata/n= o-cgroups.cgroups new file mode 100644 index 0000000000..3ed1d4e45e --- /dev/null +++ b/tests/vircgroupdata/no-cgroups.cgroups @@ -0,0 +1,8 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 0 1 1 +cpu 0 1 1 +cpuacct 0 1 1 +memory 0 1 1 +devices 0 1 1 +freezer 0 1 1 +blkio 0 1 1 diff --git a/tests/vircgroupdata/no-cgroups.parsed b/tests/vircgroupdata/no= -cgroups.parsed deleted file mode 100644 index bf4eea085f..0000000000 --- a/tests/vircgroupdata/no-cgroups.parsed +++ /dev/null @@ -1,10 +0,0 @@ -cpu -cpuacct -cpuset -memory -devices -freezer -blkio -net_cls -perf_event -name=3Dsystemd diff --git a/tests/vircgroupdata/no-cgroups.self.cgroup b/tests/vircgroupda= ta/no-cgroups.self.cgroup new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/vircgroupdata/ovirt-node-6.6.cgroups b/tests/vircgroupda= ta/ovirt-node-6.6.cgroups new file mode 100644 index 0000000000..aaabf11a44 --- /dev/null +++ b/tests/vircgroupdata/ovirt-node-6.6.cgroups @@ -0,0 +1,9 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 0 1 1 +cpu 1 1 1 +cpuacct 2 1 1 +blkio 7 1 1 +memory 3 1 1 +devices 4 1 1 +freezer 5 1 1 +net_cls 6 1 1 diff --git a/tests/vircgroupdata/ovirt-node-6.6.self.cgroup b/tests/vircgro= updata/ovirt-node-6.6.self.cgroup new file mode 100644 index 0000000000..dadc8155fa --- /dev/null +++ b/tests/vircgroupdata/ovirt-node-6.6.self.cgroup @@ -0,0 +1,8 @@ +7:blkio:/ +6:net_cls:/ +5:freezer:/ +4:devices:/ +3:memory:/ +2:cpuacct:/ +1:cpu:/ +0:cpuset:/ diff --git a/tests/vircgroupdata/ovirt-node-7.1.cgroups b/tests/vircgroupda= ta/ovirt-node-7.1.cgroups new file mode 100644 index 0000000000..687297ad4a --- /dev/null +++ b/tests/vircgroupdata/ovirt-node-7.1.cgroups @@ -0,0 +1,11 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 2 1 1 +blkio 7 1 1 +memory 3 1 1 +devices 4 1 1 +freezer 5 1 1 +net_cls 6 1 1 +perf_event 8 1 1 +hugetlb 9 1 1 diff --git a/tests/vircgroupdata/ovirt-node-7.1.self.cgroup b/tests/vircgro= updata/ovirt-node-7.1.self.cgroup new file mode 100644 index 0000000000..f07e8e20f5 --- /dev/null +++ b/tests/vircgroupdata/ovirt-node-7.1.self.cgroup @@ -0,0 +1,10 @@ +9:hugetlb:/ +8:perf_event:/ +7:blkio:/ +6:net_cls:/ +5:freezer:/ +4:devices:/ +3:memory:/ +2:cpu,cpuacct:/ +1:cpuset:/ +0:name=3Dsystemd:/ diff --git a/tests/vircgroupdata/rhel-7.1.cgroups b/tests/vircgroupdata/rhe= l-7.1.cgroups new file mode 100644 index 0000000000..687297ad4a --- /dev/null +++ b/tests/vircgroupdata/rhel-7.1.cgroups @@ -0,0 +1,11 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 1 1 1 +cpu 2 1 1 +cpuacct 2 1 1 +blkio 7 1 1 +memory 3 1 1 +devices 4 1 1 +freezer 5 1 1 +net_cls 6 1 1 +perf_event 8 1 1 +hugetlb 9 1 1 diff --git a/tests/vircgroupdata/rhel-7.1.self.cgroup b/tests/vircgroupdata= /rhel-7.1.self.cgroup new file mode 100644 index 0000000000..f07e8e20f5 --- /dev/null +++ b/tests/vircgroupdata/rhel-7.1.self.cgroup @@ -0,0 +1,10 @@ +9:hugetlb:/ +8:perf_event:/ +7:blkio:/ +6:net_cls:/ +5:freezer:/ +4:devices:/ +3:memory:/ +2:cpu,cpuacct:/ +1:cpuset:/ +0:name=3Dsystemd:/ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 54945eea2d..b6564bdd45 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -158,26 +158,37 @@ const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = =3D { }; =20 =20 +struct _detectMountsData { + const char *file; + bool fail; +}; + + static int testCgroupDetectMounts(const void *args) { int result =3D -1; - const char *file =3D args; + const struct _detectMountsData *data =3D args; char *parsed =3D NULL; const char *actual; virCgroupPtr group =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 - setenv("VIR_CGROUP_MOCK_FILENAME", file, 1); + setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1); =20 - if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir, fil= e) < 0) + if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", + abs_srcdir, data->file) < 0) { goto cleanup; + } =20 - if (VIR_ALLOC(group) < 0) + if (virCgroupNewSelf(&group) < 0) { + if (data->fail) + result =3D 0; goto cleanup; + } =20 - if (virCgroupDetectMounts(group) < 0) + if (data->fail) goto cleanup; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -869,13 +880,16 @@ mymain(void) =20 setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); =20 -# define DETECT_MOUNTS(file) \ +# define DETECT_MOUNTS_FULL(file, fail) \ do { \ + struct _detectMountsData data =3D { file, fail }; \ if (virTestRun("Detect cgroup mounts for " file, \ testCgroupDetectMounts, \ - file) < 0) \ + &data) < 0) \ ret =3D -1; \ } while (0) +# define DETECT_MOUNTS(file) DETECT_MOUNTS_FULL(file, false); +# define DETECT_MOUNTS_FAIL(file) DETECT_MOUNTS_FULL(file, true); =20 DETECT_MOUNTS("ovirt-node-6.6"); DETECT_MOUNTS("ovirt-node-7.1"); @@ -886,7 +900,7 @@ mymain(void) DETECT_MOUNTS("cgroups2"); DETECT_MOUNTS("cgroups3"); DETECT_MOUNTS("all-in-one"); - DETECT_MOUNTS("no-cgroups"); + DETECT_MOUNTS_FAIL("no-cgroups"); DETECT_MOUNTS("kubevirt"); =20 setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list