aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-24 11:05:17 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:23:35 -0400
commit44414d82cfe0f68cb59d0a42f599ccd893ae0032 (patch)
treef89c89cf2f7c919c22bcf3dac566c89eac6d2ff4
parentfddda2b7b521185f3aa018f9559eb33b0aee53a9 (diff)
proc: introduce proc_create_seq_private
Variant of proc_create_data that directly take a struct seq_operations argument + a private state size and drastically reduces the boilerplate code in the callers. All trivial callers converted over. Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--fs/locks.c16
-rw-r--r--fs/proc/generic.c9
-rw-r--r--fs/proc/internal.h1
-rw-r--r--include/linux/atalk.h7
-rw-r--r--include/linux/proc_fs.h9
-rw-r--r--kernel/time/timer_list.c16
-rw-r--r--mm/vmalloc.c18
-rw-r--r--net/appletalk/aarp.c20
-rw-r--r--net/appletalk/atalk_proc.c3
-rw-r--r--net/atm/lec.c15
-rw-r--r--net/decnet/af_decnet.c17
-rw-r--r--net/decnet/dn_route.c19
12 files changed, 37 insertions, 113 deletions
diff --git a/fs/locks.c b/fs/locks.c
index 62bbe8b31f26..05e211be8684 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2788,22 +2788,10 @@ static const struct seq_operations locks_seq_operations = {
2788 .show = locks_show, 2788 .show = locks_show,
2789}; 2789};
2790 2790
2791static int locks_open(struct inode *inode, struct file *filp)
2792{
2793 return seq_open_private(filp, &locks_seq_operations,
2794 sizeof(struct locks_iterator));
2795}
2796
2797static const struct file_operations proc_locks_operations = {
2798 .open = locks_open,
2799 .read = seq_read,
2800 .llseek = seq_lseek,
2801 .release = seq_release_private,
2802};
2803
2804static int __init proc_locks_init(void) 2791static int __init proc_locks_init(void)
2805{ 2792{
2806 proc_create("locks", 0, NULL, &proc_locks_operations); 2793 proc_create_seq_private("locks", 0, NULL, &locks_seq_operations,
2794 sizeof(struct locks_iterator), NULL);
2807 return 0; 2795 return 0;
2808} 2796}
2809fs_initcall(proc_locks_init); 2797fs_initcall(proc_locks_init);
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index af644caaaf85..f87cb0053387 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -560,6 +560,8 @@ static int proc_seq_open(struct inode *inode, struct file *file)
560{ 560{
561 struct proc_dir_entry *de = PDE(inode); 561 struct proc_dir_entry *de = PDE(inode);
562 562
563 if (de->state_size)
564 return seq_open_private(file, de->seq_ops, de->state_size);
563 return seq_open(file, de->seq_ops); 565 return seq_open(file, de->seq_ops);
564} 566}
565 567
@@ -570,9 +572,9 @@ static const struct file_operations proc_seq_fops = {
570 .release = seq_release, 572 .release = seq_release,
571}; 573};
572 574
573struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, 575struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
574 struct proc_dir_entry *parent, const struct seq_operations *ops, 576 struct proc_dir_entry *parent, const struct seq_operations *ops,
575 void *data) 577 unsigned int state_size, void *data)
576{ 578{
577 struct proc_dir_entry *p; 579 struct proc_dir_entry *p;
578 580
@@ -581,9 +583,10 @@ struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode,
581 return NULL; 583 return NULL;
582 p->proc_fops = &proc_seq_fops; 584 p->proc_fops = &proc_seq_fops;
583 p->seq_ops = ops; 585 p->seq_ops = ops;
586 p->state_size = state_size;
584 return proc_register(parent, p); 587 return proc_register(parent, p);
585} 588}
586EXPORT_SYMBOL(proc_create_seq_data); 589EXPORT_SYMBOL(proc_create_seq_private);
587 590
588void proc_set_size(struct proc_dir_entry *de, loff_t size) 591void proc_set_size(struct proc_dir_entry *de, loff_t size)
589{ 592{
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 4fb01c5f9c1a..bcfe830ffd59 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -46,6 +46,7 @@ struct proc_dir_entry {
46 const struct file_operations *proc_fops; 46 const struct file_operations *proc_fops;
47 const struct seq_operations *seq_ops; 47 const struct seq_operations *seq_ops;
48 void *data; 48 void *data;
49 unsigned int state_size;
49 unsigned int low_ino; 50 unsigned int low_ino;
50 nlink_t nlink; 51 nlink_t nlink;
51 kuid_t uid; 52 kuid_t uid;
diff --git a/include/linux/atalk.h b/include/linux/atalk.h
index 40373920ea58..23f805562f4e 100644
--- a/include/linux/atalk.h
+++ b/include/linux/atalk.h
@@ -145,7 +145,12 @@ extern rwlock_t atalk_interfaces_lock;
145 145
146extern struct atalk_route atrtr_default; 146extern struct atalk_route atrtr_default;
147 147
148extern const struct file_operations atalk_seq_arp_fops; 148struct aarp_iter_state {
149 int bucket;
150 struct aarp_entry **table;
151};
152
153extern const struct seq_operations aarp_seq_ops;
149 154
150extern int sysctl_aarp_expiry_time; 155extern int sysctl_aarp_expiry_time;
151extern int sysctl_aarp_tick_time; 156extern int sysctl_aarp_tick_time;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index f368a896a8cb..314713a48817 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -25,11 +25,13 @@ extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
25 struct proc_dir_entry *); 25 struct proc_dir_entry *);
26struct proc_dir_entry *proc_create_mount_point(const char *name); 26struct proc_dir_entry *proc_create_mount_point(const char *name);
27 27
28struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, 28struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
29 struct proc_dir_entry *parent, const struct seq_operations *ops, 29 struct proc_dir_entry *parent, const struct seq_operations *ops,
30 void *data); 30 unsigned int state_size, void *data);
31#define proc_create_seq_data(name, mode, parent, ops, data) \
32 proc_create_seq_private(name, mode, parent, ops, 0, data)
31#define proc_create_seq(name, mode, parent, ops) \ 33#define proc_create_seq(name, mode, parent, ops) \
32 proc_create_seq_data(name, mode, parent, ops, NULL) 34 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
33 35
34extern struct proc_dir_entry *proc_create_data(const char *, umode_t, 36extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
35 struct proc_dir_entry *, 37 struct proc_dir_entry *,
@@ -64,6 +66,7 @@ static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
64 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } 66 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
65static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, 67static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
66 umode_t mode, struct proc_dir_entry *parent) { return NULL; } 68 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
69#define proc_create_seq_private(name, mode, parent, ops, 0, data) ({NULL;})
67#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) 70#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
68#define proc_create_seq(name, mode, parent, ops) ({NULL;}) 71#define proc_create_seq(name, mode, parent, ops) ({NULL;})
69#define proc_create(name, mode, parent, proc_fops) ({NULL;}) 72#define proc_create(name, mode, parent, proc_fops) ({NULL;})
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 0ed768b56c60..675c4e9563a9 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -372,24 +372,12 @@ static const struct seq_operations timer_list_sops = {
372 .show = timer_list_show, 372 .show = timer_list_show,
373}; 373};
374 374
375static int timer_list_open(struct inode *inode, struct file *filp)
376{
377 return seq_open_private(filp, &timer_list_sops,
378 sizeof(struct timer_list_iter));
379}
380
381static const struct file_operations timer_list_fops = {
382 .open = timer_list_open,
383 .read = seq_read,
384 .llseek = seq_lseek,
385 .release = seq_release_private,
386};
387
388static int __init init_timer_list_procfs(void) 375static int __init init_timer_list_procfs(void)
389{ 376{
390 struct proc_dir_entry *pe; 377 struct proc_dir_entry *pe;
391 378
392 pe = proc_create("timer_list", 0400, NULL, &timer_list_fops); 379 pe = proc_create_seq_private("timer_list", 0400, NULL, &timer_list_sops,
380 sizeof(struct timer_list_iter), NULL);
393 if (!pe) 381 if (!pe)
394 return -ENOMEM; 382 return -ENOMEM;
395 return 0; 383 return 0;
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index bc43c7838778..63a5f502da08 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2751,24 +2751,12 @@ static const struct seq_operations vmalloc_op = {
2751 .show = s_show, 2751 .show = s_show,
2752}; 2752};
2753 2753
2754static int vmalloc_open(struct inode *inode, struct file *file)
2755{
2756 return seq_open_private(file, &vmalloc_op,
2757 nr_node_ids * sizeof(unsigned int));
2758}
2759
2760static const struct file_operations proc_vmalloc_operations = {
2761 .open = vmalloc_open,
2762 .read = seq_read,
2763 .llseek = seq_lseek,
2764 .release = seq_release_private,
2765};
2766
2767static int __init proc_vmalloc_init(void) 2754static int __init proc_vmalloc_init(void)
2768{ 2755{
2769 if (IS_ENABLED(CONFIG_NUMA)) 2756 if (IS_ENABLED(CONFIG_NUMA))
2770 proc_create("vmallocinfo", S_IRUSR, NULL, 2757 proc_create_seq_private("vmallocinfo", S_IRUSR, NULL,
2771 &proc_vmalloc_operations); 2758 &vmalloc_op,
2759 nr_node_ids * sizeof(unsigned int), NULL);
2772 else 2760 else
2773 proc_create_seq("vmallocinfo", S_IRUSR, NULL, &vmalloc_op); 2761 proc_create_seq("vmallocinfo", S_IRUSR, NULL, &vmalloc_op);
2774 return 0; 2762 return 0;
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c
index d4c1021e74e1..49a16cee2aae 100644
--- a/net/appletalk/aarp.c
+++ b/net/appletalk/aarp.c
@@ -907,11 +907,6 @@ void aarp_device_down(struct net_device *dev)
907} 907}
908 908
909#ifdef CONFIG_PROC_FS 909#ifdef CONFIG_PROC_FS
910struct aarp_iter_state {
911 int bucket;
912 struct aarp_entry **table;
913};
914
915/* 910/*
916 * Get the aarp entry that is in the chain described 911 * Get the aarp entry that is in the chain described
917 * by the iterator. 912 * by the iterator.
@@ -1033,25 +1028,12 @@ static int aarp_seq_show(struct seq_file *seq, void *v)
1033 return 0; 1028 return 0;
1034} 1029}
1035 1030
1036static const struct seq_operations aarp_seq_ops = { 1031const struct seq_operations aarp_seq_ops = {
1037 .start = aarp_seq_start, 1032 .start = aarp_seq_start,
1038 .next = aarp_seq_next, 1033 .next = aarp_seq_next,
1039 .stop = aarp_seq_stop, 1034 .stop = aarp_seq_stop,
1040 .show = aarp_seq_show, 1035 .show = aarp_seq_show,
1041}; 1036};
1042
1043static int aarp_seq_open(struct inode *inode, struct file *file)
1044{
1045 return seq_open_private(file, &aarp_seq_ops,
1046 sizeof(struct aarp_iter_state));
1047}
1048
1049const struct file_operations atalk_seq_arp_fops = {
1050 .open = aarp_seq_open,
1051 .read = seq_read,
1052 .llseek = seq_lseek,
1053 .release = seq_release_private,
1054};
1055#endif 1037#endif
1056 1038
1057/* General module cleanup. Called from cleanup_module() in ddp.c. */ 1039/* General module cleanup. Called from cleanup_module() in ddp.c. */
diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
index d456c702e725..8006295f8bd7 100644
--- a/net/appletalk/atalk_proc.c
+++ b/net/appletalk/atalk_proc.c
@@ -236,7 +236,8 @@ int __init atalk_proc_init(void)
236 if (!p) 236 if (!p)
237 goto out_socket; 237 goto out_socket;
238 238
239 p = proc_create("arp", 0444, atalk_proc_dir, &atalk_seq_arp_fops); 239 p = proc_create_seq_private("arp", 0444, atalk_proc_dir, &aarp_seq_ops,
240 sizeof(struct aarp_iter_state), NULL);
240 if (!p) 241 if (!p)
241 goto out_arp; 242 goto out_arp;
242 243
diff --git a/net/atm/lec.c b/net/atm/lec.c
index 3138a869b5c0..5a95fcf6f9b6 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -990,18 +990,6 @@ static const struct seq_operations lec_seq_ops = {
990 .stop = lec_seq_stop, 990 .stop = lec_seq_stop,
991 .show = lec_seq_show, 991 .show = lec_seq_show,
992}; 992};
993
994static int lec_seq_open(struct inode *inode, struct file *file)
995{
996 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
997}
998
999static const struct file_operations lec_seq_fops = {
1000 .open = lec_seq_open,
1001 .read = seq_read,
1002 .llseek = seq_lseek,
1003 .release = seq_release_private,
1004};
1005#endif 993#endif
1006 994
1007static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 995static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
@@ -1047,7 +1035,8 @@ static int __init lane_module_init(void)
1047#ifdef CONFIG_PROC_FS 1035#ifdef CONFIG_PROC_FS
1048 struct proc_dir_entry *p; 1036 struct proc_dir_entry *p;
1049 1037
1050 p = proc_create("lec", 0444, atm_proc_root, &lec_seq_fops); 1038 p = proc_create_seq_private("lec", 0444, atm_proc_root, &lec_seq_ops,
1039 sizeof(struct lec_state), NULL);
1051 if (!p) { 1040 if (!p) {
1052 pr_err("Unable to initialize /proc/net/atm/lec\n"); 1041 pr_err("Unable to initialize /proc/net/atm/lec\n");
1053 return -ENOMEM; 1042 return -ENOMEM;
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 32751602767f..7d6ff983ba2c 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -2314,19 +2314,6 @@ static const struct seq_operations dn_socket_seq_ops = {
2314 .stop = dn_socket_seq_stop, 2314 .stop = dn_socket_seq_stop,
2315 .show = dn_socket_seq_show, 2315 .show = dn_socket_seq_show,
2316}; 2316};
2317
2318static int dn_socket_seq_open(struct inode *inode, struct file *file)
2319{
2320 return seq_open_private(file, &dn_socket_seq_ops,
2321 sizeof(struct dn_iter_state));
2322}
2323
2324static const struct file_operations dn_socket_seq_fops = {
2325 .open = dn_socket_seq_open,
2326 .read = seq_read,
2327 .llseek = seq_lseek,
2328 .release = seq_release_private,
2329};
2330#endif 2317#endif
2331 2318
2332static const struct net_proto_family dn_family_ops = { 2319static const struct net_proto_family dn_family_ops = {
@@ -2383,7 +2370,9 @@ static int __init decnet_init(void)
2383 dev_add_pack(&dn_dix_packet_type); 2370 dev_add_pack(&dn_dix_packet_type);
2384 register_netdevice_notifier(&dn_dev_notifier); 2371 register_netdevice_notifier(&dn_dev_notifier);
2385 2372
2386 proc_create("decnet", 0444, init_net.proc_net, &dn_socket_seq_fops); 2373 proc_create_seq_private("decnet", 0444, init_net.proc_net,
2374 &dn_socket_seq_ops, sizeof(struct dn_iter_state),
2375 NULL);
2387 dn_register_sysctl(); 2376 dn_register_sysctl();
2388out: 2377out:
2389 return rc; 2378 return rc;
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index eca0cc6b761f..e74765024d88 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1852,20 +1852,6 @@ static const struct seq_operations dn_rt_cache_seq_ops = {
1852 .stop = dn_rt_cache_seq_stop, 1852 .stop = dn_rt_cache_seq_stop,
1853 .show = dn_rt_cache_seq_show, 1853 .show = dn_rt_cache_seq_show,
1854}; 1854};
1855
1856static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1857{
1858 return seq_open_private(file, &dn_rt_cache_seq_ops,
1859 sizeof(struct dn_rt_cache_iter_state));
1860}
1861
1862static const struct file_operations dn_rt_cache_seq_fops = {
1863 .open = dn_rt_cache_seq_open,
1864 .read = seq_read,
1865 .llseek = seq_lseek,
1866 .release = seq_release_private,
1867};
1868
1869#endif /* CONFIG_PROC_FS */ 1855#endif /* CONFIG_PROC_FS */
1870 1856
1871void __init dn_route_init(void) 1857void __init dn_route_init(void)
@@ -1918,8 +1904,9 @@ void __init dn_route_init(void)
1918 1904
1919 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1); 1905 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
1920 1906
1921 proc_create("decnet_cache", 0444, init_net.proc_net, 1907 proc_create_seq_private("decnet_cache", 0444, init_net.proc_net,
1922 &dn_rt_cache_seq_fops); 1908 &dn_rt_cache_seq_ops,
1909 sizeof(struct dn_rt_cache_iter_state), NULL);
1923 1910
1924#ifdef CONFIG_DECNET_ROUTER 1911#ifdef CONFIG_DECNET_ROUTER
1925 rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE, 1912 rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE,