All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: idryomov@gmail.com, amarkuze@redhat.com, xiubo.li@clyso.com,
	ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Max Kellermann <max.kellermann@ionos.com>
Subject: [PATCH] net/ceph/messenger: print TCP connect error
Date: Thu, 10 Sep 2026 14:39:50 +0200	[thread overview]
Message-ID: <20260910123951.1241279-1-max.kellermann@ionos.com> (raw)

A non-blocking connect() usually returns `-EINPROGRESS` and fails
later, asynchronously; the actual error is then only visible as
`sk->sk_err` in the sk_state_change() callback and was silently
dropped.  All the user got was:

 libceph: mon4 (1)192.168.1.42:6789 socket closed (con state V1_BANNER)

Save the error in the new field `ceph_connection.error_code` and let
con_fault() print it next to `error_msg`:

 libceph: mon4 (1)192.168.1.42:6789 socket closed (con state V1_BANNER) (-ECONNREFUSED)

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 include/linux/ceph/messenger.h |  1 +
 net/ceph/messenger.c           | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h
index 6aa4c6478c9f..f3aa977d7886 100644
--- a/include/linux/ceph/messenger.h
+++ b/include/linux/ceph/messenger.h
@@ -482,6 +482,7 @@ struct ceph_connection {
 
 	unsigned long flags;  /* CEPH_CON_F_* */
 	const char *error_msg;  /* error message, if any */
+	int error_code;  /* errno (negative), if any */
 
 	struct ceph_entity_name peer_name; /* peer name */
 	struct ceph_entity_addr peer_addr; /* peer address */
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 212e7797f9e4..f989e043686d 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -398,6 +398,7 @@ static void ceph_sock_state_change(struct sock *sk)
 	case TCP_CLOSE_WAIT:
 		dout("%s TCP_CLOSE_WAIT\n", __func__);
 		con_sock_state_closing(con);
+		WRITE_ONCE(con->error_code, -READ_ONCE(sk->sk_err));
 		ceph_con_flag_set(con, CEPH_CON_F_SOCK_CLOSED);
 		queue_con(con);
 		break;
@@ -448,8 +449,10 @@ int ceph_tcp_connect(struct ceph_connection *con)
 	ret = sock_create_kern(read_pnet(&con->msgr->net), ss.ss_family,
 			       SOCK_STREAM, IPPROTO_TCP, &sock);
 	memalloc_noio_restore(noio_flag);
-	if (ret)
+	if (ret) {
+		con->error_code = ret;
 		return ret;
+	}
 	sock->sk->sk_allocation = GFP_NOFS;
 	sock->sk->sk_use_task_frag = false;
 
@@ -467,9 +470,9 @@ int ceph_tcp_connect(struct ceph_connection *con)
 		     ceph_pr_addr(&con->peer_addr),
 		     sock->sk->sk_state);
 	} else if (ret < 0) {
-		pr_err("connect %s error %d\n",
-		       ceph_pr_addr(&con->peer_addr), ret);
 		sock_release(sock);
+		/* reported by con_fault() */
+		con->error_code = ret;
 		return ret;
 	}
 
@@ -501,6 +504,7 @@ int ceph_con_close_socket(struct ceph_connection *con)
 	 * shut the socket down.
 	 */
 	ceph_con_flag_clear(con, CEPH_CON_F_SOCK_CLOSED);
+	con->error_code = 0;
 
 	con_sock_state_closed(con);
 	return rc;
@@ -1613,12 +1617,21 @@ static void ceph_con_workfn(struct work_struct *work)
  */
 static void con_fault(struct ceph_connection *con)
 {
+	int error_code;
+
 	dout("fault %p state %d to peer %s\n",
 	     con, con->state, ceph_pr_addr(&con->peer_addr));
 
-	pr_warn("%s%lld %s %s\n", ENTITY_NAME(con->peer_name),
-		ceph_pr_addr(&con->peer_addr), con->error_msg);
+	error_code = READ_ONCE(con->error_code);
+	if (error_code)
+		pr_warn("%s%lld %s %s (%pe)\n", ENTITY_NAME(con->peer_name),
+			ceph_pr_addr(&con->peer_addr), con->error_msg,
+			ERR_PTR(error_code));
+	else
+		pr_warn("%s%lld %s %s\n", ENTITY_NAME(con->peer_name),
+			ceph_pr_addr(&con->peer_addr), con->error_msg);
 	con->error_msg = NULL;
+	con->error_code = 0;
 
 	WARN_ON(con->state == CEPH_CON_S_STANDBY ||
 		con->state == CEPH_CON_S_CLOSED);
-- 
2.47.3


             reply	other threads:[~2026-09-10 12:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 12:39 Max Kellermann [this message]
2026-09-22 11:15 ` net/ceph/messenger: print TCP connect error Alex Markuze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260910123951.1241279-1-max.kellermann@ionos.com \
    --to=max.kellermann@ionos.com \
    --cc=amarkuze@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiubo.li@clyso.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.