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