Skip to contentSkip to conversation

fstest: btrfs/196: test for alien btrfs-devices

PATCH Superseded Anand Jain 2 participants 8 messages Oct 7, 2019 – Oct 22, 2019 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/2 fstest: btrfs/196: test for alien btrfs-devices

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians someother btrfs.

---
 tests/btrfs/196     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/196.out | 25 +++++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 103 insertions(+)
 create mode 100755 tests/btrfs/196
 create mode 100644 tests/btrfs/196.out
tests/btrfs/196 new file +77 -0
new file mode 100755
index 000000000000..e35cdce492e5
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 196
+#
+# Test stale and alien btrfs-device in the fs devices list.
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR"
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	$BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR"
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/196.out new file +25 -0
new file mode 100644
index 000000000000..311ae9e2f46a
@@ -0,0 +1,25 @@
+QA output created by 196
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index 3ce6fa4628d8..c86ea2516397 100644
@@ -198,3 +198,4 @@
 193 auto quick qgroup enospc limit
 194 auto volume
 195 auto volume
+196 auto quick volume
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 fstest: btrfs/197: test for alien devices

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians no btrfs magic string.

---
 tests/btrfs/197     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/197.out | 25 +++++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 105 insertions(+)
 create mode 100755 tests/btrfs/197
 create mode 100644 tests/btrfs/197.out
tests/btrfs/197 new file +79 -0
new file mode 100755
index 000000000000..82e1a299ca43
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 197
+#
+# Test stale and alien device in the fs devices list.
+# Similar to the testcase btrfs/196 except that here the alien device no more
+# contains the btrfs superblock.
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_command "$WIPEFS_PROG" wipefs
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/197.out new file +25 -0
new file mode 100644
index 000000000000..79237b854b5a
@@ -0,0 +1,25 @@
+QA output created by 197
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index c86ea2516397..f2eac5c20712 100644
@@ -199,3 +199,4 @@
 194 auto volume
 195 auto volume
 196 auto quick volume
+197 auto quick volume
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 2/2] fstest: btrfs/197: test for alien devices

Quoted 63 lines · Anand Jain

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians no btrfs magic string.

---
 tests/btrfs/197     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/197.out | 25 +++++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 105 insertions(+)
 create mode 100755 tests/btrfs/197
 create mode 100644 tests/btrfs/197.out
tests/btrfs/197 new file +45 -0
new file mode 100755
index 000000000000..82e1a299ca43
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 197
+#
+# Test stale and alien device in the fs devices list.
+# Similar to the testcase btrfs/196 except that here the alien device no more
+# contains the btrfs superblock.
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_command "$WIPEFS_PROG" wipefs
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1

tests/btrfs/197 line 55

Quoted 10 lines
tests/btrfs/197 new file +10 -0
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR

Stale comments above.

Otherwise looks fine to me.

tests/btrfs/197 line 60

Quoted 5 lines
tests/btrfs/197 new file +5 -0
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1

If creating a new btrfs works for btrfs/196, I wonder if we could merge the two tests into one test, firstly create a new fs & degraded mount, then wipefs & degraded mount.

Thanks,
Eryu

Quoted 62 lines
tests/btrfs/197 new file +19 -0
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/197.out new file +25 -0
new file mode 100644
index 000000000000..79237b854b5a
@@ -0,0 +1,25 @@
+QA output created by 197
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index c86ea2516397..f2eac5c20712 100644
@@ -199,3 +199,4 @@
 194 auto volume
 195 auto volume
 196 auto quick volume
+197 auto quick volume
Signature · 1 line
1.8.3.1
author
#3 lore raw

Re: [PATCH 2/2] fstest: btrfs/197: test for alien devices

Quoted 68 lines · Eryu Guan
Quoted 67 lines · Anand Jain

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians no btrfs magic string.

---
  tests/btrfs/197     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  tests/btrfs/197.out | 25 +++++++++++++++++
  tests/btrfs/group   |  1 +
  3 files changed, 105 insertions(+)

create mode 100755 tests/btrfs/197
create mode 100644 tests/btrfs/197.out

tests/btrfs/197 new file +49 -0
new file mode 100755
index 000000000000..82e1a299ca43
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 197
+#
+# Test stale and alien device in the fs devices list.
+# Similar to the testcase btrfs/196 except that here the alien device no more
+# contains the btrfs superblock.
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_command "$WIPEFS_PROG" wipefs
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
Quoted 8 lines

tests/btrfs/197 line 55

Quoted 6 lines
tests/btrfs/197 new file +6 -0
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR

Stale comments above.

updated in v2.

Quoted 11 lines

Otherwise looks fine to me.

tests/btrfs/197 line 60

Quoted 5 lines
tests/btrfs/197 new file +5 -0
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1

If creating a new btrfs works for btrfs/196, I wonder if we could merge the two tests into one test, firstly create a new fs & degraded mount, then wipefs & degraded mount.

Its better if they are separate. The workout is already looping for different raids. Per experiences from btrfs/011 it gets harder to debug with testing different cases in one test case. Can I keep them separate?

V2 is being sent out in a while.

Thanks, Anand

Quoted 65 lines

Thanks,
Eryu

Quoted 62 lines
tests/btrfs/197 new file +19 -0
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/197.out new file +25 -0
new file mode 100644
index 000000000000..79237b854b5a
@@ -0,0 +1,25 @@
+QA output created by 197
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index c86ea2516397..f2eac5c20712 100644
@@ -199,3 +199,4 @@
  194 auto volume
  195 auto volume
  196 auto quick volume
+197 auto quick volume
Signature · 1 line
1.8.3.1
#4 lore raw
In reply to Anand Jain
Quoted 44 lines · Anand Jain

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians someother btrfs.

---
 tests/btrfs/196     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/196.out | 25 +++++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 103 insertions(+)
 create mode 100755 tests/btrfs/196
 create mode 100644 tests/btrfs/196.out
tests/btrfs/196 new file +26 -0
new file mode 100755
index 000000000000..e35cdce492e5
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 196
+#
+# Test stale and alien btrfs-device in the fs devices list.
+#
+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/196 line 36

Quoted 10 lines
tests/btrfs/196 new file +10 -0
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux

_supported_os btrfs

Quoted 6 lines
tests/btrfs/196 new file +6 -0
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1

tests/btrfs/196 line 52

Quoted 10 lines
tests/btrfs/196 new file +10 -0
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR

Instead of adding $device_1 to $TEST_DIR, does creating a new btrfs on $device_1 work? I'm a bit worried that changing $TEST_DIR/$TEST_DEV configuration would have some side effects, e.g. we add it to $TEST_DIR and cancle the test before removing it, the $TEST_DEV will end up in an unexpected state in next test run. (Though we could remove the device in _cleanup, this is just an example.)

tests/btrfs/196 line 61

Quoted 9 lines
tests/btrfs/196 new file +9 -0
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR"
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out

Test could be renumbered, no need to hardcode 196.out, just ".out file" would be fine.

tests/btrfs/196 line 65

Quoted 4 lines
tests/btrfs/196 new file +4 -0
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	$BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR"

I think we should remove $device_1 in _cleanup if it's not empty in case test exits unexpectly. But as mentioned above, better to avoid adding new device to $TEST_DIR.

Thanks,
Eryu

Quoted 55 lines
tests/btrfs/196 new file +12 -0
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/196.out new file +25 -0
new file mode 100644
index 000000000000..311ae9e2f46a
@@ -0,0 +1,25 @@
+QA output created by 196
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index 3ce6fa4628d8..c86ea2516397 100644
@@ -198,3 +198,4 @@
 193 auto quick qgroup enospc limit
 194 auto volume
 195 auto volume
+196 auto quick volume
Signature · 1 line
1.8.3.1
author
#5 lore raw
Quoted 49 lines · Eryu Guan
Quoted 48 lines · Anand Jain

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians someother btrfs.

---
  tests/btrfs/196     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  tests/btrfs/196.out | 25 +++++++++++++++++
  tests/btrfs/group   |  1 +
  3 files changed, 103 insertions(+)

create mode 100755 tests/btrfs/196
create mode 100644 tests/btrfs/196.out

tests/btrfs/196 new file +30 -0
new file mode 100755
index 000000000000..e35cdce492e5
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 196
+#
+# Test stale and alien btrfs-device in the fs devices list.
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
Quoted 8 lines

tests/btrfs/196 line 36

Quoted 6 lines
tests/btrfs/196 new file +6 -0
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux

_supported_os btrfs

Thanks fixed in v2.

Quoted 15 lines
Quoted 15 lines
tests/btrfs/196 new file +15 -0
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
Quoted 8 lines

tests/btrfs/196 line 52

Quoted 1 line
tests/btrfs/196 new file +1 -0
+	# adding it to the $TEST_DIR

Instead of adding $device_1 to $TEST_DIR, does creating a new btrfs on $device_1 work? I'm a bit worried that changing $TEST_DIR/$TEST_DEV configuration would have some side effects, e.g. we add it to $TEST_DIR and cancle the test before removing it, the $TEST_DEV will end up in an unexpected state in next test run. (Though we could remove the device in _cleanup, this is just an example.)

In v2 I am avoiding adding $device_1 to $TEST_DIR. Instead, I am using $SPARE_DEV to create a new btrfs and $device_1 is added to it. I feel this is a better fix which shall completely avoid messing up the $TEST_DEV. Thanks.

Quoted 4 lines
Quoted 4 lines
tests/btrfs/196 new file +4 -0
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
Quoted 8 lines

tests/btrfs/196 line 61

Quoted 5 lines
tests/btrfs/196 new file +5 -0
+	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR"
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out

Test could be renumbered, no need to hardcode 196.out, just ".out file" would be fine.

Oh. Thanks this is fixed in v2.

Quoted 8 lines

tests/btrfs/196 line 65

Quoted 4 lines
tests/btrfs/196 new file +4 -0
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	$BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR"

I think we should remove $device_1 in _cleanup if it's not empty in case test exits unexpectly. But as mentioned above, better to avoid adding new device to $TEST_DIR.

As I am not using $TEST_DIR to add the $device_1. So this won't be needed now.

Thanks, Anand

Quoted 58 lines

Thanks,
Eryu

Quoted 55 lines
tests/btrfs/196 new file +12 -0
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/196.out new file +25 -0
new file mode 100644
index 000000000000..311ae9e2f46a
@@ -0,0 +1,25 @@
+QA output created by 196
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index 3ce6fa4628d8..c86ea2516397 100644
@@ -198,3 +198,4 @@
  193 auto quick qgroup enospc limit
  194 auto volume
  195 auto volume
+196 auto quick volume
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH v2 1/2 fstest: btrfs/197: test for alien btrfs-devices

In reply to Anand Jain

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians someother btrfs.

---
v2: Comments updated with the required kernel patch to pass this test.
Use spare device instead of test_mnt to create an alien btrfs device. Fix comment, remove ref to 196.
Fix _supported_fs generic

 tests/btrfs/197     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/197.out | 25 +++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 114 insertions(+)
 create mode 100755 tests/btrfs/197
 create mode 100644 tests/btrfs/197.out
tests/btrfs/197 new file +88 -0
new file mode 100755
index 000000000000..9019df1a4897
@@ -0,0 +1,88 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 197
+#
+# Test stale and alien btrfs-device in the fs devices list.
+#  Bug fixed in the kernel patch:
+#   btrfs: include non-missing as a qualifier for the latest_bdev
+#   btrfs: remove identified alien btrfs device in open_fs_devices
+#
+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()
+{
+	rm -rf $TEST_DIR/$seq.mnt
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_os Linux
+_supported_fs btrfs
+_require_scratch
+_require_scratch_dev_pool 5
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+	_spare_dev_get
+
+	_mkfs_dev $SPARE_DEV
+	mkdir -p $TEST_DIR/$seq.mnt
+	_mount $SPARE_DEV $TEST_DIR/$seq.mnt
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 an alien btrfs device for the raid created above by
+	# adding it to the $TEST_DIR
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR/$seq.mnt"
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the .out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	$BTRFS_UTIL_PROG device remove "$device_1" "$TEST_DIR/$seq.mnt"
+	umount $TEST_DIR/$seq.mnt
+	_scratch_unmount
+	_spare_dev_put
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/197.out new file +25 -0
new file mode 100644
index 000000000000..79237b854b5a
@@ -0,0 +1,25 @@
+QA output created by 197
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index c2ab3e7de9b6..208720efba61 100644
@@ -199,3 +199,4 @@
 194 auto volume
 195 auto volume
 196 auto metadata log volume
+197 auto quick volume
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH v2 2/2 fstest: btrfs/198: test for alien devices

Test if btrfs.ko sucessfully identifies and reports the missing device, if the missed device contians no btrfs magic string.

---
v2: Comments added to list kernel patch required to pass the test case
Fix copy and paste error in the comment

 tests/btrfs/198     | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/198.out | 25 +++++++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 105 insertions(+)
 create mode 100755 tests/btrfs/198
 create mode 100644 tests/btrfs/198.out
tests/btrfs/198 new file +79 -0
new file mode 100755
index 000000000000..c4c651b310c8
@@ -0,0 +1,79 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Oracle.  All Rights Reserved.
+#
+# FS QA Test 198
+#
+# Test stale and alien non-btrfs device in the fs devices list.
+#  Bug fixed in:
+#    btrfs: remove identified alien device in open_fs_devices
+#
+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
+. ./common/filter.btrfs
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_command "$WIPEFS_PROG" wipefs
+_require_scratch
+_require_scratch_dev_pool 4
+
+workout()
+{
+	raid=$1
+	device_nr=$2
+
+	echo $raid
+	_scratch_dev_pool_get $device_nr
+
+	_scratch_pool_mkfs "-d$raid -m$raid" >> $seqres.full 2>&1 || \
+							_fail "mkfs failed"
+
+	# Make device_1 a free btrfs device for the raid created above by
+	# clearing its superblock
+
+	# don't test with the first device as auto fs check (_check_scratch_fs)
+	# picks the first device
+	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1
+
+	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	_mount -o degraded $device_2 $SCRATCH_MNT
+	# Check if missing device is reported as in the 196.out
+	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
+						_filter_btrfs_filesystem_show
+
+	_scratch_unmount
+	_scratch_dev_pool_put
+}
+
+workout "raid1" "2"
+workout "raid5" "3"
+workout "raid6" "4"
+workout "raid10" "4"
+
+# success, all done
+status=0
+exit
tests/btrfs/198.out new file +25 -0
new file mode 100644
index 000000000000..af904a39efd6
@@ -0,0 +1,25 @@
+QA output created by 198
+raid1
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid5
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid6
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
+raid10
+Label: none  uuid: <UUID>
+	Total devices <NUM> FS bytes used <SIZE>
+	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
+	*** Some devices missing
+
tests/btrfs/group +1 -0
index 208720efba61..94961044f1fe 100644
@@ -200,3 +200,4 @@
 195 auto volume
 196 auto metadata log volume
 197 auto quick volume
+198 auto quick volume
Signature · 1 line
1.8.3.1