Commit 2a42461a authored by Hou Tao's avatar Hou Tao Committed by Daniel Borkmann

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: default avatarHou Tao <houtao1@huawei.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221121073440.1828292-3-houtao@huaweicloud.com
parent 1a5160d4
...@@ -333,6 +333,25 @@ int get_root_cgroup(void) ...@@ -333,6 +333,25 @@ int get_root_cgroup(void)
return fd; return fd;
} }
/*
* remove_cgroup() - Remove a cgroup
* @relative_path: The cgroup path, relative to the workdir, to remove
*
* This function expects a cgroup to already be created, relative to the cgroup
* work dir. It also expects the cgroup doesn't have any children or live
* processes and it removes the cgroup.
*
* On failure, it will print an error to stderr.
*/
void remove_cgroup(const char *relative_path)
{
char cgroup_path[PATH_MAX + 1];
format_cgroup_path(cgroup_path, relative_path);
if (rmdir(cgroup_path))
log_err("rmdiring cgroup %s .. %s", relative_path, cgroup_path);
}
/** /**
* create_and_get_cgroup() - Create a cgroup, relative to workdir, and get the FD * create_and_get_cgroup() - Create a cgroup, relative to workdir, and get the FD
* @relative_path: The cgroup path, relative to the workdir, to join * @relative_path: The cgroup path, relative to the workdir, to join
......
...@@ -18,6 +18,7 @@ int write_cgroup_file_parent(const char *relative_path, const char *file, ...@@ -18,6 +18,7 @@ int write_cgroup_file_parent(const char *relative_path, const char *file,
int cgroup_setup_and_join(const char *relative_path); int cgroup_setup_and_join(const char *relative_path);
int get_root_cgroup(void); int get_root_cgroup(void);
int create_and_get_cgroup(const char *relative_path); int create_and_get_cgroup(const char *relative_path);
void remove_cgroup(const char *relative_path);
unsigned long long get_cgroup_id(const char *relative_path); unsigned long long get_cgroup_id(const char *relative_path);
int join_cgroup(const char *relative_path); int join_cgroup(const char *relative_path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment