Commit ba8f48f7 authored by Paolo Abeni's avatar Paolo Abeni Committed by Jakub Kicinski

mptcp: introduce mptcp_schedule_work

remove some of code duplications an allow preventing
rescheduling on close.
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 77c3c956
...@@ -89,8 +89,7 @@ static bool mptcp_pm_schedule_work(struct mptcp_sock *msk, ...@@ -89,8 +89,7 @@ static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
return false; return false;
msk->pm.status |= BIT(new_status); msk->pm.status |= BIT(new_status);
if (schedule_work(&msk->work)) mptcp_schedule_work((struct sock *)msk);
sock_hold((struct sock *)msk);
return true; return true;
} }
......
...@@ -620,9 +620,8 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk) ...@@ -620,9 +620,8 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
* this is not a good place to change state. Let the workqueue * this is not a good place to change state. Let the workqueue
* do it. * do it.
*/ */
if (mptcp_pending_data_fin(sk, NULL) && if (mptcp_pending_data_fin(sk, NULL))
schedule_work(&msk->work)) mptcp_schedule_work(sk);
sock_hold(sk);
} }
spin_unlock_bh(&sk->sk_lock.slock); spin_unlock_bh(&sk->sk_lock.slock);
...@@ -699,23 +698,32 @@ static void mptcp_reset_timer(struct sock *sk) ...@@ -699,23 +698,32 @@ static void mptcp_reset_timer(struct sock *sk)
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, jiffies + tout); sk_reset_timer(sk, &icsk->icsk_retransmit_timer, jiffies + tout);
} }
bool mptcp_schedule_work(struct sock *sk)
{
if (inet_sk_state_load(sk) != TCP_CLOSE &&
schedule_work(&mptcp_sk(sk)->work)) {
/* each subflow already holds a reference to the sk, and the
* workqueue is invoked by a subflow, so sk can't go away here.
*/
sock_hold(sk);
return true;
}
return false;
}
void mptcp_data_acked(struct sock *sk) void mptcp_data_acked(struct sock *sk)
{ {
mptcp_reset_timer(sk); mptcp_reset_timer(sk);
if ((!test_bit(MPTCP_SEND_SPACE, &mptcp_sk(sk)->flags) || if ((!test_bit(MPTCP_SEND_SPACE, &mptcp_sk(sk)->flags) ||
(inet_sk_state_load(sk) != TCP_ESTABLISHED)) && (inet_sk_state_load(sk) != TCP_ESTABLISHED)))
schedule_work(&mptcp_sk(sk)->work)) mptcp_schedule_work(sk);
sock_hold(sk);
} }
void mptcp_subflow_eof(struct sock *sk) void mptcp_subflow_eof(struct sock *sk)
{ {
struct mptcp_sock *msk = mptcp_sk(sk); if (!test_and_set_bit(MPTCP_WORK_EOF, &mptcp_sk(sk)->flags))
mptcp_schedule_work(sk);
if (!test_and_set_bit(MPTCP_WORK_EOF, &msk->flags) &&
schedule_work(&msk->work))
sock_hold(sk);
} }
static void mptcp_check_for_eof(struct mptcp_sock *msk) static void mptcp_check_for_eof(struct mptcp_sock *msk)
...@@ -1620,8 +1628,7 @@ static void mptcp_retransmit_handler(struct sock *sk) ...@@ -1620,8 +1628,7 @@ static void mptcp_retransmit_handler(struct sock *sk)
mptcp_stop_timer(sk); mptcp_stop_timer(sk);
} else { } else {
set_bit(MPTCP_WORK_RTX, &msk->flags); set_bit(MPTCP_WORK_RTX, &msk->flags);
if (schedule_work(&msk->work)) mptcp_schedule_work(sk);
sock_hold(sk);
} }
} }
...@@ -2334,7 +2341,8 @@ static void mptcp_release_cb(struct sock *sk) ...@@ -2334,7 +2341,8 @@ static void mptcp_release_cb(struct sock *sk)
struct sock *ssk; struct sock *ssk;
ssk = mptcp_subflow_recv_lookup(msk); ssk = mptcp_subflow_recv_lookup(msk);
if (!ssk || !schedule_work(&msk->work)) if (!ssk || sk->sk_state == TCP_CLOSE ||
!schedule_work(&msk->work))
__sock_put(sk); __sock_put(sk);
} }
......
...@@ -408,6 +408,7 @@ static inline bool mptcp_is_fully_established(struct sock *sk) ...@@ -408,6 +408,7 @@ static inline bool mptcp_is_fully_established(struct sock *sk)
void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk); void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk);
void mptcp_data_ready(struct sock *sk, struct sock *ssk); void mptcp_data_ready(struct sock *sk, struct sock *ssk);
bool mptcp_finish_join(struct sock *sk); bool mptcp_finish_join(struct sock *sk);
bool mptcp_schedule_work(struct sock *sk);
void mptcp_data_acked(struct sock *sk); void mptcp_data_acked(struct sock *sk);
void mptcp_subflow_eof(struct sock *sk); void mptcp_subflow_eof(struct sock *sk);
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit); bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit);
......
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