diff mbox series

generic: test i_blocks for truncated large files

Message ID 20220906155320.952636-1-preichl@redhat.com (mailing list archive)
State New, archived
Headers show
Series generic: test i_blocks for truncated large files | expand

Commit Message

Pavel Reichl Sept. 6, 2022, 3:53 p.m. UTC
This is a regression test for an incorrect computation of i_blocks for
truncated files larger than 4 GiB. Bug was filed for exFAT.

Test is based on reproducer provied by Christophe Vu-Brugier as part
of kernel patch-fix submission.

Signed-off-by: Pavel Reichl <preichl@redhat.com>
---
 tests/generic/698     | 47 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/698.out |  2 ++
 2 files changed, 49 insertions(+)
 create mode 100755 tests/generic/698
 create mode 100644 tests/generic/698.out

Comments

Zorro Lang Sept. 7, 2022, 1:05 a.m. UTC | #1
On Tue, Sep 06, 2022 at 05:53:20PM +0200, Pavel Reichl wrote:
> This is a regression test for an incorrect computation of i_blocks for
> truncated files larger than 4 GiB. Bug was filed for exFAT.
> 
> Test is based on reproducer provied by Christophe Vu-Brugier as part
> of kernel patch-fix submission.
> 
> Signed-off-by: Pavel Reichl <preichl@redhat.com>
> ---

Hi Pavel,

Your patch has been merged as generic/694,

>  tests/generic/698     | 47 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/698.out |  2 ++
>  2 files changed, 49 insertions(+)
>  create mode 100755 tests/generic/698
>  create mode 100644 tests/generic/698.out
> 
> diff --git a/tests/generic/698 b/tests/generic/698
> new file mode 100755
> index 00000000..217641e6
> --- /dev/null
> +++ b/tests/generic/698
> @@ -0,0 +1,47 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2022  Red Hat Inc. All Rights Reserved.
> +#
> +# FS QA Test 698
> +#
> +# Verify that i_blocks for truncated files larger than 4 GiB have correct
> +# values.
> +#
> +# This test verifies the problem fixed in kernel with commit
> +# 92fba084b79e exfat: fix i_blocks for files truncated over 4 GiB
> +#
> +. ./common/preamble
> +_begin_fstest auto
> +
> +# Override the default cleanup function.
> +_cleanup()
> +{
> +	cd /
> +	rm -r -f $tmp.* $junk_dir
> +}
> +
> +_supported_fs generic
> +_require_test
> +_require_fs_space $TEST_DIR $((5 * 1024 * 1024)) #kB

_fixed_by_kernel_commit 92fba084b79e \
	exfat: fix i_blocks for files truncated over 4 GiB

> +
> +echo "Silence is golden"
> +
> +junk_dir=$TEST_DIR/$seq
> +junk_file=$junk_dir/junk
> +mkdir -p $junk_dir
> +
> +$XFS_IO_PROG -f -c "pwrite -W 0 5G" $junk_file > /dev/null
> +
> +

Useless empty lines

> +truncate -s $((4 * 1024 * 1024 * 1024)) $junk_file
> +
> +iblocks_after_truncate=`stat -c '%b' $junk_file`
> +iblocks_expected=$((4 * 1024 * 1024 * 2))

I think you suspect that the `stat -c %B xxx` always be 512. I don't know if
it's always 512 on Linux, or better to check %B size at first.

Thanks,
Zorro

> +
> +if [ "$iblocks_expected" != "$iblocks_after_truncate" ]; then
> +	echo "Number of blocks needs to be same: $iblocks_expected, $iblocks_after_truncate"
> +fi
> +
> +status=0
> +
> +exit
> diff --git a/tests/generic/698.out b/tests/generic/698.out
> new file mode 100644
> index 00000000..222db0de
> --- /dev/null
> +++ b/tests/generic/698.out
> @@ -0,0 +1,2 @@
> +QA output created by 698
> +Silence is golden
> -- 
> 2.37.3
>
Zorro Lang Sept. 7, 2022, 4:49 a.m. UTC | #2
On Wed, Sep 07, 2022 at 09:05:59AM +0800, Zorro Lang wrote:
> On Tue, Sep 06, 2022 at 05:53:20PM +0200, Pavel Reichl wrote:
> > This is a regression test for an incorrect computation of i_blocks for
> > truncated files larger than 4 GiB. Bug was filed for exFAT.
> > 
> > Test is based on reproducer provied by Christophe Vu-Brugier as part
> > of kernel patch-fix submission.
> > 
> > Signed-off-by: Pavel Reichl <preichl@redhat.com>
> > ---
> 
> Hi Pavel,
> 
> Your patch has been merged as generic/694,

