aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/bpf/cgroup_helpers.c
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2023-12-06 11:53:25 +0000
committerMartin KaFai Lau <martin.lau@kernel.org>2023-12-08 17:08:18 -0800
commitf4199271dae12ae407fa739e7012914ea6b3f37b (patch)
treef45ea4d4106916951d18033bbe40d446916a779f /tools/testing/selftests/bpf/cgroup_helpers.c
parentbpf: Enable bpf_cgrp_storage for cgroup1 non-attach case (diff)
downloadwireguard-linux-f4199271dae12ae407fa739e7012914ea6b3f37b.tar.xz
wireguard-linux-f4199271dae12ae407fa739e7012914ea6b3f37b.zip
selftests/bpf: Add a new cgroup helper open_classid()
This new helper allows us to obtain the fd of a net_cls cgroup, which will be utilized in the subsequent patch. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20231206115326.4295-3-laoar.shao@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/cgroup_helpers.c')
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index 5aa133bf3688..19be9c63d5e8 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -689,3 +689,19 @@ int get_cgroup1_hierarchy_id(const char *subsys_name)
fclose(file);
return found ? id : -1;
}
+
+/**
+ * open_classid() - Open a cgroupv1 net_cls classid
+ *
+ * This function expects the cgroup work dir to be already created, as we
+ * open it here.
+ *
+ * On success, it returns the file descriptor. On failure it returns -1.
+ */
+int open_classid(void)
+{
+ char cgroup_workdir[PATH_MAX + 1];
+
+ format_classid_path(cgroup_workdir);
+ return open(cgroup_workdir, O_RDONLY);
+}