Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\cgroup.c Create Date:2022-07-28 13:27:39
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:__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

Proto:int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, enum bpf_attach_type type, u32 flags)

Type:int

Parameter:

TypeParameterName
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  If flags & cgroup-bpf attach flags used in BPF_PROG_ATTACH command* NONE(default): No further bpf programs allowed in the subtree && flags & BPF_F_ALLOW_MULTI Then Return -EINVAL
314  If Not parent has non-overridable prog attached,* disallow attaching new programs to the descendent cgroup.* if parent has overridable or multi-prog, allow attaching Then Return -EPERM
317  If Not list_empty - tests whether a list is empty*@head: the list to test. && flags[type] != flags Then Return -EPERM
324  If number of elements in the list.* it's slow but the list cannot be long >= BPF_CGROUP_MAX_PROGS Then Return -E2BIG
328  storage[stype] = bpf_cgroup_storage_alloc(prog, stype)
329  If IS_ERR(storage[stype]) Then
330  storage[stype] = NULL
331  for_each_cgroup_storage_type(stype)
332  bpf_cgroup_storage_free(storage[stype])
333  Return -ENOMEM
337  If flags & BPF_F_ALLOW_MULTI Then
339  If prog == prog Then
343  Return -EINVAL
347  pl = Allocation memory
348  If Not pl Then
349  for_each_cgroup_storage_type(stype)
350  bpf_cgroup_storage_free(storage[stype])
351  Return -ENOMEM
354  pl_was_allocated = true
355  prog = prog
356  for_each_cgroup_storage_type(stype)
357  storage[stype] = storage[stype]
358  list_add_tail - add a new entry*@new: new entry to be added*@head: list head to add it before* Insert a new entry before the specified head.* This is useful for implementing queues.
359  Else
362  If Not pl Then
367  pl_was_allocated = true
369  Else
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  If err Then Go to cleanup
389  Advanced usage; refcount, branch is enabled when: count != 0( & cgroup_bpf_enabled_key)
391  If Not old_storage[stype] Then Continue
393  bpf_cgroup_storage_free(old_storage[stype])
395  If old_prog Then
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  Return 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  If pl_was_allocated Then
412  deletes entry from list
413  kfree(pl)
415  Return err