History

libbpf: Add "bool skipped" to struct bpf_map

Fix error: "failed to pin map: Bad file descriptor, path: /sys/fs/bpf/_rodata_str1_1." In the old kernel, the global data map will not be created, see [0]. So we should skip the pinning of the global data map to avoid bpf_object__pin_maps returning error. Therefore, when the map is not created, we mark “map->skipped" as true and then check during relocation and during pinning.

Shuyi Cheng committed 4 years ago

Commit 229fae31 parent b69c5c01 file · +8 −3Browse files

Unified · Split

tools/lib/bpf/libbpf.c+8−3
@@ -431,6 +431,7 @@ struct bpf_map { · 430 unmodified lines
431431 char *pin_path;
432432 bool pinned;
433433 bool reused;
434+ bool skipped;
434435 __u64 map_extra;
435436 };
436437
@@ -5087,8 +5088,10 @@ bpf_object__create_maps(struct bpf_object *obj) · 4650 unmodified lines
50875088 * kernels.
50885089 */
50895090 if (bpf_map__is_internal(map) &&
5090− !kernel_supports(obj, FEAT_GLOBAL_DATA))
5091+ !kernel_supports(obj, FEAT_GLOBAL_DATA)) {
5092+ map->skipped = true;
50915093 continue;
5094+ }
50925095
50935096 retried = false;
50945097 retry:
@@ -5717,8 +5720,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog) · 622 unmodified lines
57175720 } else {
57185721 const struct bpf_map *map = &obj->maps[relo->map_idx];
57195722
5720− if (bpf_map__is_internal(map) &&
5721− !kernel_supports(obj, FEAT_GLOBAL_DATA)) {
5723+ if (map->skipped) {
57225724 pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n",
57235725 prog->name, i);
57245726 return -ENOTSUP;
@@ -7926,6 +7928,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) · 2201 unmodified lines
79267928 char *pin_path = NULL;
79277929 char buf[PATH_MAX];
79287930
7931+ if (map->skipped)
7932+ continue;
7933+
79297934 if (path) {
79307935 int len;
79317936