mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption
@ 2026-11-23  8:01 Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 1/5] libceph: don't back off exponentially on EADDRNOTAVAIL Ionut Nechita
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

When the Ceph daemons become unreachable for a long time (seen during
Rook-Ceph rolling upgrades with active CephFS I/O), the kernel client
leaves sync(2) and syncfs(2) stuck in an unkillable D state, keeps
backing off on a purely local connect() error, and can miss the mdsmap
update that carries the new MDS address.

  1    libceph: fixed 100ms retry instead of exponential backoff when
       connect() fails locally with EADDRNOTAVAIL
  2-3  make the sync(2)/syncfs(2) waits in ceph_mdsc_sync() and
       ceph_osdc_sync() killable
  4    request a full mdsmap when an MDS keeps faulting or a session
       goes HUNG
  5    don't escalate the monitor hunt backoff on EADDRNOTAVAIL

Changes since v2 (thanks, Alex):
- 2/7 and 3/7 no longer bound the waits by mount_timeout, because
  sync(2) ignores the ->sync_fs() return value and would return with
  metadata still unsafe.  The waits are now killable instead: an
  un-killed sync still waits for everything, the task can be killed,
  and the hung task detector no longer fires.  The wait_caps_flush()
  diagnostic loop is kept.
- Dropped "ceph: bound the safe-completion wait in
  ceph_lock_wait_for_completion()".  That wait is already killable
  upstream, and a timeout can return before a lock grant is installed
  locally.
- Dropped "ceph: set default timeout for MDS requests" (Slava's
  Reviewed-by goes with it).  ceph_mdsc_wait_request() has been
  killable since aa91647c898d ("ceph: make mds requests killable, not
  interruptible"), so it doesn't trigger the hung task detector.  A
  default timeout would only turn MDS outages into -ETIMEDOUT for
  applications, and for file locks (the interrupt request as well as
  non-blocking F_SETLK) it can leave a lock granted on the MDS but not
  installed locally.
- Rebased on next-20261120.

Built with W=1 and sparse, and bisected build by build.  Not run
against a live cluster.

I used an LLM to help rebase the series, review the code and draft
the changelogs.  I have reviewed every change and take responsibility
for it.

v2: https://lore.kernel.org/all/20261120073431.53636-1-ionut.nechita@windriver.com/
v1: https://lore.kernel.org/all/20260312081619.40854-1-ionut.nechita@windriver.com/

Ionut Nechita (5):
  libceph: don't back off exponentially on EADDRNOTAVAIL
  ceph: make the ceph_mdsc_sync() waits killable
  ceph: make the ceph_osdc_sync() wait killable
  ceph: request a full mdsmap when an MDS stays unreachable
  libceph: don't escalate monitor hunt backoff on EADDRNOTAVAIL

 fs/ceph/mds_client.c            | 85 +++++++++++++++++++++++++++++----
 fs/ceph/mds_client.h            |  4 +-
 fs/ceph/super.c                 |  9 ++--
 include/linux/ceph/messenger.h  |  7 +++
 include/linux/ceph/osd_client.h |  2 +-
 net/ceph/messenger.c            | 15 ++++--
 net/ceph/mon_client.c           |  8 ++++
 net/ceph/osd_client.c           |  9 +++-
 8 files changed, 119 insertions(+), 20 deletions(-)


base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/5] libceph: don't back off exponentially on EADDRNOTAVAIL
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
@ 2026-11-23  8:01 ` Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 2/5] ceph: make the ceph_mdsc_sync() waits killable Ionut Nechita
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

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@windriver.com>
---
 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 2/5] ceph: make the ceph_mdsc_sync() waits killable
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 1/5] libceph: don't back off exponentially on EADDRNOTAVAIL Ionut Nechita
@ 2026-11-23  8:01 ` Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 3/5] ceph: make the ceph_osdc_sync() wait killable Ionut Nechita
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

When the MDS is unreachable, sync(2) and syncfs(2) wait in
ceph_mdsc_sync() in TASK_UNINTERRUPTIBLE with no way out:
flush_mdlog_and_wait_mdsc_unsafe_requests() waits for
r_safe_completion, and wait_caps_flush() waits for the cap flushes.
The task can't be killed and keeps tripping the hung task detector:

  INFO: task sync:514917 blocked for more than 983 seconds.
  Call Trace:
   ceph_mdsc_sync+0x4d6/0x5a0 [ceph]
   ceph_sync_fs+0x31/0x130 [ceph]
   iterate_supers+0x97/0x100
   ksys_sync+0x32/0xb0

Bounding these waits isn't an option: sync(2) ignores the ->sync_fs()
return value, so returning early would break its guarantee that
metadata is stable once it returns.

Make both waits killable instead, keeping the wait_caps_flush()
diagnostics, and propagate the error out of ceph_sync_fs().  A sync
that isn't killed still waits for everything to be flushed.

Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
---
 fs/ceph/mds_client.c | 37 +++++++++++++++++++++++++++----------
 fs/ceph/mds_client.h |  2 +-
 fs/ceph/super.c      |  5 +++--
 3 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3791fc627714c..f64a9c97cb882 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2522,9 +2522,10 @@ static void dump_cap_flushes(struct ceph_mds_client *mdsc, u64 want_tid)
 /*
  * Wait for all cap flushes through @want_flush_tid to complete.
  * Periodically dumps pending cap flush state for diagnostics.
+ * Returns 0, or -ERESTARTSYS if a fatal signal is pending.
  */
-static void wait_caps_flush(struct ceph_mds_client *mdsc,
-			    u64 want_flush_tid)
+static int wait_caps_flush(struct ceph_mds_client *mdsc,
+			   u64 want_flush_tid)
 {
 	struct ceph_client *cl = mdsc->fsc->client;
 	int i = 0;
@@ -2534,9 +2535,11 @@ static void wait_caps_flush(struct ceph_mds_client *mdsc,
 
 	do {
 		/* 60 * HZ fits in a long on all supported architectures. */
-		ret = wait_event_timeout(mdsc->cap_flushing_wq,
+		ret = wait_event_killable_timeout(mdsc->cap_flushing_wq,
 			   check_caps_flush(mdsc, want_flush_tid),
 			   CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC * HZ);
+		if (ret < 0)
+			return ret;
 		if (ret == 0) {
 			if (i < CEPH_CAP_FLUSH_MAX_DUMP_ITERS)
 				dump_cap_flushes(mdsc, want_flush_tid);
@@ -2548,6 +2551,7 @@ static void wait_caps_flush(struct ceph_mds_client *mdsc,
 	} while (ret == 0);
 
 	doutc(cl, "ok, flushed thru %llu\n", want_flush_tid);
+	return 0;
 }
 
 /*
@@ -6737,13 +6741,14 @@ void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
 /*
  * flush the mdlog and wait for all write mds requests to flush.
  */
-static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
-						 u64 want_tid)
+static int flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
+						      u64 want_tid)
 {
 	struct ceph_client *cl = mdsc->fsc->client;
 	struct ceph_mds_request *req = NULL, *nextreq;
 	struct ceph_mds_session *last_session = NULL;
 	struct rb_node *n;
+	int err;
 
 	mutex_lock(&mdsc->mutex);
 	doutc(cl, "want %lld\n", want_tid);
@@ -6782,7 +6787,14 @@ static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *md
 			}
 			doutc(cl, "wait on %llu (want %llu)\n",
 			      req->r_tid, want_tid);
-			wait_for_completion(&req->r_safe_completion);
+			err = wait_for_completion_killable(&req->r_safe_completion);
+			if (err) {
+				ceph_mdsc_put_request(req);
+				if (nextreq)
+					ceph_mdsc_put_request(nextreq);
+				ceph_put_mds_session(last_session);
+				return err;
+			}
 
 			mutex_lock(&mdsc->mutex);
 			ceph_mdsc_put_request(req);
@@ -6800,15 +6812,17 @@ static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *md
 	mutex_unlock(&mdsc->mutex);
 	ceph_put_mds_session(last_session);
 	doutc(cl, "done\n");
+	return 0;
 }
 
-void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
+int ceph_mdsc_sync(struct ceph_mds_client *mdsc)
 {
 	struct ceph_client *cl = mdsc->fsc->client;
 	u64 want_tid, want_flush;
+	int ret;
 
 	if (READ_ONCE(mdsc->fsc->mount_state) >= CEPH_MOUNT_SHUTDOWN)
-		return;
+		return 0;
 
 	doutc(cl, "sync\n");
 	mutex_lock(&mdsc->mutex);
@@ -6829,8 +6843,11 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
 
 	doutc(cl, "sync want tid %lld flush_seq %lld\n", want_tid, want_flush);
 
-	flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
-	wait_caps_flush(mdsc, want_flush);
+	ret = flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
+	if (ret)
+		return ret;
+
+	return wait_caps_flush(mdsc, want_flush);
 }
 
 /*
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 4749438d94e1f..31abbb3b3bdb3 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -635,7 +635,7 @@ extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
 extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
 extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
 
-extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
+extern int ceph_mdsc_sync(struct ceph_mds_client *mdsc);
 
 extern void ceph_invalidate_dir_request(struct ceph_mds_request *req);
 extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 7b5ef76e430d7..7936b76aa3cc0 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
 	struct ceph_client *cl = fsc->client;
+	int ret;
 
 	if (!wait) {
 		doutc(cl, "(non-blocking)\n");
@@ -137,9 +138,9 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
 
 	doutc(cl, "(blocking)\n");
 	ceph_osdc_sync(&fsc->client->osdc);
-	ceph_mdsc_sync(fsc->mdsc);
+	ret = ceph_mdsc_sync(fsc->mdsc);
 	doutc(cl, "(blocking) done\n");
-	return 0;
+	return ret;
 }
 
 /*
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 3/5] ceph: make the ceph_osdc_sync() wait killable
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 1/5] libceph: don't back off exponentially on EADDRNOTAVAIL Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 2/5] ceph: make the ceph_mdsc_sync() waits killable Ionut Nechita
@ 2026-11-23  8:01 ` Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 4/5] ceph: request a full mdsmap when an MDS stays unreachable Ionut Nechita
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

ceph_sync_fs() calls ceph_osdc_sync() before ceph_mdsc_sync(), and
ceph_osdc_sync() waits for every in-flight write with a plain
wait_for_completion().  With an OSD unreachable, sync(2) hangs there
in TASK_UNINTERRUPTIBLE:

  ceph_osdc_sync [libceph]
  ceph_sync_fs [ceph]
  iterate_supers
  ksys_sync

Make the wait killable like the MDS side and propagate the error.
The requests are not cancelled, and a sync that isn't killed still
waits for all of them.

Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
---
 fs/ceph/super.c                 | 4 +++-
 include/linux/ceph/osd_client.h | 2 +-
 net/ceph/osd_client.c           | 9 +++++++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 7936b76aa3cc0..166f6eb21f0af 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -137,7 +137,9 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
 	}
 
 	doutc(cl, "(blocking)\n");
-	ceph_osdc_sync(&fsc->client->osdc);
+	ret = ceph_osdc_sync(&fsc->client->osdc);
+	if (ret)
+		return ret;
 	ret = ceph_mdsc_sync(fsc->mdsc);
 	doutc(cl, "(blocking) done\n");
 	return ret;
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 7349ca09a227a..674dd9221d657 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -579,7 +579,7 @@ void ceph_osdc_start_request(struct ceph_osd_client *osdc,
 extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
 				  struct ceph_osd_request *req);
-extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
+extern int ceph_osdc_sync(struct ceph_osd_client *osdc);
 
 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
 void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 4479ec7a932b3..ff82aa16b5f52 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -4715,11 +4715,13 @@ EXPORT_SYMBOL(ceph_osdc_wait_request);
 
 /*
  * sync - wait for all in-flight requests to flush.  avoid starvation.
+ * Returns 0, or -ERESTARTSYS if a fatal signal is pending.
  */
-void ceph_osdc_sync(struct ceph_osd_client *osdc)
+int ceph_osdc_sync(struct ceph_osd_client *osdc)
 {
 	struct rb_node *n, *p;
 	u64 last_tid = atomic64_read(&osdc->last_tid);
+	int ret;
 
 again:
 	down_read(&osdc->lock);
@@ -4742,8 +4744,10 @@ void ceph_osdc_sync(struct ceph_osd_client *osdc)
 			up_read(&osdc->lock);
 			dout("%s waiting on req %p tid %llu last_tid %llu\n",
 			     __func__, req, req->r_tid, last_tid);
-			wait_for_completion(&req->r_completion);
+			ret = wait_for_completion_killable(&req->r_completion);
 			ceph_osdc_put_request(req);
+			if (ret)
+				return ret;
 			goto again;
 		}
 
@@ -4752,6 +4756,7 @@ void ceph_osdc_sync(struct ceph_osd_client *osdc)
 
 	up_read(&osdc->lock);
 	dout("%s done last_tid %llu\n", __func__, last_tid);
+	return 0;
 }
 EXPORT_SYMBOL(ceph_osdc_sync);
 
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 4/5] ceph: request a full mdsmap when an MDS stays unreachable
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
                   ` (2 preceding siblings ...)
  2026-11-23  8:01 ` [PATCH v3 3/5] ceph: make the ceph_osdc_sync() wait killable Ionut Nechita
@ 2026-11-23  8:01 ` Ionut Nechita
  2026-11-23  8:01 ` [PATCH v3 5/5] libceph: don't escalate monitor hunt backoff on EADDRNOTAVAIL Ionut Nechita
  2026-11-24 13:54 ` [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Alex Markuze
  5 siblings, 0 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

The client subscribes to incremental mdsmap updates starting at
current_epoch + 1.  If an MDS restarts at a different address while
the monitor session is also down (e.g. during a rolling upgrade in a
containerized deployment), the client can miss that update and keep
reconnecting to the stale address indefinitely.  This was observed
with the mdsmap stuck at epoch 53 while the cluster was at epoch 68,
the session HUNG and monc reporting "have mdsmap 53 want 54+".

Nothing currently reacts to this: mds_con_ops has no .fault callback,
and a session going HUNG doesn't touch the subscription either.

Add a .fault callback that asks for a full mdsmap (start epoch 0) on
every MDS_CON_FAIL_REFRESH_MDSMAP consecutive faults, resetting the
count on any session message, and do the same when a session is
marked HUNG, which covers a connection that went to STANDBY and thus
never faults.

Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
---
 fs/ceph/mds_client.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
 fs/ceph/mds_client.h |  2 ++
 2 files changed, 50 insertions(+)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index f64a9c97cb882..0338c7feec108 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -72,6 +72,13 @@ static void ceph_mdsc_reset_workfn(struct work_struct *work);
 
 static const struct ceph_connection_operations mds_con_ops;
 
+/*
+ * Consecutive MDS connection faults after which we ask the monitor for
+ * a full mdsmap.  With the messenger backoff (250ms doubling up to 15s)
+ * ten faults take about a minute, comparable to mount_timeout.
+ */
+#define MDS_CON_FAIL_REFRESH_MDSMAP	10
+
 static void ceph_metric_bind_session(struct ceph_mds_client *mdsc,
 				     struct ceph_mds_session *session)
 {
@@ -4632,6 +4639,9 @@ static void handle_session(struct ceph_mds_session *session,
 	      ceph_session_op_name(op), session,
 	      ceph_session_state_name(session->s_state), seq);
 
+	/* the connection works, see mds_fault() */
+	session->s_con_failures = 0;
+
 	if (session->s_state == CEPH_MDS_SESSION_HUNG) {
 		session->s_state = CEPH_MDS_SESSION_OPEN;
 		pr_info_client(cl, "mds%d came back\n", session->s_mds);
@@ -6266,6 +6276,18 @@ static void maybe_recover_session(struct ceph_mds_client *mdsc)
 	ceph_force_reconnect(fsc->sb);
 }
 
+/*
+ * Subscribe to the mdsmap from epoch 0 so that the monitor sends the
+ * current full map rather than waiting for an incremental update.
+ */
+static void request_full_mdsmap(struct ceph_mds_client *mdsc)
+{
+	struct ceph_mon_client *monc = &mdsc->fsc->client->monc;
+
+	if (ceph_monc_want_map(monc, CEPH_SUB_MDSMAP, 0, true))
+		ceph_monc_renew_subs(monc);
+}
+
 bool check_session_state(struct ceph_mds_session *s)
 {
 	struct ceph_client *cl = s->s_mdsc->fsc->client;
@@ -6275,6 +6297,12 @@ bool check_session_state(struct ceph_mds_session *s)
 		if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
 			s->s_state = CEPH_MDS_SESSION_HUNG;
 			pr_info_client(cl, "mds%d hung\n", s->s_mds);
+			/*
+			 * The MDS may have come back at a different
+			 * address while the connection sat in STANDBY,
+			 * which doesn't fault.
+			 */
+			request_full_mdsmap(s->s_mdsc);
 		}
 		break;
 	case CEPH_MDS_SESSION_CLOSING:
@@ -7499,12 +7527,32 @@ static int mds_check_message_signature(struct ceph_msg *msg)
        return ceph_auth_check_message_signature(auth, msg);
 }
 
+/*
+ * If the MDS keeps failing to connect, our mdsmap may be stale (e.g. the
+ * MDS restarted at a different address and the incremental update was
+ * missed while the monitor session was down).  Periodically ask for a
+ * full map.
+ */
+static void mds_fault(struct ceph_connection *con)
+{
+	struct ceph_mds_session *s = con->private;
+
+	if (++s->s_con_failures < MDS_CON_FAIL_REFRESH_MDSMAP)
+		return;
+
+	s->s_con_failures = 0;
+	doutc(s->s_mdsc->fsc->client,
+	      "mds%d keeps faulting, requesting full mdsmap\n", s->s_mds);
+	request_full_mdsmap(s->s_mdsc);
+}
+
 static const struct ceph_connection_operations mds_con_ops = {
 	.get = mds_get_con,
 	.put = mds_put_con,
 	.alloc_msg = mds_alloc_msg,
 	.dispatch = mds_dispatch,
 	.peer_reset = mds_peer_reset,
+	.fault = mds_fault,
 	.get_authorizer = mds_get_authorizer,
 	.add_authorizer_challenge = mds_add_authorizer_challenge,
 	.verify_authorizer_reply = mds_verify_authorizer_reply,
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 31abbb3b3bdb3..46e13446afcc7 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -301,6 +301,8 @@ struct ceph_mds_session {
 	struct list_head  s_unsafe;   /* unsafe requests */
 	struct xarray	  s_delegated_inos;
 	atomic_t	  s_num_deleg_inos;
+
+	u8		  s_con_failures; /* consecutive connection faults */
 };
 
 /*
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 5/5] libceph: don't escalate monitor hunt backoff on EADDRNOTAVAIL
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
                   ` (3 preceding siblings ...)
  2026-11-23  8:01 ` [PATCH v3 4/5] ceph: request a full mdsmap when an MDS stays unreachable Ionut Nechita
@ 2026-11-23  8:01 ` Ionut Nechita
  2026-11-24 13:54 ` [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Alex Markuze
  5 siblings, 0 replies; 7+ messages in thread
From: Ionut Nechita @ 2026-11-23  8:01 UTC (permalink / raw)
  To: ceph-devel
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	Viacheslav Dubeyko, Xiubo Li, Sebastian Andrzej Siewior,
	linux-kernel

While hunting, every reopen_session() doubles hunt_mult up to
CEPH_MONC_HUNT_MAX_MULT, so the client ends up spending 30s on each
monitor before moving to the next one.  The backoff is there to avoid
hammering monitors, but when connect() fails locally with
EADDRNOTAVAIL nothing reaches the monitor and another monitor may
well be routable.

Reset hunt_mult when the monitor connection faults with
EADDRNOTAVAIL so that hunting keeps going at the base interval.

Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
---
 net/ceph/mon_client.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index 2f0181b2566dc..bceeaa3690145 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -1568,6 +1568,14 @@ static void mon_fault(struct ceph_connection *con)
 			__schedule_delayed(monc);
 		} else {
 			dout("%s already hunting\n", __func__);
+			/*
+			 * A local EADDRNOTAVAIL never reached the
+			 * monitor, so there is nothing to back off from.
+			 * Keep moving on to the next monitor at the
+			 * base hunt interval.
+			 */
+			if (con->addr_notavail)
+				monc->hunt_mult = 1;
 		}
 	}
 	mutex_unlock(&monc->mutex);
-- 
2.56.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption
  2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
                   ` (4 preceding siblings ...)
  2026-11-23  8:01 ` [PATCH v3 5/5] libceph: don't escalate monitor hunt backoff on EADDRNOTAVAIL Ionut Nechita
@ 2026-11-24 13:54 ` Alex Markuze
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Markuze @ 2026-11-24 13:54 UTC (permalink / raw)
  To: Ionut Nechita
  Cc: ceph-devel, Ilya Dryomov, Viacheslav Dubeyko, Viacheslav Dubeyko,
	Xiubo Li, Sebastian Andrzej Siewior, linux-kernel

Hi Ionut,

A normal final unmount calls sync_filesystem() from ceph_kill_sb(),
but ignores its return. If SIGKILL interrupts the new killable cap
flush wait while the MDS is unreachable, teardown can continue without
the flush being acknowledged. If the update never reaches the MDS and
the outage lasts through session close, the client can purge the flush,
losing a previously successful cached xattr update.

Please keep the OSD-then-MDS sync waits uninterruptible during normal
superblock teardown, including both sync_filesystem() calls. Keep the
sync()/syncfs() waits killable outside teardown and preserve the
existing forced-unmount abort behavior.

Thanks,
Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-24 13:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23  8:01 [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Ionut Nechita
2026-11-23  8:01 ` [PATCH v3 1/5] libceph: don't back off exponentially on EADDRNOTAVAIL Ionut Nechita
2026-11-23  8:01 ` [PATCH v3 2/5] ceph: make the ceph_mdsc_sync() waits killable Ionut Nechita
2026-11-23  8:01 ` [PATCH v3 3/5] ceph: make the ceph_osdc_sync() wait killable Ionut Nechita
2026-11-23  8:01 ` [PATCH v3 4/5] ceph: request a full mdsmap when an MDS stays unreachable Ionut Nechita
2026-11-23  8:01 ` [PATCH v3 5/5] libceph: don't escalate monitor hunt backoff on EADDRNOTAVAIL Ionut Nechita
2026-11-24 13:54 ` [PATCH v3 0/5] ceph/libceph: killable sync waits and faster recovery after network disruption Alex Markuze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®