Skip to content

Commit 9c6e755

Browse files
committed
libbpf: Use map_is_created helper in map setters
JIRA: https://issues.redhat.com/browse/RHEL-78202 commit 6ef78c4 Author: Mykyta Yatsenko <yatsenko@meta.com> Date: Mon Mar 3 13:57:49 2025 +0000 libbpf: Use map_is_created helper in map setters Refactoring: use map_is_created helper in map setters that need to check the state of the map. This helps to reduce the number of the places that depend explicitly on the loaded flag, simplifying refactoring in the next patch of this set. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20250303135752.158343-2-mykyta.yatsenko5@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Gregory Bell <grbell@redhat.com>
1 parent 99e762a commit 9c6e755

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,14 +4836,19 @@ static int bpf_get_map_info_from_fdinfo(int fd, struct bpf_map_info *info)
48364836
return 0;
48374837
}
48384838

4839+
static bool map_is_created(const struct bpf_map *map)
4840+
{
4841+
return map->obj->loaded || map->reused;
4842+
}
4843+
48394844
bool bpf_map__autocreate(const struct bpf_map *map)
48404845
{
48414846
return map->autocreate;
48424847
}
48434848

48444849
int bpf_map__set_autocreate(struct bpf_map *map, bool autocreate)
48454850
{
4846-
if (map->obj->loaded)
4851+
if (map_is_created(map))
48474852
return libbpf_err(-EBUSY);
48484853

48494854
map->autocreate = autocreate;
@@ -4937,7 +4942,7 @@ struct bpf_map *bpf_map__inner_map(struct bpf_map *map)
49374942

49384943
int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries)
49394944
{
4940-
if (map->obj->loaded)
4945+
if (map_is_created(map))
49414946
return libbpf_err(-EBUSY);
49424947

49434948
map->def.max_entries = max_entries;
@@ -5182,11 +5187,6 @@ bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map)
51825187

51835188
static void bpf_map__destroy(struct bpf_map *map);
51845189

5185-
static bool map_is_created(const struct bpf_map *map)
5186-
{
5187-
return map->obj->loaded || map->reused;
5188-
}
5189-
51905190
static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, bool is_inner)
51915191
{
51925192
LIBBPF_OPTS(bpf_map_create_opts, create_attr);
@@ -10290,7 +10290,7 @@ static int map_btf_datasec_resize(struct bpf_map *map, __u32 size)
1029010290

1029110291
int bpf_map__set_value_size(struct bpf_map *map, __u32 size)
1029210292
{
10293-
if (map->obj->loaded || map->reused)
10293+
if (map_is_created(map))
1029410294
return libbpf_err(-EBUSY);
1029510295

1029610296
if (map->mmaped) {
@@ -10336,7 +10336,7 @@ int bpf_map__set_initial_value(struct bpf_map *map,
1033610336
{
1033710337
size_t actual_sz;
1033810338

10339-
if (map->obj->loaded || map->reused)
10339+
if (map_is_created(map))
1034010340
return libbpf_err(-EBUSY);
1034110341

1034210342
if (!map->mmaped || map->libbpf_type == LIBBPF_MAP_KCONFIG)

0 commit comments

Comments
 (0)