fstests: btrfs: Test if btrfs will corrupt nodatasum compressed extent when replacing device
PATCH 1/1 fstests: btrfs: Test if btrfs will corrupt nodatasum compressed extent when replacing device
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
--- tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 + tests/btrfs/group | 1 + 3 files changed, 94 insertions(+) create mode 100755 tests/btrfs/161 create mode 100644 tests/btrfs/161.out
tests/btrfs/161 new file +91 -0
@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_test +_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync + +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount + +_mount $SPARE_DEV $SCRATCH_MNT + +# Since now the compressed extent contains *UNCOMPRESSED* data, reading it will +# easily trigger a EIO error +cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exit
tests/btrfs/161.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is golden
tests/btrfs/group +1 -0
@@ -163,3 +163,4 @@ 158 auto quick raid scrub 159 auto quick 160 auto quick +161 auto quick replace
Signature · 1 line
2.17.0
Quoted 100 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 + tests/btrfs/group | 1 + 3 files changed, 94 insertions(+)create mode 100755 tests/btrfs/161
create mode 100644 tests/btrfs/161.outtests/btrfs/161 new file +71
-0@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_test +_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync
tests/btrfs/161 line 81
Quoted 10 lines
tests/btrfs/161 new file +10
-0+ +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount + +_mount $SPARE_DEV $SCRATCH_MNT + +# Since now the compressed extent contains *UNCOMPRESSED* data, reading it will +# easily trigger a EIO error
This sentence is confusing. Are you referring to the bug? what is compressed extent containing uncompressed data?
Thanks, Anand
Quoted 28 lines
tests/btrfs/161 new file +10
-0+cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exittests/btrfs/161.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is goldentests/btrfs/group +1
-0@@ -163,3 +163,4 @@ 158 auto quick raid scrub 159 auto quick 160 auto quick +161 auto quick replace
Quoted 111 lines · Anand Jain
Quoted 108 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data
other than the original compressed data.And since btrfs still consider the data is compressed and will try to read it
as compressed, it can cause read error.The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace".
(The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>---
tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 +
tests/btrfs/group | 1 +3 files changed, 94 insertions(+)create mode 100755 tests/btrfs/161
create mode 100644 tests/btrfs/161.outtests/btrfs/161 new file +76
-0@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_test +_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync + +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount
Quoted 8 lines
Quoted 6 lines
tests/btrfs/161 new file +4
-0+ +_mount $SPARE_DEV $SCRATCH_MNT + +# Since now the compressed extent contains *UNCOMPRESSED* data,reading it will
+# easily trigger a EIO errorThis sentence is confusing. Are you referring to the bug?
Yes.
Quoted 1 line
what is compressed extent containing uncompressed data?
The data extent has lzo compression flag.
While its on-disk data is in fact the uncompressed data.
With the test case, just check the on-disk data extent, you'll find that's all 0xcd, other the lzo compressed data.
Thanks,
Qu
Quoted 35 lines
Thanks, Anand
Quoted 28 lines
tests/btrfs/161 new file +10
-0+cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exittests/btrfs/161.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is goldentests/btrfs/group +0
-0@@ -163,3 +163,4 @@158 auto quick raid scrub
159 auto quick
160 auto quick
+161 auto quick replaceSignature · 3 lines
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 8 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
Quoted 7 lines
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>
Looks fine to me overall, some minor issues inline. But I'd really like an explicit ACK from btrfs folks.
Quoted 59 lines
--- tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 + tests/btrfs/group | 1 + 3 files changed, 94 insertions(+) create mode 100755 tests/btrfs/161 create mode 100644 tests/btrfs/161.outtests/btrfs/161 new file +45
-0@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter
tests/btrfs/161 line 55
Quoted 10 lines
tests/btrfs/161 new file +10
-0+ +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_test
This is not needed, there's no point running fsck on $TEST_DEV after test when it's not used at all.
Quoted 13 lines
tests/btrfs/161 new file +13
-0+_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null
tests/btrfs/161 line 78
Quoted 10 lines
tests/btrfs/161 new file +10
-0+ +# Write the compressed data back to disk +sync + +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount + +_mount $SPARE_DEV $SCRATCH_MNT
Better to explain the cycle mount with comments.
Quoted 26 lines
tests/btrfs/161 new file +13
-0+ +# Since now the compressed extent contains *UNCOMPRESSED* data, reading it will +# easily trigger a EIO error +cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exittests/btrfs/161.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is goldentests/btrfs/group +0
-0
tests/btrfs/group line 166
Quoted 4 lines
tests/btrfs/group +1
-0@@ -163,3 +163,4 @@ 158 auto quick raid scrub 159 auto quick 160 auto quick +161 auto quick replace
Anand introduced a new 'volume' group in commit 144c8463d38b ("btrfs:
introduce btrfs/volume group"), all 'replace' tests should be in 'volume' group now.
Thanks,
Eryu
Quoted 7 lines
Signature · 6 lines
2.17.0 -- 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 84 lines · Eryu Guan
Quoted 8 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
Quoted 7 lines
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>Looks fine to me overall, some minor issues inline. But I'd really like an explicit ACK from btrfs folks.
Quoted 64 lines
--- tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 + tests/btrfs/group | 1 + 3 files changed, 94 insertions(+) create mode 100755 tests/btrfs/161 create mode 100644 tests/btrfs/161.outtests/btrfs/161 new file +50
-0@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here
Quoted 8 lines
tests/btrfs/161 line 55
Quoted 5 lines
tests/btrfs/161 new file +5
-0+ +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_testThis is not needed, there's no point running fsck on $TEST_DEV after test when it's not used at all.
Forgot to remove that line.
Quoted 18 lines
Quoted 18 lines
tests/btrfs/161 new file +17
-0+_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync +
Quoted 8 lines
tests/btrfs/161 line 78
Quoted 6 lines
tests/btrfs/161 new file +6
-0+# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount + +_mount $SPARE_DEV $SCRATCH_MNTBetter to explain the cycle mount with comments.
It's used to drop the page cache so that next read will fetch data from disk other than using the cache.
I'll add the comment in the next version.
Quoted 27 lines
Quoted 27 lines
tests/btrfs/161 new file +13
-0+ +# Since now the compressed extent contains *UNCOMPRESSED* data, reading it will +# easily trigger a EIO error +cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exittests/btrfs/161.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is goldentests/btrfs/group +0
-0@@ -163,3 +163,4 @@
Quoted 8 lines
tests/btrfs/group line 166
Quoted 4 lines
tests/btrfs/group +1
-0158 auto quick raid scrub 159 auto quick 160 auto quick +161 auto quick replaceAnand introduced a new 'volume' group in commit
144c8463d38b("btrfs:
introduce btrfs/volume group"), all 'replace' tests should be in 'volume' group now.
Makes sense.
Thanks,
Qu
Quoted 16 lines
Thanks,
EryuQuoted 7 lines
Signature · 6 lines
2.17.0 -- 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--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
Quoted 7 lines
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>
Quoted 123 lines
--- tests/btrfs/161 | 91 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/161.out | 2 + tests/btrfs/group | 1 + 3 files changed, 94 insertions(+) create mode 100755 tests/btrfs/161 create mode 100644 tests/btrfs/161.outtests/btrfs/161 new file +91
-0@@ -0,0 +1,91 @@ +#! /bin/bash +# FS QA Test 161 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing replacing device. +# +# This could be fixed by the following RFC patch: +# "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace" +# +#----------------------------------------------------------------------- +# Copyright (C) 2018 SUSE Linux Products GmbH. 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" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_test +_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync + +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +_scratch_unmount + +_mount $SPARE_DEV $SCRATCH_MNT + +# Since now the compressed extent contains *UNCOMPRESSED* data, reading it will +# easily trigger a EIO error +cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" +# success, all done +status=0 +exittests/btrfs/161.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 161 +Silence is goldentests/btrfs/group +1
-0@@ -163,3 +163,4 @@ 158 auto quick raid scrub 159 auto quick 160 auto quick +161 auto quick replace
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Quoted 4 lines
Quoted 2 lines
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>
Thanks for the review! I assume the v3 patch also passes your review :)
Eryu
Quoted 17 lines · Eryu Guan
Quoted 16 lines · Nikolay Borisov
Quoted 13 lines · Qu Wenruo
This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data.
And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error.
The root cause is located, and one RFC patch already sent to fix it, titled "[PATCH RFC] btrfs: scrub: Don't use inode pages for device replace". (The RFC is only for the extra possible way to fix the bug, the fix itself should work without problem)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Reported-by James Harvey <[email protected]>Signed-off-by Qu Wenruo <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>Thanks for the review! I assume the v3 patch also passes your review :)
Yes, I just saw that you requested an ack from a btrfs developer some time ago and this test didn't move forward, hence i replied. But yes, it's a valid test for btrfs.
Quoted 7 lines
Eryu
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html