Skip to content

Commit c350637

Browse files
author
Christoph Hellwig
committed
proc: introduce proc_create_net{,_data}
Variants of proc_create{,_data} that directly take a struct seq_operations and deal with network namespaces in ->open and ->release. All callers of proc_create + seq_open_net converted over, and seq_{open,release}_net are removed entirely. Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent a2dcdee commit c350637

57 files changed

Lines changed: 202 additions & 939 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎drivers/net/ppp/pppoe.c‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,21 +1096,6 @@ static const struct seq_operations pppoe_seq_ops = {
10961096
.stop = pppoe_seq_stop,
10971097
.show = pppoe_seq_show,
10981098
};
1099-
1100-
static int pppoe_seq_open(struct inode *inode, struct file *file)
1101-
{
1102-
return seq_open_net(inode, file, &pppoe_seq_ops,
1103-
sizeof(struct seq_net_private));
1104-
}
1105-
1106-
static const struct file_operations pppoe_seq_fops = {
1107-
.owner = THIS_MODULE,
1108-
.open = pppoe_seq_open,
1109-
.read = seq_read,
1110-
.llseek = seq_lseek,
1111-
.release = seq_release_net,
1112-
};
1113-
11141099
#endif /* CONFIG_PROC_FS */
11151100

11161101
static const struct proto_ops pppoe_ops = {
@@ -1146,7 +1131,8 @@ static __net_init int pppoe_init_net(struct net *net)
11461131

11471132
rwlock_init(&pn->hash_lock);
11481133

1149-
pde = proc_create("pppoe", 0444, net->proc_net, &pppoe_seq_fops);
1134+
pde = proc_create_net("pppoe", 0444, net->proc_net,
1135+
&pppoe_seq_ops, sizeof(struct seq_net_private));
11501136
#ifdef CONFIG_PROC_FS
11511137
if (!pde)
11521138
return -ENOMEM;

‎fs/nfs/client.c‎

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,6 @@ void nfs_clients_init(struct net *net)
10671067
}
10681068

10691069
#ifdef CONFIG_PROC_FS
1070-
static int nfs_server_list_open(struct inode *inode, struct file *file);
10711070
static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
10721071
static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
10731072
static void nfs_server_list_stop(struct seq_file *p, void *v);
@@ -1080,14 +1079,6 @@ static const struct seq_operations nfs_server_list_ops = {
10801079
.show = nfs_server_list_show,
10811080
};
10821081

1083-
static const struct file_operations nfs_server_list_fops = {
1084-
.open = nfs_server_list_open,
1085-
.read = seq_read,
1086-
.llseek = seq_lseek,
1087-
.release = seq_release_net,
1088-
};
1089-
1090-
static int nfs_volume_list_open(struct inode *inode, struct file *file);
10911082
static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
10921083
static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
10931084
static void nfs_volume_list_stop(struct seq_file *p, void *v);
@@ -1100,23 +1091,6 @@ static const struct seq_operations nfs_volume_list_ops = {
11001091
.show = nfs_volume_list_show,
11011092
};
11021093

1103-
static const struct file_operations nfs_volume_list_fops = {
1104-
.open = nfs_volume_list_open,
1105-
.read = seq_read,
1106-
.llseek = seq_lseek,
1107-
.release = seq_release_net,
1108-
};
1109-
1110-
/*
1111-
* open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1112-
* we're dealing
1113-
*/
1114-
static int nfs_server_list_open(struct inode *inode, struct file *file)
1115-
{
1116-
return seq_open_net(inode, file, &nfs_server_list_ops,
1117-
sizeof(struct seq_net_private));
1118-
}
1119-
11201094
/*
11211095
* set up the iterator to start reading from the server list and return the first item
11221096
*/
@@ -1184,15 +1158,6 @@ static int nfs_server_list_show(struct seq_file *m, void *v)
11841158
return 0;
11851159
}
11861160

1187-
/*
1188-
* open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1189-
*/
1190-
static int nfs_volume_list_open(struct inode *inode, struct file *file)
1191-
{
1192-
return seq_open_net(inode, file, &nfs_volume_list_ops,
1193-
sizeof(struct seq_net_private));
1194-
}
1195-
11961161
/*
11971162
* set up the iterator to start reading from the volume list and return the first item
11981163
*/
@@ -1278,14 +1243,14 @@ int nfs_fs_proc_net_init(struct net *net)
12781243
goto error_0;
12791244

12801245
/* a file of servers with which we're dealing */
1281-
p = proc_create("servers", S_IFREG|S_IRUGO,
1282-
nn->proc_nfsfs, &nfs_server_list_fops);
1246+
p = proc_create_net("servers", S_IFREG|S_IRUGO, nn->proc_nfsfs,
1247+
&nfs_server_list_ops, sizeof(struct seq_net_private));
12831248
if (!p)
12841249
goto error_1;
12851250

12861251
/* a file of volumes that we have mounted */
1287-
p = proc_create("volumes", S_IFREG|S_IRUGO,
1288-
nn->proc_nfsfs, &nfs_volume_list_fops);
1252+
p = proc_create_net("volumes", S_IFREG|S_IRUGO, nn->proc_nfsfs,
1253+
&nfs_volume_list_ops, sizeof(struct seq_net_private));
12891254
if (!p)
12901255
goto error_1;
12911256
return 0;

‎fs/proc/proc_net.c‎

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ static struct net *get_proc_net(const struct inode *inode)
3838
return maybe_get_net(PDE_NET(PDE(inode)));
3939
}
4040

41-
int seq_open_net(struct inode *ino, struct file *f,
42-
const struct seq_operations *ops, int size)
41+
static int seq_open_net(struct inode *inode, struct file *file)
4342
{
44-
struct net *net;
43+
unsigned int state_size = PDE(inode)->state_size;
4544
struct seq_net_private *p;
45+
struct net *net;
4646

47-
BUG_ON(size < sizeof(*p));
47+
WARN_ON_ONCE(state_size < sizeof(*p));
4848

49-
net = get_proc_net(ino);
50-
if (net == NULL)
49+
net = get_proc_net(inode);
50+
if (!net)
5151
return -ENXIO;
5252

53-
p = __seq_open_private(f, ops, size);
54-
if (p == NULL) {
53+
p = __seq_open_private(file, PDE(inode)->seq_ops, state_size);
54+
if (!p) {
5555
put_net(net);
5656
return -ENOMEM;
5757
}
@@ -60,7 +60,38 @@ int seq_open_net(struct inode *ino, struct file *f,
6060
#endif
6161
return 0;
6262
}
63-
EXPORT_SYMBOL_GPL(seq_open_net);
63+
64+
static int seq_release_net(struct inode *ino, struct file *f)
65+
{
66+
struct seq_file *seq = f->private_data;
67+
68+
put_net(seq_file_net(seq));
69+
seq_release_private(ino, f);
70+
return 0;
71+
}
72+
73+
static const struct file_operations proc_net_seq_fops = {
74+
.open = seq_open_net,
75+
.read = seq_read,
76+
.llseek = seq_lseek,
77+
.release = seq_release_net,
78+
};
79+
80+
struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
81+
struct proc_dir_entry *parent, const struct seq_operations *ops,
82+
unsigned int state_size, void *data)
83+
{
84+
struct proc_dir_entry *p;
85+
86+
p = proc_create_reg(name, mode, &parent, data);
87+
if (!p)
88+
return NULL;
89+
p->proc_fops = &proc_net_seq_fops;
90+
p->seq_ops = ops;
91+
p->state_size = state_size;
92+
return proc_register(parent, p);
93+
}
94+
EXPORT_SYMBOL_GPL(proc_create_net_data);
6495

6596
int single_open_net(struct inode *inode, struct file *file,
6697
int (*show)(struct seq_file *, void *))
@@ -86,18 +117,6 @@ int single_open_net(struct inode *inode, struct file *file,
86117
}
87118
EXPORT_SYMBOL_GPL(single_open_net);
88119

89-
int seq_release_net(struct inode *ino, struct file *f)
90-
{
91-
struct seq_file *seq;
92-
93-
seq = f->private_data;
94-
95-
put_net(seq_file_net(seq));
96-
seq_release_private(ino, f);
97-
return 0;
98-
}
99-
EXPORT_SYMBOL_GPL(seq_release_net);
100-
101120
int single_release_net(struct inode *ino, struct file *f)
102121
{
103122
struct seq_file *seq = f->private_data;

‎include/linux/proc_fs.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ extern void proc_remove(struct proc_dir_entry *);
5353
extern void remove_proc_entry(const char *, struct proc_dir_entry *);
5454
extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
5555

56+
struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
57+
struct proc_dir_entry *parent, const struct seq_operations *ops,
58+
unsigned int state_size, void *data);
59+
#define proc_create_net(name, mode, parent, state_size, ops) \
60+
proc_create_net_data(name, mode, parent, state_size, ops, NULL)
61+
5662
#else /* CONFIG_PROC_FS */
5763

5864
static inline void proc_root_init(void)
@@ -89,6 +95,9 @@ static inline void proc_remove(struct proc_dir_entry *de) {}
8995
#define remove_proc_entry(name, parent) do {} while (0)
9096
static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
9197

98+
#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
99+
#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
100+
92101
#endif /* CONFIG_PROC_FS */
93102

94103
struct net;

‎include/linux/seq_file_net.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ struct seq_net_private {
1313
#endif
1414
};
1515

16-
int seq_open_net(struct inode *, struct file *,
17-
const struct seq_operations *, int);
1816
int single_open_net(struct inode *, struct file *file,
1917
int (*show)(struct seq_file *, void *));
20-
int seq_release_net(struct inode *, struct file *);
2118
int single_release_net(struct inode *, struct file *);
2219
static inline struct net *seq_file_net(struct seq_file *seq)
2320
{

‎include/net/ip6_fib.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,15 @@ void fib6_gc_cleanup(void);
394394

395395
int fib6_init(void);
396396

397-
int ipv6_route_open(struct inode *inode, struct file *file);
397+
struct ipv6_route_iter {
398+
struct seq_net_private p;
399+
struct fib6_walker w;
400+
loff_t skip;
401+
struct fib6_table *tbl;
402+
int sernum;
403+
};
404+
405+
extern const struct seq_operations ipv6_route_seq_ops;
398406

399407
int call_fib6_notifier(struct notifier_block *nb, struct net *net,
400408
enum fib_event_type event_type,

‎include/net/phonet/pn_dev.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct net_device *phonet_route_output(struct net *net, u8 daddr);
5656

5757
#define PN_NO_ADDR 0xff
5858

59-
extern const struct file_operations pn_sock_seq_fops;
60-
extern const struct file_operations pn_res_seq_fops;
59+
extern const struct seq_operations pn_sock_seq_ops;
60+
extern const struct seq_operations pn_res_seq_ops;
6161

6262
#endif

‎include/net/udp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ void *udp_seq_start(struct seq_file *seq, loff_t *pos);
423423
void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos);
424424
void udp_seq_stop(struct seq_file *seq, void *v);
425425

426-
extern const struct file_operations udp_afinfo_seq_fops;
427-
extern const struct file_operations udp6_afinfo_seq_fops;
426+
extern const struct seq_operations udp_seq_ops;
427+
extern const struct seq_operations udp6_seq_ops;
428428

429429
int udp4_proc_init(void);
430430
void udp4_proc_exit(void);

‎net/8021q/vlanproc.c‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ static const struct seq_operations vlan_seq_ops = {
7373
.show = vlan_seq_show,
7474
};
7575

76-
static int vlan_seq_open(struct inode *inode, struct file *file)
77-
{
78-
return seq_open_net(inode, file, &vlan_seq_ops,
79-
sizeof(struct seq_net_private));
80-
}
81-
82-
static const struct file_operations vlan_fops = {
83-
.open = vlan_seq_open,
84-
.read = seq_read,
85-
.llseek = seq_lseek,
86-
.release = seq_release_net,
87-
};
88-
8976
/*
9077
* Proc filesystem directory entries.
9178
*/
@@ -132,8 +119,9 @@ int __net_init vlan_proc_init(struct net *net)
132119
if (!vn->proc_vlan_dir)
133120
goto err;
134121

135-
vn->proc_vlan_conf = proc_create(name_conf, S_IFREG | 0600,
136-
vn->proc_vlan_dir, &vlan_fops);
122+
vn->proc_vlan_conf = proc_create_net(name_conf, S_IFREG | 0600,
123+
vn->proc_vlan_dir, &vlan_seq_ops,
124+
sizeof(struct seq_net_private));
137125
if (!vn->proc_vlan_conf)
138126
goto err;
139127
return 0;

‎net/atm/clip.c‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -863,20 +863,6 @@ static const struct seq_operations arp_seq_ops = {
863863
.stop = neigh_seq_stop,
864864
.show = clip_seq_show,
865865
};
866-
867-
static int arp_seq_open(struct inode *inode, struct file *file)
868-
{
869-
return seq_open_net(inode, file, &arp_seq_ops,
870-
sizeof(struct clip_seq_state));
871-
}
872-
873-
static const struct file_operations arp_seq_fops = {
874-
.open = arp_seq_open,
875-
.read = seq_read,
876-
.llseek = seq_lseek,
877-
.release = seq_release_net,
878-
.owner = THIS_MODULE
879-
};
880866
#endif
881867

882868
static void atm_clip_exit_noproc(void);
@@ -893,7 +879,8 @@ static int __init atm_clip_init(void)
893879
{
894880
struct proc_dir_entry *p;
895881

896-
p = proc_create("arp", 0444, atm_proc_root, &arp_seq_fops);
882+
p = proc_create_net("arp", 0444, atm_proc_root, &arp_seq_ops,
883+
sizeof(struct clip_seq_state));
897884
if (!p) {
898885
pr_err("Unable to initialize /proc/net/atm/arp\n");
899886
atm_clip_exit_noproc();

0 commit comments

Comments
 (0)