diff mbox series

[V5,02/13] common/xfs: Add a helper to get an inode fork's extent count

Message ID 20210308155111.53874-3-chandanrlinux@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series xfs: Tests to verify inode fork extent count overflow detection | expand

Commit Message

Chandan Babu R March 8, 2021, 3:51 p.m. UTC
This commit adds the helper _scratch_get_iext_count() which returns an
inode fork's extent count.

Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
 common/xfs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Darrick J. Wong March 8, 2021, 5:52 p.m. UTC | #1
On Mon, Mar 08, 2021 at 09:21:00PM +0530, Chandan Babu R wrote:
> This commit adds the helper _scratch_get_iext_count() which returns an
> inode fork's extent count.
> 
> Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
> ---
>  common/xfs | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/common/xfs b/common/xfs
> index 7ec89492..f0ae321e 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -914,6 +914,29 @@ _scratch_get_bmx_prefix() {
>  	return 1
>  }
>  
> +_scratch_get_iext_count()
> +{
> +	local ino=$1
> +	local whichfork=$2
> +	local nextents=0
> +	local field=""
> +
> +	case $whichfork in
> +		"attr")
> +			field=core.naextents
> +			;;
> +		"data")
> +			field=core.nextents
> +			;;
> +		*)
> +			return 1
> +	esac
> +
> +	nextents=$(_scratch_xfs_get_metadata_field $field "inode $ino")
> +
> +	echo $nextents

Any reason why you capture the contents into a variable and then echo
the variable a line later?  You could omit all that and just end with
the get_metadata_field call.

--D

> +}
> +
>  #
>  # Ensures that we don't pass any mount options incompatible with XFS v4
>  #
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/common/xfs b/common/xfs
index 7ec89492..f0ae321e 100644
--- a/common/xfs
+++ b/common/xfs
@@ -914,6 +914,29 @@  _scratch_get_bmx_prefix() {
 	return 1
 }
 
+_scratch_get_iext_count()
+{
+	local ino=$1
+	local whichfork=$2
+	local nextents=0
+	local field=""
+
+	case $whichfork in
+		"attr")
+			field=core.naextents
+			;;
+		"data")
+			field=core.nextents
+			;;
+		*)
+			return 1
+	esac
+
+	nextents=$(_scratch_xfs_get_metadata_field $field "inode $ino")
+
+	echo $nextents
+}
+
 #
 # Ensures that we don't pass any mount options incompatible with XFS v4
 #