Skip to contentSkip to conversation

Make ./new work for non-root user

PATCH In review Jan Kara 2 participants 7 messages May 24, 2018 – May 29, 2018

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 Make ./new work for non-root user

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

---
 check              | 16 +++++-----------
 common/config      | 16 ++--------------
 common/config-base | 21 +++++++++++++++++++++
 common/rc          | 27 ++-------------------------
 new                |  2 +-
 5 files changed, 31 insertions(+), 51 deletions(-)
 create mode 100644 common/config-base
check +5 -11
index 96198ac4714e..4c6e8285bc16 100755
@@ -331,10 +331,11 @@ while [ $# -gt 0 ]; do
 	shift
 done
 
-# we need common/config, source it after processing args, overlay needs FSTYP
-# set before sourcing common/config
-if ! . ./common/config; then
-	echo "$iam: failed to source common/config"
+# we need common/rc, that also sources common/config. We need to source it
+# after processing args, overlay needs FSTYP set before sourcing common/config
+if ! . ./common/rc
+then
+	echo "check: failed to source common/rc"
 	exit 1
 fi
 
@@ -374,13 +375,6 @@ elif [ -z "$GROUP_LIST" ]; then
 	GROUP_LIST="auto"
 fi
 
-# we need common/rc
-if ! . ./common/rc
-then
-    echo "check: failed to source common/rc"
-    exit 1
-fi
-
 if [ `id -u` -ne 0 ]
 then
     echo "check: QA must be run as root"
common/config +2 -14
index af360cefc804..fa07a6799824 100644
@@ -47,6 +47,8 @@
 #   validity or mountedness.
 #
 
+. common/config-base
+
 # all tests should use a common language setting to prevent golden
 # output mismatches.
 export LANG=C
@@ -88,12 +90,6 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
-# $1 = prog to look for
-set_prog_path()
-{
-	type -P $1
-}
-
 # Handle mkfs.$fstyp which does (or does not) require -f to overwrite
 set_mkfs_prog_path_with_opts()
 {
@@ -132,9 +128,6 @@ export FSSTRESS_PROG="./ltp/fsstress"
 export PERL_PROG="`set_prog_path perl`"
 [ "$PERL_PROG" = "" ] && _fatal "perl not found"
 
-export AWK_PROG="`set_prog_path awk`"
-[ "$AWK_PROG" = "" ] && _fatal "awk not found"
-
 export SED_PROG="`set_prog_path sed`"
 [ "$SED_PROG" = "" ] && _fatal "sed not found"
 
@@ -271,11 +264,6 @@ fi
 rm -f /tmp/crc_check.img
 export XFS_MKFS_HAS_NO_META_SUPPORT
 
-# new doesn't need config file parsed, we can stop here
-if [ "$iam" == "new" ]; then
-	return 0
-fi
-
 _mount_opts()
 {
 	case $FSTYP in
common/config-base new file +21 -0
new file mode 100644
index 000000000000..5d8a858160af
@@ -0,0 +1,21 @@
+##/bin/bash
+
+# Valid test names start with 3 digits "NNN":
+#  "[0-9]\{3\}"
+# followed by an optional "-":
+#  "-\?"
+# followed by an optional combination of alphanumeric and "-" chars:
+#  "[[:alnum:]-]*"
+# e.g. 999-the-mark-of-fstests
+#
+VALID_TEST_ID="[0-9]\{3\}"
+VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"
+
+# $1 = prog to look for
+set_prog_path()
+{
+	type -P $1
+}
+
+export AWK_PROG="`set_prog_path awk`"
+[ "$AWK_PROG" = "" ] && _fatal "awk not found"
common/rc +2 -25
index ffe5323603eb..7368e2e12988 100644
@@ -20,18 +20,9 @@
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
-BC=$(which bc 2> /dev/null) || BC=
+. common/config
 
-# Valid test names start with 3 digits "NNN":
-#  "[0-9]\{3\}"
-# followed by an optional "-":
-#  "-\?"
-# followed by an optional combination of alphanumeric and "-" chars:
-#  "[[:alnum:]-]*"
-# e.g. 999-the-mark-of-fstests
-#
-VALID_TEST_ID="[0-9]\{3\}"
-VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"
+BC=$(which bc 2> /dev/null) || BC=
 
 # Some tests are not relevant or functional when testing XFS realtime
 # subvolumes along with the rtinherit=1 mkfs option.  In these cases,
@@ -110,16 +101,6 @@ _ls_l()
 	ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
 }
 
-# we need common/config
-if [ "$iam" != "check" ]
-then
-    if ! . ./common/config
-        then
-        echo "$iam: failed to source common/config"
-        exit 1
-    fi
-fi
-
 _dump_err()
 {
     _err_msg="$*"
@@ -3560,10 +3541,6 @@ _disable_dmesg_check()
 
 init_rc()
 {
-	if [ "$iam" == new ]
-	then
-		return
-	fi
 	# make some further configuration checks here
 	if [ "$TEST_DEV" = ""  ]
 	then
new +1 -1
index 4eacccd3bf8b..2b322b2fdfb3 100755
@@ -23,7 +23,7 @@
 
 # generic initialization
 iam=new
-. ./common/rc
+. ./common/config-base
 
 trap "rm -f /tmp/$$.; exit" 0 1 2 3 15
 
Signature · 1 line
2.13.6
#1 lore raw
Quoted 9 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

....

common/rc line 23

Quoted 8 lines
common/rc +1 -1
@@ -20,18 +20,9 @@
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
-BC=$(which bc 2> /dev/null) || BC=
+. common/config

Doesn't this means we now include common/config in every test setup routine, even though the environment it sets up is inherited from the check function.

If so, that's going to add significantly to the individual test startup time (which already takes a significant fraction of a second) and this happens hundreds of times over an auto run instead of only once when we start the test run. It seems wrong to be doing this over and over again unecessarily....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#2 lore raw
Quoted 17 lines · Dave Chinner
Quoted 9 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

....

Quoted 6 lines
common/rc +0 -0
@@ -20,18 +20,9 @@
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
Quoted 6 lines

common/rc line 23

Quoted 2 lines
common/rc +1 -1
-BC=$(which bc 2> /dev/null) || BC=
+. common/config

Doesn't this means we now include common/config in every test setup routine, even though the environment it sets up is inherited from the check function.

What you describe was happening already in the past AFAICT. The test gets executed as "./$seq" so only exported variables are inherited. Thus 'iam' variable is not set when executing the test and therefore common/rc was already including common/config. Also including common/config in each test is even required to get functions declared there. Am I missing something?

Quoted 5 lines

If so, that's going to add significantly to the individual test startup time (which already takes a significant fraction of a second) and this happens hundreds of times over an auto run instead of only once when we start the test run. It seems wrong to be doing this over and over again unecessarily....

I agree but it's not a new problem introduced by my patch. I've just kept the current status and tried to make the initialization less confusing.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw
Quoted 25 lines · Jan Kara
Quoted 17 lines · Dave Chinner
Quoted 9 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

....

Quoted 6 lines
common/rc +0 -0
@@ -20,18 +20,9 @@
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
Quoted 6 lines

common/rc line 23

Quoted 2 lines
common/rc +1 -1
-BC=$(which bc 2> /dev/null) || BC=
+. common/config

Doesn't this means we now include common/config in every test setup routine, even though the environment it sets up is inherited from the check function.

Quoted 5 lines

What you describe was happening already in the past AFAICT. The test gets executed as "./$seq" so only exported variables are inherited. Thus 'iam' variable is not set when executing the test and therefore common/rc was already including common/config. Also including common/config in each test is even required to get functions declared there. Am I missing something?

No, I just read the code incorrectly. The way common/config gets included is a maze of twisty passages - I'll go back and look at the patch again...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#4 lore raw
In reply to Jan Kara

Second go....

Quoted 7 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

FWIW, common/config is also called from setup.

Quoted 19 lines
---
 check              | 16 +++++-----------
 common/config      | 16 ++--------------
 common/config-base | 21 +++++++++++++++++++++
 common/rc          | 27 ++-------------------------
 new                |  2 +-
 5 files changed, 31 insertions(+), 51 deletions(-)
 create mode 100644 common/config-base
check +0 -1
index 96198ac4714e..4c6e8285bc16 100755
@@ -331,10 +331,11 @@ while [ $# -gt 0 ]; do
 	shift
 done
 
-# we need common/config, source it after processing args, overlay needs FSTYP

check while [ $# -gt 0 ]; do · line 340

Quoted 10 lines
check +5 -3
-# set before sourcing common/config
-if ! . ./common/config; then
-	echo "$iam: failed to source common/config"
+# we need common/rc, that also sources common/config. We need to source it
+# after processing args, overlay needs FSTYP set before sourcing common/config
+if ! . ./common/rc
+then
+	echo "check: failed to source common/rc"
 	exit 1
 fi

Can we keep the existing formatting of "if foo ; then", please?

Quoted 14 lines
common/config +2 -0
index af360cefc804..fa07a6799824 100644
@@ -47,6 +47,8 @@
 #   validity or mountedness.
 #
 
+. common/config-base
+
 # all tests should use a common language setting to prevent golden
 # output mismatches.
 export LANG=C

common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 95

Quoted 8 lines
common/config +0 -5
@@ -88,12 +90,6 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
-# $1 = prog to look for
-set_prog_path()
-{
-	type -P $1
-}

Can we just get rid of set_prog_path() and replace it with direct calls to $(type -P foo) as an initial patch? This goes away at that point, because new can then just use a locally coded version....

Quoted 5 lines
common/config-base new file +2 -0
@@ -0,0 +1,21 @@
+##/bin/bash
+

common/config-base line 12

Quoted 10 lines
common/config-base new file +10 -0
+# Valid test names start with 3 digits "NNN":
+#  "[0-9]\{3\}"
+# followed by an optional "-":
+#  "-\?"
+# followed by an optional combination of alphanumeric and "-" chars:
+#  "[[:alnum:]-]*"
+# e.g. 999-the-mark-of-fstests
+#
+VALID_TEST_ID="[0-9]\{3\}"
+VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"

This, then, is really the only thing shared between check and new, right? So perhaps rename the file to common/test_names so it doesn't get confused with stuff to do with configuration?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#5 lore raw
Quoted 12 lines · Dave Chinner

Second go....

Quoted 7 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

FWIW, common/config is also called from setup.

.....

Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -88,12 +90,6 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
Quoted 9 lines

Review export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 95

Quoted 5 lines
(quoted diff) +0 -5
-# $1 = prog to look for
-set_prog_path()
-{
-	type -P $1
-}

Can we just get rid of set_prog_path() and replace it with direct calls to $(type -P foo) as an initial patch? This goes away at that point, because new can then just use a locally coded version....

Something like this?

Cheers,

Dave.

Signature · 18 lines
Dave Chinner
[email protected]

fstests: get rid of set_prog_path

From: Dave Chinner <[email protected]>

It's just a one line wrapper that adds complexity, remove it. Move
the couple of calls in tests to common/config, but leave the xfsdump
setup in place and just convert it.

Signed-off-by: Dave Chinner <[email protected]>
---
 common/config   | 170 +++++++++++++++++++++++++++-----------------------------
 common/dump     |   6 +-
 tests/btrfs/085 |   2 -
 tests/xfs/446   |   1 -
 4 files changed, 86 insertions(+), 93 deletions(-)
common/config +83 -87
index 1cf402eee1dc..ef774b8d552b 100644
@@ -88,17 +88,11 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
-# $1 = prog to look for
-set_prog_path()
-{
-	type -P $1
-}
-
 # Handle mkfs.$fstyp which does (or does not) require -f to overwrite
 set_mkfs_prog_path_with_opts()
 {
 	local fstyp=$1
-	local p=`set_prog_path mkfs.$fstyp`
+	local p=$(type -P mkfs.$fstyp)
 
 	# Note: mkfs.f2fs doesn't support the --help option yet, but it doesn't
 	# matter since it also prints the help when an invalid option is given.
@@ -117,105 +111,106 @@ _fatal()
     exit 1
 }
 
-export MKFS_PROG="`set_prog_path mkfs`"
+export MKFS_PROG=$(type -P mkfs)
 [ "$MKFS_PROG" = "" ] && _fatal "mkfs not found"
 
-export MOUNT_PROG="`set_prog_path mount`"
+export MOUNT_PROG=$(type -P mount)
 [ "$MOUNT_PROG" = "" ] && _fatal "mount not found"
 
-export UMOUNT_PROG="`set_prog_path umount`"
+export UMOUNT_PROG=$(type -P umount)
 [ "$UMOUNT_PROG" = "" ] && _fatal "umount not found"
 
 export FSSTRESS_PROG="./ltp/fsstress"
 [ ! -x $FSSTRESS_PROG ] && _fatal "fsstress not found or executable"
 
-export PERL_PROG="`set_prog_path perl`"
+export PERL_PROG=$(type -P perl)
 [ "$PERL_PROG" = "" ] && _fatal "perl not found"
 
-export AWK_PROG="`set_prog_path awk`"
+export AWK_PROG=$(type -P awk)
 [ "$AWK_PROG" = "" ] && _fatal "awk not found"
 
-export SED_PROG="`set_prog_path sed`"
+export SED_PROG=$(type -P sed)
 [ "$SED_PROG" = "" ] && _fatal "sed not found"
 
-export BC_PROG="`set_prog_path bc`"
+export BC_PROG=$(type -P bc)
 [ "$BC_PROG" = "" ] && _fatal "bc not found"
 
 export PS_ALL_FLAGS="-ef"
 
-export DF_PROG="`set_prog_path df`"
+export DF_PROG=$(type -P df)
 [ "$DF_PROG" = "" ] && _fatal "df not found"
 [ "$HOSTOS" = "Linux" ] && export DF_PROG="$DF_PROG -T -P"
 
-export XFS_IO_PROG="`set_prog_path xfs_io`"
+export XFS_IO_PROG=$(type -P xfs_io)
 [ "$XFS_IO_PROG" = "" ] && _fatal "xfs_io not found"
 
-export XFS_LOGPRINT_PROG="`set_prog_path xfs_logprint`"
-export XFS_REPAIR_PROG="`set_prog_path xfs_repair`"
-export XFS_DB_PROG="`set_prog_path xfs_db`"
-export XFS_GROWFS_PROG=`set_prog_path xfs_growfs`
-export XFS_SPACEMAN_PROG="`set_prog_path xfs_spaceman`"
-export XFS_SCRUB_PROG="`set_prog_path xfs_scrub`"
-export XFS_PARALLEL_REPAIR_PROG="`set_prog_path xfs_prepair`"
-export XFS_PARALLEL_REPAIR64_PROG="`set_prog_path xfs_prepair64`"
-export __XFSDUMP_PROG="`set_prog_path xfsdump`"
+export XFS_LOGPRINT_PROG=$(type -P xfs_logprint)
+export XFS_REPAIR_PROG=$(type -P xfs_repair)
+export XFS_DB_PROG=$(type -P xfs_db)
+export XFS_GROWFS_PROG=$(type -P xfs_growfs)
+export XFS_SPACEMAN_PROG=$(type -P xfs_spaceman)
+export XFS_SCRUB_PROG=$(type -P xfs_scrub)
+export XFS_PARALLEL_REPAIR_PROG=$(type -P xfs_prepair)
+export XFS_PARALLEL_REPAIR64_PROG=$(type -P xfs_prepair64)
+export __XFSDUMP_PROG=$(type -P xfsdump)
 if [ -n "$__XFSDUMP_PROG" ]; then
 	export XFSDUMP_PROG="$__XFSDUMP_PROG -e"
 else
 	export XFSDUMP_PROG=""
 fi
-export XFSRESTORE_PROG="`set_prog_path xfsrestore`"
-export XFSINVUTIL_PROG="`set_prog_path xfsinvutil`"
-export GETFATTR_PROG="`set_prog_path getfattr`"
-export SETFATTR_PROG="`set_prog_path setfattr`"
-export CHACL_PROG="`set_prog_path chacl`"
-export ATTR_PROG="`set_prog_path attr`"
-export QUOTA_PROG="`set_prog_path quota`"
-export XFS_QUOTA_PROG="`set_prog_path xfs_quota`"
-export KILLALL_PROG="`set_prog_path killall`"
-export INDENT_PROG="`set_prog_path indent`"
-export XFS_COPY_PROG="`set_prog_path xfs_copy`"
-export FSTRIM_PROG="`set_prog_path fstrim`"
-export DUMPE2FS_PROG="`set_prog_path dumpe2fs`"
-export FIO_PROG="`set_prog_path fio`"
-export FILEFRAG_PROG="`set_prog_path filefrag`"
-export E4DEFRAG_PROG="`set_prog_path e4defrag`"
-export LOGGER_PROG="`set_prog_path logger`"
-export DBENCH_PROG="`set_prog_path dbench`"
-export DMSETUP_PROG="`set_prog_path dmsetup`"
-export WIPEFS_PROG="`set_prog_path wipefs`"
-export DUMP_PROG="`set_prog_path dump`"
-export RESTORE_PROG="`set_prog_path restore`"
-export LVM_PROG="`set_prog_path lvm`"
-export CHATTR_PROG="`set_prog_path chattr`"
-export DEBUGFS_PROG="`set_prog_path debugfs`"
-export UUIDGEN_PROG="`set_prog_path uuidgen`"
-export GETRICHACL_PROG="`set_prog_path getrichacl`"
-export SETRICHACL_PROG="`set_prog_path setrichacl`"
-export KEYCTL_PROG="`set_prog_path keyctl`"
-export XZ_PROG="`set_prog_path xz`"
-export FLOCK_PROG="`set_prog_path flock`"
-export LDD_PROG="`set_prog_path ldd`"
-export TIMEOUT_PROG="`set_prog_path timeout`"
-export MAN_PROG="`set_prog_path man`"
-export NFS4_SETFACL_PROG="`set_prog_path nfs4_setfacl`"
-export NFS4_GETFACL_PROG="`set_prog_path nfs4_getfacl`"
-export UBIUPDATEVOL_PROG="`set_prog_path ubiupdatevol`"
-export THIN_CHECK_PROG="$(set_prog_path thin_check)"
-export PYTHON2_PROG="`set_prog_path python2`"
-export SQLITE3_PROG="`set_prog_path sqlite3`"
-export TIMEOUT_PROG="`set_prog_path timeout`"
-export SETCAP_PROG="`set_prog_path setcap`"
-export GETCAP_PROG="`set_prog_path getcap`"
+export XFSRESTORE_PROG=$(type -P xfsrestore)
+export XFSINVUTIL_PROG=$(type -P xfsinvutil)
+export GETFATTR_PROG=$(type -P getfattr)
+export SETFATTR_PROG=$(type -P setfattr)
+export CHACL_PROG=$(type -P chacl)
+export ATTR_PROG=$(type -P attr)
+export QUOTA_PROG=$(type -P quota)
+export XFS_QUOTA_PROG=$(type -P xfs_quota)
+export KILLALL_PROG=$(type -P killall)
+export INDENT_PROG=$(type -P indent)
+export XFS_COPY_PROG=$(type -P xfs_copy)
+export FSTRIM_PROG=$(type -P fstrim)
+export DUMPE2FS_PROG=$(type -P dumpe2fs)
+export FIO_PROG=$(type -P fio)
+export FILEFRAG_PROG=$(type -P filefrag)
+export E4DEFRAG_PROG=$(type -P e4defrag)
+export LOGGER_PROG=$(type -P logger)
+export DBENCH_PROG=$(type -P dbench)
+export DMSETUP_PROG=$(type -P dmsetup)
+export WIPEFS_PROG=$(type -P wipefs)
+export DUMP_PROG=$(type -P dump)
+export RESTORE_PROG=$(type -P restore)
+export LVM_PROG=$(type -P lvm)
+export CHATTR_PROG=$(type -P chattr)
+export DEBUGFS_PROG=$(type -P debugfs)
+export UUIDGEN_PROG=$(type -P uuidgen)
+export GETRICHACL_PROG=$(type -P getrichacl)
+export SETRICHACL_PROG=$(type -P setrichacl)
+export KEYCTL_PROG=$(type -P keyctl)
+export XZ_PROG=$(type -P xz)
+export FLOCK_PROG=$(type -P flock)
+export LDD_PROG=$(type -P ldd)
+export TIMEOUT_PROG=$(type -P timeout)
+export MAN_PROG=$(type -P man)
+export NFS4_SETFACL_PROG=$(type -P nfs4_setfacl)
+export NFS4_GETFACL_PROG=$(type -P nfs4_getfacl)
+export UBIUPDATEVOL_PROG=$(type -P ubiupdatevol)
+export THIN_CHECK_PROG=$(type -P thin_check)
+export PYTHON2_PROG=$(type -P python2)
+export SQLITE3_PROG=$(type -P sqlite3)
+export TIMEOUT_PROG=$(type -P timeout)
+export SETCAP_PROG=$(type -P setcap)
+export GETCAP_PROG=$(type -P getcap)
+export CHECKBASHISMS_PROG=$(type -P checkbashisms)
 
 # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
 # newer systems have udevadm command but older systems like RHEL5 don't.
 # But if neither one is available, just set it to "sleep 1" to wait for lv to
 # be settled
-UDEV_SETTLE_PROG="`set_prog_path udevadm`"
+UDEV_SETTLE_PROG=$(type -P udevadm)
 if [ "$UDEV_SETTLE_PROG" == "" ]; then
 	# try udevsettle command
-	UDEV_SETTLE_PROG="`set_prog_path udevsettle`"
+	UDEV_SETTLE_PROG=$(type -P udevsettle)
 else
 	# udevadm is available, add 'settle' as subcommand
 	UDEV_SETTLE_PROG="$UDEV_SETTLE_PROG settle"
@@ -228,23 +223,24 @@ export UDEV_SETTLE_PROG
 
 case "$HOSTOS" in
     Linux)
-        export MKFS_XFS_PROG="`set_prog_path mkfs.xfs`"
-        export MKFS_EXT4_PROG="`set_prog_path mkfs.ext4`"
-        export MKFS_UDF_PROG="`set_prog_path mkudffs`"
-        export MKFS_BTRFS_PROG="`set_mkfs_prog_path_with_opts btrfs`"
-        export MKFS_F2FS_PROG="`set_mkfs_prog_path_with_opts f2fs`"
-        export DUMP_F2FS_PROG="`set_prog_path dump.f2fs`"
-        export BTRFS_UTIL_PROG="`set_prog_path btrfs`"
-        export BTRFS_SHOW_SUPER_PROG="`set_prog_path btrfs-show-super`"
-	export BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
-        export XFS_FSR_PROG="`set_prog_path xfs_fsr`"
-        export MKFS_NFS_PROG="false"
-        export MKFS_CIFS_PROG="false"
-        export MKFS_OVERLAY_PROG="false"
-        export MKFS_REISER4_PROG="`set_prog_path mkfs.reiser4`"
-	export E2FSCK_PROG="`set_prog_path e2fsck`"
-	export TUNE2FS_PROG="`set_prog_path tune2fs`"
-	export FSCK_OVERLAY_PROG="`set_prog_path fsck.overlay`"
+	export MKFS_XFS_PROG=$(type -P mkfs.xfs)
+	export MKFS_EXT4_PROG=$(type -P mkfs.ext4)
+	export MKFS_UDF_PROG=$(type -P mkudffs)
+	export MKFS_BTRFS_PROG=$(type -P btrfs)
+	export MKFS_F2FS_PROG=$(type -P f2fs)
+	export DUMP_F2FS_PROG=$(type -P dump.f2fs)
+	export BTRFS_UTIL_PROG=$(type -P btrfs)
+	export BTRFS_SHOW_SUPER_PROG=$(type -P btrfs-show-super)
+	export BTRFS_CONVERT_PROG=$(type -P btrfs-convert)
+	export BTRFS_DEBUG_TREE_PROG=$(type -P btrfs-debug-tree)
+	export XFS_FSR_PROG=$(type -P xfs_fsr)
+	export MKFS_NFS_PROG="false"
+	export MKFS_CIFS_PROG="false"
+	export MKFS_OVERLAY_PROG="false"
+	export MKFS_REISER4_PROG=$(type -P mkfs.reiser4)
+	export E2FSCK_PROG=$(type -P e2fsck)
+	export TUNE2FS_PROG=$(type -P tune2fs)
+	export FSCK_OVERLAY_PROG=$(type -P fsck.overlay)
         ;;
 esac
 
common/dump +3 -3
index 7b9c10a25414..8a0ba1096d6a 100644
@@ -29,10 +29,10 @@ if [ -n "$DEBUGDUMP" ]; then
 
 	# Use dump/restore in qa directory (copy them here) for debugging
 	export PATH="$here:$PATH"
-	export __XFSDUMP_PROG="`set_prog_path xfsdump`"
+	export __XFSDUMP_PROG=$(type -P xfsdump)
 	export XFSDUMP_PROG="$__XFSDUMP_PROG -e"
-	export XFSRESTORE_PROG="`set_prog_path xfsrestore`"
-	export XFSINVUTIL_PROG="`set_prog_path xfsinvutil`"
+	export XFSRESTORE_PROG=$(type -P xfsrestore)
+	export XFSINVUTIL_PROG=$(type -P xfsinvutil)
 	[ -x $here/xfsdump ]    && echo "Using xfstests' xfsdump for debug"
 	[ -x $here/xfsrestore ] && echo "Using xfstests' xfsrestore for debug"
 	[ -x $here/xfsinvutil ] && echo "Using xfstests' xfsinvutil for debug"
tests/btrfs/085 +0 -2
index 804899724cba..a1edc28341da 100755
@@ -55,8 +55,6 @@ _supported_fs btrfs
 _supported_os Linux
 _require_scratch
 _require_dm_target flakey
-
-BTRFS_DEBUG_TREE_PROG="`set_prog_path btrfs-debug-tree`"
 _require_command "$BTRFS_DEBUG_TREE_PROG" btrfs-debug-tree
 
 rm -f $seqres.full
tests/xfs/446 +0 -1
index 752c6a7de827..ac74723f471f 100755
@@ -37,7 +37,6 @@ trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
 # real QA test starts here
 _supported_fs xfs
 _supported_os Linux
-export CHECKBASHISMS_PROG="`set_prog_path checkbashisms`"
 _require_command "$CHECKBASHISMS_PROG" checkbashisms
 
 test -z "$WORKAREA" && _notrun "Can't find xfsprogs source"
author
#6 lore raw
In reply to Dave Chinner
Quoted 10 lines · Dave Chinner
Quoted 7 lines · Jan Kara

Currently 'new' script sources common/config which tries to find mkfs and fails if not found (which is likely for non-root user). This is inconvenient as development usually does not happen as root. In fact the vast majority of setup in common/config and common/rc is not necessary for 'new'. Split out the necessary bits into new common/config-base and use it in 'new'. Cleanup common/rc and common/config now that it's only used from 'check'.

FWIW, common/config is also called from setup.

Fixed up.

Quoted 8 lines
Quoted 8 lines
check +0 -0
index 96198ac4714e..4c6e8285bc16 100755
@@ -331,10 +331,11 @@ while [ $# -gt 0 ]; do
 	shift
 done
 
Quoted 13 lines

check while [ $# -gt 0 ]; do · line 340

Quoted 11 lines
check +5 -4
-# we need common/config, source it after processing args, overlay needs FSTYP
-# set before sourcing common/config
-if ! . ./common/config; then
-	echo "$iam: failed to source common/config"
+# we need common/rc, that also sources common/config. We need to source it
+# after processing args, overlay needs FSTYP set before sourcing common/config
+if ! . ./common/rc
+then
+	echo "check: failed to source common/rc"
 	exit 1
 fi

Can we keep the existing formatting of "if foo ; then", please?

Will do.

Quoted 17 lines
Quoted 17 lines
common/config +2 -0
index af360cefc804..fa07a6799824 100644
@@ -47,6 +47,8 @@
 #   validity or mountedness.
 #
 
+. common/config-base
+
 # all tests should use a common language setting to prevent golden
 # output mismatches.
 export LANG=C
@@ -88,12 +90,6 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
Quoted 9 lines

common/config export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes} · line 95

Quoted 5 lines
common/config +0 -5
-# $1 = prog to look for
-set_prog_path()
-{
-	type -P $1
-}

Can we just get rid of set_prog_path() and replace it with direct calls to $(type -P foo) as an initial patch? This goes away at that point, because new can then just use a locally coded version....

I've added your patch to the series. Thanks!

Quoted 11 lines
Quoted 11 lines
common/config-base new file +8 -0
@@ -0,0 +1,21 @@
+##/bin/bash
+
+# Valid test names start with 3 digits "NNN":
+#  "[0-9]\{3\}"
+# followed by an optional "-":
+#  "-\?"
+# followed by an optional combination of alphanumeric and "-" chars:
+#  "[[:alnum:]-]*"
Quoted 8 lines

common/config-base line 12

Quoted 4 lines
common/config-base new file +4 -0
+# e.g. 999-the-mark-of-fstests
+#
+VALID_TEST_ID="[0-9]\{3\}"
+VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"

This, then, is really the only thing shared between check and new, right? So perhaps rename the file to common/test_names so it doesn't get confused with stuff to do with configuration?

OK, there's also the AWK_PROG thing but I've decided to just have that directly in 'new'. There's not much to break there.

Thanks for review!

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR