Skip to content

mds: Fix deadlock in file_blockdiff - #67969

Merged
vshankar merged 1 commit into
ceph:mainfrom
kotreshhr:mds-fileblockdiff-hang
Aug 31, 2026
Merged

vshankar merged 1 commit into
ceph:mainfrom
kotreshhr:mds-fileblockdiff-hang

Conversation

@kotreshhr

@kotreshhr kotreshhr commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

The MDCache::file_blockdiff can deadlock
itself with the mds_lock.

The MDSDaemon::ms_dispatch2 takes the mds_lock
and MDCache::file_blockdiff tries to acquire
same lock while finishing it's context synchronously
at gather_ctx.activate()

The fix is to call finish() directly in synchronous case and
use a noop gather finisher only to tear down the gather.

Following is the traceback

-----------------------------
(gdb) bt
0  0x0000ffff7da4656c in __futex_abstimed_wait_cancelable64 () from /lib64/libc.so.6 
1  0x0000ffff7da48ff0 [PAC] in pthread_cond_wait@@GLIBC_2.17 () from /lib64/libc.so.6 
2  0x0000ffff7efe0380 [PAC] in ceph::condition_variable_debug::wait (this=this@entry=0xaaaace348018, lock=...) at /lsandbox/upstream/ceph/src/common/mutex_debug.h:153 
3  0x0000aaaaaf698b70 in ceph::condition_variable_debug::wait<ceph::fair_mutex::lock()::{lambda()#1}>(std::unique_lock<ceph::mutex_debug_detail::mutex_debug_impl<false> >&, ceph::fair_mutex::lock()::{lambda()#1}) (
   this=0xaaaace348018, lock=..., pred=...) at /lsandbox/upstream/ceph/src/common/condition_variable_debug.h:34
4  ceph::fair_mutex::lock (this=this@entry=0xaaaace348010) at /lsandbox/upstream/ceph/src/common/fair_mutex.h:28 5  0x0000aaaaaf9d71a0 in std::lock_guard<ceph::fair_mutex>::lock_guard (this=0xffff786cb760, __m=...) at /usr/include/c++/14/bits/std_mutex.h:250
 6  MDSIOContextBase::complete (this=0xaaaadd1f3800, r=0) at /lsandbox/upstream/ceph/src/mds/MDSContext.cc:102 
7  0x0000aaaaaf6f00a0 in C_GatherBase<MDSContext, C_MDSInternalNoop>::delete_me (this=this@entry=0xaaaadd167450) at /lsandbox/upstream/ceph/src/include/Context.h:351 
8  0x0000aaaaaf6f0114 in C_GatherBase<MDSContext, C_MDSInternalNoop>::activate (this=0xaaaadd167450) at /lsandbox/upstream/ceph/src/include/Context.h:401 
9  0x0000aaaaaf6f016c in C_GatherBuilderBase<MDSContext, C_GatherBase<MDSContext, C_MDSInternalNoop> >::activate (this=this@entry=0xffff786cb898) at /lsandbox/upstream/ceph/src/include/Context.h:490 
10 0x0000aaaaaf83ac5c in MDCache::file_blockdiff (this=0xaaaace3f4000, in1=in1@entry=0xaaaadcc12680, in2=in2@entry=0xaaaad386cc00, block_diff=block_diff@entry=0xaaaadf0b0a30, max_objects=<optimized out>,
   max_objects@entry=16, ctx=ctx@entry=0xaaaadf0b0a10) at /lsandbox/upstream/ceph/src/mds/MDCache.cc:14933
