#include"../cgroup/cgroup-internal.h"/* cgroup_mutex and cgroup_is_dead */
/* cgroup_iter provides four modes of traversal to the cgroup hierarchy. * * 1. Walk the descendants of a cgroup in pre-order. * 2. Walk the descendants of a cgroup in post-order. * 3. Walk the ancestors of a cgroup. * 4. Show the given cgroup only. * * For walking descendants, cgroup_iter can walk in either pre-order or * post-order. For walking ancestors, the iter walks up from a cgroup to * the root. * * The iter program can terminate the walk early by returning 1. Walk * continues if prog returns 0. * * The prog can check (seq->num == 0) to determine whether this is * the first element. The prog may also be passed a NULL cgroup, * which means the walk has completed and the prog has a chance to * do post-processing, such as outputting an epilogue. * * Note: the iter_prog is called with cgroup_mutex held. * * Currently only one session is supported, which means, depending on the * volume of data bpf program intends to send to user space, the number * of cgroups that can be walked is limited. For example, given the current * buffer size is 8 * PAGE_SIZE, if the program sends 64B data for each * cgroup, assuming PAGE_SIZE is 4kb, the total number of cgroups that can * be walked is 512. This is a limitation of cgroup_iter. If the output data * is larger than the kernel buffer size, after all data in the kernel buffer * is consumed by user space, the subsequent read() syscall will signal * EOPNOTSUPP. In order to work around, the user may have to update their * program to reduce the volume of data sent to output. For example, skip * some uninteresting cgroups.
*/
/* bpf_iter_attach_cgroup() has already acquired an extra reference * for the start cgroup, but the reference may be released after * cgroup_iter_seq_init(), so acquire another reference for the * start cgroup.
*/
p->start_css = &cgrp->self;
css_get(p->start_css);
p->terminate = false;
p->visited_all = false;
p->order = aux->cgroup.order; return 0;
}
staticint bpf_iter_attach_cgroup(struct bpf_prog *prog, union bpf_iter_link_info *linfo, struct bpf_iter_aux_info *aux)
{ int fd = linfo->cgroup.cgroup_fd;
u64 id = linfo->cgroup.cgroup_id; int order = linfo->cgroup.order; struct cgroup *cgrp;
if (order != BPF_CGROUP_ITER_DESCENDANTS_PRE &&
order != BPF_CGROUP_ITER_DESCENDANTS_POST &&
order != BPF_CGROUP_ITER_ANCESTORS_UP &&
order != BPF_CGROUP_ITER_SELF_ONLY) return -EINVAL;
if (fd && id) return -EINVAL;
if (fd)
cgrp = cgroup_v1v2_get_from_fd(fd); elseif (id)
cgrp = cgroup_get_from_id(id); else/* walk the entire hierarchy by default. */
cgrp = cgroup_get_from_path("/");
/* If cgroup_path_ns() fails, buf will be an empty string, cgroup_path * will print nothing. * * Path is in the calling process's cgroup namespace.
*/
cgroup_path_ns(aux->cgroup.start, buf, PATH_MAX,
current->nsproxy->cgroup_ns);
seq_printf(seq, "cgroup_path:\t%s\n", buf);
kfree(buf);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.