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.
Unified · Split
| @@ -431,6 +431,7 @@ struct bpf_map { · 430 unmodified lines | ||
| 431 | 431 | char *pin_path; |
| 432 | 432 | bool pinned; |
| 433 | 433 | bool reused; |
| 434 | + bool skipped; | |
| 434 | 435 | __u64 map_extra; |
| 435 | 436 | }; |
| 436 | 437 | |
| @@ -5087,8 +5088,10 @@ bpf_object__create_maps(struct bpf_object *obj) · 4650 unmodified lines | ||
| 5087 | 5088 | * kernels. |
| 5088 | 5089 | */ |
| 5089 | 5090 | if (bpf_map__is_internal(map) && |
| 5090 | − !kernel_supports(obj, FEAT_GLOBAL_DATA)) | |
| 5091 | + !kernel_supports(obj, FEAT_GLOBAL_DATA)) { | |
| 5092 | + map->skipped = true; | |
| 5091 | 5093 | continue; |
| 5094 | + } | |
| 5092 | 5095 | |
| 5093 | 5096 | retried = false; |
| 5094 | 5097 | retry: |
| @@ -5717,8 +5720,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog) · 622 unmodified lines | ||
| 5717 | 5720 | } else { |
| 5718 | 5721 | const struct bpf_map *map = &obj->maps[relo->map_idx]; |
| 5719 | 5722 | |
| 5720 | − if (bpf_map__is_internal(map) && | |
| 5721 | − !kernel_supports(obj, FEAT_GLOBAL_DATA)) { | |
| 5723 | + if (map->skipped) { | |
| 5722 | 5724 | pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n", |
| 5723 | 5725 | prog->name, i); |
| 5724 | 5726 | return -ENOTSUP; |
| @@ -7926,6 +7928,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) · 2201 unmodified lines | ||
| 7926 | 7928 | char *pin_path = NULL; |
| 7927 | 7929 | char buf[PATH_MAX]; |
| 7928 | 7930 | |
| 7931 | + if (map->skipped) | |
| 7932 | + continue; | |
| 7933 | + | |
| 7929 | 7934 | if (path) { |
| 7930 | 7935 | int len; |
| 7931 | 7936 | |