Oh, ignore this line ^^ :)

> 
> >  tests/generic/698     | 47 +++++++++++++++++++++++++++++++++++++++++++
> >  tests/generic/698.out |  2 ++
> >  2 files changed, 49 insertions(+)
> >  create mode 100755 tests/generic/698
> >  create mode 100644 tests/generic/698.out
> > 
> > diff --git a/tests/generic/698 b/tests/generic/698
> > new file mode 100755
> > index 00000000..217641e6
> > --- /dev/null
> > +++ b/tests/generic/698
> > @@ -0,0 +1,47 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (c) 2022  Red Hat Inc. All Rights Reserved.
> > +#
> > +# FS QA Test 698
> > +#
> > +# Verify that i_blocks for truncated files larger than 4 GiB have correct
> > +# values.
> > +#
> > +# This test verifies the problem fixed in kernel with commit
> > +# 92fba084b79e exfat: fix i_blocks for files truncated over 4 GiB
> > +#
> > +. ./common/preamble
> > +_begin_fstest auto
> > +
> > +# Override the default cleanup function.
> > +_cleanup()
> > +{
> > +	cd /
> > +	rm -r -f $tmp.* $junk_dir
> > +}
> > +
> > +_supported_fs generic
> > +_require_test
> > +_require_fs_space $TEST_DIR $((5 * 1024 * 1024)) #kB
> 
> _fixed_by_kernel_commit 92fba084b79e \
> 	exfat: fix i_blocks for files truncated over 4 GiB
> 
> > +
> > +echo "Silence is golden"
> > +
> > +junk_dir=$TEST_DIR/$seq
> > +junk_file=$junk_dir/junk
> > +mkdir -p $junk_dir
> > +
> > +$XFS_IO_PROG -f -c "pwrite -W 0 5G" $junk_file > /dev/null
> > +
> > +
> 
> Useless empty lines
> 
> > +truncate -s $((4 * 1024 * 1024 * 1024)) $junk_file
> > +
> > +iblocks_after_truncate=`stat -c '%b' $junk_file`
> > +iblocks_expected=$((4 * 1024 * 1024 * 2))
> 
> I think you suspect that the `stat -c %B xxx` always be 512. I don't know if
> it's always 512 on Linux, or better to check %B size at first.
> 
> Thanks,
> Zorro
> 
> > +
> > +if [ "$iblocks_expected" != "$iblocks_after_truncate" ]; then
> > +	echo "Number of blocks needs to be same: $iblocks_expected, $iblocks_after_truncate"
> > +fi
> > +
> > +status=0
> > +
> > +exit
> > diff --git a/tests/generic/698.out b/tests/generic/698.out
> > new file mode 100644
> > index 00000000..222db0de
> > --- /dev/null
> > +++ b/tests/generic/698.out
> > @@ -0,0 +1,2 @@
> > +QA output created by 698
> > +Silence is golden
> > -- 
> > 2.37.3
> >
Darrick J. Wong Sept. 7, 2022, 3:26 p.m. UTC | #3
On Tue, Sep 06, 2022 at 05:53:20PM +0200, Pavel Reichl wrote:
> This is a regression test for an incorrect computation of i_blocks for
> truncated files larger than 4 GiB. Bug was filed for exFAT.
> 
> Test is based on reproducer provied by Christophe Vu-Brugier as part
> of kernel patch-fix submission.
> 
> Signed-off-by: Pavel Reichl <preichl@redhat.com>
> ---
>  tests/generic/698     | 47 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/698.out |  2 ++
>  2 files changed, 49 insertions(+)
>  create mode 100755 tests/generic/698
>  create mode 100644 tests/generic/698.out
> 
> diff --git a/tests/generic/698 b/tests/generic/698
> new file mode 100755
> index 00000000..217641e6
> --- /dev/null
> +++ b/tests/generic/698
> @@ -0,0 +1,47 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2022  Red Hat Inc. All Rights Reserved.
> +#
> +# FS QA Test 698
> +#
> +# Verify that i_blocks for truncated files larger than 4 GiB have correct
> +# values.
> +#
> +# This test verifies the problem fixed in kernel with commit
> +# 92fba084b79e exfat: fix i_blocks for files truncated over 4 GiB
> +#
> +. ./common/preamble
> +_begin_fstest auto
> +
> +# Override the default cleanup function.
> +_cleanup()
> +{
> +	cd /
> +	rm -r -f $tmp.* $junk_dir
> +}
> +
> +_supported_fs generic
> +_require_test
> +_require_fs_space $TEST_DIR $((5 * 1024 * 1024)) #kB
> +
> +echo "Silence is golden"
> +
> +junk_dir=$TEST_DIR/$seq
> +junk_file=$junk_dir/junk
> +mkdir -p $junk_dir
> +
> +$XFS_IO_PROG -f -c "pwrite -W 0 5G" $junk_file > /dev/null
> +
> +
> +truncate -s $((4 * 1024 * 1024 * 1024)) $junk_file
> +
> +iblocks_after_truncate=`stat -c '%b' $junk_file`
> +iblocks_expected=$((4 * 1024 * 1024 * 2))

What happens if the filesystem allocates a substantial number of blocks
to store block mappings (e.g. ext2)?  Those are accounted to i_blocks.

> +
> +if [ "$iblocks_expected" != "$iblocks_after_truncate" ]; then
> +	echo "Number of blocks needs to be same: $iblocks_expected, $iblocks_after_truncate"

_within_range?

--D

> +fi
> +
> +status=0
> +
> +exit
> diff --git a/tests/generic/698.out b/tests/generic/698.out
> new file mode 100644
> index 00000000..222db0de
> --- /dev/null
> +++ b/tests/generic/698.out
> @@ -0,0 +1,2 @@
> +QA output created by 698
> +Silence is golden
> -- 
> 2.37.3
>
diff mbox series

Patch

diff --git a/tests/generic/698 b/tests/generic/698
new file mode 100755
index 00000000..217641e6
--- /dev/null
+++ b/tests/generic/698
@@ -0,0 +1,47 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022  Red Hat Inc. All Rights Reserved.
+#
+# FS QA Test 698
+#
+# Verify that i_blocks for truncated files larger than 4 GiB have correct
+# values.
+#
+# This test verifies the problem fixed in kernel with commit
+# 92fba084b79e exfat: fix i_blocks for files truncated over 4 GiB
+#
+. ./common/preamble
+_begin_fstest auto
+
+# Override the default cleanup function.
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.* $junk_dir
+}
+
+_supported_fs generic
+_require_test
+_require_fs_space $TEST_DIR $((5 * 1024 * 1024)) #kB
+
+echo "Silence is golden"
+
+junk_dir=$TEST_DIR/$seq
+junk_file=$junk_dir/junk
+mkdir -p $junk_dir
+
+$XFS_IO_PROG -f -c "pwrite -W 0 5G" $junk_file > /dev/null
+
+
+truncate -s $((4 * 1024 * 1024 * 1024)) $junk_file
+
+iblocks_after_truncate=`stat -c '%b' $junk_file`
+iblocks_expected=$((4 * 1024 * 1024 * 2))
+
+if [ "$iblocks_expected" != "$iblocks_after_truncate" ]; then
+	echo "Number of blocks needs to be same: $iblocks_expected, $iblocks_after_truncate"
+fi
+
+status=0
+
+exit
diff --git a/tests/generic/698.out b/tests/generic/698.out
new file mode 100644
index 00000000..222db0de
--- /dev/null
+++ b/tests/generic/698.out
@@ -0,0 +1,2 @@ 
+QA output created by 698
+Silence is golden