Commit 94cb310c authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Daniel Borkmann
Browse files

bpf: libbpf: remove map name retry from bpf_create_map_xattr



Instead, check for a newly created caps.name bpf_object capability.
If kernel doesn't support names, don't specify the attribute.

See commit 23499442 ("bpf: libbpf: retry map creation without
the name") for rationale.

Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 47eff617
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
{
	__u32 name_len = create_attr->name ? strlen(create_attr->name) : 0;
	union bpf_attr attr;
	int ret;

	memset(&attr, '\0', sizeof(attr));

@@ -87,16 +86,8 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
	attr.map_ifindex = create_attr->map_ifindex;
	attr.inner_map_fd = create_attr->inner_map_fd;

	ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
	if (ret < 0 && errno == EINVAL && create_attr->name) {
		/* Retry the same syscall, but without the name.
		 * Pre v4.14 kernels don't support map names.
		 */
		memset(attr.map_name, 0, sizeof(attr.map_name));
	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
}
	return ret;
}

int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
			int key_size, int value_size, int max_entries,
+2 −1
Original line number Diff line number Diff line
@@ -1211,6 +1211,7 @@ bpf_object__create_maps(struct bpf_object *obj)
			continue;
		}

		if (obj->caps.name)
			create_attr.name = map->name;
		create_attr.map_ifindex = map->map_ifindex;
		create_attr.map_type = def->type;