Skip to content

Commit f419927

Browse files
laoarMartin KaFai Lau
authored and
Martin KaFai Lau
committed
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 <[email protected]> Acked-by: Tejun Heo <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 73d9eb3 commit f419927

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tools/testing/selftests/bpf/cgroup_helpers.c

+16
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,19 @@ int get_cgroup1_hierarchy_id(const char *subsys_name)
689689
fclose(file);
690690
return found ? id : -1;
691691
}
692+
693+
/**
694+
* open_classid() - Open a cgroupv1 net_cls classid
695+
*
696+
* This function expects the cgroup work dir to be already created, as we
697+
* open it here.
698+
*
699+
* On success, it returns the file descriptor. On failure it returns -1.
700+
*/
701+
int open_classid(void)
702+
{
703+
char cgroup_workdir[PATH_MAX + 1];
704+
705+
format_classid_path(cgroup_workdir);
706+
return open(cgroup_workdir, O_RDONLY);
707+
}

tools/testing/selftests/bpf/cgroup_helpers.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void cleanup_cgroup_environment(void);
3333
int set_classid(void);
3434
int join_classid(void);
3535
unsigned long long get_classid_cgroup_id(void);
36+
int open_classid(void);
3637

3738
int setup_classid_environment(void);
3839
void cleanup_classid_environment(void);

0 commit comments

Comments
 (0)