diff options
author | Christoph Hellwig <hch@lst.de> | 2018-04-13 13:44:18 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-16 01:23:35 -0400 |
commit | fddda2b7b521185f3aa018f9559eb33b0aee53a9 (patch) | |
tree | ece18b3d82822f8eaefd8b0afa2f93307e83b253 /fs | |
parent | 7aed53d1dfd14d468e065212ce45068e2b50c1fa (diff) |
proc: introduce proc_create_seq{,_data}
Variants of proc_create{,_data} that directly take a struct seq_operations
argument and drastically reduces the boilerplate code in the callers.
All trivial callers converted over.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/cachefiles/proc.c | 19 | ||||
-rw-r--r-- | fs/fscache/histogram.c | 17 | ||||
-rw-r--r-- | fs/fscache/internal.h | 3 | ||||
-rw-r--r-- | fs/fscache/proc.c | 4 | ||||
-rw-r--r-- | fs/proc/consoles.c | 14 | ||||
-rw-r--r-- | fs/proc/devices.c | 14 | ||||
-rw-r--r-- | fs/proc/generic.c | 30 | ||||
-rw-r--r-- | fs/proc/internal.h | 1 | ||||
-rw-r--r-- | fs/proc/interrupts.c | 14 | ||||
-rw-r--r-- | fs/proc/nommu.c | 14 | ||||
-rw-r--r-- | fs/proc/proc_tty.c | 16 |
11 files changed, 44 insertions, 102 deletions
diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c index 125b90f6c796..0ce1aa56b67f 100644 --- a/fs/cachefiles/proc.c +++ b/fs/cachefiles/proc.c | |||
@@ -85,21 +85,6 @@ static const struct seq_operations cachefiles_histogram_ops = { | |||
85 | }; | 85 | }; |
86 | 86 | ||
87 | /* | 87 | /* |
88 | * open "/proc/fs/cachefiles/XXX" which provide statistics summaries | ||
89 | */ | ||
90 | static int cachefiles_histogram_open(struct inode *inode, struct file *file) | ||
91 | { | ||
92 | return seq_open(file, &cachefiles_histogram_ops); | ||
93 | } | ||
94 | |||
95 | static const struct file_operations cachefiles_histogram_fops = { | ||
96 | .open = cachefiles_histogram_open, | ||
97 | .read = seq_read, | ||
98 | .llseek = seq_lseek, | ||
99 | .release = seq_release, | ||
100 | }; | ||
101 | |||
102 | /* | ||
103 | * initialise the /proc/fs/cachefiles/ directory | 88 | * initialise the /proc/fs/cachefiles/ directory |
104 | */ | 89 | */ |
105 | int __init cachefiles_proc_init(void) | 90 | int __init cachefiles_proc_init(void) |
@@ -109,8 +94,8 @@ int __init cachefiles_proc_init(void) | |||
109 | if (!proc_mkdir("fs/cachefiles", NULL)) | 94 | if (!proc_mkdir("fs/cachefiles", NULL)) |
110 | goto error_dir; | 95 | goto error_dir; |
111 | 96 | ||
112 | if (!proc_create("fs/cachefiles/histogram", S_IFREG | 0444, NULL, | 97 | if (!proc_create_seq("fs/cachefiles/histogram", S_IFREG | 0444, NULL, |
113 | &cachefiles_histogram_fops)) | 98 | &cachefiles_histogram_ops)) |
114 | goto error_histogram; | 99 | goto error_histogram; |
115 | 100 | ||
116 | _leave(" = 0"); | 101 | _leave(" = 0"); |
diff --git a/fs/fscache/histogram.c b/fs/fscache/histogram.c index 15a3d042247e..9a13e9e15b69 100644 --- a/fs/fscache/histogram.c +++ b/fs/fscache/histogram.c | |||
@@ -83,24 +83,9 @@ static void fscache_histogram_stop(struct seq_file *m, void *v) | |||
83 | { | 83 | { |
84 | } | 84 | } |
85 | 85 | ||
86 | static const struct seq_operations fscache_histogram_ops = { | 86 | const struct seq_operations fscache_histogram_ops = { |
87 | .start = fscache_histogram_start, | 87 | .start = fscache_histogram_start, |
88 | .stop = fscache_histogram_stop, | 88 | .stop = fscache_histogram_stop, |
89 | .next = fscache_histogram_next, | 89 | .next = fscache_histogram_next, |
90 | .show = fscache_histogram_show, | 90 | .show = fscache_histogram_show, |
91 | }; | 91 | }; |
92 | |||
93 | /* | ||
94 | * open "/proc/fs/fscache/histogram" to provide latency data | ||
95 | */ | ||
96 | static int fscache_histogram_open(struct inode *inode, struct file *file) | ||
97 | { | ||
98 | return seq_open(file, &fscache_histogram_ops); | ||
99 | } | ||
100 | |||
101 | const struct file_operations fscache_histogram_fops = { | ||
102 | .open = fscache_histogram_open, | ||
103 | .read = seq_read, | ||
104 | .llseek = seq_lseek, | ||
105 | .release = seq_release, | ||
106 | }; | ||
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h index 500650f938fe..53cfd0b34c38 100644 --- a/fs/fscache/internal.h +++ b/fs/fscache/internal.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/fscache-cache.h> | 31 | #include <linux/fscache-cache.h> |
32 | #include <trace/events/fscache.h> | 32 | #include <trace/events/fscache.h> |
33 | #include <linux/sched.h> | 33 | #include <linux/sched.h> |
34 | #include <linux/seq_file.h> | ||
34 | 35 | ||
35 | #define FSCACHE_MIN_THREADS 4 | 36 | #define FSCACHE_MIN_THREADS 4 |
36 | #define FSCACHE_MAX_THREADS 32 | 37 | #define FSCACHE_MAX_THREADS 32 |
@@ -84,7 +85,7 @@ static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif) | |||
84 | atomic_inc(&histogram[jif]); | 85 | atomic_inc(&histogram[jif]); |
85 | } | 86 | } |
86 | 87 | ||
87 | extern const struct file_operations fscache_histogram_fops; | 88 | extern const struct seq_operations fscache_histogram_ops; |
88 | 89 | ||
89 | #else | 90 | #else |
90 | #define fscache_hist(hist, start_jif) do {} while (0) | 91 | #define fscache_hist(hist, start_jif) do {} while (0) |
diff --git a/fs/fscache/proc.c b/fs/fscache/proc.c index 1d9e4951a597..459df553ea09 100644 --- a/fs/fscache/proc.c +++ b/fs/fscache/proc.c | |||
@@ -32,8 +32,8 @@ int __init fscache_proc_init(void) | |||
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #ifdef CONFIG_FSCACHE_HISTOGRAM | 34 | #ifdef CONFIG_FSCACHE_HISTOGRAM |
35 | if (!proc_create("fs/fscache/histogram", S_IFREG | 0444, NULL, | 35 | if (!proc_create_seq("fs/fscache/histogram", S_IFREG | 0444, NULL, |
36 | &fscache_histogram_fops)) | 36 | &fscache_histogram_ops)) |
37 | goto error_histogram; | 37 | goto error_histogram; |
38 | #endif | 38 | #endif |
39 | 39 | ||
diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index a8ac48aebd59..954caf0b7fee 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c | |||
@@ -91,21 +91,9 @@ static const struct seq_operations consoles_op = { | |||
91 | .show = show_console_dev | 91 | .show = show_console_dev |
92 | }; | 92 | }; |
93 | 93 | ||
94 | static int consoles_open(struct inode *inode, struct file *file) | ||
95 | { | ||
96 | return seq_open(file, &consoles_op); | ||
97 | } | ||
98 | |||
99 | static const struct file_operations proc_consoles_operations = { | ||
100 | .open = consoles_open, | ||
101 | .read = seq_read, | ||
102 | .llseek = seq_lseek, | ||
103 | .release = seq_release, | ||
104 | }; | ||
105 | |||
106 | static int __init proc_consoles_init(void) | 94 | static int __init proc_consoles_init(void) |
107 | { | 95 | { |
108 | proc_create("consoles", 0, NULL, &proc_consoles_operations); | 96 | proc_create_seq("consoles", 0, NULL, &consoles_op); |
109 | return 0; | 97 | return 0; |
110 | } | 98 | } |
111 | fs_initcall(proc_consoles_init); | 99 | fs_initcall(proc_consoles_init); |
diff --git a/fs/proc/devices.c b/fs/proc/devices.c index 2c7f22b14489..37d38697eaf8 100644 --- a/fs/proc/devices.c +++ b/fs/proc/devices.c | |||
@@ -51,21 +51,9 @@ static const struct seq_operations devinfo_ops = { | |||
51 | .show = devinfo_show | 51 | .show = devinfo_show |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static int devinfo_open(struct inode *inode, struct file *filp) | ||
55 | { | ||
56 | return seq_open(filp, &devinfo_ops); | ||
57 | } | ||
58 | |||
59 | static const struct file_operations proc_devinfo_operations = { | ||
60 | .open = devinfo_open, | ||
61 | .read = seq_read, | ||
62 | .llseek = seq_lseek, | ||
63 | .release = seq_release, | ||
64 | }; | ||
65 | |||
66 | static int __init proc_devices_init(void) | 54 | static int __init proc_devices_init(void) |
67 | { | 55 | { |
68 | proc_create("devices", 0, NULL, &proc_devinfo_operations); | 56 | proc_create_seq("devices", 0, NULL, &devinfo_ops); |
69 | return 0; | 57 | return 0; |
70 | } | 58 | } |
71 | fs_initcall(proc_devices_init); | 59 | fs_initcall(proc_devices_init); |
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index ab6a321076b8..af644caaaf85 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/spinlock.h> | 25 | #include <linux/spinlock.h> |
26 | #include <linux/completion.h> | 26 | #include <linux/completion.h> |
27 | #include <linux/uaccess.h> | 27 | #include <linux/uaccess.h> |
28 | #include <linux/seq_file.h> | ||
28 | 29 | ||
29 | #include "internal.h" | 30 | #include "internal.h" |
30 | 31 | ||
@@ -555,6 +556,35 @@ struct proc_dir_entry *proc_create(const char *name, umode_t mode, | |||
555 | } | 556 | } |
556 | EXPORT_SYMBOL(proc_create); | 557 | EXPORT_SYMBOL(proc_create); |
557 | 558 | ||
559 | static int proc_seq_open(struct inode *inode, struct file *file) | ||
560 | { | ||
561 | struct proc_dir_entry *de = PDE(inode); | ||
562 | |||
563 | return seq_open(file, de->seq_ops); | ||
564 | } | ||
565 | |||
566 | static const struct file_operations proc_seq_fops = { | ||
567 | .open = proc_seq_open, | ||
568 | .read = seq_read, | ||
569 | .llseek = seq_lseek, | ||
570 | .release = seq_release, | ||
571 | }; | ||
572 | |||
573 | struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, | ||
574 | struct proc_dir_entry *parent, const struct seq_operations *ops, | ||
575 | void *data) | ||
576 | { | ||
577 | struct proc_dir_entry *p; | ||
578 | |||
579 | p = proc_create_reg(name, mode, &parent, data); | ||
580 | if (!p) | ||
581 | return NULL; | ||
582 | p->proc_fops = &proc_seq_fops; | ||
583 | p->seq_ops = ops; | ||
584 | return proc_register(parent, p); | ||
585 | } | ||
586 | EXPORT_SYMBOL(proc_create_seq_data); | ||
587 | |||
558 | void proc_set_size(struct proc_dir_entry *de, loff_t size) | 588 | void proc_set_size(struct proc_dir_entry *de, loff_t size) |
559 | { | 589 | { |
560 | de->size = size; | 590 | de->size = size; |
diff --git a/fs/proc/internal.h b/fs/proc/internal.h index dd1e11400b97..4fb01c5f9c1a 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h | |||
@@ -44,6 +44,7 @@ struct proc_dir_entry { | |||
44 | struct completion *pde_unload_completion; | 44 | struct completion *pde_unload_completion; |
45 | const struct inode_operations *proc_iops; | 45 | const struct inode_operations *proc_iops; |
46 | const struct file_operations *proc_fops; | 46 | const struct file_operations *proc_fops; |
47 | const struct seq_operations *seq_ops; | ||
47 | void *data; | 48 | void *data; |
48 | unsigned int low_ino; | 49 | unsigned int low_ino; |
49 | nlink_t nlink; | 50 | nlink_t nlink; |
diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c index 6a6bee9c603c..cb0edc7cbf09 100644 --- a/fs/proc/interrupts.c +++ b/fs/proc/interrupts.c | |||
@@ -34,21 +34,9 @@ static const struct seq_operations int_seq_ops = { | |||
34 | .show = show_interrupts | 34 | .show = show_interrupts |
35 | }; | 35 | }; |
36 | 36 | ||
37 | static int interrupts_open(struct inode *inode, struct file *filp) | ||
38 | { | ||
39 | return seq_open(filp, &int_seq_ops); | ||
40 | } | ||
41 | |||
42 | static const struct file_operations proc_interrupts_operations = { | ||
43 | .open = interrupts_open, | ||
44 | .read = seq_read, | ||
45 | .llseek = seq_lseek, | ||
46 | .release = seq_release, | ||
47 | }; | ||
48 | |||
49 | static int __init proc_interrupts_init(void) | 37 | static int __init proc_interrupts_init(void) |
50 | { | 38 | { |
51 | proc_create("interrupts", 0, NULL, &proc_interrupts_operations); | 39 | proc_create_seq("interrupts", 0, NULL, &int_seq_ops); |
52 | return 0; | 40 | return 0; |
53 | } | 41 | } |
54 | fs_initcall(proc_interrupts_init); | 42 | fs_initcall(proc_interrupts_init); |
diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c index 75634379f82e..3b63be64e436 100644 --- a/fs/proc/nommu.c +++ b/fs/proc/nommu.c | |||
@@ -113,21 +113,9 @@ static const struct seq_operations proc_nommu_region_list_seqop = { | |||
113 | .show = nommu_region_list_show | 113 | .show = nommu_region_list_show |
114 | }; | 114 | }; |
115 | 115 | ||
116 | static int proc_nommu_region_list_open(struct inode *inode, struct file *file) | ||
117 | { | ||
118 | return seq_open(file, &proc_nommu_region_list_seqop); | ||
119 | } | ||
120 | |||
121 | static const struct file_operations proc_nommu_region_list_operations = { | ||
122 | .open = proc_nommu_region_list_open, | ||
123 | .read = seq_read, | ||
124 | .llseek = seq_lseek, | ||
125 | .release = seq_release, | ||
126 | }; | ||
127 | |||
128 | static int __init proc_nommu_init(void) | 116 | static int __init proc_nommu_init(void) |
129 | { | 117 | { |
130 | proc_create("maps", S_IRUGO, NULL, &proc_nommu_region_list_operations); | 118 | proc_create_seq("maps", S_IRUGO, NULL, &proc_nommu_region_list_seqop); |
131 | return 0; | 119 | return 0; |
132 | } | 120 | } |
133 | 121 | ||
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c index d0cf1c50bb6c..b1a4a8ddd246 100644 --- a/fs/proc/proc_tty.c +++ b/fs/proc/proc_tty.c | |||
@@ -126,18 +126,6 @@ static const struct seq_operations tty_drivers_op = { | |||
126 | .show = show_tty_driver | 126 | .show = show_tty_driver |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static int tty_drivers_open(struct inode *inode, struct file *file) | ||
130 | { | ||
131 | return seq_open(file, &tty_drivers_op); | ||
132 | } | ||
133 | |||
134 | static const struct file_operations proc_tty_drivers_operations = { | ||
135 | .open = tty_drivers_open, | ||
136 | .read = seq_read, | ||
137 | .llseek = seq_lseek, | ||
138 | .release = seq_release, | ||
139 | }; | ||
140 | |||
141 | /* | 129 | /* |
142 | * This function is called by tty_register_driver() to handle | 130 | * This function is called by tty_register_driver() to handle |
143 | * registering the driver's /proc handler into /proc/tty/driver/<foo> | 131 | * registering the driver's /proc handler into /proc/tty/driver/<foo> |
@@ -186,6 +174,6 @@ void __init proc_tty_init(void) | |||
186 | * entry. | 174 | * entry. |
187 | */ | 175 | */ |
188 | proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL); | 176 | proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL); |
189 | proc_create("tty/ldiscs", 0, NULL, &tty_ldiscs_proc_fops); | 177 | proc_create_seq("tty/ldiscs", 0, NULL, &tty_ldiscs_seq_ops); |
190 | proc_create("tty/drivers", 0, NULL, &proc_tty_drivers_operations); | 178 | proc_create_seq("tty/drivers", 0, NULL, &tty_drivers_op); |
191 | } | 179 | } |