e2fsck: fix sliding the directory block down on bigalloc

If we find a hole in a directory on a bigalloc filesystem, we need to
obey the cluster alignment rules when collapsing the gap to avoid
later complaints.

Specifically, the calculation of the new logical cluster number was
incorrect, and we need to ensure that the logical cluster alignment
respects the physical cluster alignment, since we've concluded that
the extent's logical block number is wrong.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
crypto
Darrick J. Wong 2014-09-18 21:29:21 -04:00 committed by Theodore Ts'o
parent 7936236065
commit 7ef1b8b424
5 changed files with 83 additions and 3 deletions

View File

@ -2568,9 +2568,9 @@ report_problem:
new_lblk = pb->last_block + 1;
if (EXT2FS_CLUSTER_RATIO(ctx->fs) > 1)
new_lblk = ((new_lblk +
EXT2FS_CLUSTER_RATIO(ctx->fs)) &
EXT2FS_CLUSTER_MASK(ctx->fs)) |
(extent.e_lblk &
EXT2FS_CLUSTER_RATIO(ctx->fs) - 1) &
~EXT2FS_CLUSTER_MASK(ctx->fs)) |
(extent.e_pblk &
EXT2FS_CLUSTER_MASK(ctx->fs));
pctx->blk = extent.e_lblk;
pctx->blk2 = new_lblk;

68
tests/f_holedir4/expect.1 Normal file
View File

@ -0,0 +1,68 @@
Pass 1: Checking inodes, blocks, and sizes
Directory inode 12 block 211 should be at block 25. Fix? yes
Inode 12, i_size is 4096, should be 110592. Fix? yes
Inode 12, i_blocks is 128, should be 256. Fix? yes
Pass 2: Checking directory structure
Directory inode 12 has an unallocated block #2. Allocate? yes
Directory inode 12 has an unallocated block #3. Allocate? yes
Directory inode 12 has an unallocated block #4. Allocate? yes
Directory inode 12 has an unallocated block #5. Allocate? yes
Directory inode 12 has an unallocated block #6. Allocate? yes
Directory inode 12 has an unallocated block #7. Allocate? yes
Directory inode 12 has an unallocated block #8. Allocate? yes
Directory inode 12 has an unallocated block #9. Allocate? yes
Directory inode 12 has an unallocated block #10. Allocate? yes
Directory inode 12 has an unallocated block #11. Allocate? yes
Directory inode 12 has an unallocated block #12. Allocate? yes
Directory inode 12 has an unallocated block #13. Allocate? yes
Directory inode 12 has an unallocated block #14. Allocate? yes
Directory inode 12 has an unallocated block #15. Allocate? yes
Directory inode 12 has an unallocated block #16. Allocate? yes
Directory inode 12 has an unallocated block #17. Allocate? yes
Directory inode 12 has an unallocated block #18. Allocate? yes
Directory inode 12 has an unallocated block #19. Allocate? yes
Directory inode 12 has an unallocated block #20. Allocate? yes
Directory inode 12 has an unallocated block #21. Allocate? yes
Directory inode 12 has an unallocated block #22. Allocate? yes
Directory inode 12 has an unallocated block #23. Allocate? yes
Directory inode 12 has an unallocated block #24. Allocate? yes
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #0 (26, counted=25).
Fix? yes
Free blocks count wrong (416, counted=400).
Fix? yes
test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
test_filesys: 13/32 files (7.7% non-contiguous), 112/512 blocks
Exit status is 1

11
tests/f_holedir4/expect.2 Normal file
View File

@ -0,0 +1,11 @@
Pass 1: Checking inodes, blocks, and sizes
Inode 12, i_blocks is 3072, should be 128. Fix? yes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
test_filesys: 13/32 files (0.0% non-contiguous), 112/512 blocks
Exit status is 1

BIN
tests/f_holedir4/image.gz Normal file

Binary file not shown.

1
tests/f_holedir4/name Normal file
View File

@ -0,0 +1 @@
bigalloc directory with hole and misaligned extent after hole