Skip to contentSkip to conversation

e2fsck: don't flush the FS unless it's actually dirty

PATCH Applied Darrick J. Wong 2 participants 3 messages Aug 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 e2fsck: don't flush the FS unless it's actually dirty

ext2fs_flush2() unconditionally writes the block group descriptors to disk even if the underlying FS isn't marked dirty. This causes the following error message on a fsck -n run:

# e2fsck -fn /tmp/a
e2fsck 1.43-WIP (09-Jul-2014)
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
Error writing block 2 (Attempt to write block to filesystem resulted in short write).  Ignore error? no

Error writing block 2 (Attempt to write block to filesystem resulted in short write). Ignore error? no

Error writing file system info: Attempt to write block to filesystem resulted in short write

Since ext2fs_close2() only calls flush if the dirty flag is set, modify e2fsck to exhibit the same behavior so that we don't spit out write errors for a read only check.

v2: Fix test to use $CRCSUM instead of md5sum.

---
 e2fsck/unix.c                  |    8 ++++---
 tests/f_readonly_fsck/expect   |   11 ++++++++++
 tests/f_readonly_fsck/image.gz |  Bin
 tests/f_readonly_fsck/name     |    1 +
 tests/f_readonly_fsck/script   |   46 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 3 deletions(-)
 create mode 100644 tests/f_readonly_fsck/expect
 create mode 100644 tests/f_readonly_fsck/image.gz
 create mode 100644 tests/f_readonly_fsck/name
 create mode 100644 tests/f_readonly_fsck/script
e2fsck/unix.c +5 -3
index 78bf3f4..6b0ca96 100644
@@ -1762,9 +1762,11 @@ no_journal:
 	}
 
 	e2fsck_write_bitmaps(ctx);
-	pctx.errcode = ext2fs_flush(ctx->fs);
-	if (pctx.errcode)
-		fix_problem(ctx, PR_6_FLUSH_FILESYSTEM, &pctx);
+	if (fs->flags & EXT2_FLAG_DIRTY) {
+		pctx.errcode = ext2fs_flush(ctx->fs);
+		if (pctx.errcode)
+			fix_problem(ctx, PR_6_FLUSH_FILESYSTEM, &pctx);
+	}
 	pctx.errcode = io_channel_flush(ctx->fs->io);
 	if (pctx.errcode)
 		fix_problem(ctx, PR_6_IO_FLUSH, &pctx);
tests/f_readonly_fsck/expect new file +11 -0
new file mode 100644
index 0000000..994dfa4
@@ -0,0 +1,11 @@
+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
+Free blocks count wrong (4294968254, counted=958).
+Fix? no
+
+test_filesys: 11/256 files (9.1% non-contiguous), 18446744069414585410/2048 blocks
+Exit status is 0
+crc did not change.  2466215161
tests/f_readonly_fsck/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..59f9cd91144b4b1978a59551f49e17f8740763e3
GIT binary patch
tests/f_readonly_fsck/name new file +1 -0
new file mode 100644
index 0000000..97ab428
@@ -0,0 +1 @@
+ensure that a readonly check doesn't modify the fs
tests/f_readonly_fsck/script new file +46 -0

46 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Darrick J. Wong

ext2fs_flush2() unconditionally writes the block group descriptors to disk even if the underlying FS isn't marked dirty. This causes the following error message on a fsck -n run:...

v2: Fix test to use $CRCSUM instead of md5sum.

Thanks, applied.

As it turns out, I was wrong; there were other users of md5sum in the tests that I had forgotten about. Now that we have crcsum, it makes sense to convert them over to use md5sum as well, so I'll do that.

Thanks again,

- Ted

#2 lore raw

PATCH 1/1 tests: convert use of md5sum to crcsum

The following tests were using md5sum: i_e2image, u_mke2fs, and u_tune2fs. Convert them to use crcsum for better portability (not all environments have md5sum; some might have sha1sum instead :-)

For our purposes crcsum is quite sufficient.

