Skip to content

Commit 9d2aac1

Browse files
laoargregkh
authored andcommitted
selftests/bpf: Fix issues in setup_classid_environment()
[ Upstream commit 4849775 ] 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 torvalds#44 cgroup_v1v2:FAIL Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED - After that change $ tools/testing/selftests/bpf/test_progs --name=cgroup_v1v2 torvalds#44 cgroup_v1v2:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Yafang Shao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 3eb0fff commit 9d2aac1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: tools/testing/selftests/bpf/cgroup_helpers.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,20 @@ int setup_classid_environment(void)
523523
return 1;
524524
}
525525

526-
if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls") &&
527-
errno != EBUSY) {
528-
log_err("mount cgroup net_cls");
529-
return 1;
526+
if (mount("net_cls", NETCLS_MOUNT_PATH, "cgroup", 0, "net_cls")) {
527+
if (errno != EBUSY) {
528+
log_err("mount cgroup net_cls");
529+
return 1;
530+
}
531+
532+
if (rmdir(NETCLS_MOUNT_PATH)) {
533+
log_err("rmdir cgroup net_cls");
534+
return 1;
535+
}
536+
if (umount(CGROUP_MOUNT_DFLT)) {
537+
log_err("umount cgroup base");
538+
return 1;
539+
}
530540
}
531541

532542
cleanup_classid_environment();

0 commit comments

Comments
 (0)