public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: ast-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org,
	john.fastabend-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	martin.lau-fxUVXftIFDnyG1zEObXtfA@public.gmane.org,
	song-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	yonghong.song-fxUVXftIFDnyG1zEObXtfA@public.gmane.org,
	kpsingh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	sdf-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	haoluo-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org,
	hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
	yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	mkoutny-IBi9RG/b67k@public.gmane.org
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	bpf-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Yafang Shao <laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [RFC PATCH bpf-next 5/8] selftests/bpf: Fix issues in setup_classid_environment()
Date: Fri, 22 Sep 2023 11:28:43 +0000	[thread overview]
Message-ID: <20230922112846.4265-6-laoar.shao@gmail.com> (raw)
In-Reply-To: <20230922112846.4265-1-laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

If the net_cls subsystem is already mounted, attempting to mount it again
in setup_classid_environment() will result in a failure with the error code
EBUSY. Despite this, tmpfs will have been successfully mounted at
/sys/fs/cgroup/net_cls. Consequently, the /sys/fs/cgroup/net_cls directory
will be empty, causing subsequent setup operations to fail.

Here's an error log excerpt illustrating the issue when net_cls has already
been mounted at /sys/fs/cgroup/net_cls prior to running
setup_classid_environment():

- Before that change

  $ tools/testing/selftests/bpf/test_progs --name=cgroup_v1v2
  test_cgroup_v1v2:PASS:server_fd 0 nsec
  test_cgroup_v1v2:PASS:client_fd 0 nsec
  test_cgroup_v1v2:PASS:cgroup_fd 0 nsec
  test_cgroup_v1v2:PASS:server_fd 0 nsec
  run_test:PASS:skel_open 0 nsec
  run_test:PASS:prog_attach 0 nsec
  test_cgroup_v1v2:PASS:cgroup-v2-only 0 nsec
  (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup.procs
  (cgroup_helpers.c:540: errno: No such file or directory) Opening cgroup classid: /sys/fs/cgroup/net_cls/cgroup-test-work-dir/net_cls.classid
  run_test:PASS:skel_open 0 nsec
  run_test:PASS:prog_attach 0 nsec
  (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup-test-work-dir/cgroup.procs
  run_test:FAIL:join_classid unexpected error: 1 (errno 2)
  test_cgroup_v1v2:FAIL:cgroup-v1v2 unexpected error: -1 (errno 2)
  (cgroup_helpers.c:248: errno: No such file or directory) Opening Cgroup Procs: /sys/fs/cgroup/net_cls/cgroup.procs
  #44      cgroup_v1v2:FAIL
  Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED

- After that change
  $ tools/testing/selftests/bpf/test_progs --name=cgroup_v1v2
  #44      cgroup_v1v2:OK
  Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Yafang Shao <laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 tools/testing/selftests/bpf/cgroup_helpers.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index 24ba56d42f2d..9c36d1db9f94 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -518,10 +518,20 @@ int setup_classid_environment(void)
 		return 1;
 	}
 
-	if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls") &&
-	    errno != EBUSY) {
-		log_err("mount cgroup net_cls");
-		return 1;
+	if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls")) {
+		if (errno != EBUSY) {
+			log_err("mount cgroup net_cls");
+			return 1;
+		}
+
+		if (rmdir(NETCLS_MOUNT_PATH)) {
+			log_err("rmdir cgroup net_cls");
+			return 1;
+		}
+		if (umount(CGROUP_MOUNT_DFLT)) {
+			log_err("umount cgroup base");
+			return 1;
+		}
 	}
 
 	cleanup_classid_environment();
-- 
2.30.1 (Apple Git-130)


  parent reply	other threads:[~2023-09-22 11:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 11:28 [RFC PATCH bpf-next 0/8] bpf, cgroup: Add bpf support for cgroup controller Yafang Shao
     [not found] ` <20230922112846.4265-1-laoar.shao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-09-22 11:28   ` [RFC PATCH bpf-next 1/8] bpf: Fix missed rcu read lock in bpf_task_under_cgroup() Yafang Shao
2023-09-22 11:28   ` [RFC PATCH bpf-next 2/8] cgroup: Enable task_under_cgroup_hierarchy() on cgroup1 Yafang Shao
2023-09-22 11:28   ` [RFC PATCH bpf-next 3/8] cgroup: Add cgroup_get_from_id_within_subsys() Yafang Shao
2023-09-22 11:28   ` [RFC PATCH bpf-next 4/8] bpf: Add new kfuncs support for cgroup controller Yafang Shao
2023-09-22 11:28   ` Yafang Shao [this message]
2023-09-22 11:28   ` [RFC PATCH bpf-next 6/8] selftests/bpf: Add parallel support for classid Yafang Shao
2023-09-22 11:28   ` [RFC PATCH bpf-next 7/8] selftests/bpf: Add new cgroup helper get_classid_cgroup_id() Yafang Shao
2023-09-22 11:28   ` [RFC PATCH bpf-next 8/8] selftests/bpf: Add selftests for cgroup controller Yafang Shao
2023-09-22 16:52   ` [RFC PATCH bpf-next 0/8] bpf, cgroup: Add bpf support " Tejun Heo
     [not found]     ` <ZQ3GQmYrYyKAg2uK-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-09-24  6:32       ` Yafang Shao
     [not found]         ` <CALOAHbA9-BT1daw-KXHtsrN=uRQyt-p6LU=BEpvF2Yk42A_Vxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-09-25 18:43           ` Tejun Heo
2023-09-25 18:43             ` Tejun Heo
     [not found]             ` <ZRHU6MfwqRxjBFUH-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-09-26  3:01               ` Yafang Shao
2023-09-26  3:01                 ` Yafang Shao
2023-09-26 18:25                 ` Tejun Heo
2023-09-27  2:27                   ` Yafang Shao
2023-09-25 18:22   ` Kui-Feng Lee
2023-09-25 18:22     ` Kui-Feng Lee
     [not found]     ` <9e83bda8-ea1b-75b9-c55f-61cf11b4cd83-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-09-26  3:08       ` Yafang Shao
2023-09-26  3:08         ` Yafang Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230922112846.4265-6-laoar.shao@gmail.com \
    --to=laoar.shao-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=ast-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=bpf-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=haoluo-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=john.fastabend-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=kpsingh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org \
    --cc=martin.lau-fxUVXftIFDnyG1zEObXtfA@public.gmane.org \
    --cc=mkoutny-IBi9RG/b67k@public.gmane.org \
    --cc=sdf-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=song-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=yonghong.song-fxUVXftIFDnyG1zEObXtfA@public.gmane.org \
    --cc=yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox