Skip to content

mds: fix snapdiff dropping file with unflushed cap snap and/or inode comparison check - #71936

Open
vshankar wants to merge 4 commits into
ceph:mainfrom
vshankar:wip-snapdiff-cap-snap-race
Open

vshankar wants to merge 4 commits into
ceph:mainfrom
vshankar:wip-snapdiff-cap-snap-race

Conversation

@vshankar

@vshankar vshankar commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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

cc @LiShengG

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.

@vshankar
vshankar requested review from a team, ifed01 and kotreshhr September 21, 2026 05:11
@vshankar vshankar added the cephfs Ceph File System label Sep 21, 2026
@github-actions github-actions Bot added the tests label Sep 21, 2026
@kotreshhr

Copy link
Copy Markdown
Contributor

With the fix #69895 the test did reproduce the issue once in 50 runs. So the test is catching the issue but it's very racy.

./bin/ceph_test_libcephfs_snapdiff --gtest_filter=LibCephFS.SnapDiffPendingCapsnap --gtest_repeat=50
...
....
Repeating all tests (iteration 45) . . .

Note: Google Test filter = LibCephFS.SnapDiffPendingCapsnap
[==========] Running 1 test from 1 test suite.
[----------] 1 test from LibCephFS
[ RUN      ] LibCephFS.SnapDiffPendingCapsnap
/lsandbox/upstream/ceph/src/test/libcephfs/snapdiff.cc:2557: Failure
Value of: found_racy
  Actual: false
Expected: true
fileA changed between snap1 and snap2 but is missing from the diff taken before the MDS committed the snapflush

[  FAILED  ] LibCephFS.SnapDiffPendingCapsnap (2030 ms)
[----------] 1 test from LibCephFS (2030 ms total)

[==========] 1 test from 1 test suite ran. (2030 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] LibCephFS.SnapDiffPendingCapsnap

 1 FAILED TEST
 ...

@vshankar

Copy link
Copy Markdown
Contributor Author

With the fix #69895 the test did reproduce the issue once in 50 runs. So the test is catching the issue but it's very racy.

Yeh. For me, it failed in within 10 iterations, so the race window depends on a lot of things converging :/

Comment thread src/mds/Server.cc Outdated
// @snapid is not known here yet.
for (const auto& p : head->get_client_caps()) {
const Capability& cap = p.second;
if ((cap.issued() & CEPH_CAP_ANY_WR) && cap.client_follows < snapid) {

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.

Should this be as below ?

int issued = cap.need_snapflush() ? CEPH_CAP_ANY_WR : cap.issued();
if ((issued & CEPH_CAP_ANY_WR) && cap.client_follows < snapid)
  return true;

The cow_inode() also uses the similar check

int issued = cap->need_snapflush() ? CEPH_CAP_ANY_WR : cap->issued();

I think the case is that if the client wrote and dropped the Fwb then cap.need_snapflush would catch that ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the case is that if the client wrote and dropped the Fwb then cap.need_snapflush would catch that ?

Fwb will be dropped only after it can flush its buffered data, so the cap update/snapflush race still holkds true. I think the additional cap.need_snapflush() is really not required due to the client_follows check here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as the check in cow_inode is concerned, the check here (in snapdiff) should cover a broader case since we do not do any additional check that cow_inode() does.

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.

Yeah I was little confused on why it's done in cow_inode! You are right, Fwb is dropped only after FLUSHSNAP is received.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, unfortunately this condition is buggy for loner client doing sync write (exactly, what LibCephFS.SnapDiffLib2 does. There are no queues cap snaps from such clients and the predicate just keeps on revoking Fw rdlock_start and hands it over back in rdlock_finish.

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

nit: s/interations/iterations in the commit message of 6e011a6

@vshankar
vshankar force-pushed the wip-snapdiff-cap-snap-race branch from 6e011a6 to fbbb09d Compare September 21, 2026 09:32
@vshankar

Copy link
Copy Markdown
Contributor Author

nit: s/interations/iterations in the commit message of 6e011a6

Fixed.

@kotreshhr

Copy link
Copy Markdown
Contributor

lgtm

@vshankar

Copy link
Copy Markdown
Contributor Author

This PR has been added to main integration testing by vshankar started 2026-09-21-09:47.

@kotreshhr

Copy link
Copy Markdown
Contributor

@vshankar The windows test seems to be real failure with the PR ?

Assisted-by: cursor, I didn't spend too much time on this.

ceph_test_libcephfs_snapdiff timed out after 1800s in existing LibCephFS.SnapDiffLib2 
(not the new SnapDiffPendingCapsnap test). Windows is just where CI runs that suite.

What happened: readdir_snapdiff stuck with locks held for ~1800s; MDS then saw the 
client ignore cap revoke and evicted it:

[ RUN ] LibCephFS.SnapDiffLib2
... readdir_snapdiff ... currently acquired locks  (blocked >1800s)
mds.b: client ... isn't responding to mclientcaps(revoke) ... Evicting client
Command timed out (1800s)

Why: The PR widens snapflush_pending() in Server.cc to treat any client with write caps 
and client_follows < snapid as needing a snapflush, then takes rdlock_file_start and waits 
for that flush. In SnapDiffLib2, the same client still holds those WR caps while calling 
readdir_snapdiff, so the MDS waits for a flush that client never sends → self-deadlock
 until timeout.

@vshankar

Copy link
Copy Markdown
Contributor Author

@vshankar

Copy link
Copy Markdown
Contributor Author

@vshankar The windows test seems to be real failure with the PR ?

https://github.com/ceph/ceph/pull/71936/changes#r4062824990

@vshankar The windows test seems to be real failure with the PR ?

https://github.com/ceph/ceph/pull/71936/changes#r4062824990

OK, so this is a live-lock, not really a deadlock and its reproducible. We would have caught it in teuthology testing but I'm happy that it got caught earlier. Here is the bug:

  1. Walk reaches fileA's dentry. snapflush_pending(in) -> true (issued has ANY_WR, client_follows < snapid).
  2. rdlock_file_start(in) -> filelock is SYNC, can_rdlock is ANY -> granted immediately, no wait. locked = true.
  3. inode_at_snap() / meta_differs() -- the comparison, under the lock.
  4. rdlock_file_finish(in) -> try_eval() → file_eval() sees the loner still wants Fxwb -> file_excl() → fileA heads back to EXCL, caps re-issued, seq bumps.
  5. Then add_result_cb(dn, in, true) appends fileA's name + lease + inodestat into dnbl.

Then, the next file:

  1. Walk moves to fileB. snapflush_pending -> true. rdlock_file_start(in) -> fileB is EXCL -> blocks. *waiting = true, return false.
  2. _readdir_diff hits if (waiting) return; — dnbl, holding fileA, goes out of scope. Nothing sent.
  3. fileB's revoke completes (ifile excl->sync --> SYNC), C_MDS_RetryRequest fires.
  4. Next round starts at dir->begin() again — and fileA is EXCL now, from step 4. So this round blocks on fileA.
  5. fileA's revoke completes, retry, fileA is SYNC -> steps 1-5 again -> flips back -> fileB, which by now has also reverted to EXCL (nothing rdlocked it, and eval pushed it back once its gather finished) -> blocks.

... over and over again. The combination of the loner client, the lock state and the readdir retry results in cap revoke+grant over and over.

@vshankar
vshankar force-pushed the wip-snapdiff-cap-snap-race branch from fbbb09d to c8b8ea9 Compare September 22, 2026 09:40
@vshankar

Copy link
Copy Markdown
Contributor Author

@kotreshhr - unfortunately 0c0577a does not fully fix the issue. So, I am going to work on it separately (separate PR). For this PR, I will just be including the projected inode fixes.

@vshankar

Copy link
Copy Markdown
Contributor Author

@kotreshhr - unfortunately 0c0577a does not fully fix the issue. So, I am going to work on it separately (separate PR). For this PR, I will just be including the projected inode fixes.

https://tracker.ceph.com/issues/80778 (tracker for this change which will include just the projected inode fixes)
https://tracker.ceph.com/issues/80634 (will include the pending snap cap fixes -- will be worked after this PR gets merged)

A file modified between two snapshots could be missing from
readdir_snapdiff output, leaving cephfs-mirror silently out of sync until
the file changed again.

Locker::_do_snap_update() applies a FLUSHSNAP by projecting onto the
inode and journalling an EUpdate; the projection is popped only when that
entry commits, and unlike the regular cap flush path it never calls
mdlog->flush(). Server::build_snap_diff() meanwhile read committed state
via CInode::get_inode(), so between the FLUSHSNAP arriving and the
journal committing it saw the pre-snapflush values.

The COW itself runs synchronously, so the diff ends up comparing a
correctly COWed snapshot inode against a head that still carries the old
metadata, concludes nothing changed, and drops the entry:

  handle_client_caps on 0x1000000001b tid 4 follows 1e op flushsnap
  _do_snap_update dirty Fw follows 1e snap 1f on [inode ... [1e,head] s=2]
  cow_inode [inode ... [1f,head] auth v4 pv10 ... s=2 n(..b2..)->n(..b4096..)] to [inode ... [1e,1e] ... s=2]

v4/pv10 is the hint here: size 4096 exists only in the projection while
get_inode() still reports 2, which is what the comparison used. The
window closes on the next mdlog flush though.

For this fix, read both operands through get_projected_inode() instead, in
EntryInfo::meta_differs() and in the head branch of inode_at_snap().
old_inodes needs no equivalent change: _do_snap_update() installs it with
reset_old_inodes() before submitting the journal entry rather than
projecting it.

Fixes: http://tracker.ceph.com/issues/80778
Signed-off-by: Venky Shankar <[email protected]>
Fortunately, this fd leak exposed in a bug in LibCephFS.SnapDiffLib2()
test with the fixes for the newly introduced LibCephFS.SnapDiffPendingCapsnap()
test. The bug will be fixed separately and a legit test involving
an open file descriptor will be added as a separate commit.

Signed-off-by: Venky Shankar <[email protected]>
readdir_snapdiff against a directory whose files are open for write is an
ordinary state -- a database, a log writer or an rsync in flight all hold a
descriptor open -- but nothing in this file exercised it deliberately.
write_full() leaked its descriptors, so every test here happened to run
that way by accident. With that fixed, the coverage is gone.

An open descriptor keeps Fw in caps_wanted(), so the MDS re-grants EXCL as
soon as any rdlock taken on the file is released. This scenario needs to
be kept as part of the test matrix. So, hold two descriptors open across
a snap1 vs snap2 diff and assert the expected entries.

Signed-off-by: Venky Shankar <[email protected]>
@vshankar
vshankar force-pushed the wip-snapdiff-cap-snap-race branch from c8b8ea9 to 2100b67 Compare September 23, 2026 07:43
@vshankar

Copy link
Copy Markdown
Contributor Author

jenkins test windows

1 similar comment
@vshankar

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@vshankar

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

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.

2 participants