[PATCH v2 1/7] libceph: don't back off exponentially on EADDRNOTAVAIL

From: Ionut Nechita

Date: Fri Nov 20 2026 - 02:36:22 EST


When kernel_connect() fails with EADDRNOTAVAIL, the error is local:
no route or no usable source address for the peer, and nothing was
sent on the wire. con_fault() nevertheless treats it like any other
failure and doubles con->delay up to MAX_DELAY_INTERVAL (15s), so once
the local condition clears the client may sit idle for up to 15s
before trying again.

Since a failed attempt costs nothing and never reaches the peer,
retry at a fixed 100ms instead. Track the condition in struct
ceph_connection so that it doesn't depend on which protocol (msgr1 or
msgr2) is in use, and rate-limit the message.

Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
include/linux/ceph/messenger.h | 7 +++++++
net/ceph/messenger.c | 15 ++++++++++++---
2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h
index 6aa4c6478c9f6..344496967b5c5 100644
--- a/include/linux/ceph/messenger.h
+++ b/include/linux/ceph/messenger.h
@@ -321,6 +321,12 @@ struct ceph_msg {
/* ceph connection fault delay defaults, for exponential backoff */
#define BASE_DELAY_INTERVAL (HZ / 4)
#define MAX_DELAY_INTERVAL (15 * HZ)
+/*
+ * Fixed retry delay used instead of exponential backoff when connect()
+ * fails locally with EADDRNOTAVAIL. Such an attempt never reaches the
+ * peer, so backing off protects nobody and only delays recovery.
+ */
+#define ADDRNOTAVAIL_DELAY msecs_to_jiffies(100)

struct ceph_connection_v1_info {
struct kvec out_kvec[8], /* sending header/footer data */
@@ -507,6 +513,7 @@ struct ceph_connection {

struct delayed_work work; /* send|recv work */
unsigned long delay; /* current delay interval */
+ bool addr_notavail; /* last connect() failed with EADDRNOTAVAIL */

union {
struct ceph_connection_v1_info v1;
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index cc7db8c61db37..3c893bc0f7d8b 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -467,8 +467,13 @@ 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);
+ if (ret == -EADDRNOTAVAIL)
+ pr_warn_ratelimited("connect %s: address not available, will retry\n",
+ ceph_pr_addr(&con->peer_addr));
+ else
+ pr_err("connect %s error %d\n",
+ ceph_pr_addr(&con->peer_addr), ret);
+ con->addr_notavail = ret == -EADDRNOTAVAIL;
sock_release(sock);
return ret;
}
@@ -477,6 +482,7 @@ int ceph_tcp_connect(struct ceph_connection *con)
tcp_sock_set_nodelay(sock->sk);

con->sock = sock;
+ con->addr_notavail = false;
return 0;
}

@@ -610,6 +616,7 @@ void ceph_con_open(struct ceph_connection *con,

memcpy(&con->peer_addr, addr, sizeof(*addr));
con->delay = 0; /* reset backoff memory */
+ con->addr_notavail = false;
mutex_unlock(&con->mutex);
queue_con(con);
}
@@ -1644,7 +1651,9 @@ static void con_fault(struct ceph_connection *con)
} else {
/* retry after a delay. */
con->state = CEPH_CON_S_PREOPEN;
- if (!con->delay) {
+ if (con->addr_notavail) {
+ con->delay = ADDRNOTAVAIL_DELAY;
+ } else if (!con->delay) {
con->delay = BASE_DELAY_INTERVAL;
} else if (con->delay < MAX_DELAY_INTERVAL) {
con->delay *= 2;
--
2.56.0