Commit c558246e authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

mptcp: add statistics for mptcp socket in use

Do the statistics of mptcp socket in use with sock_prot_inuse_add().
Therefore, we can get the count of used mptcp socket from
/proc/net/protocols:

& cat /proc/net/protocols
protocol  size sockets  memory press maxhdr  slab module     cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
MPTCPv6   2048      0       0   no       0   yes  kernel      y  n  y  y  y  y  y  y  y  y  y  y  n  n  n  y  y  y  n
MPTCP     1896      1       0   no       0   yes  kernel      y  n  y  y  y  y  y  y  y  y  y  y  n  n  n  y  y  y  n
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 294de909
...@@ -2891,6 +2891,12 @@ static __poll_t mptcp_check_readable(struct mptcp_sock *msk) ...@@ -2891,6 +2891,12 @@ static __poll_t mptcp_check_readable(struct mptcp_sock *msk)
return EPOLLIN | EPOLLRDNORM; return EPOLLIN | EPOLLRDNORM;
} }
static void mptcp_listen_inuse_dec(struct sock *sk)
{
if (inet_sk_state_load(sk) == TCP_LISTEN)
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
}
bool __mptcp_close(struct sock *sk, long timeout) bool __mptcp_close(struct sock *sk, long timeout)
{ {
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
...@@ -2900,6 +2906,7 @@ bool __mptcp_close(struct sock *sk, long timeout) ...@@ -2900,6 +2906,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
sk->sk_shutdown = SHUTDOWN_MASK; sk->sk_shutdown = SHUTDOWN_MASK;
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) { if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
mptcp_listen_inuse_dec(sk);
inet_sk_state_store(sk, TCP_CLOSE); inet_sk_state_store(sk, TCP_CLOSE);
goto cleanup; goto cleanup;
} }
...@@ -3000,6 +3007,7 @@ static int mptcp_disconnect(struct sock *sk, int flags) ...@@ -3000,6 +3007,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
if (msk->fastopening) if (msk->fastopening)
return 0; return 0;
mptcp_listen_inuse_dec(sk);
inet_sk_state_store(sk, TCP_CLOSE); inet_sk_state_store(sk, TCP_CLOSE);
mptcp_stop_timer(sk); mptcp_stop_timer(sk);
...@@ -3657,8 +3665,10 @@ static int mptcp_listen(struct socket *sock, int backlog) ...@@ -3657,8 +3665,10 @@ static int mptcp_listen(struct socket *sock, int backlog)
err = ssock->ops->listen(ssock, backlog); err = ssock->ops->listen(ssock, backlog);
inet_sk_state_store(sk, inet_sk_state_load(ssock->sk)); inet_sk_state_store(sk, inet_sk_state_load(ssock->sk));
if (!err) if (!err) {
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
mptcp_copy_inaddrs(sk, ssock->sk); mptcp_copy_inaddrs(sk, ssock->sk);
}
mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED); mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED);
......
...@@ -153,6 +153,7 @@ int mptcp_token_new_connect(struct sock *ssk) ...@@ -153,6 +153,7 @@ int mptcp_token_new_connect(struct sock *ssk)
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
struct mptcp_sock *msk = mptcp_sk(subflow->conn); struct mptcp_sock *msk = mptcp_sk(subflow->conn);
int retries = MPTCP_TOKEN_MAX_RETRIES; int retries = MPTCP_TOKEN_MAX_RETRIES;
struct sock *sk = subflow->conn;
struct token_bucket *bucket; struct token_bucket *bucket;
again: again:
...@@ -175,6 +176,7 @@ int mptcp_token_new_connect(struct sock *ssk) ...@@ -175,6 +176,7 @@ int mptcp_token_new_connect(struct sock *ssk)
__sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain); __sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain);
bucket->chain_len++; bucket->chain_len++;
spin_unlock_bh(&bucket->lock); spin_unlock_bh(&bucket->lock);
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
return 0; return 0;
} }
...@@ -190,8 +192,10 @@ void mptcp_token_accept(struct mptcp_subflow_request_sock *req, ...@@ -190,8 +192,10 @@ void mptcp_token_accept(struct mptcp_subflow_request_sock *req,
struct mptcp_sock *msk) struct mptcp_sock *msk)
{ {
struct mptcp_subflow_request_sock *pos; struct mptcp_subflow_request_sock *pos;
struct sock *sk = (struct sock *)msk;
struct token_bucket *bucket; struct token_bucket *bucket;
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
bucket = token_bucket(req->token); bucket = token_bucket(req->token);
spin_lock_bh(&bucket->lock); spin_lock_bh(&bucket->lock);
...@@ -370,12 +374,14 @@ void mptcp_token_destroy_request(struct request_sock *req) ...@@ -370,12 +374,14 @@ void mptcp_token_destroy_request(struct request_sock *req)
*/ */
void mptcp_token_destroy(struct mptcp_sock *msk) void mptcp_token_destroy(struct mptcp_sock *msk)
{ {
struct sock *sk = (struct sock *)msk;
struct token_bucket *bucket; struct token_bucket *bucket;
struct mptcp_sock *pos; struct mptcp_sock *pos;
if (sk_unhashed((struct sock *)msk)) if (sk_unhashed((struct sock *)msk))
return; return;
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
bucket = token_bucket(msk->token); bucket = token_bucket(msk->token);
spin_lock_bh(&bucket->lock); spin_lock_bh(&bucket->lock);
pos = __token_lookup_msk(bucket, msk->token); pos = __token_lookup_msk(bucket, msk->token);
......
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