1#!/usr/bin/ksh 2 3# 4# This file and its contents are supplied under the terms of the 5# Common Development and Distribution License ("CDDL"), version 1.0. 6# You may only use this file in accordance with the terms of version 7# 1.0 of the CDDL. 8# 9# A full copy of the text of the CDDL should have accompanied this 10# source. A copy of the CDDL is also available via the Internet at 11# http://www.illumos.org/license/CDDL. 12# 13 14# 15# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 16# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved. 17# Copyright 2016 Nexenta Systems, Inc. 18# 19 20export NOINUSE_CHECK=1 21export STF_SUITE="/opt/zfs-tests" 22export STF_TOOLS="/opt/test-runner/stf" 23runner="/opt/test-runner/bin/run" 24auto_detect=false 25 26if [[ -z "$TESTFAIL_CALLBACKS" ]] ; then 27 export TESTFAIL_CALLBACKS="$STF_SUITE/callbacks/zfs_dbgmsg.ksh" 28fi 29 30function fail 31{ 32 echo $1 33 exit ${2:-1} 34} 35 36function find_disks 37{ 38 typeset all_disks=$(echo '' | sudo -k /usr/sbin/format | awk \ 39 '/c[0-9]/ {print $2}') 40 typeset used_disks=$(/sbin/zpool status | awk \ 41 '/c[0-9]*t[0-9a-f]*d[0-9]/ {print $1}' | sed 's/s[0-9]//g') 42 43 typeset disk used avail_disks 44 for disk in $all_disks; do 45 for used in $used_disks; do 46 [[ "$disk" = "$used" ]] && continue 2 47 done 48 [[ -n $avail_disks ]] && avail_disks="$avail_disks $disk" 49 [[ -z $avail_disks ]] && avail_disks="$disk" 50 done 51 52 echo $avail_disks 53} 54 55function find_rpool 56{ 57 typeset ds=$(/usr/sbin/mount | awk '/^\/ / {print $3}') 58 echo ${ds%%/*} 59} 60 61function find_runfile 62{ 63 typeset distro= 64 if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then 65 distro=delphix 66 elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then 67 distro=openindiana 68 elif [[ 0 -ne $(grep -c OmniOS /etc/release 2>/dev/null) ]]; then 69 distro=omnios 70 fi 71 72 [[ -n $distro ]] && echo $STF_SUITE/runfiles/$distro.run 73} 74 75function verify_id 76{ 77 [[ $(id -u) = "0" ]] && fail "This script must not be run as root." 78 79 sudo -k -n id >/dev/null 2>&1 80 [[ $? -eq 0 ]] || fail "User must be able to sudo without a password." 81} 82 83function verify_disks 84{ 85 typeset disk 86 for disk in $DISKS; do 87 sudo -k /usr/sbin/prtvtoc /dev/rdsk/${disk}s0 >/dev/null 2>&1 88 [[ $? -eq 0 ]] || return 1 89 done 90 return 0 91} 92 93verify_id 94 95while getopts ac:q c; do 96 case $c in 97 'a') 98 auto_detect=true 99 ;; 100 'c') 101 runfile=$OPTARG 102 [[ -f $runfile ]] || fail "Cannot read file: $runfile" 103 ;; 104 'q') 105 quiet='-q' 106 ;; 107 esac 108done 109shift $((OPTIND - 1)) 110 111# If the user specified -a, then use free disks, otherwise use those in $DISKS. 112if $auto_detect; then 113 export DISKS=$(find_disks) 114elif [[ -z $DISKS ]]; then 115 fail "\$DISKS not set in env, and -a not specified." 116else 117 verify_disks || fail "Couldn't verify all the disks in \$DISKS" 118fi 119 120# Add the root pool to $KEEP according to its contents. 121# It's ok to list it twice. 122if [[ -z $KEEP ]]; then 123 KEEP="$(find_rpool)" 124else 125 KEEP+=" $(find_rpool)" 126fi 127 128export __ZFS_POOL_EXCLUDE="$KEEP" 129export KEEP="^$(echo $KEEP | sed 's/ /$|^/g')\$" 130 131[[ -z $runfile ]] && runfile=$(find_runfile) 132[[ -z $runfile ]] && fail "Couldn't determine distro" 133 134. $STF_SUITE/include/default.cfg 135 136num_disks=$(echo $DISKS | awk '{print NF}') 137[[ $num_disks -lt 3 ]] && fail "Not enough disks to run ZFS Test Suite" 138 139# Ensure user has only basic privileges. 140/usr/bin/ppriv -s EIP=basic -e $runner $quiet -c $runfile 141 142exit $? 143