All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature
@ 2022-06-27 14:30 Yang Xu
  2022-06-27 14:30 ` [PATCH 2/2] xfs/082: Add xfs_db get value regression test Yang Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yang Xu @ 2022-06-27 14:30 UTC (permalink / raw)
  To: fstests; +Cc: Yang Xu

Currently, this case fails on old xfsprogs as below:
+/var/lib/xfstests/tests/xfs/270: line 51: [: !=: unary operator expected

Getting ro_compat value will report the following error after setting new ro_compat
value:
+cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
+cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
+cache_zero_check: refcount is 1, not zero (node=0x56033fdf9110

Old xfsprogs miss a bugfix
f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()").

Here we skip the get step of new ro_comap value when nrext64 feature is supported.
Also will add a new test to cover this xfsprog bug.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 tests/xfs/270 | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tests/xfs/270 b/tests/xfs/270
index b740c379..5ff83ead 100755
--- a/tests/xfs/270
+++ b/tests/xfs/270
@@ -22,6 +22,10 @@ _require_scratch_nocheck
 # Only V5 XFS disallow rw mount/remount with unknown ro-compat features
 _require_scratch_xfs_crc
 
+nrext64_supported=0
+_scratch_mkfs_xfs_supported -m crc=1 -i nrext64 > /dev/null 2>&1 && \
+	nrext64_supported=1
+
 _scratch_mkfs_xfs >>$seqres.full 2>&1
 
 # set the highest bit of features_ro_compat, use it as an unknown
@@ -43,13 +47,18 @@ ro_compat=$(echo $ro_compat | \
 _scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
 				> $seqres.full 2>&1
 
-# read the newly set ro compat filed for verification
-new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
-						2>/dev/null)
-
-# verify the new ro_compat field is correct.
-if [ $new_ro_compat != $ro_compat ]; then
-	echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
+# Indeed, xfsprogs has a bug here and fixed by commit f4afdcb
+# ("xfs_db: clean up the salvage read callsites in set_cur()")
+# Here, we use nrext64 feature as a proxy.
+if [ $nrext64_supported -eq 1 ]; then
+	# read the newly set ro compat filed for verification
+	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" \
+					"sb 0" 2>/dev/null)
+	# verify the new ro_compat field is correct.
+	if [ $new_ro_compat != $ro_compat ]; then
+		echo "Unable to set new features_ro_compat. Wanted $ro_compat, \
+			got $new_ro_compat"
+	fi
 fi
 
 # rw mount with unknown ro-compat feature should fail
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] xfs/082: Add xfs_db get value regression test
  2022-06-27 14:30 [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature Yang Xu
@ 2022-06-27 14:30 ` Yang Xu
  2022-07-04 17:57   ` Zorro Lang
  2022-07-04  9:43 ` [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature xuyang2018.jy
  2022-07-04 15:42 ` Zorro Lang
  2 siblings, 1 reply; 7+ messages in thread
From: Yang Xu @ 2022-06-27 14:30 UTC (permalink / raw)
  To: fstests; +Cc: Yang Xu

This case is a regression test for xfsprogs commit
f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").

I found this because xfs/270 on older xfsprogs can hit this bug.
The code is pasted from xfs/270 but remove mount rw/ro test.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 tests/xfs/082     | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/082.out |  2 ++
 2 files changed, 69 insertions(+)
 create mode 100755 tests/xfs/082
 create mode 100644 tests/xfs/082.out

diff --git a/tests/xfs/082 b/tests/xfs/082
new file mode 100755
index 00000000..7a5ece8f
--- /dev/null
+++ b/tests/xfs/082
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+#
+# FS QA Test 082
+#
+# Today xfs_db set_cur whether clean up the LIBXFS_READBUF_SALVAGE
+# call sites so that we use the return value directly instead of
+# scraping it out later.
+# 
+# It is a regression test for xfsprogs
+# f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").
+#
+
+. ./common/preamble
+_begin_fstest auto quick mount
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+_supported_fs xfs
+# skip fs check because superblock contains unknown ro-compat features
+_require_scratch_nocheck
+# Only V5 XFS disallow rw mount/remount with unknown ro-compat features
+_require_scratch_xfs_crc
+
+_scratch_mkfs_xfs >>$seqres.full 2>&1
+
+# set the highest bit of features_ro_compat, use it as an unknown
+# feature bit. If one day this bit become known feature, please
+# change this case.
+
+ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
+echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$'
+if [[ $? != 0  ]]; then
+	echo "features_ro_compat has an invalid value."
+fi
+
+ro_compat=$(echo $ro_compat | \
+		    awk '/^0x[[:xdigit:]]+/ {
+				printf("0x%x\n", or(strtonum($1), 0x80000000))
+			}')
+
+# write the new ro compat field to the superblock
+_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
+				> $seqres.full 2>&1
+
+# read the newly set ro compat filed for verification
+new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
+					>$seqres.full 2>&1)
+
+# verify the new ro_compat field is empty
+# Without xfsprog patch, xfs_db set_cur function doesn't return directly when
+# meeting error by using LIBXFS_READBUF_SALVAGE flag. So cache_purge will complain
+# about this.
+if [ -z $new_ro_compat ]; then
+	grep -q "cache_purge: shake on cache" $seqres.full && \
+		echo "Hit xfsprogs set_cur bug"
+	echo "Unable to get new ro compat filed"
+fi
+
+echo "Silence is golden."
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/082.out b/tests/xfs/082.out
new file mode 100644
index 00000000..6ed56cb1
--- /dev/null
+++ b/tests/xfs/082.out
@@ -0,0 +1,2 @@
+QA output created by 082
+Silence is golden.
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature
  2022-06-27 14:30 [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature Yang Xu
  2022-06-27 14:30 ` [PATCH 2/2] xfs/082: Add xfs_db get value regression test Yang Xu
@ 2022-07-04  9:43 ` xuyang2018.jy
  2022-07-04 15:42 ` Zorro Lang
  2 siblings, 0 replies; 7+ messages in thread
From: xuyang2018.jy @ 2022-07-04  9:43 UTC (permalink / raw)
  To: Zorro Lang; +Cc: fstests

Hi Zorro

What do you think this patch or should I just add a 'x' string when
comparing get_value/new_value, then just remind user they may hit a old
xfsprogs bug

f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").

Best Regards
Yang Xu

> Currently, this case fails on old xfsprogs as below:
> +/var/lib/xfstests/tests/xfs/270: line 51: [: !=: unary operator expected
> 
> Getting ro_compat value will report the following error after setting new ro_compat
> value:
> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
> +cache_zero_check: refcount is 1, not zero (node=0x56033fdf9110
> 
> Old xfsprogs miss a bugfix
> f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()").
> 
> Here we skip the get step of new ro_comap value when nrext64 feature is supported.
> Also will add a new test to cover this xfsprog bug.
> 
> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
> ---
>   tests/xfs/270 | 23 ++++++++++++++++-------
>   1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/xfs/270 b/tests/xfs/270
> index b740c379..5ff83ead 100755
> --- a/tests/xfs/270
> +++ b/tests/xfs/270
> @@ -22,6 +22,10 @@ _require_scratch_nocheck
>   # Only V5 XFS disallow rw mount/remount with unknown ro-compat features
>   _require_scratch_xfs_crc
> 
> +nrext64_supported=0
> +_scratch_mkfs_xfs_supported -m crc=1 -i nrext64>  /dev/null 2>&1&&  \
> +	nrext64_supported=1
> +
>   _scratch_mkfs_xfs>>$seqres.full 2>&1
> 
>   # set the highest bit of features_ro_compat, use it as an unknown
> @@ -43,13 +47,18 @@ ro_compat=$(echo $ro_compat | \
>   _scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
>   				>  $seqres.full 2>&1
> 
> -# read the newly set ro compat filed for verification
> -new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
> -						2>/dev/null)
> -
> -# verify the new ro_compat field is correct.
> -if [ $new_ro_compat != $ro_compat ]; then
> -	echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
> +# Indeed, xfsprogs has a bug here and fixed by commit f4afdcb
> +# ("xfs_db: clean up the salvage read callsites in set_cur()")
> +# Here, we use nrext64 feature as a proxy.
> +if [ $nrext64_supported -eq 1 ]; then
> +	# read the newly set ro compat filed for verification
> +	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" \
> +					"sb 0" 2>/dev/null)
> +	# verify the new ro_compat field is correct.
> +	if [ $new_ro_compat != $ro_compat ]; then
> +		echo "Unable to set new features_ro_compat. Wanted $ro_compat, \
> +			got $new_ro_compat"
> +	fi
>   fi
> 
>   # rw mount with unknown ro-compat feature should fail

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature
  2022-06-27 14:30 [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature Yang Xu
  2022-06-27 14:30 ` [PATCH 2/2] xfs/082: Add xfs_db get value regression test Yang Xu
  2022-07-04  9:43 ` [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature xuyang2018.jy
@ 2022-07-04 15:42 ` Zorro Lang
  2022-07-05  5:46   ` xuyang2018.jy
  2 siblings, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2022-07-04 15:42 UTC (permalink / raw)
  To: Yang Xu; +Cc: fstests

On Mon, Jun 27, 2022 at 10:30:02PM +0800, Yang Xu wrote:
> Currently, this case fails on old xfsprogs as below:
> +/var/lib/xfstests/tests/xfs/270: line 51: [: !=: unary operator expected
> 
> Getting ro_compat value will report the following error after setting new ro_compat
> value:
> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
> +cache_zero_check: refcount is 1, not zero (node=0x56033fdf9110
> 
> Old xfsprogs miss a bugfix
> f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()").
> 
> Here we skip the get step of new ro_comap value when nrext64 feature is supported.
> Also will add a new test to cover this xfsprog bug.
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  tests/xfs/270 | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/xfs/270 b/tests/xfs/270
> index b740c379..5ff83ead 100755
> --- a/tests/xfs/270
> +++ b/tests/xfs/270
> @@ -22,6 +22,10 @@ _require_scratch_nocheck
>  # Only V5 XFS disallow rw mount/remount with unknown ro-compat features
>  _require_scratch_xfs_crc
>  
> +nrext64_supported=0
> +_scratch_mkfs_xfs_supported -m crc=1 -i nrext64 > /dev/null 2>&1 && \
> +	nrext64_supported=1
> +
>  _scratch_mkfs_xfs >>$seqres.full 2>&1
>  
>  # set the highest bit of features_ro_compat, use it as an unknown
> @@ -43,13 +47,18 @@ ro_compat=$(echo $ro_compat | \
>  _scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
>  				> $seqres.full 2>&1
>  
> -# read the newly set ro compat filed for verification
> -new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
> -						2>/dev/null)
> -
> -# verify the new ro_compat field is correct.
> -if [ $new_ro_compat != $ro_compat ]; then

My personal opinion is -- change above line as:
   if [ "$new_ro_compat" != "$ro_compat" ]
to avoid the bash syntax error. Then the failure (on old xfsprogs) correspond
to a known xfsprogs bug. That's good enough.

Thanks,
Zorro

> -	echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
> +# Indeed, xfsprogs has a bug here and fixed by commit f4afdcb
> +# ("xfs_db: clean up the salvage read callsites in set_cur()")
> +# Here, we use nrext64 feature as a proxy.
> +if [ $nrext64_supported -eq 1 ]; then
> +	# read the newly set ro compat filed for verification
> +	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" \
> +					"sb 0" 2>/dev/null)
> +	# verify the new ro_compat field is correct.
> +	if [ $new_ro_compat != $ro_compat ]; then
> +		echo "Unable to set new features_ro_compat. Wanted $ro_compat, \
> +			got $new_ro_compat"
> +	fi
>  fi
>  
>  # rw mount with unknown ro-compat feature should fail
> -- 
> 2.27.0
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] xfs/082: Add xfs_db get value regression test
  2022-06-27 14:30 ` [PATCH 2/2] xfs/082: Add xfs_db get value regression test Yang Xu
@ 2022-07-04 17:57   ` Zorro Lang
  2022-07-05  7:23     ` xuyang2018.jy
  0 siblings, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2022-07-04 17:57 UTC (permalink / raw)
  To: Yang Xu; +Cc: fstests

On Mon, Jun 27, 2022 at 10:30:03PM +0800, Yang Xu wrote:
> This case is a regression test for xfsprogs commit
> f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").
> 
> I found this because xfs/270 on older xfsprogs can hit this bug.
> The code is pasted from xfs/270 but remove mount rw/ro test.
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  tests/xfs/082     | 67 +++++++++++++++++++++++++++++++++++++++++++++++
>  tests/xfs/082.out |  2 ++
>  2 files changed, 69 insertions(+)
>  create mode 100755 tests/xfs/082
>  create mode 100644 tests/xfs/082.out
> 
> diff --git a/tests/xfs/082 b/tests/xfs/082
> new file mode 100755
> index 00000000..7a5ece8f
> --- /dev/null
> +++ b/tests/xfs/082
> @@ -0,0 +1,67 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +#
> +# FS QA Test 082
> +#
> +# Today xfs_db set_cur whether clean up the LIBXFS_READBUF_SALVAGE
> +# call sites so that we use the return value directly instead of
> +# scraping it out later.
> +# 
> +# It is a regression test for xfsprogs
> +# f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").
> +#
> +
> +. ./common/preamble
> +_begin_fstest auto quick mount
> +
> +# Import common functions.
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs xfs
> +# skip fs check because superblock contains unknown ro-compat features
> +_require_scratch_nocheck
> +# Only V5 XFS disallow rw mount/remount with unknown ro-compat features
> +_require_scratch_xfs_crc
> +
> +_scratch_mkfs_xfs >>$seqres.full 2>&1
> +
> +# set the highest bit of features_ro_compat, use it as an unknown
> +# feature bit. If one day this bit become known feature, please
> +# change this case.
> +
> +ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
> +echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$'
> +if [[ $? != 0  ]]; then
> +	echo "features_ro_compat has an invalid value."
> +fi
> +
> +ro_compat=$(echo $ro_compat | \
> +		    awk '/^0x[[:xdigit:]]+/ {
> +				printf("0x%x\n", or(strtonum($1), 0x80000000))
> +			}')
> +
> +# write the new ro compat field to the superblock
> +_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
> +				> $seqres.full 2>&1
> +
> +# read the newly set ro compat filed for verification
> +new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
> +					>$seqres.full 2>&1)

Hi,

Although you hit this issue by xfs/270, but that doesn't mean you need to do the
same complicated calculation.

You nearly can corrupt many fields to trigger that xfs_db bug, due to
you don't need to test xfs mount. For example corrupt the features_ro_compat
simply:

  # xfs_db -x -c "sb 0" -c "write -d features_ro_compat 0x80000000" /dev/sda3
  Allowing write of corrupted data with good CRC
  features_ro_compat = 0x80000000
  # xfs_db -c "sb 0" -c "print features_ro_compat" /dev/sda3
  Superblock has unknown read-only compatible features (0x80000000) enabled.
  Attempted to mount read-only compatible filesystem read-write.
  Filesystem can only be safely mounted read only.
  no current type
  cache_purge: shake on cache 0x562ed6463a70 left 1 nodes!?
  cache_purge: shake on cache 0x562ed6463a70 left 1 nodes!?
  cache_zero_check: refcount is 1, not zero (node=0x562ed6478110)

Or even corrupt the sb magicnum (sb 0 need -F) directly:

  # xfs_db -x -c "sb 1" -c "write -d magicnum 0" /dev/sda3
  Allowing write of corrupted data and bad CRC
  magicnum = 0
  # xfs_db -c "sb 1" -c "print magicnum" /dev/sda3
  bad magic number
  no current type
  cache_purge: shake on cache 0x5589a86a9a70 left 1 nodes!?
  cache_purge: shake on cache 0x5589a86a9a70 left 1 nodes!?
  cache_zero_check: refcount is 1, not zero (node=0x5589a86be110)

Or choose other fields you feel good.

> +
> +# verify the new ro_compat field is empty
> +# Without xfsprog patch, xfs_db set_cur function doesn't return directly when
> +# meeting error by using LIBXFS_READBUF_SALVAGE flag. So cache_purge will complain
> +# about this.
> +if [ -z $new_ro_compat ]; then
> +	grep -q "cache_purge: shake on cache" $seqres.full && \
> +		echo "Hit xfsprogs set_cur bug"
> +	echo "Unable to get new ro compat filed"

Let those "cache_purge ..." things break golden image (.out2 file) directly.

> +fi
> +
> +echo "Silence is golden."
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/xfs/082.out b/tests/xfs/082.out
> new file mode 100644
> index 00000000..6ed56cb1
> --- /dev/null
> +++ b/tests/xfs/082.out
> @@ -0,0 +1,2 @@
> +QA output created by 082
> +Silence is golden.
> -- 
> 2.27.0
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature
  2022-07-04 15:42 ` Zorro Lang
@ 2022-07-05  5:46   ` xuyang2018.jy
  0 siblings, 0 replies; 7+ messages in thread
From: xuyang2018.jy @ 2022-07-05  5:46 UTC (permalink / raw)
  To: Zorro Lang; +Cc: fstests

on 2022/07/04 23:42, Zorro Lang wrote:
> On Mon, Jun 27, 2022 at 10:30:02PM +0800, Yang Xu wrote:
>> Currently, this case fails on old xfsprogs as below:
>> +/var/lib/xfstests/tests/xfs/270: line 51: [: !=: unary operator expected
>>
>> Getting ro_compat value will report the following error after setting new ro_compat
>> value:
>> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
>> +cache_purge: shake on cache 0x56033fde4920 left 1 nodes!?
>> +cache_zero_check: refcount is 1, not zero (node=0x56033fdf9110
>>
>> Old xfsprogs miss a bugfix
>> f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()").
>>
>> Here we skip the get step of new ro_comap value when nrext64 feature is supported.
>> Also will add a new test to cover this xfsprog bug.
>>
>> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
>> ---
>>   tests/xfs/270 | 23 ++++++++++++++++-------
>>   1 file changed, 16 insertions(+), 7 deletions(-)
>>
>> diff --git a/tests/xfs/270 b/tests/xfs/270
>> index b740c379..5ff83ead 100755
>> --- a/tests/xfs/270
>> +++ b/tests/xfs/270
>> @@ -22,6 +22,10 @@ _require_scratch_nocheck
>>   # Only V5 XFS disallow rw mount/remount with unknown ro-compat features
>>   _require_scratch_xfs_crc
>>
>> +nrext64_supported=0
>> +_scratch_mkfs_xfs_supported -m crc=1 -i nrext64>  /dev/null 2>&1&&  \
>> +	nrext64_supported=1
>> +
>>   _scratch_mkfs_xfs>>$seqres.full 2>&1
>>
>>   # set the highest bit of features_ro_compat, use it as an unknown
>> @@ -43,13 +47,18 @@ ro_compat=$(echo $ro_compat | \
>>   _scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
>>   				>  $seqres.full 2>&1
>>
>> -# read the newly set ro compat filed for verification
>> -new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
>> -						2>/dev/null)
>> -
>> -# verify the new ro_compat field is correct.
>> -if [ $new_ro_compat != $ro_compat ]; then
>
> My personal opinion is -- change above line as:
>     if [ "$new_ro_compat" != "$ro_compat" ]
> to avoid the bash syntax error. Then the failure (on old xfsprogs) correspond
> to a known xfsprogs bug. That's good enough.

Ok, will do it on v2. Thanks.

Best Regards
Yang Xu
>
> Thanks,
> Zorro
>
>> -	echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
>> +# Indeed, xfsprogs has a bug here and fixed by commit f4afdcb
>> +# ("xfs_db: clean up the salvage read callsites in set_cur()")
>> +# Here, we use nrext64 feature as a proxy.
>> +if [ $nrext64_supported -eq 1 ]; then
>> +	# read the newly set ro compat filed for verification
>> +	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" \
>> +					"sb 0" 2>/dev/null)
>> +	# verify the new ro_compat field is correct.
>> +	if [ $new_ro_compat != $ro_compat ]; then
>> +		echo "Unable to set new features_ro_compat. Wanted $ro_compat, \
>> +			got $new_ro_compat"
>> +	fi
>>   fi
>>
>>   # rw mount with unknown ro-compat feature should fail
>> --
>> 2.27.0
>>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] xfs/082: Add xfs_db get value regression test
  2022-07-04 17:57   ` Zorro Lang
@ 2022-07-05  7:23     ` xuyang2018.jy
  0 siblings, 0 replies; 7+ messages in thread
From: xuyang2018.jy @ 2022-07-05  7:23 UTC (permalink / raw)
  To: Zorro Lang; +Cc: fstests

on 2022/07/05 1:57, Zorro Lang wrote:
> On Mon, Jun 27, 2022 at 10:30:03PM +0800, Yang Xu wrote:
>> This case is a regression test for xfsprogs commit
>> f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").
>>
>> I found this because xfs/270 on older xfsprogs can hit this bug.
>> The code is pasted from xfs/270 but remove mount rw/ro test.
>>
>> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
>> ---
>>   tests/xfs/082     | 67 +++++++++++++++++++++++++++++++++++++++++++++++
>>   tests/xfs/082.out |  2 ++
>>   2 files changed, 69 insertions(+)
>>   create mode 100755 tests/xfs/082
>>   create mode 100644 tests/xfs/082.out
>>
>> diff --git a/tests/xfs/082 b/tests/xfs/082
>> new file mode 100755
>> index 00000000..7a5ece8f
>> --- /dev/null
>> +++ b/tests/xfs/082
>> @@ -0,0 +1,67 @@
>> +#! /bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> +#
>> +# FS QA Test 082
>> +#
>> +# Today xfs_db set_cur whether clean up the LIBXFS_READBUF_SALVAGE
>> +# call sites so that we use the return value directly instead of
>> +# scraping it out later.
>> +#
>> +# It is a regression test for xfsprogs
>> +# f4afdcb0a ("xfs_db: clean up the salvage read callsites in set_cur()").
>> +#
>> +
>> +. ./common/preamble
>> +_begin_fstest auto quick mount
>> +
>> +# Import common functions.
>> +. ./common/filter
>> +
>> +# real QA test starts here
>> +_supported_fs xfs
>> +# skip fs check because superblock contains unknown ro-compat features
>> +_require_scratch_nocheck
>> +# Only V5 XFS disallow rw mount/remount with unknown ro-compat features
>> +_require_scratch_xfs_crc
>> +
>> +_scratch_mkfs_xfs>>$seqres.full 2>&1
>> +
>> +# set the highest bit of features_ro_compat, use it as an unknown
>> +# feature bit. If one day this bit become known feature, please
>> +# change this case.
>> +
>> +ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
>> +echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$'
>> +if [[ $? != 0  ]]; then
>> +	echo "features_ro_compat has an invalid value."
>> +fi
>> +
>> +ro_compat=$(echo $ro_compat | \
>> +		    awk '/^0x[[:xdigit:]]+/ {
>> +				printf("0x%x\n", or(strtonum($1), 0x80000000))
>> +			}')
>> +
>> +# write the new ro compat field to the superblock
>> +_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
>> +				>  $seqres.full 2>&1
>> +
>> +# read the newly set ro compat filed for verification
>> +new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
>> +					>$seqres.full 2>&1)
>
> Hi,
>
> Although you hit this issue by xfs/270, but that doesn't mean you need to do the
> same complicated calculation.
>
> You nearly can corrupt many fields to trigger that xfs_db bug, due to
> you don't need to test xfs mount. For example corrupt the features_ro_compat
> simply:
>
>    # xfs_db -x -c "sb 0" -c "write -d features_ro_compat 0x80000000" /dev/sda3
>    Allowing write of corrupted data with good CRC
>    features_ro_compat = 0x80000000
>    # xfs_db -c "sb 0" -c "print features_ro_compat" /dev/sda3
>    Superblock has unknown read-only compatible features (0x80000000) enabled.
>    Attempted to mount read-only compatible filesystem read-write.
>    Filesystem can only be safely mounted read only.
>    no current type
>    cache_purge: shake on cache 0x562ed6463a70 left 1 nodes!?
>    cache_purge: shake on cache 0x562ed6463a70 left 1 nodes!?
>    cache_zero_check: refcount is 1, not zero (node=0x562ed6478110)
>
> Or even corrupt the sb magicnum (sb 0 need -F) directly:
>
>    # xfs_db -x -c "sb 1" -c "write -d magicnum 0" /dev/sda3
>    Allowing write of corrupted data and bad CRC
>    magicnum = 0
>    # xfs_db -c "sb 1" -c "print magicnum" /dev/sda3
>    bad magic number
>    no current type
>    cache_purge: shake on cache 0x5589a86a9a70 left 1 nodes!?
>    cache_purge: shake on cache 0x5589a86a9a70 left 1 nodes!?
>    cache_zero_check: refcount is 1, not zero (node=0x5589a86be110)

I think corrputing sb 1 magic number is ok. Will use it on v2. Thanks.

>
> Or choose other fields you feel good.


>
>> +
>> +# verify the new ro_compat field is empty
>> +# Without xfsprog patch, xfs_db set_cur function doesn't return directly when
>> +# meeting error by using LIBXFS_READBUF_SALVAGE flag. So cache_purge will complain
>> +# about this.
>> +if [ -z $new_ro_compat ]; then
>> +	grep -q "cache_purge: shake on cache" $seqres.full&&  \
>> +		echo "Hit xfsprogs set_cur bug"
>> +	echo "Unable to get new ro compat filed"
>
> Let those "cache_purge ..." things break golden image (.out2 file) directly.

Yes.

Best Regard
Yang Xu
>
>> +fi
>> +
>> +echo "Silence is golden."
>> +
>> +# success, all done
>> +status=0
>> +exit
>> diff --git a/tests/xfs/082.out b/tests/xfs/082.out
>> new file mode 100644
>> index 00000000..6ed56cb1
>> --- /dev/null
>> +++ b/tests/xfs/082.out
>> @@ -0,0 +1,2 @@
>> +QA output created by 082
>> +Silence is golden.
>> --
>> 2.27.0
>>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-05  7:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 14:30 [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature Yang Xu
2022-06-27 14:30 ` [PATCH 2/2] xfs/082: Add xfs_db get value regression test Yang Xu
2022-07-04 17:57   ` Zorro Lang
2022-07-05  7:23     ` xuyang2018.jy
2022-07-04  9:43 ` [PATCH 1/2] xfs/270: only check new_ro_compat value when mkfs.xfs supports nrext64 feature xuyang2018.jy
2022-07-04 15:42 ` Zorro Lang
2022-07-05  5:46   ` xuyang2018.jy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.