From patchwork Mon Nov 19 10:34:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 151468 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2489779ljp; Mon, 19 Nov 2018 02:34:43 -0800 (PST) X-Google-Smtp-Source: AJdET5fq8s6TBf8434sq72CBK5L0dqmIsZUsnxbEEazh5UzmFOfl/vT+cHxPapHu+8q03+N8jU3k X-Received: by 2002:a63:dc0c:: with SMTP id s12mr19791116pgg.398.1542623683510; Mon, 19 Nov 2018 02:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542623683; cv=none; d=google.com; s=arc-20160816; b=Y1GCE6uZrybviFWnlDjtIPxer3YmAWV1NEpJh5yW/y5WeLWgXDftRVe0Sy3bv1XkfC 1Sb522TanFNRrcsLHDBU5da407dKBoBrFjAG7B+/YBBawpM+C6poWzRgoBagflPOjiNi aCF/JIMCObBqM6MPNbXI+GZYdOssOsIPv/ltWUdTEU0a4kyiUyduCge9YJVQOlBat0CB hI/eiEb4EfvLu97kbLCIodE0UZZJfshBahsO16tDSF1mHZUZt4zKC5Coa2MK+O8FVpRW FuvXMTuDcCiY8/VcekoOzJo3YoEYURraxidLqprQp2YAwd3AqS4h/CVtcFnGgPCauYRj ok9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=LmkQD0tbtsZAukIf+hDcnldAyNR4PdixWTebwHtfE1o=; b=tihK072xl+d+WMy+He5fI1x8oG68bj6iQ08Pidu2LLZ61D3frhOU91KJ3kZiMB45pa hd00UIQs+UvNvOqpIbxvpRFjaSXxKEzD0F9iqRvmGUTQvxNWqbuJl7RSf/eDRE8dpMQv NuImvVf2tCMU6K5biYE8CCxlTecUdxnGTlqMqouoYzri1DEsM75NiU5Am3f1IdIr09vK 9XXW90Vtyx9s6M90OvF2PPxqUFpNp25WqH4Qe6luo3P5STp2aX4kNIUCelD8AK9M3mom lefWxGItbBXfbwU9kwpGNaTAZvQBN1ZQq5B8AMDcFuN1GCBGweahKZ8671ISs3RctlJW C0KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AaxJv2p3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 189si37525025pgh.320.2018.11.19.02.34.42; Mon, 19 Nov 2018 02:34:43 -0800 (PST) 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=@linaro.org header.s=google header.b=AaxJv2p3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728127AbeKSU5x (ORCPT + 32 others); Mon, 19 Nov 2018 15:57:53 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38351 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbeKSU5w (ORCPT ); Mon, 19 Nov 2018 15:57:52 -0500 Received: by mail-wr1-f66.google.com with SMTP id e3-v6so31457479wrs.5 for ; Mon, 19 Nov 2018 02:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LmkQD0tbtsZAukIf+hDcnldAyNR4PdixWTebwHtfE1o=; b=AaxJv2p3JFx65im37SGV+IZMjQz1PPfDkb8OcXtv8JDpUPSwtJZtW84/AKZepCQe+C N6ByZWMq30fbYPq9WLjLvcq+3L+10BQzWw1OW1Pt/d9MWCFPc6NjMm4cKoRYnUAPMnD9 s0GJUK1te5M31nWFXEdF1uRlg/3TqiSkMp1y0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LmkQD0tbtsZAukIf+hDcnldAyNR4PdixWTebwHtfE1o=; b=mqFPIIDVbQFzL3/b9/RD7lo9KkDtQpRUjXSvCJDOBmZNzBk+8qfNOe4cY0Ta/b6uaW nxGwGu15jiJVsiByEZkV2WDFH3sJhZLZXKYJPrFNlpN+pG1RBxgmDZ/FwWL+TEQuqbh/ 9aZRQm6RJbUGFacVnbcMm2xQAcI599twauq8qrKa8Oz/NVpmm04VRIBZTbd2C1MH5u0s /Oz19wVPTkXag54BhZ3oGUy45cDXRQZPRMrmxUEQrkzWY9Zemm6Ez8rGA3BZvPA02stO KQDd9yz2tcSiV45N4+3QY15cMKv/4SnAeyqpSF+Ms/0q6P3w6rHLCMmIMBRQwh19jZag q0/A== X-Gm-Message-State: AA+aEWa08TAzC3+SYOWZAxIrVxkCRW596sUzl6FKvyDVGVwD036VGgC9 T8RCW9tUDZ9dHNDw2LpOwkO4Og== X-Received: by 2002:adf:a743:: with SMTP id e3mr4979481wrd.56.1542623677866; Mon, 19 Nov 2018 02:34:37 -0800 (PST) Received: from localhost.localdomain ([37.162.18.180]) by smtp.gmail.com with ESMTPSA id e9sm14973298wro.16.2018.11.19.02.34.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 02:34:37 -0800 (PST) From: Paolo Valente To: Jens Axboe , Greg Kroah-Hartman , Tejun Heo , Li Zefan , Angelo Ruocco , Dennis Zhou , Josef Bacik , Liu Bo , Bart Van Assche , Johannes Weiner Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, broonie@kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, Jonathan Corbet , Paolo Valente Subject: [PATCH V2 01/10] cgroup: add hook seq_show_cft with also the owning cftype as parameter Date: Mon, 19 Nov 2018 11:34:15 +0100 Message-Id: <20181119103424.3853-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20181119103424.3853-1-paolo.valente@linaro.org> References: <20181119103424.3853-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of the seq_show hook in the cftype struct has only, as parameters, the seq_file to write to and the arguments passed by the command line. Thus, the only way to retrieve the cftype that owns an instance of such hook function is by using the accessor in the seq_file itself. But in a future scenario where the same file may be shared by multiple cftypes, this accessor will point only to the first of the cftypes linked to the seq_file. It will then be impossible to access the cftype owning the seq_show function within the seq_show itself, unless such cftype is the first one. This commit adds an additional seq_show_cft hook that has as a formal parameter also the cftype that owns the function. Signed-off-by: Angelo Ruocco Signed-off-by: Paolo Valente --- include/linux/cgroup-defs.h | 3 ++- kernel/cgroup/cgroup.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) -- 2.16.1 diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 5e1694fe035b..7841db6e7fb3 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -543,8 +543,9 @@ struct cftype { */ s64 (*read_s64)(struct cgroup_subsys_state *css, struct cftype *cft); - /* generic seq_file read interface */ + /* generic seq_file read interfaces*/ int (*seq_show)(struct seq_file *sf, void *v); + int (*seq_show_cft)(struct seq_file *sf, struct cftype *cft, void *v); /* optional ops, implement all or none */ void *(*seq_start)(struct seq_file *sf, loff_t *ppos); diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 6aaf5dd5383b..9d0993dd68fe 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -1418,7 +1418,8 @@ static umode_t cgroup_file_mode(const struct cftype *cft) { umode_t mode = 0; - if (cft->read_u64 || cft->read_s64 || cft->seq_show) + if (cft->read_u64 || cft->read_s64 || cft->seq_show || + cft->seq_show_cft) mode |= S_IRUGO; if (cft->write_u64 || cft->write_s64 || cft->write) { @@ -3519,17 +3520,19 @@ static int cgroup_seqfile_show(struct seq_file *m, void *arg) { struct cftype *cft = seq_cft(m); struct cgroup_subsys_state *css = seq_css(m); + int ret = 0; if (cft->seq_show) - return cft->seq_show(m, arg); - - if (cft->read_u64) + ret = cft->seq_show(m, arg); + else if (cft->seq_show_cft) + ret = cft->seq_show_cft(m, cft, arg); + else if (cft->read_u64) seq_printf(m, "%llu\n", cft->read_u64(css, cft)); else if (cft->read_s64) seq_printf(m, "%lld\n", cft->read_s64(css, cft)); else - return -EINVAL; - return 0; + ret = -EINVAL; + return ret; } static struct kernfs_ops cgroup_kf_single_ops = {