On Thu, Oct 24, 2019 at 6:11 AM Toke Høiland-Jørgensen <toke@xxxxxxxxxx> wrote: > > From: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> > > This adds support to libbpf for setting map pinning information as part of > the BTF map declaration. We introduce a version new > bpf_object__map_pin_opts() function to pin maps based on this setting, as > well as a getter and setter function for the pin information that callers > can use after map load. > > The pinning type currently only supports a single PIN_BY_NAME mode, where > each map will be pinned by its name in a path that can be overridden, but > defaults to /sys/fs/bpf. > > The pinning options supports a 'pin_all' setting, which corresponds to the > old bpf_object__map_pin() function with an explicit path. In addition, the > function now defaults to just skipping over maps that are already > pinned (since the previous commit started recording this in struct > bpf_map). This behaviour can be turned off with the 'no_skip_pinned' option. > > Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx> > --- I think you are overcomplicating this... Here's how I think we can satisfy both simplicity goals, as well as good usability: 1. add `const char *pin_root_path` to bpf_object_open_opts. This pinning path override doesn't need to leave in some separate set of options, it's BPF object's parameter, so let's put it into open settings. 2. If BTF-defined map definition has pinning set to PIN_BY_NAME, that means bpf_object__load should do auto-pinning. If not, no auto-pinning, only if manually requested by explicit bpf_map__pin. Further, if someone wants to auto-pin map to a custom location, do bpf_map__set_pin_path() before bpf_object__load(), and load should auto-pin it as well. 3. bpf_map__get_pinning/bpf_map__set_pinning are unnecessary, at least for now. Let's not add unnecessary APIs. 4. pin_all/skip_pinned seems unnecessary. What scenarios are you solving with them? Given #1 and #4, just drop bpf_object__pin_maps_opts(). The way I see it, libbpf should behave sanely for declarative use case, but allow custom tuning programmatically. If map is set to PIN_BY_NAME in map definition - we derive pin_path (potentially taking into account custom pin root path from open opts) and auto-pin on load (unless application set pin_path manually). In a weird case, where map is declaratively defined as auto-pinnable, but application for whatever reason decides not to do it - it can unset pin_path with bpf_map__set_pin_path(NULL). Full control, but simple and intuitive default behavior? Does it make sense? > tools/lib/bpf/bpf_helpers.h | 6 ++ > tools/lib/bpf/libbpf.c | 134 ++++++++++++++++++++++++++++++++++--------- > tools/lib/bpf/libbpf.h | 26 ++++++++ > tools/lib/bpf/libbpf.map | 3 + > 4 files changed, 142 insertions(+), 27 deletions(-) >