FS/XFS testing framework
 help / color / mirror / Atom feed
* [PATCH] Fix warning of "Usage: _is_block_dev dev"
@ 2015-02-12 12:48 Zhaolei
  2015-02-15 23:04 ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Zhaolei @ 2015-02-12 12:48 UTC (permalink / raw)
  To: fstests; +Cc: Zhao Lei

From: Zhao Lei <zhaolei@cn.fujitsu.com>

_is_block_dev() will show above warning when "$dev" is not exist.
It happened when user hadn't set $SCRATCH_DEV(optional) and check
$TEST_DEV.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 common/rc | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/common/rc b/common/rc
index 5377ba0..d9815c7 100644
--- a/common/rc
+++ b/common/rc
@@ -1167,19 +1167,22 @@ _require_test()
 		fi
 		;;
 	*)
-		 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
-		 then
-		     _notrun "this test requires a valid \$TEST_DEV"
-		 fi
-		 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
-		 then
-		     _notrun "this test requires a valid \$TEST_DEV"
-		 fi
+		if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
+		then
+		    _notrun "this test requires a valid \$TEST_DEV"
+		fi
+		if [ -n "$SCRATCH_DEV" ]
+		then
+		    if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
+		    then
+			_notrun "this test requires a valid \$TEST_DEV"
+		    fi
+		fi
 		if [ ! -d "$TEST_DIR" ]
 		then
-		     _notrun "this test requires a valid \$TEST_DIR"
+		    _notrun "this test requires a valid \$TEST_DIR"
 		fi
-		 ;;
+		;;
     esac
 
     # mounted?
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix warning of "Usage: _is_block_dev dev"
  2015-02-12 12:48 [PATCH] Fix warning of "Usage: _is_block_dev dev" Zhaolei
@ 2015-02-15 23:04 ` Dave Chinner
  2015-02-16  2:27   ` Zhao Lei
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Chinner @ 2015-02-15 23:04 UTC (permalink / raw)
  To: Zhaolei; +Cc: fstests

On Thu, Feb 12, 2015 at 08:48:14PM +0800, Zhaolei wrote:
> From: Zhao Lei <zhaolei@cn.fujitsu.com>
> 
> _is_block_dev() will show above warning when "$dev" is not exist.
> It happened when user hadn't set $SCRATCH_DEV(optional) and check
> $TEST_DEV.

_is_block_dev() is used in many places to check whether the block
device exists.  i.e. I'd suggest that _is_block_dev() should return
an empty string to indicate it's not a block device rather than exit
if a null. That means we don't have to execute _is_block_dev() in a
subshell (i.e. via `_is_block_dev ...`) to prevent it from killing
the script that runs it if the block device passed to it is null.

That means we don't have to add checks everywhere it is called, and
we can simplify the calling convention at the same time....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] Fix warning of "Usage: _is_block_dev dev"
  2015-02-15 23:04 ` Dave Chinner
@ 2015-02-16  2:27   ` Zhao Lei
  2015-02-16  5:23     ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Zhao Lei @ 2015-02-16  2:27 UTC (permalink / raw)
  To: 'Dave Chinner'; +Cc: fstests

Hi,

> -----Original Message-----
> From: Dave Chinner [mailto:david@fromorbit.com]
> Sent: Monday, February 16, 2015 7:05 AM
> To: Zhaolei
> Cc: fstests@vger.kernel.org
> Subject: Re: [PATCH] Fix warning of "Usage: _is_block_dev dev"
> 
> On Thu, Feb 12, 2015 at 08:48:14PM +0800, Zhaolei wrote:
> > From: Zhao Lei <zhaolei@cn.fujitsu.com>
> >
> > _is_block_dev() will show above warning when "$dev" is not exist.
> > It happened when user hadn't set $SCRATCH_DEV(optional) and check
> > $TEST_DEV.
> 
> _is_block_dev() is used in many places to check whether the block device exists.
> i.e. I'd suggest that _is_block_dev() should return an empty string to indicate
> it's not a block device rather than exit if a null. That means we don't have to
> execute _is_block_dev() in a subshell (i.e. via `_is_block_dev ...`) to prevent it
> from killing the script that runs it if the block device passed to it is null.
> 
> That means we don't have to add checks everywhere it is called, and we can
> simplify the calling convention at the same time....
> 
Thanks for your suggestion.

Are you mean this?

diff --git a/common/rc b/common/rc
index 7449a1d..12861b8 100644
--- a/common/rc
+++ b/common/rc
@@ -951,8 +951,7 @@ _is_block_dev()
 {
     if [ $# -ne 1 ]
     then
-       echo "Usage: _is_block_dev dev" 1>&2
-       exit 1
+       return
     fi

     _dev=$1
@@ -1095,7 +1094,7 @@ _require_scratch_nocheck()
                fi
                ;;
        *)
-                if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
+                if [ "`_is_block_dev $SCRATCH_DEV`" = "" ]
                 then
                     _notrun "this test requires a valid \$SCRATCH_DEV"
                 fi
@@ -1167,7 +1166,7 @@ _require_test()
                fi
                ;;
        *)
