Skip to content

Lowmem fsck repair to fix filetype mismatch

Qu Wenruo linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 12 repliesIn review
  2. v13 patches 6 repliesSuperseded

Changes in v2 from the cover letter

No longer play tricks to add new parameters to let btrfs_unlink() to locate invalid dir_index, but remove the unnecessary filetype check in verify_dir_item().
Since user of functions in dir-items.c are all btrfs check, either repairing or checking, and both original mode and lowmem mode can handle it well.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs-progs: lowmem fsck: Remove corupted link before re-add correct linkcmds-check.c+4 -01 reply
2/3btrfs-progs: dir-item: Don't do extra filetype validaction check for btrfs_match_dir_item_namedir-item.c+0 -68 replies
2/3btrfs-progs: dir-item: Don't do extra filetype validaction check for btrfs_match_dir_item_namedir-item.c+0 -61 reply
3/3btrfs-progs: dir-item: Make btrfs_delete_one_dir_name more robust to handle corrupted name lendir-item.c+9 -22 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchSu YueNikolay Borisov
1/3R-b
2/3R-b R-b
2/3R-b R-b
3/3R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] Lowmem fsck repair to fix filetype mismatch

Sebastian reported a filesystem corruption where DIR_INDEX has wrong filetype against INODE_ITEM.

Lowmem mode normally handles such problem by checking DIR_INDEX, DIR_ITEM and INODE_REF/INODE_ITEM to determine the correct file type. In such case, lowmem mode fsck can get the correct filetype.

When fixing the problem, lowmem mode will try to re-insert correct (DIR_INDEX, DIR_ITEM, INODE_REF) tuple, and if existing correct DIR_ITEM and INODE_REF is found, btrfs_link() will just skip and only insert correct DIR_INDEX.

However, when inserting correct DIR_INDEX, due to extra DIR_INDEX validation, incorrect one will be skiped and correct one will be inserted after invalid one.

This leads to lowmem mode repair to create duplicated DIR_INDEX.

This patch will fix it by removing the whole (DIR_INDEX, DIR_ITEM, INODE_REF) tuple before inserting correct tuple.
And the removing part, btrfs_unlink(), will be enhanced to handle incorrect tuple member more robust.

Please note that, due a bug in lowmem mode repair, btrfs check will still show "error(s) found in fs tree" even repair is done successfully.

And test case for this repair still needs extra work for original mode to support such repair, or test case won't pass original mode test.

Changelog:
v2:
No longer play tricks to add new parameters to let btrfs_unlink() to locate invalid dir_index, but remove the unnecessary filetype check in verify_dir_item().
Since user of functions in dir-items.c are all btrfs check, either repairing or checking, and both original mode and lowmem mode can handle it well.

Qu Wenruo (3):
btrfs-progs: lowmem fsck: Remove corupted link before re-add correct
link
btrfs-progs: dir-item: Don't do extra filetype validaction check for
btrfs_match_dir_item_name
btrfs-progs: dir-item: Make btrfs_delete_one_dir_name more robust to
handle corrupted name len

 cmds-check.c |  4 ++++
 dir-item.c   | 17 +++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
2.15.1