diff mbox series

libceph: queue_con only if the sock is connected

Message ID tencent_BC846D74CA86E95DAC48E65686FEE6359C07@qq.com (mailing list archive)
State New, archived
Headers show
Series libceph: queue_con only if the sock is connected | expand

Commit Message

Chen Yuanrun Oct. 2, 2022, 8:16 a.m. UTC
tcp_sendmsg_locked will trigger sk->sk_write_space while the sock
is still connecting, if con try to write to a connecting sock,
sk->sk_write_space will be called again, which lead to a endless loop.

This will happen if the public network of the cluster is down, and
the cpu will be in high usage.

Signed-off-by: Chen Yuanrun <chen-yuanrun@foxmail.com>
---
  net/ceph/messenger.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index d3bb656308b4..eef5d4dfd1f1 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -367,7 +367,8 @@  static void ceph_sock_write_space(struct sock *sk)
       * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
       * and net/core/stream.c:sk_stream_write_space().
       */
-    if (ceph_con_flag_test(con, CEPH_CON_F_WRITE_PENDING)) {
+    if (ceph_con_flag_test(con, CEPH_CON_F_WRITE_PENDING) &&
+        atomic_read(&con->sock_state) == CON_SOCK_STATE_CONNECTED) {
          if (sk_stream_is_writeable(sk)) {
              dout("%s %p queueing write work\n", __func__, con);
              clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);