History

bpf: btf: Add pretty print support to the basic arraymap

This patch adds pretty print support to the basic arraymap. Support for other bpf maps can be added later. This patch adds new attrs to the BPF_MAP_CREATE command to allow specifying the btf_fd, btf_key_id and btf_value_id. The BPF_MAP_CREATE can then associate the btf to the map if the creating map supports BTF. A BTF supported map needs to implement two new map ops, map_seq_show_elem() and map_check_btf(). This patch has implemented these new map ops for the basic arraymap. It also adds file_operations, bpffs_map_fops, to the pinned map such that the pinned map can be opened and read. After that, the user has an intuitive way to do "cat bpffs/pathto/a-pinned-map" instead of getting an error. bpffs_map_fops should not be extended further to support other operations. Other operations (e.g. write/key-lookup...) should be realized by the userspace tools (e.g. bpftool) through the BPF_OBJ_GET_INFO_BY_FD, map's lookup/update interface...etc. Follow up patches will allow the userspace to obtain the BTF from a map-fd. Here is a sample output when reading a pinned arraymap with the following map's value: struct map_value { int count_a; int count_b; }; cat /sys/fs/bpf/pinned_array_map: 0: {1,2} 1: {3,4} 2: {5,6} ...

Martin KaFai Lau committed 8 years ago

Commit a26ca7c1 parent 60197cf5 files · +254 −7Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+3−0
@@ -280,6 +280,9 @@ union bpf_attr { · 279 unmodified lines
280 */280 */
281 char map_name[BPF_OBJ_NAME_LEN];281 char map_name[BPF_OBJ_NAME_LEN];
282 __u32 map_ifindex; /* ifindex of netdev to create on */282 __u32 map_ifindex; /* ifindex of netdev to create on */
283 __u32 btf_fd; /* fd pointing to a BTF type data */
284 __u32 btf_key_id; /* BTF type_id of the key */
285 __u32 btf_value_id; /* BTF type_id of the value */
283 };286 };
284 287
285 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */288 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */