Skip to content

Rework directory block enumeration accounting - #97

Open
RoyWFHuang wants to merge 1 commit into
sysprog21:masterfrom
RoyWFHuang:bug/dir_walk_accounting
Open

Rework directory block enumeration accounting#97
RoyWFHuang wants to merge 1 commit into
sysprog21:masterfrom
RoyWFHuang:bug/dir_walk_accounting

Conversation

@RoyWFHuang

@RoyWFHuang RoyWFHuang commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

__file_lookup() and simplefs_remove_from_dir() both walk a directory's extents block by block, but bound the walk differently:

  • __file_lookup() subtracts a block's nr_files before scanning the block.
  • simplefs_remove_from_dir() bounds its inner loop by the extent length (ee_len) instead of by the number of files left to find.

Neither skips blocks whose nr_files is 0, so an empty block is still walked entry by entry.

  • Bound both inner loops by nr_bi_files, and decrement it only after a block has been scanned.
  • Skip blocks whose nr_files is 0.
  • In simplefs_try_remove_entry(), zero the freed slot's nr_blk after merging it into the preceding entry, and drop the blk_nr_files guard that the caller's count-based loop makes redundant.

Summary by cubic

Unifies directory block enumeration in __file_lookup() and simplefs_remove_from_dir() with consistent file-count and extent-length bounds, and skips empty blocks. Bounds outer loops by SIMPLEFS_MAX_EXTENTS to prevent infinite walks under i_rwsem and reduce unnecessary reads.

  • Bug Fixes
    • Bound inner loops by remaining files and extent length; decrement only after scanning each block, and skip blocks with nr_files == 0.
    • Bound outer loops by SIMPLEFS_MAX_EXTENTS to avoid infinite walks when counts disagree with on-disk entries.
    • In simplefs_try_remove_entry(), zero the freed entry’s nr_blk after merging and remove the redundant blk_nr_files guard.

Written for commit add7479. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread inode.c Outdated
__file_lookup() and simplefs_remove_from_dir() bound their block walks
differently, and neither skips directory blocks that hold no files.

Bound both inner loops by nr_bi_files and by the extent length,
decrement the count only after a block is scanned, and skip blocks whose
nr_files is zero. Bound the outer loops by SIMPLEFS_MAX_EXTENTS the same
way, so a file count that disagrees with the entries actually present
cannot leave a walk looping while it holds the directory's i_rwsem. In
simplefs_try_remove_entry(), zero the freed slot's nr_blk and drop the
now redundant blk_nr_files guard.
@RoyWFHuang
RoyWFHuang force-pushed the bug/dir_walk_accounting branch from 19654ba to add7479 Compare August 12, 2026 12:57
@RoyWFHuang
RoyWFHuang requested a review from jserv August 12, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant