* [PATCH v5 1/2] ceph: Use unsigned types for snapshot split counts
@ 2026-12-02 4:50 Kaho Jiang
2026-12-02 4:50 ` [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker Kaho Jiang
0 siblings, 1 reply; 4+ messages in thread
From: Kaho Jiang @ 2026-12-02 4:50 UTC (permalink / raw)
To: Ilya Dryomov, Alex Markuze, Xiubo Li, Viacheslav Dubeyko
Cc: ceph-devel, linux-kernel, stable, co+408fcc361565713f, Kaho Jiang
ceph_handle_snap() stores the unsigned 32-bit split counts from the
message header in signed integers. Values with the high bit set become
negative and, on 64-bit systems, cause the subsequent pointer arithmetic
to move backwards before the message buffer.
BUG: KASAN: slab-out-of-bounds in ceph_update_snap_trace (fs/ceph/snap.c:815)
Read of size 8 at addr ffff888024f45478 by task kworker/1:3/2220
CPU: 1 UID: 0 PID: 2220 Comm: kworker/1:3 Not tainted 7.4.0-rc2-g7475ea8b5861 #1 PREEMPT(full)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: ceph-msgr ceph_con_workfn
Call Trace:
<TASK>
dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
ceph_update_snap_trace (fs/ceph/snap.c:815)
ceph_handle_snap (fs/ceph/snap.c:1057)
__pfx_ceph_update_snap_trace (./include/linux/list.h:172)
down_write (kernel/locking/rwsem.c:1350 kernel/locking/rwsem.c:1356 kernel/locking/rwsem.c:1632)
__pfx_down_write (kernel/locking/rwsem.c:602)
ceph_handle_snap (fs/ceph/snap.c:1158)
mds_dispatch (fs/ceph/mds_client.c:7298)
find_held_lock (kernel/locking/lockdep.c:5401)
ceph_con_process_message (net/ceph/messenger.c:1413)
ceph_con_process_message (net/ceph/messenger.c:1424)
ceph_con_in_msg_alloc (net/ceph/messenger.c:2094)
ceph_con_v1_try_read (net/ceph/messenger_v1.c:1434)
ceph_con_workfn (net/ceph/messenger.c:1576)
process_one_work (kernel/workqueue.c:3495)
worker_thread (kernel/workqueue.c:3578 kernel/workqueue.c:3659)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
</TASK>
Kernel Offset: disabled
Use u32 for both counts and validate both split arrays against the
remaining message buffer before advancing the decode pointer. Use
size_mul() to detect multiplication overflow on 32-bit systems, and
ceph_decode_skip_n() for checked skips in the non-split branch.
Fixes: 963b61eb041e ("ceph: snapshot management")
Cc: stable@vger.kernel.org
Reported-by: co+408fcc361565713f@bugs.sh
Assisted-by: LLM
Signed-off-by: Kaho Jiang <kj2864@nyu.edu>
---
fs/ceph/snap.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 54c022d1fd68..3a1b3beaacf5 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -1039,7 +1039,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
void *p = msg->front.iov_base;
void *e = p + msg->front.iov_len;
struct ceph_mds_snap_head *h;
- int num_split_inos, num_split_realms;
+ u32 num_split_inos, num_split_realms;
__le64 *split_inos = NULL, *split_realms = NULL;
int i;
int locked_rwsem = 0;
@@ -1076,8 +1076,10 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
* child.
*/
split_inos = p;
+ ceph_decode_need(&p, e, size_mul(num_split_inos, sizeof(u64)), bad);
p += sizeof(u64) * num_split_inos;
split_realms = p;
+ ceph_decode_need(&p, e, size_mul(num_split_realms, sizeof(u64)), bad);
p += sizeof(u64) * num_split_realms;
ceph_decode_need(&p, e, sizeof(*ri), bad);
/* we will peek at realm info here, but will _not_
@@ -1156,8 +1158,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
* positioned at the start of realm info, as expected by
* ceph_update_snap_trace().
*/
- p += sizeof(u64) * num_split_inos;
- p += sizeof(u64) * num_split_realms;
+ ceph_decode_skip_n(&p, e, size_mul(num_split_inos, sizeof(u64)), bad);
+ ceph_decode_skip_n(&p, e, size_mul(num_split_realms, sizeof(u64)), bad);
}
/*
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker
2026-12-02 4:50 [PATCH v5 1/2] ceph: Use unsigned types for snapshot split counts Kaho Jiang
@ 2026-12-02 4:50 ` Kaho Jiang
2026-12-02 15:13 ` Alex Markuze
2026-12-02 15:30 ` kernel test robot
0 siblings, 2 replies; 4+ messages in thread
From: Kaho Jiang @ 2026-12-02 4:50 UTC (permalink / raw)
To: Ilya Dryomov, Alex Markuze, Xiubo Li, Viacheslav Dubeyko
Cc: ceph-devel, linux-kernel, stable, co+408fcc361565713f, Kaho Jiang
On a malformed SPLIT the failure path calls ceph_monc_blocklist_add()
with snap_rwsem held, and then ceph_mdsc_close_sessions() from the MDS
connection worker that must deliver the SESSION_CLOSE reply it waits
for. With mount_timeout=0 the worker never processes the reply, so the
wait is indefinite.
Defer the blocklist (and its OSD map wait) and the fence to a work item
so the worker is never blocked. Keep the client fenced by setting
CEPH_MOUNT_FENCE_IO synchronously, then fail pending MDS requests and
drop each session's caps from the work item, as the force-umount path
does, without waiting for a close ack a blocklisted client can never
get. Also discard the target inode in handle_reply() when it is still
I_NEW, so a later cap lookup cannot block forever on it.
Fixes: a68e564adcaa ("ceph: blocklist the kclient when receiving corrupted snap trace")
Reported-by: co+408fcc361565713f@bugs.sh
Assisted-by: LLM
Signed-off-by: Kaho Jiang <kj2864@nyu.edu>
---
fs/ceph/caps.c | 2 +-
fs/ceph/mds_client.c | 41 ++++++++++++++++++++++++++++++++++++++++-
fs/ceph/mds_client.h | 3 +++
fs/ceph/snap.c | 33 ++++++++++-----------------------
4 files changed, 54 insertions(+), 25 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index cc8748f7e0bd..4e86c277ac00 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -4983,7 +4983,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,
/* Defer closing the sessions after s_mutex lock being released */
if (close_sessions)
- ceph_mdsc_close_sessions(mdsc);
+ ceph_mdsc_schedule_snap_fence(mdsc);
kfree(extra_info.fscrypt_auth);
return;
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3d3bd5e06a92..d6a2bb660a49 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -69,6 +69,7 @@ static void __wake_requests(struct ceph_mds_client *mdsc,
static void ceph_cap_release_work(struct work_struct *work);
static void ceph_cap_reclaim_work(struct work_struct *work);
static void ceph_mdsc_reset_workfn(struct work_struct *work);
+static void ceph_mdsc_snap_fence_workfn(struct work_struct *work);
static const struct ceph_connection_operations mds_con_ops;
@@ -4373,6 +4374,9 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
ceph_unreserve_caps(mdsc, &req->r_caps_reservation);
}
out_err:
+ if (req->r_target_inode && (req->r_target_inode->i_state & I_NEW))
+ discard_new_inode(req->r_target_inode);
+
mutex_lock(&mdsc->mutex);
if (!test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) {
if (err) {
@@ -4398,7 +4402,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
/* Defer closing the sessions after s_mutex lock being released */
if (close_sessions)
- ceph_mdsc_close_sessions(mdsc);
+ ceph_mdsc_schedule_snap_fence(mdsc);
return;
}
@@ -6515,6 +6519,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
init_waitqueue_head(&mdsc->reset_state.blocked_wq);
atomic_set(&mdsc->reset_state.blocked_requests, 0);
INIT_WORK(&mdsc->reset_work, ceph_mdsc_reset_workfn);
+ INIT_WORK(&mdsc->snap_fence_work, ceph_mdsc_snap_fence_workfn);
+ atomic_set(&mdsc->snap_fence_pending, 0);
ceph_caps_init(mdsc);
ceph_adjust_caps_max_min(mdsc, fsc->mount_options);
@@ -6909,6 +6915,38 @@ static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped)
return atomic_read(&mdsc->num_sessions) <= skipped;
}
+static void ceph_mdsc_snap_fence_workfn(struct work_struct *work)
+{
+ struct ceph_mds_client *mdsc =
+ container_of(work, struct ceph_mds_client, snap_fence_work);
+ struct ceph_client *cl = mdsc->fsc->client;
+ int ret;
+
+ ret = ceph_monc_blocklist_add(&cl->monc, &cl->msgr.inst.addr);
+ if (ret)
+ pr_err_client(cl, "failed to blocklist %s: %d\n",
+ ceph_pr_addr(&cl->msgr.inst.addr), ret);
+ else
+ pr_warn_ratelimited_client(cl,
+ "%s %s was blocklisted, do remount to continue after corrupted snaptrace is fixed\n",
+ __func__, ceph_pr_addr(&cl->msgr.inst.addr));
+
+ ceph_mdsc_force_umount(mdsc);
+ ceph_dec_osd_stopping_blocker(mdsc);
+}
+
+void ceph_mdsc_schedule_snap_fence(struct ceph_mds_client *mdsc)
+{
+ if (atomic_cmpxchg(&mdsc->snap_fence_pending, 0, 1))
+ return;
+
+ if (!ceph_inc_osd_stopping_blocker(mdsc))
+ return;
+
+ if (!queue_work(system_dfl_wq, &mdsc->snap_fence_work))
+ ceph_dec_osd_stopping_blocker(mdsc);
+}
+
/*
* called after sb is ro or when metadata corrupted.
*/
@@ -7067,6 +7105,7 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
wake_up_all(&mdsc->reset_state.blocked_wq);
cancel_work_sync(&mdsc->reset_work);
+ cancel_work_sync(&mdsc->snap_fence_work);
ceph_mdsc_stop(mdsc);
ceph_metric_destroy(&mdsc->metric);
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index ff9ba09f3b59..65d0fd878741 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -590,6 +590,8 @@ struct ceph_mds_client {
struct ceph_client_metric metric;
struct work_struct reset_work;
struct ceph_client_reset_state reset_state;
+ struct work_struct snap_fence_work;
+ atomic_t snap_fence_pending;
struct ceph_subvolume_metrics_tracker subvol_metrics;
/* Subvolume metrics send tracking */
@@ -633,6 +635,7 @@ int ceph_mdsc_wait_for_reset(struct ceph_mds_client *mdsc);
extern int ceph_mdsc_init(struct ceph_fs_client *fsc);
extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
+extern void ceph_mdsc_schedule_snap_fence(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);
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 3a1b3beaacf5..6bf6a74f76fa 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -796,11 +796,9 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
struct ceph_snap_realm *realm;
struct ceph_snap_realm *first_realm = NULL;
struct ceph_snap_realm *realm_to_rebuild = NULL;
- struct ceph_client *client = mdsc->fsc->client;
size_t snaps_len;
int rebuild_snapcs;
int err = -ENOMEM;
- int ret;
LIST_HEAD(dirty_realms);
lockdep_assert_held_write(&mdsc->snap_rwsem);
@@ -924,22 +922,8 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
* When receiving a corrupted snap trace we don't know what
* exactly has happened in MDS side. And we shouldn't continue
* writing to OSD, which may corrupt the snapshot contents.
- *
- * Just try to blocklist this kclient and then this kclient
- * must be remounted to continue after the corrupted metadata
- * fixed in the MDS side.
*/
WRITE_ONCE(mdsc->fsc->mount_state, CEPH_MOUNT_FENCE_IO);
- ret = ceph_monc_blocklist_add(&client->monc, &client->msgr.inst.addr);
- if (ret)
- pr_err_client(cl, "failed to blocklist %s: %d\n",
- ceph_pr_addr(&client->msgr.inst.addr), ret);
-
- pr_warn_ratelimited_client(cl, "%s %s%sdo remount to continue%s",
- __func__,
- ret ? "" : ceph_pr_addr(&client->msgr.inst.addr),
- ret ? "" : " was blocklisted, ",
- err == -EIO ? " after corrupted snaptrace is fixed" : "");
return err;
}
@@ -1050,7 +1034,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
/* decode */
if (msg->front.iov_len < sizeof(*h))
- goto bad;
+ goto fail;
h = p;
op = le32_to_cpu(h->op);
split = le64_to_cpu(h->split); /* non-zero if we are splitting an
@@ -1076,12 +1060,12 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
* child.
*/
split_inos = p;
- ceph_decode_need(&p, e, size_mul(num_split_inos, sizeof(u64)), bad);
+ ceph_decode_need(&p, e, size_mul(num_split_inos, sizeof(u64)), fail);
p += sizeof(u64) * num_split_inos;
split_realms = p;
- ceph_decode_need(&p, e, size_mul(num_split_realms, sizeof(u64)), bad);
+ ceph_decode_need(&p, e, size_mul(num_split_realms, sizeof(u64)), fail);
p += sizeof(u64) * num_split_realms;
- ceph_decode_need(&p, e, sizeof(*ri), bad);
+ ceph_decode_need(&p, e, sizeof(*ri), fail);
/* we will peek at realm info here, but will _not_
* advance p, as the realm update will occur below in
* ceph_update_snap_trace. */
@@ -1158,8 +1142,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
* positioned at the start of realm info, as expected by
* ceph_update_snap_trace().
*/
- ceph_decode_skip_n(&p, e, size_mul(num_split_inos, sizeof(u64)), bad);
- ceph_decode_skip_n(&p, e, size_mul(num_split_realms, sizeof(u64)), bad);
+ ceph_decode_skip_n(&p, e, size_mul(num_split_inos, sizeof(u64)), fail);
+ ceph_decode_skip_n(&p, e, size_mul(num_split_realms, sizeof(u64)), fail);
}
/*
@@ -1185,6 +1169,9 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
ceph_dec_mds_stopping_blocker(mdsc);
return;
+fail:
+ WRITE_ONCE(mdsc->fsc->mount_state, CEPH_MOUNT_FENCE_IO);
+ close_sessions = true;
bad:
pr_err_client(cl, "corrupt snap message from mds%d\n", mds);
ceph_msg_dump(msg);
@@ -1195,7 +1182,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
ceph_dec_mds_stopping_blocker(mdsc);
if (close_sessions)
- ceph_mdsc_close_sessions(mdsc);
+ ceph_mdsc_schedule_snap_fence(mdsc);
return;
}
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker
2026-12-02 4:50 ` [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker Kaho Jiang
@ 2026-12-02 15:13 ` Alex Markuze
2026-12-02 15:30 ` kernel test robot
1 sibling, 0 replies; 4+ messages in thread
From: Alex Markuze @ 2026-12-02 15:13 UTC (permalink / raw)
To: Kaho Jiang
Cc: Ilya Dryomov, Xiubo Li, Viacheslav Dubeyko, ceph-devel,
linux-kernel, stable, co+408fcc361565713f
Hi Kaho,
Thanks for splitting the bounds fix and moving the fence work off the MDS
worker. The deferred path still needs to keep the client fenced while it
handles the error and the blocklist operation.
On kernels where i_state is a struct inode_state_flags, the new I_NEW test
does not compile; inode_state_read_once() is the accessor used in this
tree. On a snap-trace failure, discard_new_inode() consumes the target
reference but leaves r_target_inode pointing to it. It also wakes waiters
while the incomplete inode is still hashed. iget_failed() marks the inode
bad, unhashes it before waking waiters, and puts it; it is a candidate for
a target still being initialized. The request's reference needs to be
detached safely, with the create, async-create and unsafe-request paths
retaining the references they need.
A direct writer can pass the shutdown check and wait for snap_rwsem while
the snap update fails. In try_get_cap_refs(), rechecking the fence after
taking snap_rwsem and before taking the cached context would stop that
waiter, provided mount and recovery cannot clear the fence. That check
alone does not cover writers that already have a context or queued I/O.
For a wider local gate, ceph_osdc_abort_requests() fails ordinary OSD
submissions after its abort latch is installed. Its placement in the
failure paths needs a lock-order check, and a writer can still enqueue
while the abort is waiting for the OSD-client lock. A wider gate needs
an ordering shared with submission and resend paths. The abort cannot
retract a write that has already reached an OSD.
One direction for mount and recovery is to keep the corruption state
sticky for the lifetime of the client, separate from whether fence work
is queued or running. A matching mount or an already-started clean
recovery must not make the corrupted client usable again. Coordinate
recovery with the worker so a nonce reset cannot make it blocklist a
replacement identity.
The monitor wait needs a bound on the version request as well as the map
wait: ceph_wait_for_latest_osdmap() calls ceph_monc_get_version() before
waiting for the map, and this call uses a zero map timeout.
wait_generic_request_timeout() may be useful for a bounded version-request
variant, with cancellation and late replies handled. Separating local MDS
request wakeups from the remote wait would let local cleanup progress;
sent and unsafe requests still need their completion and ownership rules.
Moving the whole ceph_mdsc_force_umount() earlier also requests session
closes and does not retract writes already sent to OSDs. A denied or timed-out
blocklist is not confirmation that the OSDs exclude those writes.
For testing, fail snap-trace allocation after allocating a new target
inode, with a concurrent I_NEW waiter, and check the inode's lifetime and
what the waiter receives. Pause a direct writer at snap_rwsem while failing
a snap-array allocation and check that it cannot submit the old context.
With a client allowed to blocklist, let the command succeed and then
withhold the version reply to check request and unmount progress.
Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker
2026-12-02 4:50 ` [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker Kaho Jiang
2026-12-02 15:13 ` Alex Markuze
@ 2026-12-02 15:30 ` kernel test robot
1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-12-02 15:30 UTC (permalink / raw)
To: Kaho Jiang, Ilya Dryomov, Alex Markuze, Xiubo Li, Viacheslav Dubeyko
Cc: oe-kbuild-all, ceph-devel, linux-kernel, stable,
co+408fcc361565713f, Kaho Jiang
Hi Kaho,
kernel test robot noticed the following build errors:
[auto build test ERROR on ceph-client/testing]
[cannot apply to ceph-client/for-linus linus/master v7.4-rc5 next-20261130]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kaho-Jiang/ceph-defer-the-blocklist-and-fence-off-the-MDS-worker/20261201-235041
base: https://github.com/ceph/ceph-client.git testing
patch link: https://lore.kernel.org/r/20261202045041.130195-2-kj2864%40nyu.edu
patch subject: [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261202/20261202232609.3qv8TXnG-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261202/20261202232609.3qv8TXnG-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261202232609.3qv8TXnG-lkp@intel.com/
All errors (new ones prefixed by >>):
fs/ceph/mds_client.c: In function 'handle_reply':
>> fs/ceph/mds_client.c:4377:66: error: invalid operands to binary & (have 'struct inode_state_flags' and 'int')
4377 | if (req->r_target_inode && (req->r_target_inode->i_state & I_NEW))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
| |
| struct inode_state_flags
vim +4377 fs/ceph/mds_client.c
4158
4159 /*
4160 * Handle mds reply.
4161 *
4162 * We take the session mutex and parse and process the reply immediately.
4163 * This preserves the logical ordering of replies, capabilities, etc., sent
4164 * by the MDS as they are applied to our local cache.
4165 */
4166 static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
4167 {
4168 struct ceph_mds_client *mdsc = session->s_mdsc;
4169 struct ceph_client *cl = mdsc->fsc->client;
4170 struct ceph_mds_request *req;
4171 struct ceph_mds_reply_head *head = msg->front.iov_base;
4172 struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */
4173 struct ceph_snap_realm *realm;
4174 unsigned int nofs_flags;
4175 struct dentry *lookup_dn;
4176 u64 tid;
4177 int err, result;
4178 int mds = session->s_mds;
4179 bool close_sessions = false;
4180
4181 if (msg->front.iov_len < sizeof(*head)) {
4182 pr_err_client(cl, "got corrupt (short) reply\n");
4183 ceph_msg_dump(msg);
4184 return;
4185 }
4186
4187 /* get request, session */
4188 tid = le64_to_cpu(msg->hdr.tid);
4189 mutex_lock(&mdsc->mutex);
4190 req = lookup_get_request(mdsc, tid);
4191 if (!req) {
4192 doutc(cl, "on unknown tid %llu\n", tid);
4193 mutex_unlock(&mdsc->mutex);
4194 return;
4195 }
4196 doutc(cl, "handle_reply %p\n", req);
4197
4198 /* correct session? */
4199 if (req->r_session != session) {
4200 pr_err_client(cl, "got %llu on session mds%d not mds%d\n",
4201 tid, session->s_mds,
4202 req->r_session ? req->r_session->s_mds : -1);
4203 mutex_unlock(&mdsc->mutex);
4204 goto out;
4205 }
4206
4207 /* dup? */
4208 if ((test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags) && !head->safe) ||
4209 (test_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags) && head->safe)) {
4210 pr_warn_client(cl, "got a dup %s reply on %llu from mds%d\n",
4211 head->safe ? "safe" : "unsafe", tid, mds);
4212 mutex_unlock(&mdsc->mutex);
4213 goto out;
4214 }
4215 if (test_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags)) {
4216 pr_warn_client(cl, "got unsafe after safe on %llu from mds%d\n",
4217 tid, mds);
4218 mutex_unlock(&mdsc->mutex);
4219 goto out;
4220 }
4221
4222 result = le32_to_cpu(head->result);
4223
4224 if (head->safe) {
4225 set_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags);
4226 __unregister_request(mdsc, req);
4227
4228 /* last request during umount? */
4229 if (mdsc->stopping && !__get_oldest_req(mdsc))
4230 complete_all(&mdsc->safe_umount_waiters);
4231
4232 if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) {
4233 /*
4234 * We already handled the unsafe response, now do the
4235 * cleanup. No need to examine the response; the MDS
4236 * doesn't include any result info in the safe
4237 * response. And even if it did, there is nothing
4238 * useful we could do with a revised return value.
4239 */
4240 doutc(cl, "got safe reply %llu, mds%d\n", tid, mds);
4241
4242 mutex_unlock(&mdsc->mutex);
4243 goto out;
4244 }
4245 } else {
4246 set_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags);
4247 list_add_tail(&req->r_unsafe_item, &req->r_session->s_unsafe);
4248 }
4249
4250 /*
4251 * Now that all mutex-protected state has been updated above
4252 * (the request has been unregistered or added to the
4253 * session's unsafe list), we can unlock it.
4254 */
4255 mutex_unlock(&mdsc->mutex);
4256
4257 doutc(cl, "tid %lld result %d\n", tid, result);
4258 if (test_bit(CEPHFS_FEATURE_REPLY_ENCODING, &session->s_features))
4259 err = parse_reply_info(session, msg, req, (u64)-1);
4260 else
4261 err = parse_reply_info(session, msg, req,
4262 session->s_con.peer_features);
4263
4264 /* Must find target inode outside of mutexes to avoid deadlocks */
4265 rinfo = &req->r_reply_info;
4266 if ((err >= 0) && rinfo->head->is_target) {
4267 struct inode *in = xchg(&req->r_new_inode, NULL);
4268 struct ceph_vino tvino = {
4269 .ino = le64_to_cpu(rinfo->targeti.in->ino),
4270 .snap = le64_to_cpu(rinfo->targeti.in->snapid)
4271 };
4272
4273 /*
4274 * If we ended up opening an existing inode, discard
4275 * r_new_inode
4276 */
4277 if (req->r_op == CEPH_MDS_OP_CREATE &&
4278 !req->r_reply_info.has_create_ino) {
4279 /* This should never happen on an async create */
4280 WARN_ON_ONCE(req->r_deleg_ino);
4281 iput(in);
4282 in = NULL;
4283 }
4284
4285 in = ceph_get_inode(mdsc->fsc->sb, tvino, in);
4286 if (IS_ERR(in)) {
4287 err = PTR_ERR(in);
4288 mutex_lock(&session->s_mutex);
4289 goto out_err;
4290 }
4291 req->r_target_inode = in;
4292 ceph_inode_set_subvolume(in, rinfo->targeti.subvolume_id);
4293 }
4294
4295 mutex_lock(&session->s_mutex);
4296 if (err < 0) {
4297 pr_err_client(cl, "got corrupt reply mds%d(tid:%lld)\n",
4298 mds, tid);
4299 ceph_msg_dump(msg);
4300 goto out_err;
4301 }
4302
4303 /* snap trace */
4304 realm = NULL;
4305 if (rinfo->snapblob_len) {
4306 down_write(&mdsc->snap_rwsem);
4307 err = ceph_update_snap_trace(mdsc, rinfo->snapblob,
4308 rinfo->snapblob + rinfo->snapblob_len,
4309 le32_to_cpu(head->op) == CEPH_MDS_OP_RMSNAP,
4310 &realm);
4311 if (err) {
4312 up_write(&mdsc->snap_rwsem);
4313 close_sessions = true;
4314 if (err == -EIO)
4315 ceph_msg_dump(msg);
4316 goto out_err;
4317 }
4318 downgrade_write(&mdsc->snap_rwsem);
4319 } else {
4320 down_read(&mdsc->snap_rwsem);
4321 }
4322
4323 /* insert trace into our cache */
4324 mutex_lock(&req->r_fill_mutex);
4325
4326 /*
4327 * ceph_fill_trace() may end the lookup of an in-lookup r_dentry
4328 * (d_splice_alias()), which lockdep sees as releasing its
4329 * DCACHE_PAR_LOOKUP lock: own it here meanwhile, see
4330 * ceph_mdsc_do_request(). splice_dentry() may replace r_dentry.
4331 */
4332 lookup_dn = NULL;
4333 if (test_bit(CEPH_MDS_R_LOOKUP_HANDOFF, &req->r_req_flags)) {
4334 lookup_dn = req->r_dentry;
4335 d_lookup_acquire(lookup_dn);
4336 }
4337
4338 /* disable fs reclaim while we are using current->journal_info
4339 * for our own purposes, or else shrinkers of other
4340 * filesystems might dereference this pointer as a different
4341 * type
4342 */
4343 nofs_flags = memalloc_nofs_save();
4344
4345 current->journal_info = req;
4346 err = ceph_fill_trace(mdsc->fsc->sb, req);
4347 if (err == 0) {
4348 if (result == 0 && (req->r_op == CEPH_MDS_OP_READDIR ||
4349 req->r_op == CEPH_MDS_OP_LSSNAP))
4350 err = ceph_readdir_prepopulate(req, req->r_session);
4351 }
4352 current->journal_info = NULL;
4353 memalloc_nofs_restore(nofs_flags);
4354
4355 if (lookup_dn)
4356 d_lookup_release(lookup_dn);
4357 mutex_unlock(&req->r_fill_mutex);
4358
4359 up_read(&mdsc->snap_rwsem);
4360 if (realm)
4361 ceph_put_snap_realm(mdsc, realm);
4362
4363 if (err == 0) {
4364 if (req->r_target_inode &&
4365 test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) {
4366 struct ceph_inode_info *ci =
4367 ceph_inode(req->r_target_inode);
4368 spin_lock(&ci->i_unsafe_lock);
4369 list_add_tail(&req->r_unsafe_target_item,
4370 &ci->i_unsafe_iops);
4371 spin_unlock(&ci->i_unsafe_lock);
4372 }
4373
4374 ceph_unreserve_caps(mdsc, &req->r_caps_reservation);
4375 }
4376 out_err:
> 4377 if (req->r_target_inode && (req->r_target_inode->i_state & I_NEW))
4378 discard_new_inode(req->r_target_inode);
4379
4380 mutex_lock(&mdsc->mutex);
4381 if (!test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) {
4382 if (err) {
4383 req->r_err = err;
4384 } else {
4385 req->r_reply = ceph_msg_get(msg);
4386 set_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags);
4387 }
4388 } else {
4389 doutc(cl, "reply arrived after request %lld was aborted\n", tid);
4390 }
4391 mutex_unlock(&mdsc->mutex);
4392
4393 mutex_unlock(&session->s_mutex);
4394
4395 /* kick calling process */
4396 complete_request(mdsc, req);
4397
4398 ceph_update_metadata_metrics(&mdsc->metric, req->r_start_latency,
4399 req->r_end_latency, err);
4400 out:
4401 ceph_mdsc_put_request(req);
4402
4403 /* Defer closing the sessions after s_mutex lock being released */
4404 if (close_sessions)
4405 ceph_mdsc_schedule_snap_fence(mdsc);
4406 return;
4407 }
4408
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 15:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 4:50 [PATCH v5 1/2] ceph: Use unsigned types for snapshot split counts Kaho Jiang
2026-12-02 4:50 ` [PATCH v5 2/2] ceph: defer the blocklist and fence off the MDS worker Kaho Jiang
2026-12-02 15:13 ` Alex Markuze
2026-12-02 15:30 ` kernel test robot
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®