Skip to content

Commit 44414d8

Browse files
author
Christoph Hellwig
committed
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 <[email protected]>
1 parent fddda2b commit 44414d8

File tree

12 files changed

+37
-113
lines changed

12 files changed

+37
-113
lines changed

fs/locks.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,22 +2788,10 @@ static const struct seq_operations locks_seq_operations = {
27882788
.show = locks_show,
27892789
};
27902790

2791-
static 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-
2797-
static 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-
28042791
static int __init proc_locks_init(void)
28052792
{
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);
28072795
return 0;
28082796
}
28092797
fs_initcall(proc_locks_init);

fs/proc/generic.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ static int proc_seq_open(struct inode *inode, struct file *file)
560560
{
561561
struct proc_dir_entry *de = PDE(inode);
562562

563+
if (de->state_size)
564+
return seq_open_private(file, de->seq_ops, de->state_size);
563565
return seq_open(file, de->seq_ops);
564566
}
565567

@@ -570,9 +572,9 @@ static const struct file_operations proc_seq_fops = {
570572
.release = seq_release,
571573
};
572574

573-
struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode,
575+
struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
574576
struct proc_dir_entry *parent, const struct seq_operations *ops,
575-
void *data)
577+
unsigned int state_size, void *data)
576578
{
577579
struct proc_dir_entry *p;
578580

@@ -581,9 +583,10 @@ struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode,
581583
return NULL;
582584
p->proc_fops = &proc_seq_fops;
583585
p->seq_ops = ops;
586+
p->state_size = state_size;
584587
return proc_register(parent, p);
585588
}
586-
EXPORT_SYMBOL(proc_create_seq_data);
589+
EXPORT_SYMBOL(proc_create_seq_private);
587590

588591
void proc_set_size(struct proc_dir_entry *de, loff_t size)
589592
{

fs/proc/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct proc_dir_entry {
4646
const struct file_operations *proc_fops;
4747
const struct seq_operations *seq_ops;
4848
void *data;
49+
unsigned int state_size;
4950
unsigned int low_ino;
5051
nlink_t nlink;
5152
kuid_t uid;

include/linux/atalk.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ extern rwlock_t atalk_interfaces_lock;
145145

146146
extern struct atalk_route atrtr_default;
147147

148-
extern const struct file_operations atalk_seq_arp_fops;
148+
struct aarp_iter_state {
149+
int bucket;
150+
struct aarp_entry **table;
151+
};
152+
153+
extern const struct seq_operations aarp_seq_ops;
149154

150155
extern int sysctl_aarp_expiry_time;
151156
extern int sysctl_aarp_tick_time;

include/linux/proc_fs.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
2525
struct proc_dir_entry *);
2626
struct proc_dir_entry *proc_create_mount_point(const char *name);
2727

28-
struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode,
28+
struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
2929
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)
3133
#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)
3335

3436
extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
3537
struct proc_dir_entry *,
@@ -64,6 +66,7 @@ static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
6466
umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
6567
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
6668
umode_t mode, struct proc_dir_entry *parent) { return NULL; }
69+
#define proc_create_seq_private(name, mode, parent, ops, 0, data) ({NULL;})
6770
#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
6871
#define proc_create_seq(name, mode, parent, ops) ({NULL;})
6972
#define proc_create(name, mode, parent, proc_fops) ({NULL;})

kernel/time/timer_list.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,12 @@ static const struct seq_operations timer_list_sops = {
372372
.show = timer_list_show,
373373
};
374374

375-
static 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-
381-
static 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-
388375
static int __init init_timer_list_procfs(void)
389376
{
390377
struct proc_dir_entry *pe;
391378

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);
393381
if (!pe)
394382
return -ENOMEM;
395383
return 0;

mm/vmalloc.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,24 +2751,12 @@ static const struct seq_operations vmalloc_op = {
27512751
.show = s_show,
27522752
};
27532753