-                if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
+                if [ "`_is_block_dev $TEST_DEV`" = "" ]
                 then
                     _notrun "this test requires a valid \$TEST_DEV"
                 Fi

It is clean than before, but we still need call _is_block_dev() in a subshell to get its return string.

If we want to avoid calling _is_block_dev in a subshell, we can do following change:

_is_block_dev()
{
    return 1 if "$1" is not block dev
}
_same_dev()
{
    return 1 if "$1" and "$2" are not same dev
}

And caller code will be:

if [ ! _is_block_dev "$SCRATCH_DEV" -o _same_dev "$SCRATCH_DEV" "$TEST_DEV" ]
then
    _notrun "this test requires a valid \$SCRATCH_DEV"
fi

Thanks
Zhaolei

> Cheers,
> 
> Dave.
> --
> Dave Chinner
> david@fromorbit.com



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix warning of "Usage: _is_block_dev dev"
  2015-02-16  2:27   ` Zhao Lei
@ 2015-02-16  5:23     ` Dave Chinner
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Chinner @ 2015-02-16  5:23 UTC (permalink / raw)
  To: Zhao Lei; +Cc: fstests

On Mon, Feb 16, 2015 at 10:27:33AM +0800, Zhao Lei wrote:
> Hi,
> 
> > -----Original Message-----
> > From: Dave Chinner [mailto:david@fromorbit.com]
> > Sent: Monday, February 16, 2015 7:05 AM
> > To: Zhaolei
> > Cc: fstests@vger.kernel.org
> > Subject: Re: [PATCH] Fix warning of "Usage: _is_block_dev dev"
> > 
> > On Thu, Feb 12, 2015 at 08:48:14PM +0800, Zhaolei wrote:
> > > From: Zhao Lei <zhaolei@cn.fujitsu.com>
> > >
> > > _is_block_dev() will show above warning when "$dev" is not exist.
> > > It happened when user hadn't set $SCRATCH_DEV(optional) and check
> > > $TEST_DEV.
> > 
> > _is_block_dev() is used in many places to check whether the block device exists.
> > i.e. I'd suggest that _is_block_dev() should return an empty string to indicate
> > it's not a block device rather than exit if a null. That means we don't have to
> > execute _is_block_dev() in a subshell (i.e. via `_is_block_dev ...`) to prevent it
> > from killing the script that runs it if the block device passed to it is null.
> > 
> > That means we don't have to add checks everywhere it is called, and we can
> > simplify the calling convention at the same time....
> > 
> Thanks for your suggestion.
> 
> Are you mean this?
> 
> diff --git a/common/rc b/common/rc
> index 7449a1d..12861b8 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -951,8 +951,7 @@ _is_block_dev()
>  {
>      if [ $# -ne 1 ]
>      then
> -       echo "Usage: _is_block_dev dev" 1>&2
> -       exit 1
> +       return
>      fi
> 
>      _dev=$1
> @@ -1095,7 +1094,7 @@ _require_scratch_nocheck()
>                 fi
>                 ;;
>         *)
> -                if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
> +                if [ "`_is_block_dev $SCRATCH_DEV`" = "" ]
>                  then
>                      _notrun "this test requires a valid \$SCRATCH_DEV"
>                  fi
> @@ -1167,7 +1166,7 @@ _require_test()
>                 fi
>                 ;;
>         *)
> -                if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
> +                if [ "`_is_block_dev $TEST_DEV`" = "" ]
>                  then
>                      _notrun "this test requires a valid \$TEST_DEV"
>                  Fi

Yes, and there are a couple of other places where the same thing can
be done.

FWIW, should convert to "if [...]; then" format at the same time.

> If we want to avoid calling _is_block_dev in a subshell, we can do following change:
> 
> _is_block_dev()
> {
>     return 1 if "$1" is not block dev
> }
> _same_dev()
> {
>     return 1 if "$1" and "$2" are not same dev
> }

yes, that's a good idea, too.

> And caller code will be:
> 
> if [ ! _is_block_dev "$SCRATCH_DEV" -o _same_dev "$SCRATCH_DEV" "$TEST_DEV" ]
> then
>     _notrun "this test requires a valid \$SCRATCH_DEV"
> fi

Well, I'd say that if $TEST_DEV exists and $SCRATCH_DEV doesn't,
then clearly they are not the same device. Hence the test
for _same_dev() should handle those cases correctly internally.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-16  5:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12 12:48 [PATCH] Fix warning of "Usage: _is_block_dev dev" Zhaolei
2015-02-15 23:04 ` Dave Chinner
2015-02-16  2:27   ` Zhao Lei
2015-02-16  5:23     ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox