Re: [PATCH bpf-next 4/4] bpftool: Generate helpers for pinning prog through bpf object skeleton

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 25, 2022 at 10:03 PM Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote:
>
> On 4/23/22 4:00 PM, Yafang Shao wrote:
> > After this change, with command 'bpftool gen skeleton XXX.bpf.o', the
> > helpers for pinning BPF prog will be generated in BPF object skeleton. It
> > could simplify userspace code which wants to pin bpf progs in bpffs.
> >
> > The new helpers are named with __{pin, unpin}_prog, because it only pins
> > bpf progs. If the user also wants to pin bpf maps in bpffs, he can use
> > LIBBPF_PIN_BY_NAME.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >   tools/bpf/bpftool/gen.c | 16 ++++++++++++++++
> >   1 file changed, 16 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> > index 8f76d8d9996c..1d06ebde723b 100644
> > --- a/tools/bpf/bpftool/gen.c
> > +++ b/tools/bpf/bpftool/gen.c
> > @@ -1087,6 +1087,8 @@ static int do_skeleton(int argc, char **argv)
> >                       static inline int load(struct %1$s *skel);          \n\
> >                       static inline int attach(struct %1$s *skel);        \n\
> >                       static inline void detach(struct %1$s *skel);       \n\
> > +                     static inline int pin_prog(struct %1$s *skel, const char *path);\n\
> > +                     static inline void unpin_prog(struct %1$s *skel);   \n\
> >                       static inline void destroy(struct %1$s *skel);      \n\
> >                       static inline const void *elf_bytes(size_t *sz);    \n\
> >               #endif /* __cplusplus */                                    \n\
> > @@ -1172,6 +1174,18 @@ static int do_skeleton(int argc, char **argv)
> >               %1$s__detach(struct %1$s *obj)                              \n\
> >               {                                                           \n\
> >                       bpf_object__detach_skeleton(obj->skeleton);         \n\
> > +             }                                                           \n\
> > +                                                                         \n\
> > +             static inline int                                           \n\
> > +             %1$s__pin_prog(struct %1$s *obj, const char *path)          \n\
> > +             {                                                           \n\
> > +                     return bpf_object__pin_skeleton_prog(obj->skeleton, path);\n\
> > +             }                                                           \n\
> > +                                                                         \n\
> > +             static inline void                                          \n\
> > +             %1$s__unpin_prog(struct %1$s *obj)                          \n\
> > +             {                                                           \n\
> > +                     bpf_object__unpin_skeleton_prog(obj->skeleton);     \n\
> >               }                                                           \n\
>
> (This should also have BPF selftest code as in-tree user.)
>

Will do it, thanks.

[snip]

-- 
Regards
Yafang



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux