Created
July 22, 2021 13:49
-
-
Save brb/fff66e47586373fdc1fe39b88175036c to your computer and use it in GitHub Desktop.
libbpf map pin race
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/libbpf.c b/src/libbpf.c | |
index a97490c..4587950 100644 | |
--- a/src/libbpf.c | |
+++ b/src/libbpf.c | |
@@ -4686,10 +4686,13 @@ bpf_object__create_maps(struct bpf_object *obj) | |
char *cp, errmsg[STRERR_BUFSIZE]; | |
unsigned int i, j; | |
int err; | |
+ bool retried; | |
for (i = 0; i < obj->nr_maps; i++) { | |
map = &obj->maps[i]; | |
+ retried = false; | |
+retry: | |
if (map->pin_path) { | |
err = bpf_object__reuse_map(map); | |
if (err) { | |
@@ -4697,6 +4700,12 @@ bpf_object__create_maps(struct bpf_object *obj) | |
map->name); | |
goto err_out; | |
} | |
+ if (retried && map->fd < 0) { | |
+ pr_warn("map '%s': cannot find pinned map\n", | |
+ map->name); | |
+ err = -ENOENT; | |
+ goto err_out; | |
+ } | |
} | |
if (map->fd >= 0) { | |
@@ -4730,9 +4739,13 @@ bpf_object__create_maps(struct bpf_object *obj) | |
if (map->pin_path && !map->pinned) { | |
err = bpf_map__pin(map, NULL); | |
if (err) { | |
+ zclose(map->fd); | |
+ if (!retried && err == -EEXIST) { | |
+ retried = true; | |
+ goto retry; | |
+ } | |
pr_warn("map '%s': failed to auto-pin at '%s': %d\n", | |
map->name, map->pin_path, err); | |
- zclose(map->fd); | |
goto err_out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment