Skip to contentSkip to conversation

_supports_xfs_scrub cleanups

PATCH In review Christoph Hellwig 3 participants 12 messages Jan 11, 2024 – Jan 12, 2024

lore
Share & tools
lore
#0 lore raw

Hi all,

this series adds a missing scrub support fix to xfs/262 and cleans up a few bits around this.

#1 lore raw

PATCH 1/3 xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Add a sanity check that the passed in mount point is actually mounted to guard against actually calling _supports_xfs_scrub before $SCRATCH_MNT is mounted.

---
 common/xfs | 2 ++
 1 file changed, 2 insertions(+)
common/xfs +2 -0
index f53b33fc5..9db998837 100644
@@ -649,6 +649,8 @@ _supports_xfs_scrub()
 	test "$FSTYP" = "xfs" || return 1
 	test -x "$XFS_SCRUB_PROG" || return 1
 
+	mountpoint $mountpoint >/dev/null || echo "$mountpoint is not mounted"
+
 	# Probe for kernel support...
 	$XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
 	$XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Quoted 14 lines · Christoph Hellwig

Add a sanity check that the passed in mount point is actually mounted to guard against actually calling _supports_xfs_scrub before $SCRATCH_MNT is mounted.

---
 common/xfs | 2 ++
 1 file changed, 2 insertions(+)
common/xfs +0 -0
index f53b33fc5..9db998837 100644

common/xfs _supports_xfs_scrub() · line 652

Quoted 4 lines
common/xfs +1 -0
@@ -649,6 +649,8 @@ _supports_xfs_scrub()
 	test "$FSTYP" = "xfs" || return 1
 	test -x "$XFS_SCRUB_PROG" || return 1
 
+	mountpoint $mountpoint >/dev/null || echo "$mountpoint is not mounted"

The helper needs to return nonzero on failure, e.g.

if ! mountpoint -q $mountpoint; then
echo "$mountpoint is not mounted"
return 1
fi

common/xfs _supports_xfs_scrub() · line 655

Quoted 3 lines
common/xfs +1 -0
+
 	# Probe for kernel support...
 	$XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1

Like it already does down here.

--D

Quoted 4 lines
common/xfs +0 -0
 	$XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
Signature · 1 line
2.39.2
#3 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Quoted 8 lines · Darrick J. Wong

common/xfs _supports_xfs_scrub() · line 652

Quoted 1 line
common/xfs +1 -0
+	mountpoint $mountpoint >/dev/null || echo "$mountpoint is not mounted"

The helper needs to return nonzero on failure, e.g.

if ! mountpoint -q $mountpoint; then
echo "$mountpoint is not mounted"
return 1
fi

No, it doesn't.. I actually did exactly that first, but that causes the test to be _notrun instead of reporting the error and thus telling the author that they usage of this helper is wrong.

#4 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

common/xfs _supports_xfs_scrub() · line 652

Quoted 1 line
common/xfs +1 -0
+	mountpoint $mountpoint >/dev/null || echo "$mountpoint is not mounted"

The helper needs to return nonzero on failure, e.g.

Quoted 8 lines
Quoted 4 lines

if ! mountpoint -q $mountpoint; then
echo "$mountpoint is not mounted"
return 1
fi

No, it doesn't.. I actually did exactly that first, but that causes the test to be _notrun instead of reporting the error and thus telling the author that they usage of this helper is wrong.

So below "usage" message won't be gotten either, if a _notrun be called after this helper return 1 .

if [ -z "$device" ] || [ -z "$mountpoint" ]; then
echo "Usage: _supports_xfs_scrub mountpoint device" return 1
fi

If there's not _notrun after that, the message will be gotten I think. So I think the "return 1" makes sense.

What do both of you think ?

Thanks,
Zorro

Quoted 1 line
#5 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Quoted 23 lines · Zorro Lang
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

common/xfs _supports_xfs_scrub() · line 652

Quoted 1 line
common/xfs +1 -0
+	mountpoint $mountpoint >/dev/null || echo "$mountpoint is not mounted"

The helper needs to return nonzero on failure, e.g.

Quoted 8 lines
Quoted 4 lines

if ! mountpoint -q $mountpoint; then
echo "$mountpoint is not mounted"
return 1
fi

No, it doesn't.. I actually did exactly that first, but that causes the test to be _notrun instead of reporting the error and thus telling the author that they usage of this helper is wrong.

So below "usage" message won't be gotten either, if a _notrun be called after this helper return 1 .

if [ -z "$device" ] || [ -z "$mountpoint" ]; then
echo "Usage: _supports_xfs_scrub mountpoint device" return 1
fi

Quoted 4 lines

If there's not _notrun after that, the message will be gotten I think. So I think the "return 1" makes sense.

What do both of you think ?

_fail "\$mountpoint must be mounted to use _require_scratch_xfs_scrub" ?

--D

Quoted 6 lines

Thanks,
Zorro

Quoted 1 line
#6 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

Quoted 6 lines · Darrick J. Wong
Quoted 4 lines

If there's not _notrun after that, the message will be gotten I think. So I think the "return 1" makes sense.

What do both of you think ?

_fail "\$mountpoint must be mounted to use _require_scratch_xfs_scrub" ?

Yes, that's better. I didn't even remember _fail exists..

#7 lore raw

Re: [PATCH 1/3] xfs: check that the mountpoint is actually mounted in _supports_xfs_scrub

In reply to Zorro Lang
Quoted 6 lines · Zorro Lang
Quoted 3 lines

No, it doesn't.. I actually did exactly that first, but that causes the test to be _notrun instead of reporting the error and thus telling the author that they usage of this helper is wrong.

So below "usage" message won't be gotten either, if a _notrun be called after this helper return 1 .

True. But for the case reproducing my original error where I just misplaced it it does get shown.

Quoted 2 lines

If there's not _notrun after that, the message will be gotten I think. So I think the "return 1" makes sense.

As this point we might as well skip this patch, as it won't be useful.

#8 lore raw

PATCH 2/3 xfs: add a _scratch_require_xfs_scrub helper

In reply to Christoph Hellwig

Add a helper to call _supports_xfs_scrub with $SCRATCH_MNT and $SCRATCH_DEV.

---
 common/xfs    | 7 +++++++
 tests/xfs/556 | 2 +-
 tests/xfs/716 | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)
common/xfs +7 -0
index 9db998837..bfe979dbb 100644
@@ -661,6 +661,13 @@ _supports_xfs_scrub()
 	return 0
 }
 
+# Does the scratch file system support scrub?
+_scratch_require_xfs_scrub()
+{
+	_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || \
+		_notrun "Scrub not supported"
+}
+
 # Save a snapshot of a corrupt xfs filesystem for later debugging.
 _xfs_metadump() {
 	local metadump="$1"
tests/xfs/556 +1 -1
index 061d8d572..6be993273 100755
@@ -40,7 +40,7 @@ _scratch_mkfs >> $seqres.full
 _dmerror_init
 _dmerror_mount >> $seqres.full 2>&1
 
-_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || _notrun "Scrub not supported"
+_scratch_require_xfs_scrub
 
 # Write a file with 4 file blocks worth of data
 victim=$SCRATCH_MNT/a
tests/xfs/716 +1 -1
index 930a0ecbb..4cfb27f18 100755
@@ -31,7 +31,7 @@ _require_test_program "punch-alternating"
 _scratch_mkfs > $tmp.mkfs
 _scratch_mount
 
-_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || _notrun "Scrub not supported"
+_scratch_require_xfs_scrub
 
 # Force data device extents so that we can create a file with the exact bmbt
 # that we need regardless of rt configuration.
Signature · 1 line
2.39.2
Reviewed-by on v1 2/3
#9 lore raw

Re: [PATCH 2/3] xfs: add a _scratch_require_xfs_scrub helper

Quoted 4 lines · Christoph Hellwig

Add a helper to call _supports_xfs_scrub with $SCRATCH_MNT and $SCRATCH_DEV.

Thanks for the cleanup,

--D

Quoted 53 lines
---
 common/xfs    | 7 +++++++
 tests/xfs/556 | 2 +-
 tests/xfs/716 | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)
