From: Quentin Monnet <quentin@isovalent.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] tools: bpftool: allow all prog/map handles for pinning objects
Date: Thu, 12 Mar 2020 18:39:18 +0000 [thread overview]
Message-ID: <c1e31b68-203c-9cc8-77fa-f65f9fac97f0@isovalent.com> (raw)
In-Reply-To: <20200312182555.945-2-quentin@isovalent.com>
2020-03-12 18:25 UTC+0000 ~ Quentin Monnet <quentin@isovalent.com>
> Documentation and interactive help for bpftool have always explained
> that the regular handles for programs (id|name|tag|pinned) and maps
> (id|name|pinned) can be passed to the utility when attempting to pin
> objects (bpftool prog pin PROG / bpftool map pin MAP).
>
> THIS IS A LIE!! The tool actually accepts only ids, as the parsing is
> done in do_pin_any() in common.c instead of reusing the parsing
> functions that have long been generic for program and map handles.
>
> Instead of fixing the doc, fix the code. It is trivial to reuse the
> generic parsing, and to simplify do_pin_any() in the process.
>
> Do not accept to pin multiple objects at the same time with
> prog_parse_fds() or map_parse_fds() (this would require a more complex
> syntax for passing multiple sysfs paths and validating that they
> correspond to the number of e.g. programs we find for a given name or
> tag).
>
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> ---
> tools/bpf/bpftool/common.c | 39 +++++---------------------------------
> tools/bpf/bpftool/main.h | 2 +-
> tools/bpf/bpftool/map.c | 2 +-
> tools/bpf/bpftool/prog.c | 2 +-
> 4 files changed, 8 insertions(+), 37 deletions(-)
>
> diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
> index b75b8ec5469c..92e51a62bd72 100644
> --- a/tools/bpf/bpftool/common.c
> +++ b/tools/bpf/bpftool/common.c
> @@ -211,44 +211,15 @@ int do_pin_fd(int fd, const char *name)
> return err;
> }
>
> -int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
> +int do_pin_any(int argc, char **argv, int (*get_fd)(int *, char ***))
> {
> - unsigned int id;
> - char *endptr;
> - int err;
> int fd;
>
> - if (argc < 3) {
> - p_err("too few arguments, id ID and FILE path is required");
> - return -1;
> - } else if (argc > 3) {
> - p_err("too many arguments");
> - return -1;
> - }
> -
> - if (!is_prefix(*argv, "id")) {
> - p_err("expected 'id' got %s", *argv);
> - return -1;
> - }
> - NEXT_ARG();
> -
> - id = strtoul(*argv, &endptr, 0);
> - if (*endptr) {
> - p_err("can't parse %s as ID", *argv);
> - return -1;
> - }
> - NEXT_ARG();
> -
> - fd = get_fd_by_id(id);
> - if (fd < 0) {
> - p_err("can't open object by id (%u): %s", id, strerror(errno));
> - return -1;
> - }
> -
> - err = do_pin_fd(fd, *argv);
> + fd = get_fd(&argc, &argv);
> + if (fd < 0)
> + return fd;
>
> - close(fd);
> - return err;
> + return do_pin_fd(fd, *argv);
Looks like someone trimmed too much and forgot to close his fd. Will
send v2.
> }
>
next prev parent reply other threads:[~2020-03-12 18:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-12 18:25 [PATCH bpf-next 0/2] tools: bpftool: fix object pinning and bash Quentin Monnet
2020-03-12 18:25 ` [PATCH bpf-next 1/2] tools: bpftool: allow all prog/map handles for pinning objects Quentin Monnet
2020-03-12 18:39 ` Quentin Monnet [this message]
2020-03-12 18:25 ` [PATCH bpf-next 2/2] tools: bpftool: fix minor bash completion mistakes Quentin Monnet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1e31b68-203c-9cc8-77fa-f65f9fac97f0@isovalent.com \
--to=quentin@isovalent.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).