Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp990705ybm; Wed, 22 May 2019 15:20:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9F00giuHNCHobmIZXa9CNVK4Yn9MmgkGb+w5ePLhYYmmLlUc8o4Vr9zhq6WDtn2ZZmFh6 X-Received: by 2002:a17:902:28c9:: with SMTP id f67mr73739119plb.190.1558563608662; Wed, 22 May 2019 15:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558563608; cv=none; d=google.com; s=arc-20160816; b=vniBwXVvpKz4NjrzhPeDxMFVKbUHu9Fbf28TVfhBmFlJavTCa9CaHikyYUyTQUbzm8 faRlSVIgJENZUBWVmP6K67epfNn2XQiT02gF7jxJgFSwUu2QYlJwQuvz/6rKyVrUVLDz Up06Ax6r5MDDWnmOC4xY1LEsMldjH70I3XRzoDHTz7gASKPSD1L0Xu43xUlyQhzc27u5 rCMFS3QhFpfpfJa9cSqWRCDV/eaEd5YUZ1KE7y0sT3P8HoTsyE2uZkN0tXuTKgPWrJ8F ISnXb0s2WpYIFW2E5FzyvhGd0stgYTsSGXOb4XYFb2ptRGsDdAH9A3mkaCq+PrpLjOf3 TITQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QUdAmGAks4E+4DtrN0mw6crQFbwVYGBopZMl7vlB5xU=; b=Jn0643w0pfvZgj1CoEI5UZTkOMup0He5umSTjdKdpPpc/CmxDflsJ/elxEzUI9kS2r 48c2IBardLZ1h5yh3qUgOOQ9DoC2kZY2nI9bQ4LcWwCJvyj2f1aV47PU4OzSQArB8Qnx wTx2z0ns6GLhuwT96x1F8SI9b8WRo6tQUQCK/LNwFeZ07ecfrZNrWcbsVbWzDLVPLPzO VmFXSeQQ+0YPtRJoiGQFED2S1jI6XCBP9U/9up1FKX1YBDNoEJNhc/GBrwEDeaAghuea 2dHwelZN1jO2AFwr6LkdIPSh6LSC3G1CIufRr2MQmz/4qfFBjGHMA0TPV/3am3KNYpKj 09mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fomichev-me.20150623.gappssmtp.com header.s=20150623 header.b=gnPu95pB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92si22066393plw.163.2019.05.22.15.19.53; Wed, 22 May 2019 15:20:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fomichev-me.20150623.gappssmtp.com header.s=20150623 header.b=gnPu95pB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727899AbfEVWSq (ORCPT + 99 others); Wed, 22 May 2019 18:18:46 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37626 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbfEVWSp (ORCPT ); Wed, 22 May 2019 18:18:45 -0400 Received: by mail-pl1-f193.google.com with SMTP id p15so1731043pll.4 for ; Wed, 22 May 2019 15:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fomichev-me.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QUdAmGAks4E+4DtrN0mw6crQFbwVYGBopZMl7vlB5xU=; b=gnPu95pB76Hc4txzz6BDi48JQGwlBKlryzlDHuG/n0DhE+ubr+d43v3d4CVQQARDfv rDONLYaYKQ8KqJ9i++TTN0BPf98fY37iG3zfc6/oSlvf6rd3PoVUGcLZ+qk5MujPnyHx kGbxwb6lScVthKUY9+NLiUOuf7eI7JIbT0Vyx5A860qAlECkU6+LM3bqn/pAj4MZ7srv 5+I5uMRWrfuHhSKRjjpoUuu2QdfaAe5pQHq6mnpg8lhi8LjhGXP/C0tsx4cyD/1pjA+b maDom5+rvbWtufW7OFGn2mS3ghksirusuFNUjDPBn4Vw4BDTtymMKQRTfGPGyPsDtI01 D+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QUdAmGAks4E+4DtrN0mw6crQFbwVYGBopZMl7vlB5xU=; b=OdjqDzLlKceA4KZ2jGPe4fGiFqjhfBZuEZ9DOk9O+yAWafaMwvyUKpXrx9bVhYkCq4 vcMmATPq6gdDRoSwt4U9hOLyyfIOwduluriCR5wFQz+B/kGTR3wzMeU1vrzPNkei/Eb9 n9rM8g2eoQZeFbEh+Uz1IG9jzGfS52BSP0k+fd3AnQyX4Qx61iH/rp1zrKrWU//IefuE BGaLPmMr4ZhvLVfgoErMSfmNL99iqeN0OL5eiudRhSKQESocJMvfN6V4ytA1TX8IxPYX 4gwvNwGc94CpAzKpRKLaK2NnS8EQDyX0b4EXBUxT3yQTFCvwYly4h3w53hY3IG7In179 qO7w== X-Gm-Message-State: APjAAAXaDnfZEwgOb4tyKHE6hyHE2rYl209wkry2vQqTpdU6AQOEIymj Y+MU5xr4zm3ZPck2RofXU2ZNyA== X-Received: by 2002:a17:902:b949:: with SMTP id h9mr49158945pls.50.1558563524887; Wed, 22 May 2019 15:18:44 -0700 (PDT) Received: from localhost ([2601:646:8f00:18d9:d0fa:7a4b:764f:de48]) by smtp.gmail.com with ESMTPSA id q14sm26900610pgg.10.2019.05.22.15.18.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 May 2019 15:18:44 -0700 (PDT) Date: Wed, 22 May 2019 15:18:43 -0700 From: Stanislav Fomichev To: Roman Gushchin Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, Tejun Heo , kernel-team@fb.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH bpf-next 3/4] selftests/bpf: enable all available cgroup v2 controllers Message-ID: <20190522221843.GA3032@mini-arch> References: <20190522212932.2646247-1-guro@fb.com> <20190522212932.2646247-4-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190522212932.2646247-4-guro@fb.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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: if (len < 0) { ... } buf[len] = 0; close(fd); I was actually writing a comment about missing buf[len]=0 until I somehow spotted it :-) > + for (c = strtok_r(buf, " ", &c2); c; c = strtok_r(NULL, " ", &c2)) { > + if (dprintf(cfd, "+%s\n", c) <= 0) { > + log_err("Enabling controller %s: %s", c, path); > + close(cfd); > + return -1; > + } > + } > + close(cfd); > + return 0; > +} > + > /** > * setup_cgroup_environment() - Setup the cgroup environment > * > @@ -71,6 +126,9 @@ int setup_cgroup_environment(void) > return 1; > } > > + if (enable_all_controllers(cgroup_workdir)) > + return 1; > + > return 0; > } > > -- > 2.20.1 >