[PATCH v2 0/6] xfs_repair: do not trash valid root dirs

Darrick J. Wong
2019-12-04T17:04:29Z

Hi all,

Alex Lyakas observed that xfs_repair can accidentally trash the root
directory on a filesystem. Specifically, if one formats a V4 filesystem
without sparse inodes but with sunit/swidth set and then mounts that
filesystem with a different sunit/swidth, the kernel will update the
values in the superblock. This causes xfs_repair's sb_rootino
estimation to differ from the actual root directory, and it discards the
actual root directory even though there's nothing wrong with it.

Therefore, hoist the logic that computes the root inode location into
libxfs so that the kernel will avoid the sb update if the proposed
sunit/swidth changes would alter the sb_rootino estimation; and then
teach xfs_repair to retain the root directory even if the estimation
doesn't add up, as long as sb_rootino points to a directory whose '..'
entry points to itself.

This is an extraordinary way to destroy everything. Enjoy!
Comments and questions are, as always, welcome.

--D