diff mbox series

[1/2] common/xfs,xfs/207: Adding a common helper function to check xflag bits on a given file

Message ID 6ba7f682af7e0bc99a8baeccc0d7aa4e5062a433.1729624806.git.nirjhar@linux.ibm.com (mailing list archive)
State Deferred, archived
Headers show
Series generic: Addition of new tests for extsize hints | expand

Commit Message

Nirjhar Roy Oct. 22, 2024, 7:26 p.m. UTC
This patch defines a common helper function to test whether any of
fsxattr xflags field is set or not. We will use this helper in the next
patch for checking extsize (e) flag.

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
---
 common/xfs    |  9 +++++++++
 tests/xfs/207 | 14 +++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)

Comments

Darrick J. Wong Oct. 24, 2024, 6:08 p.m. UTC | #1
On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
> This patch defines a common helper function to test whether any of
> fsxattr xflags field is set or not. We will use this helper in the next
> patch for checking extsize (e) flag.
> 
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
> ---
>  common/xfs    |  9 +++++++++
>  tests/xfs/207 | 14 +++-----------
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/common/xfs b/common/xfs
> index 62e3100e..7340ccbf 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
>  	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
>  }
>  
> +# Check whether a fsxattr xflags character field is set on a given file.
> +# e.g. fsxattr.xflags = 0x0 [--------------C-]
> +# Returns 0 if passed flag character is set, otherwise returns 1
> +_test_xfs_xflags_field()

Seeing as fsxattr got added to ext4 and others, this probably should be
called _test_fsxattr_xflags() and live in common/rc.

> +{
> +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
> +        && return 0 || return 1

No need for this bit, the grep -q will set the return value to 0 or 1
and bash will leave that set for the caller.

--D

> +}
> +
>  _setup_large_xfs_fs()
>  {
>  	fs_size=$1
> diff --git a/tests/xfs/207 b/tests/xfs/207
> index bbe21307..adb925df 100755
> --- a/tests/xfs/207
> +++ b/tests/xfs/207
> @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
>  # Import common functions.
>  . ./common/filter
>  . ./common/reflink
> +. ./common/xfs
>  
>  _require_scratch_reflink
>  _require_cp_reflink
>  _require_xfs_io_command "fiemap"
>  _require_xfs_io_command "cowextsize"
>  
> -# Takes the fsxattr.xflags line,
> -# i.e. fsxattr.xflags = 0x0 [--------------C-]
> -# and tests whether a flag character is set
> -test_xflag()
> -{
> -    local flg=$1
> -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
> -}
> -
>  echo "Format and mount"
>  _scratch_mkfs > $seqres.full 2>&1
>  _scratch_mount >> $seqres.full 2>&1
> @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
>  $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
>  _scratch_cycle_mount
>  
> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>  
>  echo "Unset cowextsize and check flag"
>  $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
>  _scratch_cycle_mount
>  
> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>  
>  status=0
> -- 
> 2.43.5
> 
>
Zorro Lang Oct. 25, 2024, 2:56 a.m. UTC | #2
On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
> This patch defines a common helper function to test whether any of
> fsxattr xflags field is set or not. We will use this helper in the next
> patch for checking extsize (e) flag.
> 
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
> ---
>  common/xfs    |  9 +++++++++
>  tests/xfs/207 | 14 +++-----------
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/common/xfs b/common/xfs
> index 62e3100e..7340ccbf 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
>  	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
>  }
>  
> +# Check whether a fsxattr xflags character field is set on a given file.

Better to explain the arguments, e.g.

# Check whether a fsxattr xflags character ($2) field is set on a given file ($1).

> +# e.g. fsxattr.xflags = 0x0 [--------------C-]
> +# Returns 0 if passed flag character is set, otherwise returns 1
> +_test_xfs_xflags_field()
> +{
> +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
> +        && return 0 || return 1

That's too complex. Those "return" aren't needed as Darrick metioned. About
that two "grep", how about combine them, e.g.

_test_xfs_xflags_field()
{
	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
}



> +}
> +
>  _setup_large_xfs_fs()
>  {
>  	fs_size=$1
> diff --git a/tests/xfs/207 b/tests/xfs/207
> index bbe21307..adb925df 100755
> --- a/tests/xfs/207
> +++ b/tests/xfs/207
> @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
>  # Import common functions.
>  . ./common/filter
>  . ./common/reflink
> +. ./common/xfs

Is this really necessary? Will this test fail without this line?
The common/$FSTYP file is imported automatically, if it's not, that a bug.

Thanks,
Zorro

>  
>  _require_scratch_reflink
>  _require_cp_reflink
>  _require_xfs_io_command "fiemap"
>  _require_xfs_io_command "cowextsize"
>  
> -# Takes the fsxattr.xflags line,
> -# i.e. fsxattr.xflags = 0x0 [--------------C-]
> -# and tests whether a flag character is set
> -test_xflag()
> -{
> -    local flg=$1
> -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
> -}
> -
>  echo "Format and mount"
>  _scratch_mkfs > $seqres.full 2>&1
>  _scratch_mount >> $seqres.full 2>&1
> @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
>  $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
>  _scratch_cycle_mount
>  
> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>  
>  echo "Unset cowextsize and check flag"
>  $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
>  _scratch_cycle_mount
>  
> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>  
>  status=0
> -- 
> 2.43.5
> 
>
Darrick J. Wong Oct. 25, 2024, 4:07 a.m. UTC | #3
On Fri, Oct 25, 2024 at 10:56:51AM +0800, Zorro Lang wrote:
> On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
> > This patch defines a common helper function to test whether any of
> > fsxattr xflags field is set or not. We will use this helper in the next
> > patch for checking extsize (e) flag.
> > 
> > Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> > Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> > Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
> > ---
> >  common/xfs    |  9 +++++++++
> >  tests/xfs/207 | 14 +++-----------
> >  2 files changed, 12 insertions(+), 11 deletions(-)
> > 
> > diff --git a/common/xfs b/common/xfs
> > index 62e3100e..7340ccbf 100644
> > --- a/common/xfs
> > +++ b/common/xfs
> > @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
> >  	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
> >  }
> >  
> > +# Check whether a fsxattr xflags character field is set on a given file.
> 
> Better to explain the arguments, e.g.
> 
> # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
> 
> > +# e.g. fsxattr.xflags = 0x0 [--------------C-]
> > +# Returns 0 if passed flag character is set, otherwise returns 1
> > +_test_xfs_xflags_field()
> > +{
> > +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
> > +        && return 0 || return 1
> 
> That's too complex. Those "return" aren't needed as Darrick metioned. About
> that two "grep", how about combine them, e.g.
> 
> _test_xfs_xflags_field()
> {
> 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
> }
> 
> 
> 
> > +}
> > +
> >  _setup_large_xfs_fs()
> >  {
> >  	fs_size=$1
> > diff --git a/tests/xfs/207 b/tests/xfs/207
> > index bbe21307..adb925df 100755
> > --- a/tests/xfs/207
> > +++ b/tests/xfs/207
> > @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
> >  # Import common functions.
> >  . ./common/filter
> >  . ./common/reflink
> > +. ./common/xfs
> 
> Is this really necessary? Will this test fail without this line?
> The common/$FSTYP file is imported automatically, if it's not, that a bug.

If the generic helper goes in common/rc instead then it's not necessary
at all.

--D

> Thanks,
> Zorro
> 
> >  
> >  _require_scratch_reflink
> >  _require_cp_reflink
> >  _require_xfs_io_command "fiemap"
> >  _require_xfs_io_command "cowextsize"
> >  
> > -# Takes the fsxattr.xflags line,
> > -# i.e. fsxattr.xflags = 0x0 [--------------C-]
> > -# and tests whether a flag character is set
> > -test_xflag()
> > -{
> > -    local flg=$1
> > -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
> > -}
> > -
> >  echo "Format and mount"
> >  _scratch_mkfs > $seqres.full 2>&1
> >  _scratch_mount >> $seqres.full 2>&1
> > @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
> >  $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
> >  _scratch_cycle_mount
> >  
> > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> >  
> >  echo "Unset cowextsize and check flag"
> >  $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
> >  _scratch_cycle_mount
> >  
> > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> >  
> >  status=0
> > -- 
> > 2.43.5
> > 
> > 
>
Zorro Lang Oct. 25, 2024, 4:15 a.m. UTC | #4
On Thu, Oct 24, 2024 at 09:07:03PM -0700, Darrick J. Wong wrote:
> On Fri, Oct 25, 2024 at 10:56:51AM +0800, Zorro Lang wrote:
> > On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
> > > This patch defines a common helper function to test whether any of
> > > fsxattr xflags field is set or not. We will use this helper in the next
> > > patch for checking extsize (e) flag.
> > > 
> > > Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> > > Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> > > Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
> > > ---
> > >  common/xfs    |  9 +++++++++
> > >  tests/xfs/207 | 14 +++-----------
> > >  2 files changed, 12 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/common/xfs b/common/xfs
> > > index 62e3100e..7340ccbf 100644
> > > --- a/common/xfs
> > > +++ b/common/xfs
> > > @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
> > >  	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
> > >  }
> > >  
> > > +# Check whether a fsxattr xflags character field is set on a given file.
> > 
> > Better to explain the arguments, e.g.
> > 
> > # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
> > 
> > > +# e.g. fsxattr.xflags = 0x0 [--------------C-]
> > > +# Returns 0 if passed flag character is set, otherwise returns 1
> > > +_test_xfs_xflags_field()
> > > +{
> > > +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
> > > +        && return 0 || return 1
> > 
> > That's too complex. Those "return" aren't needed as Darrick metioned. About
> > that two "grep", how about combine them, e.g.
> > 
> > _test_xfs_xflags_field()
> > {
> > 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
> > }
> > 
> > 
> > 
> > > +}
> > > +
> > >  _setup_large_xfs_fs()
> > >  {
> > >  	fs_size=$1
> > > diff --git a/tests/xfs/207 b/tests/xfs/207
> > > index bbe21307..adb925df 100755
> > > --- a/tests/xfs/207
> > > +++ b/tests/xfs/207
> > > @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
> > >  # Import common functions.
> > >  . ./common/filter
> > >  . ./common/reflink
> > > +. ./common/xfs
> > 
> > Is this really necessary? Will this test fail without this line?
> > The common/$FSTYP file is imported automatically, if it's not, that a bug.
> 
> If the generic helper goes in common/rc instead then it's not necessary
> at all.

Won't the "_source_specific_fs $FSTYP" in common/rc helps to import common/xfs?

> 
> --D
> 
> > Thanks,
> > Zorro
> > 
> > >  
> > >  _require_scratch_reflink
> > >  _require_cp_reflink
> > >  _require_xfs_io_command "fiemap"
> > >  _require_xfs_io_command "cowextsize"
> > >  
> > > -# Takes the fsxattr.xflags line,
> > > -# i.e. fsxattr.xflags = 0x0 [--------------C-]
> > > -# and tests whether a flag character is set
> > > -test_xflag()
> > > -{
> > > -    local flg=$1
> > > -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
> > > -}
> > > -
> > >  echo "Format and mount"
> > >  _scratch_mkfs > $seqres.full 2>&1
> > >  _scratch_mount >> $seqres.full 2>&1
> > > @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
> > >  $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
> > >  _scratch_cycle_mount
> > >  
> > > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> > >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> > >  
> > >  echo "Unset cowextsize and check flag"
> > >  $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
> > >  _scratch_cycle_mount
> > >  
> > > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> > >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> > >  
> > >  status=0
> > > -- 
> > > 2.43.5
> > > 
> > > 
> > 
>
Darrick J. Wong Oct. 25, 2024, 5:27 a.m. UTC | #5
On Fri, Oct 25, 2024 at 12:15:01PM +0800, Zorro Lang wrote:
> On Thu, Oct 24, 2024 at 09:07:03PM -0700, Darrick J. Wong wrote:
> > On Fri, Oct 25, 2024 at 10:56:51AM +0800, Zorro Lang wrote:
> > > On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
> > > > This patch defines a common helper function to test whether any of
> > > > fsxattr xflags field is set or not. We will use this helper in the next
> > > > patch for checking extsize (e) flag.
> > > > 
> > > > Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> > > > Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> > > > Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
> > > > ---
> > > >  common/xfs    |  9 +++++++++
> > > >  tests/xfs/207 | 14 +++-----------
> > > >  2 files changed, 12 insertions(+), 11 deletions(-)
> > > > 
> > > > diff --git a/common/xfs b/common/xfs
> > > > index 62e3100e..7340ccbf 100644
> > > > --- a/common/xfs
> > > > +++ b/common/xfs
> > > > @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
> > > >  	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
> > > >  }
> > > >  
> > > > +# Check whether a fsxattr xflags character field is set on a given file.
> > > 
> > > Better to explain the arguments, e.g.
> > > 
> > > # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
> > > 
> > > > +# e.g. fsxattr.xflags = 0x0 [--------------C-]
> > > > +# Returns 0 if passed flag character is set, otherwise returns 1
> > > > +_test_xfs_xflags_field()
> > > > +{
> > > > +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
> > > > +        && return 0 || return 1
> > > 
> > > That's too complex. Those "return" aren't needed as Darrick metioned. About
> > > that two "grep", how about combine them, e.g.
> > > 
> > > _test_xfs_xflags_field()
> > > {
> > > 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
> > > }
> > > 
> > > 
> > > 
> > > > +}
> > > > +
> > > >  _setup_large_xfs_fs()
> > > >  {
> > > >  	fs_size=$1
> > > > diff --git a/tests/xfs/207 b/tests/xfs/207
> > > > index bbe21307..adb925df 100755
> > > > --- a/tests/xfs/207
> > > > +++ b/tests/xfs/207
> > > > @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
> > > >  # Import common functions.
> > > >  . ./common/filter
> > > >  . ./common/reflink
> > > > +. ./common/xfs
> > > 
> > > Is this really necessary? Will this test fail without this line?
> > > The common/$FSTYP file is imported automatically, if it's not, that a bug.
> > 
> > If the generic helper goes in common/rc instead then it's not necessary
> > at all.
> 
> Won't the "_source_specific_fs $FSTYP" in common/rc helps to import common/xfs?

Yeah, that too.

--D

> > 
> > --D
> > 
> > > Thanks,
> > > Zorro
> > > 
> > > >  
> > > >  _require_scratch_reflink
> > > >  _require_cp_reflink
> > > >  _require_xfs_io_command "fiemap"
> > > >  _require_xfs_io_command "cowextsize"
> > > >  
> > > > -# Takes the fsxattr.xflags line,
> > > > -# i.e. fsxattr.xflags = 0x0 [--------------C-]
> > > > -# and tests whether a flag character is set
> > > > -test_xflag()
> > > > -{
> > > > -    local flg=$1
> > > > -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
> > > > -}
> > > > -
> > > >  echo "Format and mount"
> > > >  _scratch_mkfs > $seqres.full 2>&1
> > > >  _scratch_mount >> $seqres.full 2>&1
> > > > @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
> > > >  $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
> > > >  _scratch_cycle_mount
> > > >  
> > > > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > > > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> > > >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> > > >  
> > > >  echo "Unset cowextsize and check flag"
> > > >  $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
> > > >  _scratch_cycle_mount
> > > >  
> > > > -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
> > > > +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
> > > >  $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
> > > >  
> > > >  status=0
> > > > -- 
> > > > 2.43.5
> > > > 
> > > > 
> > > 
> > 
> 
>
Nirjhar Roy Oct. 25, 2024, 6:14 a.m. UTC | #6
On 10/25/24 08:26, Zorro Lang wrote:
> On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
>> This patch defines a common helper function to test whether any of
>> fsxattr xflags field is set or not. We will use this helper in the next
>> patch for checking extsize (e) flag.
>>
>> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
>> Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
>> ---
>>   common/xfs    |  9 +++++++++
>>   tests/xfs/207 | 14 +++-----------
>>   2 files changed, 12 insertions(+), 11 deletions(-)
>>
>> diff --git a/common/xfs b/common/xfs
>> index 62e3100e..7340ccbf 100644
>> --- a/common/xfs
>> +++ b/common/xfs
>> @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
>>   	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
>>   }
>>   
>> +# Check whether a fsxattr xflags character field is set on a given file.
> Better to explain the arguments, e.g.
>
> # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
Noted.
>
>> +# e.g. fsxattr.xflags = 0x0 [--------------C-]
>> +# Returns 0 if passed flag character is set, otherwise returns 1
>> +_test_xfs_xflags_field()
>> +{
>> +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
>> +        && return 0 || return 1
> That's too complex. Those "return" aren't needed as Darrick metioned. About
> that two "grep", how about combine them, e.g.
>
> _test_xfs_xflags_field()
> {
> 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
> }
>
Yes. This looks better. Thank you for the suggestion.
>
>> +}
>> +
>>   _setup_large_xfs_fs()
>>   {
>>   	fs_size=$1
>> diff --git a/tests/xfs/207 b/tests/xfs/207
>> index bbe21307..adb925df 100755
>> --- a/tests/xfs/207
>> +++ b/tests/xfs/207
>> @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
>>   # Import common functions.
>>   . ./common/filter
>>   . ./common/reflink
>> +. ./common/xfs
> Is this really necessary? Will this test fail without this line?
> The common/$FSTYP file is imported automatically, if it's not, that a bug.
>
> Thanks,
> Zorro
No, actually, it isn't. I have verified. Also, I am moving the helper 
function to common/rc, so this will not be required anyway.
>
>>   
>>   _require_scratch_reflink
>>   _require_cp_reflink
>>   _require_xfs_io_command "fiemap"
>>   _require_xfs_io_command "cowextsize"
>>   
>> -# Takes the fsxattr.xflags line,
>> -# i.e. fsxattr.xflags = 0x0 [--------------C-]
>> -# and tests whether a flag character is set
>> -test_xflag()
>> -{
>> -    local flg=$1
>> -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
>> -}
>> -
>>   echo "Format and mount"
>>   _scratch_mkfs > $seqres.full 2>&1
>>   _scratch_mount >> $seqres.full 2>&1
>> @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
>>   $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
>>   _scratch_cycle_mount
>>   
>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>   
>>   echo "Unset cowextsize and check flag"
>>   $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
>>   _scratch_cycle_mount
>>   
>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>   
>>   status=0
>> -- 
>> 2.43.5
>>
>>
Nirjhar Roy Oct. 25, 2024, 6:16 a.m. UTC | #7
On 10/25/24 09:37, Darrick J. Wong wrote:
> On Fri, Oct 25, 2024 at 10:56:51AM +0800, Zorro Lang wrote:
>> On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
>>> This patch defines a common helper function to test whether any of
>>> fsxattr xflags field is set or not. We will use this helper in the next
>>> patch for checking extsize (e) flag.
>>>
>>> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>>> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
>>> Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
>>> ---
>>>   common/xfs    |  9 +++++++++
>>>   tests/xfs/207 | 14 +++-----------
>>>   2 files changed, 12 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/common/xfs b/common/xfs
>>> index 62e3100e..7340ccbf 100644
>>> --- a/common/xfs
>>> +++ b/common/xfs
>>> @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
>>>   	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
>>>   }
>>>   
>>> +# Check whether a fsxattr xflags character field is set on a given file.
>> Better to explain the arguments, e.g.
>>
>> # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
>>
>>> +# e.g. fsxattr.xflags = 0x0 [--------------C-]
>>> +# Returns 0 if passed flag character is set, otherwise returns 1
>>> +_test_xfs_xflags_field()
>>> +{
>>> +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
>>> +        && return 0 || return 1
>> That's too complex. Those "return" aren't needed as Darrick metioned. About
>> that two "grep", how about combine them, e.g.
>>
>> _test_xfs_xflags_field()
>> {
>> 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
>> }
>>
>>
>>
>>> +}
>>> +
>>>   _setup_large_xfs_fs()
>>>   {
>>>   	fs_size=$1
>>> diff --git a/tests/xfs/207 b/tests/xfs/207
>>> index bbe21307..adb925df 100755
>>> --- a/tests/xfs/207
>>> +++ b/tests/xfs/207
>>> @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
>>>   # Import common functions.
>>>   . ./common/filter
>>>   . ./common/reflink
>>> +. ./common/xfs
>> Is this really necessary? Will this test fail without this line?
>> The common/$FSTYP file is imported automatically, if it's not, that a bug.
> If the generic helper goes in common/rc instead then it's not necessary
> at all.
>
> --D
Yeah, this makes sense.
>
>> Thanks,
>> Zorro
>>
>>>   
>>>   _require_scratch_reflink
>>>   _require_cp_reflink
>>>   _require_xfs_io_command "fiemap"
>>>   _require_xfs_io_command "cowextsize"
>>>   
>>> -# Takes the fsxattr.xflags line,
>>> -# i.e. fsxattr.xflags = 0x0 [--------------C-]
>>> -# and tests whether a flag character is set
>>> -test_xflag()
>>> -{
>>> -    local flg=$1
>>> -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
>>> -}
>>> -
>>>   echo "Format and mount"
>>>   _scratch_mkfs > $seqres.full 2>&1
>>>   _scratch_mount >> $seqres.full 2>&1
>>> @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
>>>   $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
>>>   _scratch_cycle_mount
>>>   
>>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>>   
>>>   echo "Unset cowextsize and check flag"
>>>   $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
>>>   _scratch_cycle_mount
>>>   
>>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>>   
>>>   status=0
>>> -- 
>>> 2.43.5
>>>
>>>
Nirjhar Roy Oct. 25, 2024, 6:17 a.m. UTC | #8
On 10/25/24 09:45, Zorro Lang wrote:
> On Thu, Oct 24, 2024 at 09:07:03PM -0700, Darrick J. Wong wrote:
>> On Fri, Oct 25, 2024 at 10:56:51AM +0800, Zorro Lang wrote:
>>> On Wed, Oct 23, 2024 at 12:56:19AM +0530, Nirjhar Roy wrote:
>>>> This patch defines a common helper function to test whether any of
>>>> fsxattr xflags field is set or not. We will use this helper in the next
>>>> patch for checking extsize (e) flag.
>>>>
>>>> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>>>> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
>>>> Signed-off-by: Nirjhar Roy <nirjhar@linux.ibm.com>
>>>> ---
>>>>   common/xfs    |  9 +++++++++
>>>>   tests/xfs/207 | 14 +++-----------
>>>>   2 files changed, 12 insertions(+), 11 deletions(-)
>>>>
>>>> diff --git a/common/xfs b/common/xfs
>>>> index 62e3100e..7340ccbf 100644
>>>> --- a/common/xfs
>>>> +++ b/common/xfs
>>>> @@ -13,6 +13,15 @@ __generate_xfs_report_vars() {
>>>>   	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
>>>>   }
>>>>   
>>>> +# Check whether a fsxattr xflags character field is set on a given file.
>>> Better to explain the arguments, e.g.
>>>
>>> # Check whether a fsxattr xflags character ($2) field is set on a given file ($1).
>>>
>>>> +# e.g. fsxattr.xflags = 0x0 [--------------C-]
>>>> +# Returns 0 if passed flag character is set, otherwise returns 1
>>>> +_test_xfs_xflags_field()
>>>> +{
>>>> +    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
>>>> +        && return 0 || return 1
>>> That's too complex. Those "return" aren't needed as Darrick metioned. About
>>> that two "grep", how about combine them, e.g.
>>>
>>> _test_xfs_xflags_field()
>>> {
>>> 	grep -q "fsxattr.xflags.*\[.*$2.*\]" <($XFS_IO_PROG -c "stat" "$1")
>>> }
>>>
>>>
>>>
>>>> +}
>>>> +
>>>>   _setup_large_xfs_fs()
>>>>   {
>>>>   	fs_size=$1
>>>> diff --git a/tests/xfs/207 b/tests/xfs/207
>>>> index bbe21307..adb925df 100755
>>>> --- a/tests/xfs/207
>>>> +++ b/tests/xfs/207
>>>> @@ -15,21 +15,13 @@ _begin_fstest auto quick clone fiemap
>>>>   # Import common functions.
>>>>   . ./common/filter
>>>>   . ./common/reflink
>>>> +. ./common/xfs
>>> Is this really necessary? Will this test fail without this line?
>>> The common/$FSTYP file is imported automatically, if it's not, that a bug.
>> If the generic helper goes in common/rc instead then it's not necessary
>> at all.
> Won't the "_source_specific_fs $FSTYP" in common/rc helps to import common/xfs?
Yeah, it gets imported automatically(I have verified). Anyway, I am 
moving the helper function to common/rc, so this won't be required.
>
>> --D
>>
>>> Thanks,
>>> Zorro
>>>
>>>>   
>>>>   _require_scratch_reflink
>>>>   _require_cp_reflink
>>>>   _require_xfs_io_command "fiemap"
>>>>   _require_xfs_io_command "cowextsize"
>>>>   
>>>> -# Takes the fsxattr.xflags line,
>>>> -# i.e. fsxattr.xflags = 0x0 [--------------C-]
>>>> -# and tests whether a flag character is set
>>>> -test_xflag()
>>>> -{
>>>> -    local flg=$1
>>>> -    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
>>>> -}
>>>> -
>>>>   echo "Format and mount"
>>>>   _scratch_mkfs > $seqres.full 2>&1
>>>>   _scratch_mount >> $seqres.full 2>&1
>>>> @@ -65,14 +57,14 @@ echo "Set cowextsize and check flag"
>>>>   $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
>>>>   _scratch_cycle_mount
>>>>   
>>>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>>>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>>>   
>>>>   echo "Unset cowextsize and check flag"
>>>>   $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
>>>>   _scratch_cycle_mount
>>>>   
>>>> -$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
>>>> +_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
>>>>   $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
>>>>   
>>>>   status=0
>>>> -- 
>>>> 2.43.5
>>>>
>>>>
diff mbox series

Patch

diff --git a/common/xfs b/common/xfs
index 62e3100e..7340ccbf 100644
--- a/common/xfs
+++ b/common/xfs
@@ -13,6 +13,15 @@  __generate_xfs_report_vars() {
 	REPORT_ENV_LIST_OPT+=("TEST_XFS_REPAIR_REBUILD" "TEST_XFS_SCRUB_REBUILD")
 }
 
+# Check whether a fsxattr xflags character field is set on a given file.
+# e.g. fsxattr.xflags = 0x0 [--------------C-]
+# Returns 0 if passed flag character is set, otherwise returns 1
+_test_xfs_xflags_field()
+{
+    $XFS_IO_PROG -c "stat" "$1" | grep "fsxattr.xflags" | grep -q "\[.*$2.*\]" \
+        && return 0 || return 1
+}
+
 _setup_large_xfs_fs()
 {
 	fs_size=$1
diff --git a/tests/xfs/207 b/tests/xfs/207
index bbe21307..adb925df 100755
--- a/tests/xfs/207
+++ b/tests/xfs/207
@@ -15,21 +15,13 @@  _begin_fstest auto quick clone fiemap
 # Import common functions.
 . ./common/filter
 . ./common/reflink
+. ./common/xfs
 
 _require_scratch_reflink
 _require_cp_reflink
 _require_xfs_io_command "fiemap"
 _require_xfs_io_command "cowextsize"
 
-# Takes the fsxattr.xflags line,
-# i.e. fsxattr.xflags = 0x0 [--------------C-]
-# and tests whether a flag character is set
-test_xflag()
-{
-    local flg=$1
-    grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
-}
-
 echo "Format and mount"
 _scratch_mkfs > $seqres.full 2>&1
 _scratch_mount >> $seqres.full 2>&1
@@ -65,14 +57,14 @@  echo "Set cowextsize and check flag"
 $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
 _scratch_cycle_mount
 
-$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
+_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
 
 echo "Unset cowextsize and check flag"
 $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
 _scratch_cycle_mount
 
-$XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
+_test_xfs_xflags_field "$testdir/file3" "C" && echo "C flag set" || echo "C flag unset"
 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
 
 status=0