linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-rtc@vger.kernel.org,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	jfs-discussion@lists.sourceforge.net,
	linux-afs@lists.infradead.org, linux-acpi@vger.kernel.org,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.com>,
	linux-ext4@vger.kernel.org, Alexey Dobriyan <adobriyan@gmail.com>,
	megaraidlinux.pdl@broadcom.com, drbd-dev@lists.linbit.com
Subject: [PATCH 21/40] afs: simplify procfs code
Date: Wed, 25 Apr 2018 17:48:08 +0200	[thread overview]
Message-ID: <20180425154827.32251-22-hch@lst.de> (raw)
In-Reply-To: <20180425154827.32251-1-hch@lst.de>

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 <hch@lst.de>
---
 fs/afs/proc.c | 134 ++++++--------------------------------------------
 1 file changed, 15 insertions(+), 119 deletions(-)

diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 839a22280606..3aad32762989 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -62,7 +62,6 @@ static const struct file_operations afs_proc_rootcell_fops = {
 	.llseek		= no_llseek,
 };
 
-static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
 static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos);
 static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
 					loff_t *pos);
@@ -76,15 +75,6 @@ static const struct seq_operations afs_proc_cell_volumes_ops = {
 	.show	= afs_proc_cell_volumes_show,
 };
 
-static const struct file_operations afs_proc_cell_volumes_fops = {
-	.open		= afs_proc_cell_volumes_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
-static int afs_proc_cell_vlservers_open(struct inode *inode,
-					struct file *file);
 static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos);
 static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
 					  loff_t *pos);
@@ -98,14 +88,6 @@ static const struct seq_operations afs_proc_cell_vlservers_ops = {
 	.show	= afs_proc_cell_vlservers_show,
 };
 
-static const struct file_operations afs_proc_cell_vlservers_fops = {
-	.open		= afs_proc_cell_vlservers_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
-static int afs_proc_servers_open(struct inode *inode, struct file *file);
 static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos);
 static void *afs_proc_servers_next(struct seq_file *p, void *v,
 					loff_t *pos);
@@ -119,13 +101,6 @@ static const struct seq_operations afs_proc_servers_ops = {
 	.show	= afs_proc_servers_show,
 };
 
