From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>, Corey Minyard <minyard@acm.org>,
Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
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 19/39] sg: simplify procfs code
Date: Thu, 19 Apr 2018 14:41:20 +0200 [thread overview]
Message-ID: <20180419124140.9309-20-hch@lst.de> (raw)
In-Reply-To: <20180419124140.9309-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>
---
drivers/scsi/sg.c | 124 +++++-----------------------------------------
1 file changed, 12 insertions(+), 112 deletions(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c198b96368dd..8ff687158704 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -66,7 +66,6 @@ static int sg_version_num = 30536; /* 2 digits for each component */
static char *sg_version_date = "20140603";
static int sg_proc_init(void);
-static void sg_proc_cleanup(void);
#endif
#define SG_ALLOW_DIO_DEF 0
@@ -1661,7 +1660,7 @@ static void __exit
exit_sg(void)
{
#ifdef CONFIG_SCSI_PROC_FS
- sg_proc_cleanup();
+ remove_proc_subtree("scsi/sg", NULL);
#endif /* CONFIG_SCSI_PROC_FS */
scsi_unregister_interface(&sg_interface);
class_destroy(sg_sysfs_class);
@@ -2274,11 +2273,6 @@ sg_get_dev(int dev)
}
#ifdef CONFIG_SCSI_PROC_FS
-
-static struct proc_dir_entry *sg_proc_sgp = NULL;
-
-static char sg_proc_sg_dirname[] = "scsi/sg";
-
static int sg_proc_seq_show_int(struct seq_file *s, void *v);
static int sg_proc_single_open_adio(struct inode *inode, struct file *file);
@@ -2306,37 +2300,11 @@ static const struct file_operations dressz_fops = {
};
static int sg_proc_seq_show_version(struct seq_file *s, void *v);
-static int sg_proc_single_open_version(struct inode *inode, struct file *file);
-static const struct file_operations version_fops = {
- .owner = THIS_MODULE,
- .open = sg_proc_single_open_version,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v);
-static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file);
-static const struct file_operations devhdr_fops = {
- .owner = THIS_MODULE,
- .open = sg_proc_single_open_devhdr,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
static int sg_proc_seq_show_dev(struct seq_file *s, void *v);
-static int sg_proc_open_dev(struct inode *inode, struct file *file);
static void * dev_seq_start(struct seq_file *s, loff_t *pos);
static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos);
static void dev_seq_stop(struct seq_file *s, void *v);
-static const struct file_operations dev_fops = {
- .owner = THIS_MODULE,
- .open = sg_proc_open_dev,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
-};
static const struct seq_operations dev_seq_ops = {
.start = dev_seq_start,
.next = dev_seq_next,
@@ -2345,14 +2313,6 @@ static const struct seq_operations dev_seq_ops = {
};
static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v);
-static int sg_proc_open_devstrs(struct inode *inode, struct file *file);
-static const struct file_operations devstrs_fops = {
- .owner = THIS_MODULE,
- .open = sg_proc_open_devstrs,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
-};
static const struct seq_operations devstrs_seq_ops = {
.start = dev_seq_start,
.next = dev_seq_next,
@@ -2361,14 +2321,6 @@ static const struct seq_operations devstrs_seq_ops = {
};
static int sg_proc_seq_show_debug(struct seq_file *s, void *v);
-static int sg_proc_open_debug(struct inode *inode, struct file *file);
-static const struct file_operations debug_fops = {
- .owner = THIS_MODULE,
- .open = sg_proc_open_debug,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
-};
static const struct seq_operations debug_seq_ops = {
.start = dev_seq_start,
.next = dev_seq_next,
@@ -2376,50 +2328,23 @@ static const struct seq_operations debug_seq_ops = {
.show = sg_proc_seq_show_debug,
};
-
-struct sg_proc_leaf {
- const char * name;
- const struct file_operations * fops;
-};
-
-static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
- {"allow_dio", &adio_fops},
- {"debug", &debug_fops},
- {"def_reserved_size", &dressz_fops},
- {"device_hdr", &devhdr_fops},
- {"devices", &dev_fops},
- {"device_strs", &devstrs_fops},
- {"version", &version_fops}
-};
-
static int
sg_proc_init(void)
{
- int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
- int k;
+ struct proc_dir_entry *p;
- sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
- if (!sg_proc_sgp)
+ p = proc_mkdir("scsi/sg", NULL);
+ if (!p)
return 1;
- for (k = 0; k < num_leaves; ++k) {
- const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
- umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
- proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
- }
- return 0;
-}
-static void
-sg_proc_cleanup(void)
-{
- int k;
- int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
-
- if (!sg_proc_sgp)
- return;
- for (k = 0; k < num_leaves; ++k)
- remove_proc_entry(sg_proc_leaf_arr[k].name, sg_proc_sgp);
- remove_proc_entry(sg_proc_sg_dirname, NULL);
+ proc_create("allow_dio", S_IRUGO | S_IWUSR, p, &adio_fops);
+ proc_create_seq("debug", S_IRUGO, p, &debug_seq_ops);
+ proc_create("def_reserved_size", S_IRUGO | S_IWUSR, p, &dressz_fops);
+ proc_create_single("device_hdr", S_IRUGO, p, sg_proc_seq_show_devhdr);
+ proc_create_seq("devices", S_IRUGO, p, &dev_seq_ops);
+ proc_create_seq("device_strs", S_IRUGO, p, &devstrs_seq_ops);
+ proc_create_single("version", S_IRUGO, p, sg_proc_seq_show_version);
+ return 0;
}
@@ -2482,22 +2407,12 @@ static int sg_proc_seq_show_version(struct seq_file *s, void *v)
return 0;
}
-static int sg_proc_single_open_version(struct inode *inode, struct file *file)
-{
- return single_open(file, sg_proc_seq_show_version, NULL);
-}
-
static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v)
{
seq_puts(s, "host\tchan\tid\tlun\ttype\topens\tqdepth\tbusy\tonline\n");
return 0;
}
-static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file)
-{
- return single_open(file, sg_proc_seq_show_devhdr, NULL);
-}
-
struct sg_proc_deviter {
loff_t index;
size_t max;
@@ -2531,11 +2446,6 @@ static void dev_seq_stop(struct seq_file *s, void *v)
kfree(s->private);
}
-static int sg_proc_open_dev(struct inode *inode, struct file *file)
-{
- return seq_open(file, &dev_seq_ops);
-}
-
static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
{
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
@@ -2562,11 +2472,6 @@ static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
return 0;
}
-static int sg_proc_open_devstrs(struct inode *inode, struct file *file)
-{
- return seq_open(file, &devstrs_seq_ops);
-}
-
static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
{
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
@@ -2650,11 +2555,6 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
}
}
-static int sg_proc_open_debug(struct inode *inode, struct file *file)
-{
- return seq_open(file, &debug_seq_ops);
-}
-
static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
{
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
--
2.17.0
next prev parent reply other threads:[~2018-04-19 12:41 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 12:41 simplify procfs code for seq_file instances Christoph Hellwig
2018-04-19 12:41 ` [PATCH 01/39] net/can: single_open_net needs to be paired with single_release_net Christoph Hellwig
2018-04-19 12:41 ` [PATCH 02/39] proc: introduce proc_create_seq{,_data} Christoph Hellwig
2018-04-19 18:41 ` Alexey Dobriyan
2018-04-24 14:29 ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 03/39] proc: introduce proc_create_seq_private Christoph Hellwig
2018-04-19 14:18 ` Dan Carpenter
2018-04-24 14:19 ` Christoph Hellwig
2018-04-19 18:50 ` Alexey Dobriyan
2018-04-24 14:29 ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 04/39] proc: introduce proc_create_single{,_data} Christoph Hellwig
2018-04-19 12:41 ` [PATCH 05/39] ipv{4,6}/udp{,lite}: simplify proc registration Christoph Hellwig
2018-04-19 12:41 ` [PATCH 06/39] ipv{4,6}/tcp: simplify procfs registration Christoph Hellwig
2018-04-19 12:41 ` [PATCH 07/39] ipv{4,6}/ping: simplify proc file creation Christoph Hellwig
2018-04-19 12:41 ` [PATCH 08/39] ipv{4, 6}/raw: simplify ѕeq_file code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 09/39] ipv6/flowlabel: simplify pid namespace lookup Christoph Hellwig
2018-04-19 12:41 ` [PATCH 10/39] net/kcm: simplify proc registration Christoph Hellwig
2018-04-19 12:41 ` [PATCH 11/39] netfilter/x_tables: simplify ѕeq_file code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 12/39] net: move seq_file_single_net to <linux/seq_file_net.h> Christoph Hellwig
2018-04-19 12:41 ` [PATCH 13/39] proc: introduce proc_create_net{,_data} Christoph Hellwig
2018-04-19 12:41 ` [PATCH 14/39] proc: introduce proc_create_net_single Christoph Hellwig
2018-04-19 18:44 ` Alexey Dobriyan
2018-04-19 12:41 ` [PATCH 15/39] acpi/battery: simplify procfs code Christoph Hellwig
2018-04-22 9:42 ` Rafael J. Wysocki
2018-04-19 12:41 ` [PATCH 16/39] ipmi: " Christoph Hellwig
2018-04-19 15:29 ` Corey Minyard
2018-04-24 14:16 ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 17/39] sgi-gru: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 18/39] megaraid: " Christoph Hellwig
2018-04-19 12:41 ` Christoph Hellwig [this message]
2018-04-19 12:41 ` [PATCH 20/39] afs: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 21/39] ext4: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 22/39] jfs: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 23/39] staging/rtl8192u: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 24/39] resource: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 25/39] drbd: switch to proc_create_single Christoph Hellwig
2018-04-19 12:41 ` [PATCH 26/39] rtc/proc: switch to proc_create_single_data Christoph Hellwig
2018-04-19 13:10 ` Alexandre Belloni
2018-04-24 14:15 ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 27/39] bonding: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 28/39] hostap: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 29/39] neigh: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 30/39] netfilter/xt_hashlimit: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 31/39] netfilter/x_tables: switch to proc_create_seq_private Christoph Hellwig
2018-04-19 12:41 ` [PATCH 32/39] bluetooth: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 33/39] atm: simplify procfs code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 34/39] atm: switch to proc_create_seq_private Christoph Hellwig
2018-04-19 12:41 ` [PATCH 35/39] isdn: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-19 12:41 ` [PATCH 36/39] proc: don't detour through seq->private to get the inode Christoph Hellwig
2018-04-19 12:41 ` [PATCH 37/39] ide: remove ide_driver_proc_write Christoph Hellwig
2018-04-19 12:41 ` [PATCH 38/39] ide: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-19 12:41 ` [PATCH 39/39] tty: " Christoph Hellwig
2018-04-19 13:00 ` [PATCH 20/39] afs: simplify procfs code David Howells
2018-04-19 18:57 ` simplify procfs code for seq_file instances Alexey Dobriyan
2018-04-24 14:23 ` Christoph Hellwig
2018-04-24 15:19 ` Andrew Morton
2018-04-24 16:06 ` Christoph Hellwig
2018-04-25 21:24 ` Alexey Dobriyan
2018-04-20 12:29 ` [PATCH 20/39] afs: simplify procfs code David Howells
2018-04-24 14:12 ` Christoph Hellwig
2018-04-30 14:37 ` David Howells
2018-04-20 12:31 ` [PATCH 01/02] net: Export get_proc_net() David Howells
2018-04-20 12:32 ` [PATCH 02/02] afs: Implement namespacing David Howells
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=20180419124140.9309-20-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=minyard@acm.org \
--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).