Skip to content

mds: do not replicate an xlocked dentry whose linkage is projected - #72790

Merged
vshankar merged 2 commits into
ceph:mainfrom
anthonyeleven:wip-81730-mds-discover-xlocked
Nov 6, 2026
Merged

vshankar merged 2 commits into
ceph:mainfrom
anthonyeleven:wip-81730-mds-discover-xlocked

Conversation

@anthonyeleven

@anthonyeleven anthonyeleven commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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

handle_discover lets a path_locked discover replicate an xlocked dentry. The exception is meant for the xlocker's own witnesses, but MDiscover carries no request id, so a peer working on another request gets it too, for example handle_peer_rename_prep opening a remote dentry's inode. If the dentry belongs to a rename that has already projected its new linkage, such as an early-replied rename waiting on its journal entry, the new replica gets the old linkage and is not a witness. When the rename commits, _rename_finish sends MDentryLink to that replica, and the peer fails ceph_assert(dnl->is_null()) in MDCache::handle_dentry_link.

This change allows the exception only while the dentry has no projected linkage. Otherwise the discover blocks on the xlock as a normal discover does, and the log is nudged so an early-replied xlocker does not hold it until the next tick. The xlocker's own witnesses all traverse before it projects, so they are unaffected.

Testing: reproduced deterministically on v18.2.7 with two active ranks, one kernel client and mds_log_pause on the rename leader. The reproducer script, debug_mds 20 logs from both ranks and the sequence are on the tracker. Without this change the peer rank aborted in 2 of 2 runs. With it, cherry-picked onto v18.2.7, it aborted in 0 of 2: the auth rank logs handle_discover blocking on xlocked, and the second rename completes once the first commits. The diff is identical on main.

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.

Signed-off-by: Anthony D'Atri [email protected]
Assisted by Claude Opus-5.5

handle_discover lets a path_locked discover replicate an xlocked
dentry. The exception exists for the xlocker's own witnesses, which
traverse the paths before the xlocker projects anything: a rename leader
sends rename_prep only after it holds all locks, and calls
_rename_prepare only after every witness has acked. MDiscover does not
carry a request id, though, so any peer that traverses with
MDS_TRAVERSE_PATH_LOCKED gets the exception, including one working for an
unrelated request. open_remote_dentry with want_xlocked, as used by
handle_peer_rename_prep and handle_peer_rmdir_prep, discovers the primary
dentry of the inode it is opening that way.

If that dentry belongs to a rename that has already projected its new
linkage and is waiting for its journal entry, the new replica gets the
old linkage and is not a witness. When the rename commits,
_rename_finish sends MDentryLink for destdn to every replica that did not
witness it, on the assumption that such a replica is null. A replica of a
rename-over destdn is not null, so handle_dentry_link fails its assertion
that the replica is null. A late replica of srcdn is never told that the
name became null, which can trip the same assert the next time the name
is linked.

early_reply already relies on this not happening. It leaves a rename's
dentry xlocks undone for exactly this reason:

    // so do not set xlocks on dentries "done", the xlocks prevent dentries
    // that have projected linkages from getting new replica.

The path_locked exception bypasses that.

One way to get there: a client renames over the primary link of a hard
linked inode. The rename has no journaled peers, so it gets an early
reply. Its inode xlocks become xlockdone, and the same client can take
them over at once; without the early reply the two renames would
serialize on those xlocks. The client then renames over another link of
the same inode. A rank that witnesses this second rename and does not
have the inode in cache opens it, discovers the primary dentry, still
xlocked by the first rename, and receives its pre-rename linkage. A
moment later the first rename commits and sends that rank MDentryLink.

If both renames move links of one source inode, as when a tool replaces
every link of a set with links to a new inode, that witness is not the
source inode's auth: such a witness journals, so the first rename would
not have been early-replied. It is a witness because it still holds a
replica of srcdn or destdn, for example one left behind after the
directory's subtree was exported, while it no longer has the inode
itself in cache.

Reproduced on v18.2.7 with two active ranks and one client. /d is
pinned to rank 1 and /d/C to rank 0; /d/A/f is the primary link of
inode O, /d/B/f1 a remote link to O, /d/C/u the primary link of U and
/d/B/.stg1 a remote link to U. With mds_log_pause set on rank 1,
renaming /d/A/T over /d/A/f gets an early reply, and renaming
/d/B/.stg1 over /d/B/f1 makes rank 0, the auth of U, a witness. Its
rename_prep opens O, and rank 1 logs "handle_discover allowing discovery of xlocked
[dentry #0x1/d/A/f ... pv=16 v=8 ...]". When the log is unpaused,
_rename_finish sends MDentryLink for /d/A/f, and rank 0 fails the
assertion in handle_dentry_link. With this change, rank 1 logs
"handle_discover blocking on xlocked" for /d/A/f, the second rename
completes once the first commits, and neither rank aborts.

Allow the path_locked exception only while the dentry has no projected
linkage. After that, block on the xlock the same way a normal discover
does. The xlocker no longer depends on any peer, so it will finish and
drop the xlock, and the discover is retried against the committed
linkage. The xlocker's own witnesses are unaffected because they never
discover after it projects. Nudge the log when blocking: an
early-replied xlocker defers its journal flush, and the discover, and
any peer request waiting behind it, should not wait for the next tick.

Also drop the comments about tail items. They have been stale since
commit cac3c01, "mds: change MDCache::discover_path()'s
wants_xlocked semantic", made the exception apply at every depth.

Signed-off-by: Anthony D'Atri <[email protected]>
Assisted by Claude Opus-5.5
@github-actions github-actions Bot added the cephfs Ceph File System label Oct 16, 2026
@anthonyeleven
anthonyeleven marked this pull request as ready for review October 16, 2026 21:23
@anthonyeleven

Copy link
Copy Markdown
Contributor Author

@vshankar

@anthonyeleven
anthonyeleven requested review from a team and vshankar October 16, 2026 21:23
@vshankar vshankar self-assigned this Oct 21, 2026
@vshankar

Copy link
Copy Markdown
Contributor

Thanks for the patch @anthonyeleven. This is pending on me for review.

@anthonyeleven

Copy link
Copy Markdown
Contributor Author

Thanks for the patch @anthonyeleven. This is pending on me for review.

Awesome, thanks for your attention. As you might deduce, this bit me in production.

@vshankar

Copy link
Copy Markdown
Contributor

Awesome, thanks for your attention. As you might deduce, this bit me in production.

Got it and its under review now.

@xiubli

xiubli commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Thanks for the detailed write-up. I reviewed the change and tested it; it looks good to me.

Testing

Built from main (0fab663) with and without this PR. vstart cluster on a VM: 2 active ranks, 1 standby, one kernel client, /d pinned to rank 1 and /d/C to rank 0.

1. The reproducer from the commit message, with mds_log_pause set on rank 1:

main main + PR
rank 1 log allowing discovery of xlocked for /d/A/f (pv=28 v=26) blocking on xlocked for /d/A/f, then nudge_log YES
after unpausing the log rank 0: FAILED ceph_assert(dnl->is_null()) in handle_dentry_link, standby takes over rank 0 second rename completes, no assert, no failover

2. Stress test, no log pause. 300 rounds. In each round O is a fresh inode created on rank 1 (/d/A/fK, plus a remote link /d/B/fK1), and U is created on rank 0 (/d/C/uK, plus a remote link /d/B/.stgK). Each round renames /d/A/TK over /d/A/fK, then immediately renames /d/B/.stgK over /d/B/fK1. This is the pattern of a tool that replaces every link of a hard-link set with links to a new inode.

main main + PR
rounds completed 3 of 300 (fs stuck) 300 of 300
handle_dentry_link asserts 4: rank 0 asserted in round 1, the standby that took over asserted in round 3 0
failovers 4 replays 0
discover blocked on a projected xlocked dentry n/a 574 times

Latency of the second rename with the PR, in ms (single run, n=300):

p50 p90 p95 p99 p99.9 p99.99 max
32.7 44.8 48.9 82.8 101.4 101.4 101.4

3. Recovery and cleanup. Without the PR, the new rank 0 replayed the half-done second rename (EPeerUpdate.replay prepare ... saving rollback info), and resolve committed it. File contents matched the md5 sums taken before the renames. On both builds, a recursive scrub left damage ls empty, and after rm -rf the data pool held no objects.

4. qa via vstart_runner (test_strays, test_exports, test_multimds_misc):

module main + PR main
test_multimds_misc 6/6 ok not run
test_strays 18 ok, 4 failed the same 4 fail
test_exports 37 ok, 5 failed the failures not caused by local tests also fail on main (below)

@anthonyeleven Locally I wrote a qa reproducer in 267feae, you can just included it in this PR or you write a new one if you like.

┌─────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────┐
│               MDS               │                                               Result                                                │
├─────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ upstream main (without the fix) │ FAIL: assertTrue(mds_is_running(rank0)) fails; the MDS log shows FAILED ceph_assert(dnl->is_null()) │
├─────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ main + PR 72790                 │ OK                                                                                                  │
└─────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────┘

Each run takes about 52 seconds.

@anthonyeleven

anthonyeleven commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Forgive my cluelessness please: you mention having written a reproducer but don’t I already have one in the pr? Is more needed for approval?

@xiubli

xiubli commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Forgive my cluelessness please: you mention having written a reproducer but don’t I already have one in the pr? Is more needed for approval?

I mean a qa test which also includes the reproducer in it. Usually for the bug fix we'd better have one qa test together with it.

With two active ranks, rename a file over the primary link of a hard
linked inode on rank 1 while rank 1's journal is paused, so the rename
gets an early reply and keeps its new linkage projected. Then rename a
remote link of an inode on rank 0 over another link of the same inode.
Rank 0 is a witness of that rename, and its rename_prep discovers the
primary dentry still xlocked by the first rename.

Check that rank 0 is still running, with the same gid, after the
journal is unpaused, and that both renames took effect. Without the
fix, the discover returns the pre-rename linkage, and the first
rename's MDentryLink fails ceph_assert(dnl->is_null()) on rank 0.

Fixes: https://tracker.ceph.com/issues/81730
Assisted-by: LLM
Signed-off-by: Xiubo Li <[email protected]>
@anthonyeleven

Copy link
Copy Markdown
Contributor Author

Thanks, I've included your qa test 267feae as-is (your authorship) in this PR.

@github-actions github-actions Bot added the tests label Oct 30, 2026

@xiubli xiubli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @anthonyeleven

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

The fix is correct. I will do a sample run of the test with a branch that does not have this fix. The MDS should hit that assert.

So, LGTM, but deferring approval till I validate the test.

@vshankar

vshankar commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Reproduces like a piece of cake on a branch without the fix. See: https://pulpito.ceph.com/vshankar-2026-11-02_13:53:46-fs:functional-wip-vshankar-oft-load-shrink-journal-oob-distro-default-trial/705437/

2026-11-02T14:01:49.942 INFO:teuthology.orchestra.run:Running command with timeout 300
2026-11-02T14:01:49.943 DEBUG:teuthology.orchestra.run.trial031:> (cd /home/ubuntu/cephtest/mnt.0 && exec mv d/B/.stg1 d/B/f1)
2026-11-02T14:01:55.087 DEBUG:teuthology.orchestra.run.trial191:> sudo adjust-ulimits ceph-coverage /home/ubuntu/cephtest/archive/coverage timeout 300 ceph --cluster ceph --admin-daemon /var/run/ceph/ceph-mds.b.asok --format=json config set mds_log_pause false
2026-11-02T14:01:55.176 INFO:tasks.ceph.mds.d.trial191.stderr:/ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: In function 'void MDCache::handle_dentry_link(ceph::cref_t&)' thread 7f50fa3f66c0 time 2026-11-02T14:01:55.176707+0000
2026-11-02T14:01:55.176 INFO:tasks.ceph.mds.d.trial191.stderr:/ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: 11587: FAILED ceph_assert(dnl->is_null())
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: ceph version 22.0.0-270-ge66c451f (e66c451fd13cc7276e554eca2419e33b1ab59269) vampire (dev - RelWithDebInfo)
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 1: ceph-mds(+0xbefce) [0x5562cf0e6fce]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 2: (MDCache::dispatch(boost::intrusive_ptr const&)+0x30a) [0x5562cf2e4e0a]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 3: (MDSRank::handle_message(boost::intrusive_ptr const&)+0x223) [0x5562cf165c83]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 4: (MDSRank::_dispatch(boost::intrusive_ptr const&, bool)+0x553) [0x5562cf167ee3]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 5: (MDSRankDispatcher::ms_dispatch(boost::intrusive_ptr const&)+0x53) [0x5562cf168313]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 6: (MDSDaemon::ms_dispatch2(boost::intrusive_ptr const&)+0x13c) [0x5562cf151fdc]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 7: (DispatchQueue::entry()+0x50f) [0x7f50ffbf2eff]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 8: /usr/lib64/ceph/libceph-common.so.2(+0x4879f1) [0x7f50ffc879f1]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 9: /lib64/libc.so.6(+0x958bf) [0x7f50ff2bc8bf]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 10: /lib64/libc.so.6(+0x10643c) [0x7f50ff32d43c]
2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr:2026-11-02T14:01:55.176+0000 7f50fa3f66c0 -1 /ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: In function 'void MDCache::handle_dentry_link(ceph::cref_t&)' thread 7f50fa3f66c0 time 2026-11-02T14:01:55.176707+0000

@vshankar

vshankar commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by vshankar started 2026-11-04-08:50.

@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 c9664d9 into ceph:main Nov 6, 2026
23 checks passed
@anthonyeleven

Copy link
Copy Markdown
Contributor Author

@anthonyeleven
anthonyeleven deleted the wip-81730-mds-discover-xlocked branch November 8, 2026 02:47
dvanders added a commit to dvanders/ceph that referenced this pull request Nov 10, 2026
A rename into a directory on another rank of a file the client has just
written waits a full mds_tick_interval (5 s). Two waits in that path
are for an update that is already submitted to the journal but not
flushed, and nothing asks for a flush, so the update is only journaled
by the next tick:

- handle_peer_rename_prep() freezes the renamed inode on the rank that
  owns it. When the client flushes its dirty caps on the file, at the
  same time or just before, _do_cap_update() holds an auth pin on the
  inode until the update is journaled, and the freeze waits for it.
  Flush the log when the freeze has to wait, and have _do_cap_update()
  ask for a flush when the inode is being frozen, for a cap flush that
  arrives after the freeze started.
- The other rank discovers the just-created source dentry, and
  handle_discover() blocks on its xlock, which the create holds until it
  is journaled. d0a7454 ("mds: do not replicate an xlocked dentry
  whose linkage is projected", ceph#72790) already nudges the log there.

On a vstart cluster with two active ranks, renaming a just-written 4 KiB
or 1 MiB file from a directory on rank 0 into one on rank 1 took a
median of 2.8-5.0 s with a kernel client and 3.5-4.6 s with ceph-fuse,
and about 1.5 s with mds_tick_interval set to 1. With this change it
takes 140-210 ms with either client, against 3 ms (kernel) and 37 ms
(ceph-fuse) within one rank. Measured on Reef 18.2.8. On main, with
ceph-fuse, the same renames took 4.9-5.0 s before and 16-110 ms after;
with mds_tick_interval at 10 they took 10 s before and 80-100 ms after.

Fixes: https://tracker.ceph.com/issues/82190
Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants