Skip to contentSkip to conversation

e2fsck: handle preallocation for large PAGE_SIZE

PATCH New Andreas Dilger 1 participant 1 message Sep 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsck: handle preallocation for large PAGE_SIZE

Fix handling of block preallocation support in cases where the kernel PAGE_SIZE is larger than the filesystem blocksize (e.g. Lustre+PPC).

There was an existing test to try and verify this behaviour using 1KB blocksize, but it had a off-by-one error using pb.last_init_lblock (which is 3 for a 4KB file) and was over-zealous in "fixing" the size of inodes with 4KB of data blocks allocated.

---
 e2fsck/pass1.c             |   10 +++++++---
 tests/f_eofblocks/expect.1 |    6 ++----
 tests/f_eofblocks/expect.2 |    2 +-
 tests/f_eofblocks/image.gz |  Bin 1364 -> 1372 bytes
 4 files changed, 10 insertions(+), 8 deletions(-)
e2fsck/pass1.c +7 -3
index 50a8b99..898b7d0 100644
@@ -2323,10 +2323,14 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
 
 		size = EXT2_I_SIZE(inode);
 		if ((pb.last_init_lblock >= 0) &&
-		    /* allow allocated blocks to end of PAGE_SIZE */
+		    /* if size is smaller than expected by the block count,
+		     * allow allocated blocks to end of PAGE_SIZE.
+		     * last_init_lblock is the last in-use block, so it is
+		     * the minimum expected file size. */
 		    (size < (__u64)pb.last_init_lblock * fs->blocksize) &&
-		    (pb.last_init_lblock / blkpg * blkpg != pb.last_init_lblock ||
-		     size < (__u64)(pb.last_init_lblock & ~(blkpg-1)) *
+		    ((pb.last_init_lblock + 1) / blkpg * blkpg !=
+		     (pb.last_init_lblock + 1) ||
+		     size < (__u64)(pb.last_init_lblock & ~(blkpg - 1)) *
 		     fs->blocksize))
 			bad_size = 3;
 		else if (!(extent_fs && (inode->i_flags & EXT4_EXTENTS_FL)) &&
tests/f_eofblocks/expect.1 +2 -4
index 2e9133e..3422248 100644
@@ -1,7 +1,5 @@
 Pass 1: Checking inodes, blocks, and sizes
-Inode 30, i_size is 2048, should be 4096.  Fix? yes
-
-Inode 31, i_size is 2048, should be 4096.  Fix? yes
+Inode 31, i_size is 2048, should be 6144.  Fix? yes
 
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
@@ -9,5 +7,5 @@ Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 31/56 files (29.0% non-contiguous), 83/400 blocks
+test_filesys: 31/56 files (29.0% non-contiguous), 85/400 blocks
 Exit status is 1
tests/f_eofblocks/expect.2 +1 -1
index 2a2bca5..0cce314 100644
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 31/56 files (29.0% non-contiguous), 83/400 blocks
+test_filesys: 31/56 files (29.0% non-contiguous), 85/400 blocks
 Exit status is 0
tests/f_eofblocks/image.gz binary +0 -0
index 2586a6a7670ad609ba7e66911a8f7a8f4df96321..e1177b3a7d6f33ce135fe91c7b6d11bbb1ee09a3 100644
GIT binary patch
Signature · 1 line
1.7.3.4