Skip to contentSkip to conversation

ceph: don't unregister an MDS session before removing its caps

PATCH Superseded Max Kellermann 2 participants 2 messages Aug 24 – Aug 27 Ceph client

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ceph: don't unregister an MDS session before removing its caps

handle_session() removed the session from mdsc->sessions[] at the very top of CEPH_SESSION_CLOSE handling, before taking s_mutex. Between session unregistration and remove_session_caps(), the MDS rank has no registered session while the old session still owns all caps it was granted.

Any concurrent filesystem operation may walk into that and the next __do_request() call registers a new session for this rank. Once it is open and the MDS issues caps, ceph_fill_inode() calls ceph_add_cap(), which looks caps up by rank, not
by session identity, finding old caps linked to the old session.

The list_move_tail() call then moves the cap object to the new session, which is already a bad thing to do. Since it doesn't decrement old_session->s_nr_caps, this will quickly run into a BUG() instead of crashing:

kernel BUG at fs/ceph/mds_client.c:1959!

  Internal error: Oops - BUG: 00000000f2000800 [#1]  SMP
  [...]
  Workqueue: ceph-msgr ceph_con_workfn
  pstate: 20400009 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
  pc : remove_session_caps+0x2bc/0x2d8
  lr : remove_session_caps+0x74/0x2d8
  [...]
  Call trace:
   remove_session_caps+0x2bc/0x2d8 (P)
   mds_dispatch+0xf48/0x1b60
   ceph_con_process_message+0x74/0xa0
   ceph_con_v1_try_read+0x3a0/0x1510
   ceph_con_workfn+0x260/0x460
   process_one_work+0x168/0x3b8
   worker_thread+0x1bc/0x3a0
   kthread+0x118/0x1e0
   ret_from_fork+0x10/0x20

That's BUG_ON(session->s_nr_caps > 0).

I was able to reproduce this reliably by delaying the close and starting I/O during the delay.

This patch keeps the session registered with CEPH_MDS_SESSION_CLOSED. New requests will be put on the s_waiting list where they will be resumed on the new session.

---
v1->v2: skip CLOSED sessions in check_new_map()

---
 fs/ceph/caps.c       |  9 +++++++-
 fs/ceph/mds_client.c | 55 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 6 deletions(-)
fs/ceph/caps.c +8 -1
index d7283fb54cec..ad9609162c4a 100644
@@ -4195,7 +4195,14 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
 		}
 		new_cap = ceph_get_cap(mdsc, NULL);
 	} else {
-		WARN_ON(1);
+		/*
+		 * -EAGAIN means the target rank's session is
+		 * currently being closed; set target=-1, which drops
+		 * the exported cap - the MDS will reissue it for the
+		 * new session
+		 */
+		WARN_ON(tsession != ERR_PTR(-EAGAIN));
+
 		tsession = NULL;
 		target = -1;
 		mutex_lock(&session->s_mutex);
fs/ceph/mds_client.c +50 -5

88 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer
#1 lore raw

Hi Max,

NACK. Please send a v3.

1. fs/ceph/mds_client.c:5942: Address-change path overwrites CLOSED and reconnects a session CLOSE will purge Max, the CLOSED skip at the top of check_new_map() is a single
load under mdsc->mutex.
After retaking mdsc->mutex in the address-change block, if the
session is CLOSED, leave it alone (no ceph_con_close(), no
RESTARTING, no reconnect).
2. fs/ceph/mds_client.c:6016: Closed-session export targets can miss their only reconnect check_new_map() now skips any export-target rank whose registered
session is CEPH_MDS_SESSION_CLOSED.
When a registered session is only being kept alive for cap
teardown, do not just continue out of the reconnect path.

Signature · 1 line
Alex Markuze