All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] common/xfs: Initialise OPTIND for getopts calls
@ 2018-02-23  3:54 Dave Chinner
  2018-02-23  4:29 ` Eryu Guan
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2018-02-23  3:54 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

According to the bash man page:

	OPTIND is initialized to 1 each time the shell or a shell
	script is invoked.

This doesn't appear to be true - in tests scripts with no other
getopts calls, I'm seeing the getopts loop in _xfs_check to fail
to parse input parameters correctly. Tracing shows the parameters
are being passed to _xfs_check correctly, but on occassion getopts
simply doesn't see the,

Hence when running tests with both external log and real time
devices, tests are failing at random because xfs_check is
mis-parsing the parameters passed to it and not configuring the
external log correctly:

_check_xfs_filesystem: filesystem on /dev/sdg is inconsistent (c)
*** xfs_check output ***
aborting - no external log specified for FS with an external log
*** end xfs_check output

Fix this by ensuring OPTIND is correctly initialised before using
getopts. Do it for all places that call getopts that don't already
set OPTIND=1 before starting their parsing loop.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
---
 common/xfs        | 1 +
 tests/generic/074 | 1 +
 tests/generic/075 | 1 +
 tests/generic/112 | 1 +
 4 files changed, 4 insertions(+)

diff --git a/common/xfs b/common/xfs
index 2cb77778831a..2aff1b3bcb5c 100644
--- a/common/xfs
+++ b/common/xfs
@@ -119,6 +119,7 @@ _xfs_check()
 	DBOPTS=" "
 	USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
 
+	OPTIND=1
 	while getopts "b:fi:l:stvV" c; do
 		case $c in
 			s) OPTS=$OPTS"-s ";;
diff --git a/tests/generic/074 b/tests/generic/074
index 5f205b509eb6..d39f9a3d4309 100755
--- a/tests/generic/074
+++ b/tests/generic/074
@@ -87,6 +87,7 @@ _usage()
 
 _process_args()
 {
+    OPTIND=1
     while getopts "f:l:n:?" c $@
     do
         case $c
diff --git a/tests/generic/075 b/tests/generic/075
index 321c72177618..e9dd4a5c5dcd 100755
--- a/tests/generic/075
+++ b/tests/generic/075
@@ -98,6 +98,7 @@ _usage()
 
 _process_args()
 {
+    OPTIND=1
     while getopts "l:n:N:?" c $@
     do
         case $c
diff --git a/tests/generic/112 b/tests/generic/112
index 0ab1c8c87907..5ab1cb3ad4ca 100755
--- a/tests/generic/112
+++ b/tests/generic/112
@@ -94,6 +94,7 @@ _usage()
 
 _process_args()
 {
+    OPTIND=1
     while getopts "l:n:N:?" c $@
     do
         case $c
-- 
2.16.1


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

* Re: [PATCH] common/xfs: Initialise OPTIND for getopts calls
  2018-02-23  3:54 [PATCH] common/xfs: Initialise OPTIND for getopts calls Dave Chinner
@ 2018-02-23  4:29 ` Eryu Guan
  2018-02-23  4:56   ` Dave Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Eryu Guan @ 2018-02-23  4:29 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Fri, Feb 23, 2018 at 02:54:54PM +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> According to the bash man page:
> 
> 	OPTIND is initialized to 1 each time the shell or a shell
> 	script is invoked.
> 
> This doesn't appear to be true - in tests scripts with no other
> getopts calls, I'm seeing the getopts loop in _xfs_check to fail
> to parse input parameters correctly. Tracing shows the parameters
> are being passed to _xfs_check correctly, but on occassion getopts
> simply doesn't see the,

Hmm, unfinished sentence here?

Otherwise looks fine to me.

Thanks,
Eryu

> 
> Hence when running tests with both external log and real time
> devices, tests are failing at random because xfs_check is
> mis-parsing the parameters passed to it and not configuring the
> external log correctly:
> 
> _check_xfs_filesystem: filesystem on /dev/sdg is inconsistent (c)
> *** xfs_check output ***
> aborting - no external log specified for FS with an external log
> *** end xfs_check output
> 
> Fix this by ensuring OPTIND is correctly initialised before using
> getopts. Do it for all places that call getopts that don't already
> set OPTIND=1 before starting their parsing loop.
> 
> Signed-Off-By: Dave Chinner <dchinner@redhat.com>
> ---
>  common/xfs        | 1 +
>  tests/generic/074 | 1 +
>  tests/generic/075 | 1 +
>  tests/generic/112 | 1 +
>  4 files changed, 4 insertions(+)
> 
> diff --git a/common/xfs b/common/xfs
> index 2cb77778831a..2aff1b3bcb5c 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -119,6 +119,7 @@ _xfs_check()
>  	DBOPTS=" "
>  	USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
>  
> +	OPTIND=1
>  	while getopts "b:fi:l:stvV" c; do
>  		case $c in
>  			s) OPTS=$OPTS"-s ";;
> diff --git a/tests/generic/074 b/tests/generic/074
> index 5f205b509eb6..d39f9a3d4309 100755
> --- a/tests/generic/074
> +++ b/tests/generic/074
> @@ -87,6 +87,7 @@ _usage()
>  
>  _process_args()
>  {
> +    OPTIND=1
>      while getopts "f:l:n:?" c $@
>      do
>          case $c
> diff --git a/tests/generic/075 b/tests/generic/075
> index 321c72177618..e9dd4a5c5dcd 100755
> --- a/tests/generic/075
> +++ b/tests/generic/075
> @@ -98,6 +98,7 @@ _usage()
>  
>  _process_args()
>  {
> +    OPTIND=1
>      while getopts "l:n:N:?" c $@
>      do
>          case $c
> diff --git a/tests/generic/112 b/tests/generic/112
> index 0ab1c8c87907..5ab1cb3ad4ca 100755
> --- a/tests/generic/112
> +++ b/tests/generic/112
> @@ -94,6 +94,7 @@ _usage()
>  
>  _process_args()
>  {
> +    OPTIND=1
>      while getopts "l:n:N:?" c $@
>      do
>          case $c
> -- 
> 2.16.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] common/xfs: Initialise OPTIND for getopts calls
  2018-02-23  4:29 ` Eryu Guan
@ 2018-02-23  4:56   ` Dave Chinner
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2018-02-23  4:56 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests

On Fri, Feb 23, 2018 at 12:29:28PM +0800, Eryu Guan wrote:
> On Fri, Feb 23, 2018 at 02:54:54PM +1100, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> > 
> > According to the bash man page:
> > 
> > 	OPTIND is initialized to 1 each time the shell or a shell
> > 	script is invoked.
> > 
> > This doesn't appear to be true - in tests scripts with no other
> > getopts calls, I'm seeing the getopts loop in _xfs_check to fail
> > to parse input parameters correctly. Tracing shows the parameters
> > are being passed to _xfs_check correctly, but on occassion getopts
> > simply doesn't see the,
> 
> Hmm, unfinished sentence here?

Typo. "simply doesn't see them."

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

end of thread, other threads:[~2018-02-23  4:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-23  3:54 [PATCH] common/xfs: Initialise OPTIND for getopts calls Dave Chinner
2018-02-23  4:29 ` Eryu Guan
2018-02-23  4:56   ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.