---
 tests/i_e2image/i_e2image.crc | 15 +++++++++++++++
 tests/i_e2image/i_e2image.md5 | 15 ---------------
 tests/i_e2image/script        | 24 ++++++++++++------------
 tests/u_mke2fs/script         | 14 +++++++-------
 tests/u_tune2fs/script        | 14 +++++++-------
 5 files changed, 41 insertions(+), 41 deletions(-)
 create mode 100644 tests/i_e2image/i_e2image.crc
 delete mode 100644 tests/i_e2image/i_e2image.md5
tests/i_e2image/i_e2image.crc new file +15 -0
new file mode 100644
index 0000000..02a8464
@@ -0,0 +1,15 @@
+i_e2image/image1024.orig
+2161078647	image1024.orig
+467277198	_image.raw
+2164212449	_image.qcow2
+467277198	_image.qcow2.raw
+i_e2image/image2048.orig
+672740642	image2048.orig
+3688408350	_image.raw
+3821412753	_image.qcow2
+3688408350	_image.qcow2.raw
+i_e2image/image4096.orig
+4077552412	image4096.orig
+4159471388	_image.raw
+636354894	_image.qcow2
+4159471388	_image.qcow2.raw
tests/i_e2image/i_e2image.md5 deleted +0 -15
deleted file mode 100644
index f96e721..0000000
@@ -1,15 +0,0 @@
-i_e2image/image1024.orig
-d34914e0da07bdae80ab02288118fae2  image1024.orig
-bbef4e50d7237546c7d9c521d3df5b68  _image.raw
-1d4eb39452bed097dcd2c5bcd57180e6  _image.qcow2
-bbef4e50d7237546c7d9c521d3df5b68  _image.qcow2.raw
-i_e2image/image2048.orig
-aa9f702de181188f2a6d2c5158686c09  image2048.orig
-e6f8410d0690ef551bee0c2c0c642d8c  _image.raw
-dbbd9aa97c6c946b9122586bbd2a325a  _image.qcow2
-e6f8410d0690ef551bee0c2c0c642d8c  _image.qcow2.raw
-i_e2image/image4096.orig
-1d3e7f15b2ce9ca07aa23c32951c5176  image4096.orig
-734119dd8f240a33704139f8cdd8127c  _image.raw
-85fdbf5a8451b24b36ab82a02196deb9  _image.qcow2
-734119dd8f240a33704139f8cdd8127c  _image.qcow2.raw
tests/i_e2image/script +12 -12
index adf59a4..c5b0666 100644
@@ -7,42 +7,42 @@ RAW_IMG=_image.raw
 QCOW2_IMG=_image.qcow2
 QCOW2_TO_RAW=_image.qcow2.raw
 OUT=$test_name.log
-MD5=$SRCDIR/$test_name/$test_name.md5
-MD5_TMP=$test_name.md5.tmp
+CRC=$SRCDIR/$test_name/$test_name.crc
+CRC_TMP=$test_name.crc.tmp
 
-rm -f $test_name/_image.* $MD5_TMP $OUT >/dev/null 2>&1
+rm -f $test_name/_image.* $CRC_TMP $OUT >/dev/null 2>&1
 
 (
 for i in $ORIG_IMAGES; do
 	ORIG_IMG=$test_name/$i
-	echo $ORIG_IMG >> $MD5_TMP
+	echo $ORIG_IMG >> $CRC_TMP
 
 	bunzip2 < $SRCDIR/$ORIG_IMG.bz2 > $i
-	md5sum $i >> $MD5_TMP
+	echo "$($CRCSUM $i)	$i" >> $CRC_TMP
 
 	rm -f $RAW_IMG
 	echo "e2image -r $ORIG_IMG $RAW_IMG"
 	$E2IMAGE      -r $i $RAW_IMG
-	md5sum $RAW_IMG >> $MD5_TMP
+	echo "$($CRCSUM $RAW_IMG)	$RAW_IMG"  >> $CRC_TMP
 
 	echo "e2image -Q $ORIG_IMG $QCOW2_IMG"
 	$E2IMAGE      -Q $i $QCOW2_IMG
-	md5sum $QCOW2_IMG >> $MD5_TMP
+	echo "$($CRCSUM $QCOW2_IMG)	$QCOW2_IMG"  >> $CRC_TMP
 
 	rm -f $QCOW2_TO_RAW
 	echo "e2image -r $QCOW2_IMG $QCOW2_TO_RAW"
 	$E2IMAGE      -r $i $QCOW2_TO_RAW
-	md5sum $QCOW2_TO_RAW >> $MD5_TMP
+	echo "$($CRCSUM $QCOW2_TO_RAW)	$QCOW2_TO_RAW" >> $CRC_TMP
 
 	rm -f $i
 done
 ) >> $OUT 2>&1
 
