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: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Christoph Hellwig 2018-04-10 22:08:28 +02:00
parent f455022166
commit 93cb5a1f58
3 changed files with 16 additions and 30 deletions

View File

@ -48,7 +48,6 @@ void raw_proc_exit(void);
struct raw_iter_state {
struct seq_net_private p;
int bucket;
struct raw_hashinfo *h;
};
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_next(struct seq_file *seq, void *v, loff_t *pos);
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
int raw_hash_sk(struct sock *sk);

View File

@ -1003,11 +1003,12 @@ struct proto raw_prot = {
static struct sock *raw_get_first(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);
for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
++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))
goto found;
}
@ -1018,6 +1019,7 @@ found:
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);
do {
@ -1027,7 +1029,7 @@ try_again:
} while (sk && sock_net(sk) != seq_file_net(seq));
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;
}
return sk;
@ -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)
{
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;
}
EXPORT_SYMBOL_GPL(raw_seq_start);
@ -1067,9 +1069,9 @@ EXPORT_SYMBOL_GPL(raw_seq_next);
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);
@ -1110,25 +1112,10 @@ static const struct seq_operations raw_seq_ops = {
.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)
{
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 = {
@ -1140,7 +1127,8 @@ static const struct file_operations raw_seq_fops = {
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 0;

View File

@ -1306,7 +1306,8 @@ static const struct seq_operations raw6_seq_ops = {
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 = {
@ -1318,7 +1319,8 @@ static const struct file_operations raw6_seq_fops = {
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 0;