mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
	"ionut.nechita@windriver.com" <ionut.nechita@windriver.com>
Cc: "idryomov@gmail.com" <idryomov@gmail.com>,
	Xiubo Li <xiubli@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"ionut_n2001@yahoo.com" <ionut_n2001@yahoo.com>
Subject: Re:  [PATCH v1 10/13] ceph: force mdsmap refresh on persistent MDS connection failures
Date: Thu, 12 Mar 2026 21:23:16 +0000	[thread overview]
Message-ID: <1c1893ddef801e4e637d4c31a51bd5294ace872d.camel@ibm.com> (raw)
In-Reply-To: <20260312081619.40854-11-ionut.nechita@windriver.com>

On Thu, 2026-03-12 at 10:16 +0200, Ionut Nechita (Wind River) wrote:
> From: Ionut Nechita <ionut.nechita@windriver.com>
> 
> During rolling upgrades in containerized environments (e.g.,
> rook-ceph in containerized environments), MDS daemons are restarted and
> may receive new IP addresses from the CNI plugin. The kernel CephFS
> client (libceph) maintains a cached mdsmap with the old MDS address
> and attempts to reconnect indefinitely.
> 
> The monitor client subscribes to mdsmap updates with
> start=current_epoch+1, expecting the monitor to push new maps.
> However, if the monitor connection was also disrupted during the
> upgrade (e.g., due to EADDRNOTAVAIL from IPv6 DAD), the subscription
> may not be properly re-established, leaving the client with a stale
> mdsmap.
> 
> This results in a deadlock:
> - The kernel client retries connecting to the old MDS address forever
> - The MDS connection has no .fault callback, so the MDS client is
>   never notified of persistent connection failures
> - The stale mdsmap is never refreshed because the client believes
>   its subscription is active
> - New pod mounts via CSI hang in ContainerCreating state
> - The rook-ceph upgrade cannot complete
> 
> Observed in production (kernel 6.12.0-1-rt-amd64,
> Ceph Reef 18.2.2->18.2.5 upgrade):
>   - mdsmap stuck at epoch 53 while cluster was at epoch 68
>   - MDS session state: hung
>   - monc showed: have mdsmap 53 want 54+
>   - MDS address changed from dead:beef::...eb75 to dead:beef::...bc76
>   - Client kept retrying on old address for 30+ minutes
> 
> Fix this by:
> 1. Adding a .fault callback to the MDS connection operations
>    (mds_con_ops) so the MDS client is notified when connections fail
> 2. Tracking consecutive connection failures per MDS session via a
>    new s_con_failures counter
> 3. When failures exceed MDS_CON_FAIL_REFRESH_MDSMAP (10 consecutive
>    failures, ~2.5-15 seconds depending on backoff), forcing a fresh
>    mdsmap subscription with start=0 to get the complete current map
> 4. Resetting the failure counter when a session message is
>    successfully received (in handle_session)
> 
> Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
> ---
>  fs/ceph/mds_client.c | 73 ++++++++++++++++++++++++++++++++++++++++++++
>  fs/ceph/mds_client.h |  2 ++
>  2 files changed, 75 insertions(+)
> 
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index ac86225595b5f..0e766880056c0 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -66,6 +66,12 @@ static void ceph_cap_release_work(struct work_struct *work);
>  static void ceph_cap_reclaim_work(struct work_struct *work);
>  
>  static const struct ceph_connection_operations mds_con_ops;
> +/*
> + * Number of consecutive MDS connection failures before forcing
> + * a fresh mdsmap subscription. This handles stale mdsmap scenarios
> + * during rolling upgrades where MDS addresses change.
> + */
> +#define MDS_CON_FAIL_REFRESH_MDSMAP	10

Why exactly 10? Any thoughts?

>  
>  
>  /*
> @@ -997,6 +1003,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
>  	s->s_mdsc = mdsc;
>  	s->s_mds = mds;
>  	s->s_state = CEPH_MDS_SESSION_NEW;
> +	s->s_con_failures = 0;
>  	mutex_init(&s->s_mutex);
>  
>  	ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr);
> @@ -4341,6 +4348,9 @@ static void handle_session(struct ceph_mds_session *session,
>  	      ceph_session_op_name(op), session,
>  	      ceph_session_state_name(session->s_state), seq);
>  
> +	/* Reset connection failure counter on successful session message */
> +	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);
> @@ -5427,6 +5437,22 @@ 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);

Do we need this message now?

> +
> +			/*
> +			 * Force a fresh mdsmap subscription when a session
> +			 * becomes hung. The MDS may have restarted with a
> +			 * new address during a rolling upgrade, and the
> +			 * connection may have entered STANDBY state (no
> +			 * .fault callback) rather than generating connect
> +			 * errors. Requesting mdsmap from epoch 0 ensures
> +			 * we get the current map with updated addresses.
> +			 */
> +			pr_warn_client(cl,
> +				"mds%d hung, requesting fresh mdsmap\n",
> +				s->s_mds);

Maybe, pr_info_client()?