common/xfs +7 -0
index 9db998837..bfe979dbb 100644
@@ -661,6 +661,13 @@ _supports_xfs_scrub()
 	return 0
 }
 
+# Does the scratch file system support scrub?
+_scratch_require_xfs_scrub()
+{
+	_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || \
+		_notrun "Scrub not supported"
+}
+
 # Save a snapshot of a corrupt xfs filesystem for later debugging.
 _xfs_metadump() {
 	local metadump="$1"
tests/xfs/556 +1 -1
index 061d8d572..6be993273 100755
@@ -40,7 +40,7 @@ _scratch_mkfs >> $seqres.full
 _dmerror_init
 _dmerror_mount >> $seqres.full 2>&1
 
-_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || _notrun "Scrub not supported"
+_scratch_require_xfs_scrub
 
 # Write a file with 4 file blocks worth of data
 victim=$SCRATCH_MNT/a
tests/xfs/716 +1 -1
index 930a0ecbb..4cfb27f18 100755
@@ -31,7 +31,7 @@ _require_test_program "punch-alternating"
 _scratch_mkfs > $tmp.mkfs
 _scratch_mount
 
-_supports_xfs_scrub $SCRATCH_MNT $SCRATCH_DEV || _notrun "Scrub not supported"
+_scratch_require_xfs_scrub
 
 # Force data device extents so that we can create a file with the exact bmbt
 # that we need regardless of rt configuration.
Signature · 1 line
2.39.2
#10 lore raw

PATCH 3/3 xfs/262: call _scratch_require_xfs_scrub

In reply to Christoph Hellwig

Call _scratch_require_xfs_scrub so that the test is _notrun on kernels without online scrub support.

---
 tests/xfs/262 | 3 +++
 1 file changed, 3 insertions(+)
tests/xfs/262 +3 -0
index b28a6c88b..0d1fd779d 100755
@@ -29,6 +29,9 @@ _require_xfs_io_error_injection "force_repair"
 echo "Format and populate"
 _scratch_mkfs > "$seqres.full" 2>&1
 _scratch_mount
+
+_scratch_require_xfs_scrub
+
 cp $XFS_SCRUB_PROG $SCRATCH_MNT/xfs_scrub
 $LDD_PROG $XFS_SCRUB_PROG | sed -e '/\//!d;/linux-gate/d;/=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/};s/[[:blank:]]*\([^[:blank:]]*\) (.*)/\1/' | while read lib; do
 	cp $lib $SCRATCH_MNT/
Signature · 1 line
2.39.2
Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] xfs/262: call _scratch_require_xfs_scrub

Quoted 4 lines · Christoph Hellwig

Call _scratch_require_xfs_scrub so that the test is _notrun on kernels without online scrub support.

Looks good!

--D

Quoted 21 lines
---
 tests/xfs/262 | 3 +++
 1 file changed, 3 insertions(+)
tests/xfs/262 +3 -0
index b28a6c88b..0d1fd779d 100755
@@ -29,6 +29,9 @@ _require_xfs_io_error_injection "force_repair"
 echo "Format and populate"
 _scratch_mkfs > "$seqres.full" 2>&1
 _scratch_mount
+
+_scratch_require_xfs_scrub
+
 cp $XFS_SCRUB_PROG $SCRATCH_MNT/xfs_scrub
 $LDD_PROG $XFS_SCRUB_PROG | sed -e '/\//!d;/linux-gate/d;/=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/};s/[[:blank:]]*\([^[:blank:]]*\) (.*)/\1/' | while read lib; do
 	cp $lib $SCRATCH_MNT/
Signature · 1 line
2.39.2