2754-
static 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-
2760-
static 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-
27672754
static int __init proc_vmalloc_init(void)
27682755
{
27692756
if (IS_ENABLED(CONFIG_NUMA))
2770-
proc_create("vmallocinfo", S_IRUSR, NULL,
2771-
&proc_vmalloc_operations);
2757+
proc_create_seq_private("vmallocinfo", S_IRUSR, NULL,
2758+
&vmalloc_op,
2759+
nr_node_ids * sizeof(unsigned int), NULL);
27722760
else
27732761
proc_create_seq("vmallocinfo", S_IRUSR, NULL, &vmalloc_op);
27742762
return 0;

net/appletalk/aarp.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,6 @@ void aarp_device_down(struct net_device *dev)
907907
}
908908

909909
#ifdef CONFIG_PROC_FS
910-
struct aarp_iter_state {
911-
int bucket;
912-
struct aarp_entry **table;
913-
};
914-
915910
/*
916911
* Get the aarp entry that is in the chain described
917912
* by the iterator.
@@ -1033,25 +1028,12 @@ static int aarp_seq_show(struct seq_file *seq, void *v)
10331028
return 0;
10341029
}
10351030

1036-
static const struct seq_operations aarp_seq_ops = {
1031+
const struct seq_operations aarp_seq_ops = {
10371032
.start = aarp_seq_start,
10381033
.next = aarp_seq_next,
10391034
.stop = aarp_seq_stop,
10401035
.show = aarp_seq_show,
10411036
};
1042-
1043-
static 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-
1049-
const 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-
};
10551037
#endif
10561038

10571039
/* General module cleanup. Called from cleanup_module() in ddp.c. */

net/appletalk/atalk_proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ int __init atalk_proc_init(void)
236236
if (!p)
237237
goto out_socket;
238238

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);
240241
if (!p)
241242
goto out_arp;
242243

net/atm/lec.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -990,18 +990,6 @@ static const struct seq_operations lec_seq_ops = {
990990
.stop = lec_seq_stop,
991991
.show = lec_seq_show,
992992
};
993-
994-
static 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-
999-
static 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-
};
1005993
#endif
1006994

1007995
static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
@@ -1047,7 +1035,8 @@ static int __init lane_module_init(void)
10471035
#ifdef CONFIG_PROC_FS
10481036
struct proc_dir_entry *p;
10491037

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);
10511040
if (!p) {
10521041
pr_err("Unable to initialize /proc/net/atm/lec\n");
10531042
return -ENOMEM;

net/decnet/af_decnet.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,19 +2314,6 @@ static const struct seq_operations dn_socket_seq_ops = {
23142314
.stop = dn_socket_seq_stop,
23152315
.show = dn_socket_seq_show,
23162316
};
2317-
2318-
static 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-
2324-
static 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-
};
23302317
#endif
23312318

23322319
static const struct net_proto_family dn_family_ops = {
@@ -2383,7 +2370,9 @@ static int __init decnet_init(void)
23832370
dev_add_pack(&dn_dix_packet_type);
23842371
register_netdevice_notifier(&dn_dev_notifier);
23852372

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);
23872376
dn_register_sysctl();
23882377
out:
23892378
return rc;

net/decnet/dn_route.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,20 +1852,6 @@ static const struct seq_operations dn_rt_cache_seq_ops = {
18521852
.stop = dn_rt_cache_seq_stop,
18531853
.show = dn_rt_cache_seq_show,
18541854
};
1855-
1856-
static 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-
1862-
static 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-
18691855
#endif /* CONFIG_PROC_FS */
18701856

18711857
void __init dn_route_init(void)
@@ -1918,8 +1904,9 @@ void __init dn_route_init(void)
19181904

19191905
dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
19201906

1921-
proc_create("decnet_cache", 0444, init_net.proc_net,
1922-
&dn_rt_cache_seq_fops);
1907+
proc_create_seq_private("decnet_cache", 0444, init_net.proc_net,
1908+
&dn_rt_cache_seq_ops,
1909+
sizeof(struct dn_rt_cache_iter_state), NULL);
19231910

19241911
#ifdef CONFIG_DECNET_ROUTER
19251912
rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE,

0 commit comments

Comments
 (0)