Commit 93cb5a1f authored by Christoph Hellwig's avatar Christoph Hellwig

ipv{4,6}/raw: simplify ѕeq_file code

Pass the hashtable to the proc private data instead of copying
it into the per-file private data.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent f4550221
...@@ -48,7 +48,6 @@ void raw_proc_exit(void); ...@@ -48,7 +48,6 @@ void raw_proc_exit(void);
struct raw_iter_state { struct raw_iter_state {
struct seq_net_private p; struct seq_net_private p;
int bucket; int bucket;
struct raw_hashinfo *h;
}; };
static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq) static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq)
...@@ -58,9 +57,6 @@ static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq) ...@@ -58,9 +57,6 @@ static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq)
void *raw_seq_start(struct seq_file *seq, loff_t *pos); void *raw_seq_start(struct seq_file *seq, loff_t *pos);
void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos); void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
void raw_seq_stop(struct seq_file *seq, void *v); void raw_seq_stop(struct seq_file *seq, void *v);
int raw_seq_open(struct inode *ino, struct file *file,
struct raw_hashinfo *h, const struct seq_operations *ops);
#endif #endif
int raw_hash_sk(struct sock *sk); int raw_hash_sk(struct sock *sk);
......
...@@ -1003,11 +1003,12 @@ struct proto raw_prot = { ...@@ -1003,11 +1003,12 @@ struct proto raw_prot = {
static struct sock *raw_get_first(struct seq_file *seq) static struct sock *raw_get_first(struct seq_file *seq)
{ {
struct sock *sk; struct sock *sk;
struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
struct raw_iter_state *state = raw_seq_private(seq); struct raw_iter_state *state = raw_seq_private(seq);
for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE; for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
++state->bucket) { ++state->bucket) {
sk_for_each(sk, &state->h->ht[state->bucket]) sk_for_each(sk, &h->ht[state->bucket])
if (sock_net(sk) == seq_file_net(seq)) if (sock_net(sk) == seq_file_net(seq))
goto found; goto found;
} }
...@@ -1018,6 +1019,7 @@ static struct sock *raw_get_first(struct seq_file *seq) ...@@ -1018,6 +1019,7 @@ static struct sock *raw_get_first(struct seq_file *seq)
static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk) static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
{ {
struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
struct raw_iter_state *state = raw_seq_private(seq); struct raw_iter_state *state = raw_seq_private(seq);
do { do {
...@@ -1027,7 +1029,7 @@ static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk) ...@@ -1027,7 +1029,7 @@ static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
} while (sk && sock_net(sk) != seq_file_net(seq)); } while (sk && sock_net(sk) != seq_file_net(seq));
if (!sk && ++state->bucket < RAW_HTABLE_SIZE) { if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
sk = sk_head(&state->h->ht[state->bucket]); sk = sk_head(&h->ht[state->bucket]);
goto try_again; goto try_again;
} }
return sk; return sk;
...@@ -1045,9 +1047,9 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos) ...@@ -1045,9 +1047,9 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
void *raw_seq_start(struct seq_file *seq, loff_t *pos) void *raw_seq_start(struct seq_file *seq, loff_t *pos)
{ {
struct raw_iter_state *state = raw_seq_private(seq); struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
read_lock(&state->h->lock); read_lock(&h->lock);
return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
} }
EXPORT_SYMBOL_GPL(raw_seq_start); EXPORT_SYMBOL_GPL(raw_seq_start);
...@@ -1067,9 +1069,9 @@ EXPORT_SYMBOL_GPL(raw_seq_next); ...@@ -1067,9 +1069,9 @@ EXPORT_SYMBOL_GPL(raw_seq_next);
void raw_seq_stop(struct seq_file *seq, void *v) void raw_seq_stop(struct seq_file *seq, void *v)
{ {
struct raw_iter_state *state = raw_seq_private(seq); struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
read_unlock(&state->h->lock); read_unlock(&h->lock);
} }
EXPORT_SYMBOL_GPL(raw_seq_stop); EXPORT_SYMBOL_GPL(raw_seq_stop);
...@@ -1110,25 +1112,10 @@ static const struct seq_operations raw_seq_ops = { ...@@ -1110,25 +1112,10 @@ static const struct seq_operations raw_seq_ops = {
.show = raw_seq_show, .show = raw_seq_show,
}; };
int raw_seq_open(struct inode *ino, struct file *file,
struct raw_hashinfo *h, const struct seq_operations *ops)
{
int err;
struct raw_iter_state *i;
err = seq_open_net(ino, file, ops, sizeof(struct raw_iter_state));
if (err < 0)
return err;
i = raw_seq_private((struct seq_file *)file->private_data);
i->h = h;
return 0;
}
EXPORT_SYMBOL_GPL(raw_seq_open);
static int raw_v4_seq_open(struct inode *inode, struct file *file) static int raw_v4_seq_open(struct inode *inode, struct file *file)
{ {
return raw_seq_open(inode, file, &raw_v4_hashinfo, &raw_seq_ops); return seq_open_net(inode, file, &raw_seq_ops,
sizeof(struct raw_iter_state));
} }
static const struct file_operations raw_seq_fops = { static const struct file_operations raw_seq_fops = {
...@@ -1140,7 +1127,8 @@ static const struct file_operations raw_seq_fops = { ...@@ -1140,7 +1127,8 @@ static const struct file_operations raw_seq_fops = {
static __net_init int raw_init_net(struct net *net) static __net_init int raw_init_net(struct net *net)
{ {
if (!proc_create("raw", 0444, net->proc_net, &raw_seq_fops)) if (!proc_create_data("raw", 0444, net->proc_net, &raw_seq_fops,
&raw_v4_hashinfo))
return -ENOMEM; return -ENOMEM;
return 0; return 0;
......
...@@ -1306,7 +1306,8 @@ static const struct seq_operations raw6_seq_ops = { ...@@ -1306,7 +1306,8 @@ static const struct seq_operations raw6_seq_ops = {
static int raw6_seq_open(struct inode *inode, struct file *file) static int raw6_seq_open(struct inode *inode, struct file *file)
{ {
return raw_seq_open(inode, file, &raw_v6_hashinfo, &raw6_seq_ops); return seq_open_net(inode, file, &raw6_seq_ops,
sizeof(struct raw_iter_state));
} }
static const struct file_operations raw6_seq_fops = { static const struct file_operations raw6_seq_fops = {
...@@ -1318,7 +1319,8 @@ static const struct file_operations raw6_seq_fops = { ...@@ -1318,7 +1319,8 @@ static const struct file_operations raw6_seq_fops = {
static int __net_init raw6_init_net(struct net *net) static int __net_init raw6_init_net(struct net *net)
{ {
if (!proc_create("raw6", 0444, net->proc_net, &raw6_seq_fops)) if (!proc_create_data("raw6", 0444, net->proc_net, &raw6_seq_fops,
&raw_v6_hashinfo))
return -ENOMEM; return -ENOMEM;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment