函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\cgroup.c Create Date:2022-07-27 14:46:06
Last Modify:2020-03-12 14:18:49 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:__cgroup_bpf_attach() - Attach the program to a cgroup, and* propagate the change to descendants*@cgrp: The cgroup which descendants to traverse*@prog: A program to attach*@type: Type of attach operation*@flags: Option flags

函数原型:int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, enum bpf_attach_type type, u32 flags)

返回类型:int

参数:

类型参数名称
struct cgroup *cgrp
struct bpf_prog *prog
enum bpf_attach_typetype
u32flags
301  progs等于 attached progs to this cgroup and attach flags * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will * have either zero or one element * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS[type]
302  struct bpf_prog * old_prog = NULL
303  struct bpf_cgroup_storage * storage[__BPF_CGROUP_STORAGE_MAX], * old_storage[__BPF_CGROUP_STORAGE_MAX] = {NULL}
310  如果flags按位与cgroup-bpf attach flags used in BPF_PROG_ATTACH command* NONE(default): No further bpf programs allowed in the subtreeflags按位与BPF_F_ALLOW_MULTI则返回:负EINVAL
314  如果非 parent has non-overridable prog attached,* disallow attaching new programs to the descendent cgroup.* if parent has overridable or multi-prog, allow attaching则返回:负EPERM
317  如果非链表为空flags[type]不等于flags则返回:负EPERM
324  如果 number of elements in the list.* it's slow but the list cannot be long大于等于BPF_CGROUP_MAX_PROGS则返回:负E2BIG
328  storage[stype]等于bpf_cgroup_storage_alloc(prog, stype)
329  如果是错误
330  storage[stype] = NULL
331  for_each_cgroup_storage_type(stype)
332  bpf_cgroup_storage_free(storage[stype])
333  返回:负ENOMEM
337  如果flags按位与BPF_F_ALLOW_MULTI
339  如果prog恒等于prog
343  返回:负EINVAL
347  pl等于开辟内存
348  如果非pl
349  for_each_cgroup_storage_type(stype)
350  bpf_cgroup_storage_free(storage[stype])
351  返回:负ENOMEM
354  pl_was_allocated = true
355  prog等于prog
356  for_each_cgroup_storage_type(stype)
357  storage[stype]等于storage[stype]
358  添加链表项
359  否则
360  如果链表为空
361  pl等于开辟内存
362  如果非pl
367  pl_was_allocated = true
369  否则
371  old_prog等于prog
376  pl_was_allocated = false
378  prog等于prog
379  for_each_cgroup_storage_type(stype)
380  storage[stype]等于storage[stype]
383  flags[type]等于flags
385  err等于update_effective_progs(cgrp, type)
386  如果err则转到:cleanup
389  Advanced usage; refcount, branch is enabled when: count != 0( & cgroup_bpf_enabled_key)
391  如果非old_storage[stype]则继续下一循环
393  bpf_cgroup_storage_free(old_storage[stype])
395  如果old_prog
396  bpf_prog_put(old_prog)
397  static_branch_dec( & cgroup_bpf_enabled_key)
399  for_each_cgroup_storage_type(stype)
400  bpf_cgroup_storage_link(storage[stype], cgrp, type)
401  返回:0
403  cleanup :
405  prog等于old_prog
407  bpf_cgroup_storage_free(storage[stype])
408  storage[stype]等于old_storage[stype]
409  bpf_cgroup_storage_link(old_storage[stype], cgrp, type)
411  如果pl_was_allocated
412  删除链表项
413  kfree(pl)
415  返回:err
调用者
名称描述
cgroup_bpf_attachsock->sk_cgrp_data handling. For more info, see sock_cgroup_data* definition in cgroup-defs.h.