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

selftests/bpf: Add cgroup helper remove_cgroup()

Add remove_cgroup() to remove a cgroup which doesn't have any children
or live processes. It will be used by the following patch to test cgroup
iterator on a dead cgroup.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221121073440.1828292-3-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Daniel Borkmann
2a42461a 1a5160d4

+20
+19
tools/testing/selftests/bpf/cgroup_helpers.c
··· 333 333 return fd; 334 334 } 335 335 336 + /* 337 + * remove_cgroup() - Remove a cgroup 338 + * @relative_path: The cgroup path, relative to the workdir, to remove 339 + * 340 + * This function expects a cgroup to already be created, relative to the cgroup 341 + * work dir. It also expects the cgroup doesn't have any children or live 342 + * processes and it removes the cgroup. 343 + * 344 + * On failure, it will print an error to stderr. 345 + */ 346 + void remove_cgroup(const char *relative_path) 347 + { 348 + char cgroup_path[PATH_MAX + 1]; 349 + 350 + format_cgroup_path(cgroup_path, relative_path); 351 + if (rmdir(cgroup_path)) 352 + log_err("rmdiring cgroup %s .. %s", relative_path, cgroup_path); 353 + } 354 + 336 355 /** 337 356 * create_and_get_cgroup() - Create a cgroup, relative to workdir, and get the FD 338 357 * @relative_path: The cgroup path, relative to the workdir, to join
+1
tools/testing/selftests/bpf/cgroup_helpers.h
··· 18 18 int cgroup_setup_and_join(const char *relative_path); 19 19 int get_root_cgroup(void); 20 20 int create_and_get_cgroup(const char *relative_path); 21 + void remove_cgroup(const char *relative_path); 21 22 unsigned long long get_cgroup_id(const char *relative_path); 22 23 23 24 int join_cgroup(const char *relative_path);