ext4: Test for s_inodes_count overflow during fs resize
PATCH 1/1 ext4: Test for s_inodes_count overflow during fs resize
Test for overflow of s_inodes_count during filesystem resizing.
--- common/config | 1 + common/rc | 7 ++++ tests/ext4/033 | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/033.out | 6 +++ tests/ext4/group | 1 + 5 files changed, 133 insertions(+) create mode 100755 tests/ext4/033 create mode 100644 tests/ext4/033.out
common/config +1 -0
@@ -170,6 +170,7 @@ export INDENT_PROG="`set_prog_path indent`" export XFS_COPY_PROG="`set_prog_path xfs_copy`" export FSTRIM_PROG="`set_prog_path fstrim`" export DUMPE2FS_PROG="`set_prog_path dumpe2fs`" +export RESIZE2FS_PROG="`set_prog_path resize2fs`" export FIO_PROG="`set_prog_path fio`" export FILEFRAG_PROG="`set_prog_path filefrag`" export E4DEFRAG_PROG="`set_prog_path e4defrag`"
common/rc +7 -0
@@ -3176,6 +3176,13 @@ _require_dumpe2fs() fi } +_require_resize2fs() +{ + if [ -z "$RESIZE2FS_PROG" ]; then + _notrun "This test requires resize2fs utility." + fi +} + _require_ugid_map() { if [ ! -e /proc/self/uid_map ]; then
tests/ext4/033 new file +118 -0
118 lines not on this page · raw message
tests/ext4/033.out new file +6 -0
@@ -0,0 +1,6 @@ +QA output created by 033 +Figure out block size +Format huge device +Resizing to inode limit + 1... +Resizing to max group count... +Resizing device size...
tests/ext4/group +1 -0
@@ -35,6 +35,7 @@ 030 auto quick dax 031 auto quick dax 032 auto quick ioctl resize +033 auto ioctl resize 271 auto rw quick 301 aio auto ioctl rw stress defrag 302 aio auto ioctl rw stress defrag
Signature · 1 line
2.13.6
Quoted 30 lines · Jan Kara
Test for overflow of
s_inodes_countduring filesystem resizing.Signed-off-by Jan Kara <[email protected]>--- common/config | 1 + common/rc | 7 ++++ tests/ext4/033 | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/033.out | 6 +++ tests/ext4/group | 1 + 5 files changed, 133 insertions(+) create mode 100755 tests/ext4/033 create mode 100644 tests/ext4/033.outcommon/config +1
-0@@ -170,6 +170,7 @@ export INDENT_PROG="`set_prog_path indent`" export XFS_COPY_PROG="`set_prog_path xfs_copy`" export FSTRIM_PROG="`set_prog_path fstrim`" export DUMPE2FS_PROG="`set_prog_path dumpe2fs`" +export RESIZE2FS_PROG="`set_prog_path resize2fs`" export FIO_PROG="`set_prog_path fio`" export FILEFRAG_PROG="`set_prog_path filefrag`" export E4DEFRAG_PROG="`set_prog_path e4defrag`"common/rc +0
-0
common/rc _require_dumpe2fs() · line 3185
Quoted 10 lines
common/rc +7
-0@@ -3176,6 +3176,13 @@ _require_dumpe2fs() fi } +_require_resize2fs() +{ + if [ -z "$RESIZE2FS_PROG" ]; then + _notrun "This test requires resize2fs utility." + fi +} +
I think this could simply be done by
_require_command "$RESIZE2FS_PROG" resize2fs
in the test.
And this could be added to other existing resize2fs tests too, e.g. ext4/010, ext4/032 and ext4/306, and convert 'resize2fs' to '$RESIZE2FS_PROG', in a follow-up patch.
Quoted 37 lines
common/rc +0
-0_require_ugid_map() { if [ ! -e /proc/self/uid_map ]; thentests/ext4/033 new file +28
-0@@ -0,0 +1,118 @@ +#! /bin/bash +# FS QA Test 033 +# +# Test s_inodes_count overflow for huge filesystems. This bug was fixed +# by commit "ext4: Forbid overflowing inode count when resizing". +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Jan Kara, SUSE. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" +
tests/ext4/033 line 38
Quoted 10 lines
tests/ext4/033 new file +10
-0+here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + _dmhugedisk_cleanup + # Recreate scratch so that _check_filesystems() does not complain + _scratch_mkfs >/dev/null 2>&1
This could be done by calling _require_scratch_nocheck, instead of _require_scratch.
But I'm not sure why it's expected to leave a corrupted fs behind after?
Quoted 19 lines
tests/ext4/033 new file +19
-0+ cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/dmhugedisk + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs ext4 +_supported_os Linux +_require_scratch +_require_dmhugedisk +_require_dumpe2fs +_require_resize2fs
tests/ext4/033 line 67
Quoted 10 lines
tests/ext4/033 new file +10
-0+ +# Figure out block size +echo "Figure out block size" +_scratch_mkfs >/dev/null 2>&1 +_scratch_mount >> $seqres.full + +testdir=$SCRATCH_MNT/test-$seq +blksz="$(_get_block_size $SCRATCH_MNT)" + +umount $SCRATCH_MNT
_scratch_unmount
tests/ext4/033 line 73
Quoted 6 lines
tests/ext4/033 new file +6
-0+ +INODES_PER_GROUP=$((blksz*8)) +GROUP_BLOCKS=$((blksz*8)) + +# Number of groups to overflow s_inodes_count +LIMIT_GROUPS=$(((1<<32)/INODES_PER_GROUP))
Use lower case for local variables?
tests/ext4/033 line 77
Quoted 4 lines
tests/ext4/033 new file +4
-0+ +# Create device huge enough so that overflowing inode count is possible +echo "Format huge device" +_dmhugedisk_init $(((LIMIT_GROUPS + 16)*GROUP_BLOCKS*(blksz/512)))
I think we need to require a minimum size on SCRATCH_DEV too, otherwise I got mkfs failure when testing with 1k block size on a 10G SCRATCH_DEV, the backing device didn't have enough space to store the metadata.
After assigning a 25G device to SCRATCH_DEV, mkfs with 1k block size passed, but test still failed in the end, I'm not sure what's going wrong this time..
--- tests/ext4/033.out 2018-05-28 22:12:56.234867728 +0800 +++ /root/workspace/xfstests/results//ext4_1k/ext4/033.out.bad
2018-05-29 00:20:56.907283189 +0800
@@ -3,4 +3,4 @@
Format huge device
Resizing to inode limit + 1...
Resizing to max group count...
-Resizing device size...
+Resizing failed!
And dmesg showed:
[166934.718495] run fstests ext4/033 at 2018-05-29 00:07:04 [166937.651454] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: acl,user_xattr [167629.640111] EXT4-fs (dm-11): mounted filesystem with ordered data mode. Opts: (null) [167632.068897] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294967296 blocks [167632.069900] EXT4-fs warning (device dm-11): ext4_resize_fs:1937: resize would cause inodes_count overflow [167765.672787] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294959104 blocks [167765.673573] EXT4-fs error (device dm-11): ext4_resize_fs:1950: comm resize2fs: resize_inode and meta_bg enabled simultaneously [167766.005282] EXT4-fs warning (device dm-11): ext4_resize_begin:45: There are errors in the filesystem, so online resizing is not allowed
Tests with 2k/4k block sizes all passed.
Thanks,
Eryu
Quoted 72 lines
tests/ext4/033 new file +41
-0+ +# Start with small fs +GROUP_COUNT=$((LIMIT_GROUPS-16)) +_mkfs_dev -N $((GROUP_COUNT*INODES_PER_GROUP)) -b $blksz \ + $DMHUGEDISK_DEV $((GROUP_COUNT*GROUP_BLOCKS)) + +_mount $DMHUGEDISK_DEV $SCRATCH_MNT + +echo "Initial fs dump" >> $seqres.full +$DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1 + +# This should fail, s_inodes_count would just overflow! +echo "Resizing to inode limit + 1..." +$RESIZE2FS_PROG $DMHUGEDISK_DEV $((LIMIT_GROUPS*GROUP_BLOCKS)) >> $seqres.full 2>&1 +if [ $? -eq 0 ]; then + echo "Resizing succeeded but it should fail!" + exit +fi + +# This should succeed, we are maxing out inodes +echo "Resizing to max group count..." +$RESIZE2FS_PROG $DMHUGEDISK_DEV $(((LIMIT_GROUPS-1)*GROUP_BLOCKS)) >> $seqres.full 2>&1 +if [ $? -ne 0 ]; then + echo "Resizing failed!" + exit +fi + +echo "Fs dump after resize" >> $seqres.full +$DUMPE2FS_PROG -h $DMHUGEDISK_DEV >> $seqres.full 2>&1 + +# This should fail, s_inodes_count would overflow by quite a bit! +echo "Resizing device size..." +$RESIZE2FS_PROG $DMHUGEDISK_DEV >> $seqres.full 2>&1 +if [ $? -eq 0 ]; then + echo "Resizing succeeded but it should fail!" + exit +fi + +# success, all done +status=0 +exittests/ext4/033.out new file +6
-0@@ -0,0 +1,6 @@ +QA output created by 033 +Figure out block size +Format huge device +Resizing to inode limit + 1... +Resizing to max group count... +Resizing device size...tests/ext4/group +1
-0@@ -35,6 +35,7 @@ 030 auto quick dax 031 auto quick dax 032 auto quick ioctl resize +033 auto ioctl resize 271 auto rw quick 301 aio auto ioctl rw stress defrag 302 aio auto ioctl rw stress defragSignature · 6 lines
2.13.6 -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 44 lines · Eryu Guan
Quoted 30 lines · Jan Kara
Test for overflow of
s_inodes_countduring filesystem resizing.Signed-off-by Jan Kara <[email protected]>--- common/config | 1 + common/rc | 7 ++++ tests/ext4/033 | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/033.out | 6 +++ tests/ext4/group | 1 + 5 files changed, 133 insertions(+) create mode 100755 tests/ext4/033 create mode 100644 tests/ext4/033.outcommon/config +1
-0@@ -170,6 +170,7 @@ export INDENT_PROG="`set_prog_path indent`" export XFS_COPY_PROG="`set_prog_path xfs_copy`" export FSTRIM_PROG="`set_prog_path fstrim`" export DUMPE2FS_PROG="`set_prog_path dumpe2fs`" +export RESIZE2FS_PROG="`set_prog_path resize2fs`" export FIO_PROG="`set_prog_path fio`" export FILEFRAG_PROG="`set_prog_path filefrag`" export E4DEFRAG_PROG="`set_prog_path e4defrag`"common/rc +0
-0common/rc _require_dumpe2fs() · line 3185
Quoted 10 lines
common/rc +7
-0@@ -3176,6 +3176,13 @@ _require_dumpe2fs() fi } +_require_resize2fs() +{ + if [ -z "$RESIZE2FS_PROG" ]; then + _notrun "This test requires resize2fs utility." + fi +} +I think this could simply be done by
Quoted 3 lines
_require_command"$RESIZE2FS_PROG" resize2fsin the test.
Yes, will do.
Quoted 3 lines
And this could be added to other existing resize2fs tests too, e.g. ext4/010, ext4/032 and ext4/306, and convert 'resize2fs' to '$RESIZE2FS_PROG', in a follow-up patch.
Yeah, I've noticed as well. Will create a patch for that.
Quoted 9 lines
Quoted 9 lines
common/rc +9
-0+seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 +
Quoted 8 lines
common/rc
Quoted 5 lines
common/rc +5
-0+_cleanup() +{ + _dmhugedisk_cleanup + # Recreate scratch so that _check_filesystems() does not complain + _scratch_mkfs >/dev/null 2>&1This could be done by calling
_require_scratch_nocheck, instead of_require_scratch.
Thanks, I'll fixup xfs/310 as well (that's where I've copied this from ;).
Quoted 1 line
But I'm not sure why it's expected to leave a corrupted fs behind after?
Because SCRATCH_DEV is used as a DM backing store, it is not a valid filesystem...
Quoted 6 lines
common/rc
Quoted 4 lines
common/rc +4
-0+testdir=$SCRATCH_MNT/test-$seq +blksz="$(_get_block_size $SCRATCH_MNT)" + +umount $SCRATCH_MNT
_scratch_unmount
Will fix in xfs/310 as well.
Quoted 8 lines
common/rc
Quoted 6 lines
common/rc +6
-0+ +INODES_PER_GROUP=$((blksz*8)) +GROUP_BLOCKS=$((blksz*8)) + +# Number of groups to overflow s_inodes_count +LIMIT_GROUPS=$(((1<<32)/INODES_PER_GROUP))Use lower case for local variables?
OK.
Quoted 34 lines
common/rc
Quoted 4 lines
common/rc +4
-0+ +# Create device huge enough so that overflowing inode count is possible +echo "Format huge device" +_dmhugedisk_init $(((LIMIT_GROUPS + 16)*GROUP_BLOCKS*(blksz/512)))I think we need to require a minimum size on
SCRATCH_DEVtoo, otherwise I got mkfs failure when testing with 1k block size on a 10GSCRATCH_DEV, the backing device didn't have enough space to store the metadata.After assigning a 25G device to
SCRATCH_DEV, mkfs with 1k block size passed, but test still failed in the end, I'm not sure what's going wrong this time..root/workspace/xfstests/results//ext4_1k/ext4/033.out.bad renamed from ext4/033.out 2018-05-28 22:12:56.234867728 +0800 +0
-02018-05-29 00:20:56.907283189 +0800root/workspace/xfstests/results//ext4_1k/ext4/033.out.bad renamed from ext4/033.out 2018-05-28 22:12:56.234867728 +0800 +1
-1@@ -3,4 +3,4 @@ Format huge device Resizing to inode limit + 1... Resizing to max group count... -Resizing device size... +Resizing failed!And dmesg showed:
[166934.718495] run fstests ext4/033 at 2018-05-29 00:07:04 [166937.651454] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: acl,user_xattr [167629.640111] EXT4-fs (dm-11): mounted filesystem with ordered data mode. Opts: (null) [167632.068897] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294967296 blocks [167632.069900] EXT4-fs warning (device dm-11): ext4_resize_fs:1937: resize would cause inodes_count overflow [167765.672787] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294959104 blocks [167765.673573] EXT4-fs error (device dm-11): ext4_resize_fs:1950: comm resize2fs: resize_inode and meta_bg enabled simultaneously [167766.005282] EXT4-fs warning (device dm-11): ext4_resize_begin:45: There are errors in the filesystem, so online resizing is not allowed
Quoted 1 line
Tests with 2k/4k block sizes all passed.
Weird, I don't see why 1k should be any different. Let me check. Thanks for review and testing!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 75 lines · Jan Kara
Quoted 44 lines · Eryu Guan
Quoted 30 lines · Jan Kara
Test for overflow of
s_inodes_countduring filesystem resizing.Signed-off-by Jan Kara <[email protected]>--- common/config | 1 + common/rc | 7 ++++ tests/ext4/033 | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/033.out | 6 +++ tests/ext4/group | 1 + 5 files changed, 133 insertions(+) create mode 100755 tests/ext4/033 create mode 100644 tests/ext4/033.outcommon/config +1
-0@@ -170,6 +170,7 @@ export INDENT_PROG="`set_prog_path indent`" export XFS_COPY_PROG="`set_prog_path xfs_copy`" export FSTRIM_PROG="`set_prog_path fstrim`" export DUMPE2FS_PROG="`set_prog_path dumpe2fs`" +export RESIZE2FS_PROG="`set_prog_path resize2fs`" export FIO_PROG="`set_prog_path fio`" export FILEFRAG_PROG="`set_prog_path filefrag`" export E4DEFRAG_PROG="`set_prog_path e4defrag`"common/rc +0
-0common/rc _require_dumpe2fs() · line 3185
Quoted 10 lines
common/rc +7
-0@@ -3176,6 +3176,13 @@ _require_dumpe2fs() fi } +_require_resize2fs() +{ + if [ -z "$RESIZE2FS_PROG" ]; then + _notrun "This test requires resize2fs utility." + fi +} +I think this could simply be done by
Quoted 3 lines
_require_command"$RESIZE2FS_PROG" resize2fsin the test.
Yes, will do.
Quoted 3 lines
And this could be added to other existing resize2fs tests too, e.g. ext4/010, ext4/032 and ext4/306, and convert 'resize2fs' to '$RESIZE2FS_PROG', in a follow-up patch.
Yeah, I've noticed as well. Will create a patch for that.
Quoted 9 lines
Quoted 9 lines
common/rc +9
-0+seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 +Quoted 8 lines
common/rc
Quoted 5 lines
common/rc +5
-0+_cleanup() +{ + _dmhugedisk_cleanup + # Recreate scratch so that _check_filesystems() does not complain + _scratch_mkfs >/dev/null 2>&1This could be done by calling
_require_scratch_nocheck, instead of_require_scratch.
Quoted 6 lines
Thanks, I'll fixup xfs/310 as well (that's where I've copied this from ;).
Quoted 1 line
But I'm not sure why it's expected to leave a corrupted fs behind after?
Because
SCRATCH_DEVis used as a DM backing store, it is not a valid filesystem...
Aha, it must be too late last night for me to review.. :)
Thanks,
Eryu
Quoted 35 lines · Jan Kara
Quoted 34 lines · Eryu Guan
tests/ext4/033 line 77
Quoted 4 lines
tests/ext4/033 new file +4
-0+ +# Create device huge enough so that overflowing inode count is possible +echo "Format huge device" +_dmhugedisk_init $(((LIMIT_GROUPS + 16)*GROUP_BLOCKS*(blksz/512)))I think we need to require a minimum size on
SCRATCH_DEVtoo, otherwise I got mkfs failure when testing with 1k block size on a 10GSCRATCH_DEV, the backing device didn't have enough space to store the metadata.After assigning a 25G device to
SCRATCH_DEV, mkfs with 1k block size passed, but test still failed in the end, I'm not sure what's going wrong this time..root/workspace/xfstests/results//ext4_1k/ext4/033.out.bad renamed from ext4/033.out 2018-05-28 22:12:56.234867728 +0800 +0
-02018-05-29 00:20:56.907283189 +0800root/workspace/xfstests/results//ext4_1k/ext4/033.out.bad renamed from ext4/033.out 2018-05-28 22:12:56.234867728 +0800 +1
-1@@ -3,4 +3,4 @@ Format huge device Resizing to inode limit + 1... Resizing to max group count... -Resizing device size... +Resizing failed!And dmesg showed:
[166934.718495] run fstests ext4/033 at 2018-05-29 00:07:04 [166937.651454] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: acl,user_xattr [167629.640111] EXT4-fs (dm-11): mounted filesystem with ordered data mode. Opts: (null) [167632.068897] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294967296 blocks [167632.069900] EXT4-fs warning (device dm-11): ext4_resize_fs:1937: resize would cause inodes_count overflow [167765.672787] EXT4-fs (dm-11): resizing filesystem from 4294836224 to 4294959104 blocks [167765.673573] EXT4-fs error (device dm-11): ext4_resize_fs:1950: comm resize2fs: resize_inode and meta_bg enabled simultaneously [167766.005282] EXT4-fs warning (device dm-11): ext4_resize_begin:45: There are errors in the filesystem, so online resizing is not allowed
Quoted 4 lines
Quoted 1 line
Tests with 2k/4k block sizes all passed.
Weird, I don't see why 1k should be any different. Let me check. Thanks for review and testing!
I've dug more into this. The excessive space usage for 1k blocksize is due to the chunk size of dm snapshot being 512 sectors. I've modified the test to use 16 sector chunk size. Then the test easily fits into 2GB. I've added the size test just to be sure as well.
The test failure is due to a bug in e2fsprogs - they really end up creating incorrect filesystem with these options. I'll fix that as well but it will take a while so for now the test is going to fail. If you want to test ext4/033 with 1k block size you can workaround the bug with:
export MKFS_OPTIONS="-b 1024 -O ^resize_inode"
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR