Skip to content

Commit

Permalink
backport struct bpf_create_map_attr
Browse files Browse the repository at this point in the history
Since
libbpf/libbpf@7e8d423,
this structure is gone from libbpf.

BCC uses it as a structure to pass around `bcc_create_map_xattr` and
`libbpf_bpf_map_create`.
The alternative would be to modify both libbpf_bpf_map_create and
bcc_create_map_xattr to take each arguments, which I am not sure it
would be any better.
Renamed the struct from `bpf_create_map_xattr` to `bcc_create_map_xattr` to better reflect this is a bcc-provided struct, not bpf anymore.
  • Loading branch information
chantra committed Jun 20, 2022
1 parent e84e46f commit 1900809
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int BPFModule::create_maps(std::map<std::string, std::pair<int, int>> &map_tids,
}

if (pinned_id <= 0) {
struct bpf_create_map_attr attr = {};
struct bcc_create_map_attr attr = {};
attr.map_type = (enum bpf_map_type)map_type;
attr.name = map_name;
attr.key_size = key_size;
Expand Down
6 changes: 3 additions & 3 deletions src/cc/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static uint64_t ptr_to_u64(void *ptr)
return (uint64_t) (unsigned long) ptr;
}

static int libbpf_bpf_map_create(struct bpf_create_map_attr *create_attr)
static int libbpf_bpf_map_create(struct bcc_create_map_attr *create_attr)
{
LIBBPF_OPTS(bpf_map_create_opts, p);

Expand All @@ -326,7 +326,7 @@ static int libbpf_bpf_map_create(struct bpf_create_map_attr *create_attr)
create_attr->value_size, create_attr->max_entries, &p);
}

int bcc_create_map_xattr(struct bpf_create_map_attr *attr, bool allow_rlimit)
int bcc_create_map_xattr(struct bcc_create_map_attr *attr, bool allow_rlimit)
{
unsigned name_len = attr->name ? strlen(attr->name) : 0;
char map_name[BPF_OBJ_NAME_LEN] = {};
Expand Down Expand Up @@ -383,7 +383,7 @@ int bcc_create_map(enum bpf_map_type map_type, const char *name,
int key_size, int value_size,
int max_entries, int map_flags)
{
struct bpf_create_map_attr attr = {};
struct bcc_create_map_attr attr = {};

attr.map_type = map_type;
attr.name = name;
Expand Down
20 changes: 18 additions & 2 deletions src/cc/libbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@
extern "C" {
#endif

struct bpf_create_map_attr;
struct bcc_create_map_attr {
const char *name;
enum bpf_map_type map_type;
__u32 map_flags;
__u32 key_size;
__u32 value_size;
__u32 max_entries;
__u32 numa_node;
__u32 btf_fd;
__u32 btf_key_type_id;
__u32 btf_value_type_id;
__u32 map_ifindex;
union {
__u32 inner_map_fd;
__u32 btf_vmlinux_value_type_id;
};
};
struct bpf_load_program_attr;

enum bpf_probe_attach_type {
Expand All @@ -44,7 +60,7 @@ struct bcc_perf_buffer_opts {
int bcc_create_map(enum bpf_map_type map_type, const char *name,
int key_size, int value_size, int max_entries,
int map_flags);
int bcc_create_map_xattr(struct bpf_create_map_attr *attr, bool allow_rlimit);
int bcc_create_map_xattr(struct bcc_create_map_attr *attr, bool allow_rlimit);
int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
Expand Down

0 comments on commit 1900809

Please sign in to comment.