Netdev List
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels.
@ 2021-12-09  8:44 Shuyi Cheng
  2021-12-09 17:26 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Shuyi Cheng @ 2021-12-09  8:44 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools)


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/20211123200105.387855-1-andrii@kernel.org

Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com>
---
  tools/lib/bpf/libbpf.c | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6db0b5e8540e..d96cf49cebab 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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;

-- 
2.19.1.6.gb485710b

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-10  3:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-09  8:44 [PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels Shuyi Cheng
2021-12-09 17:26 ` Andrii Nakryiko
2021-12-10  3:02   ` Shuyi Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox