diff options
author | John Wren Kennedy <[email protected]> | 2017-04-05 20:18:22 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-04-06 09:25:36 -0700 |
commit | c1d9abf9059a19c2b48eaa645dbce2e1fba3e0b1 (patch) | |
tree | e10f847d69d44292b0b641324cc5007b8c4badff /tests/zfs-tests/include | |
parent | 7a4500a10102c00a67442628df2ac2395484757e (diff) |
OpenZFS 7290 - ZFS test suite needs to control what utilities it can run
Authored by: John Wren Kennedy <[email protected]>
Reviewed by: Dan Kimmel <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: Dan McDonald <[email protected]>
Approved by: Gordon Ross <[email protected]>
Ported-by: Brian Behlendorf <[email protected]>
Ported-by: George Melikov <[email protected]>
Porting Notes:
- Utilities which aren't available under Linux have been removed.
- Because of sudo's default secure path behavior PATH must be
explicitly reset at the top of libtest.shlib. This avoids the
need for all users to customize secure path on their system.
- Updated ZoL infrastructure to manage constrained path
- Updated all test cases
- Check permissions for usergroup tests
- When testing in-tree create links under bin/
- Update fault cleanup such that missing files during
cleanup aren't fatal.
- Configure su environment with constrained path
OpenZFS-issue: https://www.illumos.org/issues/7290
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/1d32ba6
Closes #5903
Diffstat (limited to 'tests/zfs-tests/include')
-rw-r--r-- | tests/zfs-tests/include/.gitignore | 2 | ||||
-rw-r--r-- | tests/zfs-tests/include/commands.cfg | 156 | ||||
-rw-r--r-- | tests/zfs-tests/include/commands.cfg.in | 133 | ||||
-rw-r--r-- | tests/zfs-tests/include/default.cfg (renamed from tests/zfs-tests/include/default.cfg.in) | 55 | ||||
-rw-r--r-- | tests/zfs-tests/include/libtest.shlib | 851 | ||||
-rw-r--r-- | tests/zfs-tests/include/math.shlib | 8 | ||||
-rw-r--r-- | tests/zfs-tests/include/properties.shlib | 4 |
7 files changed, 600 insertions, 609 deletions
diff --git a/tests/zfs-tests/include/.gitignore b/tests/zfs-tests/include/.gitignore deleted file mode 100644 index 5de1b82cb..000000000 --- a/tests/zfs-tests/include/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/commands.cfg -/default.cfg diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg new file mode 100644 index 000000000..0776c53fa --- /dev/null +++ b/tests/zfs-tests/include/commands.cfg @@ -0,0 +1,156 @@ +# +# These variables are used by zfs-tests.sh to constrain which utilities +# may be used by the suite. The suite will create a directory which is +# the only element of $PATH and create symlinks from that dir to the +# binaries listed below. +# +# Please keep the contents of each variable sorted for ease of reading +# and maintenance. +# +export SYSTEM_FILES='arp + awk + attr + basename + bc + blockdev + bunzip2 + bzcat + cat + chattr + chgrp + chmod + chown + cksum + cmp + cp + cpio + cut + date + dd + df + diff + dirname + du + echo + egrep + exportfs + expr + false + fdisk + file + find + fio + getconf + getent + getfacl + grep + groupadd + groupdel + groupmod + gunzip + gzip + head + hostname + id + iostat + kill + ksh + ln + logname + ls + lsblk + lsmod + lsscsi + md5sum + mkdir + mknod + mktemp + modprobe + mount + mpstat + mv + net + openssl + parted + pax + pgrep + ping + pkill + printf + ps + pwd + python + quotaon + readlink + rm + rmdir + sed + seq + setenforce + setfacl + setfattr + sh + sha256sum + shuf + sleep + sort + stat + strings + su + sudo + sum + swapon + sync + tail + tar + timeout + touch + tr + true + truncate + udevadm + umask + umount + uname + useradd + userdel + usermod + uuidgen + vmstat + wait + wc + which + xargs' + +export ZFS_FILES='zdb + zfs + zhack + zinject + zpool + ztest + zpios + raidz_test + arc_summary.py + arcstat.py + dbufstat.py + zed' + +export ZFSTEST_FILES='chg_usr_exec + devname2devid + dir_rd_update + file_check + file_trunc + file_write + largest_file + mkbusy + mkfile + mkfiles + mktree + mmap_exec + mmapwrite + randfree_file + readmmap + rename_dir + rm_lnkcnt_zero_file + threadsappend + xattrtest' diff --git a/tests/zfs-tests/include/commands.cfg.in b/tests/zfs-tests/include/commands.cfg.in deleted file mode 100644 index 39266d2ef..000000000 --- a/tests/zfs-tests/include/commands.cfg.in +++ /dev/null @@ -1,133 +0,0 @@ -export AWK="@AWK@" -export BLOCKDEV="@BLOCKDEV@" -export BASENAME="@BASENAME@" -export BC="@BC@" -export BUNZIP2="@BUNZIP2@" -export BZCAT="@BZCAT@" -export CAT="@CAT@" -export CD="@CD@" -export CHACL="@CHACL@" -export CHGRP="@CHGRP@" -export CHMOD="@CHMOD@" -export CHOWN="@CHOWN@" -export CKSUM="@CKSUM@" -export CMP="@CMP@" -export COMPRESS="@COMPRESS@" -export COREADM="@COREADM@" -export CP="@CP@" -export CPIO="@CPIO@" -export CUT="@CUT@" -export DATE="@DATE@" -export DD="@DD@" -export DF="@DF@" -export DIFF="@DIFF@" -export DIRCMP="@DIRCMP@" -export DIRNAME="@DIRNAME@" -export DU="@DU@" -export DUMPADM="@DUMPADM@" -export ECHO="@ECHO@" -export EGREP="@EGREP@" -export FALSE="@FALSE@" -export FDISK="@FDISK@" -export FGREP="@FGREP@" -export FILE="@FILE@" -export FIND="@FIND@" -export FIO="@FIO@" -export FORMAT="@FORMAT@" -export FREE="@FREE@" -export FSCK="@FSCK@" -export GETENT="@GETENT@" -export GETFACL="@GETFACL@" -export GETMAJOR="@GETMAJOR@" -export GNUDD="@GNUDD@" -export GREP="@GREP@" -export GROUPADD="@GROUPADD@" -export GROUPDEL="@GROUPDEL@" -export GROUPMOD="@GROUPMOD@" -export HEAD="@HEAD@" -export HOSTNAME="@HOSTNAME@" -export ID="@ID@" -export IOSTAT="@IOSTAT@" -export KILL="@KILL@" -export KSH="@KSH@" -export KSTAT="@KSTAT@" -export LOCKFS="@LOCKFS@" -export LOFIADM="@LOFIADM@" -export LOGNAME="@LOGNAME@" -export LS="@LS@" -export LSBLK="@LSBLK@" -export LSMOD="@LSMOD@" -export LSSCSI="@LSSCSI@" -export MD5SUM="@MD5SUM@" -export MKDIR="@MKDIR@" -export MKNOD="@MKNOD@" -export MKTEMP="@MKTEMP@" -export MNTTAB="@MNTTAB@" -export MODINFO="@MODINFO@" -export MODLOAD="@MODLOAD@" -export MODUNLOAD="@MODUNLOAD@" -export MOUNT="@MOUNT@" -export MPSTAT="@MPSTAT@" -export MV="@MV@" -export NAWK="@AWK@" -export NET="@NET@" -export NEWFS="@NEWFS@" -export NPROC="@NPROC@" -export PAGESIZE="@PAGESIZE@" -export PFEXEC="@PFEXEC@" -export PGREP="@PGREP@" -export PING="@PING@" -export PKGINFO="@PKGINFO@" -export PKILL="@PKILL@" -export PRINTF="@PRINTF@" -export PRTVTOC="@PRTVTOC@" -export PS="@PS@" -export PSRINFO="@PSRINFO@" -export PYTHON="@PYTHON@" -export READLINK="@READLINK@" -export REBOOT="@REBOOT@" -export RM="@RM@" -export RMDIR="@RMDIR@" -export RSH="@RSH@" -export SED="@SED@" -export SETFACL="@SETFACL@" -export SHARE="@SHARE@" -export SHUF="@SHUF@" -export SLEEP="@SLEEP@" -export SORT="@SORT@" -export STAT="@STAT@" -export STRINGS="@STRINGS@" -export SU="@SU@" -export SUM="@SUM@" -export SVCADM="@SVCADM@" -export SVCS="@SVCS@" -export SWAP="@SWAP@" -export SWAPADD="@SWAPADD@" -export SYNC="@SYNC@" -export TAIL="@TAIL@" -export TAR="@TAR@" -export TIMEOUT="@TIMEOUT@" -export TOUCH="@TOUCH@" -export TR="@TR@" -export TRUNCATE="@TRUNCATE@" -export TRUE="@TRUE@" -export UDEVADM="@UDEVADM@" -export UFSDUMP="@UFSDUMP@" -export UFSRESTORE="@UFSRESTORE@" -export UMASK="@UMASK@" -export UMOUNT="@UMOUNT@" -export UMOUNTALL="@UMOUNTALL@" -export UNAME="@UNAME@" -export UNCOMPRESS="@UNCOMPRESS@" -export UNIQ="@UNIQ@" -export UNSHARE="@UNSHARE@" -export USERADD="@USERADD@" -export USERDEL="@USERDEL@" -export USERMOD="@USERMOD@" -export UUIDGEN="@UUIDGEN@" -export VMSTAT="@VMSTAT@" -export WAIT="@WAIT@" -export WC="@WC@" -export ZONEADM="@ZONEADM@" -export ZONECFG="@ZONECFG@" -export ZONENAME="@ZONENAME@" diff --git a/tests/zfs-tests/include/default.cfg.in b/tests/zfs-tests/include/default.cfg index 4df1d844a..63104a8b7 100644 --- a/tests/zfs-tests/include/default.cfg.in +++ b/tests/zfs-tests/include/default.cfg @@ -30,35 +30,10 @@ # . $STF_SUITE/include/commands.cfg - -# Common paths -bindir=@bindir@ -sbindir=@sbindir@ -etcdir=@sysconfdir@ - -# ZFS Directories -export ZEDLETDIR=${ZEDLETDIR:-${etcdir}/zfs/zed.d} - -# ZFS Commands -export ZDB=${ZDB:-${sbindir}/zdb} -export ZFS=${ZFS:-${sbindir}/zfs} -export ZHACK=${ZHACK:-${sbindir}/zhack} -export ZINJECT=${ZINJECT:-${sbindir}/zinject} -export ZPOOL=${ZPOOL:-${sbindir}/zpool} -export ZTEST=${ZTEST:-${sbindir}/ztest} -export ZPIOS=${ZPIOS:-${sbindir}/zpios} -export RAIDZ_TEST=${RAIDZ_TEST:-${bindir}/raidz_test} -export ARC_SUMMARY=${ARC_SUMMARY:-${bindir}/arc_summary.py} -export ARCSTAT=${ARCSTAT:-${bindir}/arcstat.py} -export DBUFSTAT=${DBUFSTAT:-${bindir}/dbufstat.py} -export ZED=${ZED:-${sbindir}/zed} - . $STF_SUITE/include/libtest.shlib -# Optionally override the installed ZFS commands to run in-tree -if [[ -f "$SRCDIR/zfs-script-config.sh" ]]; then - . $SRCDIR/zfs-script-config.sh -fi +# ZFS Directories +export ZEDLETDIR=${ZEDLETDIR:-/etc/zfs/zed.d} # Define run length constants export RT_LONG="3" @@ -69,28 +44,6 @@ export RT_SHORT="1" export ZONE_POOL="zonepool" export ZONE_CTR="zonectr" -# Test Suite Specific Commands -helperdir=@datarootdir@/@PACKAGE@/zfs-tests/bin -export CHG_USR_EXEC=${CHG_USR_EXEC:-${helperdir}/chg_usr_exec} -export DEVNAME2DEVID=${DEVNAME2DEVID:-${helperdir}/devname2devid} -export DIR_RD_UPDATE=${DIR_RD_UPDATE:-${helperdir}/dir_rd_update} -export FILE_CHECK=${FILE_CHECK:-${helperdir}/file_check} -export FILE_TRUNC=${FILE_TRUNC:-${helperdir}/file_trunc} -export FILE_WRITE=${FILE_WRITE:-${helperdir}/file_write} -export LARGEST_FILE=${LARGEST_FILE:-${helperdir}/largest_file} -export MKBUSY=${MKBUSY:-${helperdir}/mkbusy} -export MKFILE=${MKFILE:-${helperdir}/mkfile} -export MKFILES=${MKFILES:-${helperdir}/mkfiles} -export MKTREE=${MKTREE:-${helperdir}/mktree} -export MMAP_EXEC=${MMAP_EXEC:-${helperdir}/mmap_exec} -export MMAPWRITE=${MMAPWRITE:-${helperdir}/mmapwrite} -export RANDFREE_FILE=${RANDFREE_FILE:-${helperdir}/randfree_file} -export READMMAP=${READMMAP:-${helperdir}/readmmap} -export RENAME_DIR=${RENAME_DIR:-${helperdir}/rename_dir} -export RM_LNKCNT_ZERO_FILE=${RM_LNKCNT_ZERO_FILE:-${helperdir}/rm_lnkcnt_zero_file} -export THREADSAPPEND=${THREADSAPPEND:-${helperdir}/threadsappend} -export XATTRTEST=${XATTRTEST:-${helperdir}/xattrtest} - # ensure we're running in the C locale, since # localised messages may result in test failures export LC_ALL="C" @@ -181,6 +134,10 @@ export SPA_MINDEVSIZE=$((64 * 1024 * 1024)) # For iscsi target support export ISCSITGTFILE=/tmp/iscsitgt_file export ISCSITGT_FMRI=svc:/system/iscsitgt:default +if ! is_linux; then +export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \ + '{print $3}') +fi # # finally, if we're running in a local zone diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 159b4c79b..4a6a15ec4 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -23,20 +23,28 @@ # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. -# Copyright (c) 2012, 2015 by Delphix. All rights reserved. +# Copyright (c) 2012, 2016 by Delphix. All rights reserved. # Copyright 2016 Nexenta Systems, Inc. # Copyright (c) 2017 Lawrence Livermore National Security, LLC. # . ${STF_TOOLS}/include/logapi.shlib +# +# Apply constrained path when available. This is required since the +# PATH may have been modified by sudo's secure_path behavior. +# +if [ -n "$STF_PATH" ]; then + PATH="$STF_PATH" +fi + # Determine if this is a Linux test system # # Return 0 if platform Linux, 1 if otherwise function is_linux { - if [[ $($UNAME -o) == "GNU/Linux" ]]; then + if [[ $(uname -o) == "GNU/Linux" ]]; then return 0 else return 1 @@ -85,17 +93,17 @@ function ismounted case $fstype in zfs) if [[ "$1" == "/"* ]] ; then - for out in $($ZFS mount | $AWK '{print $2}'); do + for out in $(zfs mount | awk '{print $2}'); do [[ $1 == $out ]] && return 0 done else - for out in $($ZFS mount | $AWK '{print $1}'); do + for out in $(zfs mount | awk '{print $1}'); do [[ $1 == $out ]] && return 0 done fi ;; ufs|nfs) - out=$($DF -F $fstype $1 2>/dev/null) + out=$(df -F $fstype $1 2>/dev/null) ret=$? (($ret != 0)) && return $ret @@ -108,14 +116,14 @@ function ismounted [[ "$1" == "$dir" || "$1" == "$name" ]] && return 0 ;; ext2) - out=$($DF -t $fstype $1 2>/dev/null) + out=$(df -t $fstype $1 2>/dev/null) return $? ;; zvol) if [[ -L "$ZVOL_DEVDIR/$1" ]]; then link=$(readlink -f $ZVOL_DEVDIR/$1) [[ -n "$link" ]] && \ - $MOUNT | $GREP -q "^$link" && \ + mount | grep -q "^$link" && \ return 0 fi ;; @@ -154,7 +162,7 @@ function unmounted function splitline { - $ECHO $1 | $SED "s/,/ /g" + echo $1 | sed "s/,/ /g" } function default_setup @@ -178,38 +186,37 @@ function default_setup_noexit if poolexists $TESTPOOL ; then destroy_pool $TESTPOOL fi - [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL - log_note creating pool $TESTPOOL $disklist - log_must $ZPOOL create -f $TESTPOOL $disklist + [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL + log_must zpool create -f $TESTPOOL $disklist else reexport_pool fi - $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR - $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR + mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR - log_must $ZFS create $TESTPOOL/$TESTFS - log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must zfs create $TESTPOOL/$TESTFS + log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS if [[ -n $container ]]; then - $RM -rf $TESTDIR1 || \ + rm -rf $TESTDIR1 || \ log_unresolved Could not remove $TESTDIR1 - $MKDIR -p $TESTDIR1 || \ + mkdir -p $TESTDIR1 || \ log_unresolved Could not create $TESTDIR1 - log_must $ZFS create $TESTPOOL/$TESTCTR - log_must $ZFS set canmount=off $TESTPOOL/$TESTCTR - log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1 - log_must $ZFS set mountpoint=$TESTDIR1 \ + log_must zfs create $TESTPOOL/$TESTCTR + log_must zfs set canmount=off $TESTPOOL/$TESTCTR + log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1 + log_must zfs set mountpoint=$TESTDIR1 \ $TESTPOOL/$TESTCTR/$TESTFS1 fi if [[ -n $volume ]]; then if is_global_zone ; then - log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL block_device_wait else - log_must $ZFS create $TESTPOOL/$TESTVOL + log_must zfs create $TESTPOOL/$TESTVOL fi fi } @@ -268,7 +275,7 @@ function create_snapshot datasetexists $fs_vol || \ log_fail "$fs_vol must exist." - log_must $ZFS snapshot $fs_vol@$snap + log_must zfs snapshot $fs_vol@$snap } # @@ -287,7 +294,7 @@ function create_clone # snapshot clone [[ -z $clone ]] && \ log_fail "Clone name is undefined." - log_must $ZFS clone $snap $clone + log_must zfs clone $snap $clone } # @@ -316,7 +323,7 @@ function create_bookmark snapexists $fs_vol@$snap || \ log_fail "$fs_vol@$snap must exist." - log_must $ZFS bookmark $fs_vol@$snap $fs_vol#$bkmark + log_must zfs bookmark $fs_vol@$snap $fs_vol#$bkmark } function default_mirror_setup @@ -341,10 +348,10 @@ function default_mirror_setup_noexit log_fail "$func: No parameters passed" [[ -z $secondary ]] && \ log_fail "$func: No secondary partition passed" - [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL - log_must $ZPOOL create -f $TESTPOOL mirror $@ - log_must $ZFS create $TESTPOOL/$TESTFS - log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL + log_must zpool create -f $TESTPOOL mirror $@ + log_must zfs create $TESTPOOL/$TESTFS + log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } # @@ -361,8 +368,8 @@ function setup_mirrors shift while ((nmirrors > 0)); do log_must test -n "$1" -a -n "$2" - [[ -d /$TESTPOOL$nmirrors ]] && $RM -rf /$TESTPOOL$nmirrors - log_must $ZPOOL create -f $TESTPOOL$nmirrors mirror $1 $2 + [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors + log_must zpool create -f $TESTPOOL$nmirrors mirror $1 $2 shift 2 ((nmirrors = nmirrors - 1)) done @@ -382,8 +389,8 @@ function setup_raidzs shift while ((nraidzs > 0)); do log_must test -n "$1" -a -n "$2" - [[ -d /$TESTPOOL$nraidzs ]] && $RM -rf /$TESTPOOL$nraidzs - log_must $ZPOOL create -f $TESTPOOL$nraidzs raidz $1 $2 + [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs + log_must zpool create -f $TESTPOOL$nraidzs raidz $1 $2 shift 2 ((nraidzs = nraidzs - 1)) done @@ -413,10 +420,10 @@ function default_raidz_setup log_fail "A raid-z requires a minimum of two disks." fi - [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL - log_must $ZPOOL create -f $TESTPOOL raidz $1 $2 $3 - log_must $ZFS create $TESTPOOL/$TESTFS - log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL + log_must zpool create -f $TESTPOOL raidz $1 $2 $3 + log_must zfs create $TESTPOOL/$TESTFS + log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_pass } @@ -445,11 +452,10 @@ function default_cleanup_noexit # filesystems it contains. # if is_global_zone; then - $ZFS unmount -a > /dev/null 2>&1 - [[ -z "$KEEP" ]] && KEEP="rpool" - exclude=`eval $ECHO \"'(${KEEP})'\"` - ALL_POOLS=$($ZPOOL list -H -o name \ - | $GREP -v "$NO_POOLS" | $EGREP -vw "$exclude") + zfs unmount -a > /dev/null 2>&1 + exclude=`eval echo \"'(${KEEP})'\"` + ALL_POOLS=$(zpool list -H -o name \ + | grep -v "$NO_POOLS" | egrep -v "$exclude") # Here, we loop through the pools we're allowed to # destroy, only destroying them if it's safe to do # so. @@ -461,57 +467,57 @@ function default_cleanup_noexit then destroy_pool $pool fi - ALL_POOLS=$($ZPOOL list -H -o name \ - | $GREP -v "$NO_POOLS" \ - | $EGREP -v "$exclude") + ALL_POOLS=$(zpool list -H -o name \ + | grep -v "$NO_POOLS" \ + | egrep -v "$exclude") done done - $ZFS mount -a + zfs mount -a else typeset fs="" - for fs in $($ZFS list -H -o name \ - | $GREP "^$ZONE_POOL/$ZONE_CTR[01234]/"); do + for fs in $(zfs list -H -o name \ + | grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do datasetexists $fs && \ - log_must $ZFS destroy -Rf $fs + log_must zfs destroy -Rf $fs done # Need cleanup here to avoid garbage dir left. - for fs in $($ZFS list -H -o name); do + for fs in $(zfs list -H -o name); do [[ $fs == /$ZONE_POOL ]] && continue - [[ -d $fs ]] && log_must $RM -rf $fs/* + [[ -d $fs ]] && log_must rm -rf $fs/* done # # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to # the default value # - for fs in $($ZFS list -H -o name); do + for fs in $(zfs list -H -o name); do if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then - log_must $ZFS set reservation=none $fs - log_must $ZFS set recordsize=128K $fs - log_must $ZFS set mountpoint=/$fs $fs + log_must zfs set reservation=none $fs + log_must zfs set recordsize=128K $fs + log_must zfs set mountpoint=/$fs $fs typeset enc="" enc=$(get_prop encryption $fs) if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \ [[ "$enc" == "off" ]]; then - log_must $ZFS set checksum=on $fs + log_must zfs set checksum=on $fs fi - log_must $ZFS set compression=off $fs - log_must $ZFS set atime=on $fs - log_must $ZFS set devices=off $fs - log_must $ZFS set exec=on $fs - log_must $ZFS set setuid=on $fs - log_must $ZFS set readonly=off $fs - log_must $ZFS set snapdir=hidden $fs - log_must $ZFS set aclmode=groupmask $fs - log_must $ZFS set aclinherit=secure $fs + log_must zfs set compression=off $fs + log_must zfs set atime=on $fs + log_must zfs set devices=off $fs + log_must zfs set exec=on $fs + log_must zfs set setuid=on $fs + log_must zfs set readonly=off $fs + log_must zfs set snapdir=hidden $fs + log_must zfs set aclmode=groupmask $fs + log_must zfs set aclinherit=secure $fs fi done fi [[ -d $TESTDIR ]] && \ - log_must $RM -rf $TESTDIR + log_must rm -rf $TESTDIR disk1=${DISKS%% *} if is_mpath_device $disk1; then @@ -532,16 +538,16 @@ function default_container_cleanup ismounted $TESTPOOL/$TESTCTR/$TESTFS1 [[ $? -eq 0 ]] && \ - log_must $ZFS unmount $TESTPOOL/$TESTCTR/$TESTFS1 + log_must zfs unmount $TESTPOOL/$TESTCTR/$TESTFS1 datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \ - log_must $ZFS destroy -R $TESTPOOL/$TESTCTR/$TESTFS1 + log_must zfs destroy -R $TESTPOOL/$TESTCTR/$TESTFS1 datasetexists $TESTPOOL/$TESTCTR && \ - log_must $ZFS destroy -Rf $TESTPOOL/$TESTCTR + log_must zfs destroy -Rf $TESTPOOL/$TESTCTR [[ -e $TESTDIR1 ]] && \ - log_must $RM -rf $TESTDIR1 > /dev/null 2>&1 + log_must rm -rf $TESTDIR1 > /dev/null 2>&1 default_cleanup } @@ -572,9 +578,9 @@ function destroy_snapshot log_fail "get_prop mountpoint $snap failed." fi - log_must $ZFS destroy $snap + log_must zfs destroy $snap [[ $mtpt != "" && -d $mtpt ]] && \ - log_must $RM -rf $mtpt + log_must rm -rf $mtpt } # @@ -598,9 +604,9 @@ function destroy_clone log_fail "get_prop mountpoint $clone failed." fi - log_must $ZFS destroy $clone + log_must zfs destroy $clone [[ $mtpt != "" && -d $mtpt ]] && \ - log_must $RM -rf $mtpt + log_must rm -rf $mtpt } # @@ -617,7 +623,7 @@ function destroy_bookmark log_fail "'$bkmarkp' does not existed." fi - log_must $ZFS destroy $bkmark + log_must zfs destroy $bkmark } # Return 0 if a snapshot exists; $? otherwise @@ -626,7 +632,7 @@ function destroy_bookmark function snapexists { - $ZFS list -H -t snapshot "$1" > /dev/null 2>&1 + zfs list -H -t snapshot "$1" > /dev/null 2>&1 return $? } @@ -637,7 +643,7 @@ function snapexists # function bkmarkexists { - $ZFS list -H -t bookmark "$1" > /dev/null 2>&1 + zfs list -H -t bookmark "$1" > /dev/null 2>&1 return $? } @@ -662,7 +668,7 @@ function dataset_setprop return 1 fi typeset output= - output=$($ZFS set $2=$3 $1 2>&1) + output=$(zfs set $2=$3 $1 2>&1) typeset rv=$? if ((rv != 0)); then log_note "Setting property on $1 failed." @@ -694,7 +700,7 @@ function dataset_set_defaultproperties typeset confset= typeset -i found=0 - for confset in $($ZFS list); do + for confset in $(zfs list); do if [[ $dataset = $confset ]]; then found=1 break @@ -736,7 +742,7 @@ function zero_partitions #<whole_disk_name> typeset i if is_linux; then - log_must $FORMAT $DEV_DSKDIR/$diskname -s -- mklabel gpt + log_must parted $DEV_DSKDIR/$diskname -s -- mklabel gpt else for i in 0 1 3 4 5 6 7 do @@ -775,10 +781,10 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk # Create GPT partition table when setting slice 0 or # when the device doesn't already contain a GPT label. - $FORMAT $DEV_DSKDIR/$disk -s -- print 1 >/dev/null + parted $DEV_DSKDIR/$disk -s -- print 1 >/dev/null typeset ret_val=$? if [[ $slicenum -eq 0 || $ret_val -ne 0 ]]; then - log_must $FORMAT $DEV_DSKDIR/$disk -s -- mklabel gpt + log_must parted $DEV_DSKDIR/$disk -s -- mklabel gpt fi # When no start is given align on the first cylinder. @@ -789,34 +795,35 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk # Determine the cylinder size for the device and using # that calculate the end offset in cylinders. typeset -i cly_size_kb=0 - cly_size_kb=$($FORMAT -m $DEV_DSKDIR/$disk -s -- \ - unit cyl print | $HEAD -3 | $TAIL -1 | \ - $AWK -F '[:k.]' '{print $4}') + cly_size_kb=$(parted -m $DEV_DSKDIR/$disk -s -- \ + unit cyl print | head -3 | tail -1 | \ + awk -F '[:k.]' '{print $4}') ((end = (size_mb * 1024 / cly_size_kb) + start)) - log_must $FORMAT $DEV_DSKDIR/$disk -s -- \ + log_must parted $DEV_DSKDIR/$disk -s -- \ mkpart part$slicenum ${start}cyl ${end}cyl - $BLOCKDEV --rereadpt $DEV_DSKDIR/$disk 2>/dev/null + blockdev --rereadpt $DEV_DSKDIR/$disk 2>/dev/null block_device_wait else typeset format_file=/var/tmp/format_in.$$ - $ECHO "partition" >$format_file - $ECHO "$slicenum" >> $format_file - $ECHO "" >> $format_file - $ECHO "" >> $format_file - $ECHO "$start" >> $format_file - $ECHO "$size" >> $format_file - $ECHO "label" >> $format_file - $ECHO "" >> $format_file - $ECHO "q" >> $format_file - $ECHO "q" >> $format_file + echo "partition" >$format_file + echo "$slicenum" >> $format_file + echo "" >> $format_file + echo "" >> $format_file + echo "$start" >> $format_file + echo "$size" >> $format_file + echo "label" >> $format_file + echo "" >> $format_file + echo "q" >> $format_file + echo "q" >> $format_file - $FORMAT -e -s -d $disk -f $format_file + format -e -s -d $disk -f $format_file fi + typeset ret_val=$? - $RM -f $format_file + rm -f $format_file [[ $ret_val -ne 0 ]] && \ log_fail "Unable to format $disk slice $slicenum to $size" return 0 @@ -832,7 +839,7 @@ function delete_partitions typeset -i j=1 if [[ -z $DISK_ARRAY_NUM ]]; then - DISK_ARRAY_NUM=$($ECHO ${DISKS} | $NAWK '{print NF}') + DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}') fi if [[ -z $DISKSARRAY ]]; then DISKSARRAY=$DISKS @@ -841,9 +848,10 @@ function delete_partitions if is_linux; then if (( $DISK_ARRAY_NUM == 1 )); then while ((j < MAX_PARTITIONS)); do - $FORMAT $DEV_DSKDIR/$DISK -s rm $j > /dev/null 2>&1 + parted $DEV_DSKDIR/$DISK -s rm $j \ + > /dev/null 2>&1 if (( $? == 1 )); then - $LSBLK | $EGREP ${DISK}${SLICE_PREFIX}${j} > /dev/null + lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null if (( $? == 1 )); then log_note "Partitions for $DISK should be deleted" else @@ -851,7 +859,7 @@ function delete_partitions fi return 0 else - $LSBLK | $EGREP ${DISK}${SLICE_PREFIX}${j} > /dev/null + lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null if (( $? == 0 )); then log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted" fi @@ -859,11 +867,11 @@ function delete_partitions ((j = j+1)) done else - for disk in `$ECHO $DISKSARRAY`; do + for disk in `echo $DISKSARRAY`; do while ((j < MAX_PARTITIONS)); do - $FORMAT $DEV_DSKDIR/$disk -s rm $j > /dev/null 2>&1 + parted $DEV_DSKDIR/$disk -s rm $j > /dev/null 2>&1 if (( $? == 1 )); then - $LSBLK | $EGREP ${disk}${SLICE_PREFIX}${j} > /dev/null + lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null if (( $? == 1 )); then log_note "Partitions for $disk should be deleted" else @@ -871,7 +879,7 @@ function delete_partitions fi j=7 else - $LSBLK | $EGREP ${disk}${SLICE_PREFIX}${j} > /dev/null + lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null if (( $? == 0 )); then log_fail "Partition for ${disk}${SLICE_PREFIX}${j} not deleted" fi @@ -897,10 +905,10 @@ function get_endslice #<disk> <slice> fi if is_linux; then - endcyl=$($FORMAT -s $DEV_DSKDIR/$disk -- unit cyl print | \ - $GREP "part${slice}" | \ - $AWK '{print $3}' | \ - $SED 's,cyl,,') + endcyl=$(parted -s $DEV_DSKDIR/$disk -- unit cyl print | \ + grep "part${slice}" | \ + awk '{print $3}' | \ + sed 's,cyl,,') ((endcyl = (endcyl + 1))) else disk=${disk#/dev/dsk/} @@ -908,20 +916,20 @@ function get_endslice #<disk> <slice> disk=${disk%s*} typeset -i ratio=0 - ratio=$($PRTVTOC /dev/rdsk/${disk}s2 | \ - $GREP "sectors\/cylinder" | \ - $AWK '{print $2}') + ratio=$(prtvtoc /dev/rdsk/${disk}s2 | \ + grep "sectors\/cylinder" | \ + awk '{print $2}') if ((ratio == 0)); then return fi - typeset -i endcyl=$($PRTVTOC -h /dev/rdsk/${disk}s2 | - $NAWK -v token="$slice" '{if ($1==token) print $6}') + typeset -i endcyl=$(prtvtoc -h /dev/rdsk/${disk}s2 | + nawk -v token="$slice" '{if ($1==token) print $6}') ((endcyl = (endcyl + 1) / ratio)) fi - + echo $endcyl } @@ -955,7 +963,7 @@ function partition_disk #<slice_size> <whole_disk_name> <total_slices> # # This function continues to write to a filenum number of files into dirnum -# number of directories until either $FILE_WRITE returns an error or the +# number of directories until either file_write returns an error or the # maximum number of files per directory have been written. # # Usage: @@ -991,13 +999,13 @@ function fill_fs # destdir dirnum filenum bytes num_writes data typeset -i fn=0 typeset -i retval=0 - log_must $MKDIR -p $destdir/$idirnum + log_must mkdir -p $destdir/$idirnum while (($odirnum > 0)); do if ((dirnum >= 0 && idirnum >= dirnum)); then odirnum=0 break fi - $FILE_WRITE -o create -f $destdir/$idirnum/$TESTFILE.$fn \ + file_write -o create -f $destdir/$idirnum/$TESTFILE.$fn \ -b $bytes -c $num_writes -d $data retval=$? if (($retval != 0)); then @@ -1007,7 +1015,7 @@ function fill_fs # destdir dirnum filenum bytes num_writes data if (($fn >= $filenum)); then fn=0 ((idirnum = idirnum + 1)) - log_must $MKDIR -p $destdir/$idirnum + log_must mkdir -p $destdir/$idirnum else ((fn = fn + 1)) fi @@ -1027,14 +1035,14 @@ function get_prop # property dataset typeset prop=$1 typeset dataset=$2 - prop_val=$($ZFS get -pH -o value $prop $dataset 2>/dev/null) + prop_val=$(zfs get -pH -o value $prop $dataset 2>/dev/null) if [[ $? -ne 0 ]]; then log_note "Unable to get $prop property for dataset " \ "$dataset" return 1 fi - $ECHO "$prop_val" + echo "$prop_val" return 0 } @@ -1051,8 +1059,8 @@ function get_pool_prop # property pool typeset pool=$2 if poolexists $pool ; then - prop_val=$($ZPOOL get -pH $prop $pool 2>/dev/null | $TAIL -1 | \ - $AWK '{print $3}') + prop_val=$(zpool get -pH $prop $pool 2>/dev/null | tail -1 | \ + awk '{print $3}') if [[ $? -ne 0 ]]; then log_note "Unable to get $prop property for pool " \ "$pool" @@ -1063,7 +1071,7 @@ function get_pool_prop # property pool return 1 fi - $ECHO "$prop_val" + echo "$prop_val" return 0 } @@ -1080,7 +1088,7 @@ function poolexists return 1 fi - $ZPOOL get name "$pool" > /dev/null 2>&1 + zpool get name "$pool" > /dev/null 2>&1 return $? } @@ -1095,7 +1103,7 @@ function datasetexists fi while (($# > 0)); do - $ZFS get name $1 > /dev/null 2>&1 || \ + zfs get name $1 > /dev/null 2>&1 || \ return $? shift done @@ -1114,7 +1122,7 @@ function datasetnonexists fi while (($# > 0)); do - $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \ + zfs list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \ && return 1 shift done @@ -1147,7 +1155,7 @@ function is_shared fi if is_linux; then - for mtpt in `$SHARE | $AWK '{print $1}'` ; do + for mtpt in `share | awk '{print $1}'` ; do if [[ $mtpt == $fs ]] ; then return 0 fi @@ -1155,13 +1163,13 @@ function is_shared return 1 fi - for mtpt in `$SHARE | $AWK '{print $2}'` ; do + for mtpt in `share | awk '{print $2}'` ; do if [[ $mtpt == $fs ]] ; then return 0 fi done - typeset stat=$($SVCS -H -o STA nfs/server:default) + typeset stat=$(svcs -H -o STA nfs/server:default) if [[ $stat != "ON" ]]; then log_note "Current nfs/server status: $stat" fi @@ -1186,7 +1194,7 @@ function is_shared_smb fi if is_linux; then - for mtpt in `$NET usershare list | $AWK '{print $1}'` ; do + for mtpt in `net usershare list | awk '{print $1}'` ; do if [[ $mtpt == $fs ]] ; then return 0 fi @@ -1241,7 +1249,7 @@ function unshare_fs #fs is_shared $fs || is_shared_smb $fs if (($? == 0)); then - log_must $ZFS unshare $fs + log_must zfs unshare $fs fi return 0 @@ -1257,12 +1265,12 @@ function share_nfs #fs if is_linux; then is_shared $fs if (($? != 0)); then - log_must $SHARE "*:$fs" + log_must share "*:$fs" fi else is_shared $fs if (($? != 0)); then - log_must $SHARE -F nfs $fs + log_must share -F nfs $fs fi fi @@ -1279,12 +1287,12 @@ function unshare_nfs #fs if is_linux; then is_shared $fs if (($? == 0)); then - log_must $UNSHARE -u "*:$fs" + log_must unshare -u "*:$fs" fi else is_shared $fs if (($? == 0)); then - log_must $UNSHARE -F nfs $fs + log_must unshare -F nfs $fs fi fi @@ -1297,9 +1305,9 @@ function unshare_nfs #fs function showshares_nfs { if is_linux; then - $SHARE -v + share -v else - $SHARE -F nfs + share -F nfs fi return 0 @@ -1311,9 +1319,9 @@ function showshares_nfs function showshares_smb { if is_linux; then - $NET usershare list + net usershare list else - $SHARE -F smb + share -F smb fi return 0 @@ -1337,7 +1345,7 @@ function setup_nfs_server fi typeset nfs_fmri="svc:/network/nfs/server:default" - if [[ $($SVCS -Ho STA $nfs_fmri) != "ON" ]]; then + if [[ $(svcs -Ho STA $nfs_fmri) != "ON" ]]; then # # Only really sharing operation can enable NFS server # to online permanently. @@ -1345,11 +1353,11 @@ function setup_nfs_server typeset dummy=/tmp/dummy if [[ -d $dummy ]]; then - log_must $RM -rf $dummy + log_must rm -rf $dummy fi - log_must $MKDIR $dummy - log_must $SHARE $dummy + log_must mkdir $dummy + log_must share $dummy # # Waiting for fmri's status to be the final status. @@ -1358,20 +1366,20 @@ function setup_nfs_server # # Waiting for 1's at least. # - log_must $SLEEP 1 + log_must sleep 1 timeout=10 - while [[ timeout -ne 0 && $($SVCS -Ho STA $nfs_fmri) == *'*' ]] + while [[ timeout -ne 0 && $(svcs -Ho STA $nfs_fmri) == *'*' ]] do - log_must $SLEEP 1 + log_must sleep 1 ((timeout -= 1)) done - log_must $UNSHARE $dummy - log_must $RM -rf $dummy + log_must unshare $dummy + log_must rm -rf $dummy fi - log_note "Current NFS status: '$($SVCS -Ho STA,FMRI $nfs_fmri)'" + log_note "Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'" } # @@ -1381,11 +1389,15 @@ function setup_nfs_server # function is_global_zone { - typeset cur_zone=$($ZONENAME 2>/dev/null) - if [[ $cur_zone != "global" ]]; then - return 1 + if is_linux; then + return 0 + else + typeset cur_zone=$(zonename 2>/dev/null) + if [[ $cur_zone != "global" ]]; then + return 1 + fi + return 0 fi - return 0 } # @@ -1453,8 +1465,8 @@ function create_pool #pool devs_list fi if is_global_zone ; then - [[ -d /$pool ]] && $RM -rf /$pool - log_must $ZPOOL create -f $pool $@ + [[ -d /$pool ]] && rm -rf /$pool + log_must zpool create -f $pool $@ fi return 0 @@ -1487,16 +1499,16 @@ function destroy_pool #pool typeset -i wait_time=10 ret=1 count=0 must="" while [[ $ret -ne 0 ]]; do - $must $ZPOOL destroy -f $pool + $must zpool destroy -f $pool ret=$? [[ $ret -eq 0 ]] && break log_note "zpool destroy failed with $ret" [[ count++ -ge 7 ]] && must=log_must - $SLEEP $wait_time + sleep $wait_time done [[ -d $mtpt ]] && \ - log_must $RM -rf $mtpt + log_must rm -rf $mtpt else log_note "Pool does not exist. ($pool)" return 1 @@ -1527,15 +1539,15 @@ function zfs_zones_setup #zone_name zone_root zone_ip # Create pool and 5 container within it # - [[ -d /$pool_name ]] && $RM -rf /$pool_name - log_must $ZPOOL create -f $pool_name $DISKS + [[ -d /$pool_name ]] && rm -rf /$pool_name + log_must zpool create -f $pool_name $DISKS while ((i < cntctr)); do - log_must $ZFS create $pool_name/$prefix_ctr$i + log_must zfs create $pool_name/$prefix_ctr$i ((i += 1)) done # create a zvol - log_must $ZFS create -V 1g $pool_name/zone_zvol + log_must zfs create -V 1g $pool_name/zone_zvol block_device_wait # @@ -1543,81 +1555,81 @@ function zfs_zones_setup #zone_name zone_root zone_ip # if verify_slog_support ; then typeset sdevs="/var/tmp/sdev1 /var/tmp/sdev2" - log_must $MKFILE $MINVDEVSIZE $sdevs - log_must $ZPOOL add $pool_name log mirror $sdevs + log_must mkfile $MINVDEVSIZE $sdevs + log_must zpool add $pool_name log mirror $sdevs fi # this isn't supported just yet. # Create a filesystem. In order to add this to # the zone, it must have it's mountpoint set to 'legacy' - # log_must $ZFS create $pool_name/zfs_filesystem - # log_must $ZFS set mountpoint=legacy $pool_name/zfs_filesystem + # log_must zfs create $pool_name/zfs_filesystem + # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem [[ -d $zone_root ]] && \ - log_must $RM -rf $zone_root/$zone_name + log_must rm -rf $zone_root/$zone_name [[ ! -d $zone_root ]] && \ - log_must $MKDIR -p -m 0700 $zone_root/$zone_name + log_must mkdir -p -m 0700 $zone_root/$zone_name # Create zone configure file and configure the zone # typeset zone_conf=/tmp/zone_conf.$$ - $ECHO "create" > $zone_conf - $ECHO "set zonepath=$zone_root/$zone_name" >> $zone_conf - $ECHO "set autoboot=true" >> $zone_conf + echo "create" > $zone_conf + echo "set zonepath=$zone_root/$zone_name" >> $zone_conf + echo "set autoboot=true" >> $zone_conf i=0 while ((i < cntctr)); do - $ECHO "add dataset" >> $zone_conf - $ECHO "set name=$pool_name/$prefix_ctr$i" >> \ + echo "add dataset" >> $zone_conf + echo "set name=$pool_name/$prefix_ctr$i" >> \ $zone_conf - $ECHO "end" >> $zone_conf + echo "end" >> $zone_conf ((i += 1)) done # add our zvol to the zone - $ECHO "add device" >> $zone_conf - $ECHO "set match=$ZVOL_DEVDIR/$pool_name/zone_zvol" >> $zone_conf - $ECHO "end" >> $zone_conf + echo "add device" >> $zone_conf + echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf + echo "end" >> $zone_conf # add a corresponding zvol rdsk to the zone - $ECHO "add device" >> $zone_conf - $ECHO "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf - $ECHO "end" >> $zone_conf + echo "add device" >> $zone_conf + echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf + echo "end" >> $zone_conf # once it's supported, we'll add our filesystem to the zone - # $ECHO "add fs" >> $zone_conf - # $ECHO "set type=zfs" >> $zone_conf - # $ECHO "set special=$pool_name/zfs_filesystem" >> $zone_conf - # $ECHO "set dir=/export/zfs_filesystem" >> $zone_conf - # $ECHO "end" >> $zone_conf + # echo "add fs" >> $zone_conf + # echo "set type=zfs" >> $zone_conf + # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf + # echo "set dir=/export/zfs_filesystem" >> $zone_conf + # echo "end" >> $zone_conf - $ECHO "verify" >> $zone_conf - $ECHO "commit" >> $zone_conf - log_must $ZONECFG -z $zone_name -f $zone_conf - log_must $RM -f $zone_conf + echo "verify" >> $zone_conf + echo "commit" >> $zone_conf + log_must zonecfg -z $zone_name -f $zone_conf + log_must rm -f $zone_conf # Install the zone - $ZONEADM -z $zone_name install + zoneadm -z $zone_name install if (($? == 0)); then - log_note "SUCCESS: $ZONEADM -z $zone_name install" + log_note "SUCCESS: zoneadm -z $zone_name install" else - log_fail "FAIL: $ZONEADM -z $zone_name install" + log_fail "FAIL: zoneadm -z $zone_name install" fi # Install sysidcfg file # typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg - $ECHO "system_locale=C" > $sysidcfg - $ECHO "terminal=dtterm" >> $sysidcfg - $ECHO "network_interface=primary {" >> $sysidcfg - $ECHO "hostname=$zone_name" >> $sysidcfg - $ECHO "}" >> $sysidcfg - $ECHO "name_service=NONE" >> $sysidcfg - $ECHO "root_password=mo791xfZ/SFiw" >> $sysidcfg - $ECHO "security_policy=NONE" >> $sysidcfg - $ECHO "timezone=US/Eastern" >> $sysidcfg + echo "system_locale=C" > $sysidcfg + echo "terminal=dtterm" >> $sysidcfg + echo "network_interface=primary {" >> $sysidcfg + echo "hostname=$zone_name" >> $sysidcfg + echo "}" >> $sysidcfg + echo "name_service=NONE" >> $sysidcfg + echo "root_password=mo791xfZ/SFiw" >> $sysidcfg + echo "security_policy=NONE" >> $sysidcfg + echo "timezone=US/Eastern" >> $sysidcfg # Boot this zone - log_must $ZONEADM -z $zone_name boot + log_must zoneadm -z $zone_name boot } # @@ -1632,12 +1644,12 @@ function reexport_pool if ((i == 0)); then TESTPOOL=$ZONE_POOL/$ZONE_CTR$i if ! ismounted $TESTPOOL; then - log_must $ZFS mount $TESTPOOL + log_must zfs mount $TESTPOOL fi else eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i if eval ! ismounted \$TESTPOOL$i; then - log_must eval $ZFS mount \$TESTPOOL$i + log_must eval zfs mount \$TESTPOOL$i fi fi ((i += 1)) @@ -1660,10 +1672,10 @@ function check_state # pool disk state{online,offline,degraded} if [[ -z $disk ]]; then #check pool state only - $ZPOOL get -H -o value health $pool \ + zpool get -H -o value health $pool \ | grep -i "$state" > /dev/null 2>&1 else - $ZPOOL status -v $pool | grep "$disk" \ + zpool status -v $pool | grep "$disk" \ | grep -i "$state" > /dev/null 2>&1 fi @@ -1682,14 +1694,14 @@ function scan_scsi_hosts if is_linux; then if [[ -z $hostnum ]]; then for host in /sys/class/scsi_host/host*; do - log_must eval "$ECHO '- - -' > $host/scan" + log_must eval "echo '- - -' > $host/scan" done else log_must eval \ - "$ECHO /sys/class/scsi_host/host$hostnum/scan" \ + "echo /sys/class/scsi_host/host$hostnum/scan" \ > /dev/null log_must eval \ - "$ECHO '- - -' > /sys/class/scsi_host/host$hostnum/scan" + "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan" fi fi } @@ -1699,8 +1711,8 @@ function scan_scsi_hosts function block_device_wait { if is_linux; then - $UDEVADM trigger - $UDEVADM settle + udevadm trigger + udevadm settle fi } @@ -1722,38 +1734,38 @@ function on_off_disk # disk state{online,offline} host if is_linux; then if [[ $state == "offline" ]] && ( is_mpath_device $disk ); then - dm_name="$($READLINK $DEV_DSKDIR/$disk \ - | $NAWK -F / '{print $2}')" - slave="$($LS /sys/block/${dm_name}/slaves \ - | $NAWK '{print $1}')" + dm_name="$(readlink $DEV_DSKDIR/$disk \ + | nawk -F / '{print $2}')" + slave="$(ls /sys/block/${dm_name}/slaves \ + | nawk '{print $1}')" while [[ -n $slave ]]; do #check if disk is online - $LSSCSI | $EGREP $slave > /dev/null + lsscsi | egrep $slave > /dev/null if (($? == 0)); then slave_dir="/sys/block/${dm_name}" slave_dir+="/slaves/${slave}/device" ss="${slave_dir}/state" sd="${slave_dir}/delete" - log_must eval "$ECHO 'offline' > ${ss}" - log_must eval "$ECHO '1' > ${sd}" - $LSSCSI | $EGREP $slave > /dev/null + log_must eval "echo 'offline' > ${ss}" + log_must eval "echo '1' > ${sd}" + lsscsi | egrep $slave > /dev/null if (($? == 0)); then log_fail "Offlining" \ "$disk failed" fi fi - slave="$($LS /sys/block/$dm_name/slaves \ - 2>/dev/null | $NAWK '{print $1}')" + slave="$(ls /sys/block/$dm_name/slaves \ + 2>/dev/null | nawk '{print $1}')" done elif [[ $state == "offline" ]] && ( is_real_device $disk ); then #check if disk is online - $LSSCSI | $EGREP $disk > /dev/null + lsscsi | egrep $disk > /dev/null if (($? == 0)); then dev_state="/sys/block/$disk/device/state" dev_delete="/sys/block/$disk/device/delete" - log_must eval "$ECHO 'offline' > ${dev_state}" - log_must eval "$ECHO '1' > ${dev_delete}" - $LSSCSI | $EGREP $disk > /dev/null + log_must eval "echo 'offline' > ${dev_state}" + log_must eval "echo '1' > ${dev_delete}" + lsscsi | egrep $disk > /dev/null if (($? == 0)); then log_fail "Offlining $disk" \ "failed" @@ -1766,16 +1778,16 @@ function on_off_disk # disk state{online,offline} host scan_scsi_hosts $host block_device_wait if is_mpath_device $disk; then - dm_name="$($READLINK $DEV_DSKDIR/$disk \ - | $NAWK -F / '{print $2}')" - slave="$($LS /sys/block/$dm_name/slaves \ - | $NAWK '{print $1}')" - $LSSCSI | $EGREP $slave > /dev/null + dm_name="$(readlink $DEV_DSKDIR/$disk \ + | nawk -F / '{print $2}')" + slave="$(ls /sys/block/$dm_name/slaves \ + | nawk '{print $1}')" + lsscsi | egrep $slave > /dev/null if (($? != 0)); then log_fail "Onlining $disk failed" fi elif is_real_device $disk; then - $LSSCSI | $EGREP $disk > /dev/null + lsscsi | egrep $disk > /dev/null if (($? != 0)); then log_fail "Onlining $disk failed" fi @@ -1808,7 +1820,7 @@ function snapshot_mountpoint log_fail "Error name of snapshot '$dataset'." fi - $ECHO $(get_prop mountpoint $fs)/.zfs/snapshot/$snap + echo $(get_prop mountpoint $fs)/.zfs/snapshot/$snap } # @@ -1827,9 +1839,9 @@ function verify_filesys # pool filesystem dir typeset dirs=$@ typeset search_path="" - log_note "Calling $ZDB to verify filesystem '$filesys'" - $ZFS unmount -a > /dev/null 2>&1 - log_must $ZPOOL export $pool + log_note "Calling zdb to verify filesystem '$filesys'" + zfs unmount -a > /dev/null 2>&1 + log_must zpool export $pool if [[ -n $dirs ]] ; then for dir in $dirs ; do @@ -1837,17 +1849,17 @@ function verify_filesys # pool filesystem dir done fi - log_must $ZPOOL import $search_path $pool + log_must zpool import $search_path $pool - $ZDB -cudi $filesys > $zdbout 2>&1 + zdb -cudi $filesys > $zdbout 2>&1 if [[ $? != 0 ]]; then - log_note "Output: $ZDB -cudi $filesys" - $CAT $zdbout - log_fail "$ZDB detected errors with: '$filesys'" + log_note "Output: zdb -cudi $filesys" + cat $zdbout + log_fail "zdb detected errors with: '$filesys'" fi - log_must $ZFS mount -a - log_must $RM -rf $zdbout + log_must zfs mount -a + log_must rm -rf $zdbout } # @@ -1857,11 +1869,11 @@ function get_disklist # pool { typeset disklist="" - disklist=$($ZPOOL iostat -v $1 | $NAWK '(NR >4) {print $1}' | \ - $GREP -v "\-\-\-\-\-" | \ - $EGREP -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$") + disklist=$(zpool iostat -v $1 | nawk '(NR >4) {print $1}' | \ + grep -v "\-\-\-\-\-" | \ + egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$") - $ECHO $disklist + echo $disklist } # @@ -1894,14 +1906,14 @@ function stress_timeout log_note "Waiting for child processes($cpids). " \ "It could last dozens of minutes, please be patient ..." - log_must $SLEEP $TIMEOUT + log_must sleep $TIMEOUT log_note "Killing child processes after ${TIMEOUT} stress timeout." typeset pid for pid in $cpids; do - $PS -p $pid > /dev/null 2>&1 + ps -p $pid > /dev/null 2>&1 if (($? == 0)); then - log_must $KILL -USR1 $pid + log_must kill -USR1 $pid fi done } @@ -1975,9 +1987,9 @@ function check_pool_status # pool token keyword typeset token=$2 typeset keyword=$3 - $ZPOOL status -v "$pool" 2>/dev/null | $NAWK -v token="$token:" ' + zpool status -v "$pool" 2>/dev/null | nawk -v token="$token:" ' ($1==token) {print $0}' \ - | $GREP -i "$keyword" > /dev/null 2>&1 + | grep -i "$keyword" > /dev/null 2>&1 return $? } @@ -2049,17 +2061,17 @@ function verify_rsh_connect #rhost, username { typeset rhost=$1 typeset username=$2 - typeset rsh_cmd="$RSH -n" + typeset rsh_cmd="rsh -n" typeset cur_user= - $GETENT hosts $rhost >/dev/null 2>&1 + getent hosts $rhost >/dev/null 2>&1 if (($? != 0)); then log_note "$rhost cannot be found from" \ "administrative database." return 1 fi - $PING $rhost 3 >/dev/null 2>&1 + ping $rhost 3 >/dev/null 2>&1 if (($? != 0)); then log_note "$rhost is not reachable." return 1 @@ -2069,11 +2081,11 @@ function verify_rsh_connect #rhost, username rsh_cmd="$rsh_cmd -l $username" cur_user="given user \"$username\"" else - cur_user="current user \"`$LOGNAME`\"" + cur_user="current user \"`logname`\"" fi - if ! $rsh_cmd $rhost $TRUE; then - log_note "$RSH to $rhost is not accessible" \ + if ! $rsh_cmd $rhost true; then + log_note "rsh to $rhost is not accessible" \ "with $cur_user." return 1 fi @@ -2130,9 +2142,9 @@ function rsh_status err_file=/tmp/${rhost}.$$.err if ((${#ruser} == 0)); then - rsh_str="$RSH -n" + rsh_str="rsh -n" else - rsh_str="$RSH -n -l $ruser" + rsh_str="rsh -n -l $ruser" fi $rsh_str $rhost /bin/ksh -c "'$cmd_str; \ @@ -2140,16 +2152,16 @@ function rsh_status >/dev/null 2>$err_file ret=$? if (($ret != 0)); then - $CAT $err_file - $RM -f $std_file $err_file - log_fail "$RSH itself failed with exit code $ret..." + cat $err_file + rm -f $std_file $err_file + log_fail "rsh itself failed with exit code $ret..." fi - ret=$($GREP -v 'print -u 2' $err_file | $GREP 'status=' | \ - $CUT -d= -f2) - (($ret != 0)) && $CAT $err_file >&2 + ret=$(grep -v 'print -u 2' $err_file | grep 'status=' | \ + cut -d= -f2) + (($ret != 0)) && cat $err_file >&2 - $RM -f $err_file >/dev/null 2>&1 + rm -f $err_file >/dev/null 2>&1 return $ret } @@ -2162,10 +2174,10 @@ function get_remote_pkgpath typeset rhost=$1 typeset pkgpath="" - pkgpath=$($RSH -n $rhost "$PKGINFO -l SUNWstc-fs-zfs | $GREP BASEDIR: |\ - $CUT -d: -f2") + pkgpath=$(rsh -n $rhost "pkginfo -l SUNWstc-fs-zfs | grep BASEDIR: |\ + cut -d: -f2") - $ECHO $pkgpath + echo $pkgpath } #/** @@ -2182,7 +2194,7 @@ function find_disks { # Trust provided list, no attempt is made to locate unused devices. if is_linux; then - $ECHO "$@" + echo "$@" return fi @@ -2191,15 +2203,15 @@ function find_disks dmpi=/tmp/dumpdev.$$ max_finddisksnum=${MAX_FINDDISKSNUM:-6} - $SWAP -l > $sfi - $DUMPADM > $dmpi 2>/dev/null + swap -l > $sfi + dumpadm > $dmpi 2>/dev/null # write an awk script that can process the output of format # to produce a list of disks we know about. Note that we have # to escape "$2" so that the shell doesn't interpret it while # we're creating the awk script. # ------------------- - $CAT > /tmp/find_disks.awk <<EOF + cat > /tmp/find_disks.awk <<EOF #!/bin/nawk -f BEGIN { FS="."; } @@ -2220,29 +2232,29 @@ function find_disks EOF #--------------------- - $CHMOD 755 /tmp/find_disks.awk - disks=${@:-$($ECHO "" | $FORMAT -e 2>/dev/null | /tmp/find_disks.awk)} - $RM /tmp/find_disks.awk + chmod 755 /tmp/find_disks.awk + disks=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)} + rm /tmp/find_disks.awk unused="" for disk in $disks; do # Check for mounted - $GREP "${disk}[sp]" /etc/mnttab >/dev/null + grep "${disk}[sp]" /etc/mnttab >/dev/null (($? == 0)) && continue # Check for swap - $GREP "${disk}[sp]" $sfi >/dev/null + grep "${disk}[sp]" $sfi >/dev/null (($? == 0)) && continue # check for dump device - $GREP "${disk}[sp]" $dmpi >/dev/null + grep "${disk}[sp]" $dmpi >/dev/null (($? == 0)) && continue # check to see if this disk hasn't been explicitly excluded # by a user-set environment variable - $ECHO "${ZFS_HOST_DEVICES_IGNORE}" | $GREP "${disk}" > /dev/null + echo "${ZFS_HOST_DEVICES_IGNORE}" | grep "${disk}" > /dev/null (($? == 0)) && continue unused_candidates="$unused_candidates $disk" done - $RM $sfi - $RM $dmpi + rm $sfi + rm $dmpi # now just check to see if those disks do actually exist # by looking for a device pointing to the first slice in @@ -2259,7 +2271,7 @@ EOF done # finally, return our disk list - $ECHO $unused + echo $unused } # @@ -2279,14 +2291,17 @@ function add_user #<group_name> <user_name> <basedir> log_fail "group name or user name are not defined." fi - log_must $USERADD -g $gname -d $basedir/$uname -m $uname + log_must useradd -g $gname -d $basedir/$uname -m $uname + echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile + echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile + echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login # Add new users to the same group and the command line utils. # This allows them to be run out of the original users home # directory as long as it permissioned to be group readable. if is_linux; then - cmd_group=$(stat --format="%G" $ZFS) - log_must $USERMOD -a -G $cmd_group $uname + cmd_group=$(stat --format="%G" $(which zfs)) + log_must usermod -a -G $cmd_group $uname fi return 0 @@ -2307,11 +2322,11 @@ function del_user #<logname> <basedir> log_fail "login name is necessary." fi - if $ID $user > /dev/null 2>&1; then - log_must $USERDEL $user + if id $user > /dev/null 2>&1; then + log_must userdel $user fi - [[ -d $basedir/$user ]] && $RM -fr $basedir/$user + [[ -d $basedir/$user ]] && rm -fr $basedir/$user return 0 } @@ -2333,7 +2348,7 @@ function add_group #<group_name> # Linux because for many distributions 1000 and under are reserved. if is_linux; then while true; do - $GROUPADD $group > /dev/null 2>&1 + groupadd $group > /dev/null 2>&1 typeset -i ret=$? case $ret in 0) return 0 ;; @@ -2342,9 +2357,8 @@ function add_group #<group_name> done else typeset -i gid=100 - while true; do - $GROUPADD -g $gid $group > /dev/null 2>&1 + groupadd -g $gid $group > /dev/null 2>&1 typeset -i ret=$? case $ret in 0) return 0 ;; @@ -2369,23 +2383,23 @@ function del_group #<group_name> fi if is_linux; then - $GETENT group $grp > /dev/null 2>&1 + getent group $grp > /dev/null 2>&1 typeset -i ret=$? case $ret in # Group does not exist. 2) return 0 ;; # Name already exists as a group name - 0) log_must $GROUPDEL $grp ;; + 0) log_must groupdel $grp ;; *) return 1 ;; esac else - $GROUPMOD -n $grp $grp > /dev/null 2>&1 + groupmod -n $grp $grp > /dev/null 2>&1 typeset -i ret=$? case $ret in # Group does not exist. 6) return 0 ;; # Name already exists as a group name - 9) log_must $GROUPDEL $grp ;; + 9) log_must groupdel $grp ;; *) return 1 ;; esac fi @@ -2408,29 +2422,29 @@ function safe_to_destroy_pool { # $1 the pool name # by looking at all other pools, ensuring that they # aren't built from files or zvols contained in this pool. - for pool in $($ZPOOL list -H -o name) + for pool in $(zpool list -H -o name) do ALTMOUNTPOOL="" # this is a list of the top-level directories in each of the # files that make up the path to the files the pool is based on - FILEPOOL=$($ZPOOL status -v $pool | $GREP /$1/ | \ - $AWK '{print $1}') + FILEPOOL=$(zpool status -v $pool | grep /$1/ | \ + awk '{print $1}') # this is a list of the zvols that make up the pool - ZVOLPOOL=$($ZPOOL status -v $pool | $GREP "$ZVOL_DEVDIR/$1$" \ - | $AWK '{print $1}') + ZVOLPOOL=$(zpool status -v $pool | grep "$ZVOL_DEVDIR/$1$" \ + | awk '{print $1}') # also want to determine if it's a file-based pool using an # alternate mountpoint... - POOL_FILE_DIRS=$($ZPOOL status -v $pool | \ - $GREP / | $AWK '{print $1}' | \ - $AWK -F/ '{print $2}' | $GREP -v "dev") + POOL_FILE_DIRS=$(zpool status -v $pool | \ + grep / | awk '{print $1}' | \ + awk -F/ '{print $2}' | grep -v "dev") for pooldir in $POOL_FILE_DIRS do - OUTPUT=$($ZFS list -H -r -o mountpoint $1 | \ - $GREP "${pooldir}$" | $AWK '{print $1}') + OUTPUT=$(zfs list -H -r -o mountpoint $1 | \ + grep "${pooldir}$" | awk '{print $1}') ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}" done @@ -2480,11 +2494,11 @@ function get_compress_opts COMPRESS_OPTS="on off lzjb" fi typeset valid_opts="$COMPRESS_OPTS" - $ZFS get 2>&1 | $GREP gzip >/dev/null 2>&1 + zfs get 2>&1 | grep gzip >/dev/null 2>&1 if [[ $? -eq 0 ]]; then valid_opts="$valid_opts $GZIP_OPTS" fi - $ECHO "$valid_opts" + echo "$valid_opts" } # @@ -2537,15 +2551,15 @@ function verify_opt_p_ops # make sure the upper level filesystem does not exist if datasetexists ${newdataset%/*} ; then - log_must $ZFS destroy -rRf ${newdataset%/*} + log_must zfs destroy -rRf ${newdataset%/*} fi # without -p option, operation will fail - log_mustnot $ZFS $ops $dataset $newdataset + log_mustnot zfs $ops $dataset $newdataset log_mustnot datasetexists $newdataset ${newdataset%/*} # with -p option, operation should succeed - log_must $ZFS $ops -p $dataset $newdataset + log_must zfs $ops -p $dataset $newdataset block_device_wait if ! datasetexists $newdataset ; then @@ -2554,7 +2568,7 @@ function verify_opt_p_ops # when $ops is create or clone, redo the operation still return zero if [[ $ops != "rename" ]]; then - log_must $ZFS $ops -p $dataset $newdataset + log_must zfs $ops -p $dataset $newdataset fi return 0 @@ -2574,12 +2588,12 @@ function get_config if ! poolexists "$pool" ; then return 1 fi - alt_root=$($ZPOOL list -H $pool | $AWK '{print $NF}') + alt_root=$(zpool list -H $pool | awk '{print $NF}') if [[ $alt_root == "-" ]]; then - value=$($ZDB -C $pool | $GREP "$config:" | $AWK -F: \ + value=$(zdb -C $pool | grep "$config:" | awk -F: \ '{print $2}') else - value=$($ZDB -e $pool | $GREP "$config:" | $AWK -F: \ + value=$(zdb -e $pool | grep "$config:" | awk -F: \ '{print $2}') fi if [[ -n $value ]] ; then @@ -2606,8 +2620,8 @@ function _random_get typeset -i ind ((ind = RANDOM % cnt + 1)) - typeset ret=$($ECHO "$str" | $CUT -f $ind -d ' ') - $ECHO $ret + typeset ret=$(echo "$str" | cut -f $ind -d ' ') + echo $ret } # @@ -2639,14 +2653,14 @@ function verify_slog_support typeset vdev=$dir/a typeset sdev=$dir/b - $MKDIR -p $dir - $MKFILE $MINVDEVSIZE $vdev $sdev + mkdir -p $dir + mkfile $MINVDEVSIZE $vdev $sdev typeset -i ret=0 - if ! $ZPOOL create -n $pool $vdev log $sdev > /dev/null 2>&1; then + if ! zpool create -n $pool $vdev log $sdev > /dev/null 2>&1; then ret=1 fi - $RM -r $dir + rm -r $dir return $ret } @@ -2675,7 +2689,7 @@ function gen_dataset_name ((iter -= 1)) done - $ECHO $l_name + echo $l_name } # @@ -2690,10 +2704,10 @@ function gen_dataset_name function datasetcksum { typeset cksum - $SYNC - cksum=$($ZDB -vvv $1 | $GREP "^Dataset $1 \[" | $GREP "cksum" \ - | $AWK -F= '{print $7}') - $ECHO $cksum + sync + cksum=$(zdb -vvv $1 | grep "^Dataset $1 \[" | grep "cksum" \ + | awk -F= '{print $7}') + echo $cksum } # @@ -2703,8 +2717,8 @@ function datasetcksum function checksum { typeset cksum - cksum=$($CKSUM $1 | $AWK '{print $1}') - $ECHO $cksum + cksum=$(cksum $1 | awk '{print $1}') + echo $cksum } # @@ -2716,8 +2730,8 @@ function get_device_state #pool disk field("", "spares","logs") typeset disk=${2#$DEV_DSKDIR/} typeset field=${3:-$pool} - state=$($ZPOOL status -v "$pool" 2>/dev/null | \ - $NAWK -v device=$disk -v pool=$pool -v field=$field \ + state=$(zpool status -v "$pool" 2>/dev/null | \ + nawk -v device=$disk -v pool=$pool -v field=$field \ 'BEGIN {startconfig=0; startfield=0; } /config:/ {startconfig=1} (startconfig==1) && ($1==field) {startfield=1; next;} @@ -2745,7 +2759,7 @@ function get_fstype # $ df -n / # / : ufs # - $DF -n $dir | $AWK '{print $3}' + df -n $dir | awk '{print $3}' } # @@ -2759,7 +2773,7 @@ function labelvtoc log_fail "The disk name is unspecified." fi typeset label_file=/var/tmp/labelvtoc.$$ - typeset arch=$($UNAME -p) + typeset arch=$(uname -p) if is_linux; then log_note "Currently unsupported by the test framework" @@ -2767,33 +2781,33 @@ function labelvtoc fi if [[ $arch == "i386" ]]; then - $ECHO "label" > $label_file - $ECHO "0" >> $label_file - $ECHO "" >> $label_file - $ECHO "q" >> $label_file - $ECHO "q" >> $label_file + echo "label" > $label_file + echo "0" >> $label_file + echo "" >> $label_file + echo "q" >> $label_file + echo "q" >> $label_file - $FDISK -B $disk >/dev/null 2>&1 + fdisk -B $disk >/dev/null 2>&1 # wait a while for fdisk finishes - $SLEEP 60 + sleep 60 elif [[ $arch == "sparc" ]]; then - $ECHO "label" > $label_file - $ECHO "0" >> $label_file - $ECHO "" >> $label_file - $ECHO "" >> $label_file - $ECHO "" >> $label_file - $ECHO "q" >> $label_file + echo "label" > $label_file + echo "0" >> $label_file + echo "" >> $label_file + echo "" >> $label_file + echo "" >> $label_file + echo "q" >> $label_file else log_fail "unknown arch type" fi - $FORMAT -e -s -d $disk -f $label_file + format -e -s -d $disk -f $label_file typeset -i ret_val=$? - $RM -f $label_file + rm -f $label_file # # wait the format to finish # - $SLEEP 60 + sleep 60 if ((ret_val != 0)); then log_fail "unable to label $disk as VTOC." fi @@ -2807,7 +2821,7 @@ function labelvtoc # function is_zfsroot { - $DF -n / | $GREP zfs > /dev/null 2>&1 + df -n / | grep zfs > /dev/null 2>&1 return $? } @@ -2818,14 +2832,14 @@ function is_zfsroot function get_rootfs { typeset rootfs="" - rootfs=$($AWK '{if ($2 == "/" && $3 == "zfs") print $1}' \ + rootfs=$(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \ /etc/mnttab) if [[ -z "$rootfs" ]]; then log_fail "Can not get rootfs" fi - $ZFS list $rootfs > /dev/null 2>&1 + zfs list $rootfs > /dev/null 2>&1 if (($? == 0)); then - $ECHO $rootfs + echo $rootfs else log_fail "This is not a zfsroot system." fi @@ -2840,15 +2854,15 @@ function get_rootpool { typeset rootfs="" typeset rootpool="" - rootfs=$($AWK '{if ($2 == "/" && $3 =="zfs") print $1}' \ + rootfs=$(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \ /etc/mnttab) if [[ -z "$rootfs" ]]; then log_fail "Can not get rootpool" fi - $ZFS list $rootfs > /dev/null 2>&1 + zfs list $rootfs > /dev/null 2>&1 if (($? == 0)); then - rootpool=`$ECHO $rootfs | awk -F\/ '{print $1}'` - $ECHO $rootpool + rootpool=`echo $rootfs | awk -F\/ '{print $1}'` + echo $rootpool else log_fail "This is not a zfsroot system." fi @@ -2867,7 +2881,7 @@ function is_physical_device #device [[ -f /sys/module/loop/parameters/max_part ]] return $? else - $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 + echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 return $? fi } @@ -2881,8 +2895,8 @@ function is_real_device #disk [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then - ($LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP disk > /dev/null) \ - 2>/dev/null + lsblk $DEV_RDSKDIR/$disk -o TYPE 2>/dev/null | \ + egrep disk >/dev/null return $? fi } @@ -2896,8 +2910,8 @@ function is_loop_device #disk [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then - ($LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP loop > /dev/null) \ - 2>/dev/null + lsblk $DEV_RDSKDIR/$disk -o TYPE 2>/dev/null | \ + egrep loop >/dev/null return $? fi } @@ -2913,10 +2927,10 @@ function is_mpath_device #disk [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then - ($LSBLK $DEV_MPATHDIR/$disk -o TYPE | $EGREP mpath >/dev/null) \ - 2>/dev/null + lsblk $DEV_MPATHDIR/$disk -o TYPE 2>/dev/null | \ + egrep mpath >/dev/null if (($? == 0)); then - $READLINK $DEV_MPATHDIR/$disk > /dev/null 2>&1 + readlink $DEV_MPATHDIR/$disk > /dev/null 2>&1 return $? else return $? @@ -2936,10 +2950,9 @@ function set_slice_prefix if is_linux; then while (( i < $DISK_ARRAY_NUM )); do - disk="$($ECHO $DISKS | $NAWK '{print $(i + 1)}')" - if ( is_mpath_device $disk ) && [[ -z $($ECHO $disk \ - | awk 'substr($1,18,1) ~ /^[[:digit:]]+$/') ]] || \ - ( is_real_device $disk ); then + disk="$(echo $DISKS | nawk '{print $(i + 1)}')" + if ( is_mpath_device $disk ) && [[ -z $(echo $disk | awk 'substr($1,18,1)\ + ~ /^[[:digit:]]+$/') ]] || ( is_real_device $disk ); then export SLICE_PREFIX="" return 0 elif ( is_mpath_device $disk || is_loop_device \ @@ -2969,7 +2982,7 @@ function set_device_dir if is_linux; then while (( i < $DISK_ARRAY_NUM )); do - disk="$($ECHO $DISKS | $NAWK '{print $(i + 1)}')" + disk="$(echo $DISKS | nawk '{print $(i + 1)}')" if is_mpath_device $disk; then export DEV_DSKDIR=$DEV_MPATHDIR return 0 @@ -2998,9 +3011,9 @@ function get_device_dir #device if [[ -b "$DEV_DSKDIR/$device" ]]; then device="$DEV_DSKDIR" fi - $ECHO $device + echo $device else - $ECHO "$DEV_DSKDIR" + echo "$DEV_DSKDIR" fi } @@ -3014,21 +3027,21 @@ function get_persistent_disk_name #device if is_linux; then if is_real_device $device; then - dev_id="$($UDEVADM info -q all -n $DEV_DSKDIR/$device \ - | $EGREP disk/by-id | $NAWK '{print $2; exit}' \ - | $NAWK -F / '{print $3}')" - $ECHO $dev_id + dev_id="$(udevadm info -q all -n $DEV_DSKDIR/$device \ + | egrep disk/by-id | nawk '{print $2; exit}' \ + | nawk -F / '{print $3}')" + echo $dev_id elif is_mpath_device $device; then - dev_id="$($UDEVADM info -q all -n $DEV_DSKDIR/$device \ - | $EGREP disk/by-id/dm-uuid \ - | $NAWK '{print $2; exit}' \ - | $NAWK -F / '{print $3}')" - $ECHO $dev_id + dev_id="$(udevadm info -q all -n $DEV_DSKDIR/$device \ + | egrep disk/by-id/dm-uuid \ + | nawk '{print $2; exit}' \ + | nawk -F / '{print $3}')" + echo $dev_id else - $ECHO $device + echo $device fi else - $ECHO $device + echo $device fi } @@ -3046,19 +3059,19 @@ function load_scsi_debug # dev_size_mb add_host num_tgts max_luns [[ -z $luns ]] && log_fail "Arguments invalid or missing" if is_linux; then - $MODLOAD -n scsi_debug + modprobe -n scsi_debug if (($? != 0)); then log_unsupported "Platform does not have scsi_debug" "module" fi - $LSMOD | $EGREP scsi_debug > /dev/zero + lsmod | egrep scsi_debug > /dev/null if (($? == 0)); then log_fail "scsi_debug module already installed" else - log_must $MODLOAD scsi_debug dev_size_mb=$devsize \ + log_must modprobe scsi_debug dev_size_mb=$devsize \ add_host=$hosts num_tgts=$tgts max_luns=$luns block_device_wait - $LSSCSI | $EGREP scsi_debug > /dev/null + lsscsi | egrep scsi_debug > /dev/null if (($? == 1)); then log_fail "scsi_debug module install failed" fi @@ -3081,7 +3094,7 @@ function get_package_name # function get_word_count { - $ECHO $1 | $WC -w + echo $1 | wc -w } # @@ -3125,7 +3138,7 @@ function ds_is_snapshot # function is_te_enabled { - $SVCS -H -o state labeld 2>/dev/null | $GREP "enabled" + svcs -H -o state labeld 2>/dev/null | grep "enabled" if (($? != 0)); then return 1 else @@ -3137,9 +3150,9 @@ function is_te_enabled function is_mp { if is_linux; then - (($($NPROC) > 1)) + (($(nproc) > 1)) else - (($($PSRINFO | $WC -l) > 1)) + (($(psrinfo | wc -l) > 1)) fi return $? @@ -3148,9 +3161,9 @@ function is_mp function get_cpu_freq { if is_linux; then - lscpu | $AWK '/CPU MHz/ { print $3 }' + lscpu | awk '/CPU MHz/ { print $3 }' else - $PSRINFO -v 0 | $AWK '/processor operates at/ {print $6}' + psrinfo -v 0 | awk '/processor operates at/ {print $6}' fi } @@ -3161,7 +3174,7 @@ function user_run shift log_note "user:$user $@" - eval \$SU \$user -c \"$@\" > /tmp/out 2>/tmp/err + eval su - \$user -c \"$@\" > /tmp/out 2>/tmp/err return $? } @@ -3186,14 +3199,14 @@ function vdevs_in_pool shift - typeset tmpfile=$($MKTEMP) - $ZPOOL list -Hv "$pool" >$tmpfile + typeset tmpfile=$(mktemp) + zpool list -Hv "$pool" >$tmpfile for vdev in $@; do - $GREP -w ${vdev##*/} $tmpfile >/dev/null 2>&1 + grep -w ${vdev##*/} $tmpfile >/dev/null 2>&1 [[ $? -ne 0 ]] && return 1 done - $RM -f $tmpfile + rm -f $tmpfile return 0; } @@ -3232,19 +3245,19 @@ function sync_pool #pool typeset pool=${1:-$TESTPOOL} log_must $SYNC - log_must $SLEEP 2 + log_must sleep 2 # Flush all the pool data. typeset -i ret - $ZPOOL scrub $pool >/dev/null 2>&1 + zpool scrub $pool >/dev/null 2>&1 ret=$? (( $ret != 0 )) && \ - log_fail "$ZPOOL scrub $pool failed." + log_fail "zpool scrub $pool failed." while ! is_pool_scrubbed $pool; do if is_pool_resilvered $pool ; then log_fail "$pool should not be resilver completed." fi - log_must $SLEEP 2 + log_must sleep 2 done } @@ -3257,8 +3270,8 @@ function wait_freeing #pool { typeset pool=${1:-$TESTPOOL} while true; do - [[ "0" == "$($ZPOOL list -Ho freeing $pool)" ]] && break - log_must $SLEEP 1 + [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break + log_must sleep 1 done } @@ -3270,21 +3283,22 @@ function zed_start if is_linux; then # ZEDLET_DIR=/var/tmp/zed if [[ ! -d $ZEDLET_DIR ]]; then - log_must $MKDIR $ZEDLET_DIR + log_must mkdir $ZEDLET_DIR fi # Verify the ZED is not already running. - $PGREP -x zed > /dev/null + pgrep -x zed > /dev/null if (($? == 0)); then log_fail "ZED already running" fi - log_must $CP ${ZEDLETDIR}/all-syslog.sh $ZEDLET_DIR + # ZEDLETDIR=</etc/zfs/zed.d | ${SRCDIR}/cmd/zed/zed.d> + log_must cp ${ZEDLETDIR}/all-syslog.sh $ZEDLET_DIR log_note "Starting ZED" # run ZED in the background and redirect foreground logging # output to zedlog - log_must eval "$ZED -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \ + log_must eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \ "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &" fi } @@ -3296,14 +3310,13 @@ function zed_stop { if is_linux; then if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then - zedpid=$($CAT ${ZEDLET_DIR}/zed.pid) - log_must $KILL $zedpid + zedpid=$(cat ${ZEDLET_DIR}/zed.pid) + log_must kill $zedpid fi - log_must $RM -f ${ZEDLET_DIR}/all-syslog.sh - log_must $RM -f ${ZEDLET_DIR}/zed.pid - log_must $RM -f ${ZEDLET_DIR}/zedlog - log_must $RM -f ${ZEDLET_DIR}/state - log_must $RMDIR $ZEDLET_DIR - + log_must rm -f ${ZEDLET_DIR}/all-syslog.sh + log_must rm -f ${ZEDLET_DIR}/zed.pid + log_must rm -f ${ZEDLET_DIR}/zedlog + log_must rm -f ${ZEDLET_DIR}/state + log_must rmdir $ZEDLET_DIR fi } diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib index 38479d352..ca1cbcb4e 100644 --- a/tests/zfs-tests/include/math.shlib +++ b/tests/zfs-tests/include/math.shlib @@ -10,7 +10,7 @@ # # -# Copyright (c) 2012 by Delphix. All rights reserved. +# Copyright (c) 2012, 2016 by Delphix. All rights reserved. # # @@ -30,14 +30,14 @@ function within_percent typeset percent=$3 # Set $a or $b to $2 such that a >= b - [[ '1' = $($ECHO "if ($2 > $a) 1" | $BC) ]] && a=$2 || b=$2 + [[ '1' = $(echo "if ($2 > $a) 1" | bc) ]] && a=$2 || b=$2 # Prevent division by 0 [[ $a =~ [1-9] ]] || return 1 - typeset p=$($ECHO "scale=2; $b * 100 / $a" | $BC) + typeset p=$(echo "scale=2; $b * 100 / $a" | bc) log_note "Comparing $a and $b given $percent% (calculated: $p%)" - [[ '1' = $($ECHO "scale=2; if ($p >= $percent) 1" | $BC) ]] && return 0 + [[ '1' = $(echo "scale=2; if ($p >= $percent) 1" | bc) ]] && return 0 return 1 } diff --git a/tests/zfs-tests/include/properties.shlib b/tests/zfs-tests/include/properties.shlib index c495eecb4..8817b6f2c 100644 --- a/tests/zfs-tests/include/properties.shlib +++ b/tests/zfs-tests/include/properties.shlib @@ -10,7 +10,7 @@ # # -# Copyright (c) 2012 by Delphix. All rights reserved. +# Copyright (c) 2012, 2016 by Delphix. All rights reserved. # typeset -a compress_props=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2' 'gzip-3' @@ -37,7 +37,7 @@ function get_rand_prop typeset prop_max=$((${#prop_array[@]} - 1)) typeset -i i - for i in $($SHUF -i $start-$prop_max -n $num_props); do + for i in $(shuf -i $start-$prop_max -n $num_props); do retstr="${prop_array[$i]} $retstr" done echo $retstr |