[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEKGpzifL18heCuioO8Qoei6a3epkrZcM=Av6qwdi2w1faTkKg@mail.gmail.com>
Date: Tue, 24 Nov 2020 17:50:34 +0900
From: "Daniel T. Lee" <danieltimlee@...il.com>
To: Martin KaFai Lau <kafai@...com>
Cc: Daniel Borkmann <daniel@...earbox.net>,
Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>, brakmo <brakmo@...com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Andrii Nakryiko <andrii.nakryiko@...il.com>,
Lorenzo Bianconi <lorenzo@...nel.org>,
David Ahern <dsa@...ulusnetworks.com>,
Yonghong Song <yhs@...com>,
Toke Høiland-Jørgensen <toke@...hat.com>,
Ira Weiny <ira.weiny@...el.com>, Thomas Graf <tgraf@...g.ch>,
Jakub Kicinski <kuba@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
bpf <bpf@...r.kernel.org>, netdev <netdev@...r.kernel.org>,
Xdp <xdp-newbies@...r.kernel.org>
Subject: Re: [PATCH bpf-next v2 1/7] samples: bpf: refactor hbm program with libbpf
Sorry for the late reply.
On Sat, Nov 21, 2020 at 11:34 AM Martin KaFai Lau <kafai@...com> wrote:
>
> On Thu, Nov 19, 2020 at 03:06:11PM +0000, Daniel T. Lee wrote:
> [ ... ]
>
> > static int run_bpf_prog(char *prog, int cg_id)
> > [ ... ]
> > if (!outFlag)
> > - type = BPF_CGROUP_INET_INGRESS;
> > - if (bpf_prog_attach(bpfprog_fd, cg1, type, 0)) {
> > - printf("ERROR: bpf_prog_attach fails!\n");
> > - log_err("Attaching prog");
> > + bpf_program__set_expected_attach_type(bpf_prog, BPF_CGROUP_INET_INGRESS);
> > +
> > + link = bpf_program__attach_cgroup(bpf_prog, cg1);
> > + if (libbpf_get_error(link)) {
> > + fprintf(stderr, "ERROR: bpf_program__attach_cgroup failed\n");
> > + link = NULL;
> Again, this is not needed. bpf_link__destroy() can
> handle both NULL and error pointer. Please take a look
> at the bpf_link__destroy() in libbpf.c
>
> > + goto err;
> > + }
> > [ ... ]
> > @@ -398,10 +400,10 @@ static int run_bpf_prog(char *prog, int cg_id)
> > err:
> > rc = 1;
> >
> > - if (cg1)
> > - close(cg1);
> > + bpf_link__destroy(link);
> > + close(cg1);
> > cleanup_cgroup_environment();
> > -
> > + bpf_object__close(obj);
> The bpf_* cleanup condition still looks wrong.
>
> I can understand why it does not want to cleanup_cgroup_environment()
> on the success case because the sh script may want to run test under this
> cgroup.
>
> However, the bpf_link__destroy(), bpf_object__close(), and
> even close(cg1) should be done in both success and error
> cases.
>
> The cg1 test still looks wrong also. The cg1 should
> be init to -1 and then test for "if (cg1 == -1)".
Thanks for pointing this out.
I'll remove NULL initialize and fix this on the next patch.
--
Best,
Daniel T. Lee
Powered by blists - more mailing lists