Skip to content

Commit e30d009

Browse files
laoarKernel Patches Daemon
authored andcommitted
bpf: Add a new kfunc for cgroup1 hierarchy
A new kfunc is added to acquire cgroup1 of a task: - bpf_task_get_cgroup1 Acquires the associated cgroup of a task whithin a specific cgroup1 hierarchy. The cgroup1 hierarchy is identified by its hierarchy ID. This new kfunc enables the tracing of tasks within a designated container or cgroup directory in BPF programs. Suggested-by: Tejun Heo <[email protected]> Signed-off-by: Yafang Shao <[email protected]>
1 parent 7d66216 commit e30d009

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

kernel/bpf/helpers.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,25 @@ __bpf_kfunc long bpf_task_under_cgroup(struct task_struct *task,
22262226
rcu_read_unlock();
22272227
return ret;
22282228
}
2229+
2230+
/**
2231+
* bpf_task_get_cgroup1 - Acquires the associated cgroup of a task within a
2232+
* specific cgroup1 hierarchy. The cgroup1 hierarchy is identified by its
2233+
* hierarchy ID.
2234+
* @task: The target task
2235+
* @hierarchy_id: The ID of a cgroup1 hierarchy
2236+
*
2237+
* On success, the cgroup is returen. On failure, NULL is returned.
2238+
*/
2239+
__bpf_kfunc struct cgroup *
2240+
bpf_task_get_cgroup1(struct task_struct *task, int hierarchy_id)
2241+
{
2242+
struct cgroup *cgrp = task_get_cgroup1(task, hierarchy_id);
2243+
2244+
if (IS_ERR(cgrp))
2245+
return NULL;
2246+
return cgrp;
2247+
}
22292248
#endif /* CONFIG_CGROUPS */
22302249

22312250
/**
@@ -2532,6 +2551,7 @@ BTF_ID_FLAGS(func, bpf_cgroup_release, KF_RELEASE)
25322551
BTF_ID_FLAGS(func, bpf_cgroup_ancestor, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
25332552
BTF_ID_FLAGS(func, bpf_cgroup_from_id, KF_ACQUIRE | KF_RET_NULL)
25342553
BTF_ID_FLAGS(func, bpf_task_under_cgroup, KF_RCU)
2554+
BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
25352555
#endif
25362556
BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
25372557
BTF_ID_FLAGS(func, bpf_throw)

0 commit comments

Comments
 (0)