Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Yafang Shao and committed by
Martin KaFai Lau
f4199271 73d9eb34

+17
+16
tools/testing/selftests/bpf/cgroup_helpers.c
··· 689 689 fclose(file); 690 690 return found ? id : -1; 691 691 } 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 + }
+1
tools/testing/selftests/bpf/cgroup_helpers.h
··· 33 33 int set_classid(void); 34 34 int join_classid(void); 35 35 unsigned long long get_classid_cgroup_id(void); 36 + int open_classid(void); 36 37 37 38 int setup_classid_environment(void); 38 39 void cleanup_classid_environment(void);