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