summaryrefslogtreecommitdiff
path: root/kernel/bpf/local_storage.c
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-12-15 22:13:52 -0800
committerDaniel Borkmann <daniel@iogearbox.net>2018-12-18 01:11:59 +0100
commitffa0c1cf59596fba54546ea828305acfcc2cf55e (patch)
treeb30071761afe90e0fbc7779429d3381cb1501b53 /kernel/bpf/local_storage.c
parent9d5f9f701b1891466fb3dbb1806ad97716f95cc3 (diff)
bpf: enable cgroup local storage map pretty print with kind_flag
Commit 970289fc0a83 ("bpf: add bpffs pretty print for cgroup local storage maps") added bpffs pretty print for cgroup local storage maps. The commit worked for struct without kind_flag set. This patch refactored and made pretty print also work with kind_flag set for the struct. Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/local_storage.c')
-rw-r--r--kernel/bpf/local_storage.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 5eca03da0989..07a34ef562a0 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -315,9 +315,8 @@ static int cgroup_storage_check_btf(const struct bpf_map *map,
const struct btf_type *key_type,
const struct btf_type *value_type)
{
- const struct btf_type *t;
struct btf_member *m;
- u32 id, size;
+ u32 offset, size;
/* Key is expected to be of struct bpf_cgroup_storage_key type,
* which is:
@@ -338,25 +337,17 @@ static int cgroup_storage_check_btf(const struct bpf_map *map,
* The first field must be a 64 bit integer at 0 offset.
*/
m = (struct btf_member *)(key_type + 1);
- if (m->offset)
- return -EINVAL;
- id = m->type;
- t = btf_type_id_size(btf, &id, NULL);
size = FIELD_SIZEOF(struct bpf_cgroup_storage_key, cgroup_inode_id);
- if (!t || !btf_type_is_reg_int(t, size))
+ if (!btf_member_is_reg_int(btf, key_type, m, 0, size))
return -EINVAL;
/*
* The second field must be a 32 bit integer at 64 bit offset.
*/
m++;
- if (m->offset != offsetof(struct bpf_cgroup_storage_key, attach_type) *
- BITS_PER_BYTE)
- return -EINVAL;
- id = m->type;
- t = btf_type_id_size(btf, &id, NULL);
+ offset = offsetof(struct bpf_cgroup_storage_key, attach_type);
size = FIELD_SIZEOF(struct bpf_cgroup_storage_key, attach_type);
- if (!t || !btf_type_is_reg_int(t, size))
+ if (!btf_member_is_reg_int(btf, key_type, m, offset, size))
return -EINVAL;
return 0;