Skip to content

mds: drop dirty_old_rstats of purged old inodes - #72611

Open
xiubli wants to merge 2 commits into
ceph:mainfrom
xiubli:wip-mds-dirty-old-rstats
Open

xiubli wants to merge 2 commits into
ceph:mainfrom
xiubli:wip-mds-dirty-old-rstats

Conversation

@xiubli

@xiubli xiubli commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

With mds_snap_rstat enabled, the MDS can segfault while propagating the rstats of a stray directory:

 *** Caught signal (Segmentation fault) **
 in thread mds-log-trim
 2: (MDCache::project_rstat_inode_to_frag(...)+0x32e)
 3: (CDir::assimilate_dirty_rstat_inodes(...)+0x10e)
 4: (CInode::finish_scatter_gather_update(int, ...)+0x1c2e)
 5: (Locker::scatter_writebehind(ScatterLock*)+0x467)
 6: (Locker::scatter_nudge(ScatterLock*, MDSContext*, bool)+0x567)
 7: (LogSegment::try_to_expire(...)+0xb16)
 8: (MDLog::try_expire(...)+0x66)
 9: (MDLog::trim()+0x5b5)

The standby that takes over crashes the same way. It is hit by qa/tasks/cephfs/volumes/test_clone_stats.py, which sets mds_snap_rstat=true.

Root cause

  1. The stray dirs live in the global snaprealm, so once any snapshot has been taken, cow_old_inode() cows an old inode for them. As the rstat of that old inode is not fully accounted, its snapid is also recorded in dirty_old_rstats.
  2. Committing the ~mdsN dirfrag calls CInode::purge_stale_snap_data() on the stray dir. No snapshot covers the old inode, so it is purged, but its dirty_old_rstats entry is left behind.
  3. The next nest scatter of ~mdsN runs project_rstat_inode_to_frag(), which does cur->get_old_inodes()->at(p) for each dirty_old_rstats entry. old_inodes is now null, so the MDS crashes. If only some of the old inodes had been purged, at() would throw std::out_of_range instead.

Fix

Drop the dirty_old_rstats entries of the old inodes that purge_stale_snap_data() purges.

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

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.

With mds_snap_rstat enabled, cow_old_inode() records the snapid of a
newly cowed old inode in dirty_old_rstats when its rstat is not fully
accounted, and project_rstat_inode_to_frag() later looks each of these
up in old_inodes to propagate the rstat to the parent dirfrag.

purge_stale_snap_data() removes old inodes that no snapshot covers any
more, but it leaves their dirty_old_rstats entries behind.  The next
rstat propagation then dereferences a null old_inodes map, or throws
std::out_of_range from at() when only some of them were purged.

This is easy to hit with the stray dirs: they live in the global
snaprealm, so they get an old inode cowed as soon as any snapshot has
been taken, and committing ~mdsN purges it right away because no
snapshot covers the stray dirs.  The next nest scatter of ~mdsN, e.g.
from the log trimming, crashes the MDS:

  MDCache::project_rstat_inode_to_frag
  CDir::assimilate_dirty_rstat_inodes
  CInode::finish_scatter_gather_update
  Locker::scatter_writebehind
  Locker::scatter_nudge
  LogSegment::try_to_expire
  MDLog::trim

Drop the dirty_old_rstats entries together with the purged old inodes.

Fixes: https://tracker.ceph.com/issues/81672
Signed-off-by: Xiubo Li <[email protected]>
With mds_snap_rstat enabled, take and remove a snapshot so that the
stray dirs get an old inode cowed, unlink some files and flush the
journal, and check that the MDS does not crash propagating the rstats
of the stray dir after its old inode has been purged.

Fixes: https://tracker.ceph.com/issues/81672
Signed-off-by: Xiubo Li <[email protected]>
@xiubli
xiubli requested review from a team and batrick October 13, 2026 04:31
@github-actions github-actions Bot added cephfs Ceph File System tests labels Oct 13, 2026
@dparmar18

Copy link
Copy Markdown
Contributor

you got to this first :) i found this while testing one of my PR #72152

@vshankar vshankar self-assigned this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants