: udp_proc_register simplification.
Subsystems (3)
cover : udp_proc_register simplification.
Hello, Dave!
Here is a small set of changes to simplify udp_proc_register. It seems to difficult for me. Let's simplify it a bit.
Regards,
Den
PATCH 1/6 : Replace struct net on udp_iter_state with seq_net_private.
--- include/net/udp.h | 2 +- net/ipv4/udp.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/udp.h +1 -1
@@ -194,7 +194,7 @@ struct udp_seq_afinfo { };struct udp_iter_state { -struct net *net; +struct seq_net_private p;sa_family_t family;struct hlist_head *hashtable;int bucket;
net/ipv4/udp.c +4 -4
@@ -1506,7 +1506,7 @@ static struct sock *udp_get_first(struct seq_file *seq) {struct sock *sk;struct udp_iter_state *state = seq->private; -struct net *net = state->net; +struct net *net =seq_file_net (seq);for (state->bucket =0 ; state->bucket <UDP_HTABLE_SIZE ; ++state->bucket) {struct hlist_node *node;
@@ -1525,7 +1525,7 @@ found:static struct sock *udp_get_next (struct seq_file *seq,struct sock *sk) {struct udp_iter_state *state = seq->private; -struct net *net = state->net; +struct net *net =seq_file_net (seq); do { sk = sk_next(sk);
@@ -1598,7 +1598,7 @@ static int udp_seq_open(struct inode *inode, struct file *file) s->seq_ops.next = udp_seq_next; s->seq_ops.show = afinfo->seq_show; s->seq_ops.stop = udp_seq_stop; - s->net = net; + s->p.net = net; rc =seq_open (file, &s->seq_ops);if (rc)
@@ -1620,7 +1620,7 @@ static int udp_seq_release(struct inode *inode, struct file *file)struct seq_file *seq = file->private_data;struct udp_iter_state *s = seq->private; -put_net (s->net); +put_net (s->p.net);seq_release_private (inode, file);return 0 ; }
Signature · 1 line
1.5.3.rc5
PATCH 2/6 : No need to check afinfo != NULL in udp_proc_(un)register.
In reply to Denis V. Lunevudp_proc_register/udp_proc_unregister are called with a static pointer only.
--- net/ipv4/udp.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
net/ipv4/udp.c +0 -4
@@ -1631,8 +1631,6 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)struct proc_dir_entry *p;int rc =0 ; -if (!afinfo) -return -EINVAL ; afinfo->seq_fops->owner = afinfo->owner; afinfo->seq_fops->open = udp_seq_open; afinfo->seq_fops->read = seq_read;
@@ -1649,8 +1647,6 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)void udp_proc_unregister (struct net *net,struct udp_seq_afinfo *afinfo) { -if (!afinfo) -return ;proc_net_remove (net, afinfo->name);memset (afinfo->seq_fops,0 ,sizeof (*afinfo->seq_fops)); }
Signature · 1 line
1.5.3.rc5
PATCH 3/6 : Move seq_ops from udp_iter_state to udp_seq_afinfo.
In reply to Denis V. LunevNo need to create seq_operations for each instance of 'netstat'.
--- include/net/udp.h | 3 +-- net/ipv4/udp.c | 14 ++++++++------ net/ipv4/udplite.c | 4 +++- net/ipv6/udp.c | 4 +++- net/ipv6/udplite.c | 4 +++- 5 files changed, 18 insertions(+), 11 deletions(-)
include/net/udp.h +1 -2
@@ -189,8 +189,8 @@ struct udp_seq_afinfo {char *name;sa_family_t family;struct hlist_head *hashtable; -int (*seq_show) (struct seq_file *m,void *v);struct file_operations *seq_fops; +struct seq_operations seq_ops; };struct udp_iter_state {
@@ -198,7 +198,6 @@ struct udp_iter_state {sa_family_t family;struct hlist_head *hashtable;int bucket; -struct seq_operations seq_ops; };#ifdef CONFIG_PROC_FS
net/ipv4/udp.c +8 -6
@@ -1594,13 +1594,9 @@ static int udp_seq_open(struct inode *inode, struct file *file) s->family = afinfo->family; s->hashtable = afinfo->hashtable; - s->seq_ops.start = udp_seq_start; - s->seq_ops.next = udp_seq_next; - s->seq_ops.show = afinfo->seq_show; - s->seq_ops.stop = udp_seq_stop; s->p.net = net; - rc =seq_open (file, &s->seq_ops); + rc =seq_open (file, &afinfo->seq_ops);if (rc) goto out_put_net;
@@ -1637,6 +1633,10 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo) afinfo->seq_fops->llseek = seq_lseek; afinfo->seq_fops->release = udp_seq_release; + afinfo->seq_ops.start = udp_seq_start; + afinfo->seq_ops.next = udp_seq_next; + afinfo->seq_ops.stop = udp_seq_stop; + p =proc_net_fops_create (net, afinfo->name,S_IRUGO , afinfo->seq_fops);if (p) p->data = afinfo;
@@ -1693,8 +1693,10 @@ static struct udp_seq_afinfo udp4_seq_afinfo = { .name = "udp", .family = AF_INET, .hashtable = udp_hash, - .seq_show = udp4_seq_show, .seq_fops = &udp4_seq_fops, + .seq_ops = { + .show = udp4_seq_show, + }, };static int udp4_proc_init_net (struct net *net)
net/ipv4/udplite.c +3 -1
@@ -80,8 +80,10 @@ static struct udp_seq_afinfo udplite4_seq_afinfo = { .name = "udplite", .family = AF_INET, .hashtable = udplite_hash, - .seq_show = udp4_seq_show, .seq_fops = &udplite4_seq_fops, + .seq_ops = { + .show = udp4_seq_show, + }, };static int udplite4_proc_init_net (struct net *net)
net/ipv6/udp.c +3 -1
@@ -983,8 +983,10 @@ static struct udp_seq_afinfo udp6_seq_afinfo = { .name = "udp6", .family = AF_INET6, .hashtable = udp_hash, - .seq_show = udp6_seq_show, .seq_fops = &udp6_seq_fops, + .seq_ops = { + .show = udp6_seq_show, + }, };int udp6_proc_init (struct net *net)
net/ipv6/udplite.c +3 -1
@@ -105,8 +105,10 @@ static struct udp_seq_afinfo udplite6_seq_afinfo = { .name = "udplite6", .family = AF_INET6, .hashtable = udplite_hash, - .seq_show = udp6_seq_show, .seq_fops = &udplite6_seq_fops, + .seq_ops = { + .show = udp6_seq_show, + }, };static int udplite6_proc_init_net (struct net *net)
Signature · 1 line
1.5.3.rc5
PATCH 4/6 : Cleanup /proc/udp[6] creation/removal.
In reply to Denis V. LunevReplace seq_open with seq_open_net and remove udp_seq_release completely. seq_release_net will do this job just fine.
--- net/ipv4/udp.c | 46 +++++++++------------------------------------- 1 files changed, 9 insertions(+), 37 deletions(-)
net/ipv4/udp.c +9 -37
@@ -1579,46 +1579,18 @@ static void udp_seq_stop(struct seq_file *seq, void *v)static int udp_seq_open (struct inode *inode,struct file *file) {struct udp_seq_afinfo *afinfo =PDE (inode)->data; -struct seq_file *seq; -struct net *net; -int rc = -ENOMEM ; -struct udp_iter_state *s =kzalloc (sizeof (*s),GFP_KERNEL ); - -if (!s) - goto out; +struct udp_iter_state *s; +int err; - rc = -ENXIO ; - net =get_proc_net (inode); -if (!net) - goto out_kfree; + err =seq_open_net (inode, file, &afinfo->seq_ops, +sizeof (struct udp_iter_state )); +if (err <0 ) +return err; + s = ((struct seq_file *)file->private_data)->private; s->family = afinfo->family; s->hashtable = afinfo->hashtable; - s->p.net = net; - - rc =seq_open (file, &afinfo->seq_ops); -if (rc) - goto out_put_net; - - seq = file->private_data; - seq->private = s; -out: -return rc; -out_put_net: -put_net (net); -out_kfree: -kfree (s); - goto out; -} - -static int udp_seq_release (struct inode *inode,struct file *file) -{ -struct seq_file *seq = file->private_data; -struct udp_iter_state *s = seq->private; - -put_net (s->p.net); -seq_release_private (inode, file); -return 0 ; +return err; }/* ------------------------------------------------------------------------ */
@@ -1631,7 +1603,7 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo) afinfo->seq_fops->open = udp_seq_open; afinfo->seq_fops->read = seq_read; afinfo->seq_fops->llseek = seq_lseek; - afinfo->seq_fops->release = udp_seq_release; + afinfo->seq_fops->release = seq_release_net; afinfo->seq_ops.start = udp_seq_start; afinfo->seq_ops.next = udp_seq_next;
Signature · 1 line
1.5.3.rc5
PATCH 5/6 : Place file operations directly into udp_seq_afinfo.
In reply to Denis V. LunevNo need to have separate never-used variable.
--- include/net/udp.h | 2 +- net/ipv4/udp.c | 15 ++++++--------- net/ipv4/udplite.c | 2 -- net/ipv6/udp.c | 2 -- net/ipv6/udplite.c | 2 -- 5 files changed, 7 insertions(+), 16 deletions(-)
include/net/udp.h +1 -1
@@ -189,7 +189,7 @@ struct udp_seq_afinfo {char *name;sa_family_t family;struct hlist_head *hashtable; -struct file_operations *seq_fops; +struct file_operations seq_fops;struct seq_operations seq_ops; };
net/ipv4/udp.c +6 -9
@@ -1599,17 +1599,17 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)struct proc_dir_entry *p;int rc =0 ; - afinfo->seq_fops->owner = afinfo->owner; - afinfo->seq_fops->open = udp_seq_open; - afinfo->seq_fops->read = seq_read; - afinfo->seq_fops->llseek = seq_lseek; - afinfo->seq_fops->release = seq_release_net; + afinfo->seq_fops.owner = afinfo->owner; + afinfo->seq_fops.open = udp_seq_open; + afinfo->seq_fops.read = seq_read; + afinfo->seq_fops.llseek = seq_lseek; + afinfo->seq_fops.release = seq_release_net; afinfo->seq_ops.start = udp_seq_start; afinfo->seq_ops.next = udp_seq_next; afinfo->seq_ops.stop = udp_seq_stop; - p =proc_net_fops_create (net, afinfo->name,S_IRUGO , afinfo->seq_fops); + p =proc_net_fops_create (net, afinfo->name,S_IRUGO , &afinfo->seq_fops);if (p) p->data = afinfo;else
@@ -1620,7 +1620,6 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)void udp_proc_unregister (struct net *net,struct udp_seq_afinfo *afinfo) {proc_net_remove (net, afinfo->name); -memset (afinfo->seq_fops,0 ,sizeof (*afinfo->seq_fops)); }/* ------------------------------------------------------------------------ */
@@ -1659,13 +1658,11 @@ int udp4_seq_show(struct seq_file *seq, void *v) }/* ------------------------------------------------------------------------ */ -static struct file_operations udp4_seq_fops;static struct udp_seq_afinfo udp4_seq_afinfo = { .owner =THIS_MODULE , .name ="udp" , .family =AF_INET , .hashtable = udp_hash, - .seq_fops = &udp4_seq_fops, .seq_ops = { .show = udp4_seq_show, },
net/ipv4/udplite.c +0 -2
@@ -74,13 +74,11 @@ static struct inet_protosw udplite4_protosw = { };#ifdef CONFIG_PROC_FS -static struct file_operations udplite4_seq_fops;static struct udp_seq_afinfo udplite4_seq_afinfo = { .owner =THIS_MODULE , .name ="udplite" , .family =AF_INET , .hashtable = udplite_hash, - .seq_fops = &udplite4_seq_fops, .seq_ops = { .show = udp4_seq_show, },
net/ipv6/udp.c +0 -2
@@ -977,13 +977,11 @@ int udp6_seq_show(struct seq_file *seq, void *v)return 0 ; } -static struct file_operations udp6_seq_fops;static struct udp_seq_afinfo udp6_seq_afinfo = { .owner =THIS_MODULE , .name ="udp6" , .family =AF_INET6 , .hashtable = udp_hash, - .seq_fops = &udp6_seq_fops, .seq_ops = { .show = udp6_seq_show, },
net/ipv6/udplite.c +0 -2
@@ -99,13 +99,11 @@ void udplitev6_exit(void) }#ifdef CONFIG_PROC_FS -static struct file_operations udplite6_seq_fops;static struct udp_seq_afinfo udplite6_seq_afinfo = { .owner =THIS_MODULE , .name ="udplite6" , .family =AF_INET6 , .hashtable = udplite_hash, - .seq_fops = &udplite6_seq_fops, .seq_ops = { .show = udp6_seq_show, },
Signature · 1 line
1.5.3.rc5
PATCH 6/6 : Remove owner from udp_seq_afinfo.
In reply to Denis V. LunevMove it to udp_seq_afinfo->seq_fops as should be.
--- include/net/udp.h | 1 - net/ipv4/udp.c | 5 +++-- net/ipv4/udplite.c | 4 +++- net/ipv6/udp.c | 4 +++- net/ipv6/udplite.c | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-)
include/net/udp.h +0 -1
@@ -185,7 +185,6 @@ DECLARE_SNMP_STAT(struct udp_mib, udplite_stats_in6);/* /proc */ struct udp_seq_afinfo { -struct module *owner;char *name;sa_family_t family;struct hlist_head *hashtable;
net/ipv4/udp.c +3 -2
@@ -1599,7 +1599,6 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)struct proc_dir_entry *p;int rc =0 ; - afinfo->seq_fops.owner = afinfo->owner; afinfo->seq_fops.open = udp_seq_open; afinfo->seq_fops.read = seq_read; afinfo->seq_fops.llseek = seq_lseek;
@@ -1659,10 +1658,12 @@ int udp4_seq_show(struct seq_file *seq, void *v)/* ------------------------------------------------------------------------ */ static struct udp_seq_afinfo udp4_seq_afinfo = { - .owner =THIS_MODULE , .name ="udp" , .family =AF_INET , .hashtable = udp_hash, + .seq_fops = { + .owner =THIS_MODULE , + }, .seq_ops = { .show = udp4_seq_show, },
net/ipv4/udplite.c +3 -1
@@ -75,10 +75,12 @@ static struct inet_protosw udplite4_protosw = {#ifdef CONFIG_PROC_FS static struct udp_seq_afinfo udplite4_seq_afinfo = { - .owner =THIS_MODULE , .name ="udplite" , .family =AF_INET , .hashtable = udplite_hash, + .seq_fops = { + .owner =THIS_MODULE , + }, .seq_ops = { .show = udp4_seq_show, },
net/ipv6/udp.c +3 -1
@@ -978,10 +978,12 @@ int udp6_seq_show(struct seq_file *seq, void *v) }static struct udp_seq_afinfo udp6_seq_afinfo = { - .owner =THIS_MODULE , .name ="udp6" , .family =AF_INET6 , .hashtable = udp_hash, + .seq_fops = { + .owner =THIS_MODULE , + }, .seq_ops = { .show = udp6_seq_show, },
net/ipv6/udplite.c +3 -1
@@ -100,10 +100,12 @@ void udplitev6_exit(void)#ifdef CONFIG_PROC_FS static struct udp_seq_afinfo udplite6_seq_afinfo = { - .owner =THIS_MODULE , .name ="udplite6" , .family =AF_INET6 , .hashtable = udplite_hash, + .seq_fops = { + .owner =THIS_MODULE , + }, .seq_ops = { .show = udp6_seq_show, },
Signature · 1 line
1.5.3.rc5
David Miller
maintainerFrom: "Denis V. Lunev" <[email protected]>
Date: Thu, 27 Mar 2008 17:10:41 +0300
Quoted 4 lines
Hello, Dave!
Here is a small set of changes to simplify
udp_proc_register. It seems to difficult for me. Let's simplify it a bit.
All applied, thanks!