-echo "md5sums:" >> $OUT
-cat $MD5_TMP >> $OUT
+echo "checksum:" >> $OUT
+cat $CRC_TMP >> $OUT
 echo "" >> $OUT
 
-diff $MD5 $MD5_TMP >> $OUT 2>&1
+diff $CRC $CRC_TMP >> $OUT 2>&1
 
 if [ $? -eq 0 ]; then
 	echo "$test_name: $test_description: ok"
@@ -52,7 +52,7 @@ else
 	echo "$test_name: $test_description: failed"
 fi
 
-rm -f _image.* $MD5_TMP >/dev/null 2>&1
+rm -f _image.* $CRC_TMP >/dev/null 2>&1
 
 else #if test -x $E2IMAGE_EXE; then
 	echo "$test_name: $test_description: skipped"
tests/u_mke2fs/script +7 -7
index fcf5eae..d249ddd 100644
@@ -11,19 +11,19 @@ dd if=/dev/zero of=$TMPFILE bs=1k count=512 > /dev/null 2>&1
 
 echo mke2fs -q -F -o Linux -b 1024 test.img  > $OUT
 $MKE2FS -F -o Linux -I 128 -b 1024 $TMPFILE  >> $OUT 2>&1
-md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum before mke2fs $md5 >> $OUT
+crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM before mke2fs $crc >> $OUT
 
 echo using mke2fs to test e2undo >> $OUT
 $MKE2FS -q -F -o Linux -I 256 -O uninit_bg -E lazy_itable_init=1 -b 1024 $TMPFILE  >> $OUT 2>&1
-new_md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum after mke2fs $new_md5 >> $OUT
+new_crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM after mke2fs $new_crc >> $OUT
 
 $E2UNDO_EXE  $TDB_FILE $TMPFILE  >> $OUT 2>&1
-new_md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum after e2undo $new_md5 >> $OUT
+new_crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM after e2undo $new_crc >> $OUT
 
-if [ $md5 = $new_md5 ]; then
+if [ $crc = $new_crc ]; then
 	echo "$test_name: $test_description: ok"
 	touch $test_name.ok
 else
tests/u_tune2fs/script +7 -7
index 4cc1e0c..a443f5a 100644
@@ -11,19 +11,19 @@ dd if=/dev/zero of=$TMPFILE bs=1k count=512 > /dev/null 2>&1
 
 echo mke2fs -q -F -o Linux -b 1024 $TMPFILE  > $OUT
 $MKE2FS -q -F -o Linux -I 128 -b 1024 $TMPFILE  >> $OUT 2>&1
-md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum before tune2fs $md5 >> $OUT
+crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM before tune2fs $crc >> $OUT
 
 echo using tune2fs to test e2undo >> $OUT
 $TUNE2FS -I 256 $TMPFILE  >> $OUT 2>&1
-new_md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum after tune2fs $new_md5 >> $OUT
+new_crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM after tune2fs $new_crc >> $OUT
 
 $E2UNDO_EXE  $TDB_FILE $TMPFILE  >> $OUT 2>&1
-new_md5=`md5sum $TMPFILE | cut -d " " -f 1`
-echo md5sum after e2undo $new_md5 >> $OUT
+new_crc=`$CRCSUM $TMPFILE`
+echo $CRCSUM after e2undo $new_crc >> $OUT
 
-if [ $md5 = $new_md5 ]; then
+if [ $crc = $new_crc ]; then
 	echo "$test_name: $test_description: ok"
 	touch $test_name.ok
 else
Signature · 1 line
2.0.0