From patchwork Mon Sep 13 05:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 398E7C4332F for ; Mon, 13 Sep 2021 05:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1423960E90 for ; Mon, 13 Sep 2021 05:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237049AbhIMFpT (ORCPT ); Mon, 13 Sep 2021 01:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbhIMFpS (ORCPT ); Mon, 13 Sep 2021 01:45:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E438C061574; Sun, 12 Sep 2021 22:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Bc/r1/v5qYGuobd8WzRjQTK4GgUmwdQvoNbSmc4SwNk=; b=lHbzAsnoK940Q3XtXo1skkoEHr T8exy5EAQs0EYBlIha6ZaDyeZQDp0AbiGpn4evFhvKHeUY8ZE7AKqC5AJQCwnAaUBoUpnS0pAXOc7 6SZPw/5JGCYZemZ3mp55Pw81Oi0io5gL/SnEonIuJY2XqX/tl691/L3ezQsZgzENyVYpsYnJuHLN4 5SgqxI5jVIsoWpF8jVvJLE2rD47CZ5WMuertKZql5mZ4Qa4dXTAUPpmN4drCKaAuyswG3pj18lvax vjGrPKZYdV6C9omsVladCrBKdyK0iGuXCOatU0bq8SbhgsObjlvzUE9RRrNIgG1GqbteyR++wZRjZ MlLPR37w==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPejL-00DCVR-Pf; Mon, 13 Sep 2021 05:42:18 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/13] seq_file: mark seq_get_buf as deprecated Date: Mon, 13 Sep 2021 07:41:09 +0200 Message-Id: <20210913054121.616001-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This function pokes a big hole into the seq_file abstraction. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- include/linux/seq_file.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index dd99569595fd3..db16b11477875 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -59,6 +59,10 @@ static inline bool seq_has_overflowed(struct seq_file *m) * * Return the number of bytes available in the buffer, or zero if * there's no space. + * + * DOT NOT USE IN NEW CODE! This function pokes a hole into the whole seq_file + * abstraction. The only remaining user outside of seq_file.c is sysfs, which + * is gradually moving away from using seq_get_buf directly. */ static inline size_t seq_get_buf(struct seq_file *m, char **bufp) { From patchwork Mon Sep 13 05:41:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75DFAC433EF for ; Mon, 13 Sep 2021 05:45:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5411C60E8B for ; Mon, 13 Sep 2021 05:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237066AbhIMFqO (ORCPT ); Mon, 13 Sep 2021 01:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbhIMFqN (ORCPT ); Mon, 13 Sep 2021 01:46:13 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E82EC061574; Sun, 12 Sep 2021 22:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Ead5soR/lTgjqzqfyJo+0XLeX5YYtl6XszNEzk7rFcc=; b=rrFWlG4Td8osfc6LGxB41SYepr I+FpY/FuvfTFd0PmS1ErhC+iCp84e1gZ9ha5MztwtIeju6eVHf70fACStB5hTvoLc+FnfrDOTFjyj KXFUOW1zsmm0NtvtfR2y9fdPvSkzrqh/jFLII6uuRQlsntOmytgBGNCJkh7QMG0HreUO8mPJVjnBG 4Ajo+2CLcaF0wN2UGnhio2eNXixRPbzh2SqXZBhJAE2lFLjzL/RPhQs4/uquHW+G2H9teBsNcafa0 LS8MQG4uQxklnoy21LqZdi2lJqcJ+q8exgpehEEAEsalZLWu7EYQlg6I2JiMi4rFKFbius205B4bB uOVZn+xA==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPek1-00DCX1-SD; Mon, 13 Sep 2021 05:43:09 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/13] kernfs: remove kernfs_create_file and kernfs_create_file_ns Date: Mon, 13 Sep 2021 07:41:10 +0200 Message-Id: <20210913054121.616001-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org All callers actually use __kernfs_create_file. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- include/linux/kernfs.h | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 1093abf7c28cc..cecfeedb7361d 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -568,30 +568,6 @@ kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode, priv, NULL); } -static inline struct kernfs_node * -kernfs_create_file_ns(struct kernfs_node *parent, const char *name, - umode_t mode, kuid_t uid, kgid_t gid, - loff_t size, const struct kernfs_ops *ops, - void *priv, const void *ns) -{ - struct lock_class_key *key = NULL; - -#ifdef CONFIG_DEBUG_LOCK_ALLOC - key = (struct lock_class_key *)&ops->lockdep_key; -#endif - return __kernfs_create_file(parent, name, mode, uid, gid, - size, ops, priv, ns, key); -} - -static inline struct kernfs_node * -kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode, - loff_t size, const struct kernfs_ops *ops, void *priv) -{ - return kernfs_create_file_ns(parent, name, mode, - GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, - size, ops, priv, NULL); -} - static inline int kernfs_remove_by_name(struct kernfs_node *parent, const char *name) { From patchwork Mon Sep 13 05:41:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EDF3C433EF for ; Mon, 13 Sep 2021 05:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FED960E90 for ; Mon, 13 Sep 2021 05:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233274AbhIMFrM (ORCPT ); Mon, 13 Sep 2021 01:47:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbhIMFrL (ORCPT ); Mon, 13 Sep 2021 01:47:11 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B8F9C061574; Sun, 12 Sep 2021 22:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=6SfgkC+JZnr0UNolZwMoQM7LNrDA0S14AXQgn/IuMC4=; b=dhoftXNEpLcCsE4MsG8ssXT5DI R36G2CIY6RC7aqVwIsnkdsybOKMEaQUm+/ARpChj+GLJ0obZj6ehYVkXq0ojLsAZUprPlXongmXM+ mKijVBgKrmDfCw4ZlWgPLek60eK6z6yLI9eVu5glcDo9lp1ULPmZ4g4DCXRTZSLW/CTGuPU61iS4y kMviLGl+3uAZ15mta4NDwabiD0DdZl0Hwt5XAl6PmtSPdhu8GoQXtmNyhp0OSaqK5XuVnxu2FLB8X Qn8goumjhuMujmJCeVLv0eEGhVEOj9XcMT86nW6mPWxkMewZ/QzPfcGSKZKQl0tOfnI0/HbPnnHhB tciUW/yg==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPelL-00DCaY-A9; Mon, 13 Sep 2021 05:44:42 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/13] kernfs: remove the unused lockdep_key field in struct kernfs_ops Date: Mon, 13 Sep 2021 07:41:11 +0200 Message-Id: <20210913054121.616001-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No actually used anywhere. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- include/linux/kernfs.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index cecfeedb7361d..3ccce6f245484 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -269,10 +269,6 @@ struct kernfs_ops { struct poll_table_struct *pt); int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); - -#ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lock_class_key lockdep_key; -#endif }; /* From patchwork Mon Sep 13 05:41:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2883EC433EF for ; Mon, 13 Sep 2021 05:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 087AB6058D for ; Mon, 13 Sep 2021 05:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237029AbhIMFsE (ORCPT ); Mon, 13 Sep 2021 01:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbhIMFsE (ORCPT ); Mon, 13 Sep 2021 01:48:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F203AC061574; Sun, 12 Sep 2021 22:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nZvqPG4+2NdzXFSLEHoLxGtJGnDe20+xSZBBnwc+cmw=; b=lID8utpB1KlZAn5OqOci6HE/BW dzeAsiQJYQTUsvnKKjFlK97MHPKB6l2eJALElSxQo/S4+7IXPVpvvPEe691o5OEQYO/3H3N8l5Fla ESl9ivt+4Vpzm9CQgi3NIX2dZy5e6wAlJBMIXc8fOx6di3ynd2YPJtcy4TL7ee8RRmK/CruFp2pyk PjdFra5fQUngq+BOW+lxGXZwBH7YoRa/OFb7XyssI7EAFa3RleD91Ix8UhlFsYRiBPvx4kZgK4BZd MvdYYBgkxeq8JVYGM/nVgMrCa9r8Ce5w/TXwKFYEEPqWgrsdAgTfJM2iRaNObG0pwID3I1G02cMmP /G921jBg==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPemN-00DCeb-FI; Mon, 13 Sep 2021 05:45:46 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/13] sysfs: split out binary attribute handling from sysfs_add_file_mode_ns Date: Mon, 13 Sep 2021 07:41:12 +0200 Message-Id: <20210913054121.616001-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Split adding binary attributes into a separate handler instead of overloading sysfs_add_file_mode_ns. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- fs/sysfs/file.c | 120 ++++++++++++++++++++++++++--------------------- fs/sysfs/group.c | 15 +++--- fs/sysfs/sysfs.h | 8 ++-- 3 files changed, 78 insertions(+), 65 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index d019d6ac6ad09..f737bd61f71bf 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -255,59 +255,73 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = { }; int sysfs_add_file_mode_ns(struct kernfs_node *parent, - const struct attribute *attr, bool is_bin, - umode_t mode, kuid_t uid, kgid_t gid, const void *ns) + const struct attribute *attr, umode_t mode, kuid_t uid, + kgid_t gid, const void *ns) { + struct kobject *kobj = parent->priv; + const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; struct lock_class_key *key = NULL; const struct kernfs_ops *ops; struct kernfs_node *kn; - loff_t size; - - if (!is_bin) { - struct kobject *kobj = parent->priv; - const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; - - /* every kobject with an attribute needs a ktype assigned */ - if (WARN(!sysfs_ops, KERN_ERR - "missing sysfs attribute operations for kobject: %s\n", - kobject_name(kobj))) - return -EINVAL; - - if (sysfs_ops->show && sysfs_ops->store) { - if (mode & SYSFS_PREALLOC) - ops = &sysfs_prealloc_kfops_rw; - else - ops = &sysfs_file_kfops_rw; - } else if (sysfs_ops->show) { - if (mode & SYSFS_PREALLOC) - ops = &sysfs_prealloc_kfops_ro; - else - ops = &sysfs_file_kfops_ro; - } else if (sysfs_ops->store) { - if (mode & SYSFS_PREALLOC) - ops = &sysfs_prealloc_kfops_wo; - else - ops = &sysfs_file_kfops_wo; - } else - ops = &sysfs_file_kfops_empty; - - size = PAGE_SIZE; - } else { - struct bin_attribute *battr = (void *)attr; - - if (battr->mmap) - ops = &sysfs_bin_kfops_mmap; - else if (battr->read && battr->write) - ops = &sysfs_bin_kfops_rw; - else if (battr->read) - ops = &sysfs_bin_kfops_ro; - else if (battr->write) - ops = &sysfs_bin_kfops_wo; + + /* every kobject with an attribute needs a ktype assigned */ + if (WARN(!sysfs_ops, KERN_ERR + "missing sysfs attribute operations for kobject: %s\n", + kobject_name(kobj))) + return -EINVAL; + + if (sysfs_ops->show && sysfs_ops->store) { + if (mode & SYSFS_PREALLOC) + ops = &sysfs_prealloc_kfops_rw; else - ops = &sysfs_file_kfops_empty; + ops = &sysfs_file_kfops_rw; + } else if (sysfs_ops->show) { + if (mode & SYSFS_PREALLOC) + ops = &sysfs_prealloc_kfops_ro; + else + ops = &sysfs_file_kfops_ro; + } else if (sysfs_ops->store) { + if (mode & SYSFS_PREALLOC) + ops = &sysfs_prealloc_kfops_wo; + else + ops = &sysfs_file_kfops_wo; + } else + ops = &sysfs_file_kfops_empty; - size = battr->size; +#ifdef CONFIG_DEBUG_LOCK_ALLOC + if (!attr->ignore_lockdep) + key = attr->key ?: (struct lock_class_key *)&attr->skey; +#endif + + kn = __kernfs_create_file(parent, attr->name, mode & 0777, uid, gid, + PAGE_SIZE, ops, (void *)attr, ns, key); + if (IS_ERR(kn)) { + if (PTR_ERR(kn) == -EEXIST) + sysfs_warn_dup(parent, attr->name); + return PTR_ERR(kn); } + return 0; +} + +int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent, + const struct bin_attribute *battr, umode_t mode, + kuid_t uid, kgid_t gid, const void *ns) +{ + const struct attribute *attr = &battr->attr; + struct lock_class_key *key = NULL; + const struct kernfs_ops *ops; + struct kernfs_node *kn; + + if (battr->mmap) + ops = &sysfs_bin_kfops_mmap; + else if (battr->read && battr->write) + ops = &sysfs_bin_kfops_rw; + else if (battr->read) + ops = &sysfs_bin_kfops_ro; + else if (battr->write) + ops = &sysfs_bin_kfops_wo; + else + ops = &sysfs_file_kfops_empty; #ifdef CONFIG_DEBUG_LOCK_ALLOC if (!attr->ignore_lockdep) @@ -315,7 +329,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, #endif kn = __kernfs_create_file(parent, attr->name, mode & 0777, uid, gid, - size, ops, (void *)attr, ns, key); + battr->size, ops, (void *)attr, ns, key); if (IS_ERR(kn)) { if (PTR_ERR(kn) == -EEXIST) sysfs_warn_dup(parent, attr->name); @@ -340,9 +354,7 @@ int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, return -EINVAL; kobject_get_ownership(kobj, &uid, &gid); - return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode, - uid, gid, ns); - + return sysfs_add_file_mode_ns(kobj->sd, attr, attr->mode, uid, gid, ns); } EXPORT_SYMBOL_GPL(sysfs_create_file_ns); @@ -385,8 +397,8 @@ int sysfs_add_file_to_group(struct kobject *kobj, return -ENOENT; kobject_get_ownership(kobj, &uid, &gid); - error = sysfs_add_file_mode_ns(parent, attr, false, - attr->mode, uid, gid, NULL); + error = sysfs_add_file_mode_ns(parent, attr, attr->mode, uid, gid, + NULL); kernfs_put(parent); return error; @@ -555,8 +567,8 @@ int sysfs_create_bin_file(struct kobject *kobj, return -EINVAL; kobject_get_ownership(kobj, &uid, &gid); - return sysfs_add_file_mode_ns(kobj->sd, &attr->attr, true, - attr->attr.mode, uid, gid, NULL); + return sysfs_add_bin_file_mode_ns(kobj->sd, attr, attr->attr.mode, uid, + gid, NULL); } EXPORT_SYMBOL_GPL(sysfs_create_bin_file); diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index f29d620045272..eeb0e30994215 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -61,8 +61,8 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, (*attr)->name, mode); mode &= SYSFS_PREALLOC | 0664; - error = sysfs_add_file_mode_ns(parent, *attr, false, - mode, uid, gid, NULL); + error = sysfs_add_file_mode_ns(parent, *attr, mode, uid, + gid, NULL); if (unlikely(error)) break; } @@ -90,10 +90,9 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, (*bin_attr)->attr.name, mode); mode &= SYSFS_PREALLOC | 0664; - error = sysfs_add_file_mode_ns(parent, - &(*bin_attr)->attr, true, - mode, - uid, gid, NULL); + error = sysfs_add_bin_file_mode_ns(parent, *bin_attr, + mode, uid, gid, + NULL); if (error) break; } @@ -340,8 +339,8 @@ int sysfs_merge_group(struct kobject *kobj, kobject_get_ownership(kobj, &uid, &gid); for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) - error = sysfs_add_file_mode_ns(parent, *attr, false, - (*attr)->mode, uid, gid, NULL); + error = sysfs_add_file_mode_ns(parent, *attr, (*attr)->mode, + uid, gid, NULL); if (error) { while (--i >= 0) kernfs_remove_by_name(parent, (*--attr)->name); diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 0050cc0c0236d..3f28c9af57562 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h @@ -28,9 +28,11 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name); * file.c */ int sysfs_add_file_mode_ns(struct kernfs_node *parent, - const struct attribute *attr, bool is_bin, - umode_t amode, kuid_t uid, kgid_t gid, - const void *ns); + const struct attribute *attr, umode_t amode, kuid_t uid, + kgid_t gid, const void *ns); +int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent, + const struct bin_attribute *battr, umode_t mode, + kuid_t uid, kgid_t gid, const void *ns); /* * symlink.c From patchwork Mon Sep 13 05:41:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62466C433FE for ; Mon, 13 Sep 2021 05:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 392DA60E97 for ; Mon, 13 Sep 2021 05:47:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237033AbhIMFtI (ORCPT ); Mon, 13 Sep 2021 01:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbhIMFtH (ORCPT ); Mon, 13 Sep 2021 01:49:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 764D4C061574; Sun, 12 Sep 2021 22:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GBo5Rz+WJXS0VW8m3fPXrsQLeRaC3/dTvflymAX4JWU=; b=MztTY+PAdeihgiwb7bWszYZcpx UvuQSQySzGxh6Iwkq0KI7oGGaZdmrljC2x77LIWGoh4z4wP5hIklvwzptVsfJ19uGuFQ5nMAZ/swn cxT49bGlIRjl5c9eaegBB+xR1CAChlBQXdb8OcEEvacFYtsZS2rs7BBKz45GNx3nQxI6s1wqqyRSX 3mjiIBLIOup5Om6fdAwAx+nvkbLK0SWAU1r+Oel1QluM3El8+TSSPH6tdEGSW5itCWoZQHc6+jLhG qeAQ5t7+9jMFdUNTN7P6ddMlwEvmB4VuebzQxar8Oqk0xAPCCpq/G2JtvWEpAZzSZb91kDMtOrGrn drIc8eBA==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPen2-00DChO-Tp; Mon, 13 Sep 2021 05:46:15 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/13] sysfs: refactor sysfs_add_file_mode_ns Date: Mon, 13 Sep 2021 07:41:13 +0200 Message-Id: <20210913054121.616001-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Regroup the code so that preallocated attributes and normal attributes are handled in clearly separate blocks. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- fs/sysfs/file.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index f737bd61f71bf..74a2a8021c8bb 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -261,7 +261,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, struct kobject *kobj = parent->priv; const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; struct lock_class_key *key = NULL; - const struct kernfs_ops *ops; + const struct kernfs_ops *ops = NULL; struct kernfs_node *kn; /* every kobject with an attribute needs a ktype assigned */ @@ -270,22 +270,23 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, kobject_name(kobj))) return -EINVAL; - if (sysfs_ops->show && sysfs_ops->store) { - if (mode & SYSFS_PREALLOC) + if (mode & SYSFS_PREALLOC) { + if (sysfs_ops->show && sysfs_ops->store) ops = &sysfs_prealloc_kfops_rw; - else - ops = &sysfs_file_kfops_rw; - } else if (sysfs_ops->show) { - if (mode & SYSFS_PREALLOC) + else if (sysfs_ops->show) ops = &sysfs_prealloc_kfops_ro; - else - ops = &sysfs_file_kfops_ro; - } else if (sysfs_ops->store) { - if (mode & SYSFS_PREALLOC) + else if (sysfs_ops->store) ops = &sysfs_prealloc_kfops_wo; - else + } else { + if (sysfs_ops->show && sysfs_ops->store) + ops = &sysfs_file_kfops_rw; + else if (sysfs_ops->show) + ops = &sysfs_file_kfops_ro; + else if (sysfs_ops->store) ops = &sysfs_file_kfops_wo; - } else + } + + if (!ops) ops = &sysfs_file_kfops_empty; #ifdef CONFIG_DEBUG_LOCK_ALLOC From patchwork Mon Sep 13 05:41:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97E8FC4332F for ; Mon, 13 Sep 2021 05:48:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81B5E60F4B for ; Mon, 13 Sep 2021 05:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237095AbhIMFts (ORCPT ); Mon, 13 Sep 2021 01:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbhIMFtr (ORCPT ); Mon, 13 Sep 2021 01:49:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AECB6C061574; Sun, 12 Sep 2021 22:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=iPSg9fzhb7ugDsun1O8XdsG/v81d56clxIVC4PupvcU=; b=BylZxWILvx+YFJGWUCLciodiR1 Z4qK/AvTb7/s9GucyqBm3cYi0tYVJcq5cf2aMgvN77HrH0i91g9w4bGY8IY5g0WGzcRIsnhWEvBPG h+SWN0E+bMe2br+DsVPPDJx7v0fKdwd3OaLNaCUU8CNB0VArETFtFN4k1zu/rf4Q1xwzJ9NUCyCqM FCNhMgdSDite0x1fAI/Lnbvv7yu2BIjq6j2G07iW4U0ntHc9bcUSfav+fRH+Er+6Ici+2MsITgEy8 +5g+P43FBMvJVke5GQE1VBSXoGQC6Zly9KKZZ6c3io5Sqrk5fVV5CGVF5qcnzCjV2xYt0hfoyT9ug 3xtxsZow==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPeoN-00DCnV-Ci; Mon, 13 Sep 2021 05:47:39 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/13] sysfs: simplify sysfs_kf_seq_show Date: Mon, 13 Sep 2021 07:41:14 +0200 Message-Id: <20210913054121.616001-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Contrary to the comment ->show is never called from lseek for sysfs, given that sysfs does not use seq_lseek. So remove the NULL ->show case and just WARN and return an error if some future code path ends up here. Signed-off-by: Christoph Hellwig --- fs/sysfs/file.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 74a2a8021c8bb..42dcf96881b68 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -45,6 +45,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) ssize_t count; char *buf; + if (WARN_ON_ONCE(!ops->show)) + return -EINVAL; + /* acquire buffer and ensure that it's >= PAGE_SIZE and clear */ count = seq_get_buf(sf, &buf); if (count < PAGE_SIZE) { @@ -53,15 +56,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) } memset(buf, 0, PAGE_SIZE); - /* - * Invoke show(). Control may reach here via seq file lseek even - * if @ops->show() isn't implemented. - */ - if (ops->show) { - count = ops->show(kobj, of->kn->priv, buf); - if (count < 0) - return count; - } + count = ops->show(kobj, of->kn->priv, buf); + if (count < 0) + return count; /* * The code works fine with PAGE_SIZE return but it's likely to From patchwork Mon Sep 13 05:41:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 968DFC4332F for ; Mon, 13 Sep 2021 05:49:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B7F360FF2 for ; Mon, 13 Sep 2021 05:49:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237115AbhIMFuo (ORCPT ); Mon, 13 Sep 2021 01:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbhIMFun (ORCPT ); Mon, 13 Sep 2021 01:50:43 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE79C061574; Sun, 12 Sep 2021 22:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ZlNshhcRbh7TTTSVkfYJWF8qycoraf4MAz4lP9XUHsc=; b=qEssEVXa3xjHznRIrCx8lBb2XD DS2hJrDQ+w2Bs6gJiCZ7Ft0fC60K+uApT2CiWS5kwhkWQKeLBCJWqv6Gpy3Nl8tyrkDDx2ID16Ib2 GKd50AkDLlJFnUurQiM/EbVjIz6Su/aqsCoK9gljUPQErhxUG3wDPUNLPG3ZhGe218bj8h+0YwrhN uhtD+YDRtput2x1HRqiN8Wc2NRwqseWwpC0vN/htGCSXyU3jzUvPyL/HSjd9GJsNV5ZxOSdQM5xJd lfjal3NT/3xqF61gehnyXbiPzsTEn75IC8aZn7aOi3L77BshpSU9duXbl1D++4lEKOy+Kd68ZbzvD g/cTh6tg==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPeoy-00DCpG-FY; Mon, 13 Sep 2021 05:48:06 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/13] sysfs: add ->seq_show support to sysfs_ops Date: Mon, 13 Sep 2021 07:41:15 +0200 Message-Id: <20210913054121.616001-8-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Allow attributes to directly use the seq_file method instead of carving out a buffer that can easily lead to buffer overflows. Signed-off-by: Christoph Hellwig Acked-by: Christian Brauner --- fs/sysfs/file.c | 19 ++++++++++++++----- include/linux/sysfs.h | 9 +++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 42dcf96881b68..12e0bfe40a2b4 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -45,6 +45,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) ssize_t count; char *buf; + if (ops->seq_show) + return ops->seq_show(kobj, of->kn->priv, sf); + if (WARN_ON_ONCE(!ops->show)) return -EINVAL; @@ -268,6 +271,10 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, return -EINVAL; if (mode & SYSFS_PREALLOC) { + if (WARN(sysfs_ops->seq_show, KERN_ERR + "seq_show not supported on prealloc file: %s\n", + kobject_name(kobj))) + return -EINVAL; if (sysfs_ops->show && sysfs_ops->store) ops = &sysfs_prealloc_kfops_rw; else if (sysfs_ops->show) @@ -275,12 +282,14 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, else if (sysfs_ops->store) ops = &sysfs_prealloc_kfops_wo; } else { - if (sysfs_ops->show && sysfs_ops->store) - ops = &sysfs_file_kfops_rw; - else if (sysfs_ops->show) - ops = &sysfs_file_kfops_ro; - else if (sysfs_ops->store) + if (sysfs_ops->seq_show || sysfs_ops->show) { + if (sysfs_ops->store) + ops = &sysfs_file_kfops_rw; + else + ops = &sysfs_file_kfops_ro; + } else if (sysfs_ops->store) { ops = &sysfs_file_kfops_wo; + } } if (!ops) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e3f1e8ac1f85b..e1ab4da716730 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -236,8 +236,13 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size) struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) struct sysfs_ops { - ssize_t (*show)(struct kobject *, struct attribute *, char *); - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); + int (*seq_show)(struct kobject *kobj, struct attribute *attr, + struct seq_file *sf); + ssize_t (*store)(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t size); + + /* deprecated except for preallocated attributes: */ + ssize_t (*show)(struct kobject *kob, struct attribute *attr, char *buf); }; #ifdef CONFIG_SYSFS From patchwork Mon Sep 13 05:41:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D3FCC433FE for ; Mon, 13 Sep 2021 05:50:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84F2F60F9B for ; Mon, 13 Sep 2021 05:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237049AbhIMFwL (ORCPT ); Mon, 13 Sep 2021 01:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbhIMFwD (ORCPT ); Mon, 13 Sep 2021 01:52:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC28C061574; Sun, 12 Sep 2021 22:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UXp+fCkzH2CgbRglk3bxc6R/C42uMSQO+IFVmi1XBWI=; b=vmxsq3hppe0dYahL5qFfdE0tJ/ 2ShQjICI/kC6mB0ChKBLQCxgBaPncDLqYiqspAn8/f3LAksAHTBQN8enw54iej21JfpBYEdEGCx8K gN27kY46iMty53v/i5rvgM3b7Etf6H8IeufhJa+NSlW9l+OPurYcO7QupS6LRgUF7JA+h3Mrtgpfk qilZ9npxNVyQcks4Lm6ScYT0C/Q9ncJXUQNcqwB1nMLHt1FY1hvv6YuLrkBZBXyogxMnA11ws0OAW MukKRHZwlaUwA2v9Aw1nnQ4yzCAC+pyiCUENgniEg0QxeJM+sisbE/1N4tcvvoshVVgSmon0NS74A iEJ88Rgg==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPepg-00DCsG-Kh; Mon, 13 Sep 2021 05:49:07 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/13] block: convert the blk_mq_hw_ctx attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:16 +0200 Message-Id: <20210913054121.616001-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- block/blk-mq-sysfs.c | 64 +++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 253c857cba47c..cae649b83bd54 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -47,29 +47,27 @@ static void blk_mq_hw_sysfs_release(struct kobject *kobj) struct blk_mq_hw_ctx_sysfs_entry { struct attribute attr; - ssize_t (*show)(struct blk_mq_hw_ctx *, char *); - ssize_t (*store)(struct blk_mq_hw_ctx *, const char *, size_t); + void (*show)(struct blk_mq_hw_ctx *hctx, struct seq_file *sf); + ssize_t (*store)(struct blk_mq_hw_ctx *hctx, const char *buf, + size_t size); }; -static ssize_t blk_mq_hw_sysfs_show(struct kobject *kobj, - struct attribute *attr, char *page) +static int blk_mq_hw_sysfs_seq_show(struct kobject *kobj, + struct attribute *attr, struct seq_file *sf) { - struct blk_mq_hw_ctx_sysfs_entry *entry; - struct blk_mq_hw_ctx *hctx; - struct request_queue *q; - ssize_t res; - - entry = container_of(attr, struct blk_mq_hw_ctx_sysfs_entry, attr); - hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj); - q = hctx->queue; + struct blk_mq_hw_ctx_sysfs_entry *entry = + container_of(attr, struct blk_mq_hw_ctx_sysfs_entry, attr); + struct blk_mq_hw_ctx *hctx = + container_of(kobj, struct blk_mq_hw_ctx, kobj); + struct request_queue *q = hctx->queue; if (!entry->show) return -EIO; mutex_lock(&q->sysfs_lock); - res = entry->show(hctx, page); + entry->show(hctx, sf); mutex_unlock(&q->sysfs_lock); - return res; + return 0; } static ssize_t blk_mq_hw_sysfs_store(struct kobject *kobj, @@ -94,39 +92,33 @@ static ssize_t blk_mq_hw_sysfs_store(struct kobject *kobj, return res; } -static ssize_t blk_mq_hw_sysfs_nr_tags_show(struct blk_mq_hw_ctx *hctx, - char *page) +static void blk_mq_hw_sysfs_nr_tags_show(struct blk_mq_hw_ctx *hctx, + struct seq_file *sf) { - return sprintf(page, "%u\n", hctx->tags->nr_tags); + seq_printf(sf, "%u\n", hctx->tags->nr_tags); } -static ssize_t blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx, - char *page) +static void blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx, + struct seq_file *sf) { - return sprintf(page, "%u\n", hctx->tags->nr_reserved_tags); + seq_printf(sf, "%u\n", hctx->tags->nr_reserved_tags); } -static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page) +static void blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, + struct seq_file *sf) { - const size_t size = PAGE_SIZE - 1; - unsigned int i, first = 1; - int ret = 0, pos = 0; + bool first = true; + unsigned int i; for_each_cpu(i, hctx->cpumask) { if (first) - ret = snprintf(pos + page, size - pos, "%u", i); + seq_printf(sf, "%u", i); else - ret = snprintf(pos + page, size - pos, ", %u", i); - - if (ret >= size - pos) - break; - - first = 0; - pos += ret; + seq_printf(sf, ", %u", i); + first = false; } - ret = snprintf(pos + page, size + 1 - pos, "\n"); - return pos + ret; + seq_printf(sf, "\n"); } static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_tags = { @@ -151,8 +143,8 @@ static struct attribute *default_hw_ctx_attrs[] = { ATTRIBUTE_GROUPS(default_hw_ctx); static const struct sysfs_ops blk_mq_hw_sysfs_ops = { - .show = blk_mq_hw_sysfs_show, - .store = blk_mq_hw_sysfs_store, + .seq_show = blk_mq_hw_sysfs_seq_show, + .store = blk_mq_hw_sysfs_store, }; static struct kobj_type blk_mq_ktype = { From patchwork Mon Sep 13 05:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE505C433EF for ; Mon, 13 Sep 2021 05:51:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D42ED60F9B for ; Mon, 13 Sep 2021 05:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237049AbhIMFwl (ORCPT ); Mon, 13 Sep 2021 01:52:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbhIMFwk (ORCPT ); Mon, 13 Sep 2021 01:52:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D584C061574; Sun, 12 Sep 2021 22:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=8YEdkJerf6mQ5SzK6FEJIXN9xpaT7uYrq3tnYce5GtA=; b=v6ZhPrKZsQ1WlqIcHFdq6m+o4n ys5bAv3eFp2kXT3WJEXZGqW+d1GH+oOCYfrP7V+/LelBzJE9Lb8FGGIj6WG74UTEtJ70mXzKz2k6E qHjVFxDuV0Jv/SGndnmv9im2LB5PooCUjWel+sKzYpXERTo912pGeOs4WUS9zlW2DbpaqMR8iEhj2 cYlL0laTN3CrByC3iw4FLpFRkC/e0oNdA2xLPRkg9sEPr/v9TVZR4CEbRahBxSxT1kNZcYfzhNIJz zVYhEr/cDPp8NDwKYCj5BoQ+oYmnt/ZrfO+6mk8TXmzPXAbW7ZH12gxM3prCPuEnGuD9iwbwiq+W8 qxPOGCdQ==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPeqq-00DCva-2e; Mon, 13 Sep 2021 05:50:30 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/13] block: convert the blk_integrity attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:17 +0200 Message-Id: <20210913054121.616001-10-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- block/blk-integrity.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 69a12177dfb62..dca753b395539 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -214,19 +214,20 @@ bool blk_integrity_merge_bio(struct request_queue *q, struct request *req, struct integrity_sysfs_entry { struct attribute attr; - ssize_t (*show)(struct blk_integrity *, char *); + void (*show)(struct blk_integrity *bi, struct seq_file *sf); ssize_t (*store)(struct blk_integrity *, const char *, size_t); }; -static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr, - char *page) +static int integrity_attr_seq_show(struct kobject *kobj, + struct attribute *attr, struct seq_file *sf) { struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj); struct blk_integrity *bi = &disk->queue->integrity; struct integrity_sysfs_entry *entry = container_of(attr, struct integrity_sysfs_entry, attr); - return entry->show(bi, page); + entry->show(bi, sf); + return 0; } static ssize_t integrity_attr_store(struct kobject *kobj, @@ -245,23 +246,24 @@ static ssize_t integrity_attr_store(struct kobject *kobj, return ret; } -static ssize_t integrity_format_show(struct blk_integrity *bi, char *page) +static void integrity_format_show(struct blk_integrity *bi, struct seq_file *sf) { if (bi->profile && bi->profile->name) - return sprintf(page, "%s\n", bi->profile->name); + seq_printf(sf, "%s\n", bi->profile->name); else - return sprintf(page, "none\n"); + seq_printf(sf, "none\n"); } -static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page) +static void integrity_tag_size_show(struct blk_integrity *bi, + struct seq_file *sf) { - return sprintf(page, "%u\n", bi->tag_size); + seq_printf(sf, "%u\n", bi->tag_size); } -static ssize_t integrity_interval_show(struct blk_integrity *bi, char *page) +static void integrity_interval_show(struct blk_integrity *bi, + struct seq_file *sf) { - return sprintf(page, "%u\n", - bi->interval_exp ? 1 << bi->interval_exp : 0); + seq_printf(sf, "%u\n", bi->interval_exp ? 1 << bi->interval_exp : 0); } static ssize_t integrity_verify_store(struct blk_integrity *bi, @@ -278,9 +280,9 @@ static ssize_t integrity_verify_store(struct blk_integrity *bi, return count; } -static ssize_t integrity_verify_show(struct blk_integrity *bi, char *page) +static void integrity_verify_show(struct blk_integrity *bi, struct seq_file *sf) { - return sprintf(page, "%d\n", (bi->flags & BLK_INTEGRITY_VERIFY) != 0); + seq_printf(sf, "%d\n", (bi->flags & BLK_INTEGRITY_VERIFY) != 0); } static ssize_t integrity_generate_store(struct blk_integrity *bi, @@ -297,15 +299,15 @@ static ssize_t integrity_generate_store(struct blk_integrity *bi, return count; } -static ssize_t integrity_generate_show(struct blk_integrity *bi, char *page) +static void integrity_generate_show(struct blk_integrity *bi, + struct seq_file *sf) { - return sprintf(page, "%d\n", (bi->flags & BLK_INTEGRITY_GENERATE) != 0); + seq_printf(sf, "%d\n", (bi->flags & BLK_INTEGRITY_GENERATE) != 0); } -static ssize_t integrity_device_show(struct blk_integrity *bi, char *page) +static void integrity_device_show(struct blk_integrity *bi, struct seq_file *sf) { - return sprintf(page, "%u\n", - (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE) != 0); + seq_printf(sf, "%u\n", (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE) != 0); } static struct integrity_sysfs_entry integrity_format_entry = { @@ -352,8 +354,8 @@ static struct attribute *integrity_attrs[] = { ATTRIBUTE_GROUPS(integrity); static const struct sysfs_ops integrity_ops = { - .show = &integrity_attr_show, - .store = &integrity_attr_store, + .seq_show = &integrity_attr_seq_show, + .store = &integrity_attr_store, }; static struct kobj_type integrity_ktype = { From patchwork Mon Sep 13 05:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7EC9C433FE for ; Mon, 13 Sep 2021 05:53:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB64E60FED for ; Mon, 13 Sep 2021 05:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237112AbhIMFyl (ORCPT ); Mon, 13 Sep 2021 01:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237033AbhIMFyk (ORCPT ); Mon, 13 Sep 2021 01:54:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15DDDC061574; Sun, 12 Sep 2021 22:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=zd0DRhhoJ1Ji0oazcpnhPtHKb9ndmDfjDzthXEnQj4Y=; b=vOWbnf3Jmf77lRt4hfoX9Q52S6 pQdhjHBrkdAmOMivrGxVn/8reBt+LTzhRBLgs26BOGXpO4/f+LL9OYvLBtm4kOiEOfF9BiB59yttS stoovZwyCxfy94cXE19sYK5IHqszfxtRMGB2LWxnFHsZup6eVA89Bz6z1SpN4P3Nnryc/zOxIWNng IHv2nGLxuDb3WNOkXQkpKGGuYV2wXEwaBCXs3C0MwZcLDFaPkSCd+rLGBHHyZzTwkabKrveBrtShr oRaOOoxVfax4rUJP1gngo5zjgdXpSMlNVtKhA9EES26li5kCfPqFvEvw7ALTR8+9bGp2ciRQWtE1j aqEsf/9A==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPerq-00DCxU-SQ; Mon, 13 Sep 2021 05:51:05 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/13] block: convert the request_queue attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:18 +0200 Message-Id: <20210913054121.616001-11-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- block/blk-sysfs.c | 209 ++++++++++++++++++++++----------------- block/blk-throttle.c | 5 +- block/blk.h | 2 +- block/elevator.c | 21 ++-- include/linux/elevator.h | 2 +- 5 files changed, 134 insertions(+), 105 deletions(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 614d9d47de36b..ac57256db8710 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -20,14 +20,14 @@ struct queue_sysfs_entry { struct attribute attr; - ssize_t (*show)(struct request_queue *, char *); + int (*show)(struct request_queue *q, struct seq_file *sf); ssize_t (*store)(struct request_queue *, const char *, size_t); }; -static ssize_t -queue_var_show(unsigned long var, char *page) +static int queue_var_show(unsigned long var, struct seq_file *sf) { - return sprintf(page, "%lu\n", var); + seq_printf(sf, "%lu\n", var); + return 0; } static ssize_t @@ -58,9 +58,9 @@ static ssize_t queue_var_store64(s64 *var, const char *page) return 0; } -static ssize_t queue_requests_show(struct request_queue *q, char *page) +static int queue_requests_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(q->nr_requests, page); + return queue_var_show(q->nr_requests, sf); } static ssize_t @@ -86,14 +86,14 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count) return ret; } -static ssize_t queue_ra_show(struct request_queue *q, char *page) +static int queue_ra_show(struct request_queue *q, struct seq_file *sf) { unsigned long ra_kb; if (!q->disk) return -EINVAL; ra_kb = q->disk->bdi->ra_pages << (PAGE_SHIFT - 10); - return queue_var_show(ra_kb, page); + return queue_var_show(ra_kb, sf); } static ssize_t @@ -111,75 +111,83 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count) return ret; } -static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) +static int queue_max_sectors_show(struct request_queue *q, struct seq_file *sf) { int max_sectors_kb = queue_max_sectors(q) >> 1; - return queue_var_show(max_sectors_kb, page); + return queue_var_show(max_sectors_kb, sf); } -static ssize_t queue_max_segments_show(struct request_queue *q, char *page) +static int queue_max_segments_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(queue_max_segments(q), page); + return queue_var_show(queue_max_segments(q), sf); } -static ssize_t queue_max_discard_segments_show(struct request_queue *q, - char *page) +static int queue_max_discard_segments_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_max_discard_segments(q), page); + return queue_var_show(queue_max_discard_segments(q), sf); } -static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) +static int queue_max_integrity_segments_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(q->limits.max_integrity_segments, page); + return queue_var_show(q->limits.max_integrity_segments, sf); } -static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) +static int queue_max_segment_size_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_max_segment_size(q), page); + return queue_var_show(queue_max_segment_size(q), sf); } -static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page) +static int queue_logical_block_size_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_logical_block_size(q), page); + return queue_var_show(queue_logical_block_size(q), sf); } -static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page) +static int queue_physical_block_size_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_physical_block_size(q), page); + return queue_var_show(queue_physical_block_size(q), sf); } -static ssize_t queue_chunk_sectors_show(struct request_queue *q, char *page) +static int queue_chunk_sectors_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(q->limits.chunk_sectors, page); + return queue_var_show(q->limits.chunk_sectors, sf); } -static ssize_t queue_io_min_show(struct request_queue *q, char *page) +static int queue_io_min_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(queue_io_min(q), page); + return queue_var_show(queue_io_min(q), sf); } -static ssize_t queue_io_opt_show(struct request_queue *q, char *page) +static int queue_io_opt_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(queue_io_opt(q), page); + return queue_var_show(queue_io_opt(q), sf); } -static ssize_t queue_discard_granularity_show(struct request_queue *q, char *page) +static int queue_discard_granularity_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(q->limits.discard_granularity, page); + return queue_var_show(q->limits.discard_granularity, sf); } -static ssize_t queue_discard_max_hw_show(struct request_queue *q, char *page) +static int queue_discard_max_hw_show(struct request_queue *q, + struct seq_file *sf) { - - return sprintf(page, "%llu\n", + seq_printf(sf, "%llu\n", (unsigned long long)q->limits.max_hw_discard_sectors << 9); + return 0; } -static ssize_t queue_discard_max_show(struct request_queue *q, char *page) +static int queue_discard_max_show(struct request_queue *q, struct seq_file *sf) { - return sprintf(page, "%llu\n", - (unsigned long long)q->limits.max_discard_sectors << 9); + seq_printf(sf, "%llu\n", + (unsigned long long)q->limits.max_discard_sectors << 9); + return 0; } static ssize_t queue_discard_max_store(struct request_queue *q, @@ -205,34 +213,41 @@ static ssize_t queue_discard_max_store(struct request_queue *q, return ret; } -static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page) +static int queue_discard_zeroes_data_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(0, page); + return queue_var_show(0, sf); } -static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) +static int queue_write_same_max_show(struct request_queue *q, + struct seq_file *sf) { - return sprintf(page, "%llu\n", + seq_printf(sf, "%llu\n", (unsigned long long)q->limits.max_write_same_sectors << 9); + return 0; } -static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) +static int queue_write_zeroes_max_show(struct request_queue *q, + struct seq_file *sf) { - return sprintf(page, "%llu\n", + seq_printf(sf, "%llu\n", (unsigned long long)q->limits.max_write_zeroes_sectors << 9); + return 0; } -static ssize_t queue_zone_write_granularity_show(struct request_queue *q, - char *page) +static int queue_zone_write_granularity_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_zone_write_granularity(q), page); + return queue_var_show(queue_zone_write_granularity(q), sf); } -static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) +static int queue_zone_append_max_show(struct request_queue *q, + struct seq_file *sf) { unsigned long long max_sectors = q->limits.max_zone_append_sectors; - return sprintf(page, "%llu\n", max_sectors << SECTOR_SHIFT); + seq_printf(sf, "%llu\n", max_sectors << SECTOR_SHIFT); + return 0; } static ssize_t @@ -261,25 +276,27 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) return ret; } -static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) +static int queue_max_hw_sectors_show(struct request_queue *q, + struct seq_file *sf) { int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1; - return queue_var_show(max_hw_sectors_kb, page); + return queue_var_show(max_hw_sectors_kb, sf); } -static ssize_t queue_virt_boundary_mask_show(struct request_queue *q, char *page) +static int queue_virt_boundary_mask_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(q->limits.virt_boundary_mask, page); + return queue_var_show(q->limits.virt_boundary_mask, sf); } #define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \ -static ssize_t \ -queue_##name##_show(struct request_queue *q, char *page) \ +static int \ +queue_##name##_show(struct request_queue *q, struct seq_file *sf) \ { \ int bit; \ bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \ - return queue_var_show(neg ? !bit : bit, page); \ + return queue_var_show(neg ? !bit : bit, sf); \ } \ static ssize_t \ queue_##name##_store(struct request_queue *q, const char *page, size_t count) \ @@ -305,37 +322,43 @@ QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0); QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0); #undef QUEUE_SYSFS_BIT_FNS -static ssize_t queue_zoned_show(struct request_queue *q, char *page) +static int queue_zoned_show(struct request_queue *q, + struct seq_file *sf) { switch (blk_queue_zoned_model(q)) { case BLK_ZONED_HA: - return sprintf(page, "host-aware\n"); + seq_printf(sf, "host-aware\n"); + return 0; case BLK_ZONED_HM: - return sprintf(page, "host-managed\n"); + seq_printf(sf, "host-managed\n"); + return 0; default: - return sprintf(page, "none\n"); + seq_printf(sf, "none\n"); + return 0; } } -static ssize_t queue_nr_zones_show(struct request_queue *q, char *page) +static int queue_nr_zones_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(blk_queue_nr_zones(q), page); + return queue_var_show(blk_queue_nr_zones(q), sf); } -static ssize_t queue_max_open_zones_show(struct request_queue *q, char *page) +static int queue_max_open_zones_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_max_open_zones(q), page); + return queue_var_show(queue_max_open_zones(q), sf); } -static ssize_t queue_max_active_zones_show(struct request_queue *q, char *page) +static int queue_max_active_zones_show(struct request_queue *q, + struct seq_file *sf) { - return queue_var_show(queue_max_active_zones(q), page); + return queue_var_show(queue_max_active_zones(q), sf); } -static ssize_t queue_nomerges_show(struct request_queue *q, char *page) +static int queue_nomerges_show(struct request_queue *q, struct seq_file *sf) { return queue_var_show((blk_queue_nomerges(q) << 1) | - blk_queue_noxmerges(q), page); + blk_queue_noxmerges(q), sf); } static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, @@ -357,12 +380,12 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, return ret; } -static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page) +static int queue_rq_affinity_show(struct request_queue *q, struct seq_file *sf) { bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags); bool force = test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags); - return queue_var_show(set << force, page); + return queue_var_show(set << force, sf); } static ssize_t @@ -390,7 +413,7 @@ queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count) return ret; } -static ssize_t queue_poll_delay_show(struct request_queue *q, char *page) +static int queue_poll_delay_show(struct request_queue *q, struct seq_file *sf) { int val; @@ -399,7 +422,8 @@ static ssize_t queue_poll_delay_show(struct request_queue *q, char *page) else val = q->poll_nsec / 1000; - return sprintf(page, "%d\n", val); + seq_printf(sf, "%d\n", val); + return 0; } static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, @@ -424,9 +448,9 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, return count; } -static ssize_t queue_poll_show(struct request_queue *q, char *page) +static int queue_poll_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), page); + return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), sf); } static ssize_t queue_poll_store(struct request_queue *q, const char *page, @@ -454,9 +478,10 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page, return ret; } -static ssize_t queue_io_timeout_show(struct request_queue *q, char *page) +static int queue_io_timeout_show(struct request_queue *q, struct seq_file *sf) { - return sprintf(page, "%u\n", jiffies_to_msecs(q->rq_timeout)); + seq_printf(sf, "%u\n", jiffies_to_msecs(q->rq_timeout)); + return 0; } static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page, @@ -474,12 +499,12 @@ static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page, return count; } -static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) +static int queue_wb_lat_show(struct request_queue *q, struct seq_file *sf) { if (!wbt_rq_qos(q)) return -EINVAL; - - return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); + seq_printf(sf, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); + return 0; } static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, @@ -526,12 +551,13 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, return count; } -static ssize_t queue_wc_show(struct request_queue *q, char *page) +static int queue_wc_show(struct request_queue *q, struct seq_file *sf) { if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) - return sprintf(page, "write back\n"); - - return sprintf(page, "write through\n"); + seq_printf(sf, "write back\n"); + else + seq_printf(sf, "write through\n"); + return 0; } static ssize_t queue_wc_store(struct request_queue *q, const char *page, @@ -556,14 +582,15 @@ static ssize_t queue_wc_store(struct request_queue *q, const char *page, return count; } -static ssize_t queue_fua_show(struct request_queue *q, char *page) +static int queue_fua_show(struct request_queue *q, struct seq_file *sf) { - return sprintf(page, "%u\n", test_bit(QUEUE_FLAG_FUA, &q->queue_flags)); + seq_printf(sf, "%u\n", test_bit(QUEUE_FLAG_FUA, &q->queue_flags)); + return 0; } -static ssize_t queue_dax_show(struct request_queue *q, char *page) +static int queue_dax_show(struct request_queue *q, struct seq_file *sf) { - return queue_var_show(blk_queue_dax(q), page); + return queue_var_show(blk_queue_dax(q), sf); } #define QUEUE_RO_ENTRY(_prefix, _name) \ @@ -710,8 +737,8 @@ static struct attribute_group queue_attr_group = { #define to_queue(atr) container_of((atr), struct queue_sysfs_entry, attr) -static ssize_t -queue_attr_show(struct kobject *kobj, struct attribute *attr, char *page) +static int queue_attr_seq_show(struct kobject *kobj, struct attribute *attr, + struct seq_file *sf) { struct queue_sysfs_entry *entry = to_queue(attr); struct request_queue *q = @@ -721,7 +748,7 @@ queue_attr_show(struct kobject *kobj, struct attribute *attr, char *page) if (!entry->show) return -EIO; mutex_lock(&q->sysfs_lock); - res = entry->show(q, page); + res = entry->show(q, sf); mutex_unlock(&q->sysfs_lock); return res; } @@ -837,8 +864,8 @@ static void blk_release_queue(struct kobject *kobj) } static const struct sysfs_ops queue_sysfs_ops = { - .show = queue_attr_show, - .store = queue_attr_store, + .seq_show = queue_attr_seq_show, + .store = queue_attr_store, }; struct kobj_type blk_queue_ktype = { diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 7c4e7993ba970..579d31f0269bf 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2496,11 +2496,12 @@ void blk_throtl_register_queue(struct request_queue *q) } #ifdef CONFIG_BLK_DEV_THROTTLING_LOW -ssize_t blk_throtl_sample_time_show(struct request_queue *q, char *page) +int blk_throtl_sample_time_show(struct request_queue *q, struct seq_file *sf) { if (!q->td) return -EINVAL; - return sprintf(page, "%u\n", jiffies_to_msecs(q->td->throtl_slice)); + seq_printf(sf, "%u\n", jiffies_to_msecs(q->td->throtl_slice)); + return 0; } ssize_t blk_throtl_sample_time_store(struct request_queue *q, diff --git a/block/blk.h b/block/blk.h index 7d2a0ba7ed21d..69b9b6b3b2169 100644 --- a/block/blk.h +++ b/block/blk.h @@ -300,7 +300,7 @@ static inline void blk_throtl_charge_bio_split(struct bio *bio) { } static inline bool blk_throtl_bio(struct bio *bio) { return false; } #endif /* CONFIG_BLK_DEV_THROTTLING */ #ifdef CONFIG_BLK_DEV_THROTTLING_LOW -extern ssize_t blk_throtl_sample_time_show(struct request_queue *q, char *page); +int blk_throtl_sample_time_show(struct request_queue *q, struct seq_file *sf); extern ssize_t blk_throtl_sample_time_store(struct request_queue *q, const char *page, size_t count); extern void blk_throtl_bio_endio(struct bio *bio); diff --git a/block/elevator.c b/block/elevator.c index ff45d8388f487..f068585f2f9b8 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -782,39 +782,40 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name, return ret; } -ssize_t elv_iosched_show(struct request_queue *q, char *name) +int elv_iosched_show(struct request_queue *q, struct seq_file *sf) { struct elevator_queue *e = q->elevator; struct elevator_type *elv = NULL; struct elevator_type *__e; - int len = 0; - if (!queue_is_mq(q)) - return sprintf(name, "none\n"); + if (!queue_is_mq(q)) { + seq_printf(sf, "none\n"); + return 0; + } if (!q->elevator) - len += sprintf(name+len, "[none] "); + seq_printf(sf, "[none] "); else elv = e->type; spin_lock(&elv_list_lock); list_for_each_entry(__e, &elv_list, list) { if (elv && elevator_match(elv, __e->elevator_name, 0)) { - len += sprintf(name+len, "[%s] ", elv->elevator_name); + seq_printf(sf, "[%s] ", elv->elevator_name); continue; } if (elv_support_iosched(q) && elevator_match(__e, __e->elevator_name, q->required_elevator_features)) - len += sprintf(name+len, "%s ", __e->elevator_name); + seq_printf(sf, "%s ", __e->elevator_name); } spin_unlock(&elv_list_lock); if (q->elevator) - len += sprintf(name+len, "none"); + seq_printf(sf, "none"); - len += sprintf(len+name, "\n"); - return len; + seq_printf(sf, "\n"); + return 0; } struct request *elv_rb_former_request(struct request_queue *q, diff --git a/include/linux/elevator.h b/include/linux/elevator.h index ef9ceead3db13..deecf7f9ff21a 100644 --- a/include/linux/elevator.h +++ b/include/linux/elevator.h @@ -132,7 +132,7 @@ extern void elv_unregister(struct elevator_type *); /* * io scheduler sysfs switching */ -extern ssize_t elv_iosched_show(struct request_queue *, char *); +int elv_iosched_show(struct request_queue *q, struct seq_file *sf); extern ssize_t elv_iosched_store(struct request_queue *, const char *, size_t); extern bool elv_bio_merge_ok(struct request *, struct bio *); From patchwork Mon Sep 13 05:41:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9EBEC433EF for ; Mon, 13 Sep 2021 05:56:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1AF960FF2 for ; Mon, 13 Sep 2021 05:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237115AbhIMF55 (ORCPT ); Mon, 13 Sep 2021 01:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237032AbhIMF54 (ORCPT ); Mon, 13 Sep 2021 01:57:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A740C061574; Sun, 12 Sep 2021 22:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sQ7WZDPB/0FsX6UYbW3121WLPwXJuFVnksnNbQSfWlE=; b=W27ZPTjzCZrYvlYKGYXbNMlly1 i0Xk84aAEWiw04y7JFEf2rrJ6Qxn/HXIRq0MFKFtoWxbqBnL746ac5D/3Jo7X9GUp9DoPVomyY0AF KIPOBQbe/6BPSQTnT5Cn+dF/q9nyXLN5383o0vBND/UTdSpNVS+FTiEL7D36UFqvFG/GZRRw8f/sF 3NdY+JVBlR39pewg1ZQGIBVIplsfRklHQMvHrBeo3uckOJ6rzJbHBtHzgfJHGi18OFMPOBikA/FIv N8D4mjW7mrBFpTTrUiXNo/4/7qyNEN9aMg2P4WRRLK5yNpm7+V0erkqZmebjPglU2qsRjRB8YgKUY CpD6hNuQ==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPesc-00DD0b-W1; Mon, 13 Sep 2021 05:52:43 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/13] block: convert the elevator_queue attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:19 +0200 Message-Id: <20210913054121.616001-12-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- block/bfq-iosched.c | 12 ++++++------ block/elevator.c | 21 ++++++++++++--------- block/kyber-iosched.c | 7 ++++--- block/mq-deadline.c | 5 +++-- include/linux/elevator.h | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index dd13c2bbc29c1..a72b4f90f3ba2 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -7092,9 +7092,9 @@ static int __init bfq_slab_setup(void) return 0; } -static ssize_t bfq_var_show(unsigned int var, char *page) +static void bfq_var_show(unsigned int var, struct seq_file *sf) { - return sprintf(page, "%u\n", var); + seq_printf(sf, "%u\n", var); } static int bfq_var_store(unsigned long *var, const char *page) @@ -7109,7 +7109,7 @@ static int bfq_var_store(unsigned long *var, const char *page) } #define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \ -static ssize_t __FUNC(struct elevator_queue *e, char *page) \ +static void __FUNC(struct elevator_queue *e, struct seq_file *sf) \ { \ struct bfq_data *bfqd = e->elevator_data; \ u64 __data = __VAR; \ @@ -7117,7 +7117,7 @@ static ssize_t __FUNC(struct elevator_queue *e, char *page) \ __data = jiffies_to_msecs(__data); \ else if (__CONV == 2) \ __data = div_u64(__data, NSEC_PER_MSEC); \ - return bfq_var_show(__data, (page)); \ + bfq_var_show(__data, (sf)); \ } SHOW_FUNCTION(bfq_fifo_expire_sync_show, bfqd->bfq_fifo_expire[1], 2); SHOW_FUNCTION(bfq_fifo_expire_async_show, bfqd->bfq_fifo_expire[0], 2); @@ -7131,12 +7131,12 @@ SHOW_FUNCTION(bfq_low_latency_show, bfqd->low_latency, 0); #undef SHOW_FUNCTION #define USEC_SHOW_FUNCTION(__FUNC, __VAR) \ -static ssize_t __FUNC(struct elevator_queue *e, char *page) \ +static void __FUNC(struct elevator_queue *e, struct seq_file *sf) \ { \ struct bfq_data *bfqd = e->elevator_data; \ u64 __data = __VAR; \ __data = div_u64(__data, NSEC_PER_USEC); \ - return bfq_var_show(__data, (page)); \ + bfq_var_show(__data, (sf)); \ } USEC_SHOW_FUNCTION(bfq_slice_idle_us_show, bfqd->bfq_slice_idle); #undef USEC_SHOW_FUNCTION diff --git a/block/elevator.c b/block/elevator.c index f068585f2f9b8..951bae559e5cb 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -442,21 +442,24 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq) #define to_elv(atr) container_of((atr), struct elv_fs_entry, attr) -static ssize_t -elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page) +static int elv_attr_seq_show(struct kobject *kobj, struct attribute *attr, + struct seq_file *sf) { struct elv_fs_entry *entry = to_elv(attr); - struct elevator_queue *e; - ssize_t error; + struct elevator_queue *e = + container_of(kobj, struct elevator_queue, kobj); if (!entry->show) return -EIO; - e = container_of(kobj, struct elevator_queue, kobj); mutex_lock(&e->sysfs_lock); - error = e->type ? entry->show(e, page) : -ENOENT; + if (!e->type) { + mutex_unlock(&e->sysfs_lock); + return -ENOENT; + } + entry->show(e, sf); mutex_unlock(&e->sysfs_lock); - return error; + return 0; } static ssize_t @@ -478,8 +481,8 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr, } static const struct sysfs_ops elv_sysfs_ops = { - .show = elv_attr_show, - .store = elv_attr_store, + .seq_show = elv_attr_seq_show, + .store = elv_attr_store, }; static struct kobj_type elv_ktype = { diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c index 15a8be57203d6..633f9654b99b9 100644 --- a/block/kyber-iosched.c +++ b/block/kyber-iosched.c @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -857,12 +858,12 @@ static bool kyber_has_work(struct blk_mq_hw_ctx *hctx) } #define KYBER_LAT_SHOW_STORE(domain, name) \ -static ssize_t kyber_##name##_lat_show(struct elevator_queue *e, \ - char *page) \ +static void kyber_##name##_lat_show(struct elevator_queue *e, \ + struct seq_file *sf) \ { \ struct kyber_queue_data *kqd = e->elevator_data; \ \ - return sprintf(page, "%llu\n", kqd->latency_targets[domain]); \ + seq_printf(sf, "%llu\n", kqd->latency_targets[domain]); \ } \ \ static ssize_t kyber_##name##_lat_store(struct elevator_queue *e, \ diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 7f3c3932b723e..0e1fc6d3e5d64 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -800,11 +801,11 @@ static bool dd_has_work(struct blk_mq_hw_ctx *hctx) * sysfs parts below */ #define SHOW_INT(__FUNC, __VAR) \ -static ssize_t __FUNC(struct elevator_queue *e, char *page) \ +static void __FUNC(struct elevator_queue *e, struct seq_file *sf) \ { \ struct deadline_data *dd = e->elevator_data; \ \ - return sysfs_emit(page, "%d\n", __VAR); \ + seq_printf(sf, "%d\n", __VAR); \ } #define SHOW_JIFFIES(__FUNC, __VAR) SHOW_INT(__FUNC, jiffies_to_msecs(__VAR)) SHOW_JIFFIES(deadline_read_expire_show, dd->fifo_expire[DD_READ]); diff --git a/include/linux/elevator.h b/include/linux/elevator.h index deecf7f9ff21a..ad5e4cb653a30 100644 --- a/include/linux/elevator.h +++ b/include/linux/elevator.h @@ -56,7 +56,7 @@ struct elevator_mq_ops { struct elv_fs_entry { struct attribute attr; - ssize_t (*show)(struct elevator_queue *, char *); + void (*show)(struct elevator_queue *eq, struct seq_file *sf); ssize_t (*store)(struct elevator_queue *, const char *, size_t); }; From patchwork Mon Sep 13 05:41:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF9A7C433FE for ; Mon, 13 Sep 2021 05:58:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAFDE60F9B for ; Mon, 13 Sep 2021 05:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237192AbhIMF7r (ORCPT ); Mon, 13 Sep 2021 01:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237072AbhIMF7r (ORCPT ); Mon, 13 Sep 2021 01:59:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9307C061574; Sun, 12 Sep 2021 22:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=SDg0Mwos9YPZVttdSdsXikDW9x/t9+tGLWXXq2nNYAU=; b=KgyQ1sxek7HKAbyrIIBlyyLLf1 0cBAx2qctdhqpVYPHuoQ+DFsqB4lrOqlBo79gyAzpFy6erREbV1avl5/LoDkaTcSGRf+Ou+7AiZJU w+yc58++nId3BfoAKKPSC/jiwzXWAALFwmGPkCD8WHs6XaL2eAVA8nKpGcHTF01mFuUSgS9lYYhLq DR4ZLNMPCYipmG8/Zx9PMlZKPczPtrOO/CF1VKMIfKI56LYdmATB2olm/W8Kim+Zzg76qrVKbXu2P WTcNTKD43OItXeYHxgX1tYZThkKD/Gkvq5FykXNp8488aVud4tcjTq4RCihkk83NlZemW28Kn3AUp bCdf57WQ==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPeuj-00DD4H-50; Mon, 13 Sep 2021 05:55:01 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/13] xfs: convert xfs_errortag attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:20 +0200 Message-Id: <20210913054121.616001-13-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_error.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 81c445e9489bd..143a1e0b12ffe 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -104,22 +104,22 @@ xfs_errortag_attr_store( return count; } -STATIC ssize_t -xfs_errortag_attr_show( +STATIC int +xfs_errortag_attr_seq_show( struct kobject *kobject, struct attribute *attr, - char *buf) + struct seq_file *sf) { struct xfs_mount *mp = to_mp(kobject); struct xfs_errortag_attr *xfs_attr = to_attr(attr); - return snprintf(buf, PAGE_SIZE, "%u\n", - xfs_errortag_get(mp, xfs_attr->tag)); + seq_printf(sf, "%u\n", xfs_errortag_get(mp, xfs_attr->tag)); + return 0; } static const struct sysfs_ops xfs_errortag_sysfs_ops = { - .show = xfs_errortag_attr_show, - .store = xfs_errortag_attr_store, + .seq_show = xfs_errortag_attr_seq_show, + .store = xfs_errortag_attr_store, }; #define XFS_ERRORTAG_ATTR_RW(_name, _tag) \ From patchwork Mon Sep 13 05:41:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12487933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 985E3C433F5 for ; Mon, 13 Sep 2021 05:59:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 706E660F46 for ; Mon, 13 Sep 2021 05:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237122AbhIMGAx (ORCPT ); Mon, 13 Sep 2021 02:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237072AbhIMGAw (ORCPT ); Mon, 13 Sep 2021 02:00:52 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A4BDC061574; Sun, 12 Sep 2021 22:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Q5g6HBLS9wMXdCb/wrDI9KH3R+0o9ydrgII9VUtQbLk=; b=cZ/Y6t0O3ixYHqgOKujGrkEcZq ZQfWjGQbbqkRcbfGvhtKVS9CZFx7jujqD7NEGw1VNeIbJV1hi37JaOjsRtPYB1ZlAhbZjoywedejj Fn5n+f6SkStf8BJohMHAf5CmbPh1c+QlpQEaSpWk4Am21cY3yTS5m+9ZrMYS/CvnbIfb41o9UyAOX 4VyFOU5nSpteXCW54KXn71I7m+FSg4ZsjAcUbNJNoevanyWn5hDs5bdLtktNGCOBLcZQUyUAqWiCK qnpJhM5kAsrS8+9dOkMhKWatFMNu62jynxkcP0PudMT6p/RT0mX0Ba8iIp40TdBP5JkqlsOhEUVEe tN+MqwGQ==; Received: from 089144214237.atnat0023.highway.a1.net ([89.144.214.237] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPexl-00DDEh-B8; Mon, 13 Sep 2021 05:57:57 +0000 From: Christoph Hellwig To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro Cc: Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/13] xfs: convert xfs_sysfs attrs to use ->seq_show Date: Mon, 13 Sep 2021 07:41:21 +0200 Message-Id: <20210913054121.616001-14-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913054121.616001-1-hch@lst.de> References: <20210913054121.616001-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Trivial conversion to the seq_file based sysfs attributes. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_stats.c | 24 +++++------- fs/xfs/xfs_stats.h | 2 +- fs/xfs/xfs_sysfs.c | 96 +++++++++++++++++++++++----------------------- 3 files changed, 58 insertions(+), 64 deletions(-) diff --git a/fs/xfs/xfs_stats.c b/fs/xfs/xfs_stats.c index 20e0534a772c9..71e7a84ba0403 100644 --- a/fs/xfs/xfs_stats.c +++ b/fs/xfs/xfs_stats.c @@ -16,10 +16,9 @@ static int counter_val(struct xfsstats __percpu *stats, int idx) return val; } -int xfs_stats_format(struct xfsstats __percpu *stats, char *buf) +void xfs_stats_format(struct xfsstats __percpu *stats, struct seq_file *sf) { int i, j; - int len = 0; uint64_t xs_xstrat_bytes = 0; uint64_t xs_write_bytes = 0; uint64_t xs_read_bytes = 0; @@ -58,13 +57,12 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf) /* Loop over all stats groups */ for (i = j = 0; i < ARRAY_SIZE(xstats); i++) { - len += scnprintf(buf + len, PATH_MAX - len, "%s", - xstats[i].desc); + seq_printf(sf, "%s", xstats[i].desc); + /* inner loop does each group */ for (; j < xstats[i].endpoint; j++) - len += scnprintf(buf + len, PATH_MAX - len, " %u", - counter_val(stats, j)); - len += scnprintf(buf + len, PATH_MAX - len, "\n"); + seq_printf(sf, " %u", counter_val(stats, j)); + seq_printf(sf, "\n"); } /* extra precision counters */ for_each_possible_cpu(i) { @@ -74,18 +72,14 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf) defer_relog += per_cpu_ptr(stats, i)->s.defer_relog; } - len += scnprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n", + seq_printf(sf, "xpc %Lu %Lu %Lu\n", xs_xstrat_bytes, xs_write_bytes, xs_read_bytes); - len += scnprintf(buf + len, PATH_MAX-len, "defer_relog %llu\n", - defer_relog); - len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n", + seq_printf(sf, "defer_relog %llu\n", defer_relog); #if defined(DEBUG) - 1); + seq_printf(sf, "debug 1\n"); #else - 0); + seq_printf(sf, "debug 0\n"); #endif - - return len; } void xfs_stats_clearall(struct xfsstats __percpu *stats) diff --git a/fs/xfs/xfs_stats.h b/fs/xfs/xfs_stats.h index 43ffba74f045e..6bf80565893cf 100644 --- a/fs/xfs/xfs_stats.h +++ b/fs/xfs/xfs_stats.h @@ -156,7 +156,7 @@ struct xfsstats { (offsetof(struct __xfsstats, member) / (int)sizeof(uint32_t)) -int xfs_stats_format(struct xfsstats __percpu *stats, char *buf); +void xfs_stats_format(struct xfsstats __percpu *stats, struct seq_file *sf); void xfs_stats_clearall(struct xfsstats __percpu *stats); extern struct xstats xfsstats; diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c index 18dc5eca6c045..efa2aa07f1865 100644 --- a/fs/xfs/xfs_sysfs.c +++ b/fs/xfs/xfs_sysfs.c @@ -16,7 +16,7 @@ struct xfs_sysfs_attr { struct attribute attr; - ssize_t (*show)(struct kobject *kobject, char *buf); + void (*show)(struct kobject *kobject, struct seq_file *sf); ssize_t (*store)(struct kobject *kobject, const char *buf, size_t count); }; @@ -36,15 +36,17 @@ to_attr(struct attribute *attr) #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr -STATIC ssize_t -xfs_sysfs_object_show( +STATIC int +xfs_sysfs_object_seq_show( struct kobject *kobject, struct attribute *attr, - char *buf) + struct seq_file *sf) { struct xfs_sysfs_attr *xfs_attr = to_attr(attr); - return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0; + if (xfs_attr->show) + xfs_attr->show(kobject, sf); + return 0; } STATIC ssize_t @@ -60,8 +62,8 @@ xfs_sysfs_object_store( } static const struct sysfs_ops xfs_sysfs_ops = { - .show = xfs_sysfs_object_show, - .store = xfs_sysfs_object_store, + .seq_show = xfs_sysfs_object_seq_show, + .store = xfs_sysfs_object_store, }; static struct attribute *xfs_mp_attrs[] = { @@ -100,12 +102,12 @@ bug_on_assert_store( return count; } -STATIC ssize_t +STATIC void bug_on_assert_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bug_on_assert ? 1 : 0); + seq_printf(sf, "%d\n", xfs_globals.bug_on_assert ? 1 : 0); } XFS_SYSFS_ATTR_RW(bug_on_assert); @@ -130,12 +132,12 @@ log_recovery_delay_store( return count; } -STATIC ssize_t +STATIC void log_recovery_delay_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay); + seq_printf(sf, "%d\n", xfs_globals.log_recovery_delay); } XFS_SYSFS_ATTR_RW(log_recovery_delay); @@ -160,12 +162,12 @@ mount_delay_store( return count; } -STATIC ssize_t +STATIC void mount_delay_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.mount_delay); + seq_printf(sf, "%d\n", xfs_globals.mount_delay); } XFS_SYSFS_ATTR_RW(mount_delay); @@ -183,12 +185,12 @@ always_cow_store( return count; } -static ssize_t +static void always_cow_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.always_cow); + seq_printf(sf, "%d\n", xfs_globals.always_cow); } XFS_SYSFS_ATTR_RW(always_cow); @@ -219,12 +221,12 @@ pwork_threads_store( return count; } -STATIC ssize_t +STATIC void pwork_threads_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.pwork_threads); + seq_printf(sf, "%d\n", xfs_globals.pwork_threads); } XFS_SYSFS_ATTR_RW(pwork_threads); #endif /* DEBUG */ @@ -258,14 +260,12 @@ to_xstats(struct kobject *kobject) return container_of(kobj, struct xstats, xs_kobj); } -STATIC ssize_t +STATIC void stats_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { - struct xstats *stats = to_xstats(kobject); - - return xfs_stats_format(stats->xs_stats, buf); + return xfs_stats_format(to_xstats(kobject)->xs_stats, sf); } XFS_SYSFS_ATTR_RO(stats); @@ -313,10 +313,10 @@ to_xlog(struct kobject *kobject) return container_of(kobj, struct xlog, l_kobj); } -STATIC ssize_t +STATIC void log_head_lsn_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int cycle; int block; @@ -327,28 +327,28 @@ log_head_lsn_show( block = log->l_curr_block; spin_unlock(&log->l_icloglock); - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); + seq_printf(sf, "%d:%d\n", cycle, block); } XFS_SYSFS_ATTR_RO(log_head_lsn); -STATIC ssize_t +STATIC void log_tail_lsn_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int cycle; int block; struct xlog *log = to_xlog(kobject); xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block); - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); + seq_printf(sf, "%d:%d\n", cycle, block); } XFS_SYSFS_ATTR_RO(log_tail_lsn); -STATIC ssize_t +STATIC void reserve_grant_head_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int cycle; @@ -356,21 +356,21 @@ reserve_grant_head_show( struct xlog *log = to_xlog(kobject); xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes); - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); + seq_printf(sf, "%d:%d\n", cycle, bytes); } XFS_SYSFS_ATTR_RO(reserve_grant_head); -STATIC ssize_t +STATIC void write_grant_head_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int cycle; int bytes; struct xlog *log = to_xlog(kobject); xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes); - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); + seq_printf(sf, "%d:%d\n", cycle, bytes); } XFS_SYSFS_ATTR_RO(write_grant_head); @@ -412,10 +412,10 @@ err_to_mp(struct kobject *kobject) return container_of(kobj, struct xfs_mount, m_error_kobj); } -static ssize_t +static void max_retries_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int retries; struct xfs_error_cfg *cfg = to_error_cfg(kobject); @@ -425,7 +425,7 @@ max_retries_show( else retries = cfg->max_retries; - return snprintf(buf, PAGE_SIZE, "%d\n", retries); + seq_printf(sf, "%d\n", retries); } static ssize_t @@ -453,10 +453,10 @@ max_retries_store( } XFS_SYSFS_ATTR_RW(max_retries); -static ssize_t +static void retry_timeout_seconds_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { int timeout; struct xfs_error_cfg *cfg = to_error_cfg(kobject); @@ -466,7 +466,7 @@ retry_timeout_seconds_show( else timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC; - return snprintf(buf, PAGE_SIZE, "%d\n", timeout); + seq_printf(sf, "%d\n", timeout); } static ssize_t @@ -497,14 +497,14 @@ retry_timeout_seconds_store( } XFS_SYSFS_ATTR_RW(retry_timeout_seconds); -static ssize_t +static void fail_at_unmount_show( struct kobject *kobject, - char *buf) + struct seq_file *sf) { struct xfs_mount *mp = err_to_mp(kobject); - return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_unmount); + seq_printf(sf, "%d\n", mp->m_fail_unmount); } static ssize_t