Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/test/zfs-tests/include/libtest.shlib
          +++ new/usr/src/test/zfs-tests/include/libtest.shlib
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15  # If applicable, add the following below this CDDL HEADER, with the
  16   16  # fields enclosed by brackets "[]" replaced with your own identifying
  17   17  # information: Portions Copyright [yyyy] [name of copyright owner]
  18   18  #
  19   19  # CDDL HEADER END
  20   20  #
  21   21  
  22   22  #
  23   23  # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24  # Use is subject to license terms.
  25      -# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
       25 +# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  26   26  # Copyright 2016 Nexenta Systems, Inc.
  27   27  #
  28   28  
  29   29  . ${STF_TOOLS}/contrib/include/logapi.shlib
  30   30  
  31   31  ZFS=${ZFS:-/usr/sbin/zfs}
  32   32  ZPOOL=${ZPOOL:-/usr/sbin/zpool}
  33   33  
  34   34  # Determine whether a dataset is mounted
  35   35  #
↓ open down ↓ 4 lines elided ↑ open up ↑
  40   40  
  41   41  function ismounted
  42   42  {
  43   43          typeset fstype=$2
  44   44          [[ -z $fstype ]] && fstype=zfs
  45   45          typeset out dir name ret
  46   46  
  47   47          case $fstype in
  48   48                  zfs)
  49   49                          if [[ "$1" == "/"* ]] ; then
  50      -                                for out in $($ZFS mount | $AWK '{print $2}'); do
       50 +                                for out in $(zfs mount | awk '{print $2}'); do
  51   51                                          [[ $1 == $out ]] && return 0
  52   52                                  done
  53   53                          else
  54      -                                for out in $($ZFS mount | $AWK '{print $1}'); do
       54 +                                for out in $(zfs mount | awk '{print $1}'); do
  55   55                                          [[ $1 == $out ]] && return 0
  56   56                                  done
  57   57                          fi
  58   58                  ;;
  59   59                  ufs|nfs)
  60      -                        out=$($DF -F $fstype $1 2>/dev/null)
       60 +                        out=$(df -F $fstype $1 2>/dev/null)
  61   61                          ret=$?
  62   62                          (($ret != 0)) && return $ret
  63   63  
  64   64                          dir=${out%%\(*}
  65   65                          dir=${dir%% *}
  66   66                          name=${out##*\(}
  67   67                          name=${name%%\)*}
  68   68                          name=${name%% *}
  69   69  
  70   70                          [[ "$1" == "$dir" || "$1" == "$name" ]] && return 0
↓ open down ↓ 26 lines elided ↑ open up ↑
  97   97          (($? == 1)) && return 0
  98   98          return 1
  99   99  }
 100  100  
 101  101  # split line on ","
 102  102  #
 103  103  # $1 - line to split
 104  104  
 105  105  function splitline
 106  106  {
 107      -        $ECHO $1 | $SED "s/,/ /g"
      107 +        echo $1 | sed "s/,/ /g"
 108  108  }
 109  109  
 110  110  function default_setup
 111  111  {
 112  112          default_setup_noexit "$@"
 113  113  
 114  114          log_pass
 115  115  }
 116  116  
 117  117  #
↓ open down ↓ 2 lines elided ↑ open up ↑
 120  120  function default_setup_noexit
 121  121  {
 122  122          typeset disklist=$1
 123  123          typeset container=$2
 124  124          typeset volume=$3
 125  125  
 126  126          if is_global_zone; then
 127  127                  if poolexists $TESTPOOL ; then
 128  128                          destroy_pool $TESTPOOL
 129  129                  fi
 130      -                [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
 131      -                log_must $ZPOOL create -f $TESTPOOL $disklist
      130 +                [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
      131 +                log_must zpool create -f $TESTPOOL $disklist
 132  132          else
 133  133                  reexport_pool
 134  134          fi
 135  135  
 136      -        $RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
 137      -        $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
      136 +        rm -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
      137 +        mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
 138  138  
 139      -        log_must $ZFS create $TESTPOOL/$TESTFS
 140      -        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
      139 +        log_must zfs create $TESTPOOL/$TESTFS
      140 +        log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
 141  141  
 142  142          if [[ -n $container ]]; then
 143      -                $RM -rf $TESTDIR1  || \
      143 +                rm -rf $TESTDIR1  || \
 144  144                          log_unresolved Could not remove $TESTDIR1
 145      -                $MKDIR -p $TESTDIR1 || \
      145 +                mkdir -p $TESTDIR1 || \
 146  146                          log_unresolved Could not create $TESTDIR1
 147  147  
 148      -                log_must $ZFS create $TESTPOOL/$TESTCTR
 149      -                log_must $ZFS set canmount=off $TESTPOOL/$TESTCTR
 150      -                log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1
 151      -                log_must $ZFS set mountpoint=$TESTDIR1 \
      148 +                log_must zfs create $TESTPOOL/$TESTCTR
      149 +                log_must zfs set canmount=off $TESTPOOL/$TESTCTR
      150 +                log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1
      151 +                log_must zfs set mountpoint=$TESTDIR1 \
 152  152                      $TESTPOOL/$TESTCTR/$TESTFS1
 153  153          fi
 154  154  
 155  155          if [[ -n $volume ]]; then
 156  156                  if is_global_zone ; then
 157      -                        log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
      157 +                        log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
 158  158                  else
 159      -                        log_must $ZFS create $TESTPOOL/$TESTVOL
      159 +                        log_must zfs create $TESTPOOL/$TESTVOL
 160  160                  fi
 161  161          fi
 162  162  }
 163  163  
 164  164  #
 165  165  # Given a list of disks, setup a storage pool, file system and
 166  166  # a container.
 167  167  #
 168  168  function default_container_setup
 169  169  {
↓ open down ↓ 38 lines elided ↑ open up ↑
 208  208  
 209  209          [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
 210  210          [[ -z $snap ]] && log_fail "Snapshot's name is undefined."
 211  211  
 212  212          if snapexists $fs_vol@$snap; then
 213  213                  log_fail "$fs_vol@$snap already exists."
 214  214          fi
 215  215          datasetexists $fs_vol || \
 216  216                  log_fail "$fs_vol must exist."
 217  217  
 218      -        log_must $ZFS snapshot $fs_vol@$snap
      218 +        log_must zfs snapshot $fs_vol@$snap
 219  219  }
 220  220  
 221  221  #
 222  222  # Create a clone from a snapshot, default clone name is $TESTCLONE.
 223  223  #
 224  224  # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
 225  225  # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
 226  226  #
 227  227  function create_clone   # snapshot clone
 228  228  {
 229  229          typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
 230  230          typeset clone=${2:-$TESTPOOL/$TESTCLONE}
 231  231  
 232  232          [[ -z $snap ]] && \
 233  233                  log_fail "Snapshot name is undefined."
 234  234          [[ -z $clone ]] && \
 235  235                  log_fail "Clone name is undefined."
 236  236  
 237      -        log_must $ZFS clone $snap $clone
      237 +        log_must zfs clone $snap $clone
 238  238  }
 239  239  
 240  240  function default_mirror_setup
 241  241  {
 242  242          default_mirror_setup_noexit $1 $2 $3
 243  243  
 244  244          log_pass
 245  245  }
 246  246  
 247  247  #
↓ open down ↓ 4 lines elided ↑ open up ↑
 252  252  function default_mirror_setup_noexit
 253  253  {
 254  254          readonly func="default_mirror_setup_noexit"
 255  255          typeset primary=$1
 256  256          typeset secondary=$2
 257  257  
 258  258          [[ -z $primary ]] && \
 259  259                  log_fail "$func: No parameters passed"
 260  260          [[ -z $secondary ]] && \
 261  261                  log_fail "$func: No secondary partition passed"
 262      -        [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
 263      -        log_must $ZPOOL create -f $TESTPOOL mirror $@
 264      -        log_must $ZFS create $TESTPOOL/$TESTFS
 265      -        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
      262 +        [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
      263 +        log_must zpool create -f $TESTPOOL mirror $@
      264 +        log_must zfs create $TESTPOOL/$TESTFS
      265 +        log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
 266  266  }
 267  267  
 268  268  #
 269  269  # create a number of mirrors.
 270  270  # We create a number($1) of 2 way mirrors using the pairs of disks named
 271  271  # on the command line. These mirrors are *not* mounted
 272  272  # @parameters: $1 the number of mirrors to create
 273  273  #  $... the devices to use to create the mirrors on
 274  274  # @uses: ZPOOL ZFS TESTPOOL
 275  275  function setup_mirrors
 276  276  {
 277  277          typeset -i nmirrors=$1
 278  278  
 279  279          shift
 280  280          while ((nmirrors > 0)); do
 281  281                  log_must test -n "$1" -a -n "$2"
 282      -                [[ -d /$TESTPOOL$nmirrors ]] && $RM -rf /$TESTPOOL$nmirrors
 283      -                log_must $ZPOOL create -f $TESTPOOL$nmirrors mirror $1 $2
      282 +                [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
      283 +                log_must zpool create -f $TESTPOOL$nmirrors mirror $1 $2
 284  284                  shift 2
 285  285                  ((nmirrors = nmirrors - 1))
 286  286          done
 287  287  }
 288  288  
 289  289  #
 290  290  # create a number of raidz pools.
 291  291  # We create a number($1) of 2 raidz pools  using the pairs of disks named
 292  292  # on the command line. These pools are *not* mounted
 293  293  # @parameters: $1 the number of pools to create
 294  294  #  $... the devices to use to create the pools on
 295  295  # @uses: ZPOOL ZFS TESTPOOL
 296  296  function setup_raidzs
 297  297  {
 298  298          typeset -i nraidzs=$1
 299  299  
 300  300          shift
 301  301          while ((nraidzs > 0)); do
 302  302                  log_must test -n "$1" -a -n "$2"
 303      -                [[ -d /$TESTPOOL$nraidzs ]] && $RM -rf /$TESTPOOL$nraidzs
 304      -                log_must $ZPOOL create -f $TESTPOOL$nraidzs raidz $1 $2
      303 +                [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
      304 +                log_must zpool create -f $TESTPOOL$nraidzs raidz $1 $2
 305  305                  shift 2
 306  306                  ((nraidzs = nraidzs - 1))
 307  307          done
 308  308  }
 309  309  
 310  310  #
 311  311  # Destroy the configured testpool mirrors.
 312  312  # the mirrors are of the form ${TESTPOOL}{number}
 313  313  # @uses: ZPOOL ZFS TESTPOOL
 314  314  function destroy_mirrors
↓ open down ↓ 9 lines elided ↑ open up ↑
 324  324  #
 325  325  function default_raidz_setup
 326  326  {
 327  327          typeset disklist="$*"
 328  328          disks=(${disklist[*]})
 329  329  
 330  330          if [[ ${#disks[*]} -lt 2 ]]; then
 331  331                  log_fail "A raid-z requires a minimum of two disks."
 332  332          fi
 333  333  
 334      -        [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
 335      -        log_must $ZPOOL create -f $TESTPOOL raidz $1 $2 $3
 336      -        log_must $ZFS create $TESTPOOL/$TESTFS
 337      -        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
      334 +        [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
      335 +        log_must zpool create -f $TESTPOOL raidz $1 $2 $3
      336 +        log_must zfs create $TESTPOOL/$TESTFS
      337 +        log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
 338  338  
 339  339          log_pass
 340  340  }
 341  341  
 342  342  #
 343  343  # Common function used to cleanup storage pools and datasets.
 344  344  #
 345  345  # Invoked at the start of the test suite to ensure the system
 346  346  # is in a known state, and also at the end of each set of
 347  347  # sub-tests to ensure errors from one set of tests doesn't
↓ open down ↓ 8 lines elided ↑ open up ↑
 356  356  
 357  357  function default_cleanup_noexit
 358  358  {
 359  359          typeset exclude=""
 360  360          typeset pool=""
 361  361          #
 362  362          # Destroying the pool will also destroy any
 363  363          # filesystems it contains.
 364  364          #
 365  365          if is_global_zone; then
 366      -                $ZFS unmount -a > /dev/null 2>&1
 367      -                exclude=`eval $ECHO \"'(${KEEP})'\"`
 368      -                ALL_POOLS=$($ZPOOL list -H -o name \
 369      -                    | $GREP -v "$NO_POOLS" | $EGREP -v "$exclude")
      366 +                zfs unmount -a > /dev/null 2>&1
      367 +                exclude=`eval echo \"'(${KEEP})'\"`
      368 +                ALL_POOLS=$(zpool list -H -o name \
      369 +                    | grep -v "$NO_POOLS" | egrep -v "$exclude")
 370  370                  # Here, we loop through the pools we're allowed to
 371  371                  # destroy, only destroying them if it's safe to do
 372  372                  # so.
 373  373                  while [ ! -z ${ALL_POOLS} ]
 374  374                  do
 375  375                          for pool in ${ALL_POOLS}
 376  376                          do
 377  377                                  if safe_to_destroy_pool $pool ;
 378  378                                  then
 379  379                                          destroy_pool $pool
 380  380                                  fi
 381      -                                ALL_POOLS=$($ZPOOL list -H -o name \
 382      -                                    | $GREP -v "$NO_POOLS" \
 383      -                                    | $EGREP -v "$exclude")
      381 +                                ALL_POOLS=$(zpool list -H -o name \
      382 +                                    | grep -v "$NO_POOLS" \
      383 +                                    | egrep -v "$exclude")
 384  384                          done
 385  385                  done
 386  386  
 387      -                $ZFS mount -a
      387 +                zfs mount -a
 388  388          else
 389  389                  typeset fs=""
 390      -                for fs in $($ZFS list -H -o name \
 391      -                    | $GREP "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
      390 +                for fs in $(zfs list -H -o name \
      391 +                    | grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
 392  392                          datasetexists $fs && \
 393      -                                log_must $ZFS destroy -Rf $fs
      393 +                                log_must zfs destroy -Rf $fs
 394  394                  done
 395  395  
 396  396                  # Need cleanup here to avoid garbage dir left.
 397      -                for fs in $($ZFS list -H -o name); do
      397 +                for fs in $(zfs list -H -o name); do
 398  398                          [[ $fs == /$ZONE_POOL ]] && continue
 399      -                        [[ -d $fs ]] && log_must $RM -rf $fs/*
      399 +                        [[ -d $fs ]] && log_must rm -rf $fs/*
 400  400                  done
 401  401  
 402  402                  #
 403  403                  # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
 404  404                  # the default value
 405  405                  #
 406      -                for fs in $($ZFS list -H -o name); do
      406 +                for fs in $(zfs list -H -o name); do
 407  407                          if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
 408      -                                log_must $ZFS set reservation=none $fs
 409      -                                log_must $ZFS set recordsize=128K $fs
 410      -                                log_must $ZFS set mountpoint=/$fs $fs
      408 +                                log_must zfs set reservation=none $fs
      409 +                                log_must zfs set recordsize=128K $fs
      410 +                                log_must zfs set mountpoint=/$fs $fs
 411  411                                  typeset enc=""
 412  412                                  enc=$(get_prop encryption $fs)
 413  413                                  if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \
 414  414                                          [[ "$enc" == "off" ]]; then
 415      -                                        log_must $ZFS set checksum=on $fs
      415 +                                        log_must zfs set checksum=on $fs
 416  416                                  fi
 417      -                                log_must $ZFS set compression=off $fs
 418      -                                log_must $ZFS set atime=on $fs
 419      -                                log_must $ZFS set devices=off $fs
 420      -                                log_must $ZFS set exec=on $fs
 421      -                                log_must $ZFS set setuid=on $fs
 422      -                                log_must $ZFS set readonly=off $fs
 423      -                                log_must $ZFS set snapdir=hidden $fs
 424      -                                log_must $ZFS set aclmode=groupmask $fs
 425      -                                log_must $ZFS set aclinherit=secure $fs
      417 +                                log_must zfs set compression=off $fs
      418 +                                log_must zfs set atime=on $fs
      419 +                                log_must zfs set devices=off $fs
      420 +                                log_must zfs set exec=on $fs
      421 +                                log_must zfs set setuid=on $fs
      422 +                                log_must zfs set readonly=off $fs
      423 +                                log_must zfs set snapdir=hidden $fs
      424 +                                log_must zfs set aclmode=groupmask $fs
      425 +                                log_must zfs set aclinherit=secure $fs
 426  426                          fi
 427  427                  done
 428  428          fi
 429  429  
 430  430          [[ -d $TESTDIR ]] && \
 431      -                log_must $RM -rf $TESTDIR
      431 +                log_must rm -rf $TESTDIR
 432  432  }
 433  433  
 434  434  
 435  435  #
 436  436  # Common function used to cleanup storage pools, file systems
 437  437  # and containers.
 438  438  #
 439  439  function default_container_cleanup
 440  440  {
 441  441          if ! is_global_zone; then
 442  442                  reexport_pool
 443  443          fi
 444  444  
 445  445          ismounted $TESTPOOL/$TESTCTR/$TESTFS1
 446  446          [[ $? -eq 0 ]] && \
 447      -            log_must $ZFS unmount $TESTPOOL/$TESTCTR/$TESTFS1
      447 +            log_must zfs unmount $TESTPOOL/$TESTCTR/$TESTFS1
 448  448  
 449  449          datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \
 450      -            log_must $ZFS destroy -R $TESTPOOL/$TESTCTR/$TESTFS1
      450 +            log_must zfs destroy -R $TESTPOOL/$TESTCTR/$TESTFS1
 451  451  
 452  452          datasetexists $TESTPOOL/$TESTCTR && \
 453      -            log_must $ZFS destroy -Rf $TESTPOOL/$TESTCTR
      453 +            log_must zfs destroy -Rf $TESTPOOL/$TESTCTR
 454  454  
 455  455          [[ -e $TESTDIR1 ]] && \
 456      -            log_must $RM -rf $TESTDIR1 > /dev/null 2>&1
      456 +            log_must rm -rf $TESTDIR1 > /dev/null 2>&1
 457  457  
 458  458          default_cleanup
 459  459  }
 460  460  
 461  461  #
 462  462  # Common function used to cleanup snapshot of file system or volume. Default to
 463  463  # delete the file system's snapshot
 464  464  #
 465  465  # $1 snapshot name
 466  466  #
↓ open down ↓ 10 lines elided ↑ open up ↑
 477  477          # to the really mountpoint when the snapshot is unmounted. So, firstly
 478  478          # check and make sure this snapshot's been mounted in current system.
 479  479          #
 480  480          typeset mtpt=""
 481  481          if ismounted $snap; then
 482  482                  mtpt=$(get_prop mountpoint $snap)
 483  483                  (($? != 0)) && \
 484  484                          log_fail "get_prop mountpoint $snap failed."
 485  485          fi
 486  486  
 487      -        log_must $ZFS destroy $snap
      487 +        log_must zfs destroy $snap
 488  488          [[ $mtpt != "" && -d $mtpt ]] && \
 489      -                log_must $RM -rf $mtpt
      489 +                log_must rm -rf $mtpt
 490  490  }
 491  491  
 492  492  #
 493  493  # Common function used to cleanup clone.
 494  494  #
 495  495  # $1 clone name
 496  496  #
 497  497  function destroy_clone
 498  498  {
 499  499          typeset clone=${1:-$TESTPOOL/$TESTCLONE}
↓ open down ↓ 3 lines elided ↑ open up ↑
 503  503          fi
 504  504  
 505  505          # With the same reason in destroy_snapshot
 506  506          typeset mtpt=""
 507  507          if ismounted $clone; then
 508  508                  mtpt=$(get_prop mountpoint $clone)
 509  509                  (($? != 0)) && \
 510  510                          log_fail "get_prop mountpoint $clone failed."
 511  511          fi
 512  512  
 513      -        log_must $ZFS destroy $clone
      513 +        log_must zfs destroy $clone
 514  514          [[ $mtpt != "" && -d $mtpt ]] && \
 515      -                log_must $RM -rf $mtpt
      515 +                log_must rm -rf $mtpt
 516  516  }
 517  517  
 518  518  # Return 0 if a snapshot exists; $? otherwise
 519  519  #
 520  520  # $1 - snapshot name
 521  521  
 522  522  function snapexists
 523  523  {
 524      -        $ZFS list -H -t snapshot "$1" > /dev/null 2>&1
      524 +        zfs list -H -t snapshot "$1" > /dev/null 2>&1
 525  525          return $?
 526  526  }
 527  527  
 528  528  #
 529  529  # Set a property to a certain value on a dataset.
 530  530  # Sets a property of the dataset to the value as passed in.
 531  531  # @param:
 532  532  #       $1 dataset who's property is being set
 533  533  #       $2 property to set
 534  534  #       $3 value to set property to
↓ open down ↓ 4 lines elided ↑ open up ↑
 539  539  #
 540  540  function dataset_setprop
 541  541  {
 542  542          typeset fn=dataset_setprop
 543  543  
 544  544          if (($# < 3)); then
 545  545                  log_note "$fn: Insufficient parameters (need 3, had $#)"
 546  546                  return 1
 547  547          fi
 548  548          typeset output=
 549      -        output=$($ZFS set $2=$3 $1 2>&1)
      549 +        output=$(zfs set $2=$3 $1 2>&1)
 550  550          typeset rv=$?
 551  551          if ((rv != 0)); then
 552  552                  log_note "Setting property on $1 failed."
 553  553                  log_note "property $2=$3"
 554  554                  log_note "Return Code: $rv"
 555  555                  log_note "Output: $output"
 556  556                  return $rv
 557  557          fi
 558  558          return 0
 559  559  }
↓ open down ↓ 11 lines elided ↑ open up ↑
 571  571  #   3 if the dataset could not have it's properties set.
 572  572  #
 573  573  function dataset_set_defaultproperties
 574  574  {
 575  575          typeset dataset="$1"
 576  576  
 577  577          [[ -z $dataset ]] && return 1
 578  578  
 579  579          typeset confset=
 580  580          typeset -i found=0
 581      -        for confset in $($ZFS list); do
      581 +        for confset in $(zfs list); do
 582  582                  if [[ $dataset = $confset ]]; then
 583  583                          found=1
 584  584                          break
 585  585                  fi
 586  586          done
 587  587          [[ $found -eq 0 ]] && return 2
 588  588          if [[ -n $COMPRESSION_PROP ]]; then
 589  589                  dataset_setprop $dataset compression $COMPRESSION_PROP || \
 590  590                          return 3
 591  591                  log_note "Compression set to '$COMPRESSION_PROP' on $dataset"
↓ open down ↓ 42 lines elided ↑ open up ↑
 634  634  function set_partition #<slice_num> <slice_start> <size_plus_units>  <whole_disk_name>
 635  635  {
 636  636          typeset -i slicenum=$1
 637  637          typeset start=$2
 638  638          typeset size=$3
 639  639          typeset disk=$4
 640  640          [[ -z $slicenum || -z $size || -z $disk ]] && \
 641  641              log_fail "The slice, size or disk name is unspecified."
 642  642          typeset format_file=/var/tmp/format_in.$$
 643  643  
 644      -        $ECHO "partition" >$format_file
 645      -        $ECHO "$slicenum" >> $format_file
 646      -        $ECHO "" >> $format_file
 647      -        $ECHO "" >> $format_file
 648      -        $ECHO "$start" >> $format_file
 649      -        $ECHO "$size" >> $format_file
 650      -        $ECHO "label" >> $format_file
 651      -        $ECHO "" >> $format_file
 652      -        $ECHO "q" >> $format_file
 653      -        $ECHO "q" >> $format_file
      644 +        echo "partition" >$format_file
      645 +        echo "$slicenum" >> $format_file
      646 +        echo "" >> $format_file
      647 +        echo "" >> $format_file
      648 +        echo "$start" >> $format_file
      649 +        echo "$size" >> $format_file
      650 +        echo "label" >> $format_file
      651 +        echo "" >> $format_file
      652 +        echo "q" >> $format_file
      653 +        echo "q" >> $format_file
 654  654  
 655      -        $FORMAT -e -s -d $disk -f $format_file
      655 +        format -e -s -d $disk -f $format_file
 656  656          typeset ret_val=$?
 657      -        $RM -f $format_file
      657 +        rm -f $format_file
 658  658          [[ $ret_val -ne 0 ]] && \
 659  659              log_fail "Unable to format $disk slice $slicenum to $size"
 660  660          return 0
 661  661  }
 662  662  
 663  663  #
 664  664  # Get the end cyl of the given slice
 665  665  #
 666  666  function get_endslice #<disk> <slice>
 667  667  {
↓ open down ↓ 1 lines elided ↑ open up ↑
 669  669          typeset slice=$2
 670  670          if [[ -z $disk || -z $slice ]] ; then
 671  671                  log_fail "The disk name or slice number is unspecified."
 672  672          fi
 673  673  
 674  674          disk=${disk#/dev/dsk/}
 675  675          disk=${disk#/dev/rdsk/}
 676  676          disk=${disk%s*}
 677  677  
 678  678          typeset -i ratio=0
 679      -        ratio=$($PRTVTOC /dev/rdsk/${disk}s2 | \
 680      -                $GREP "sectors\/cylinder" | \
 681      -                $AWK '{print $2}')
      679 +        ratio=$(prtvtoc /dev/rdsk/${disk}s2 | \
      680 +                grep "sectors\/cylinder" | \
      681 +                awk '{print $2}')
 682  682  
 683  683          if ((ratio == 0)); then
 684  684                  return
 685  685          fi
 686  686  
 687      -        typeset -i endcyl=$($PRTVTOC -h /dev/rdsk/${disk}s2 |
 688      -                $NAWK -v token="$slice" '{if ($1==token) print $6}')
      687 +        typeset -i endcyl=$(prtvtoc -h /dev/rdsk/${disk}s2 |
      688 +                nawk -v token="$slice" '{if ($1==token) print $6}')
 689  689  
 690  690          ((endcyl = (endcyl + 1) / ratio))
 691  691          echo $endcyl
 692  692  }
 693  693  
 694  694  
 695  695  #
 696  696  # Given a size,disk and total slice number,  this function formats the
 697  697  # disk slices from 0 to the total slice number with the same specified
 698  698  # size.
↓ open down ↓ 13 lines elided ↑ open up ↑
 712  712                          continue
 713  713                  fi
 714  714                  set_partition $i "$cyl" $slice_size $disk_name
 715  715                  cyl=$(get_endslice $disk_name $i)
 716  716                  ((i = i+1))
 717  717          done
 718  718  }
 719  719  
 720  720  #
 721  721  # This function continues to write to a filenum number of files into dirnum
 722      -# number of directories until either $FILE_WRITE returns an error or the
      722 +# number of directories until either file_write returns an error or the
 723  723  # maximum number of files per directory have been written.
 724  724  #
 725  725  # Usage:
 726  726  # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
 727  727  #
 728  728  # Return value: 0 on success
 729  729  #               non 0 on error
 730  730  #
 731  731  # Where :
 732  732  #       destdir:    is the directory where everything is to be created under
↓ open down ↓ 15 lines elided ↑ open up ↑
 748  748          typeset -i filenum=${3:-50}
 749  749          typeset -i bytes=${4:-8192}
 750  750          typeset -i num_writes=${5:-10240}
 751  751          typeset -i data=${6:-0}
 752  752  
 753  753          typeset -i odirnum=1
 754  754          typeset -i idirnum=0
 755  755          typeset -i fn=0
 756  756          typeset -i retval=0
 757  757  
 758      -        log_must $MKDIR -p $destdir/$idirnum
      758 +        log_must mkdir -p $destdir/$idirnum
 759  759          while (($odirnum > 0)); do
 760  760                  if ((dirnum >= 0 && idirnum >= dirnum)); then
 761  761                          odirnum=0
 762  762                          break
 763  763                  fi
 764      -                $FILE_WRITE -o create -f $destdir/$idirnum/$TESTFILE.$fn \
      764 +                file_write -o create -f $destdir/$idirnum/$TESTFILE.$fn \
 765  765                      -b $bytes -c $num_writes -d $data
 766  766                  retval=$?
 767  767                  if (($retval != 0)); then
 768  768                          odirnum=0
 769  769                          break
 770  770                  fi
 771  771                  if (($fn >= $filenum)); then
 772  772                          fn=0
 773  773                          ((idirnum = idirnum + 1))
 774      -                        log_must $MKDIR -p $destdir/$idirnum
      774 +                        log_must mkdir -p $destdir/$idirnum
 775  775                  else
 776  776                          ((fn = fn + 1))
 777  777                  fi
 778  778          done
 779  779          return $retval
 780  780  }
 781  781  
 782  782  #
 783  783  # Simple function to get the specified property. If unable to
 784  784  # get the property then exits.
 785  785  #
 786  786  # Note property is in 'parsable' format (-p)
 787  787  #
 788  788  function get_prop # property dataset
 789  789  {
 790  790          typeset prop_val
 791  791          typeset prop=$1
 792  792          typeset dataset=$2
 793  793  
 794      -        prop_val=$($ZFS get -pH -o value $prop $dataset 2>/dev/null)
      794 +        prop_val=$(zfs get -pH -o value $prop $dataset 2>/dev/null)
 795  795          if [[ $? -ne 0 ]]; then
 796  796                  log_note "Unable to get $prop property for dataset " \
 797  797                  "$dataset"
 798  798                  return 1
 799  799          fi
 800  800  
 801      -        $ECHO $prop_val
      801 +        echo $prop_val
 802  802          return 0
 803  803  }
 804  804  
 805  805  #
 806  806  # Simple function to get the specified property of pool. If unable to
 807  807  # get the property then exits.
 808  808  #
 809  809  function get_pool_prop # property pool
 810  810  {
 811  811          typeset prop_val
 812  812          typeset prop=$1
 813  813          typeset pool=$2
 814  814  
 815  815          if poolexists $pool ; then
 816      -                prop_val=$($ZPOOL get $prop $pool 2>/dev/null | $TAIL -1 | \
 817      -                        $AWK '{print $3}')
      816 +                prop_val=$(zpool get $prop $pool 2>/dev/null | tail -1 | \
      817 +                        awk '{print $3}')
 818  818                  if [[ $? -ne 0 ]]; then
 819  819                          log_note "Unable to get $prop property for pool " \
 820  820                          "$pool"
 821  821                          return 1
 822  822                  fi
 823  823          else
 824  824                  log_note "Pool $pool not exists."
 825  825                  return 1
 826  826          fi
 827  827  
 828      -        $ECHO $prop_val
      828 +        echo $prop_val
 829  829          return 0
 830  830  }
 831  831  
 832  832  # Return 0 if a pool exists; $? otherwise
 833  833  #
 834  834  # $1 - pool name
 835  835  
 836  836  function poolexists
 837  837  {
 838  838          typeset pool=$1
 839  839  
 840  840          if [[ -z $pool ]]; then
 841  841                  log_note "No pool name given."
 842  842                  return 1
 843  843          fi
 844  844  
 845      -        $ZPOOL get name "$pool" > /dev/null 2>&1
      845 +        zpool get name "$pool" > /dev/null 2>&1
 846  846          return $?
 847  847  }
 848  848  
 849  849  # Return 0 if all the specified datasets exist; $? otherwise
 850  850  #
 851  851  # $1-n  dataset name
 852  852  function datasetexists
 853  853  {
 854  854          if (($# == 0)); then
 855  855                  log_note "No dataset name given."
 856  856                  return 1
 857  857          fi
 858  858  
 859  859          while (($# > 0)); do
 860      -                $ZFS get name $1 > /dev/null 2>&1 || \
      860 +                zfs get name $1 > /dev/null 2>&1 || \
 861  861                          return $?
 862  862                  shift
 863  863          done
 864  864  
 865  865          return 0
 866  866  }
 867  867  
 868  868  # return 0 if none of the specified datasets exists, otherwise return 1.
 869  869  #
 870  870  # $1-n  dataset name
 871  871  function datasetnonexists
 872  872  {
 873  873          if (($# == 0)); then
 874  874                  log_note "No dataset name given."
 875  875                  return 1
 876  876          fi
 877  877  
 878  878          while (($# > 0)); do
 879      -                $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \
      879 +                zfs list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \
 880  880                      && return 1
 881  881                  shift
 882  882          done
 883  883  
 884  884          return 0
 885  885  }
 886  886  
 887  887  #
 888  888  # Given a mountpoint, or a dataset name, determine if it is shared.
 889  889  #
↓ open down ↓ 11 lines elided ↑ open up ↑
 901  901                          mtpt=$(get_prop mountpoint "$fs")
 902  902                          case $mtpt in
 903  903                                  none|legacy|-) return 1
 904  904                                          ;;
 905  905                                  *)      fs=$mtpt
 906  906                                          ;;
 907  907                          esac
 908  908                  fi
 909  909          fi
 910  910  
 911      -        for mtpt in `$SHARE | $AWK '{print $2}'` ; do
      911 +        for mtpt in `share | awk '{print $2}'` ; do
 912  912                  if [[ $mtpt == $fs ]] ; then
 913  913                          return 0
 914  914                  fi
 915  915          done
 916  916  
 917      -        typeset stat=$($SVCS -H -o STA nfs/server:default)
      917 +        typeset stat=$(svcs -H -o STA nfs/server:default)
 918  918          if [[ $stat != "ON" ]]; then
 919  919                  log_note "Current nfs/server status: $stat"
 920  920          fi
 921  921  
 922  922          return 1
 923  923  }
 924  924  
 925  925  #
 926  926  # Given a mountpoint, determine if it is not shared.
 927  927  #
↓ open down ↓ 13 lines elided ↑ open up ↑
 941  941  
 942  942  #
 943  943  # Helper function to unshare a mountpoint.
 944  944  #
 945  945  function unshare_fs #fs
 946  946  {
 947  947          typeset fs=$1
 948  948  
 949  949          is_shared $fs
 950  950          if (($? == 0)); then
 951      -                log_must $ZFS unshare $fs
      951 +                log_must zfs unshare $fs
 952  952          fi
 953  953  
 954  954          return 0
 955  955  }
 956  956  
 957  957  #
 958  958  # Check NFS server status and trigger it online.
 959  959  #
 960  960  function setup_nfs_server
 961  961  {
 962  962          # Cannot share directory in non-global zone.
 963  963          #
 964  964          if ! is_global_zone; then
 965  965                  log_note "Cannot trigger NFS server by sharing in LZ."
 966  966                  return
 967  967          fi
 968  968  
 969  969          typeset nfs_fmri="svc:/network/nfs/server:default"
 970      -        if [[ $($SVCS -Ho STA $nfs_fmri) != "ON" ]]; then
      970 +        if [[ $(svcs -Ho STA $nfs_fmri) != "ON" ]]; then
 971  971                  #
 972  972                  # Only really sharing operation can enable NFS server
 973  973                  # to online permanently.
 974  974                  #
 975  975                  typeset dummy=/tmp/dummy
 976  976  
 977  977                  if [[ -d $dummy ]]; then
 978      -                        log_must $RM -rf $dummy
      978 +                        log_must rm -rf $dummy
 979  979                  fi
 980  980  
 981      -                log_must $MKDIR $dummy
 982      -                log_must $SHARE $dummy
      981 +                log_must mkdir $dummy
      982 +                log_must share $dummy
 983  983  
 984  984                  #
 985  985                  # Waiting for fmri's status to be the final status.
 986  986                  # Otherwise, in transition, an asterisk (*) is appended for
 987  987                  # instances, unshare will reverse status to 'DIS' again.
 988  988                  #
 989  989                  # Waiting for 1's at least.
 990  990                  #
 991      -                log_must $SLEEP 1
      991 +                log_must sleep 1
 992  992                  timeout=10
 993      -                while [[ timeout -ne 0 && $($SVCS -Ho STA $nfs_fmri) == *'*' ]]
      993 +                while [[ timeout -ne 0 && $(svcs -Ho STA $nfs_fmri) == *'*' ]]
 994  994                  do
 995      -                        log_must $SLEEP 1
      995 +                        log_must sleep 1
 996  996  
 997  997                          ((timeout -= 1))
 998  998                  done
 999  999  
1000      -                log_must $UNSHARE $dummy
1001      -                log_must $RM -rf $dummy
     1000 +                log_must unshare $dummy
     1001 +                log_must rm -rf $dummy
1002 1002          fi
1003 1003  
1004      -        log_note "Current NFS status: '$($SVCS -Ho STA,FMRI $nfs_fmri)'"
     1004 +        log_note "Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1005 1005  }
1006 1006  
1007 1007  #
1008 1008  # To verify whether calling process is in global zone
1009 1009  #
1010 1010  # Return 0 if in global zone, 1 in non-global zone
1011 1011  #
1012 1012  function is_global_zone
1013 1013  {
1014      -        typeset cur_zone=$($ZONENAME 2>/dev/null)
     1014 +        typeset cur_zone=$(zonename 2>/dev/null)
1015 1015          if [[ $cur_zone != "global" ]]; then
1016 1016                  return 1
1017 1017          fi
1018 1018          return 0
1019 1019  }
1020 1020  
1021 1021  #
1022 1022  # Verify whether test is permitted to run from
1023 1023  # global zone, local zone, or both
1024 1024  #
↓ open down ↓ 51 lines elided ↑ open up ↑
1076 1076          if [[ -z $pool ]]; then
1077 1077                  log_note "Missing pool name."
1078 1078                  return 1
1079 1079          fi
1080 1080  
1081 1081          if poolexists $pool ; then
1082 1082                  destroy_pool $pool
1083 1083          fi
1084 1084  
1085 1085          if is_global_zone ; then
1086      -                [[ -d /$pool ]] && $RM -rf /$pool
1087      -                log_must $ZPOOL create -f $pool $@
     1086 +                [[ -d /$pool ]] && rm -rf /$pool
     1087 +                log_must zpool create -f $pool $@
1088 1088          fi
1089 1089  
1090 1090          return 0
1091 1091  }
1092 1092  
1093 1093  # Return 0 if destroy successfully or the pool exists; $? otherwise
1094 1094  # Note: In local zones, this function should return 0 silently.
1095 1095  #
1096 1096  # $1 - pool name
1097 1097  # Destroy pool with the given parameters.
↓ open down ↓ 12 lines elided ↑ open up ↑
1110 1110                  if poolexists "$pool" ; then
1111 1111                          mtpt=$(get_prop mountpoint "$pool")
1112 1112  
1113 1113                          # At times, syseventd activity can cause attempts to
1114 1114                          # destroy a pool to fail with EBUSY. We retry a few
1115 1115                          # times allowing failures before requiring the destroy
1116 1116                          # to succeed.
1117 1117                          typeset -i wait_time=10 ret=1 count=0
1118 1118                          must=""
1119 1119                          while [[ $ret -ne 0 ]]; do
1120      -                                $must $ZPOOL destroy -f $pool
     1120 +                                $must zpool destroy -f $pool
1121 1121                                  ret=$?
1122 1122                                  [[ $ret -eq 0 ]] && break
1123 1123                                  log_note "zpool destroy failed with $ret"
1124 1124                                  [[ count++ -ge 7 ]] && must=log_must
1125      -                                $SLEEP $wait_time
     1125 +                                sleep $wait_time
1126 1126                          done
1127 1127  
1128 1128                          [[ -d $mtpt ]] && \
1129      -                                log_must $RM -rf $mtpt
     1129 +                                log_must rm -rf $mtpt
1130 1130                  else
1131 1131                          log_note "Pool does not exist. ($pool)"
1132 1132                          return 1
1133 1133                  fi
1134 1134          fi
1135 1135  
1136 1136          return 0
1137 1137  }
1138 1138  
1139 1139  #
↓ open down ↓ 10 lines elided ↑ open up ↑
1150 1150          typeset zone_name=${1:-$(hostname)-z}
1151 1151          typeset zone_root=${2:-"/zone_root"}
1152 1152          typeset zone_ip=${3:-"10.1.1.10"}
1153 1153          typeset prefix_ctr=$ZONE_CTR
1154 1154          typeset pool_name=$ZONE_POOL
1155 1155          typeset -i cntctr=5
1156 1156          typeset -i i=0
1157 1157  
1158 1158          # Create pool and 5 container within it
1159 1159          #
1160      -        [[ -d /$pool_name ]] && $RM -rf /$pool_name
1161      -        log_must $ZPOOL create -f $pool_name $DISKS
     1160 +        [[ -d /$pool_name ]] && rm -rf /$pool_name
     1161 +        log_must zpool create -f $pool_name $DISKS
1162 1162          while ((i < cntctr)); do
1163      -                log_must $ZFS create $pool_name/$prefix_ctr$i
     1163 +                log_must zfs create $pool_name/$prefix_ctr$i
1164 1164                  ((i += 1))
1165 1165          done
1166 1166  
1167 1167          # create a zvol
1168      -        log_must $ZFS create -V 1g $pool_name/zone_zvol
     1168 +        log_must zfs create -V 1g $pool_name/zone_zvol
1169 1169  
1170 1170          #
1171 1171          # If current system support slog, add slog device for pool
1172 1172          #
1173 1173          if verify_slog_support ; then
1174 1174                  typeset sdevs="/var/tmp/sdev1 /var/tmp/sdev2"
1175      -                log_must $MKFILE $MINVDEVSIZE $sdevs
1176      -                log_must $ZPOOL add $pool_name log mirror $sdevs
     1175 +                log_must mkfile $MINVDEVSIZE $sdevs
     1176 +                log_must zpool add $pool_name log mirror $sdevs
1177 1177          fi
1178 1178  
1179 1179          # this isn't supported just yet.
1180 1180          # Create a filesystem. In order to add this to
1181 1181          # the zone, it must have it's mountpoint set to 'legacy'
1182      -        # log_must $ZFS create $pool_name/zfs_filesystem
1183      -        # log_must $ZFS set mountpoint=legacy $pool_name/zfs_filesystem
     1182 +        # log_must zfs create $pool_name/zfs_filesystem
     1183 +        # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1184 1184  
1185 1185          [[ -d $zone_root ]] && \
1186      -                log_must $RM -rf $zone_root/$zone_name
     1186 +                log_must rm -rf $zone_root/$zone_name
1187 1187          [[ ! -d $zone_root ]] && \
1188      -                log_must $MKDIR -p -m 0700 $zone_root/$zone_name
     1188 +                log_must mkdir -p -m 0700 $zone_root/$zone_name
1189 1189  
1190 1190          # Create zone configure file and configure the zone
1191 1191          #
1192 1192          typeset zone_conf=/tmp/zone_conf.$$
1193      -        $ECHO "create" > $zone_conf
1194      -        $ECHO "set zonepath=$zone_root/$zone_name" >> $zone_conf
1195      -        $ECHO "set autoboot=true" >> $zone_conf
     1193 +        echo "create" > $zone_conf
     1194 +        echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
     1195 +        echo "set autoboot=true" >> $zone_conf
1196 1196          i=0
1197 1197          while ((i < cntctr)); do
1198      -                $ECHO "add dataset" >> $zone_conf
1199      -                $ECHO "set name=$pool_name/$prefix_ctr$i" >> \
     1198 +                echo "add dataset" >> $zone_conf
     1199 +                echo "set name=$pool_name/$prefix_ctr$i" >> \
1200 1200                          $zone_conf
1201      -                $ECHO "end" >> $zone_conf
     1201 +                echo "end" >> $zone_conf
1202 1202                  ((i += 1))
1203 1203          done
1204 1204  
1205 1205          # add our zvol to the zone
1206      -        $ECHO "add device" >> $zone_conf
1207      -        $ECHO "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1208      -        $ECHO "end" >> $zone_conf
     1206 +        echo "add device" >> $zone_conf
     1207 +        echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
     1208 +        echo "end" >> $zone_conf
1209 1209  
1210 1210          # add a corresponding zvol rdsk to the zone
1211      -        $ECHO "add device" >> $zone_conf
1212      -        $ECHO "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf
1213      -        $ECHO "end" >> $zone_conf
     1211 +        echo "add device" >> $zone_conf
     1212 +        echo "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf
     1213 +        echo "end" >> $zone_conf
1214 1214  
1215 1215          # once it's supported, we'll add our filesystem to the zone
1216      -        # $ECHO "add fs" >> $zone_conf
1217      -        # $ECHO "set type=zfs" >> $zone_conf
1218      -        # $ECHO "set special=$pool_name/zfs_filesystem" >> $zone_conf
1219      -        # $ECHO "set dir=/export/zfs_filesystem" >> $zone_conf
1220      -        # $ECHO "end" >> $zone_conf
     1216 +        # echo "add fs" >> $zone_conf
     1217 +        # echo "set type=zfs" >> $zone_conf
     1218 +        # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
     1219 +        # echo "set dir=/export/zfs_filesystem" >> $zone_conf
     1220 +        # echo "end" >> $zone_conf
1221 1221  
1222      -        $ECHO "verify" >> $zone_conf
1223      -        $ECHO "commit" >> $zone_conf
1224      -        log_must $ZONECFG -z $zone_name -f $zone_conf
1225      -        log_must $RM -f $zone_conf
     1222 +        echo "verify" >> $zone_conf
     1223 +        echo "commit" >> $zone_conf
     1224 +        log_must zonecfg -z $zone_name -f $zone_conf
     1225 +        log_must rm -f $zone_conf
1226 1226  
1227 1227          # Install the zone
1228      -        $ZONEADM -z $zone_name install
     1228 +        zoneadm -z $zone_name install
1229 1229          if (($? == 0)); then
1230      -                log_note "SUCCESS: $ZONEADM -z $zone_name install"
     1230 +                log_note "SUCCESS: zoneadm -z $zone_name install"
1231 1231          else
1232      -                log_fail "FAIL: $ZONEADM -z $zone_name install"
     1232 +                log_fail "FAIL: zoneadm -z $zone_name install"
1233 1233          fi
1234 1234  
1235 1235          # Install sysidcfg file
1236 1236          #
1237 1237          typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg
1238      -        $ECHO "system_locale=C" > $sysidcfg
1239      -        $ECHO  "terminal=dtterm" >> $sysidcfg
1240      -        $ECHO  "network_interface=primary {" >> $sysidcfg
1241      -        $ECHO  "hostname=$zone_name" >> $sysidcfg
1242      -        $ECHO  "}" >> $sysidcfg
1243      -        $ECHO  "name_service=NONE" >> $sysidcfg
1244      -        $ECHO  "root_password=mo791xfZ/SFiw" >> $sysidcfg
1245      -        $ECHO  "security_policy=NONE" >> $sysidcfg
1246      -        $ECHO  "timezone=US/Eastern" >> $sysidcfg
     1238 +        echo "system_locale=C" > $sysidcfg
     1239 +        echo  "terminal=dtterm" >> $sysidcfg
     1240 +        echo  "network_interface=primary {" >> $sysidcfg
     1241 +        echo  "hostname=$zone_name" >> $sysidcfg
     1242 +        echo  "}" >> $sysidcfg
     1243 +        echo  "name_service=NONE" >> $sysidcfg
     1244 +        echo  "root_password=mo791xfZ/SFiw" >> $sysidcfg
     1245 +        echo  "security_policy=NONE" >> $sysidcfg
     1246 +        echo  "timezone=US/Eastern" >> $sysidcfg
1247 1247  
1248 1248          # Boot this zone
1249      -        log_must $ZONEADM -z $zone_name boot
     1249 +        log_must zoneadm -z $zone_name boot
1250 1250  }
1251 1251  
1252 1252  #
1253 1253  # Reexport TESTPOOL & TESTPOOL(1-4)
1254 1254  #
1255 1255  function reexport_pool
1256 1256  {
1257 1257          typeset -i cntctr=5
1258 1258          typeset -i i=0
1259 1259  
1260 1260          while ((i < cntctr)); do
1261 1261                  if ((i == 0)); then
1262 1262                          TESTPOOL=$ZONE_POOL/$ZONE_CTR$i
1263 1263                          if ! ismounted $TESTPOOL; then
1264      -                                log_must $ZFS mount $TESTPOOL
     1264 +                                log_must zfs mount $TESTPOOL
1265 1265                          fi
1266 1266                  else
1267 1267                          eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i
1268 1268                          if eval ! ismounted \$TESTPOOL$i; then
1269      -                                log_must eval $ZFS mount \$TESTPOOL$i
     1269 +                                log_must eval zfs mount \$TESTPOOL$i
1270 1270                          fi
1271 1271                  fi
1272 1272                  ((i += 1))
1273 1273          done
1274 1274  }
1275 1275  
1276 1276  #
1277 1277  # Verify a given disk is online or offline
1278 1278  #
1279 1279  # Return 0 is pool/disk matches expected state, 1 otherwise
1280 1280  #
1281 1281  function check_state # pool disk state{online,offline}
1282 1282  {
1283 1283          typeset pool=$1
1284 1284          typeset disk=${2#/dev/dsk/}
1285 1285          typeset state=$3
1286 1286  
1287      -        $ZPOOL status -v $pool | grep "$disk"  \
     1287 +        zpool status -v $pool | grep "$disk"  \
1288 1288              | grep -i "$state" > /dev/null 2>&1
1289 1289  
1290 1290          return $?
1291 1291  }
1292 1292  
1293 1293  #
1294 1294  # Get the mountpoint of snapshot
1295 1295  # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1296 1296  # as its mountpoint
1297 1297  #
↓ open down ↓ 5 lines elided ↑ open up ↑
1303 1303                  log_fail "Error name of snapshot '$dataset'."
1304 1304          fi
1305 1305  
1306 1306          typeset fs=${dataset%@*}
1307 1307          typeset snap=${dataset#*@}
1308 1308  
1309 1309          if [[ -z $fs || -z $snap ]]; then
1310 1310                  log_fail "Error name of snapshot '$dataset'."
1311 1311          fi
1312 1312  
1313      -        $ECHO $(get_prop mountpoint $fs)/.zfs/snapshot/$snap
     1313 +        echo $(get_prop mountpoint $fs)/.zfs/snapshot/$snap
1314 1314  }
1315 1315  
1316 1316  #
1317 1317  # Given a pool and file system, this function will verify the file system
1318 1318  # using the zdb internal tool. Note that the pool is exported and imported
1319 1319  # to ensure it has consistent state.
1320 1320  #
1321 1321  function verify_filesys # pool filesystem dir
1322 1322  {
1323 1323          typeset pool="$1"
1324 1324          typeset filesys="$2"
1325 1325          typeset zdbout="/tmp/zdbout.$$"
1326 1326  
1327 1327          shift
1328 1328          shift
1329 1329          typeset dirs=$@
1330 1330          typeset search_path=""
1331 1331  
1332      -        log_note "Calling $ZDB to verify filesystem '$filesys'"
1333      -        $ZFS unmount -a > /dev/null 2>&1
1334      -        log_must $ZPOOL export $pool
     1332 +        log_note "Calling zdb to verify filesystem '$filesys'"
     1333 +        zfs unmount -a > /dev/null 2>&1
     1334 +        log_must zpool export $pool
1335 1335  
1336 1336          if [[ -n $dirs ]] ; then
1337 1337                  for dir in $dirs ; do
1338 1338                          search_path="$search_path -d $dir"
1339 1339                  done
1340 1340          fi
1341 1341  
1342      -        log_must $ZPOOL import $search_path $pool
     1342 +        log_must zpool import $search_path $pool
1343 1343  
1344      -        $ZDB -cudi $filesys > $zdbout 2>&1
     1344 +        zdb -cudi $filesys > $zdbout 2>&1
1345 1345          if [[ $? != 0 ]]; then
1346      -                log_note "Output: $ZDB -cudi $filesys"
1347      -                $CAT $zdbout
1348      -                log_fail "$ZDB detected errors with: '$filesys'"
     1346 +                log_note "Output: zdb -cudi $filesys"
     1347 +                cat $zdbout
     1348 +                log_fail "zdb detected errors with: '$filesys'"
1349 1349          fi
1350 1350  
1351      -        log_must $ZFS mount -a
1352      -        log_must $RM -rf $zdbout
     1351 +        log_must zfs mount -a
     1352 +        log_must rm -rf $zdbout
1353 1353  }
1354 1354  
1355 1355  #
1356 1356  # Given a pool, and this function list all disks in the pool
1357 1357  #
1358 1358  function get_disklist # pool
1359 1359  {
1360 1360          typeset disklist=""
1361 1361  
1362      -        disklist=$($ZPOOL iostat -v $1 | $NAWK '(NR >4) {print $1}' | \
1363      -            $GREP -v "\-\-\-\-\-" | \
1364      -            $EGREP -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
     1362 +        disklist=$(zpool iostat -v $1 | nawk '(NR >4) {print $1}' | \
     1363 +            grep -v "\-\-\-\-\-" | \
     1364 +            egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1365 1365  
1366      -        $ECHO $disklist
     1366 +        echo $disklist
1367 1367  }
1368 1368  
1369 1369  # /**
1370 1370  #  This function kills a given list of processes after a time period. We use
1371 1371  #  this in the stress tests instead of STF_TIMEOUT so that we can have processes
1372 1372  #  run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1373 1373  #  would be listed as FAIL, which we don't want : we're happy with stress tests
1374 1374  #  running for a certain amount of time, then finishing.
1375 1375  #
1376 1376  # @param $1 the time in seconds after which we should terminate these processes
1377 1377  # @param $2..$n the processes we wish to terminate.
1378 1378  # */
1379 1379  function stress_timeout
1380 1380  {
1381 1381          typeset -i TIMEOUT=$1
1382 1382          shift
1383 1383          typeset cpids="$@"
1384 1384  
1385 1385          log_note "Waiting for child processes($cpids). " \
1386 1386                  "It could last dozens of minutes, please be patient ..."
1387      -        log_must $SLEEP $TIMEOUT
     1387 +        log_must sleep $TIMEOUT
1388 1388  
1389 1389          log_note "Killing child processes after ${TIMEOUT} stress timeout."
1390 1390          typeset pid
1391 1391          for pid in $cpids; do
1392      -                $PS -p $pid > /dev/null 2>&1
     1392 +                ps -p $pid > /dev/null 2>&1
1393 1393                  if (($? == 0)); then
1394      -                        log_must $KILL -USR1 $pid
     1394 +                        log_must kill -USR1 $pid
1395 1395                  fi
1396 1396          done
1397 1397  }
1398 1398  
1399 1399  #
1400 1400  # Verify a given hotspare disk is inuse or avail
1401 1401  #
1402 1402  # Return 0 is pool/disk matches expected state, 1 otherwise
1403 1403  #
1404 1404  function check_hotspare_state # pool disk state{inuse,avail}
↓ open down ↓ 53 lines elided ↑ open up ↑
1458 1458  # and to see if the content of <token> contain the <keyword> specified.
1459 1459  #
1460 1460  # Return 0 is contain, 1 otherwise
1461 1461  #
1462 1462  function check_pool_status # pool token keyword
1463 1463  {
1464 1464          typeset pool=$1
1465 1465          typeset token=$2
1466 1466          typeset keyword=$3
1467 1467  
1468      -        $ZPOOL status -v "$pool" 2>/dev/null | $NAWK -v token="$token:" '
     1468 +        zpool status -v "$pool" 2>/dev/null | nawk -v token="$token:" '
1469 1469                  ($1==token) {print $0}' \
1470      -        | $GREP -i "$keyword" > /dev/null 2>&1
     1470 +        | grep -i "$keyword" > /dev/null 2>&1
1471 1471  
1472 1472          return $?
1473 1473  }
1474 1474  
1475 1475  #
1476 1476  # These 5 following functions are instance of check_pool_status()
1477 1477  #       is_pool_resilvering - to check if the pool is resilver in progress
1478 1478  #       is_pool_resilvered - to check if the pool is resilver completed
1479 1479  #       is_pool_scrubbing - to check if the pool is scrub in progress
1480 1480  #       is_pool_scrubbed - to check if the pool is scrub completed
↓ open down ↓ 51 lines elided ↑ open up ↑
1532 1532  # Verify the rsh connectivity to each remote host in RHOSTS.
1533 1533  #
1534 1534  # Return 0 if remote host is accessible; otherwise 1.
1535 1535  # $1 remote host name
1536 1536  # $2 username
1537 1537  #
1538 1538  function verify_rsh_connect #rhost, username
1539 1539  {
1540 1540          typeset rhost=$1
1541 1541          typeset username=$2
1542      -        typeset rsh_cmd="$RSH -n"
     1542 +        typeset rsh_cmd="rsh -n"
1543 1543          typeset cur_user=
1544 1544  
1545      -        $GETENT hosts $rhost >/dev/null 2>&1
     1545 +        getent hosts $rhost >/dev/null 2>&1
1546 1546          if (($? != 0)); then
1547 1547                  log_note "$rhost cannot be found from" \
1548 1548                          "administrative database."
1549 1549                  return 1
1550 1550          fi
1551 1551  
1552      -        $PING $rhost 3 >/dev/null 2>&1
     1552 +        ping $rhost 3 >/dev/null 2>&1
1553 1553          if (($? != 0)); then
1554 1554                  log_note "$rhost is not reachable."
1555 1555                  return 1
1556 1556          fi
1557 1557  
1558 1558          if ((${#username} != 0)); then
1559 1559                  rsh_cmd="$rsh_cmd -l $username"
1560 1560                  cur_user="given user \"$username\""
1561 1561          else
1562      -                cur_user="current user \"`$LOGNAME`\""
     1562 +                cur_user="current user \"`logname`\""
1563 1563          fi
1564 1564  
1565      -         if ! $rsh_cmd $rhost $TRUE; then
1566      -                log_note "$RSH to $rhost is not accessible" \
     1565 +         if ! $rsh_cmd $rhost true; then
     1566 +                log_note "rsh to $rhost is not accessible" \
1567 1567                          "with $cur_user."
1568 1568                  return 1
1569 1569          fi
1570 1570  
1571 1571          return 0
1572 1572  }
1573 1573  
1574 1574  #
1575 1575  # Verify the remote host connection via rsh after rebooting
1576 1576  # $1 remote host
↓ open down ↓ 36 lines elided ↑ open up ↑
1613 1613          typeset rhost=$2
1614 1614          typeset -i ret=0
1615 1615          typeset cmd_str=""
1616 1616          typeset rsh_str=""
1617 1617  
1618 1618          shift; shift
1619 1619          cmd_str="$@"
1620 1620  
1621 1621          err_file=/tmp/${rhost}.$$.err
1622 1622          if ((${#ruser} == 0)); then
1623      -                rsh_str="$RSH -n"
     1623 +                rsh_str="rsh -n"
1624 1624          else
1625      -                rsh_str="$RSH -n -l $ruser"
     1625 +                rsh_str="rsh -n -l $ruser"
1626 1626          fi
1627 1627  
1628 1628          $rsh_str $rhost /usr/bin/ksh -c "'$cmd_str; \
1629 1629                  print -u 2 \"status=\$?\"'" \
1630 1630                  >/dev/null 2>$err_file
1631 1631          ret=$?
1632 1632          if (($ret != 0)); then
1633      -                $CAT $err_file
1634      -                $RM -f $std_file $err_file
1635      -                log_fail  "$RSH itself failed with exit code $ret..."
     1633 +                cat $err_file
     1634 +                rm -f $std_file $err_file
     1635 +                log_fail  "rsh itself failed with exit code $ret..."
1636 1636          fi
1637 1637  
1638      -         ret=$($GREP -v 'print -u 2' $err_file | $GREP 'status=' | \
1639      -                $CUT -d= -f2)
1640      -        (($ret != 0)) && $CAT $err_file >&2
     1638 +         ret=$(grep -v 'print -u 2' $err_file | grep 'status=' | \
     1639 +                cut -d= -f2)
     1640 +        (($ret != 0)) && cat $err_file >&2
1641 1641  
1642      -        $RM -f $err_file >/dev/null 2>&1
     1642 +        rm -f $err_file >/dev/null 2>&1
1643 1643          return $ret
1644 1644  }
1645 1645  
1646 1646  #
1647 1647  # Get the SUNWstc-fs-zfs package installation path in a remote host
1648 1648  # $1 remote host name
1649 1649  #
1650 1650  function get_remote_pkgpath
1651 1651  {
1652 1652          typeset rhost=$1
1653 1653          typeset pkgpath=""
1654 1654  
1655      -        pkgpath=$($RSH -n $rhost "$PKGINFO -l SUNWstc-fs-zfs | $GREP BASEDIR: |\
1656      -                        $CUT -d: -f2")
     1655 +        pkgpath=$(rsh -n $rhost "pkginfo -l SUNWstc-fs-zfs | grep BASEDIR: |\
     1656 +                        cut -d: -f2")
1657 1657  
1658      -        $ECHO $pkgpath
     1658 +        echo $pkgpath
1659 1659  }
1660 1660  
1661 1661  #/**
1662 1662  # A function to find and locate free disks on a system or from given
1663 1663  # disks as the parameter. It works by locating disks that are in use
1664 1664  # as swap devices and dump devices, and also disks listed in /etc/vfstab
1665 1665  #
1666 1666  # $@ given disks to find which are free, default is all disks in
1667 1667  # the test system
1668 1668  #
1669 1669  # @return a string containing the list of available disks
1670 1670  #*/
1671 1671  function find_disks
1672 1672  {
1673 1673          sfi=/tmp/swaplist.$$
1674 1674          dmpi=/tmp/dumpdev.$$
1675 1675          max_finddisksnum=${MAX_FINDDISKSNUM:-6}
1676 1676  
1677      -        $SWAP -l > $sfi
1678      -        $DUMPADM > $dmpi 2>/dev/null
     1677 +        swap -l > $sfi
     1678 +        dumpadm > $dmpi 2>/dev/null
1679 1679  
1680 1680  # write an awk script that can process the output of format
1681 1681  # to produce a list of disks we know about. Note that we have
1682 1682  # to escape "$2" so that the shell doesn't interpret it while
1683 1683  # we're creating the awk script.
1684 1684  # -------------------
1685      -        $CAT > /tmp/find_disks.awk <<EOF
     1685 +        cat > /tmp/find_disks.awk <<EOF
1686 1686  #!/bin/nawk -f
1687 1687          BEGIN { FS="."; }
1688 1688  
1689 1689          /^Specify disk/{
1690 1690                  searchdisks=0;
1691 1691          }
1692 1692  
1693 1693          {
1694 1694                  if (searchdisks && \$2 !~ "^$"){
1695 1695                          split(\$2,arr," ");
1696 1696                          print arr[1];
1697 1697                  }
1698 1698          }
1699 1699  
1700 1700          /^AVAILABLE DISK SELECTIONS:/{
1701 1701                  searchdisks=1;
1702 1702          }
1703 1703  EOF
1704 1704  #---------------------
1705 1705  
1706      -        $CHMOD 755 /tmp/find_disks.awk
1707      -        disks=${@:-$($ECHO "" | $FORMAT -e 2>/dev/null | /tmp/find_disks.awk)}
1708      -        $RM /tmp/find_disks.awk
     1706 +        chmod 755 /tmp/find_disks.awk
     1707 +        disks=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
     1708 +        rm /tmp/find_disks.awk
1709 1709  
1710 1710          unused=""
1711 1711          for disk in $disks; do
1712 1712          # Check for mounted
1713      -                $GREP "${disk}[sp]" /etc/mnttab >/dev/null
     1713 +                grep "${disk}[sp]" /etc/mnttab >/dev/null
1714 1714                  (($? == 0)) && continue
1715 1715          # Check for swap
1716      -                $GREP "${disk}[sp]" $sfi >/dev/null
     1716 +                grep "${disk}[sp]" $sfi >/dev/null
1717 1717                  (($? == 0)) && continue
1718 1718          # check for dump device
1719      -                $GREP "${disk}[sp]" $dmpi >/dev/null
     1719 +                grep "${disk}[sp]" $dmpi >/dev/null
1720 1720                  (($? == 0)) && continue
1721 1721          # check to see if this disk hasn't been explicitly excluded
1722 1722          # by a user-set environment variable
1723      -                $ECHO "${ZFS_HOST_DEVICES_IGNORE}" | $GREP "${disk}" > /dev/null
     1723 +                echo "${ZFS_HOST_DEVICES_IGNORE}" | grep "${disk}" > /dev/null
1724 1724                  (($? == 0)) && continue
1725 1725                  unused_candidates="$unused_candidates $disk"
1726 1726          done
1727      -        $RM $sfi
1728      -        $RM $dmpi
     1727 +        rm $sfi
     1728 +        rm $dmpi
1729 1729  
1730 1730  # now just check to see if those disks do actually exist
1731 1731  # by looking for a device pointing to the first slice in
1732 1732  # each case. limit the number to max_finddisksnum
1733 1733          count=0
1734 1734          for disk in $unused_candidates; do
1735 1735                  if [ -b /dev/dsk/${disk}s0 ]; then
1736 1736                  if [ $count -lt $max_finddisksnum ]; then
1737 1737                          unused="$unused $disk"
1738 1738                          # do not impose limit if $@ is provided
1739 1739                          [[ -z $@ ]] && ((count = count + 1))
1740 1740                  fi
1741 1741                  fi
1742 1742          done
1743 1743  
1744 1744  # finally, return our disk list
1745      -        $ECHO $unused
     1745 +        echo $unused
1746 1746  }
1747 1747  
1748 1748  #
1749 1749  # Add specified user to specified group
1750 1750  #
1751 1751  # $1 group name
1752 1752  # $2 user name
1753 1753  # $3 base of the homedir (optional)
1754 1754  #
1755 1755  function add_user #<group_name> <user_name> <basedir>
1756 1756  {
1757 1757          typeset gname=$1
1758 1758          typeset uname=$2
1759 1759          typeset basedir=${3:-"/var/tmp"}
1760 1760  
1761 1761          if ((${#gname} == 0 || ${#uname} == 0)); then
1762 1762                  log_fail "group name or user name are not defined."
1763 1763          fi
1764 1764  
1765      -        log_must $USERADD -g $gname -d $basedir/$uname -m $uname
     1765 +        log_must useradd -g $gname -d $basedir/$uname -m $uname
1766 1766  
1767 1767          return 0
1768 1768  }
1769 1769  
1770 1770  #
1771 1771  # Delete the specified user.
1772 1772  #
1773 1773  # $1 login name
1774 1774  # $2 base of the homedir (optional)
1775 1775  #
1776 1776  function del_user #<logname> <basedir>
1777 1777  {
1778 1778          typeset user=$1
1779 1779          typeset basedir=${2:-"/var/tmp"}
1780 1780  
1781 1781          if ((${#user} == 0)); then
1782 1782                  log_fail "login name is necessary."
1783 1783          fi
1784 1784  
1785      -        if $ID $user > /dev/null 2>&1; then
1786      -                log_must $USERDEL $user
     1785 +        if id $user > /dev/null 2>&1; then
     1786 +                log_must userdel $user
1787 1787          fi
1788 1788  
1789      -        [[ -d $basedir/$user ]] && $RM -fr $basedir/$user
     1789 +        [[ -d $basedir/$user ]] && rm -fr $basedir/$user
1790 1790  
1791 1791          return 0
1792 1792  }
1793 1793  
1794 1794  #
1795 1795  # Select valid gid and create specified group.
1796 1796  #
1797 1797  # $1 group name
1798 1798  #
1799 1799  function add_group #<group_name>
1800 1800  {
1801 1801          typeset group=$1
1802 1802  
1803 1803          if ((${#group} == 0)); then
1804 1804                  log_fail "group name is necessary."
1805 1805          fi
1806 1806  
1807 1807          # Assign 100 as the base gid
1808 1808          typeset -i gid=100
1809 1809          while true; do
1810      -                $GROUPADD -g $gid $group > /dev/null 2>&1
     1810 +                groupadd -g $gid $group > /dev/null 2>&1
1811 1811                  typeset -i ret=$?
1812 1812                  case $ret in
1813 1813                          0) return 0 ;;
1814 1814                          # The gid is not  unique
1815 1815                          4) ((gid += 1)) ;;
1816 1816                          *) return 1 ;;
1817 1817                  esac
1818 1818          done
1819 1819  }
1820 1820  
↓ open down ↓ 2 lines elided ↑ open up ↑
1823 1823  #
1824 1824  # $1 group name
1825 1825  #
1826 1826  function del_group #<group_name>
1827 1827  {
1828 1828          typeset grp=$1
1829 1829          if ((${#grp} == 0)); then
1830 1830                  log_fail "group name is necessary."
1831 1831          fi
1832 1832  
1833      -        $GROUPMOD -n $grp $grp > /dev/null 2>&1
     1833 +        groupmod -n $grp $grp > /dev/null 2>&1
1834 1834          typeset -i ret=$?
1835 1835          case $ret in
1836 1836                  # Group does not exist.
1837 1837                  6) return 0 ;;
1838 1838                  # Name already exists as a group name
1839      -                9) log_must $GROUPDEL $grp ;;
     1839 +                9) log_must groupdel $grp ;;
1840 1840                  *) return 1 ;;
1841 1841          esac
1842 1842  
1843 1843          return 0
1844 1844  }
1845 1845  
1846 1846  #
1847 1847  # This function will return true if it's safe to destroy the pool passed
1848 1848  # as argument 1. It checks for pools based on zvols and files, and also
1849 1849  # files contained in a pool that may have a different mountpoint.
↓ open down ↓ 1 lines elided ↑ open up ↑
1851 1851  function safe_to_destroy_pool { # $1 the pool name
1852 1852  
1853 1853          typeset pool=""
1854 1854          typeset DONT_DESTROY=""
1855 1855  
1856 1856          # We check that by deleting the $1 pool, we're not
1857 1857          # going to pull the rug out from other pools. Do this
1858 1858          # by looking at all other pools, ensuring that they
1859 1859          # aren't built from files or zvols contained in this pool.
1860 1860  
1861      -        for pool in $($ZPOOL list -H -o name)
     1861 +        for pool in $(zpool list -H -o name)
1862 1862          do
1863 1863                  ALTMOUNTPOOL=""
1864 1864  
1865 1865                  # this is a list of the top-level directories in each of the
1866 1866                  # files that make up the path to the files the pool is based on
1867      -                FILEPOOL=$($ZPOOL status -v $pool | $GREP /$1/ | \
1868      -                        $AWK '{print $1}')
     1867 +                FILEPOOL=$(zpool status -v $pool | grep /$1/ | \
     1868 +                        awk '{print $1}')
1869 1869  
1870 1870                  # this is a list of the zvols that make up the pool
1871      -                ZVOLPOOL=$($ZPOOL status -v $pool | $GREP "/dev/zvol/dsk/$1$" \
1872      -                    | $AWK '{print $1}')
     1871 +                ZVOLPOOL=$(zpool status -v $pool | grep "/dev/zvol/dsk/$1$" \
     1872 +                    | awk '{print $1}')
1873 1873  
1874 1874                  # also want to determine if it's a file-based pool using an
1875 1875                  # alternate mountpoint...
1876      -                POOL_FILE_DIRS=$($ZPOOL status -v $pool | \
1877      -                                        $GREP / | $AWK '{print $1}' | \
1878      -                                        $AWK -F/ '{print $2}' | $GREP -v "dev")
     1876 +                POOL_FILE_DIRS=$(zpool status -v $pool | \
     1877 +                                        grep / | awk '{print $1}' | \
     1878 +                                        awk -F/ '{print $2}' | grep -v "dev")
1879 1879  
1880 1880                  for pooldir in $POOL_FILE_DIRS
1881 1881                  do
1882      -                        OUTPUT=$($ZFS list -H -r -o mountpoint $1 | \
1883      -                                        $GREP "${pooldir}$" | $AWK '{print $1}')
     1882 +                        OUTPUT=$(zfs list -H -r -o mountpoint $1 | \
     1883 +                                        grep "${pooldir}$" | awk '{print $1}')
1884 1884  
1885 1885                          ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}"
1886 1886                  done
1887 1887  
1888 1888  
1889 1889                  if [ ! -z "$ZVOLPOOL" ]
1890 1890                  then
1891 1891                          DONT_DESTROY="true"
1892 1892                          log_note "Pool $pool is built from $ZVOLPOOL on $1"
1893 1893                  fi
↓ open down ↓ 29 lines elided ↑ open up ↑
1923 1923          typeset COMPRESS_OPTS
1924 1924          typeset GZIP_OPTS="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
1925 1925                          gzip-6 gzip-7 gzip-8 gzip-9"
1926 1926  
1927 1927          if [[ $1 == "zfs_compress" ]] ; then
1928 1928                  COMPRESS_OPTS="on lzjb"
1929 1929          elif [[ $1 == "zfs_set" ]] ; then
1930 1930                  COMPRESS_OPTS="on off lzjb"
1931 1931          fi
1932 1932          typeset valid_opts="$COMPRESS_OPTS"
1933      -        $ZFS get 2>&1 | $GREP gzip >/dev/null 2>&1
     1933 +        zfs get 2>&1 | grep gzip >/dev/null 2>&1
1934 1934          if [[ $? -eq 0 ]]; then
1935 1935                  valid_opts="$valid_opts $GZIP_OPTS"
1936 1936          fi
1937      -        $ECHO "$valid_opts"
     1937 +        echo "$valid_opts"
1938 1938  }
1939 1939  
1940 1940  #
1941 1941  # Verify zfs operation with -p option work as expected
1942 1942  # $1 operation, value could be create, clone or rename
1943 1943  # $2 dataset type, value could be fs or vol
1944 1944  # $3 dataset name
1945 1945  # $4 new dataset name
1946 1946  #
1947 1947  function verify_opt_p_ops
↓ open down ↓ 32 lines elided ↑ open up ↑
1980 1980                          log_must datasetexists $dataset
1981 1981                          log_mustnot snapexists $dataset
1982 1982                          ;;
1983 1983                  *)
1984 1984                          log_fail "$ops is not supported."
1985 1985                          ;;
1986 1986          esac
1987 1987  
1988 1988          # make sure the upper level filesystem does not exist
1989 1989          if datasetexists ${newdataset%/*} ; then
1990      -                log_must $ZFS destroy -rRf ${newdataset%/*}
     1990 +                log_must zfs destroy -rRf ${newdataset%/*}
1991 1991          fi
1992 1992  
1993 1993          # without -p option, operation will fail
1994      -        log_mustnot $ZFS $ops $dataset $newdataset
     1994 +        log_mustnot zfs $ops $dataset $newdataset
1995 1995          log_mustnot datasetexists $newdataset ${newdataset%/*}
1996 1996  
1997 1997          # with -p option, operation should succeed
1998      -        log_must $ZFS $ops -p $dataset $newdataset
     1998 +        log_must zfs $ops -p $dataset $newdataset
1999 1999          if ! datasetexists $newdataset ; then
2000 2000                  log_fail "-p option does not work for $ops"
2001 2001          fi
2002 2002  
2003 2003          # when $ops is create or clone, redo the operation still return zero
2004 2004          if [[ $ops != "rename" ]]; then
2005      -                log_must $ZFS $ops -p $dataset $newdataset
     2005 +                log_must zfs $ops -p $dataset $newdataset
2006 2006          fi
2007 2007  
2008 2008          return 0
2009 2009  }
2010 2010  
2011 2011  #
2012 2012  # Get configuration of pool
2013 2013  # $1 pool name
2014 2014  # $2 config name
2015 2015  #
2016 2016  function get_config
2017 2017  {
2018 2018          typeset pool=$1
2019 2019          typeset config=$2
2020 2020          typeset alt_root
2021 2021  
2022 2022          if ! poolexists "$pool" ; then
2023 2023                  return 1
2024 2024          fi
2025      -        alt_root=$($ZPOOL list -H $pool | $AWK '{print $NF}')
     2025 +        alt_root=$(zpool list -H $pool | awk '{print $NF}')
2026 2026          if [[ $alt_root == "-" ]]; then
2027      -                value=$($ZDB -C $pool | $GREP "$config:" | $AWK -F: \
     2027 +                value=$(zdb -C $pool | grep "$config:" | awk -F: \
2028 2028                      '{print $2}')
2029 2029          else
2030      -                value=$($ZDB -e $pool | $GREP "$config:" | $AWK -F: \
     2030 +                value=$(zdb -e $pool | grep "$config:" | awk -F: \
2031 2031                      '{print $2}')
2032 2032          fi
2033 2033          if [[ -n $value ]] ; then
2034 2034                  value=${value#'}
2035 2035                  value=${value%'}
2036 2036          fi
2037 2037          echo $value
2038 2038  
2039 2039          return 0
2040 2040  }
↓ open down ↓ 6 lines elided ↑ open up ↑
2047 2047  #
2048 2048  function _random_get
2049 2049  {
2050 2050          typeset cnt=$1
2051 2051          shift
2052 2052  
2053 2053          typeset str="$@"
2054 2054          typeset -i ind
2055 2055          ((ind = RANDOM % cnt + 1))
2056 2056  
2057      -        typeset ret=$($ECHO "$str" | $CUT -f $ind -d ' ')
2058      -        $ECHO $ret
     2057 +        typeset ret=$(echo "$str" | cut -f $ind -d ' ')
     2058 +        echo $ret
2059 2059  }
2060 2060  
2061 2061  #
2062 2062  # Random select one of item from arguments which include NONE string
2063 2063  #
2064 2064  function random_get_with_non
2065 2065  {
2066 2066          typeset -i cnt=$#
2067 2067          ((cnt =+ 1))
2068 2068  
↓ open down ↓ 11 lines elided ↑ open up ↑
2080 2080  #
2081 2081  # Detect if the current system support slog
2082 2082  #
2083 2083  function verify_slog_support
2084 2084  {
2085 2085          typeset dir=/tmp/disk.$$
2086 2086          typeset pool=foo.$$
2087 2087          typeset vdev=$dir/a
2088 2088          typeset sdev=$dir/b
2089 2089  
2090      -        $MKDIR -p $dir
2091      -        $MKFILE $MINVDEVSIZE $vdev $sdev
     2090 +        mkdir -p $dir
     2091 +        mkfile $MINVDEVSIZE $vdev $sdev
2092 2092  
2093 2093          typeset -i ret=0
2094      -        if ! $ZPOOL create -n $pool $vdev log $sdev > /dev/null 2>&1; then
     2094 +        if ! zpool create -n $pool $vdev log $sdev > /dev/null 2>&1; then
2095 2095                  ret=1
2096 2096          fi
2097      -        $RM -r $dir
     2097 +        rm -r $dir
2098 2098  
2099 2099          return $ret
2100 2100  }
2101 2101  
2102 2102  #
2103 2103  # The function will generate a dataset name with specific length
2104 2104  # $1, the length of the name
2105 2105  # $2, the base string to construct the name
2106 2106  #
2107 2107  function gen_dataset_name
↓ open down ↓ 8 lines elided ↑ open up ↑
2116 2116                  ((iter = len / baselen))
2117 2117          else
2118 2118                  ((iter = len / baselen + 1))
2119 2119          fi
2120 2120          while ((iter > 0)); do
2121 2121                  l_name="${l_name}$basestr"
2122 2122  
2123 2123                  ((iter -= 1))
2124 2124          done
2125 2125  
2126      -        $ECHO $l_name
     2126 +        echo $l_name
2127 2127  }
2128 2128  
2129 2129  #
2130 2130  # Get cksum tuple of dataset
2131 2131  # $1 dataset name
2132 2132  #
2133 2133  # sample zdb output:
2134 2134  # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2135 2135  # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2136 2136  # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2137 2137  # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2138 2138  function datasetcksum
2139 2139  {
2140 2140          typeset cksum
2141      -        $SYNC
2142      -        cksum=$($ZDB -vvv $1 | $GREP "^Dataset $1 \[" | $GREP "cksum" \
2143      -                | $AWK -F= '{print $7}')
2144      -        $ECHO $cksum
     2141 +        sync
     2142 +        cksum=$(zdb -vvv $1 | grep "^Dataset $1 \[" | grep "cksum" \
     2143 +                | awk -F= '{print $7}')
     2144 +        echo $cksum
2145 2145  }
2146 2146  
2147 2147  #
2148 2148  # Get cksum of file
2149 2149  # #1 file path
2150 2150  #
2151 2151  function checksum
2152 2152  {
2153 2153          typeset cksum
2154      -        cksum=$($CKSUM $1 | $AWK '{print $1}')
2155      -        $ECHO $cksum
     2154 +        cksum=$(cksum $1 | awk '{print $1}')
     2155 +        echo $cksum
2156 2156  }
2157 2157  
2158 2158  #
2159 2159  # Get the given disk/slice state from the specific field of the pool
2160 2160  #
2161 2161  function get_device_state #pool disk field("", "spares","logs")
2162 2162  {
2163 2163          typeset pool=$1
2164 2164          typeset disk=${2#/dev/dsk/}
2165 2165          typeset field=${3:-$pool}
2166 2166  
2167      -        state=$($ZPOOL status -v "$pool" 2>/dev/null | \
2168      -                $NAWK -v device=$disk -v pool=$pool -v field=$field \
     2167 +        state=$(zpool status -v "$pool" 2>/dev/null | \
     2168 +                nawk -v device=$disk -v pool=$pool -v field=$field \
2169 2169                  'BEGIN {startconfig=0; startfield=0; }
2170 2170                  /config:/ {startconfig=1}
2171 2171                  (startconfig==1) && ($1==field) {startfield=1; next;}
2172 2172                  (startfield==1) && ($1==device) {print $2; exit;}
2173 2173                  (startfield==1) &&
2174 2174                  ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2175 2175          echo $state
2176 2176  }
2177 2177  
2178 2178  
↓ open down ↓ 7 lines elided ↑ open up ↑
2186 2186          typeset dir=$1
2187 2187  
2188 2188          if [[ -z $dir ]]; then
2189 2189                  log_fail "Usage: get_fstype <directory>"
2190 2190          fi
2191 2191  
2192 2192          #
2193 2193          #  $ df -n /
2194 2194          #  /              : ufs
2195 2195          #
2196      -        $DF -n $dir | $AWK '{print $3}'
     2196 +        df -n $dir | awk '{print $3}'
2197 2197  }
2198 2198  
2199 2199  #
2200 2200  # Given a disk, label it to VTOC regardless what label was on the disk
2201 2201  # $1 disk
2202 2202  #
2203 2203  function labelvtoc
2204 2204  {
2205 2205          typeset disk=$1
2206 2206          if [[ -z $disk ]]; then
2207 2207                  log_fail "The disk name is unspecified."
2208 2208          fi
2209 2209          typeset label_file=/var/tmp/labelvtoc.$$
2210      -        typeset arch=$($UNAME -p)
     2210 +        typeset arch=$(uname -p)
2211 2211  
2212 2212          if [[ $arch == "i386" ]]; then
2213      -                $ECHO "label" > $label_file
2214      -                $ECHO "0" >> $label_file
2215      -                $ECHO "" >> $label_file
2216      -                $ECHO "q" >> $label_file
2217      -                $ECHO "q" >> $label_file
     2213 +                echo "label" > $label_file
     2214 +                echo "0" >> $label_file
     2215 +                echo "" >> $label_file
     2216 +                echo "q" >> $label_file
     2217 +                echo "q" >> $label_file
2218 2218  
2219      -                $FDISK -B $disk >/dev/null 2>&1
     2219 +                fdisk -B $disk >/dev/null 2>&1
2220 2220                  # wait a while for fdisk finishes
2221      -                $SLEEP 60
     2221 +                sleep 60
2222 2222          elif [[ $arch == "sparc" ]]; then
2223      -                $ECHO "label" > $label_file
2224      -                $ECHO "0" >> $label_file
2225      -                $ECHO "" >> $label_file
2226      -                $ECHO "" >> $label_file
2227      -                $ECHO "" >> $label_file
2228      -                $ECHO "q" >> $label_file
     2223 +                echo "label" > $label_file
     2224 +                echo "0" >> $label_file
     2225 +                echo "" >> $label_file
     2226 +                echo "" >> $label_file
     2227 +                echo "" >> $label_file
     2228 +                echo "q" >> $label_file
2229 2229          else
2230 2230                  log_fail "unknown arch type"
2231 2231          fi
2232 2232  
2233      -        $FORMAT -e -s -d $disk -f $label_file
     2233 +        format -e -s -d $disk -f $label_file
2234 2234          typeset -i ret_val=$?
2235      -        $RM -f $label_file
     2235 +        rm -f $label_file
2236 2236          #
2237 2237          # wait the format to finish
2238 2238          #
2239      -        $SLEEP 60
     2239 +        sleep 60
2240 2240          if ((ret_val != 0)); then
2241 2241                  log_fail "unable to label $disk as VTOC."
2242 2242          fi
2243 2243  
2244 2244          return 0
2245 2245  }
2246 2246  
2247 2247  #
2248 2248  # check if the system was installed as zfsroot or not
2249 2249  # return: 0 ture, otherwise false
2250 2250  #
2251 2251  function is_zfsroot
2252 2252  {
2253      -        $DF -n / | $GREP zfs > /dev/null 2>&1
     2253 +        df -n / | grep zfs > /dev/null 2>&1
2254 2254          return $?
2255 2255  }
2256 2256  
2257 2257  #
2258 2258  # get the root filesystem name if it's zfsroot system.
2259 2259  #
2260 2260  # return: root filesystem name
2261 2261  function get_rootfs
2262 2262  {
2263 2263          typeset rootfs=""
2264      -        rootfs=$($AWK '{if ($2 == "/" && $3 == "zfs") print $1}' \
     2264 +        rootfs=$(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2265 2265                  /etc/mnttab)
2266 2266          if [[ -z "$rootfs" ]]; then
2267 2267                  log_fail "Can not get rootfs"
2268 2268          fi
2269      -        $ZFS list $rootfs > /dev/null 2>&1
     2269 +        zfs list $rootfs > /dev/null 2>&1
2270 2270          if (($? == 0)); then
2271      -                $ECHO $rootfs
     2271 +                echo $rootfs
2272 2272          else
2273 2273                  log_fail "This is not a zfsroot system."
2274 2274          fi
2275 2275  }
2276 2276  
2277 2277  #
2278 2278  # get the rootfs's pool name
2279 2279  # return:
2280 2280  #       rootpool name
2281 2281  #
2282 2282  function get_rootpool
2283 2283  {
2284 2284          typeset rootfs=""
2285 2285          typeset rootpool=""
2286      -        rootfs=$($AWK '{if ($2 == "/" && $3 =="zfs") print $1}' \
     2286 +        rootfs=$(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2287 2287                   /etc/mnttab)
2288 2288          if [[ -z "$rootfs" ]]; then
2289 2289                  log_fail "Can not get rootpool"
2290 2290          fi
2291      -        $ZFS list $rootfs > /dev/null 2>&1
     2291 +        zfs list $rootfs > /dev/null 2>&1
2292 2292          if (($? == 0)); then
2293      -                rootpool=`$ECHO $rootfs | awk -F\/ '{print $1}'`
2294      -                $ECHO $rootpool
     2293 +                rootpool=`echo $rootfs | awk -F\/ '{print $1}'`
     2294 +                echo $rootpool
2295 2295          else
2296 2296                  log_fail "This is not a zfsroot system."
2297 2297          fi
2298 2298  }
2299 2299  
2300 2300  #
2301 2301  # Check if the given device is physical device
2302 2302  #
2303 2303  function is_physical_device #device
2304 2304  {
2305 2305          typeset device=${1#/dev/dsk/}
2306 2306          device=${device#/dev/rdsk/}
2307 2307  
2308      -        $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
     2308 +        echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
2309 2309          return $?
2310 2310  }
2311 2311  
2312 2312  #
2313 2313  # Get the directory path of given device
2314 2314  #
2315 2315  function get_device_dir #device
2316 2316  {
2317 2317          typeset device=$1
2318 2318  
2319 2319          if ! $(is_physical_device $device) ; then
2320 2320                  if [[ $device != "/" ]]; then
2321 2321                          device=${device%/*}
2322 2322                  fi
2323      -                $ECHO $device
     2323 +                echo $device
2324 2324          else
2325      -                $ECHO "/dev/dsk"
     2325 +                echo "/dev/dsk"
2326 2326          fi
2327 2327  }
2328 2328  
2329 2329  #
2330 2330  # Get the package name
2331 2331  #
2332 2332  function get_package_name
2333 2333  {
2334 2334          typeset dirpath=${1:-$STC_NAME}
2335 2335  
2336 2336          echo "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g"
2337 2337  }
2338 2338  
2339 2339  #
2340 2340  # Get the word numbers from a string separated by white space
2341 2341  #
2342 2342  function get_word_count
2343 2343  {
2344      -        $ECHO $1 | $WC -w
     2344 +        echo $1 | wc -w
2345 2345  }
2346 2346  
2347 2347  #
2348 2348  # To verify if the require numbers of disks is given
2349 2349  #
2350 2350  function verify_disk_count
2351 2351  {
2352 2352          typeset -i min=${2:-1}
2353 2353  
2354 2354          typeset -i count=$(get_word_count "$1")
↓ open down ↓ 23 lines elided ↑ open up ↑
2378 2378          typeset type=$(get_prop type $1)
2379 2379          [[ $type = "snapshot" ]] && return 0
2380 2380          return 1
2381 2381  }
2382 2382  
2383 2383  #
2384 2384  # Check if Trusted Extensions are installed and enabled
2385 2385  #
2386 2386  function is_te_enabled
2387 2387  {
2388      -        $SVCS -H -o state labeld 2>/dev/null | $GREP "enabled"
     2388 +        svcs -H -o state labeld 2>/dev/null | grep "enabled"
2389 2389          if (($? != 0)); then
2390 2390                  return 1
2391 2391          else
2392 2392                  return 0
2393 2393          fi
2394 2394  }
2395 2395  
2396 2396  # Utility function to determine if a system has multiple cpus.
2397 2397  function is_mp
2398 2398  {
2399      -        (($($PSRINFO | $WC -l) > 1))
     2399 +        (($(psrinfo | wc -l) > 1))
2400 2400  }
2401 2401  
2402 2402  function get_cpu_freq
2403 2403  {
2404      -        $PSRINFO -v 0 | $AWK '/processor operates at/ {print $6}'
     2404 +        psrinfo -v 0 | awk '/processor operates at/ {print $6}'
2405 2405  }
2406 2406  
2407 2407  # Run the given command as the user provided.
2408 2408  function user_run
2409 2409  {
2410 2410          typeset user=$1
2411 2411          shift
2412 2412  
2413      -        eval \$SU \$user -c \"$@\" > /tmp/out 2>/tmp/err
     2413 +        eval su \$user -c \"$@\" > /tmp/out 2>/tmp/err
2414 2414          return $?
2415 2415  }
2416 2416  
2417 2417  #
2418 2418  # Check if the pool contains the specified vdevs
2419 2419  #
2420 2420  # $1 pool
2421 2421  # $2..n <vdev> ...
2422 2422  #
2423 2423  # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
↓ open down ↓ 4 lines elided ↑ open up ↑
2428 2428          typeset pool=$1
2429 2429          typeset vdev
2430 2430  
2431 2431          if [[ -z $pool ]]; then
2432 2432                  log_note "Missing pool name."
2433 2433                  return 2
2434 2434          fi
2435 2435  
2436 2436          shift
2437 2437  
2438      -        typeset tmpfile=$($MKTEMP)
2439      -        $ZPOOL list -Hv "$pool" >$tmpfile
     2438 +        typeset tmpfile=$(mktemp)
     2439 +        zpool list -Hv "$pool" >$tmpfile
2440 2440          for vdev in $@; do
2441      -                $GREP -w ${vdev##*/} $tmpfile >/dev/null 2>&1
     2441 +                grep -w ${vdev##*/} $tmpfile >/dev/null 2>&1
2442 2442                  [[ $? -ne 0 ]] && return 1
2443 2443          done
2444 2444  
2445      -        $RM -f $tmpfile
     2445 +        rm -f $tmpfile
2446 2446  
2447 2447          return 0;
2448 2448  }
2449 2449  
2450 2450  function get_max
2451 2451  {
2452 2452          typeset -l i max=$1
2453 2453          shift
2454 2454  
2455 2455          for i in "$@"; do
↓ open down ↓ 17 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX