Skip to content

Commit 7218ff1

Browse files
mykyta5anakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 122f1fd commit 7218ff1

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
@@ -4845,14 +4845,19 @@ static int bpf_get_map_info_from_fdinfo(int fd, struct bpf_map_info *info)
48454845
return 0;
48464846
}
48474847

4848+
static bool map_is_created(const struct bpf_map *map)
4849+
{
4850+
return map->obj->loaded || map->reused;
4851+
}
4852+
48484853
bool bpf_map__autocreate(const struct bpf_map *map)
48494854
{
48504855
return map->autocreate;
48514856
}
48524857

48534858
int bpf_map__set_autocreate(struct bpf_map *map, bool autocreate)
48544859
{
4855-
if (map->obj->loaded)
4860+
if (map_is_created(map))
48564861
return libbpf_err(-EBUSY);
48574862

48584863
map->autocreate = autocreate;
@@ -4946,7 +4951,7 @@ struct bpf_map *bpf_map__inner_map(struct bpf_map *map)
49464951

49474952
int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries)
49484953
{
4949-
if (map->obj->loaded)
4954+
if (map_is_created(map))
49504955
return libbpf_err(-EBUSY);
49514956

49524957
map->def.max_entries = max_entries;
@@ -5191,11 +5196,6 @@ bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map)
51915196

51925197
static void bpf_map__destroy(struct bpf_map *map);
51935198

5194-
static bool map_is_created(const struct bpf_map *map)
5195-
{
5196-
return map->obj->loaded || map->reused;
5197-
}
5198-
51995199
static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, bool is_inner)
52005200
{
52015201
LIBBPF_OPTS(bpf_map_create_opts, create_attr);
@@ -10299,7 +10299,7 @@ static int map_btf_datasec_resize(struct bpf_map *map, __u32 size)
1029910299

1030010300
int bpf_map__set_value_size(struct bpf_map *map, __u32 size)
1030110301
{
10302-
if (map->obj->loaded || map->reused)
10302+
if (map_is_created(map))
1030310303
return libbpf_err(-EBUSY);
1030410304

1030510305
if (map->mmaped) {
@@ -10345,7 +10345,7 @@ int bpf_map__set_initial_value(struct bpf_map *map,
1034510345
{
1034610346
size_t actual_sz;
1034710347

10348-
if (map->obj->loaded || map->reused)
10348+
if (map_is_created(map))
1034910349
return libbpf_err(-EBUSY);
1035010350

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

0 commit comments

Comments
 (0)