All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version
@ 2021-11-18  1:20 Andrii Nakryiko
  2021-11-18  4:58 ` John Fastabend
  2021-11-18 10:58 ` Toke Høiland-Jørgensen
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2021-11-18  1:20 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Libbpf provided LIBBPF_MAJOR_VERSION and LIBBPF_MINOR_VERSION macros to
check libbpf version at compilation time. This doesn't cover all the
needs, though, because version of libbpf that application is compiled
against doesn't necessarily match the version of libbpf at runtime,
especially if libbpf is used as a shared library.

Add libbpf_major_version() and libbpf_minor_version() returning major
and minor versions, respectively, as integers. Also add a convenience
libbpf_version_string() for various tooling using libbpf to print out
libbpf version in a human-readable form. Currently it will return
"v0.6", but in the future it can contains some extra information, so the
format itself is not part of a stable API and shouldn't be relied upon.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c   | 19 +++++++++++++++++++
 tools/lib/bpf/libbpf.h   |  4 ++++
 tools/lib/bpf/libbpf.map |  3 +++
 3 files changed, 26 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index de7e09a6b5ec..78de238f975a 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -168,6 +168,25 @@ int libbpf_set_strict_mode(enum libbpf_strict_mode mode)
 	return 0;
 }
 
+__u32 libbpf_major_version(void)
+{
+	return LIBBPF_MAJOR_VERSION;
+}
+
+__u32 libbpf_minor_version(void)
+{
+	return LIBBPF_MINOR_VERSION;
+}
+
+const char *libbpf_version_string(void)
+{
+#define __S(X) #X
+#define _S(X) __S(X)
+	return  "v" _S(LIBBPF_MAJOR_VERSION) "." _S(LIBBPF_MINOR_VERSION);
+#undef _S
+#undef __S
+}
+
 enum kern_feature_id {
 	/* v4.14: kernel support for program & map names. */
 	FEAT_PROG_NAME,
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 4ec69f224342..003fdc5cf3a8 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -24,6 +24,10 @@
 extern "C" {
 #endif
 
+LIBBPF_API __u32 libbpf_major_version(void);
+LIBBPF_API __u32 libbpf_minor_version(void);
+LIBBPF_API const char *libbpf_version_string(void);
+
 enum libbpf_errno {
 	__LIBBPF_ERRNO__START = 4000,
 
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 6a59514a48cf..7f8f515588d1 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -414,4 +414,7 @@ LIBBPF_0.6.0 {
 		perf_buffer__new_deprecated;
 		perf_buffer__new_raw;
 		perf_buffer__new_raw_deprecated;
+		libbpf_major_version;
+		libbpf_minor_version;
+		libbpf_version_string;
 } LIBBPF_0.5.0;
-- 
2.30.2


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

* RE: [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version
  2021-11-18  1:20 [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version Andrii Nakryiko
@ 2021-11-18  4:58 ` John Fastabend
  2021-11-18 10:58 ` Toke Høiland-Jørgensen
  1 sibling, 0 replies; 3+ messages in thread
From: John Fastabend @ 2021-11-18  4:58 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, ast, daniel; +Cc: andrii, kernel-team

Andrii Nakryiko wrote:
> Libbpf provided LIBBPF_MAJOR_VERSION and LIBBPF_MINOR_VERSION macros to
> check libbpf version at compilation time. This doesn't cover all the
> needs, though, because version of libbpf that application is compiled
> against doesn't necessarily match the version of libbpf at runtime,
> especially if libbpf is used as a shared library.
> 
> Add libbpf_major_version() and libbpf_minor_version() returning major
> and minor versions, respectively, as integers. Also add a convenience
> libbpf_version_string() for various tooling using libbpf to print out
> libbpf version in a human-readable form. Currently it will return
> "v0.6", but in the future it can contains some extra information, so the
> format itself is not part of a stable API and shouldn't be relied upon.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---

LGTM.

Acked-by: John Fastabend <john.fastabend@gmail.com>

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

* Re: [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version
  2021-11-18  1:20 [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version Andrii Nakryiko
  2021-11-18  4:58 ` John Fastabend
@ 2021-11-18 10:58 ` Toke Høiland-Jørgensen
  1 sibling, 0 replies; 3+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-11-18 10:58 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, ast, daniel; +Cc: andrii, kernel-team

Andrii Nakryiko <andrii@kernel.org> writes:

> Libbpf provided LIBBPF_MAJOR_VERSION and LIBBPF_MINOR_VERSION macros to
> check libbpf version at compilation time. This doesn't cover all the
> needs, though, because version of libbpf that application is compiled
> against doesn't necessarily match the version of libbpf at runtime,
> especially if libbpf is used as a shared library.
>
> Add libbpf_major_version() and libbpf_minor_version() returning major
> and minor versions, respectively, as integers. Also add a convenience
> libbpf_version_string() for various tooling using libbpf to print out
> libbpf version in a human-readable form. Currently it will return
> "v0.6", but in the future it can contains some extra information, so the
> format itself is not part of a stable API and shouldn't be relied upon.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Great!

Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>


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

end of thread, other threads:[~2021-11-18 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  1:20 [PATCH bpf-next] libbpf: add runtime APIs to query libbpf version Andrii Nakryiko
2021-11-18  4:58 ` John Fastabend
2021-11-18 10:58 ` Toke Høiland-Jørgensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.