> From: Quentin Monnet [mailto:quentin.mon...@netronome.com] > > 2017-11-02 16:59 UTC+0900 ~ Prashant Bhole > <bhole_prashant...@lab.ntt.co.jp> > > Added support to show filenames of pinned objects. > > > > For example: > > > > […] > > > > > Signed-off-by: Prashant Bhole <bhole_prashant...@lab.ntt.co.jp> > > --- > > v2: > > - Dynamically identify bpf-fs moutpoint > > - Close files descriptors before returning on error > > - Fixed line break for proper output formatting > > - Code style: wrapped lines > 80, used reverse christmastree style > > Thanks for those changes! > > > > > tools/bpf/bpftool/common.c | 93 > ++++++++++++++++++++++++++++++++++++++++++++++ > > tools/bpf/bpftool/main.c | 8 ++++ > > tools/bpf/bpftool/main.h | 17 +++++++++ > > tools/bpf/bpftool/map.c | 21 +++++++++++ > > tools/bpf/bpftool/prog.c | 24 ++++++++++++ > > 5 files changed, 163 insertions(+) > > > > diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c > > index 4556947709ee..78a16c02c778 100644 > > --- a/tools/bpf/bpftool/common.c > > +++ b/tools/bpf/bpftool/common.c > > @@ -45,6 +45,8 @@ > > #include <sys/mount.h> > > #include <sys/types.h> > > #include <sys/vfs.h> > > +#include <mntent.h> > > +#include <fts.h> > > > > #include <bpf.h> > > > > @@ -290,3 +292,94 @@ void print_hex_data_json(uint8_t *data, size_t len) > > jsonw_printf(json_wtr, "\"0x%02hhx\"", data[i]); > > jsonw_end_array(json_wtr); > > } > > + > > +int build_pinned_obj_table(struct pinned_obj_table *tab, > > + enum bpf_obj_type type) > > +{ > > + struct bpf_prog_info pinned_info = {}; > > + __u32 len = sizeof(pinned_info); > > + struct pinned_obj *obj_node = NULL; > > + enum bpf_obj_type objtype; > > + struct mntent *mntent = NULL; > > + FILE *mntfile = NULL; > > + char *bpf_dir = NULL; > > + FTSENT *ftse = NULL; > > + FTS *ftsp = NULL; > > + int fd, err; > > + > > + mntfile = setmntent("/proc/mounts", "r"); > > + if (!mntfile) > > + return -1; > > + > > + while ((mntent = getmntent(mntfile)) != NULL) { > > + if (strncmp(mntent->mnt_type, "bpf", 3) == 0) { > > + bpf_dir = mntent->mnt_dir; > > + break; > > It works well to find a bpf virtual file system, but it stops after the first > one it > finds, although it is possible to have several bpffs on the system. Since you > already have all the logics, could you move the > fts_read() step inside this loop, so as to browse all existing bpffs instead > of just > the first one? >
Thanks. Sending V3 soon with this change and other coding style fixes. Prashant