linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] resize2fs: update checksums in the extent tree's relocated block
@ 2018-10-20 19:14 Theodore Ts'o
  2018-10-20 19:14 ` [PATCH 2/2] tests: move inode and its interior extent tree block Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Theodore Ts'o @ 2018-10-20 19:14 UTC (permalink / raw)
  To: Ext4 Developers List; +Cc: Theodore Ts'o

When shrinking an file system, and we need to relocate an inode, the
checksums in its extent tree must get updated to reflect its new inode
number.  When doing this, we need to do this *after* we update the
extent tree to reflect any blocks which need to be relocated due to
the file system shrink operation.

Otherwise, in the case where only an interior node of the extent tree
needs to get relocated, and none of the entries in that node need to
be adjusted, the checksum for that interior node is updated in the old
copy of that block, and then after the extent tree is updated to use
the new copy of that interior node, the extent tree is left with an
invalid checksum.

This is a relatively rare case, since it requires the following
conditions to be true:

*)  The metadata checksum feature must be enabled.
*)  An inode needs to be relocated.
*)  The inode needs to have an interior node.
*)  The block for that interior node needs to be relocated.
*)  None of blocks addressed by entries in that interior node needs
    to be relocated.

When all of these conditions are true, though, the file system is left
with corrupted with bad checksum for the extent tree block.

Addresses-Launchpad-Bug: 1798562

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Jean-Baptiste Lallement <jean-baptiste.lallement@ubuntu.com>
---
 resize/resize2fs.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index e89405042..38032e5c3 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -2244,31 +2244,20 @@ remap_blocks:
 		if (retval)
 			goto errout;
 
-		/* Rewrite extent block checksums with new inode number */
-		if (ext2fs_has_feature_metadata_csum(rfs->old_fs->super) &&
-		    (inode->i_flags & EXT4_EXTENTS_FL)) {
-			rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
-			retval = rewrite_extents(rfs->old_fs, new_inode);
-			rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
-			if (retval)
-				goto errout;
-		}
-
 		/*
 		 * Update inodes to point to new blocks; schedule directory
 		 * blocks for inode remapping.  Need to write out dir blocks
 		 * with new inode numbers if we have metadata_csum enabled.
 		 */
+		rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
 		if (ext2fs_inode_has_valid_blocks2(rfs->old_fs, inode) &&
 		    (rfs->bmap || pb.is_dir)) {
 			pb.ino = new_inode;
 			pb.old_ino = ino;
 			pb.has_extents = inode->i_flags & EXT4_EXTENTS_FL;
-			rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
 			retval = ext2fs_block_iterate3(rfs->old_fs,
 						       new_inode, 0, block_buf,
 						       process_block, &pb);
-			rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
 			if (retval)
 				goto errout;
 			if (pb.error) {
@@ -2283,6 +2272,14 @@ remap_blocks:
 			if (retval)
 				goto errout;
 		}
+
+		/* Fix up extent block checksums with the new inode number */
+		if (ext2fs_has_feature_metadata_csum(rfs->old_fs->super) &&
+		    (inode->i_flags & EXT4_EXTENTS_FL)) {
+			retval = rewrite_extents(rfs->old_fs, new_inode);
+			if (retval)
+				goto errout;
+		}
 	}
 
 	if (update_ea_inode_refs &&
@@ -2296,6 +2293,7 @@ remap_blocks:
 
 errout:
 	reset_com_err_hook();
+	rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
 	if (rfs->bmap) {
 		ext2fs_free_extent_table(rfs->bmap);
 		rfs->bmap = 0;
-- 
2.18.0.rc0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] tests: move inode and its interior extent tree block
  2018-10-20 19:14 [PATCH 1/2] resize2fs: update checksums in the extent tree's relocated block Theodore Ts'o
@ 2018-10-20 19:14 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2018-10-20 19:14 UTC (permalink / raw)
  To: Ext4 Developers List; +Cc: Theodore Ts'o

Add a test case for the bug fixed in 4b3038134baf: "resize2fs: update
checksums in the extent tree's relocated block"

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 tests/r_move_inode_int_extent/expect   |  15 +++++++++
 tests/r_move_inode_int_extent/image.gz | Bin 0 -> 20687 bytes
 tests/r_move_inode_int_extent/name     |   1 +
 tests/r_move_inode_int_extent/script   |  42 +++++++++++++++++++++++++
 4 files changed, 58 insertions(+)
 create mode 100644 tests/r_move_inode_int_extent/expect
 create mode 100644 tests/r_move_inode_int_extent/image.gz
 create mode 100644 tests/r_move_inode_int_extent/name
 create mode 100644 tests/r_move_inode_int_extent/script

diff --git a/tests/r_move_inode_int_extent/expect b/tests/r_move_inode_int_extent/expect
new file mode 100644
index 000000000..1de31d075
--- /dev/null
+++ b/tests/r_move_inode_int_extent/expect
@@ -0,0 +1,15 @@
+resize2fs test
+resize2fs test.img 8M
+Resizing the filesystem on test.img to 8192 (1k) blocks.
+The filesystem on test.img is now 8192 (1k) blocks long.
+
+Exit status is 0
+ 
+fsck -yf -E fixes_only -N test_filesys test.img
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 14/2048 files (0.0% non-contiguous), 1445/8192 blocks
+Exit status is 0
diff --git a/tests/r_move_inode_int_extent/image.gz b/tests/r_move_inode_int_extent/image.gz
new file mode 100644
index 0000000000000000000000000000000000000000..d5de18f259a033c4223184ac51d6f5f7c3a6d2da
GIT binary patch
literal 20687
zc-rlmYg7~2mdCYe8$@lmjVOwcrm+>F5hAT9uToI)0b+|_^NfIqio8Tbo~12_f`SSH
z3K$gul}8ZdA%Vo^DG(BoM+Af@2oVB72uTP@>fEYcch;JjJ8R8{`7pEQ)^Fv*zxF=o
zU;FH{>Qu5qNK#rfV%+Zbjl$$$%&jz`m*Q7Wd3bP3(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U_!w>J|psor&
z`FftJ0{|<k8%pbnp8-wt^s2@Yxa8Vn_2)`^bJin4Bf506mCprJbo8*TjSNuYKHofV
zO}}rQ$WjvwSMIv=_-#+v$oSJJ+8kK6GUK3k!pNA{KJ95>X7#LynJyc8?RoOoVh?Dp
zqW^>6frW$1Qw%Ba`0<u^TL;(yeQt0|<=}5GOQ~7}Wgc-(gEv9rvi~|tsgr-C^_3G&
zK~^6YbW=l<3>8-I3Drjmq)AjO;#82MqU+N~b(In42Ci@DQN%XRFB)xZgWt4k;f3RK
z3vFAY2>K$xal49uKIr9&;~MV3M8boW6q!{7?cGv<JX72-^hAWeN^x-he{<<mQJIOd
zY2Iv4ht5mi?qxSFypjwU^n8PN1_uWR2L}fS2L}fS2L}fS2L}fS2L}fS=fB}K+<(R9
bufJ7x0g`#WGTxDY1%kiz)v39Qip75i=o3@I

literal 0
Hc-jL100001

diff --git a/tests/r_move_inode_int_extent/name b/tests/r_move_inode_int_extent/name
new file mode 100644
index 000000000..64a55b559
--- /dev/null
+++ b/tests/r_move_inode_int_extent/name
@@ -0,0 +1 @@
+move inode and its interior extent tree block
diff --git a/tests/r_move_inode_int_extent/script b/tests/r_move_inode_int_extent/script
new file mode 100644
index 000000000..9c1a3928c
--- /dev/null
+++ b/tests/r_move_inode_int_extent/script
@@ -0,0 +1,42 @@
+if ! test -x $RESIZE2FS_EXE -o ! -x $DEBUGFS_EXE; then
+	echo "$test_name: $test_description: skipped (no debugfs/resize2fs)"
+	return 0
+fi
+
+IMAGE=$test_dir/image.gz
+FSCK_OPT="-yf -E fixes_only"
+OUT=$test_name.log
+EXP=$test_dir/expect
+
+gunzip < $IMAGE > $TMPFILE
+
+echo "resize2fs test" > $OUT.new
+
+echo "resize2fs test.img 8M" >> $OUT.new
+$RESIZE2FS $TMPFILE 8M >> $OUT.new 2>&1
+status=$?
+echo Exit status is $status >> $OUT.new
+
+echo " " >> $OUT.new
+echo fsck $FSCK_OPT -N test_filesys test.img >> $OUT.new
+$FSCK $FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
+echo Exit status is $status >> $OUT.new
+sed -f $cmd_dir/filter.sed $OUT.new > $OUT
+rm $TMPFILE $OUT.new
+
+#
+# Do the verification
+#
+
+cmp -s $OUT $EXP
+status=$?
+
+if [ "$status" = 0 ] ; then
+	echo "$test_name: $test_description: ok"
+	touch $test_name.ok
+else
+	echo "$test_name: $test_description: failed"
+	diff $DIFF_OPTS $EXP $OUT > $test_name.failed
+fi
+
+unset IMAGE FSCK_OPT OUT EXP
-- 
2.18.0.rc0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-21  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-20 19:14 [PATCH 1/2] resize2fs: update checksums in the extent tree's relocated block Theodore Ts'o
2018-10-20 19:14 ` [PATCH 2/2] tests: move inode and its interior extent tree block Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).