> +			if (ceph_monc_want_map(&s->s_mdsc->fsc->client->monc,
> +					       CEPH_SUB_MDSMAP, 0, true))
> +				ceph_monc_renew_subs(&s->s_mdsc->fsc->client->monc);
>  		}
>  		break;
>  	case CEPH_MDS_SESSION_CLOSING:
> @@ -6528,12 +6554,59 @@ static int mds_check_message_signature(struct ceph_msg *msg)
>         return ceph_auth_check_message_signature(auth, msg);
>  }
>  
> +/*
> + * Handle MDS connection fault.
> + *
> + * Track consecutive connection failures and force a fresh mdsmap
> + * subscription when failures exceed the threshold. This handles the
> + * case where the MDS address has changed (e.g., during a rolling
> + * upgrade) but the client has a stale mdsmap and keeps retrying
> + * on the old address.
> + */
> +static void mds_fault(struct ceph_connection *con)
> +{
> +	struct ceph_mds_session *s = con->private;
> +	struct ceph_mds_client *mdsc = s->s_mdsc;
> +	struct ceph_client *cl = mdsc->fsc->client;
> +	int failures;

Why do you need failures local variable? You can use s->s_con_failures
everywhere.

> +
> +	failures = ++s->s_con_failures;
> +
> +	if (failures == MDS_CON_FAIL_REFRESH_MDSMAP) {

Why not simply failures >= MDS_CON_FAIL_REFRESH_MDSMAP?

> +		pr_warn_client(cl,
> +			"mds%d connection failed %d times, requesting fresh mdsmap\n",
> +			s->s_mds, failures);

Do we need this message in system log? Maybe, debug output instead?

> +
> +		/*
> +		 * Force a fresh mdsmap subscription by requesting from
> +		 * epoch 0. This ensures we get the complete current map
> +		 * with up-to-date MDS addresses, rather than waiting for
> +		 * an incremental update that may never arrive if our
> +		 * subscription was lost during a monitor reconnection.
> +		 */
> +		if (ceph_monc_want_map(&mdsc->fsc->client->monc,
> +				       CEPH_SUB_MDSMAP, 0, true))
> +			ceph_monc_renew_subs(&mdsc->fsc->client->monc);
> +	} else if (failures > MDS_CON_FAIL_REFRESH_MDSMAP &&
> +		   failures % MDS_CON_FAIL_REFRESH_MDSMAP == 0) {

I don't follow this arithmetics. Why do you need this case at all?

> +		/*
> +		 * Periodically retry the fresh mdsmap request in case
> +		 * the previous one was lost or the monitor was also
> +		 * temporarily unavailable.
> +		 */
> +		if (ceph_monc_want_map(&mdsc->fsc->client->monc,
> +				       CEPH_SUB_MDSMAP, 0, true))
> +			ceph_monc_renew_subs(&mdsc->fsc->client->monc);
> +	}
> +}
> +
>  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 695c5a9c94026..44585b1cb4485 100644
> --- a/fs/ceph/mds_client.h
> +++ b/fs/ceph/mds_client.h
> @@ -251,6 +251,8 @@ struct ceph_mds_session {
>  	struct list_head  s_waiting;  /* waiting requests */
>  	struct list_head  s_unsafe;   /* unsafe requests */
>  	struct xarray	  s_delegated_inos;
> +
> +	int		  s_con_failures; /* consecutive connection failures */

Why do you need int data type? The upper threshold is declared as 10. Why not
u8, then ?

Thanks,
Slava.

>  };
>  
>  /*

  reply	other threads:[~2026-03-12 21:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12  8:16 [PATCH v1 00/13] ceph/libceph: fix hung tasks and connection recovery during network disruptions Ionut Nechita (Wind River)
2026-03-12  8:16 ` [PATCH v1 01/13] libceph: handle EADDRNOTAVAIL more gracefully Ionut Nechita (Wind River)
2026-03-12 18:51   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 02/13] ceph: add timeout protection to ceph_mdsc_sync() path Ionut Nechita (Wind River)
2026-03-12 19:19   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 03/13] ceph: add timeout protection to ceph_osdc_sync() path Ionut Nechita (Wind River)
2026-03-12 19:26   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 04/13] ceph: fix race condition in cleanup_session_requests() Ionut Nechita (Wind River)
2026-03-12 19:32   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 05/13] ceph: add timeout protection to ceph_lock_wait_for_completion() Ionut Nechita (Wind River)
2026-03-12 19:38   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 06/13] ceph: set default timeout for MDS requests Ionut Nechita (Wind River)
2026-03-12 19:41   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 07/13] ceph: add timeout to caps wait in __ceph_get_caps() Ionut Nechita (Wind River)
2026-03-12 19:52   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 08/13] ceph: make ceph_start_io_write() killable Ionut Nechita (Wind River)
2026-03-12 20:02   ` Viacheslav Dubeyko
2026-03-12 20:45     ` Ionut Nechita (Wind River)
2026-03-13 18:28       ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 09/13] ceph: make remaining I/O lock functions killable Ionut Nechita (Wind River)
2026-03-12 20:05   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 10/13] ceph: force mdsmap refresh on persistent MDS connection failures Ionut Nechita (Wind River)
2026-03-12 21:23   ` Viacheslav Dubeyko [this message]
2026-03-12  8:16 ` [PATCH v1 11/13] libceph: reset source address on persistent EADDRNOTAVAIL Ionut Nechita (Wind River)
2026-03-12 21:39   ` Viacheslav Dubeyko
2026-03-12  8:16 ` [PATCH v1 12/13] libceph: force monitor reconnect " Ionut Nechita (Wind River)
2026-03-12  8:16 ` [PATCH v1 13/13] libceph: force host network namespace for kernel CephFS mounts Ionut Nechita (Wind River)
2026-03-16 15:28   ` Ilya Dryomov
2026-03-16 21:20     ` Ionut Nechita (Wind River)
2026-04-02 17:06       ` Ionut Nechita (Wind River)
2026-04-03 15:05         ` Ionut Nechita (Wind River)

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=1c1893ddef801e4e637d4c31a51bd5294ace872d.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=ionut.nechita@windriver.com \
    --cc=ionut_n2001@yahoo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiubli@redhat.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 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®