netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: Stanislav Fomichev <sdf@fomichev.me>
Cc: "bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Tejun Heo <tj@kernel.org>, Kernel Team <Kernel-team@fb.com>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next 3/4] selftests/bpf: enable all available cgroup v2 controllers
Date: Wed, 22 May 2019 23:16:20 +0000	[thread overview]
Message-ID: <20190522231613.GA20167@tower.DHCP.thefacebook.com> (raw)
In-Reply-To: <20190522221843.GA3032@mini-arch>

On Wed, May 22, 2019 at 03:18:43PM -0700, Stanislav Fomichev wrote:
> On 05/22, Roman Gushchin wrote:
> > Enable all available cgroup v2 controllers when setting up
> > the environment for the bpf kselftests. It's required to properly test
> > the bpf prog auto-detach feature. Also it will generally increase
> > the code coverage.
> > 
> > Signed-off-by: Roman Gushchin <guro@fb.com>
> > ---
> >  tools/testing/selftests/bpf/cgroup_helpers.c | 58 ++++++++++++++++++++
> >  1 file changed, 58 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
> > index 6692a40a6979..4533839c0ce0 100644
> > --- a/tools/testing/selftests/bpf/cgroup_helpers.c
> > +++ b/tools/testing/selftests/bpf/cgroup_helpers.c
> > @@ -33,6 +33,61 @@
> >  	snprintf(buf, sizeof(buf), "%s%s%s", CGROUP_MOUNT_PATH, \
> >  		 CGROUP_WORK_DIR, path)
> >  
> > +/**
> > + * enable_all_controllers() - Enable all available cgroup v2 controllers
> > + *
> > + * Enable all available cgroup v2 controllers in order to increase
> > + * the code coverage.
> > + *
> > + * If successful, 0 is returned.
> > + */
> > +int enable_all_controllers(char *cgroup_path)
> > +{
> > +	char path[PATH_MAX + 1];
> > +	char buf[PATH_MAX];
> > +	char *c, *c2;
> > +	int fd, cfd;
> > +	size_t len;
> > +
> > +	snprintf(path, sizeof(path), "%s/cgroup.controllers", cgroup_path);
> > +	fd = open(path, O_RDONLY);
> > +	if (fd < 0) {
> > +		log_err("Opening cgroup.controllers: %s", path);
> > +		return -1;
> > +	}
> > +
> > +	len = read(fd, buf, sizeof(buf) - 1);
> > +	if (len < 0) {
> > +		close(fd);
> > +		log_err("Reading cgroup.controllers: %s", path);
> > +		return -1;
> > +	}
> > +
> > +	close(fd);
> > +
> > +	/* No controllers available? We're probably on cgroup v1. */
> > +	if (len == 0)
> > +		return 0;
> > +
> > +	snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path);
> > +	cfd = open(path, O_RDWR);
> > +	if (cfd < 0) {
> > +		log_err("Opening cgroup.subtree_control: %s", path);
> > +		return -1;
> > +	}
> > +
> 
> [..]
> > +	buf[len] = 0;
> nit: move this up a bit? Right after:

Ok, np. Thanks!

  reply	other threads:[~2019-05-22 23:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 21:29 [PATCH bpf-next 0/4] cgroup bpf auto-detachment Roman Gushchin
2019-05-22 21:29 ` [PATCH bpf-next 1/4] bpf: decouple the lifetime of cgroup_bpf from cgroup itself Roman Gushchin
2019-05-22 21:29 ` [PATCH bpf-next 2/4] selftests/bpf: convert test_cgrp2_attach2 example into kselftest Roman Gushchin
2019-05-22 21:29 ` [PATCH bpf-next 3/4] selftests/bpf: enable all available cgroup v2 controllers Roman Gushchin
2019-05-22 22:18   ` Stanislav Fomichev
2019-05-22 23:16     ` Roman Gushchin [this message]
2019-05-22 21:29 ` [PATCH bpf-next 4/4] selftests/bpf: add auto-detach test Roman Gushchin
2019-05-22 22:24   ` Stanislav Fomichev
2019-05-22 23:19     ` 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=20190522231613.GA20167@tower.DHCP.thefacebook.com \
    --to=guro@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=tj@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).