libbpf: Skip the pinning of global data map for old kernels.
Subsystems (4)
PATCH 1/1 libbpf: Skip the pinning of global data map for old kernels.
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.
[0]: https://lore.kernel.org/bpf/[email protected]
--- tools/lib/bpf/libbpf.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +4 -0
@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)char *pin_path =NULL ;char buf[PATH_MAX ]; +if (bpf_map__is_internal (map) && + !kernel_supports (obj,FEAT_GLOBAL_DATA )) +continue ; +if (path) {int len;
Signature · 1 line
2.19.1.6.gb485710b
Quoted 21 lines · Shuyi Cheng
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_mapsreturning error.[0]: https://lore.kernel.org/bpf/[email protected]
Signed-off-by Shuyi Cheng <[email protected]>--- tools/lib/bpf/libbpf.c | 4 ++++ 1 file changed, 4 insertions(+)tools/lib/bpf/libbpf.c +0
-0
tools/lib/bpf/libbpf.c int bpf_object__pin_maps(struct bpf_object *obj, · line 7889
Quoted 6 lines
tools/lib/bpf/libbpf.c +2
-0@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) char *pin_path = NULL;char buf[PATH_MAX ]; +if (bpf_map__is_internal (map) && + !kernel_supports (obj,FEAT_GLOBAL_DATA ))
doing the same check in 3 different places sucks. Let's add "bool skipped" to struct bpf_map, which will be set in one place (at the map creation time) and then check during relocation and during pinning?
Quoted 7 lines
tools/lib/bpf/libbpf.c +2
-1+continue ; +if (path) {int len; --2.19.1.6.gb485710b
Quoted 27 lines · Andrii Nakryiko
Quoted 25 lines · Shuyi Cheng
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_mapsreturning error.[0]: https://lore.kernel.org/bpf/[email protected]
Signed-off-by Shuyi Cheng <[email protected]>--- tools/lib/bpf/libbpf.c | 4 ++++ 1 file changed, 4 insertions(+)tools/lib/bpf/libbpf.c +0
-0@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) char *pin_path = NULL;char buf[PATH_MAX ];
Quoted 8 lines
tools/lib/bpf/libbpf.c int bpf_object__pin_maps(struct bpf_object *obj, const char *path) · line 7888
Quoted 2 lines
tools/lib/bpf/libbpf.c +2
-0+if (bpf_map__is_internal (map) && + !kernel_supports (obj,FEAT_GLOBAL_DATA ))doing the same check in 3 different places sucks. Let's add "bool skipped" to struct
bpf_map, which will be set in one place (at the map creation time) and then check during relocation and during pinning?
Agree, thanks.
regards,
Shuyi
Quoted 7 lines
Quoted 7 lines
tools/lib/bpf/libbpf.c +2
-1+continue ; +if (path) {int len; --2.19.1.6.gb485710b