Skip to contentSkip to conversation

e2fsck: fix sparse bmap to extent conversion

PATCH In review Darrick J. Wong 3 participants 5 messages May 23, 2017 – May 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsck: fix sparse bmap to extent conversion

Marc,

If it's not too much trouble, can you build e2fsprogs with this patch and see if the conversion corruption problem is fixed? The supplied regression test has a realmode.bin I made with your script, but it's always good to re-verify with the bug filer.

--D

---
When e2fsck is trying to convert a sparse block-mapped file to an extent file, we incorrectly merge block mappings that are physically contiguous but not logically contiguous because of insufficient checking with the extent we're constructing. Therefore, compare the logical offsets for contiguity as well.

---
 e2fsck/extents.c                     |    3 +
 tests/f_convert_bmap_sparse/expect.1 |   24 +++++++
 tests/f_convert_bmap_sparse/expect.2 |   12 +++
 tests/f_convert_bmap_sparse/image.gz |  Bin
 tests/f_convert_bmap_sparse/name     |    1 
 tests/f_convert_bmap_sparse/script   |  117 ++++++++++++++++++++++++++++++++++
 6 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 tests/f_convert_bmap_sparse/expect.1
 create mode 100644 tests/f_convert_bmap_sparse/expect.2
 create mode 100644 tests/f_convert_bmap_sparse/image.gz
 create mode 100644 tests/f_convert_bmap_sparse/name
 create mode 100644 tests/f_convert_bmap_sparse/script
e2fsck/extents.c +2 -1
index 98cf7c3..ef3146d 100644
@@ -171,7 +171,8 @@ static int find_blocks(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt,
 					     list->count - 1;
 		blk64_t end = last->e_len + 1;
 
-		if (last->e_pblk + last->e_len == *blocknr &&
+		if (last->e_lblk + last->e_len == blockcnt &&
+		    last->e_pblk + last->e_len == *blocknr &&
 		    end < (1ULL << 32)) {
 			last->e_len++;
 #ifdef DEBUG
tests/f_convert_bmap_sparse/expect.1 new file +24 -0
new file mode 100644
index 0000000..095fb2b
@@ -0,0 +1,24 @@
+debugfs: stat /realmode.bin
+Inode: 12   Type: regular    Mode:  0775   Flags: 0x0
+Generation: 2022334337    Version: 0x00000001
+User:  1000   Group:  1000   Size: 21080
+File ACL: 0
+Links: 1   Blockcount: 16
+Fragment:  Address: 0    Number: 0    Size: 0
+ctime: 0x5924849d -- Tue May 23 18:51:09 2017
+atime: 0x59247d36 -- Tue May 23 18:19:34 2017
+mtime: 0x591e1764 -- Thu May 18 21:51:32 2017
+BLOCKS:
+(0):513, (4-8):514-518, (IND):58, (20):2005
+TOTAL: 8
+
+Pass 1: Checking inodes, blocks, and sizes
+Pass 1E: Optimizing extent trees
+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: 12/256 files (8.3% non-contiguous), 65/2048 blocks
+Exit status is 0
tests/f_convert_bmap_sparse/expect.2 new file +12 -0
new file mode 100644
index 0000000..e5a3d44
@@ -0,0 +1,12 @@
+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: 12/256 files (8.3% non-contiguous), 65/2048 blocks
+Exit status is 0
+debugfs: ex /realmode.bin
+Level Entries       Logical      Physical Length Flags
+ 0/ 0   1/  3     0 -     0   513 -   513      1 
+ 0/ 0   2/  3     4 -     8   514 -   518      5 
+ 0/ 0   3/  3    20 -    20  2005 -  2005      1 
tests/f_convert_bmap_sparse/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1f594fd4df402b5d50a78962bbebb20e9eae2032
GIT binary patch
tests/f_convert_bmap_sparse/name new file +1 -0
new file mode 100644
index 0000000..dc3b985
@@ -0,0 +1 @@
+convert sparse blockmap file to extents file
tests/f_convert_bmap_sparse/script new file +117 -0

117 lines not on this page · raw message

#1 lore raw

Hi Darrick,

Thanks very much for the patch. I applied it to the git-master and built e2fsprogs. The new "make check" test for "f_convert_bmap_sparse" passes, and indeed my test-case script now passes.
However the test for "f_detect_junk" is failing for me:

---

$ cat f_detect_junk.failed
--- ../../tests/f_detect_junk/expect    2017-05-24 08:58:29.025273717 +0000
+++ f_detect_junk.log   2017-05-24 09:23:41.426168239 +0000
@@ -13,6 +13,7 @@

*** debugfs
test.img: Bad magic number in super-block while opening filesystem
+Checksum errors in superblock! Retrying...
*** tune2fs
../misc/tune2fs: Bad magic number in super-block while trying to open
test.img
*** mke2fs
---

I think the expect test maybe just needs updating.

I will now try the patched e2fsck on the full data-migration process I'm doing and report back. This will take a few hours.

Kind Regards,
Marc

#2 lore raw

I've applied this patch to the maint branch (with a slight adjustment to the expect file for f_convert_bmap_sprase), and then merged it into the next/master branches (with the adjustment removed), thanks.

I wasn't able see any problems with f_detect_junk, on either the maint or the next branch. So I'm not sure what issue Marc was seeing there.

- Ted

#3 lore raw

Thank you both for the rapid turn-around with this patch.
I can confirm it solves the original problem with the in-place ext3 to ext4 conversion I'm doing.

As regards the f_detect_junk test, it seems a change in "debugfs" is emitting an extra message "Checksum errors in superblock! Retrying..." which is not present in the "expect" output.
It appears this was introduced in commit
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=bf615bb0ccadeb1579463f94a2a4752e7ec53f57

Perhaps debugfs could print that message to stderr so it's not picked up?

I'm testing with the git master branch, but my git skills are weak so I could well be doing something wrong!

Kind Regards,
Marc

#4 lore raw
Quoted 6 lines · Marc Thomas

As regards the f_detect_junk test, it seems a change in "debugfs" is emitting an extra message "Checksum errors in superblock! Retrying..." which is not present in the "expect" output.
It appears this was introduced in commit
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=bf615bb0ccadeb1579463f94a2a4752e7ec53f57

Ah, now I see. This was not a regression from Darrick's patch, but rather a pre-existing failure. One that I hadn't noticed because I don't have libmagic-dev installed on my new development laptop. :-)

I've checked in a fix into my repository.

- Ted

Quoted 1 line

From 1a4c6384c438f4ca4a0eae9a21c4d465cb7275ef Mon Sep 17 00:00:00 2001

From: Theodore Ts'o <[email protected]>
Date: Thu, 25 May 2017 13:11:40 -0400
Subject: [PATCH] tests: fix expected output for f_detect_junk

The expect files for f_detect_junk had gotten out of sync with the code base, and since this test is optional (it depends on libmagic being installed), we hadn't noticed.

---
 tests/f_detect_junk/expect           | 1 +
 tests/f_detect_junk/expect.nodebugfs | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
tests/f_detect_junk/expect +1 -0
index 4295886e..8febb84d 100644
@@ -13,6 +13,7 @@ is corrupt, and you might try running e2fsck with an alternate superblock:
 
 *** debugfs
 test.img: Bad magic number in super-block while opening filesystem
+Checksum errors in superblock!  Retrying...
 *** tune2fs
 ../misc/tune2fs: Bad magic number in super-block while trying to open test.img
 *** mke2fs
tests/f_detect_junk/expect.nodebugfs +0 -2
index 0d4ba54b..b528046c 100644
@@ -11,11 +11,9 @@ is corrupt, and you might try running e2fsck with an alternate superblock:
  or
     e2fsck -b 32768 <device>
 
-test.img contains `PNG image data, 148 x 31, 8-bit/color RGBA, non-interlaced' data
 *** debugfs
 *** tune2fs
 ../misc/tune2fs: Bad magic number in super-block while trying to open test.img
-test.img contains `PNG image data, 148 x 31, 8-bit/color RGBA, non-interlaced' data
 *** mke2fs
 Creating filesystem with 16384 1k blocks and 4096 inodes
 Superblock backups stored on blocks: 
Signature · 1 line
2.11.0.rc0.7.gbe5a750