Skip to contentSkip to conversation

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

PATCH Superseded Darrick J. Wong 2 participants 2 messages Aug 11, 2014 – Aug 12, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

Add a test case to check that readonly fsck runs really don't change the file in a perceptible way.

---
 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..dc0c680
@@ -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
+MD5 did not change.  f52727a359c890d4704aaa06af669a13  -
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

Hi Darrick, thanks for the patch.

Could you change the test to use $CRCSUM instead of md5sum. I'd prefer not to introduce an additional dependency to e2fsprogs, and using a crc checksum should be sufficient for our purposes here.

Thanks!!

- Ted