From: Quentin Monnet <quentin.monnet@netronome.com>
To: Roman Gushchin <guro@fb.com>, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, ast@kernel.org,
daniel@iogearbox.net, jakub.kicinski@netronome.com, kafai@fb.com
Subject: Re: [PATCH net-next 4/5] bpftool: implement cgdetach command
Date: Fri, 1 Dec 2017 10:26:27 +0000 [thread overview]
Message-ID: <150c6e31-2fdb-3448-d434-773ebd24e351@netronome.com> (raw)
In-Reply-To: <20171130134302.2840-5-guro@fb.com>
2017-11-30 13:43 UTC+0000 ~ Roman Gushchin <guro@fb.com>
> Implement cgdetach command, which allows to detach the bpf
> program from a cgroup. It takes program id and attach type
> as arguments.
>
> Example:
> $ ./bpftool cgdetach /sys/fs/cgroup/user.slice/ device 1
>
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
> Cc: Martin KaFai Lau <kafai@fb.com>
> ---
> tools/bpf/bpftool/main.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index 8eb3b9bf5bb2..77fcc1a0bd5d 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
[…]
> @@ -338,6 +341,51 @@ static int do_cgattach(int argc, char **argv)
> return 0;
> }
>
> +static int do_cgdetach(int argc, char **argv)
> +{
> + int prog_fd, cgroup_fd;
> + enum bpf_attach_type attach_type;
> +
> + if (argc < 3) {
> + p_err("too few parameters for cgdetach\n");
> + return -1;
> + } else if (argc > 3) {
> + p_err("too many parameters for cgdetach\n");
> + return -1;
> + }
> +
> + cgroup_fd = open(argv[0], O_RDONLY);
> + if (cgroup_fd < 0) {
> + p_err("can't open cgroup %s\n", argv[1]);
> + return -1;
> + }
> +
> + attach_type = parse_attach_type(argv[1]);
> + if (attach_type == __MAX_BPF_ATTACH_TYPE) {
> + close(cgroup_fd);
> + p_err("Invalid attach type");
> + return -1;
> + }
> +
> + prog_fd = bpf_prog_get_fd_by_id(atoi(argv[2]));
> + if (prog_fd < 0) {
> + p_err("invalid program id\n");
> + return -1;
> + }
> +
> + if (bpf_prog_detach2(prog_fd, cgroup_fd, attach_type)) {
> + close(prog_fd);
> + close(cgroup_fd);
> + p_err("Failed to attach program");
> + return -1;
> + }
> +
> + close(prog_fd);
> + close(cgroup_fd);
Could you please make the function print a "null" string for JSON here?
So that it does not break JSON for batched commands. Should be as simple as:
jsonw_null(json_wtr);
This is also valid for `do_cgattach()` in patch 3.
Thanks!
> +
> + return 0;
> +}
> +
> int main(int argc, char **argv)
> {
> static const struct option options[] = {
>
next prev parent reply other threads:[~2017-12-01 10:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-30 13:42 [PATCH net-next 0/5] bpftool: cgroup bpf operations Roman Gushchin
2017-11-30 13:42 ` [PATCH net-next 1/5] libbpf: add ability to guess program type based on section name Roman Gushchin
2017-12-01 10:22 ` Quentin Monnet
2017-12-01 22:46 ` Jakub Kicinski
2017-12-04 12:34 ` Roman Gushchin
2017-12-04 13:12 ` Quentin Monnet
2017-12-04 13:22 ` Roman Gushchin
2017-11-30 13:42 ` [PATCH net-next 2/5] libbpf: prefer global symbols as bpf program name source Roman Gushchin
2017-11-30 13:43 ` [PATCH net-next 3/5] bpftool: implement cgattach command Roman Gushchin
2017-11-30 16:17 ` David Ahern
2017-11-30 16:44 ` Roman Gushchin
2017-11-30 16:24 ` David Ahern
2017-12-01 3:13 ` Jakub Kicinski
2017-11-30 13:43 ` [PATCH net-next 4/5] bpftool: implement cgdetach command Roman Gushchin
2017-12-01 10:26 ` Quentin Monnet [this message]
2017-11-30 13:43 ` [PATCH net-next 5/5] bpftool: implement cglist command Roman Gushchin
2017-12-01 3:04 ` [PATCH net-next 0/5] bpftool: cgroup bpf operations Jakub Kicinski
2017-12-01 17:06 ` Roman Gushchin
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=150c6e31-2fdb-3448-d434-773ebd24e351@netronome.com \
--to=quentin.monnet@netronome.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=guro@fb.com \
--cc=jakub.kicinski@netronome.com \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®