From: Darrick J. Wong Date: Mon, 8 Sep 2014 23:12:02 +0000 (-0700) Subject: libext2fs: write_journal_inode should check iterate return value X-Git-Tag: v1.43-WIP-2015-05-18~205 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc06f25a101f31a7b4729f5da9fcf78ff6b9c969;p=thirdparty%2Fe2fsprogs.git libext2fs: write_journal_inode should check iterate return value When creating a journal inode, check the return value from block_iterate3() because otherwise we fail to capture errors such as being unable to allocate an extent tree block, which leads to e2fsck creating broken journals. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 96b6d360e..85f86bf9b 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -365,6 +365,8 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND, 0, mkjournal_proc, &es); + if (retval) + goto errout; if (es.err) { retval = es.err; goto errout; diff --git a/tests/f_jnl_etb_alloc_fail/expect.1 b/tests/f_jnl_etb_alloc_fail/expect.1 new file mode 100644 index 000000000..8f4ebbbd8 --- /dev/null +++ b/tests/f_jnl_etb_alloc_fail/expect.1 @@ -0,0 +1,31 @@ +Superblock has an invalid journal (inode 8). +Clear? yes + +*** ext3 journal has been deleted - filesystem is now ext2 only *** + +Superblock has_journal flag is clear, but a journal is present. +Clear? yes + +Pass 1: Checking inodes, blocks, and sizes +Journal inode is not in use, but contains data. Clear? yes + +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +Block bitmap differences: -(32--33) -(35--49) -(83--511) -(513--1087) -1089 +Fix? yes + +Free blocks count wrong for group #0 (0, counted=1022). +Fix? yes + +Free blocks count wrong (0, counted=1022). +Fix? yes + +Recreate journal? yes + +Creating journal (1024 blocks): Could not allocate block in ext2 filesystem: while trying to create journal + +test_filesys: ***** FILE SYSTEM WAS MODIFIED ***** +test_filesys: 12/128 files (8.3% non-contiguous), 2048/2048 blocks +Exit status is 1 diff --git a/tests/f_jnl_etb_alloc_fail/expect.2 b/tests/f_jnl_etb_alloc_fail/expect.2 new file mode 100644 index 000000000..69859dd32 --- /dev/null +++ b/tests/f_jnl_etb_alloc_fail/expect.2 @@ -0,0 +1,20 @@ +Pass 1: Checking inodes, blocks, and sizes +Journal inode is not in use, but contains data. Clear? yes + +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +Block bitmap differences: -(32--33) -(35--49) -(83--511) -(513--1087) -1089 +Fix? yes + +Free blocks count wrong for group #0 (0, counted=1022). +Fix? yes + +Free blocks count wrong (0, counted=1022). +Fix? yes + + +test_filesys: ***** FILE SYSTEM WAS MODIFIED ***** +test_filesys: 12/128 files (8.3% non-contiguous), 1026/2048 blocks +Exit status is 1 diff --git a/tests/f_jnl_etb_alloc_fail/image.gz b/tests/f_jnl_etb_alloc_fail/image.gz new file mode 100644 index 000000000..4cf2dbf40 Binary files /dev/null and b/tests/f_jnl_etb_alloc_fail/image.gz differ diff --git a/tests/f_jnl_etb_alloc_fail/name b/tests/f_jnl_etb_alloc_fail/name new file mode 100644 index 000000000..7651fdc1f --- /dev/null +++ b/tests/f_jnl_etb_alloc_fail/name @@ -0,0 +1 @@ +can't allocate extent tree block while recreating journal