-static const struct file_operations afs_proc_servers_fops = {
-	.open		= afs_proc_servers_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
 static int afs_proc_sysname_open(struct inode *inode, struct file *file);
 static int afs_proc_sysname_release(struct inode *inode, struct file *file);
 static void *afs_proc_sysname_start(struct seq_file *p, loff_t *pos);
@@ -152,7 +127,7 @@ static const struct file_operations afs_proc_sysname_fops = {
 	.write		= afs_proc_sysname_write,
 };
 
-static const struct file_operations afs_proc_stats_fops;
+static int afs_proc_stats_show(struct seq_file *m, void *v);
 
 /*
  * initialise the /proc/fs/afs/ directory
@@ -167,8 +142,8 @@ int afs_proc_init(struct afs_net *net)
 
 	if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
 	    !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) ||
-	    !proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops) ||
-	    !proc_create("stats", 0644, net->proc_afs, &afs_proc_stats_fops) ||
+	    !proc_create_seq("servers", 0644, net->proc_afs, &afs_proc_servers_ops) ||
+	    !proc_create_single("stats", 0644, net->proc_afs, afs_proc_stats_show) ||
 	    !proc_create("sysname", 0644, net->proc_afs, &afs_proc_sysname_fops))
 		goto error_tree;
 
@@ -196,16 +171,7 @@ void afs_proc_cleanup(struct afs_net *net)
  */
 static int afs_proc_cells_open(struct inode *inode, struct file *file)
 {
-	struct seq_file *m;
-	int ret;
-
-	ret = seq_open(file, &afs_proc_cells_ops);
-	if (ret < 0)
-		return ret;
-
-	m = file->private_data;
-	m->private = PDE_DATA(inode);
-	return 0;
+	return seq_open(file, &afs_proc_cells_ops);
 }
 
 /*
@@ -430,10 +396,11 @@ int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
 	if (!dir)
 		goto error_dir;
 
-	if (!proc_create_data("vlservers", 0, dir,
-			      &afs_proc_cell_vlservers_fops, cell) ||
-	    !proc_create_data("volumes", 0, dir,
-			      &afs_proc_cell_volumes_fops, cell))
+	if (!proc_create_seq_data("vlservers", 0, dir,
+			&afs_proc_cell_vlservers_ops, cell))
+		goto error_tree;
+	if (!proc_create_seq_data("volumes", 0, dir, &afs_proc_cell_volumes_ops,
+			cell))
 		goto error_tree;
 
 	_leave(" = 0");
@@ -458,29 +425,6 @@ void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell)
 	_leave("");
 }
 
-/*
- * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
- */
-static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
-{
-	struct afs_cell *cell;
-	struct seq_file *m;
-	int ret;
-
-	cell = PDE_DATA(inode);
-	if (!cell)
-		return -ENOENT;
-
-	ret = seq_open(file, &afs_proc_cell_volumes_ops);
-	if (ret < 0)
-		return ret;
-
-	m = file->private_data;
-	m->private = cell;
-
-	return 0;
-}
-
 /*
  * set up the iterator to start reading from the cells list and return the
  * first item
@@ -488,7 +432,7 @@ static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
 static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
 	__acquires(cell->proc_lock)
 {
-	struct afs_cell *cell = m->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(m->file));
 
 	_enter("cell=%p pos=%Ld", cell, *_pos);
 
@@ -502,7 +446,7 @@ static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
 static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
 					loff_t *_pos)
 {
-	struct afs_cell *cell = p->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(p->file));
 
 	_enter("cell=%p pos=%Ld", cell, *_pos);
 	return seq_list_next(v, &cell->proc_volumes, _pos);
@@ -514,7 +458,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
 static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
 	__releases(cell->proc_lock)
 {
-	struct afs_cell *cell = p->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(p->file));
 
 	read_unlock(&cell->proc_lock);
 }
@@ -530,7 +474,7 @@ static const char afs_vol_types[3][3] = {
  */
 static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
 {
-	struct afs_cell *cell = m->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(m->file));
 	struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
 
 	/* Display header on line 1 */
@@ -546,30 +490,6 @@ static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-/*
- * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
- * location server
- */
-static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
-{
-	struct afs_cell *cell;
-	struct seq_file *m;
-	int ret;
-
-	cell = PDE_DATA(inode);
-	if (!cell)
-		return -ENOENT;
-
-	ret = seq_open(file, &afs_proc_cell_vlservers_ops);
-	if (ret<0)
-		return ret;
-
-	m = file->private_data;
-	m->private = cell;
-
-	return 0;
-}
-
 /*
  * set up the iterator to start reading from the cells list and return the
  * first item
@@ -578,7 +498,7 @@ static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
 	__acquires(rcu)
 {
 	struct afs_addr_list *alist;
-	struct afs_cell *cell = m->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(m->file));
 	loff_t pos = *_pos;
 
 	rcu_read_lock();
@@ -603,7 +523,7 @@ static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
 					  loff_t *_pos)
 {
 	struct afs_addr_list *alist;
-	struct afs_cell *cell = p->private;
+	struct afs_cell *cell = PDE_DATA(file_inode(p->file));
 	loff_t pos;
 
 	alist = rcu_dereference(cell->vl_addrs);
@@ -643,15 +563,6 @@ static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-/*
- * open "/proc/fs/afs/servers" which provides a summary of active
- * servers
- */
-static int afs_proc_servers_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &afs_proc_servers_ops);
-}
-
 /*
  * Set up the iterator to start reading from the server list and return the
  * first item.
@@ -931,18 +842,3 @@ static int afs_proc_stats_show(struct seq_file *m, void *v)
 		   atomic_long_read(&net->n_store_bytes));
 	return 0;
 }
-
-/*
- * Open "/proc/fs/afs/stats" to allow reading of the stat counters.
- */
-static int afs_proc_stats_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, afs_proc_stats_show, NULL);
-}
-
-static const struct file_operations afs_proc_stats_fops = {
-	.open		= afs_proc_stats_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release        = single_release,
-};
-- 
2.17.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2018-04-25 15:48 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 15:47 simplify procfs code for seq_file instances V2 Christoph Hellwig
2018-04-25 15:47 ` [PATCH 01/40] net/can: single_open_net needs to be paired with single_release_net Christoph Hellwig
2018-04-25 15:47 ` [PATCH 02/40] proc: simplify proc_register calling conventions Christoph Hellwig
2018-04-25 15:47 ` [PATCH 03/40] proc: add a proc_create_reg helper Christoph Hellwig
2018-04-25 15:47 ` [PATCH 04/40] proc: introduce proc_create_seq{,_data} Christoph Hellwig
2018-04-25 15:47 ` [PATCH 05/40] proc: introduce proc_create_seq_private Christoph Hellwig
2018-04-25 15:47 ` [PATCH 06/40] proc: introduce proc_create_single{,_data} Christoph Hellwig
2018-04-26  1:45   ` Finn Thain
2018-05-15 13:58     ` Christoph Hellwig
2018-04-25 15:47 ` [PATCH 07/40] ipv{4,6}/udp{,lite}: simplify proc registration Christoph Hellwig
2018-04-25 15:47 ` [PATCH 08/40] ipv{4,6}/tcp: simplify procfs registration Christoph Hellwig
2018-04-25 15:47 ` [PATCH 09/40] ipv{4,6}/ping: simplify proc file creation Christoph Hellwig
2018-04-25 15:47 ` [PATCH 10/40] ipv{4, 6}/raw: simplify ѕeq_file code Christoph Hellwig
2018-04-25 15:47 ` [PATCH 11/40] ipv6/flowlabel: simplify pid namespace lookup Christoph Hellwig
2018-05-05 12:37   ` Eric W. Biederman
2018-05-15 14:56     ` Christoph Hellwig
2018-05-17  5:28       ` Eric W. Biederman
2018-05-17  6:42         ` Christoph Hellwig
2018-05-17 19:14           ` Eric W. Biederman
2018-04-25 15:47 ` [PATCH 12/40] net/kcm: simplify proc registration Christoph Hellwig
2018-04-25 15:48 ` [PATCH 13/40] netfilter/x_tables: simplify ѕeq_file code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 14/40] net: move seq_file_single_net to <linux/seq_file_net.h> Christoph Hellwig
2018-04-25 15:48 ` [PATCH 15/40] proc: introduce proc_create_net{,_data} Christoph Hellwig
2018-04-25 15:48 ` [PATCH 16/40] proc: introduce proc_create_net_single Christoph Hellwig
2018-04-25 15:48 ` [PATCH 17/40] acpi/battery: simplify procfs code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 18/40] sgi-gru: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 19/40] megaraid: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 20/40] sg: " Christoph Hellwig
2018-04-25 15:48 ` Christoph Hellwig [this message]
2018-04-30 23:20   ` [PATCH 0/3] afs: Network-namespacing and proc David Howells
2018-04-30 23:20     ` [PATCH 1/3] afs: Rearrange fs/afs/proc.c David Howells
2018-05-15 13:43       ` Christoph Hellwig
2018-04-30 23:20     ` [PATCH 2/3] proc: Add a way to make network proc files writable David Howells
2018-05-15 13:48       ` Christoph Hellwig
2018-05-15 14:16       ` David Howells
2018-04-30 23:20     ` [PATCH 3/3] afs: Implement namespacing David Howells
2018-05-15 13:53       ` Christoph Hellwig
2018-05-15 14:28       ` 'Adding' a writable proc file under /proc/net/afs/ [was [PATCH 3/3] afs: Implement namespacing] David Howells
2018-04-25 15:48 ` [PATCH 22/40] ext4: simplify procfs code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 23/40] jfs: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 24/40] staging/rtl8192u: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 25/40] resource: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 26/40] drbd: switch to proc_create_single Christoph Hellwig
2018-04-25 15:48 ` [PATCH 27/40] rtc/proc: switch to proc_create_single_data Christoph Hellwig
2018-04-25 18:25   ` Alexandre Belloni
2018-04-25 15:48 ` [PATCH 28/40] bonding: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 29/40] hostap: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 30/40] neigh: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 31/40] netfilter/xt_hashlimit: switch to proc_create_{seq, single}_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 32/40] netfilter/x_tables: switch to proc_create_seq_private Christoph Hellwig
2018-04-25 15:48 ` [PATCH 33/40] bluetooth: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 34/40] atm: simplify procfs code Christoph Hellwig
2018-05-05 12:51   ` Eric W. Biederman
2018-05-15 14:12     ` Christoph Hellwig
2018-05-17  1:15       ` Eric W. Biederman
2018-04-25 15:48 ` [PATCH 35/40] atm: switch to proc_create_seq_private Christoph Hellwig
2018-04-25 15:48 ` [PATCH 36/40] isdn: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-25 15:48 ` [PATCH 37/40] proc: don't detour through seq->private to get the inode Christoph Hellwig
2018-04-25 15:48 ` [PATCH 38/40] ide: remove ide_driver_proc_write Christoph Hellwig
2018-05-05 13:09   ` Eric W. Biederman
2018-04-25 15:48 ` [PATCH 39/40] ide: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-25 15:48 ` [PATCH 40/40] tty: " Christoph Hellwig
2018-04-30 13:19 ` [PATCH 04/40] proc: introduce proc_create_seq{,_data} David Howells
2018-05-15 14:42   ` Christoph Hellwig
2018-04-30 15:38 ` simplify procfs code for seq_file instances V2 David Howells
2018-05-06 17:19 ` Alexey Dobriyan
2018-05-06 17:45   ` Al Viro
2018-05-09 16:53     ` Alexey Dobriyan
2018-05-15 14:03   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180425154827.32251-22-hch@lst.de \
    --to=hch@lst.de \
    --cc=a.zummo@towertech.it \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=drbd-dev@lists.linbit.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=jslaby@suse.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=megaraidlinux.pdl@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).