diff mbox series

[v2] fstests: use btrfs check repair for repairing btrfs filesystems

Message ID 28de98f456031353d34be71fe7b71937d3ef3e4b.1692600778.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v2] fstests: use btrfs check repair for repairing btrfs filesystems | expand

Commit Message

Anand Jain Aug. 21, 2023, 9:05 a.m. UTC
There are two repair functions: _repair_scratch_fs() and
_repair_test_fs(). As the names suggest, these functions are designed to
repair the filesystems SCRATCH_DEV and TEST_DEV, respectively. However,
these functions never called proper comamnd for the filesystem type btrfs.
This patch fixes it. Thx.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:

When I reran the tests, they hung because 'btrfs check --repair' was
waiting for confirmation to fix the tree, despite using the '--force'
option. This is a bug. However, we still need to support the older
btrfs-progs. So, pass in a 'yes' response.

Uses BTRFS_UTIL_PROG instead of btrfs.

 common/rc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Zorro Lang Sept. 13, 2023, 5:06 p.m. UTC | #1
On Mon, Aug 21, 2023 at 05:05:09PM +0800, Anand Jain wrote:
> There are two repair functions: _repair_scratch_fs() and
> _repair_test_fs(). As the names suggest, these functions are designed to
> repair the filesystems SCRATCH_DEV and TEST_DEV, respectively. However,
> these functions never called proper comamnd for the filesystem type btrfs.
> This patch fixes it. Thx.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---

This patch looks good to me. It's been several weeks past, there's not more
review points or better idea from others either. So I'd like to merge it, to
support btrfs specific repair.

Reviewed-by: Zorro Lang <zlang@redhat.com>

> v2:
> 
> When I reran the tests, they hung because 'btrfs check --repair' was
> waiting for confirmation to fix the tree, despite using the '--force'
> option. This is a bug. However, we still need to support the older
> btrfs-progs. So, pass in a 'yes' response.
> 
> Uses BTRFS_UTIL_PROG instead of btrfs.
> 
>  common/rc | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index 5002369b9b34..45cb56816c05 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -1187,6 +1187,15 @@ _repair_scratch_fs()
>  	fi
>  	return $res
>          ;;
> +    btrfs)
> +	echo "yes|$BTRFS_UTIL_PROG check --repair --force $SCRATCH_DEV"
> +	yes | $BTRFS_UTIL_PROG check --repair --force $SCRATCH_DEV 2>&1
> +	local res=$?
> +	if [ $res -ne 0 ]; then
> +		_dump_err2 "btrfs repair failed, err=$res"
> +	fi
> +	return $res
> +	;;
>      bcachefs)
>  	# With bcachefs, if fsck detects any errors we consider it a bug and we
>  	# want the test to fail:
> @@ -1239,6 +1248,13 @@ _repair_test_fs()
>  			res=$?
>  		fi
>  		;;
> +	btrfs)
> +	echo 'yes|$BTRFS_UTIL_PROG check --repair --force "$TEST_DEV"' > \
> +								/tmp.repair 2>&1
> +	yes | $BTRFS_UTIL_PROG check --repair --force "$TEST_DEV" >> \
> +								/tmp.repair 2>&1
> +		res=$?
> +		;;
>  	*)
>  		# Let's hope fsck -y suffices...
>  		fsck -t $FSTYP -y $TEST_DEV >$tmp.repair 2>&1
> -- 
> 2.38.1
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 5002369b9b34..45cb56816c05 100644
--- a/common/rc
+++ b/common/rc
@@ -1187,6 +1187,15 @@  _repair_scratch_fs()
 	fi
 	return $res
         ;;
+    btrfs)
+	echo "yes|$BTRFS_UTIL_PROG check --repair --force $SCRATCH_DEV"
+	yes | $BTRFS_UTIL_PROG check --repair --force $SCRATCH_DEV 2>&1
+	local res=$?
+	if [ $res -ne 0 ]; then
+		_dump_err2 "btrfs repair failed, err=$res"
+	fi
+	return $res
+	;;
     bcachefs)
 	# With bcachefs, if fsck detects any errors we consider it a bug and we
 	# want the test to fail:
@@ -1239,6 +1248,13 @@  _repair_test_fs()
 			res=$?
 		fi
 		;;
+	btrfs)
+	echo 'yes|$BTRFS_UTIL_PROG check --repair --force "$TEST_DEV"' > \
+								/tmp.repair 2>&1
+	yes | $BTRFS_UTIL_PROG check --repair --force "$TEST_DEV" >> \
+								/tmp.repair 2>&1
+		res=$?
+		;;
 	*)
 		# Let's hope fsck -y suffices...
 		fsck -t $FSTYP -y $TEST_DEV >$tmp.repair 2>&1