diff mbox series

[v6,1/3] common/xfs: add _require_xfs_scratch_shrink helper

Message ID 20210511233228.1018269-2-hsiangkao@redhat.com (mailing list archive)
State New, archived
Headers show
Series xfs: testcases for shrinking free space in the last AG | expand

Commit Message

Gao Xiang May 11, 2021, 11:32 p.m. UTC
In order to detect whether the current kernel supports XFS shrinking.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---
 common/xfs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Eryu Guan May 16, 2021, 3:31 p.m. UTC | #1
On Wed, May 12, 2021 at 07:32:26AM +0800, Gao Xiang wrote:
> In order to detect whether the current kernel supports XFS shrinking.
> 
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
> ---
>  common/xfs | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/common/xfs b/common/xfs
> index 69f76d6e..a0a4032a 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -766,6 +766,26 @@ _require_xfs_mkfs_without_validation()
>  	fi
>  }
>  
> +_require_xfs_scratch_shrink()

I renamed this to _require_scratch_xfs_shrink(), as most of other
helpers are in this format as _require_scratch_xfs_bigtime(), the only
exception is _require_xfs_scratch_rmapbt(), I think we should change
that too in another patch.

> +{
> +	_require_scratch
> +	_require_command "$XFS_GROWFS_PROG" xfs_growfs
> +
> +	_scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
> +	. $tmp.mkfs
> +	_scratch_mount
> +	# here just to check if kernel supports, no need do more extra work
> +	errmsg=$($XFS_GROWFS_PROG -D$((dblocks-1)) "$SCRATCH_MNT" 2>&1)

Also make it as local.

Thanks,
Eryu

> +	if [ "$?" -ne 0 ]; then
> +		echo "$errmsg" | grep 'XFS_IOC_FSGROWFSDATA xfsctl failed: Invalid argument' > /dev/null && \
> +			_notrun "kernel does not support shrinking"
> +		echo "$errmsg" | grep 'data size .* too small, old size is ' > /dev/null && \
> +			_notrun "xfsprogs does not support shrinking"
> +		_fail "$XFS_GROWFS_PROG failed unexpectedly: $errmsg"
> +	fi
> +	_scratch_unmount
> +}
> +
>  # XFS ability to change UUIDs on V5/CRC filesystems
>  #
>  _require_meta_uuid()
> -- 
> 2.27.0
diff mbox series

Patch

diff --git a/common/xfs b/common/xfs
index 69f76d6e..a0a4032a 100644
--- a/common/xfs
+++ b/common/xfs
@@ -766,6 +766,26 @@  _require_xfs_mkfs_without_validation()
 	fi
 }
 
+_require_xfs_scratch_shrink()
+{
+	_require_scratch
+	_require_command "$XFS_GROWFS_PROG" xfs_growfs
+
+	_scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
+	. $tmp.mkfs
+	_scratch_mount
+	# here just to check if kernel supports, no need do more extra work
+	errmsg=$($XFS_GROWFS_PROG -D$((dblocks-1)) "$SCRATCH_MNT" 2>&1)
+	if [ "$?" -ne 0 ]; then
+		echo "$errmsg" | grep 'XFS_IOC_FSGROWFSDATA xfsctl failed: Invalid argument' > /dev/null && \
+			_notrun "kernel does not support shrinking"
+		echo "$errmsg" | grep 'data size .* too small, old size is ' > /dev/null && \
+			_notrun "xfsprogs does not support shrinking"
+		_fail "$XFS_GROWFS_PROG failed unexpectedly: $errmsg"
+	fi
+	_scratch_unmount
+}
+
 # XFS ability to change UUIDs on V5/CRC filesystems
 #
 _require_meta_uuid()