From nobody Mon Feb 9 17:21:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612877210; cv=none; d=zohomail.com; s=zohoarc; b=FRaeVU87B2RZXGiljpT2ZsOFmq4hTWyYLO5V9onAAw76h/1UycqsA7L9LpXvrtCqq2dS91eOOq43P15lVNApe9fsLWRXrhZHJSfL/vCIk476tqhpjCvIvtoD9FAbInfNtankr6euncnu9KT49iypAQO9cr8IRaS9/wk9OxXazpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877210; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HZMj6Ikt+9BEjUkdqDqTak2j+p6EHbvTfVZknw4v4uQ=; b=ndhlRy7it5rn+Yqy7wAZ7wTMXiGObrEoqIRHRO6FfmBOMbJxHFul1V5heHAytkfHeQBrc77Vjo23fn/N7//XAlsBGLfv8scNtKST8XdKSflzXvr10dUPKQHCGje/1Vjj+VJJ15UiHkPSBDj/tGEtkiXhhPv/h5wnY568JDOqlwE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612877210689370.5036197790863; Tue, 9 Feb 2021 05:26:50 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-93-rSPP07lrOZ2NON922g203g-1; Tue, 09 Feb 2021 08:26:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 539EAEC1B1; Tue, 9 Feb 2021 13:26: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 ACDB260C62; Tue, 9 Feb 2021 13:26: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 755DC18089CC; Tue, 9 Feb 2021 13:26:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 119DQThg020480 for ; Tue, 9 Feb 2021 08:26:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id A120C5D9CD; Tue, 9 Feb 2021 13:26:29 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E6695D9C0 for ; Tue, 9 Feb 2021 13:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877209; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HZMj6Ikt+9BEjUkdqDqTak2j+p6EHbvTfVZknw4v4uQ=; b=OXjGidPOzSIIvDZaIRpA1crWiU/V3//xbcBE6Vo7tLo+4SoEnLlakg0rnJEhq3Gkv43TzV sjnkI0AFloNv6GArfyYWZnEqwQq12f8iQI7xHBfORApvbule3TExC0mACRrUEzfUDsJy/y gQ/dsBBluw2PMwlMBuVwtie+s0cJTNg= X-MC-Unique: rSPP07lrOZ2NON922g203g-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 9/9] tests: add cgroup nested tests Date: Tue, 9 Feb 2021 14:26:14 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- tests/vircgroupdata/systemd-legacy.cgroups | 12 ++++ tests/vircgroupdata/systemd-legacy.mounts | 11 +++ .../vircgroupdata/systemd-legacy.self.cgroup | 11 +++ tests/vircgroupdata/systemd-unified.cgroups | 13 ++++ tests/vircgroupdata/systemd-unified.mounts | 1 + .../vircgroupdata/systemd-unified.self.cgroup | 1 + tests/vircgrouptest.c | 72 +++++++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 tests/vircgroupdata/systemd-legacy.cgroups create mode 100644 tests/vircgroupdata/systemd-legacy.mounts create mode 100644 tests/vircgroupdata/systemd-legacy.self.cgroup create mode 100644 tests/vircgroupdata/systemd-unified.cgroups create mode 100644 tests/vircgroupdata/systemd-unified.mounts create mode 100644 tests/vircgroupdata/systemd-unified.self.cgroup diff --git a/tests/vircgroupdata/systemd-legacy.cgroups b/tests/vircgroupda= ta/systemd-legacy.cgroups new file mode 100644 index 0000000000..444354e3c8 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.cgroups @@ -0,0 +1,12 @@ +#subsys_name hierarchy num_cgroups enabled +blkio 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +cpuset 4 1 1 +devices 5 1 1 +freezer 6 1 1 +hugetlb 7 1 1 +memory 8 1 1 +net_cls 9 1 1 +perf_event 10 1 1 +pids 11 1 1 diff --git a/tests/vircgroupdata/systemd-legacy.mounts b/tests/vircgroupdat= a/systemd-legacy.mounts new file mode 100644 index 0000000000..23462e9e68 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.mounts @@ -0,0 +1,11 @@ +cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noe= xec,relatime,blkio 0 0 +cgroup /not/really/sys/fs/cgroup/cpu cgroup rw,seclabel,nosuid,nodev,noexe= c,relatime,cpu 0 0 +cgroup /not/really/sys/fs/cgroup/cpuacct cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,cpuacct 0 0 +cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,no= exec,relatime,cpuset 0 0 +cgroup /not/really/sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,devices 0 0 +cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,freezer 0 0 +cgroup /not/really/sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,hugetlb 0 0 +cgroup /not/really/sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,no= exec,relatime,memory 0 0 +cgroup /not/really/sys/fs/cgroup/net_cls cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,net_cls 0 0 +cgroup /not/really/sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,node= v,noexec,relatime,perf_event 0 0 +cgroup /not/really/sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noex= ec,relatime,pids 0 0 diff --git a/tests/vircgroupdata/systemd-legacy.self.cgroup b/tests/vircgro= updata/systemd-legacy.self.cgroup new file mode 100644 index 0000000000..5c133a3c08 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.self.cgroup @@ -0,0 +1,11 @@ +1:blkio:/libvirt +2:cpu:/libvirt/emulator +3:cpuacct:/libvirt/emulator +4:cpuset:/libvirt/emulator +5:devices:/libvirt +6:freezer:/libvirt +7:hugetlb:/ +8:memory:/libvirt +9:net_cls:/libvirt +10:perf_event:/libvirt +11:pids:/ diff --git a/tests/vircgroupdata/systemd-unified.cgroups b/tests/vircgroupd= ata/systemd-unified.cgroups new file mode 100644 index 0000000000..e0d8a3561c --- /dev/null +++ b/tests/vircgroupdata/systemd-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/systemd-unified.mounts b/tests/vircgroupda= ta/systemd-unified.mounts new file mode 100644 index 0000000000..8225f37f45 --- /dev/null +++ b/tests/vircgroupdata/systemd-unified.mounts @@ -0,0 +1 @@ +cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,= relatime,nsdelegate 0 0 diff --git a/tests/vircgroupdata/systemd-unified.self.cgroup b/tests/vircgr= oupdata/systemd-unified.self.cgroup new file mode 100644 index 0000000000..6007ce7e18 --- /dev/null +++ b/tests/vircgroupdata/systemd-unified.self.cgroup @@ -0,0 +1 @@ +0::/libvirt/emulator diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 1baa71e61c..85c5a6ebd4 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -576,6 +576,64 @@ static int testCgroupNewForSelfHybrid(const void *args= G_GNUC_UNUSED) } =20 =20 +static int testCgroupNewForSelfSystemdLegacy(const void *args G_GNUC_UNUSE= D) +{ + g_autoptr(virCgroup) cgroup =3D NULL; + const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; + const char *mounts[VIR_CGROUP_CONTROLLER_LAST] =3D { + [VIR_CGROUP_CONTROLLER_BLKIO] =3D "/not/really/sys/fs/cgroup/blkio= ", + [VIR_CGROUP_CONTROLLER_CPU] =3D "/not/really/sys/fs/cgroup/cpu", + [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "/not/really/sys/fs/cgroup/cpu= acct", + [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_MEMORY] =3D "/not/really/sys/fs/cgroup/memo= ry", + [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_BLKIO] =3D "", + [VIR_CGROUP_CONTROLLER_CPU] =3D "", + [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "", + [VIR_CGROUP_CONTROLLER_CPUSET] =3D "", + [VIR_CGROUP_CONTROLLER_DEVICES] =3D "", + [VIR_CGROUP_CONTROLLER_FREEZER] =3D "", + [VIR_CGROUP_CONTROLLER_MEMORY] =3D "", + [VIR_CGROUP_CONTROLLER_NET_CLS] =3D "", + [VIR_CGROUP_CONTROLLER_PERF_EVENT] =3D "", + }; + + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); + return -1; + } + + return validateCgroup(cgroup, mounts, empty, placement, NULL, NULL, 0); +} + + +static int testCgroupNewForSelfSystemdUnified(const void *args G_GNUC_UNUS= ED) +{ + g_autoptr(virCgroup) cgroup =3D NULL; + 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_DEVICES) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO); + + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); + return -1; + } + + return validateCgroup(cgroup, empty, empty, empty, + "/not/really/sys/fs/cgroup", "", + controllers); +} + + static int testCgroupAvailable(const void *args) { bool got =3D virCgroupAvailable(); @@ -1046,6 +1104,20 @@ mymain(void) ret =3D -1; cleanupFakeFS(fakerootdir); =20 + fakerootdir =3D initFakeFS("legacy", "systemd-legacy"); + if (virTestRun("New cgroup for self (systemd-legacy)", + testCgroupNewForSelfSystemdLegacy, NULL) < 0) { + ret =3D -1; + } + cleanupFakeFS(fakerootdir); + + fakerootdir =3D initFakeFS("unified", "systemd-unified"); + if (virTestRun("New cgroup for self (systemd-unified)", + testCgroupNewForSelfSystemdUnified, NULL) < 0) { + ret =3D -1; + } + cleanupFakeFS(fakerootdir); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.29.2