11 0x0000aaaaaf78afa0 in Server::handle_client_file_blockdiff (this=this@entry=0xaaaad30f9d40, mdr=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:12619 
12 0x0000aaaaaf79ed08 in Server::dispatch_client_request (this=this@entry=0xaaaad30f9d40, mdr=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:2942 
13 0x0000aaaaaf79fbc4 in Server::handle_client_request (this=this@entry=0xaaaad30f9d40, req=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:2713
 14 0x0000aaaaaf7a2d60 in Server::dispatch (this=0xaaaad30f9d40, m=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:403 
15 0x0000aaaaaf6b4674 in MDSRank::handle_message (this=this@entry=0xaaaace374008, m=...) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1252
 16 0x0000aaaaaf6b6548 in MDSRank::_dispatch (this=this@entry=0xaaaace374008, m=..., new_msg=new_msg@entry=true) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1075 
17 0x0000aaaaaf6b6e6c in MDSRankDispatcher::ms_dispatch (this=this@entry=0xaaaace374000, m=...) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1049 
18 0x0000aaaaaf6a44f4 in MDSDaemon::ms_dispatch2 (this=0xaaaace348000, m=...) at /lsandbox/upstream/ceph/src/common/RefCountedObj.h:57 
19 0x0000ffff7f089a88 in Messenger::ms_deliver_dispatch (this=0xaaaad30b8000, m=...) at /lsandbox/upstream/ceph/src/msg/Messenger.h:748 
20 0x0000ffff7f0860b8 in DispatchQueue::entry (this=0xaaaad30b83d8) at /lsandbox/upstream/ceph/src/msg/DispatchQueue.cc:203 
21 0x0000ffff7f1411c0 in DispatchQueue::DispatchThread::entry (this=<optimized out>) at /lsandbox/upstream/ceph/src/msg/DispatchQueue.h:102
 22 0x0000ffff7ef211b8 in Thread::entry_wrapper (this=0xaaaad30b8540) at /lsandbox/upstream/ceph/src/common/Thread.cc:88
 23 0x0000ffff7ef211d8 in Thread::_entry_func (arg=<optimized out>) at /lsandbox/upstream/ceph/src/common/Thread.cc:75 
24 0x0000ffff7da49b68 in start_thread () from /lib64/libc.so.6 25 0x0000ffff7dab350c [PAC] in thread_start () from /lib64/libc.so.6 ---------------

Check the tracker for more details

Fixes: https://tracker.ceph.com/issues/75676

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions github-actions Bot added the cephfs Ceph File System label Mar 24, 2026
@kotreshhr
kotreshhr requested review from a team, batrick and vshankar March 24, 2026 07:28
@kotreshhr

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@kotreshhr

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

Comment thread src/mds/MDCache.cc Resolved
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Jul 3, 2026
@vshankar vshankar removed the stale label Jul 6, 2026
@vshankar vshankar self-assigned this Jul 6, 2026
@kotreshhr
kotreshhr force-pushed the mds-fileblockdiff-hang branch 2 times, most recently from 2236bc4 to 6302a29 Compare July 16, 2026 09:18
@kotreshhr
kotreshhr force-pushed the mds-fileblockdiff-hang branch from 6302a29 to 037ea07 Compare July 29, 2026 12:22
Copilot AI review requested due to automatic review settings July 29, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an MDS deadlock during synchronous file_blockdiff gather completion.

Changes:

  • Defers gather completion through the MDS finisher.
  • Uses the generic gather builder for asynchronous dispatch.

Comment thread src/mds/MDCache.cc Resolved
Comment thread src/mds/MDCache.cc Resolved
Copilot AI review requested due to automatic review settings July 29, 2026 13:00
@kotreshhr
kotreshhr force-pushed the mds-fileblockdiff-hang branch from 037ea07 to 8d760c7 Compare July 29, 2026 13:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/mds/MDCache.cc:14710

  • The existing blockdiff tests exercise result correctness, but they do not force all Objecter callbacks to complete before gather_ctx.activate(), which is the timing required to reproduce this deadlock. Add a regression test that covers both pre-activation and post-activation completion so the deadlock fix does not regress or break the ordinary asynchronous path.
  // Defer the MDSIOContext finisher to mds->finisher so gather activate() does
  // not call MDSIOContext::complete() inline while mds_lock is held.
  // See https://tracker.ceph.com/issues/75676
  MDSGatherBuilder gather_ctx(g_ceph_context,
			      new C_MDS_OnFinisher(mds, on_finish, mds->finisher));

Comment thread src/mds/MDCache.cc Resolved
The MDCache::file_blockdiff can deadlock
itself with the mds_lock.

The MDSDaemon::ms_dispatch2 takes the mds_lock
and MDCache::file_blockdiff tries to acquire
same lock while finishing it's context synchronously
at gather_ctx.activate()

The fix is to wrap the finisher in C_OnFinisher and
use C_GatherBuilder so completion is queued on
mds->finisher instead.

Following is the traceback

-----------------------------
(gdb) bt
0  0x0000ffff7da4656c in __futex_abstimed_wait_cancelable64 () from /lib64/libc.so.6
1  0x0000ffff7da48ff0 [PAC] in pthread_cond_wait@@GLIBC_2.17 () from /lib64/libc.so.6
2  0x0000ffff7efe0380 [PAC] in ceph::condition_variable_debug::wait (this=this@entry=0xaaaace348018, lock=...) at /lsandbox/upstream/ceph/src/common/mutex_debug.h:153
3  0x0000aaaaaf698b70 in ceph::condition_variable_debug::wait<ceph::fair_mutex::lock()::{lambda()#1}>(std::unique_lock<ceph::mutex_debug_detail::mutex_debug_impl<false> >&, ceph::fair_mutex::lock()::{lambda()#1}) (
   this=0xaaaace348018, lock=..., pred=...) at /lsandbox/upstream/ceph/src/common/condition_variable_debug.h:34
4  ceph::fair_mutex::lock (this=this@entry=0xaaaace348010) at /lsandbox/upstream/ceph/src/common/fair_mutex.h:28
5  0x0000aaaaaf9d71a0 in std::lock_guard<ceph::fair_mutex>::lock_guard (this=0xffff786cb760, __m=...) at /usr/include/c++/14/bits/std_mutex.h:250
6  MDSIOContextBase::complete (this=0xaaaadd1f3800, r=0) at /lsandbox/upstream/ceph/src/mds/MDSContext.cc:102
7  0x0000aaaaaf6f00a0 in C_GatherBase<MDSContext, C_MDSInternalNoop>::delete_me (this=this@entry=0xaaaadd167450) at /lsandbox/upstream/ceph/src/include/Context.h:351
8  0x0000aaaaaf6f0114 in C_GatherBase<MDSContext, C_MDSInternalNoop>::activate (this=0xaaaadd167450) at /lsandbox/upstream/ceph/src/include/Context.h:401
9  0x0000aaaaaf6f016c in C_GatherBuilderBase<MDSContext, C_GatherBase<MDSContext, C_MDSInternalNoop> >::activate (this=this@entry=0xffff786cb898) at /lsandbox/upstream/ceph/src/include/Context.h:490
10 0x0000aaaaaf83ac5c in MDCache::file_blockdiff (this=0xaaaace3f4000, in1=in1@entry=0xaaaadcc12680, in2=in2@entry=0xaaaad386cc00, block_diff=block_diff@entry=0xaaaadf0b0a30, max_objects=<optimized out>,
   max_objects@entry=16, ctx=ctx@entry=0xaaaadf0b0a10) at /lsandbox/upstream/ceph/src/mds/MDCache.cc:14933
11 0x0000aaaaaf78afa0 in Server::handle_client_file_blockdiff (this=this@entry=0xaaaad30f9d40, mdr=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:12619
12 0x0000aaaaaf79ed08 in Server::dispatch_client_request (this=this@entry=0xaaaad30f9d40, mdr=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:2942
13 0x0000aaaaaf79fbc4 in Server::handle_client_request (this=this@entry=0xaaaad30f9d40, req=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:2713
14 0x0000aaaaaf7a2d60 in Server::dispatch (this=0xaaaad30f9d40, m=...) at /lsandbox/upstream/ceph/src/mds/Server.cc:403
15 0x0000aaaaaf6b4674 in MDSRank::handle_message (this=this@entry=0xaaaace374008, m=...) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1252
16 0x0000aaaaaf6b6548 in MDSRank::_dispatch (this=this@entry=0xaaaace374008, m=..., new_msg=new_msg@entry=true) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1075
17 0x0000aaaaaf6b6e6c in MDSRankDispatcher::ms_dispatch (this=this@entry=0xaaaace374000, m=...) at /lsandbox/upstream/ceph/src/mds/MDSRank.cc:1049
18 0x0000aaaaaf6a44f4 in MDSDaemon::ms_dispatch2 (this=0xaaaace348000, m=...) at /lsandbox/upstream/ceph/src/common/RefCountedObj.h:57
19 0x0000ffff7f089a88 in Messenger::ms_deliver_dispatch (this=0xaaaad30b8000, m=...) at /lsandbox/upstream/ceph/src/msg/Messenger.h:748
20 0x0000ffff7f0860b8 in DispatchQueue::entry (this=0xaaaad30b83d8) at /lsandbox/upstream/ceph/src/msg/DispatchQueue.cc:203
21 0x0000ffff7f1411c0 in DispatchQueue::DispatchThread::entry (this=<optimized out>) at /lsandbox/upstream/ceph/src/msg/DispatchQueue.h:102
22 0x0000ffff7ef211b8 in Thread::entry_wrapper (this=0xaaaad30b8540) at /lsandbox/upstream/ceph/src/common/Thread.cc:88
23 0x0000ffff7ef211d8 in Thread::_entry_func (arg=<optimized out>) at /lsandbox/upstream/ceph/src/common/Thread.cc:75
24 0x0000ffff7da49b68 in start_thread () from /lib64/libc.so.6
25 0x0000ffff7dab350c [PAC] in thread_start () from /lib64/libc.so.6
---------------
Check the tracker for more details

Fixes: https://tracker.ceph.com/issues/75676
Signed-off-by: Kotresh HR <[email protected]>
Copilot AI review requested due to automatic review settings July 31, 2026 09:09
@kotreshhr
kotreshhr force-pushed the mds-fileblockdiff-hang branch from 8d760c7 to 2e842da Compare July 31, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@kotreshhr

Copy link
Copy Markdown
Contributor Author

@vshankar ptal

@vshankar

vshankar commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by vshankar started 2026-08-05-16:27.

@vshankar vshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vshankar
vshankar merged commit 4283bb3 into ceph:main Aug 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants