Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1779083imm; Wed, 16 May 2018 03:00:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq3LAZhwdkTQBh//dySEweUYIJWdGNHxNhA9PaQB5a29Jb7CTFQdR2Z50yCwxf6TcvK8RQW X-Received: by 2002:a17:902:7d09:: with SMTP id z9-v6mr253863pll.4.1526464800543; Wed, 16 May 2018 03:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526464800; cv=none; d=google.com; s=arc-20160816; b=qNeqT1LK854ZH/R0Veoj7dWB/0o384opUM269hwyWrxlydES+AkxqjZmDiqoimNBhw OFGhMJjryEJWBCqAM400oEJZBiq/2/K6J3Tn6KkY+DlBskTjL4tO73uUtuz068FjemOn 5nsZOD7uaehu4Mm1DZxew15qimh2de5eaMZbX0Vhp+wP4JlYcu2qSKKWWZjZlqRyvEr0 9l2/+qJqZIMs0GiEQTFcpsyLw8OFTjGpaE//x0qLcWD5XVgFm/+nigQ4O6dU+AB3rXDL HZuc+N4VXzadGws7I7T42bIvdKaO/piwQMgkXdcUngRa6nGqrIEkKLcGzt0Y6gqmZFAD ecZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SE/Bfwh/pFpB5D945bg+atQWGn0r5VzAsJkE5LDfSHs=; b=TUdb1PGlFZesAXT3n6YBR/r3lJyZrbYFgJoHAl6eSWAlK5x+/4RB3IxaUM9Nc5pmYM 4QAWrdZG736yDjcVt03mupZbZB6R3CPZcQof873/l+UrkWDAArxAml+UUHn13cgGN+JG FAipooSKUUvFx22z4YSfonmsDULg7uVK96Mxvj8M1IF/9Y5ILnnqIVOzAW4SRnrXOCDw gB5gt1wPRQWzvvZ2OtJWZFQvtBqAnqJDgZEF+J8PC6QsgxAYt38kllMWk24xo8VBYCDu 1yiThC1YNbF7jcmxHMBskLAXHBJQte0PFIN+7ZkAUWSyaZtCNxESYFnQCwhjoAc5pjpO ofxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZT/lKR2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si2064085pli.427.2018.05.16.02.59.46; Wed, 16 May 2018 03:00:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZT/lKR2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753143AbeEPJ5z (ORCPT + 99 others); Wed, 16 May 2018 05:57:55 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48122 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752774AbeEPJqW (ORCPT ); Wed, 16 May 2018 05:46:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SE/Bfwh/pFpB5D945bg+atQWGn0r5VzAsJkE5LDfSHs=; b=ZT/lKR2NcROFR3r7Pa+mXKQzo OJqLr2n8la/DZ2EaNNMcbDkE/nCVV6cM0ek92NTBh+UQ0EMc7r26VOOoi0yjC2pLN+C3U7t+G1QBS +Xr+bpm/SmD7H2wcDJ394BOIv6vOj9qYPCNNWI0MqrX0DHEasaerjkdhtmw9x5P2k+iRCHqSbXM7n elYN4NUaWIgPp2fYjady4X1SfjJRtKhjkXOb9EdiXUzFTbB+kLppremSOWtOpot68JV11l4Aapu+C GJUTq5NUZFqvaUcHvwxd2nZjZFicwG9WQqJ8gZhu5Y4k5NR/E+dP/MMParh7k6gPYNIPq23yHk3yg y0EaM/PRg==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIt04-0007VJ-Il; Wed, 16 May 2018 09:45:37 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Alexey Dobriyan , Greg Kroah-Hartman , Jiri Slaby , Alessandro Zummo , Alexandre Belloni , linux-acpi@vger.kernel.org, drbd-dev@lists.linbit.com, linux-ide@vger.kernel.org, netdev@vger.kernel.org, linux-rtc@vger.kernel.org, megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net, netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/42] ext4: simplify procfs code Date: Wed, 16 May 2018 11:43:28 +0200 Message-Id: <20180516094346.20506-25-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516094346.20506-1-hch@lst.de> References: <20180516094346.20506-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use remove_proc_subtree to remove the whole subtree on cleanup, and unwind the registration loop into individual calls. Switch to use proc_create_seq where applicable. Signed-off-by: Christoph Hellwig --- fs/ext4/ext4.h | 2 +- fs/ext4/mballoc.c | 29 ++++------------------------ fs/ext4/sysfs.c | 49 +++++++++-------------------------------------- 3 files changed, 14 insertions(+), 66 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a42e71203e53..229ea4da6785 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2390,7 +2390,7 @@ extern int ext4_init_inode_table(struct super_block *sb, extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); /* mballoc.c */ -extern const struct file_operations ext4_seq_mb_groups_fops; +extern const struct seq_operations ext4_mb_seq_groups_ops; extern long ext4_mb_stats; extern long ext4_mb_max_to_scan; extern int ext4_mb_init(struct super_block *); diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 769a62708b1c..6884e81c1465 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -2254,7 +2254,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) { - struct super_block *sb = seq->private; + struct super_block *sb = PDE_DATA(file_inode(seq->file)); ext4_group_t group; if (*pos < 0 || *pos >= ext4_get_groups_count(sb)) @@ -2265,7 +2265,7 @@ static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) { - struct super_block *sb = seq->private; + struct super_block *sb = PDE_DATA(file_inode(seq->file)); ext4_group_t group; ++*pos; @@ -2277,7 +2277,7 @@ static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) { - struct super_block *sb = seq->private; + struct super_block *sb = PDE_DATA(file_inode(seq->file)); ext4_group_t group = (ext4_group_t) ((unsigned long) v); int i; int err, buddy_loaded = 0; @@ -2330,34 +2330,13 @@ static void ext4_mb_seq_groups_stop(struct seq_file *seq, void *v) { } -static const struct seq_operations ext4_mb_seq_groups_ops = { +const struct seq_operations ext4_mb_seq_groups_ops = { .start = ext4_mb_seq_groups_start, .next = ext4_mb_seq_groups_next, .stop = ext4_mb_seq_groups_stop, .show = ext4_mb_seq_groups_show, }; -static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file) -{ - struct super_block *sb = PDE_DATA(inode); - int rc; - - rc = seq_open(file, &ext4_mb_seq_groups_ops); - if (rc == 0) { - struct seq_file *m = file->private_data; - m->private = sb; - } - return rc; - -} - -const struct file_operations ext4_seq_mb_groups_fops = { - .open = ext4_mb_seq_groups_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, -}; - static struct kmem_cache *get_groupinfo_cache(int blocksize_bits) { int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE; diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 9ebd26c957c2..f34da0bb8f17 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -346,39 +346,9 @@ static struct kobject *ext4_root; static struct kobject *ext4_feat; -#define PROC_FILE_SHOW_DEFN(name) \ -static int name##_open(struct inode *inode, struct file *file) \ -{ \ - return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \ -} \ -\ -static const struct file_operations ext4_seq_##name##_fops = { \ - .open = name##_open, \ - .read = seq_read, \ - .llseek = seq_lseek, \ - .release = single_release, \ -} - -#define PROC_FILE_LIST(name) \ - { __stringify(name), &ext4_seq_##name##_fops } - -PROC_FILE_SHOW_DEFN(es_shrinker_info); -PROC_FILE_SHOW_DEFN(options); - -static const struct ext4_proc_files { - const char *name; - const struct file_operations *fops; -} proc_files[] = { - PROC_FILE_LIST(options), - PROC_FILE_LIST(es_shrinker_info), - PROC_FILE_LIST(mb_groups), - { NULL, NULL }, -}; - int ext4_register_sysfs(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); - const struct ext4_proc_files *p; int err; init_completion(&sbi->s_kobj_unregister); @@ -392,11 +362,14 @@ int ext4_register_sysfs(struct super_block *sb) if (ext4_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); - if (sbi->s_proc) { - for (p = proc_files; p->name; p++) - proc_create_data(p->name, S_IRUGO, sbi->s_proc, - p->fops, sb); + proc_create_single_data("options", S_IRUGO, sbi->s_proc, + ext4_seq_options_show, sb); + proc_create_single_data("es_shrinker_info", S_IRUGO, + sbi->s_proc, ext4_seq_es_shrinker_info_show, + sb); + proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, + &ext4_mb_seq_groups_ops, sb); } return 0; } @@ -404,13 +377,9 @@ int ext4_register_sysfs(struct super_block *sb) void ext4_unregister_sysfs(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); - const struct ext4_proc_files *p; - if (sbi->s_proc) { - for (p = proc_files; p->name; p++) - remove_proc_entry(p->name, sbi->s_proc); - remove_proc_entry(sb->s_id, ext4_proc_root); - } + if (sbi->s_proc) + remove_proc_subtree(sb->s_id, ext4_proc_root); kobject_del(&sbi->s_kobj); } -- 2.17.0