sctp: apply rhashtable api to sctp procfs

Traversal the transport rhashtable, get the association only once through
the condition assoc->peer.primary_path != transport.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Xin Long 2015-12-30 23:50:48 +08:00 committed by David S. Miller
parent 4f00878126
commit 39f66a7dce
1 changed files with 175 additions and 145 deletions

View File

@ -281,63 +281,114 @@ void sctp_eps_proc_exit(struct net *net)
remove_proc_entry("eps", net->sctp.proc_net_sctp); remove_proc_entry("eps", net->sctp.proc_net_sctp);
} }
struct sctp_ht_iter {
struct seq_net_private p;
struct rhashtable_iter hti;
};
static struct sctp_transport *sctp_transport_get_next(struct seq_file *seq)
{
struct sctp_ht_iter *iter = seq->private;
struct sctp_transport *t;
t = rhashtable_walk_next(&iter->hti);
for (; t; t = rhashtable_walk_next(&iter->hti)) {
if (IS_ERR(t)) {
if (PTR_ERR(t) == -EAGAIN)
continue;
break;
}
if (net_eq(sock_net(t->asoc->base.sk), seq_file_net(seq)) &&
t->asoc->peer.primary_path == t)
break;
}
return t;
}
static struct sctp_transport *sctp_transport_get_idx(struct seq_file *seq,
loff_t pos)
{
void *obj;
while (pos && (obj = sctp_transport_get_next(seq)) && !IS_ERR(obj))
pos--;
return obj;
}
static int sctp_transport_walk_start(struct seq_file *seq)
{
struct sctp_ht_iter *iter = seq->private;
int err;
err = rhashtable_walk_init(&sctp_transport_hashtable, &iter->hti);
if (err)
return err;
err = rhashtable_walk_start(&iter->hti);
return err == -EAGAIN ? 0 : err;
}
static void sctp_transport_walk_stop(struct seq_file *seq)
{
struct sctp_ht_iter *iter = seq->private;
rhashtable_walk_stop(&iter->hti);
rhashtable_walk_exit(&iter->hti);
}
static void *sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos) static void *sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
{ {
if (*pos >= sctp_assoc_hashsize) int err = sctp_transport_walk_start(seq);
return NULL;
if (*pos < 0) if (err)
*pos = 0; return ERR_PTR(err);
if (*pos == 0) return *pos ? sctp_transport_get_idx(seq, *pos) : SEQ_START_TOKEN;
seq_printf(seq, " ASSOC SOCK STY SST ST HBKT "
"ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
"RPORT LADDRS <-> RADDRS "
"HBINT INS OUTS MAXRT T1X T2X RTXC "
"wmema wmemq sndbuf rcvbuf\n");
return (void *)pos;
} }
static void sctp_assocs_seq_stop(struct seq_file *seq, void *v) static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
{ {
sctp_transport_walk_stop(seq);
} }
static void *sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos) static void *sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{ {
if (++*pos >= sctp_assoc_hashsize) ++*pos;
return NULL;
return pos; return sctp_transport_get_next(seq);
} }
/* Display sctp associations (/proc/net/sctp/assocs). */ /* Display sctp associations (/proc/net/sctp/assocs). */
static int sctp_assocs_seq_show(struct seq_file *seq, void *v) static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
{ {
struct sctp_hashbucket *head; struct sctp_transport *transport;
struct sctp_ep_common *epb;
struct sctp_association *assoc; struct sctp_association *assoc;
struct sctp_ep_common *epb;
struct sock *sk; struct sock *sk;
int hash = *(loff_t *)v;
if (hash >= sctp_assoc_hashsize) if (v == SEQ_START_TOKEN) {
return -ENOMEM; seq_printf(seq, " ASSOC SOCK STY SST ST HBKT "
"ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
"RPORT LADDRS <-> RADDRS "
"HBINT INS OUTS MAXRT T1X T2X RTXC "
"wmema wmemq sndbuf rcvbuf\n");
return 0;
}
head = &sctp_assoc_hashtable[hash]; transport = (struct sctp_transport *)v;
local_bh_disable(); assoc = transport->asoc;
read_lock(&head->lock); epb = &assoc->base;
sctp_for_each_hentry(epb, &head->chain) {
assoc = sctp_assoc(epb);
sk = epb->sk; sk = epb->sk;
if (!net_eq(sock_net(sk), seq_file_net(seq)))
continue;
seq_printf(seq, seq_printf(seq,
"%8pK %8pK %-3d %-3d %-2d %-4d " "%8pK %8pK %-3d %-3d %-2d %-4d "
"%4d %8d %8d %7u %5lu %-5d %5d ", "%4d %8d %8d %7u %5lu %-5d %5d ",
assoc, sk, sctp_sk(sk)->type, sk->sk_state, assoc, sk, sctp_sk(sk)->type, sk->sk_state,
assoc->state, hash, assoc->state, 0,
assoc->assoc_id, assoc->assoc_id,
assoc->sndbuf_used, assoc->sndbuf_used,
atomic_read(&assoc->rmem_alloc), atomic_read(&assoc->rmem_alloc),
@ -360,9 +411,6 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
sk->sk_sndbuf, sk->sk_sndbuf,
sk->sk_rcvbuf); sk->sk_rcvbuf);
seq_printf(seq, "\n"); seq_printf(seq, "\n");
}
read_unlock(&head->lock);
local_bh_enable();
return 0; return 0;
} }
@ -378,7 +426,7 @@ static const struct seq_operations sctp_assoc_ops = {
static int sctp_assocs_seq_open(struct inode *inode, struct file *file) static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
{ {
return seq_open_net(inode, file, &sctp_assoc_ops, return seq_open_net(inode, file, &sctp_assoc_ops,
sizeof(struct seq_net_private)); sizeof(struct sctp_ht_iter));
} }
static const struct file_operations sctp_assocs_seq_fops = { static const struct file_operations sctp_assocs_seq_fops = {
@ -409,61 +457,49 @@ void sctp_assocs_proc_exit(struct net *net)
static void *sctp_remaddr_seq_start(struct seq_file *seq, loff_t *pos) static void *sctp_remaddr_seq_start(struct seq_file *seq, loff_t *pos)
{ {
if (*pos >= sctp_assoc_hashsize) int err = sctp_transport_walk_start(seq);
return NULL;
if (*pos < 0) if (err)
*pos = 0; return ERR_PTR(err);
if (*pos == 0) return *pos ? sctp_transport_get_idx(seq, *pos) : SEQ_START_TOKEN;
seq_printf(seq, "ADDR ASSOC_ID HB_ACT RTO MAX_PATH_RTX "
"REM_ADDR_RTX START STATE\n");
return (void *)pos;
} }
static void *sctp_remaddr_seq_next(struct seq_file *seq, void *v, loff_t *pos) static void *sctp_remaddr_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{ {
if (++*pos >= sctp_assoc_hashsize) ++*pos;
return NULL;
return pos; return sctp_transport_get_next(seq);
} }
static void sctp_remaddr_seq_stop(struct seq_file *seq, void *v) static void sctp_remaddr_seq_stop(struct seq_file *seq, void *v)
{ {
sctp_transport_walk_stop(seq);
} }
static int sctp_remaddr_seq_show(struct seq_file *seq, void *v) static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
{ {
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_association *assoc; struct sctp_association *assoc;
struct sctp_transport *tsp; struct sctp_transport *tsp;
int hash = *(loff_t *)v;
if (hash >= sctp_assoc_hashsize) if (v == SEQ_START_TOKEN) {
return -ENOMEM; seq_printf(seq, "ADDR ASSOC_ID HB_ACT RTO MAX_PATH_RTX "
"REM_ADDR_RTX START STATE\n");
return 0;
}
tsp = (struct sctp_transport *)v;
assoc = tsp->asoc;
head = &sctp_assoc_hashtable[hash];
local_bh_disable();
read_lock(&head->lock);
rcu_read_lock();
sctp_for_each_hentry(epb, &head->chain) {
if (!net_eq(sock_net(epb->sk), seq_file_net(seq)))
continue;
assoc = sctp_assoc(epb);
list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list, list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list,
transports) { transports) {
if (tsp->dead) if (tsp->dead)
continue; continue;
/* /*
* The remote address (ADDR) * The remote address (ADDR)
*/ */
tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr); tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr);
seq_printf(seq, " "); seq_printf(seq, " ");
/* /*
* The association ID (ASSOC_ID) * The association ID (ASSOC_ID)
*/ */
@ -507,14 +543,8 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "\n"); seq_printf(seq, "\n");
} }
}
rcu_read_unlock();
read_unlock(&head->lock);
local_bh_enable();
return 0; return 0;
} }
static const struct seq_operations sctp_remaddr_ops = { static const struct seq_operations sctp_remaddr_ops = {
@ -533,7 +563,7 @@ void sctp_remaddr_proc_exit(struct net *net)
static int sctp_remaddr_seq_open(struct inode *inode, struct file *file) static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
{ {
return seq_open_net(inode, file, &sctp_remaddr_ops, return seq_open_net(inode, file, &sctp_remaddr_ops,
sizeof(struct seq_net_private)); sizeof(struct sctp_ht_iter));
} }
static const struct file_operations sctp_remaddr_seq_fops = { static const struct file_operations sctp_remaddr_seq_fops = {