Skip to content

Commit

Permalink
selftests/bpf: Add a new cgroup helper open_classid()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
laoar authored and Martin KaFai Lau committed Dec 9, 2023
1 parent 73d9eb3 commit f419927
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/testing/selftests/bpf/cgroup_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/cgroup_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void cleanup_cgroup_environment(void);
int set_classid(void);
int join_classid(void);
unsigned long long get_classid_cgroup_id(void);
int open_classid(void);

int setup_classid_environment(void);
void cleanup_classid_environment(void);
Expand Down

0 comments on commit f419927

Please sign in to comment.