Skip to contentSkip to conversation

fstests: btrfs: Test if btrfs will corrupt nodatasum compressed extent when replacing device

PATCH Superseded Qu Wenruo 5 participants 8 messages Jun 1, 2018 – Jun 28, 2018 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

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
new file mode 100755
index 00000000..d4a2b474
@@ -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
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +1 -0
index f04ee8d5..f900b3d0 100644
@@ -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
#1 lore raw
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)

---
  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 +71 -0
new file mode 100755
index 00000000..d4a2b474
@@ -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
+exit
tests/btrfs/161.out new file +2 -0
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +1 -0
index f04ee8d5..f900b3d0 100644
@@ -163,3 +163,4 @@
  158 auto quick raid scrub
  159 auto quick
  160 auto quick
+161 auto quick replace
#2 lore raw
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)

---
  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 +76 -0
new file mode 100755
index 00000000..d4a2b474
@@ -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 error

 This 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
+exit
tests/btrfs/161.out new file +2 -0
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +0 -0
index f04ee8d5..f900b3d0 100644
@@ -163,3 +163,4 @@

  158 auto quick raid scrub
  159 auto quick
  160 auto quick
+161 auto quick replace

Signature · 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
#3 lore raw
In reply to Qu Wenruo
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)

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.out
tests/btrfs/161 new file +45 -0
new file mode 100755
index 00000000..d4a2b474
@@ -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
+exit
tests/btrfs/161.out new file +2 -0
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +0 -0
index f04ee8d5..f900b3d0 100644

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
#4 lore raw
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)

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.out
tests/btrfs/161 new file +50 -0
new file mode 100755
index 00000000..d4a2b474
@@ -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_test

This 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_MNT

Better 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
+exit
tests/btrfs/161.out new file +2 -0
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +0 -0
index f04ee8d5..f900b3d0 100644
@@ -163,3 +163,4 @@
Quoted 8 lines

tests/btrfs/group line 166

Quoted 4 lines
tests/btrfs/group +1 -0
 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.

Makes sense.

Thanks,
Qu

Quoted 16 lines

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

--
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

Reviewed-by on v1 1/1
#5 lore raw
In reply to Qu Wenruo
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)

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.out
tests/btrfs/161 new file +91 -0
new file mode 100755
index 00000000..d4a2b474
@@ -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
new file mode 100644
index 00000000..1752a243
@@ -0,0 +1,2 @@
+QA output created by 161
+Silence is golden
tests/btrfs/group +1 -0
index f04ee8d5..f900b3d0 100644
@@ -163,3 +163,4 @@
 158 auto quick raid scrub
 159 auto quick
 160 auto quick
+161 auto quick replace
#6 lore raw
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

Thanks for the review! I assume the v3 patch also passes your review :)

Eryu

#7 lore raw
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

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