Minor cleanups in common/
v3 cover Minor cleanups in common/
This patch series removes some unnecessary sourcing of common/rc and decouples the call to init_rc() from the sourcing of common/rc. This is proposed in [1] and [2]. It also removes direct usage of exit command with a _exit wrapper. The individual patches have the details.
[v2] --> [v3]
1. Added R.Bs from Dave[3] and Ritesh in all the patches of [v2]
2. Replaced status=1;exit with "_exit 1" in some of the functions I missed in [v2]
3. Added some comments in the check script(suggested by Ritesh)
4. Added a new patch (patch 2) that removes redundant sourcing of common/config in generic/367
5. As of now, I didn't change the definition of _exit() function.
[1] https://lore.kernel.org/all/20250206155251.GA21787@frogsfrogsfrogs/
[2] https://lore.kernel.org/all/20250210142322.tptpphdntglsz4eq@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com/
[3] https://lore.kernel.org/all/[email protected]/
[v1] https://lore.kernel.org/all/[email protected]/
[v2] https://lore.kernel.org/all/[email protected]/
Nirjhar Roy (IBM) (6):
generic/749: Remove redundant sourcing of common/rc generic/367: Remove redundant sourcing if common/config
check: Remove redundant _test_mount in check check,common{rc,preamble}: Decouple init_rc() call from sourcing
common/rc
common/config: Introduce _exit wrapper around exit command
common: exit --> _exit
check | 10 ++--- common/btrfs | 6 +-- common/ceph | 2 +- common/config | 15 +++++-- common/dump | 11 +++-- common/ext4 | 2 +- common/populate | 2 +- common/preamble | 3 +- common/punch | 13 +++--- common/rc | 107 ++++++++++++++++++++++------------------------ common/repair | 4 +- common/xfs | 8 ++-- tests/generic/367 | 1 - tests/generic/749 | 1 - 14 files changed, 91 insertions(+), 94 deletions(-)
--
2.34.1
PATCH v3 1/6 generic/749: Remove redundant sourcing of common/rc
common/rc is already sourced before the test starts running in _begin_fstest() preamble.
--- tests/generic/749 | 1 - 1 file changed, 1 deletion(-)
tests/generic/749 +0 -1
@@ -15,7 +15,6 @@ # boundary and ensures we get a SIGBUS if we write to data beyond the system # page size even if the block size is greater than the system page size. . ./common/preamble -. ./common/rc _begin_fstest auto quick prealloc # Import common functions.
Signature · 1 line
2.34.1
PATCH v3 2/6 generic/367: Remove redundant sourcing if common/config
In reply to Nirjhar Roy (IBM)common/config will be source by _begin_fstest
--- tests/generic/367 | 1 - 1 file changed, 1 deletion(-)
tests/generic/367 +0 -1
@@ -11,7 +11,6 @@ # check if the extsize value and the xflag bit actually got reflected after # setting/re-setting the extsize value. -. ./common/config . ./common/filter . ./common/preamble
Signature · 1 line
2.34.1
Re: [PATCH v3 2/6] generic/367: Remove redundant sourcing if common/config
Quoted 2 lines · Nirjhar Roy (IBM)
common/config will be source by
_begin_fstest
Looks good to me. Please feel free to add:
Quoted 19 lines
Signed-off-by Nirjhar Roy (IBM) <[email protected]>--- tests/generic/367 | 1 - 1 file changed, 1 deletion(-)tests/generic/367 +0
-1@@ -11,7 +11,6 @@ # check if the extsize value and the xflag bit actually got reflected after # setting/re-setting the extsize value. -. ./common/config . ./common/filter . ./common/preambleSignature · 1 line
2.34.1
Re: [PATCH v3 2/6] generic/367: Remove redundant sourcing if common/config
In reply to Nirjhar Roy (IBM)Quoted 4 lines · Nirjhar Roy (IBM)
common/config will be source by
_begin_fstestSigned-off-by Nirjhar Roy (IBM) <[email protected]>---
Quoted 19 lines
tests/generic/367 | 1 - 1 file changed, 1 deletion(-)tests/generic/367 +0
-1@@ -11,7 +11,6 @@ # check if the extsize value and the xflag bit actually got reflected after # setting/re-setting the extsize value. -. ./common/config . ./common/filter . ./common/preambleSignature · 1 line
2.34.1
PATCH v3 3/6 check: Remove redundant _test_mount in check
In reply to Nirjhar Roy (IBM)init_rc already does a _test_mount. Hence removing the additional _test_mount call when OLD_TEST_FS_MOUNT_OPTS != TEST_FS_MOUNT_OPTS.
--- check | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
check +2 -6
@@ -791,13 +791,9 @@ function run_section() . common/rc _prepare_test_list elif [ "$OLD_TEST_FS_MOUNT_OPTS" != "$TEST_FS_MOUNT_OPTS" ]; then + # Unmount TEST_DEV to apply the updated mount options. + # It will be mounted again by init_rc(), called shortly after. _test_unmount 2> /dev/null - if ! _test_mount - then - echo "check: failed to mount $TEST_DEV on $TEST_DIR" - status=1 - exit - fi fi init_rc
Signature · 1 line
2.34.1
PATCH v3 4/6 check,common{rc,preamble}: Decouple init_rc() call from sourcing common/rc
In reply to Nirjhar Roy (IBM)Silently executing scripts during sourcing common/rc isn't good practice and also causes unnecessary script execution. Decouple init_rc() call and call init_rc() explicitly where required.
--- check | 2 ++ common/preamble | 1 + common/rc | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-)
check +2 -0
@@ -364,6 +364,8 @@ if ! . ./common/rc; then exit 1 fi +init_rc + # If the test config specified a soak test duration, see if there are any # unit suffixes that need converting to an integer seconds count. if [ -n "$SOAK_DURATION" ]; then
common/preamble +1 -0
@@ -50,6 +50,7 @@ _begin_fstest() _register_cleanup _cleanup . ./common/rc + init_rc # remove previous $seqres.full before test rm -f $seqres.full $seqres.hints
common/rc +0 -2
@@ -5817,8 +5817,6 @@ _require_program() { _have_program "$1" || _notrun "$tag required" } -init_rc - ################################################################################ # make sure this script returns success /bin/true
Signature · 1 line
2.34.1
PATCH v3 5/6 common/config: Introduce _exit wrapper around exit command
In reply to Nirjhar Roy (IBM)We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:
if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15
else
trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch
[xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch
This caused the init_rc() to catch the case of invalid _test_mount options. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is because init_rc exits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.
The next patch will replace exit with _exit.
--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)
common/config +8 -0
@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly. +_exit() +{ + status="$1" + exit "$status" +} + # Handle mkfs.$fstyp which does (or does not) require -f to overwrite set_mkfs_prog_path_with_opts() {
Signature · 1 line
2.34.1
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 100
Quoted 5 lines
common/config +2
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly.
...as it might not set the value of "$status" correctly, which is used as an exit code in the trap handler routine set up by the check script.
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 106
Quoted 6 lines
common/config +6
-0+_exit() +{ + status="$1" + exit "$status" +} +
I agree with Darrick’s suggestion here. It’s safer to update status only when an argument is passed - otherwise, it’s easy to trip over this.
Let’s also avoid defaulting status to 0 inside _exit(). That way, if the caller forgets to pass an argument but has explicitly set status earlier, we preserve the intended value.
We should update _exit() with...
test -n "$1" && status="$1"
-ritesh
Quoted 5 lines
common/config +0
-0# Handle mkfs.$fstyp which does (or does not) require -f to overwrite set_mkfs_prog_path_with_opts() {Signature · 1 line
2.34.1
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 68 lines · Ritesh Harjani (IBM)
Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 100
Quoted 5 lines
common/config +2
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly....as it might not set the value of "$status" correctly, which is used as an exit code in the trap handler routine set up by the check script.
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 106
Quoted 6 lines
common/config +6
-0+_exit() +{ + status="$1" + exit "$status" +} +I agree with Darrick’s suggestion here. It’s safer to update status only when an argument is passed - otherwise, it’s easy to trip over this.
Quoted 7 lines
Let’s also avoid defaulting status to 0 inside
_exit(). That way, if the caller forgets to pass an argument but has explicitly set status earlier, we preserve the intended value.We should update
_exit()with...test -n "$1" && status="$1"
Okay, so in that case if someone does "status=<value>;_exit", we should end up with the "<value>" instead of something else, right?
--NR
Quoted 9 lines
-ritesh
Quoted 5 lines
common/config +0
-0# Handle mkfs.$fstyp which does (or does not) require -f to overwrite set_mkfs_prog_path_with_opts() {Signature · 1 line
2.34.1
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 72 lines · Nirjhar Roy (IBM)
Quoted 70 lines · Ritesh Harjani (IBM)
Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 98
Quoted 3 lines
common/config +2
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly....as it might not set the value of "$status" correctly, which is used as an exit code in the trap handler routine set up by the check script.
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 106
Quoted 6 lines
common/config +6
-0+_exit() +{ + status="$1" + exit "$status" +} +I agree with Darrick’s suggestion here. It’s safer to update status only when an argument is passed - otherwise, it’s easy to trip over this.
Let’s also avoid defaulting status to 0 inside
_exit(). That way, if the caller forgets to pass an argument but has explicitly set status earlier, we preserve the intended value.
Quoted 6 lines
Quoted 3 lines
We should update
_exit()with...test -n "$1" && status="$1"
Okay, so in that case if someone does "status=<value>;_exit", we should end up with the "<value>" instead of something else, right?
Right. I think. AFAICT the following simple program actually does return 5 despite the cleanup:
trap 'echo cleanup' INT QUIT TERM EXIT
exit 5
But since fstests set a variable named "status" and then "exit $status" from cleanup, I think it doesn't matter how status gets set as long as it /does/ get set somewhere.
--D
Quoted 17 lines
--NR
Quoted 9 lines
-ritesh
Quoted 5 lines
common/config +0
-0# Handle mkfs.$fstyp which does (or does not) require -f to overwrite set_mkfs_prog_path_with_opts() {Signature · 1 line
2.34.1Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 80 lines · Darrick J. Wong
Quoted 71 lines · Nirjhar Roy (IBM)
Quoted 70 lines · Ritesh Harjani (IBM)
Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 98
Quoted 3 lines
common/config +2
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly....as it might not set the value of "$status" correctly, which is used as an exit code in the trap handler routine set up by the check script.
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 106
Quoted 6 lines
common/config +6
-0+_exit() +{ + status="$1" + exit "$status" +} +I agree with Darrick’s suggestion here. It’s safer to update status only when an argument is passed - otherwise, it’s easy to trip over this.
Let’s also avoid defaulting status to 0 inside
_exit(). That way, if the caller forgets to pass an argument but has explicitly set status earlier, we preserve the intended value.Quoted 5 lines
Quoted 3 lines
We should update
_exit()with...test -n "$1" && status="$1"
Okay, so in that case if someone does "status=<value>;_exit", we should end up with the "<value>" instead of something else, right?
Right. I think. AFAICT the following simple program actually does return 5 despite the cleanup:
Quoted 6 lines
trap 'echo cleanup' INT QUIT TERM EXIT
exit 5But since fstests set a variable named "status" and then "exit $status" from cleanup, I think it doesn't matter how status gets set as long as it /does/ get set somewhere.
Right, I have got the idea. I will make the changes in next revision.
--NR
Quoted 18 lines
--D
Quoted 15 lines
--NR
Quoted 8 lines
-ritesh
Quoted 5 lines
common/config +0
-0# Handle mkfs.$fstyp which does (or does not) require -f to overwrite set_mkfs_prog_path_with_opts() {Signature · 1 line
2.34.1Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
In reply to Nirjhar Roy (IBM)Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 105
Quoted 10 lines
common/config +7
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly. +_exit() +{ + status="$1" + exit "$status" +}
The only issue with putting this helper in common/config is that calling _exit() requires sourcing common/config from the shell context that calls it.
This means every test must source common/config and re-execute the environment setup, even though we already have all the environment set up because it was exported from check when it sourced common/config.
We have the same problem with _fatal() - it is defined in common/config instead of an independent common file. If we put such functions in their own common file, they can be sourced without dependencies on any other common file being included first.
e.g. we create common/exit and place all the functions that terminate tests in it - _fatal, _notrun, _exit, etc and source that file once per shell context before we source common/config, common/rc, etc. This means we can source and call those termination functions from any context without having to worry about dependencies...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 74 lines · Dave Chinner
Quoted 49 lines · Nirjhar Roy (IBM)
We should always set the value of status correctly when we are exiting. Else, "$?" might not give us the correct value.
If we see the following trap
handler registration in the check script:if $OPTIONS_HAVE_SECTIONS; then
trap "_kill_seq; _summary; exit \$status" 0 1 2 3 15 else trap "_kill_seq; _wrapup; exit \$status" 0 1 2 3 15fi
So, "exit 1" will exit the check script without setting the correct return value. I ran with the following local.config file:
[
xfs_4k_valid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/test
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratch[
xfs_4k_invalid]
FSTYP=xfs
TEST_DEV=/dev/loop0
TEST_DIR=/mnt1/invalid_dir
SCRATCH_DEV=/dev/loop1
SCRATCH_MNT=/mnt1/scratchThis caused the
init_rc()to catch the case of invalid_test_mountoptions. Although the check script correctly failed during the execution of the "xfs_4k_invalid" section, the return value was 0, i.e "echo $?" returned 0. This is becauseinit_rcexits with "exit 1" without correctly setting the value of "status". IMO, the correct behavior should have been that "$?" should have been non-zero.The next patch will replace exit with
_exit.Signed-off-by Nirjhar Roy (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- common/config | 8 ++++++++ 1 file changed, 8 insertions(+)common/config +0
-0common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 105
Quoted 10 lines
common/config +7
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly. +_exit() +{ + status="$1" + exit "$status" +}The only issue with putting this helper in common/config is that calling
_exit()requires sourcing common/config from the shell context that calls it.This means every test must source common/config and re-execute the environment setup, even though we already have all the environment set up because it was exported from check when it sourced common/config.
We have the same problem with
_fatal()- it is defined in common/config instead of an independent common file. If we put such functions in their own common file, they can be sourced without dependencies on any other common file being included first.
Quoted 6 lines
e.g. we create common/exit and place all the functions that terminate tests in it -
_fatal,_notrun,_exit, etc and source that file once per shell context before we source common/config, common/rc, etc. This means we can source and call those termination functions from any context without having to worry about dependencies...
Yes, I agree to the above. Do you want this refactoring to be done as a part of this patch series in the further revisions, or can this be sent as a separate series?
--NR
Quoted 3 lines
-Dave.
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 36 lines · Nirjhar Roy (IBM)
Quoted 28 lines · Dave Chinner
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 103
Quoted 13 lines · Nirjhar Roy (IBM)
common/config +7
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly. +_exit() +{ + status="$1" + exit "$status" +}The only issue with putting this helper in common/config is that calling
_exit()requires sourcing common/config from the shell context that calls it.This means every test must source common/config and re-execute the environment setup, even though we already have all the environment set up because it was exported from check when it sourced common/config.
We have the same problem with
_fatal()- it is defined in common/config instead of an independent common file. If we put such functions in their own common file, they can be sourced without dependencies on any other common file being included first.Quoted 6 lines
e.g. we create common/exit and place all the functions that terminate tests in it -
_fatal,_notrun,_exit, etc and source that file once per shell context before we source common/config, common/rc, etc. This means we can source and call those termination functions from any context without having to worry about dependencies...
Quoted 3 lines
Yes, I agree to the above. Do you want this refactoring to be done as a part of this patch series in the further revisions, or can this be sent as a separate series?
Seperate series is fine. You're not making the dependency mess any worse than it already is with this change...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v3 5/6] common/config: Introduce _exit wrapper around exit command
Quoted 36 lines · Dave Chinner
Quoted 35 lines · Nirjhar Roy (IBM)
Quoted 34 lines · Dave Chinner
common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 103
Quoted 13 lines · Nirjhar Roy (IBM)
common/config +7
-0@@ -96,6 +96,14 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false} +# This functions sets the exit code to status and then exits. Don't use +# exit directly, as it might not set the value of "status" correctly. +_exit() +{ + status="$1" + exit "$status" +}The only issue with putting this helper in common/config is that calling
_exit()requires sourcing common/config from the shell context that calls it.This means every test must source common/config and re-execute the environment setup, even though we already have all the environment set up because it was exported from check when it sourced common/config.
We have the same problem with
_fatal()- it is defined in common/config instead of an independent common file. If we put such functions in their own common file, they can be sourced without dependencies on any other common file being included first.e.g. we create common/exit and place all the functions that terminate tests in it -
_fatal,_notrun,_exit, etc and source that file once per shell context before we source common/config, common/rc, etc. This means we can source and call those termination functions from any context without having to worry about dependencies...
Quoted 5 lines
Quoted 3 lines
Yes, I agree to the above. Do you want this refactoring to be done as a part of this patch series in the further revisions, or can this be sent as a separate series?
Seperate series is fine. You're not making the dependency mess any worse than it already is with this change...
Okay, got it. I will add this list of ToDos. Thank you so much for this suggestion.
--NR
Quoted 2 lines
-Dave.
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
PATCH v3 6/6 common: exit --> _exit
In reply to Nirjhar Roy (IBM)Replace exit <return-val> with _exit <return-val> which is introduced in the previous patch.
--- common/btrfs | 6 +-- common/ceph | 2 +- common/config | 7 ++-- common/dump | 11 +++-- common/ext4 | 2 +- common/populate | 2 +- common/preamble | 2 +- common/punch | 13 +++--- common/rc | 105 +++++++++++++++++++++++------------------------- common/repair | 4 +- common/xfs | 8 ++-- 11 files changed, 78 insertions(+), 84 deletions(-)
common/btrfs +3 -3
@@ -80,7 +80,7 @@ _require_btrfs_mkfs_feature() { if [ -z $1 ]; then echo "Missing feature name argument for _require_btrfs_mkfs_feature" - exit 1 + _exit 1 fi feat=$1 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
@@ -104,7 +104,7 @@ _require_btrfs_fs_feature() { if [ -z $1 ]; then echo "Missing feature name argument for _require_btrfs_fs_feature" - exit 1 + _exit 1 fi feat=$1 modprobe btrfs > /dev/null 2>&1
@@ -214,7 +214,7 @@ _check_btrfs_filesystem() if [ $ok -eq 0 ]; then status=1 if [ "$iam" != "check" ]; then - exit 1 + _exit 1 fi return 1 fi
common/ceph +1 -1
@@ -14,7 +14,7 @@ _ceph_create_file_layout() if [ -e $fname ]; then echo "File $fname already exists." - exit 1 + _exit 1 fi touch $fname $SETFATTR_PROG -n ceph.file.layout \
common/config +3 -4
@@ -123,8 +123,7 @@ set_mkfs_prog_path_with_opts() _fatal() { echo "$*" - status=1 - exit 1 + _exit 1 } export MKFS_PROG="$(type -P mkfs)"
@@ -868,7 +867,7 @@ get_next_config() { echo "Warning: need to define parameters for host $HOST" echo " or set variables:" echo " $MC" - exit 1 + _exit 1 fi _check_device TEST_DEV required $TEST_DEV
@@ -879,7 +878,7 @@ get_next_config() { if [ ! -z "$SCRATCH_DEV_POOL" ]; then if [ ! -z "$SCRATCH_DEV" ]; then echo "common/config: Error: \$SCRATCH_DEV ($SCRATCH_DEV) should be unset when \$SCRATCH_DEV_POOL ($SCRATCH_DEV_POOL) is set" - exit 1 + _exit 1 fi SCRATCH_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'` export SCRATCH_DEV
common/dump +5 -6
@@ -280,8 +280,7 @@ _create_dumpdir_stress_num() rm -rf $dump_dir if ! mkdir $dump_dir; then echo " failed to mkdir $dump_dir" - status=1 - exit + _exit 1 fi # Remove fsstress commands that aren't supported on all xfs configs so that
@@ -480,7 +479,7 @@ _do_create_dumpdir_fill() else $verbose && echo echo "Error: cannot mkdir \"$dir\"" - exit 1 + _exit 1 fi fi else
@@ -496,7 +495,7 @@ _do_create_dumpdir_fill() else $verbose && echo echo "Error: cannot mkdir \"$dir\"" - exit 1 + _exit 1 fi fi fi
@@ -507,7 +506,7 @@ _do_create_dumpdir_fill() else $verbose && echo echo "Error: cannot create \"$file\"" - exit 1 + _exit 1 fi fi if [ -n "$owner" -a -n "$group" ]; then
@@ -649,7 +648,7 @@ _do_create_dump_symlinks() else $verbose && echo echo "Error: cannot mkdir \"$dir\"" - exit 1 + _exit 1 fi fi fi
common/ext4 +1 -1
@@ -182,7 +182,7 @@ _require_scratch_ext4_feature() { if [ -z "$1" ]; then echo "Usage: _require_scratch_ext4_feature feature" - exit 1 + _exit 1 fi $MKFS_EXT4_PROG -F $MKFS_OPTIONS -O "$1" \ $SCRATCH_DEV 512m >/dev/null 2>&1 \
common/populate +1 -1
@@ -1003,7 +1003,7 @@ _fill_fs() if [ $# -ne 4 ]; then echo "Usage: _fill_fs filesize dir blocksize switch_user" - exit 1 + _exit 1 fi if [ $switch_user -eq 0 ]; then
common/preamble +1 -1
@@ -35,7 +35,7 @@ _begin_fstest() { if [ -n "$seq" ]; then echo "_begin_fstest can only be called once!" - exit 1 + _exit 1 fi seq=`basename $0`
common/punch +6 -7
@@ -172,16 +172,16 @@ _filter_fiemap_flags() $AWK_PROG -e "$awk_script" | _coalesce_extents } -# Filters fiemap output to only print the +# Filters fiemap output to only print the # file offset column and whether or not # it is an extent or a hole _filter_hole_fiemap() { $AWK_PROG ' $3 ~ /hole/ { - print $1, $2, $3; + print $1, $2, $3; next; - } + } $5 ~ /0x[[:xdigit:]]+/ { print $1, $2, "extent"; }' |
@@ -224,8 +224,7 @@ _filter_bmap() die_now() { - status=1 - exit + _exit 1 } # test the different corner cases for zeroing a range:
@@ -276,7 +275,7 @@ _test_generic_punch() u) unwritten_tests= ;; ?) echo Invalid flag - exit 1 + _exit 1 ;; esac done
@@ -552,7 +551,7 @@ _test_block_boundaries() d) sync_cmd= ;; ?) echo Invalid flag - exit 1 + _exit 1 ;; esac done
common/rc +51 -54
409 lines not on this page · raw message
common/repair +2 -2
@@ -16,7 +16,7 @@ _zero_position() }'` if [ -z "$offset" -o -z "$length" ]; then echo "cannot calculate offset ($offset) or length ($length)" - exit + _exit 1 fi length=`expr $length / 512` $here/src/devzero -v $value -b 1 -n $length -o $offset $SCRATCH_DEV \
@@ -113,7 +113,7 @@ _filter_dd() } # do some controlled corrupting & ensure repair recovers us -# +# _check_repair() { value=$1
common/xfs +4 -4
@@ -553,7 +553,7 @@ _require_xfs_db_command() { if [ $# -ne 1 ]; then echo "Usage: _require_xfs_db_command command" 1>&2 - exit 1 + _exit 1 fi command=$1
@@ -789,7 +789,7 @@ _check_xfs_filesystem() if [ $# -ne 3 ]; then echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2 - exit 1 + _exit 1 fi extra_mount_options=""
@@ -1014,7 +1014,7 @@ _check_xfs_filesystem() if [ $ok -eq 0 ]; then status=1 if [ "$iam" != "check" ]; then - exit 1 + _exit 1 fi return 1 fi
@@ -1379,7 +1379,7 @@ _require_xfs_spaceman_command() { if [ -z "$1" ]; then echo "Usage: _require_xfs_spaceman_command command [switch]" 1>&2 - exit 1 + _exit 1 fi local command=$1 shift
Signature · 1 line
2.34.1