Commit d4ffb6f3 authored by Hao Luo's avatar Hao Luo Committed by Martin KaFai Lau

bpf: Add CGROUP prefix to cgroup_iter_order

bpf_cgroup_iter_order is globally visible but the entries do not have
CGROUP prefix. As requested by Andrii, put a CGROUP in the names
in bpf_cgroup_iter_order.

This patch fixes two previous commits: one introduced the API and
the other uses the API in bpf selftest (that is, the selftest
cgroup_hierarchical_stats).

I tested this patch via the following command:

  test_progs -t cgroup,iter,btf_dump

Fixes: d4ccaf58 ("bpf: Introduce cgroup iter")
Fixes: 88886309 ("selftests/bpf: add a selftest for cgroup hierarchical stats collection")
Suggested-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarHao Luo <haoluo@google.com>
Link: https://lore.kernel.org/r/20220825223936.1865810-1-haoluo@google.comSigned-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
parent 0a0d55ef
...@@ -88,11 +88,11 @@ struct bpf_cgroup_storage_key { ...@@ -88,11 +88,11 @@ struct bpf_cgroup_storage_key {
}; };
enum bpf_cgroup_iter_order { enum bpf_cgroup_iter_order {
BPF_ITER_ORDER_UNSPEC = 0, BPF_CGROUP_ITER_ORDER_UNSPEC = 0,
BPF_ITER_SELF_ONLY, /* process only a single object. */ BPF_CGROUP_ITER_SELF_ONLY, /* process only a single object. */
BPF_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */ BPF_CGROUP_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */
BPF_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */ BPF_CGROUP_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */
BPF_ITER_ANCESTORS_UP, /* walk ancestors upward. */ BPF_CGROUP_ITER_ANCESTORS_UP, /* walk ancestors upward. */
}; };
union bpf_iter_link_info { union bpf_iter_link_info {
......
...@@ -74,13 +74,13 @@ static void *cgroup_iter_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -74,13 +74,13 @@ static void *cgroup_iter_seq_start(struct seq_file *seq, loff_t *pos)
++*pos; ++*pos;
p->terminate = false; p->terminate = false;
p->visited_all = false; p->visited_all = false;
if (p->order == BPF_ITER_DESCENDANTS_PRE) if (p->order == BPF_CGROUP_ITER_DESCENDANTS_PRE)
return css_next_descendant_pre(NULL, p->start_css); return css_next_descendant_pre(NULL, p->start_css);
else if (p->order == BPF_ITER_DESCENDANTS_POST) else if (p->order == BPF_CGROUP_ITER_DESCENDANTS_POST)
return css_next_descendant_post(NULL, p->start_css); return css_next_descendant_post(NULL, p->start_css);
else if (p->order == BPF_ITER_ANCESTORS_UP) else if (p->order == BPF_CGROUP_ITER_ANCESTORS_UP)
return p->start_css; return p->start_css;
else /* BPF_ITER_SELF_ONLY */ else /* BPF_CGROUP_ITER_SELF_ONLY */
return p->start_css; return p->start_css;
} }
...@@ -109,13 +109,13 @@ static void *cgroup_iter_seq_next(struct seq_file *seq, void *v, loff_t *pos) ...@@ -109,13 +109,13 @@ static void *cgroup_iter_seq_next(struct seq_file *seq, void *v, loff_t *pos)
if (p->terminate) if (p->terminate)
return NULL; return NULL;
if (p->order == BPF_ITER_DESCENDANTS_PRE) if (p->order == BPF_CGROUP_ITER_DESCENDANTS_PRE)
return css_next_descendant_pre(curr, p->start_css); return css_next_descendant_pre(curr, p->start_css);
else if (p->order == BPF_ITER_DESCENDANTS_POST) else if (p->order == BPF_CGROUP_ITER_DESCENDANTS_POST)
return css_next_descendant_post(curr, p->start_css); return css_next_descendant_post(curr, p->start_css);
else if (p->order == BPF_ITER_ANCESTORS_UP) else if (p->order == BPF_CGROUP_ITER_ANCESTORS_UP)
return curr->parent; return curr->parent;
else /* BPF_ITER_SELF_ONLY */ else /* BPF_CGROUP_ITER_SELF_ONLY */
return NULL; return NULL;
} }
...@@ -188,10 +188,10 @@ static int bpf_iter_attach_cgroup(struct bpf_prog *prog, ...@@ -188,10 +188,10 @@ static int bpf_iter_attach_cgroup(struct bpf_prog *prog,
int order = linfo->cgroup.order; int order = linfo->cgroup.order;
struct cgroup *cgrp; struct cgroup *cgrp;
if (order != BPF_ITER_DESCENDANTS_PRE && if (order != BPF_CGROUP_ITER_DESCENDANTS_PRE &&
order != BPF_ITER_DESCENDANTS_POST && order != BPF_CGROUP_ITER_DESCENDANTS_POST &&
order != BPF_ITER_ANCESTORS_UP && order != BPF_CGROUP_ITER_ANCESTORS_UP &&
order != BPF_ITER_SELF_ONLY) order != BPF_CGROUP_ITER_SELF_ONLY)
return -EINVAL; return -EINVAL;
if (fd && id) if (fd && id)
...@@ -239,13 +239,13 @@ static void bpf_iter_cgroup_show_fdinfo(const struct bpf_iter_aux_info *aux, ...@@ -239,13 +239,13 @@ static void bpf_iter_cgroup_show_fdinfo(const struct bpf_iter_aux_info *aux,
kfree(buf); kfree(buf);
show_order: show_order:
if (aux->cgroup.order == BPF_ITER_DESCENDANTS_PRE) if (aux->cgroup.order == BPF_CGROUP_ITER_DESCENDANTS_PRE)
seq_puts(seq, "order: descendants_pre\n"); seq_puts(seq, "order: descendants_pre\n");
else if (aux->cgroup.order == BPF_ITER_DESCENDANTS_POST) else if (aux->cgroup.order == BPF_CGROUP_ITER_DESCENDANTS_POST)
seq_puts(seq, "order: descendants_post\n"); seq_puts(seq, "order: descendants_post\n");
else if (aux->cgroup.order == BPF_ITER_ANCESTORS_UP) else if (aux->cgroup.order == BPF_CGROUP_ITER_ANCESTORS_UP)
seq_puts(seq, "order: ancestors_up\n"); seq_puts(seq, "order: ancestors_up\n");
else /* BPF_ITER_SELF_ONLY */ else /* BPF_CGROUP_ITER_SELF_ONLY */
seq_puts(seq, "order: self_only\n"); seq_puts(seq, "order: self_only\n");
} }
......
...@@ -88,11 +88,11 @@ struct bpf_cgroup_storage_key { ...@@ -88,11 +88,11 @@ struct bpf_cgroup_storage_key {
}; };
enum bpf_cgroup_iter_order { enum bpf_cgroup_iter_order {
BPF_ITER_ORDER_UNSPEC = 0, BPF_CGROUP_ITER_ORDER_UNSPEC = 0,
BPF_ITER_SELF_ONLY, /* process only a single object. */ BPF_CGROUP_ITER_SELF_ONLY, /* process only a single object. */
BPF_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */ BPF_CGROUP_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */
BPF_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */ BPF_CGROUP_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */
BPF_ITER_ANCESTORS_UP, /* walk ancestors upward. */ BPF_CGROUP_ITER_ANCESTORS_UP, /* walk ancestors upward. */
}; };
union bpf_iter_link_info { union bpf_iter_link_info {
......
...@@ -764,7 +764,7 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d, ...@@ -764,7 +764,7 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
/* union with nested struct */ /* union with nested struct */
TEST_BTF_DUMP_DATA(btf, d, "union", str, union bpf_iter_link_info, BTF_F_COMPACT, TEST_BTF_DUMP_DATA(btf, d, "union", str, union bpf_iter_link_info, BTF_F_COMPACT,
"(union bpf_iter_link_info){.map = (struct){.map_fd = (__u32)1,},.cgroup = (struct){.order = (enum bpf_cgroup_iter_order)BPF_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},}", "(union bpf_iter_link_info){.map = (struct){.map_fd = (__u32)1,},.cgroup = (struct){.order = (enum bpf_cgroup_iter_order)BPF_CGROUP_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},}",
{ .cgroup = { .order = 1, .cgroup_fd = 1, }}); { .cgroup = { .order = 1, .cgroup_fd = 1, }});
/* struct skb with nested structs/unions; because type output is so /* struct skb with nested structs/unions; because type output is so
......
...@@ -275,7 +275,7 @@ static int setup_cgroup_iter(struct cgroup_hierarchical_stats *obj, ...@@ -275,7 +275,7 @@ static int setup_cgroup_iter(struct cgroup_hierarchical_stats *obj,
* traverse one cgroup, so set the traversal order to "self". * traverse one cgroup, so set the traversal order to "self".
*/ */
linfo.cgroup.cgroup_fd = cgroup_fd; linfo.cgroup.cgroup_fd = cgroup_fd;
linfo.cgroup.order = BPF_ITER_SELF_ONLY; linfo.cgroup.order = BPF_CGROUP_ITER_SELF_ONLY;
opts.link_info = &linfo; opts.link_info = &linfo;
opts.link_info_len = sizeof(linfo); opts.link_info_len = sizeof(linfo);
link = bpf_program__attach_iter(obj->progs.dump_vmscan, &opts); link = bpf_program__attach_iter(obj->progs.dump_vmscan, &opts);
......
...@@ -134,7 +134,7 @@ static void test_walk_preorder(struct cgroup_iter *skel) ...@@ -134,7 +134,7 @@ static void test_walk_preorder(struct cgroup_iter *skel)
cg_id[PARENT], cg_id[CHILD1], cg_id[CHILD2]); cg_id[PARENT], cg_id[CHILD1], cg_id[CHILD2]);
read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT], read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT],
BPF_ITER_DESCENDANTS_PRE, "preorder"); BPF_CGROUP_ITER_DESCENDANTS_PRE, "preorder");
} }
/* Postorder walk prints child and parent in order. */ /* Postorder walk prints child and parent in order. */
...@@ -145,7 +145,7 @@ static void test_walk_postorder(struct cgroup_iter *skel) ...@@ -145,7 +145,7 @@ static void test_walk_postorder(struct cgroup_iter *skel)
cg_id[CHILD1], cg_id[CHILD2], cg_id[PARENT]); cg_id[CHILD1], cg_id[CHILD2], cg_id[PARENT]);
read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT], read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT],
BPF_ITER_DESCENDANTS_POST, "postorder"); BPF_CGROUP_ITER_DESCENDANTS_POST, "postorder");
} }
/* Walking parents prints parent and then root. */ /* Walking parents prints parent and then root. */
...@@ -159,7 +159,7 @@ static void test_walk_ancestors_up(struct cgroup_iter *skel) ...@@ -159,7 +159,7 @@ static void test_walk_ancestors_up(struct cgroup_iter *skel)
cg_id[PARENT], cg_id[ROOT]); cg_id[PARENT], cg_id[ROOT]);
read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT], read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT],
BPF_ITER_ANCESTORS_UP, "ancestors_up"); BPF_CGROUP_ITER_ANCESTORS_UP, "ancestors_up");
skel->bss->terminal_cgroup = 0; skel->bss->terminal_cgroup = 0;
} }
...@@ -174,7 +174,7 @@ static void test_early_termination(struct cgroup_iter *skel) ...@@ -174,7 +174,7 @@ static void test_early_termination(struct cgroup_iter *skel)
PROLOGUE "%8llu\n" EPILOGUE, cg_id[PARENT]); PROLOGUE "%8llu\n" EPILOGUE, cg_id[PARENT]);
read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT], read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT],
BPF_ITER_DESCENDANTS_PRE, "early_termination"); BPF_CGROUP_ITER_DESCENDANTS_PRE, "early_termination");
skel->bss->terminate_early = 0; skel->bss->terminate_early = 0;
} }
...@@ -186,7 +186,7 @@ static void test_walk_self_only(struct cgroup_iter *skel) ...@@ -186,7 +186,7 @@ static void test_walk_self_only(struct cgroup_iter *skel)
PROLOGUE "%8llu\n" EPILOGUE, cg_id[PARENT]); PROLOGUE "%8llu\n" EPILOGUE, cg_id[PARENT]);
read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT], read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[PARENT],
BPF_ITER_SELF_ONLY, "self_only"); BPF_CGROUP_ITER_SELF_ONLY, "self_only");
} }
void test_cgroup_iter(void) void test_cgroup_iter(void)
......
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