On 3/22/23 16:42, Andrii Nakryiko wrote:
On Tue, Mar 21, 2023 at 4:28 PM Kui-Feng Lee <kuifeng@xxxxxxxx> wrote:
Introduce bpf_link__update_map(), which allows to atomically update
underlying struct_ops implementation for given struct_ops BPF link
Signed-off-by: Kui-Feng Lee <kuifeng@xxxxxxxx>
---
tools/lib/bpf/bpf.h | 5 ++++-
tools/lib/bpf/libbpf.c | 35 +++++++++++++++++++++++++++++++++++
tools/lib/bpf/libbpf.h | 1 +
tools/lib/bpf/libbpf.map | 1 +
4 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index f0f786373238..4fae4e698a8e 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -335,7 +335,10 @@ LIBBPF_API int bpf_link_detach(int link_fd);
struct bpf_link_update_opts {
size_t sz; /* size of this struct for forward/backward compatibility */
__u32 flags; /* extra flags */
- __u32 old_prog_fd; /* expected old program FD */
+ union {
+ __u32 old_prog_fd; /* expected old program FD */
+ __u32 old_map_fd; /* expected old map FD */
+ };
so for these low-level wrappers in libbpf with OPTS we've been trying
to avoid unnecessary unions. If you look at bpf_link_create and
bpf_link_create_ops some fields that are in a union in kernel UAPI are
actually listed as separate fields, and libbpf makes sure that both
fields are not specified at the same time (like iter_info_len and
target_btf_id, for instance).
So let's do the same here, instead of making a union, let's have
__u32 old_prog_fd;
__u32 old_map_fd;
and then in bpf_link_update() implementation make sure that both can't
be set at the same time.
Got it! Thanks!
The rest of the patch looks good to me, thanks....