Index: projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib (revision 292298) @@ -1,2857 +1,2871 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)libtest.kshlib 1.15 09/08/06 SMI" # . ${STF_SUITE}/include/logapi.kshlib ZFS=${ZFS:-/sbin/zfs} ZPOOL=${ZPOOL:-/sbin/zpool} os_name=`uname -s` # Determine if a test has the necessary requirements to run function test_requires { integer unsupported=0 unsupported_list="" until [[ $# -eq 0 ]];do var_name=$1 cmd=$(eval echo \$${1}) if [[ ! "$cmd" != "" ]] ; then print $var_name is not set unsupported_list="$var_name $unsupported_list" ((unsupported=unsupported+1)) fi shift done if [[ unsupported -gt 0 ]] ; then log_unsupported "$unsupported_list commands are unsupported" else log_note "All commands are supported" fi } # Determine whether a dataset is mounted # # $1 dataset name # $2 filesystem type; optional - defaulted to zfs # # Return 0 if dataset is mounted; 1 if unmounted; 2 on error function ismounted { typeset fstype=$2 [[ -z $fstype ]] && fstype=zfs typeset out dir name ret case $fstype in zfs) if [[ "$1" == "/"* ]] ; then for out in $($ZFS mount | $AWK '{print $2}') ; do [[ $1 == $out ]] && return 0 done else for out in $($ZFS mount | $AWK '{print $1}') ; do [[ $1 == $out ]] && return 0 done fi ;; ufs|nfs) # a = device, b = "on", c = mount point", d = flags $MOUNT | $GREP $fstype | while read a b c d do [[ "$1" == "$a" || "$1" == "$c" ]] && return 0 done ;; esac return 1 } # Return 0 if a dataset is mounted; 1 otherwise # # $1 dataset name # $2 filesystem type; optional - defaulted to zfs function mounted { ismounted $1 $2 (( $? == 0 )) && return 0 return 1 } # Return 0 if a dataset is unmounted; 1 otherwise # # $1 dataset name # $2 filesystem type; optional - defaulted to zfs function unmounted { ismounted $1 $2 (( $? == 1 )) && return 0 return 1 } # split line on "," # # $1 - line to split function splitline { $ECHO $1 | $SED "s/,/ /g" } function default_setup { default_setup_noexit "$@" log_pass } # # Given a list of disks, setup storage pools and datasets. # function default_setup_noexit { typeset disklist=$1 typeset container=$2 typeset volume=$3 if is_global_zone; then if poolexists $TESTPOOL ; then destroy_pool $TESTPOOL fi [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL log_must $ZPOOL create -f $TESTPOOL $disklist else reexport_pool fi $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR log_must $ZFS create $TESTPOOL/$TESTFS log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS if [[ -n $container ]]; then $RM -rf $TESTDIR1 || \ log_unresolved Could not remove $TESTDIR1 $MKDIR -p $TESTDIR1 || \ log_unresolved Could not create $TESTDIR1 log_must $ZFS create $TESTPOOL/$TESTCTR log_must $ZFS set canmount=off $TESTPOOL/$TESTCTR log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1 log_must $ZFS set mountpoint=$TESTDIR1 \ $TESTPOOL/$TESTCTR/$TESTFS1 fi if [[ -n $volume ]]; then if is_global_zone ; then log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL else log_must $ZFS create $TESTPOOL/$TESTVOL fi fi } # # Given a list of disks, setup a storage pool, file system and # a container. # function default_container_setup { typeset disklist=$1 default_setup "$disklist" "true" } # # Given a list of disks, setup a storage pool,file system # and a volume. # function default_volume_setup { typeset disklist=$1 default_setup "$disklist" "" "true" } # # Given a list of disks, setup a storage pool,file system, # a container and a volume. # function default_container_volume_setup { typeset disklist=$1 default_setup "$disklist" "true" "true" } # # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on # filesystem # # $1 Existing filesystem or volume name. Default, $TESTFS # $2 snapshot name. Default, $TESTSNAP # function create_snapshot { typeset fs_vol=${1:-$TESTFS} typeset snap=${2:-$TESTSNAP} [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined." [[ -z $snap ]] && log_fail "Snapshot's name is undefined." if snapexists $fs_vol@$snap; then log_fail "$fs_vol@$snap already exists." fi datasetexists $fs_vol || \ log_fail "$fs_vol must exist." log_must $ZFS snapshot $fs_vol@$snap } # # Create a clone from a snapshot, default clone name is $TESTCLONE. # # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default. # $2 Clone name, $TESTPOOL/$TESTCLONE is default. # function create_clone # snapshot clone { typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} typeset clone=${2:-$TESTPOOL/$TESTCLONE} [[ -z $snap ]] && \ log_fail "Snapshot name is undefined." [[ -z $clone ]] && \ log_fail "Clone name is undefined." log_must $ZFS clone $snap $clone } function default_mirror_setup { default_mirror_setup_noexit $1 $2 $3 log_pass } # # Given a pair of disks, set up a storage pool and dataset for the mirror # @parameters: $1 the primary side of the mirror # $2 the secondary side of the mirror # @uses: ZPOOL ZFS TESTPOOL TESTFS function default_mirror_setup_noexit { readonly func="default_mirror_setup_noexit" typeset primary=$1 typeset secondary=$2 [[ -z $primary ]] && \ log_fail "$func: No parameters passed" [[ -z $secondary ]] && \ log_fail "$func: No secondary partition passed" [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL log_must $ZPOOL create -f $TESTPOOL mirror $@ log_must $ZFS create $TESTPOOL/$TESTFS log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } # # create a number of mirrors. # We create a number($1) of 2 way mirrors using the pairs of disks named # on the command line. These mirrors are *not* mounted # @parameters: $1 the number of mirrors to create # $... the devices to use to create the mirrors on # @uses: ZPOOL ZFS TESTPOOL function setup_mirrors { typeset -i nmirrors=$1 shift while (( nmirrors > 0 )); do log_must test -n "$1" -a -n "$2" [[ -d /$TESTPOOL$nmirrors ]] && $RM -rf /$TESTPOOL$nmirrors log_must $ZPOOL create -f $TESTPOOL$nmirrors mirror $1 $2 shift 2 (( nmirrors = nmirrors - 1 )) done } # # create a number of raidz pools. # We create a number($1) of 2 raidz pools using the pairs of disks named # on the command line. These pools are *not* mounted # @parameters: $1 the number of pools to create # $... the devices to use to create the pools on # @uses: ZPOOL ZFS TESTPOOL function setup_raidzs { typeset -i nraidzs=$1 shift while (( nraidzs > 0 )); do log_must test -n "$1" -a -n "$2" [[ -d /$TESTPOOL$nraidzs ]] && $RM -rf /$TESTPOOL$nraidzs log_must $ZPOOL create -f $TESTPOOL$nraidzs raidz $1 $2 shift 2 (( nraidzs = nraidzs - 1 )) done } # # Destroy the configured testpool mirrors. # the mirrors are of the form ${TESTPOOL}{number} # @uses: ZPOOL ZFS TESTPOOL function destroy_mirrors { default_cleanup_noexit log_pass } # # Given a minimum of two disks, set up a storage pool and dataset for the raid-z # $1 the list of disks # function default_raidz_setup { typeset disklist="$*" set -A disks $disklist if [[ ${#disks[*]} -lt 2 ]]; then log_fail "A raid-z requires a minimum of two disks." fi [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL log_must $ZPOOL create -f $TESTPOOL raidz $1 $2 $3 log_must $ZFS create $TESTPOOL/$TESTFS log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_pass } # # Common function used to cleanup storage pools and datasets. # # Invoked at the start of the test suite to ensure the system # is in a known state, and also at the end of each set of # sub-tests to ensure errors from one set of tests doesn't # impact the execution of the next set. function default_cleanup { default_cleanup_noexit log_pass } function all_pools { cmd="$ZPOOL list -H -o name | $GREP -v '$NO_POOLS'" if [[ -n $KEEP ]]; then cmd="$cmd | $EGREP -v '(${KEEP})'" fi eval $cmd } function default_cleanup_noexit { typeset exclude="" typeset pool="" # # Destroying the pool will also destroy any # filesystems it contains. # if is_global_zone; then # Here, we loop through the pools we're allowed to # destroy, only destroying them if it's safe to do # so. for pool in $(all_pools); do if safe_to_destroy_pool $pool; then destroy_pool $pool fi done else typeset fs="" for fs in $($ZFS list -H -o name \ | $GREP "^$ZONE_POOL/$ZONE_CTR[01234]/"); do datasetexists $fs && \ log_must $ZFS destroy -Rf $fs done # Need cleanup here to avoid garbage dir left. for fs in $($ZFS list -H -o name \ ); do [[ $fs == /$ZONE_POOL ]] && continue [[ -d $fs ]] && log_must $RM -rf $fs/* done # # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to # the default value # for fs in $($ZFS list -H -o name \ ); do if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then log_must $ZFS set reservation=none $fs log_must $ZFS set recordsize=128K $fs log_must $ZFS set mountpoint=/$fs $fs typeset enc="" enc=$(get_prop encryption $fs) if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \ [[ "$enc" == "off" ]]; then log_must $ZFS set checksum=on $fs fi log_must $ZFS set compression=off $fs log_must $ZFS set atime=on $fs log_must $ZFS set devices=off $fs log_must $ZFS set exec=on $fs log_must $ZFS set setuid=on $fs log_must $ZFS set readonly=off $fs log_must $ZFS set snapdir=hidden $fs log_must $ZFS set aclmode=groupmask $fs log_must $ZFS set aclinherit=secure $fs fi done fi [[ -d $TESTDIR ]] && \ log_must $RM -rf $TESTDIR } # # Common function used to cleanup storage pools, file systems # and containers. # function default_container_cleanup { if ! is_global_zone; then reexport_pool fi ismounted $TESTPOOL/$TESTCTR/$TESTFS1 [[ $? -eq 0 ]] && \ log_must $ZFS unmount $TESTPOOL/$TESTCTR/$TESTFS1 datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \ log_must $ZFS destroy -R $TESTPOOL/$TESTCTR/$TESTFS1 datasetexists $TESTPOOL/$TESTCTR && \ log_must $ZFS destroy -Rf $TESTPOOL/$TESTCTR [[ -e $TESTDIR1 ]] && \ log_must $RM -rf $TESTDIR1 > /dev/null 2>&1 default_cleanup } # # Common function used to cleanup snapshot of file system or volume. Default to # delete the file system's snapshot # # $1 snapshot name # function destroy_snapshot { typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} if ! snapexists $snap; then log_fail "'$snap' does not existed." fi # # For the sake of the value which come from 'get_prop' is not equal # to the really mountpoint when the snapshot is unmounted. So, firstly # check and make sure this snapshot's been mounted in current system. # typeset mtpt="" if ismounted $snap; then mtpt=$(get_prop mountpoint $snap) (( $? != 0 )) && \ log_fail "get_prop mountpoint $snap failed." fi log_must $ZFS destroy $snap [[ $mtpt != "" && -d $mtpt ]] && \ log_must $RM -rf $mtpt } # # Common function used to cleanup clone. # # $1 clone name # function destroy_clone { typeset clone=${1:-$TESTPOOL/$TESTCLONE} if ! datasetexists $clone; then log_fail "'$clone' does not existed." fi # With the same reason in destroy_snapshot typeset mtpt="" if ismounted $clone; then mtpt=$(get_prop mountpoint $clone) (( $? != 0 )) && \ log_fail "get_prop mountpoint $clone failed." fi log_must $ZFS destroy $clone [[ $mtpt != "" && -d $mtpt ]] && \ log_must $RM -rf $mtpt } # Return 0 if a snapshot exists; $? otherwise # # $1 - snapshot name function snapexists { $ZFS list -H -t snapshot "$1" > /dev/null 2>&1 return $? } # # Set a property to a certain value on a dataset. # Sets a property of the dataset to the value as passed in. # @param: # $1 dataset who's property is being set # $2 property to set # $3 value to set property to # @return: # 0 if the property could be set. # non-zero otherwise. # @use: ZFS # function dataset_setprop { typeset fn=dataset_setprop if (( $# < 3 )); then log_note "$fn: Insufficient parameters (need 3, had $#)" return 1 fi typeset output= output=$($ZFS set $2=$3 $1 2>&1) typeset rv=$? if (( rv != 0 )); then log_note "Setting property on $1 failed." log_note "property $2=$3" log_note "Return Code: $rv" log_note "Output: $output" return $rv fi return 0 } # # Assign suite defined dataset properties. # This function is used to apply the suite's defined default set of # properties to a dataset. # @parameters: $1 dataset to use # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP # @returns: # 0 if the dataset has been altered. # 1 if no pool name was passed in. # 2 if the dataset could not be found. # 3 if the dataset could not have it's properties set. # function dataset_set_defaultproperties { typeset dataset="$1" [[ -z $dataset ]] && return 1 typeset confset= typeset -i found=0 for confset in $($ZFS list); do if [[ $dataset = $confset ]]; then found=1 break fi done [[ $found -eq 0 ]] && return 2 if [[ -n $COMPRESSION_PROP ]]; then dataset_setprop $dataset compression $COMPRESSION_PROP || \ return 3 log_note "Compression set to '$COMPRESSION_PROP' on $dataset" fi if [[ -n $CHECKSUM_PROP && $WRAPPER != *"crypto"* ]]; then dataset_setprop $dataset checksum $CHECKSUM_PROP || \ return 3 log_note "Checksum set to '$CHECKSUM_PROP' on $dataset" fi return 0 } # # Check a numeric assertion # @parameter: $@ the assertion to check # @output: big loud notice if assertion failed # @use: log_fail # function assert { (( $@ )) || log_fail $@ } function wipe_partition_table # [ ...] { while [[ -n $* ]]; do typeset diskname=$1 $GPART destroy -F $diskname >/dev/null 2>&1 shift done } # # Given a slice, size and disk, this function # formats the slice to the specified size. # Size should be specified with units as per # the `format` command requirements eg. 100mb 3gb # function set_partition # { typeset -i slicenum=$1 typeset start=$2 typeset size=$3 typeset disk=$4 set -A devmap a b c d e f g h [[ -z $slicenum || -z $size || -z $disk ]] && \ log_fail "The slice, size or disk name is unspecified." size=`$ECHO $size| sed s/mb/M/` size=`$ECHO $size| sed s/m/M/` size=`$ECHO $size| sed s/gb/G/` size=`$ECHO $size| sed s/g/G/` [[ -n $start ]] && start="-b $start" # Ignore the return value; it will fail if $disk is already partitioned $GPART create -s GPT $disk > /dev/null 2>&1 log_must $GPART add -t efi $start -s $size -i $slicenum $disk return 0 } +function get_disk_size # +{ + typeset disk=$1 + diskinfo da0 | awk '{print $3}' +} + +function get_available_disk_size # +{ + typeset disk=$1 + raw_size=`get_disk_size $disk` + (( available_size = raw_size * 95 / 100 )) + echo $available_size +} + # # Get the end cyl of the given slice # #TODO: fix this to be GPT-compatible if we want to use the SMI WRAPPER. This # function is not necessary on FreeBSD # function get_endslice # { log_fail "get_endslice has not been updated for GPT partitions" } # # Get the first LBA that is beyond the end of the given partition function get_partition_end # { typeset disk=$1 typeset partition_index=$2 export partition_index $GPART show $disk | $AWK \ '/^[ \t]/ && $3 ~ ENVIRON["partition_index"] {print $1 + $2}' } # # Given a size,disk and total number of partitions, this function formats the # disk partitions from 0 to the total partition number with the same specified # size. # function partition_disk # { typeset -i i=1 typeset part_size=$1 typeset disk_name=$2 typeset total_parts=$3 typeset cyl wipe_partition_table $disk_name while (( i <= $total_parts )); do set_partition $i "" $part_size $disk_name (( i = i+1 )) done } function size_of_file # fname { typeset fname=$1 sz=`stat -f '%z' $fname` [[ -z "$sz" ]] && log_fail "stat($fname) failed" $ECHO $sz return 0 } # # This function continues to write to a filenum number of files into dirnum # number of directories until either $FILE_WRITE returns an error or the # maximum number of files per directory have been written. # # Usage: # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data] # # Return value: 0 on success # non 0 on error # # Where : # destdir: is the directory where everything is to be created under # dirnum: the maximum number of subdirectories to use, -1 no limit # filenum: the maximum number of files per subdirectory # bytes: number of bytes to write # num_writes: numer of types to write out bytes # data: the data that will be writen # # E.g. # file_fs /testdir 20 25 1024 256 0 # # Note: bytes * num_writes equals the size of the testfile # function fill_fs # destdir dirnum filenum bytes num_writes data { typeset destdir=${1:-$TESTDIR} typeset -i dirnum=${2:-50} typeset -i filenum=${3:-50} typeset -i bytes=${4:-8192} typeset -i num_writes=${5:-10240} typeset -i data=${6:-0} typeset -i odirnum=1 typeset -i idirnum=0 typeset -i fn=0 typeset -i retval=0 log_must $MKDIR -p $destdir/$idirnum while (( $odirnum > 0 )); do if (( dirnum >= 0 && idirnum >= dirnum )); then odirnum=0 break fi $FILE_WRITE -o create -f $destdir/$idirnum/$TESTFILE.$fn \ -b $bytes -c $num_writes -d $data retval=$? if (( $retval != 0 )); then odirnum=0 break fi if (( $fn >= $filenum )); then fn=0 (( idirnum = idirnum + 1 )) log_must $MKDIR -p $destdir/$idirnum else (( fn = fn + 1 )) fi done return $retval } # # Simple function to get the specified property. If unable to # get the property then exits. # # Note property is in 'parsable' format (-p) # function get_prop # property dataset { typeset prop_val typeset prop=$1 typeset dataset=$2 prop_val=$($ZFS get -pH -o value $prop $dataset 2>/dev/null) if [[ $? -ne 0 ]]; then log_note "Unable to get $prop property for dataset " \ "$dataset" return 1 fi $ECHO $prop_val return 0 } # # Simple function to return the lesser of two values. # function min { typeset first_arg=$1 typeset second_arg=$2 if (( first_arg < second_arg )); then $ECHO $first_arg else $ECHO $second_arg fi return 0 } # # Simple function to get the specified property of pool. If unable to # get the property then exits. # function get_pool_prop # property pool { typeset prop_val typeset prop=$1 typeset pool=$2 if poolexists $pool ; then prop_val=$($ZPOOL get $prop $pool 2>/dev/null | $TAIL -1 | \ $AWK '{print $3}') if [[ $? -ne 0 ]]; then log_note "Unable to get $prop property for pool " \ "$pool" return 1 fi else log_note "Pool $pool not exists." return 1 fi $ECHO $prop_val return 0 } # Return 0 if a pool exists; $? otherwise # # $1 - pool name function poolexists { typeset pool=$1 if [[ -z $pool ]]; then log_note "No pool name given." return 1 fi $ZPOOL list -H "$pool" > /dev/null 2>&1 return $? } # Return 0 if all the specified datasets exist; $? otherwise # # $1-n dataset name function datasetexists { if (( $# == 0 )); then log_note "No dataset name given." return 1 fi while (( $# > 0 )); do $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 || \ return $? shift done return 0 } # return 0 if none of the specified datasets exists, otherwise return 1. # # $1-n dataset name function datasetnonexists { if (( $# == 0 )); then log_note "No dataset name given." return 1 fi while (( $# > 0 )); do $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 && \ return 1 shift done return 0 } # # Given a mountpoint, or a dataset name, determine if it is shared. # # Returns 0 if shared, 1 otherwise. # function is_shared { typeset fs=$1 typeset mtpt if [[ $fs != "/"* ]] ; then if datasetnonexists "$fs" ; then return 1 else mtpt=$(get_prop mountpoint "$fs") case $mtpt in none|legacy|-) return 1 ;; *) fs=$mtpt ;; esac fi fi for mtpt in `$SHARE | $AWK '{print $2}'` ; do if [[ $mtpt == $fs ]] ; then return 0 fi done typeset stat=$($SVCS -H -o STA nfs/server:default) if [[ $stat != "ON" ]]; then log_note "Current nfs/server status: $stat" fi return 1 } # # Given a mountpoint, determine if it is not shared. # # Returns 0 if not shared, 1 otherwise. # function not_shared { typeset fs=$1 is_shared $fs if (( $? == 0)); then return 1 fi return 0 } # # Helper function to unshare a mountpoint. # function unshare_fs #fs { typeset fs=$1 is_shared $fs if (( $? == 0 )); then log_must $ZFS unshare $fs fi return 0 } # # Check NFS server status and trigger it online. # function setup_nfs_server { # Cannot share directory in non-global zone. # if ! is_global_zone; then log_note "Cannot trigger NFS server by sharing in LZ." return fi typeset nfs_fmri="svc:/network/nfs/server:default" if [[ $($SVCS -Ho STA $nfs_fmri) != "ON" ]]; then # # Only really sharing operation can enable NFS server # to online permanently. # typeset dummy=$TMPDIR/dummy if [[ -d $dummy ]]; then log_must $RM -rf $dummy fi log_must $MKDIR $dummy log_must $SHARE $dummy # # Waiting for fmri's status to be the final status. # Otherwise, in transition, an asterisk (*) is appended for # instances, unshare will reverse status to 'DIS' again. # # Waiting for 1's at least. # log_must $SLEEP 1 timeout=10 while [[ timeout -ne 0 && $($SVCS -Ho STA $nfs_fmri) == *'*' ]] do log_must $SLEEP 1 (( timeout -= 1 )) done log_must $UNSHARE $dummy log_must $RM -rf $dummy fi log_note "Current NFS status: '$($SVCS -Ho STA,FMRI $nfs_fmri)'" } # # To verify whether calling process is in global zone # # Return 0 if in global zone, 1 in non-global zone # function is_global_zone { typeset cur_zone=$($ZONENAME 2>/dev/null) # Zones are not supported on FreeBSD. if [[ $os_name == "FreeBSD" ]]; then return 0 fi if [[ $cur_zone != "global" ]]; then return 1 fi return 0 } # # Verify whether test is permit to run from # global zone, local zone, or both # # $1 zone limit, could be "global", "local", or "both"(no limit) # # Return 0 if permit, otherwise exit with log_unsupported # function verify_runnable # zone limit { typeset limit=$1 [[ -z $limit ]] && return 0 if is_global_zone ; then case $limit in global|both) break ;; local) log_unsupported "Test is unable to run from \ global zone." break ;; *) log_note "Warning: unknown limit $limit - use both." ;; esac else case $limit in local|both) break ;; global) log_unsupported "Test is unable to run from \ local zone." break ;; *) log_note "Warning: unknown limit $limit - use both." ;; esac reexport_pool fi return 0 } # Return 0 if create successfully or the pool exists; $? otherwise # Note: In local zones, this function should return 0 silently. # # $1 - pool name # $2-n - [keyword] devs_list function create_pool #pool devs_list { typeset pool=${1%%/*} shift if [[ -z $pool ]]; then log_note "Missing pool name." return 1 fi if poolexists $pool ; then destroy_pool $pool fi if is_global_zone ; then [[ -d /$pool ]] && $RM -rf /$pool log_must $ZPOOL create -f $pool $@ fi return 0 } # Return 0 if destroy successfully or the pool exists; $? otherwise # Note: In local zones, this function should return 0 silently. # # $1 - pool name # Destroy pool with the given parameters. function destroy_pool #pool { typeset pool=${1%%/*} typeset mtpt if [[ -z $pool ]]; then log_note "No pool name given." return 1 fi if is_global_zone ; then if poolexists "$pool" ; then mtpt=$(get_prop mountpoint "$pool") log_must $ZPOOL destroy -f $pool [[ -d $mtpt ]] && \ log_must $RM -rf $mtpt else - log_note "Pool not exist. ($pool)" + log_note "Pool $pool does not exist, skipping destroy." return 1 fi fi return 0 } # # Firstly, create a pool with 5 datasets. Then, create a single zone and # export the 5 datasets to it. In addition, we also add a ZFS filesystem # and a zvol device to the zone. # # $1 zone name # $2 zone root directory prefix # $3 zone ip # function zfs_zones_setup #zone_name zone_root zone_ip { typeset zone_name=${1:-$(hostname)-z} typeset zone_root=${2:-"/zone_root"} typeset zone_ip=${3:-"10.1.1.10"} typeset prefix_ctr=$ZONE_CTR typeset pool_name=$ZONE_POOL typeset -i cntctr=5 typeset -i i=0 # Create pool and 5 container within it # [[ -d /$pool_name ]] && $RM -rf /$pool_name log_must $ZPOOL create -f $pool_name $DISKS while (( i < cntctr )); do log_must $ZFS create $pool_name/$prefix_ctr$i (( i += 1 )) done # create a zvol log_must $ZFS create -V 1g $pool_name/zone_zvol # # If current system support slog, add slog device for pool # if verify_slog_support ; then typeset sdevs="$TMPDIR/sdev1 $TMPDIR/sdev2" log_must $MKFILE 100M $sdevs log_must $ZPOOL add $pool_name log mirror $sdevs fi # this isn't supported just yet. # Create a filesystem. In order to add this to # the zone, it must have it's mountpoint set to 'legacy' # log_must $ZFS create $pool_name/zfs_filesystem # log_must $ZFS set mountpoint=legacy $pool_name/zfs_filesystem [[ -d $zone_root ]] && \ log_must $RM -rf $zone_root/$zone_name [[ ! -d $zone_root ]] && \ log_must $MKDIR -p -m 0700 $zone_root/$zone_name # Create zone configure file and configure the zone # typeset zone_conf=$TMPDIR/zone_conf.${TESTCASE_ID} $ECHO "create" > $zone_conf $ECHO "set zonepath=$zone_root/$zone_name" >> $zone_conf $ECHO "set autoboot=true" >> $zone_conf i=0 while (( i < cntctr )); do $ECHO "add dataset" >> $zone_conf $ECHO "set name=$pool_name/$prefix_ctr$i" >> \ $zone_conf $ECHO "end" >> $zone_conf (( i += 1 )) done # add our zvol to the zone $ECHO "add device" >> $zone_conf $ECHO "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf $ECHO "end" >> $zone_conf # add a corresponding zvol rdsk to the zone $ECHO "add device" >> $zone_conf $ECHO "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf $ECHO "end" >> $zone_conf # once it's supported, we'll add our filesystem to the zone # $ECHO "add fs" >> $zone_conf # $ECHO "set type=zfs" >> $zone_conf # $ECHO "set special=$pool_name/zfs_filesystem" >> $zone_conf # $ECHO "set dir=/export/zfs_filesystem" >> $zone_conf # $ECHO "end" >> $zone_conf $ECHO "verify" >> $zone_conf $ECHO "commit" >> $zone_conf log_must $ZONECFG -z $zone_name -f $zone_conf log_must $RM -f $zone_conf # Install the zone $ZONEADM -z $zone_name install if (( $? == 0 )); then log_note "SUCCESS: $ZONEADM -z $zone_name install" else log_fail "FAIL: $ZONEADM -z $zone_name install" fi # Install sysidcfg file # typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg $ECHO "system_locale=C" > $sysidcfg $ECHO "terminal=dtterm" >> $sysidcfg $ECHO "network_interface=primary {" >> $sysidcfg $ECHO "hostname=$zone_name" >> $sysidcfg $ECHO "}" >> $sysidcfg $ECHO "name_service=NONE" >> $sysidcfg $ECHO "root_password=mo791xfZ/SFiw" >> $sysidcfg $ECHO "security_policy=NONE" >> $sysidcfg $ECHO "timezone=US/Eastern" >> $sysidcfg # Boot this zone log_must $ZONEADM -z $zone_name boot } # # Reexport TESTPOOL & TESTPOOL(1-4) # function reexport_pool { typeset -i cntctr=5 typeset -i i=0 while (( i < cntctr )); do if (( i == 0 )); then TESTPOOL=$ZONE_POOL/$ZONE_CTR$i if ! ismounted $TESTPOOL; then log_must $ZFS mount $TESTPOOL fi else eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i if eval ! ismounted \$TESTPOOL$i; then log_must eval $ZFS mount \$TESTPOOL$i fi fi (( i += 1 )) done } # # Verify a given disk is online or offline # # Return 0 is pool/disk matches expected state, 1 otherwise # function check_state # pool disk state{online,offline} { typeset pool=$1 typeset disk=${2#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk#/dev/} typeset state=$3 $ZPOOL status -v $pool | grep "$disk" \ | grep -i "$state" > /dev/null 2>&1 return $? } # # Wait for a given disk to leave a state # function wait_for_state_exit { typeset pool=$1 typeset disk=$2 typeset state=$3 while check_state "$pool" "$disk" "$state"; do $SLEEP 1 done } # # Get the mountpoint of snapshot # as its mountpoint # function snapshot_mountpoint { typeset dataset=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} if [[ $dataset != *@* ]]; then log_fail "Error name of snapshot '$dataset'." fi typeset fs=${dataset%@*} typeset snap=${dataset#*@} if [[ -z $fs || -z $snap ]]; then log_fail "Error name of snapshot '$dataset'." fi $ECHO $(get_prop mountpoint $fs)/$(get_snapdir_name)/$snap } function pool_maps_intact # pool { typeset pool="$1" if ! $ZDB -bcv $pool; then return 1 fi return 0 } function filesys_has_zil # filesystem { typeset filesys="$1" if ! $ZDB -ivv $filesys | $GREP "ZIL header"; then return 1 fi return 0 } # # Given a pool and file system, this function will verify the file system # using the zdb internal tool. Note that the pool is exported and imported # to ensure it has consistent state. # function verify_filesys # pool filesystem dir { typeset pool="$1" typeset filesys="$2" typeset zdbout="$TMPDIR/zdbout.${TESTCASE_ID}" shift shift typeset dirs=$@ typeset search_path="" log_note "Calling $ZDB to verify filesystem '$filesys'" log_must $ZPOOL export $pool if [[ -n $dirs ]] ; then for dir in $dirs ; do search_path="$search_path -d $dir" done fi log_must $ZPOOL import $search_path $pool $ZDB -cudi $filesys > $zdbout 2>&1 if [[ $? != 0 ]]; then log_note "Output: $ZDB -cudi $filesys" $CAT $zdbout log_fail "$ZDB detected errors with: '$filesys'" fi log_must $RM -rf $zdbout } # # Given a pool, and this function list all disks in the pool # function get_disklist # pool { typeset disklist="" disklist=$($ZPOOL iostat -v $1 | $NAWK '(NR >4 ) {print $1}' | \ $GREP -v "\-\-\-\-\-" | \ $EGREP -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$" ) $ECHO $disklist } # # Destroy all existing metadevices and state database # function destroy_metas { typeset metad for metad in $($METASTAT -p | $AWK '{print $1}'); do log_must $METACLEAR -rf $metad done for metad in $($METADB | $CUT -f6 | $GREP dev | $UNIQ); do log_must $METADB -fd $metad done } # /** # This function kills a given list of processes after a time period. We use # this in the stress tests instead of STF_TIMEOUT so that we can have processes # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT # would be listed as FAIL, which we don't want : we're happy with stress tests # running for a certain amount of time, then finishing. # # @param $1 the time in seconds after which we should terminate these processes # @param $2..$n the processes we wish to terminate. # */ function stress_timeout { typeset -i TIMEOUT=$1 shift typeset cpids="$@" log_note "Waiting for child processes($cpids). " \ "It could last dozens of minutes, please be patient ..." log_must $SLEEP $TIMEOUT log_note "Killing child processes after ${TIMEOUT} stress timeout." typeset pid for pid in $cpids; do $PS -p $pid > /dev/null 2>&1 if (( $? == 0 )); then log_must $KILL -USR1 $pid fi done } # # Check whether current OS support a specified feature or not # # return 0 if current OS version is in unsupported list, 1 otherwise # # $1 unsupported target OS versions # function check_version # { typeset unsupported_vers="$@" typeset ver typeset cur_ver=`$UNAME -r` for ver in $unsupported_vers; do [[ "$cur_ver" == "$ver" ]] && return 0 done return 1 } # # Verify a given hotspare disk is inuse or avail # # Return 0 is pool/disk matches expected state, 1 otherwise # function check_hotspare_state # pool disk state{inuse,avail} { typeset pool=$1 typeset disk=${2#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk#/dev/} typeset state=$3 cur_state=$(get_device_state $pool $disk "spares") if [[ $state != ${cur_state} ]]; then return 1 fi return 0 } # # Verify a given slog disk is inuse or avail # # Return 0 is pool/disk matches expected state, 1 otherwise # function check_slog_state # pool disk state{online,offline,unavail} { typeset pool=$1 typeset disk=${2#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk#/dev/} typeset state=$3 cur_state=$(get_device_state $pool $disk "logs") if [[ $state != ${cur_state} ]]; then return 1 fi return 0 } # # Verify a given vdev disk is inuse or avail # # Return 0 is pool/disk matches expected state, 1 otherwise # function check_vdev_state # pool disk state{online,offline,unavail} { typeset pool=$1 typeset disk=${2#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk#/dev/} typeset state=$3 if [[ $WRAPPER == *"smi"* ]]; then $ECHO $disk | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 if (( $? == 0 )); then disk=${disk}s2 fi fi cur_state=$(get_device_state $pool $disk) if [[ $state != ${cur_state} ]]; then return 1 fi return 0 } # # Check the output of 'zpool status -v ', # and to see if the content of contain the specified. # # Return 0 is contain, 1 otherwise # function check_pool_status # pool token keyword { typeset pool=$1 typeset token=$2 typeset keyword=$3 $ZPOOL status -v "$pool" 2>/dev/null | \ $NAWK -v token="$token:" '($1==token) {print $0}' | \ $GREP -i "$keyword" >/dev/null 2>&1 return $? } # # These 5 following functions are instance of check_pool_status() # is_pool_resilvering - to check if the pool is resilver in progress # is_pool_resilvered - to check if the pool is resilver completed # is_pool_scrubbing - to check if the pool is scrub in progress # is_pool_scrubbed - to check if the pool is scrub completed # is_pool_scrub_stopped - to check if the pool is scrub stopped # function is_pool_resilvering #pool { check_pool_status "$1" "scan" "resilver in progress" return $? } function is_pool_resilvered #pool { check_pool_status "$1" "scan" "resilvered" return $? } function is_pool_scrubbing #pool { check_pool_status "$1" "scan" "scrub in progress" return $? } function is_pool_scrubbed #pool { check_pool_status "$1" "scan" "scrub repaired" return $? } function is_pool_scrub_stopped #pool { check_pool_status "$1" "scan" "scrub canceled" return $? } # # Erase the partition tables and destroy any zfs labels # function cleanup_devices #vdevs { for device in $@; do wipe_partition_table $device $ZPOOL labelclear -f $device done return 0 } # # Verify the rsh connectivity to each remote host in RHOSTS. # # Return 0 if remote host is accessible; otherwise 1. # $1 remote host name # $2 username # function verify_rsh_connect #rhost, username { typeset rhost=$1 typeset username=$2 typeset rsh_cmd="$RSH -n" typeset cur_user= $GETENT hosts $rhost >/dev/null 2>&1 if (( $? != 0 )); then log_note "$rhost cannot be found from" \ "administrative database." return 1 fi $PING $rhost 3 >/dev/null 2>&1 if (( $? != 0 )); then log_note "$rhost is not reachable." return 1 fi if (( ${#username} != 0 )); then rsh_cmd="$rsh_cmd -l $username" cur_user="given user \"$username\"" else cur_user="current user \"`$LOGNAME`\"" fi if ! $rsh_cmd $rhost $TRUE; then log_note "$RSH to $rhost is not accessible" \ "with $cur_user." return 1 fi return 0 } # # Verify the remote host connection via rsh after rebooting # $1 remote host # function verify_remote { rhost=$1 # # The following loop waits for the remote system rebooting. # Each iteration will wait for 150 seconds. there are # total 5 iterations, so the total timeout value will # be 12.5 minutes for the system rebooting. This number # is an approxiate number. # typeset -i count=0 while ! verify_rsh_connect $rhost; do sleep 150 (( count = count + 1 )) if (( count > 5 )); then return 1 fi done return 0 } # # Replacement function for /usr/bin/rsh. This function will include # the /usr/bin/rsh and meanwhile return the execution status of the # last command. # # $1 usrname passing down to -l option of /usr/bin/rsh # $2 remote machine hostname # $3... command string # function rsh_status { typeset ruser=$1 typeset rhost=$2 typeset -i ret=0 typeset cmd_str="" typeset rsh_str="" shift; shift cmd_str="$@" err_file=$TMPDIR/${rhost}.${TESTCASE_ID}.err if (( ${#ruser} == 0 )); then rsh_str="$RSH -n" else rsh_str="$RSH -n -l $ruser" fi $rsh_str $rhost /usr/local/bin/ksh93 -c "'$cmd_str; \ print -u 2 \"status=\$?\"'" \ >/dev/null 2>$err_file ret=$? if (( $ret != 0 )); then $CAT $err_file $RM -f $std_file $err_file log_fail "$RSH itself failed with exit code $ret..." fi ret=$($GREP -v 'print -u 2' $err_file | $GREP 'status=' | \ $CUT -d= -f2) (( $ret != 0 )) && $CAT $err_file >&2 $RM -f $err_file >/dev/null 2>&1 return $ret } # # Get the SUNWstc-fs-zfs package installation path in a remote host # $1 remote host name # function get_remote_pkgpath { typeset rhost=$1 typeset pkgpath="" pkgpath=$($RSH -n $rhost "$PKGINFO -l SUNWstc-fs-zfs | $GREP BASEDIR: |\ $CUT -d: -f2") $ECHO $pkgpath } #/** # A function to find and locate free disks on a system or from given # disks as the parameter. Since the conversion to ATF, this function is # superfluous; it is assumed that the user will supply an accurate list of # disks to use. So we just return the arguments. # # $@ given disks to find which are free # # @return a string containing the list of available disks #*/ function find_disks { (( first=0 )) for disk in $@; do [[ $first == 1 ]] && echo -n " " (( first=1 )) case $disk in /dev/*) echo -n "$disk" ;; *) echo -n "/dev/$disk" ;; esac done } # A function to set convenience variables for disks. function set_disks { set -A disk_array $(find_disks $DISKS) [[ -z "$DISK_ARRAY_LIMIT" ]] && typeset -i DISK_ARRAY_LIMIT=5 if (( ${#disk_array[*]} <= 1 )); then export DISK=${DISKS%% *} else export DISK="" typeset -i i=0 while (( i < ${#disk_array[*]} && i <= $DISK_ARRAY_LIMIT )); do export DISK${i}="${disk_array[$i]}" DISKSARRAY="$DISKSARRAY ${disk_array[$i]}" (( i = i + 1 )) done export DISK_ARRAY_NUM=$i export DISKSARRAY fi if (( $DISK_ARRAY_NUM == 0 )); then export disk=$DISK else export disk=$DISK0 fi } # # Add specified user to specified group # # $1 group name # $2 user name # function add_user # { typeset gname=$1 typeset uname=$2 if (( ${#gname} == 0 || ${#uname} == 0 )); then log_fail "group name or user name are not defined." fi # Check to see if the user exists. $ID $uname > /dev/null 2>&1 && return 0 # Assign 1000 as the base uid typeset -i uid=1000 while true; do typeset -i ret $USERADD -u $uid -g $gname -d /var/tmp/$uname -m $uname ret=$? case $ret in 0) return 0 ;; # The uid is not unique 65) ((uid += 1)) ;; *) return 1 ;; esac if [[ $uid == 65000 ]]; then log_fail "No user id available under 65000 for $uname" fi done return 0 } # # Delete the specified user. # # $1 login name # function del_user # { typeset user=$1 if (( ${#user} == 0 )); then log_fail "login name is necessary." fi if $ID $user > /dev/null 2>&1; then log_must $USERDEL $user fi return 0 } # # Select valid gid and create specified group. # # $1 group name # function add_group # { typeset group=$1 if (( ${#group} == 0 )); then log_fail "group name is necessary." fi # See if the group already exists. $GROUPSHOW $group >/dev/null 2>&1 [[ $? == 0 ]] && return 0 # Assign 100 as the base gid typeset -i gid=100 while true; do $GROUPADD -g $gid $group > /dev/null 2>&1 typeset -i ret=$? case $ret in 0) return 0 ;; # The gid is not unique 65) ((gid += 1)) ;; *) return 1 ;; esac if [[ $gid == 65000 ]]; then log_fail "No user id available under 65000 for $group" fi done } # # Delete the specified group. # # $1 group name # function del_group # { typeset grp=$1 if (( ${#grp} == 0 )); then log_fail "group name is necessary." fi $GROUPDEL -n $grp > /dev/null 2>&1 typeset -i ret=$? case $ret in # Group does not exist, or was deleted successfully. 0|6|65) return 0 ;; # Name already exists as a group name 9) log_must $GROUPDEL $grp ;; *) return 1 ;; esac return 0 } # # This function will return true if it's safe to destroy the pool passed # as argument 1. It checks for pools based on zvols and files, and also # files contained in a pool that may have a different mountpoint. # function safe_to_destroy_pool { # $1 the pool name typeset pool="" typeset DONT_DESTROY="" # We check that by deleting the $1 pool, we're not # going to pull the rug out from other pools. Do this # by looking at all other pools, ensuring that they # aren't built from files or zvols contained in this pool. for pool in $($ZPOOL list -H -o name) do ALTMOUNTPOOL="" # this is a list of the top-level directories in each of the files # that make up the path to the files the pool is based on FILEPOOL=$($ZPOOL status -v $pool | $GREP /$1/ | \ $AWK '{print $1}') # this is a list of the zvols that make up the pool ZVOLPOOL=$($ZPOOL status -v $pool | $GREP "/dev/zvol/dsk/$1$" | \ $AWK '{print $1}') # also want to determine if it's a file-based pool using an # alternate mountpoint... POOL_FILE_DIRS=$($ZPOOL status -v $pool | \ $GREP / | $AWK '{print $1}' | \ $AWK -F/ '{print $2}' | $GREP -v "dev") for pooldir in $POOL_FILE_DIRS do OUTPUT=$($ZFS list -H -r -o mountpoint $1 | \ $GREP "${pooldir}$" | $AWK '{print $1}') ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}" done if [ ! -z "$ZVOLPOOL" ] then DONT_DESTROY="true" log_note "Pool $pool is built from $ZVOLPOOL on $1" fi if [ ! -z "$FILEPOOL" ] then DONT_DESTROY="true" log_note "Pool $pool is built from $FILEPOOL on $1" fi if [ ! -z "$ALTMOUNTPOOL" ] then DONT_DESTROY="true" log_note "Pool $pool is built from $ALTMOUNTPOOL on $1" fi done if [ -z "${DONT_DESTROY}" ] then return 0 else log_note "Warning: it is not safe to destroy $1!" return 1 fi } # # Get IP address of hostname # $1 hostname # function getipbyhost { typeset ip ip=`$ARP $1 2>/dev/null | $AWK -F\) '{print $1}' \ | $AWK -F\( '{print $2}'` $ECHO $ip } # # Setup iSCSI initiator to target # $1 target hostname # function iscsi_isetup { # check svc:/network/iscsi_initiator:default state, try to enable it # if the state is not ON typeset ISCSII_FMRI="svc:/network/iscsi_initiator:default" if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then log_must $SVCADM enable $ISCSII_FMRI typeset -i retry=20 while [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) && \ ( $retry -ne 0 ) ]] do (( retry = retry - 1 )) $SLEEP 1 done if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then log_fail "$ISCSII_FMRI service can not be enabled!" fi fi log_must $ISCSIADM add discovery-address $(getipbyhost $1) log_must $ISCSIADM modify discovery --sendtargets enable log_must $DEVFSADM -i iscsi } # # Check whether iscsi parameter is set as remote # # return 0 if iscsi is set as remote, otherwise 1 # function check_iscsi_remote { if [[ $iscsi == "remote" ]] ; then return 0 else return 1 fi } # # Check if a volume is a valide iscsi target # $1 volume name # return 0 if suceeds, otherwise, return 1 # function is_iscsi_target { typeset dataset=$1 typeset target targets [[ -z $dataset ]] && return 1 targets=$($ISCSITADM list target | $GREP "Target:" | $AWK '{print $2}') [[ -z $targets ]] && return 1 for target in $targets; do [[ $dataset == $target ]] && return 0 done return 1 } # # Get the iSCSI name of a target # $1 target name # function iscsi_name { typeset target=$1 typeset name [[ -z $target ]] && log_fail "No parameter." if ! is_iscsi_target $target ; then log_fail "Not a target." fi name=$($ISCSITADM list target $target | $GREP "iSCSI Name:" \ | $AWK '{print $2}') return $name } # # check svc:/system/iscsitgt:default state, try to enable it if the state # is not ON # function iscsitgt_setup { log_must $RM -f $ISCSITGTFILE if [[ "ON" == $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then log_note "iscsitgt is already enabled" return fi log_must $SVCADM enable -t $ISCSITGT_FMRI typeset -i retry=20 while [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) && \ ( $retry -ne 0 ) ]] do $SLEEP 1 (( retry = retry - 1 )) done if [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then log_fail "$ISCSITGT_FMRI service can not be enabled!" fi log_must $TOUCH $ISCSITGTFILE } # # set DISABLED state of svc:/system/iscsitgt:default # which is the most suiteable state if $ISCSITGTFILE exists # function iscsitgt_cleanup { if [[ -e $ISCSITGTFILE ]]; then log_must $SVCADM disable $ISCSITGT_FMRI log_must $RM -f $ISCSITGTFILE fi } # # Close iSCSI initiator to target # $1 target hostname # function iscsi_iclose { log_must $ISCSIADM modify discovery --sendtargets disable log_must $ISCSIADM remove discovery-address $(getipbyhost $1) $DEVFSADM -Cv } # # Get the available ZFS compression options # $1 option type zfs_set|zfs_compress # function get_compress_opts { typeset COMPRESS_OPTS typeset GZIP_OPTS="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \ gzip-6 gzip-7 gzip-8 gzip-9" if [[ $1 == "zfs_compress" ]] ; then COMPRESS_OPTS="on lzjb" elif [[ $1 == "zfs_set" ]] ; then COMPRESS_OPTS="on off lzjb" fi typeset valid_opts="$COMPRESS_OPTS" $ZFS get 2>&1 | $GREP gzip >/dev/null 2>&1 if [[ $? -eq 0 ]]; then valid_opts="$valid_opts $GZIP_OPTS" fi $ECHO "$valid_opts" } # # Check the subcommand/option is supported # function check_opt_support #command, option { typeset command=$1 typeset option=$2 if [[ -z $command ]]; then return 0 elif [[ -z $option ]]; then eval "$ZFS 2>&1 | $GREP '$command' > /dev/null 2>&1" else eval "$ZFS $command 2>&1 | $GREP -- '$option' | \ $GREP -v -- 'User-defined' > /dev/null 2>&1" fi return $? } # # Check the zpool subcommand/option is supported # function check_zpool_opt_support #command, option { typeset command=$1 typeset option=$2 if [[ -z $command ]]; then return 0 elif [[ -z $option ]]; then eval "$ZPOOL 2>&1 | $GREP '$command' > /dev/null 2>&1" else eval "$ZPOOL $command 2>&1 | $GREP -- '$option' > /dev/null 2>&1" fi return $? } # # Verify zfs operation with -p option work as expected # $1 operation, value could be create, clone or rename # $2 dataset type, value could be fs or vol # $3 dataset name # $4 new dataset name # function verify_opt_p_ops { typeset ops=$1 typeset datatype=$2 typeset dataset=$3 typeset newdataset=$4 if [[ $datatype != "fs" && $datatype != "vol" ]]; then log_fail "$datatype is not supported." fi # check parameters accordingly case $ops in create) newdataset=$dataset dataset="" if [[ $datatype == "vol" ]]; then ops="create -V $VOLSIZE" fi ;; clone) if [[ -z $newdataset ]]; then log_fail "newdataset should not be empty" \ "when ops is $ops." fi log_must datasetexists $dataset log_must snapexists $dataset ;; rename) if [[ -z $newdataset ]]; then log_fail "newdataset should not be empty" \ "when ops is $ops." fi log_must datasetexists $dataset log_mustnot snapexists $dataset ;; *) log_fail "$ops is not supported." ;; esac # make sure the upper level filesystem does not exist if datasetexists ${newdataset%/*} ; then log_must $ZFS destroy -rRf ${newdataset%/*} fi # without -p option, operation will fail log_mustnot $ZFS $ops $dataset $newdataset log_mustnot datasetexists $newdataset ${newdataset%/*} # with -p option, operation should succeed log_must $ZFS $ops -p $dataset $newdataset if ! datasetexists $newdataset ; then log_fail "-p option does not work for $ops" fi # when $ops is create or clone, redo the operation still return zero if [[ $ops != "rename" ]]; then log_must $ZFS $ops -p $dataset $newdataset fi return 0 } function get_disk_guid { typeset diskname=$1 lastcwd=$(pwd) cd /dev guid=$($ZDB -l ${diskname} | ${AWK} '/^ guid:/ {print $2}' | head -1) cd $lastcwd echo $guid } # # Get configuration of pool # $1 pool name # $2 config name # function get_config { typeset pool=$1 typeset config=$2 typeset vdevdir=$3 typeset alt_root typeset zdb_opts if poolexists "$pool"; then cachefile=$(get_pool_prop cachefile $pool) if [[ $? != 0 ]]; then # Shouldn't get here. Try treating as an exported pool zdb_opts="-eC" else case $cachefile in none) # Treat as exported pool zdb_opts="-eC" break ;; "-") # Normal pool zdb_opts="-C" break ;; *) zdb_opts="-U $cachefile -C" break ;; esac fi else # use -e for exported pools zdb_opts="-eC" [[ -n "$vdevdir" ]] && zdb_opts="$zdb_opts -p $vdevdir" fi value=$($ZDB $zdb_opts $pool | $GREP "$config:" | $AWK -F: '{print $2}') if [[ -n $value ]] ; then value=${value#'} value=${value%'} else return 1 fi print $value return 0 } # # Privated function. Random select one of items from arguments. # # $1 count # $2-n string # function _random_get { typeset cnt=$1 shift typeset str="$@" typeset -i ind ((ind = RANDOM % cnt + 1)) typeset ret=$($ECHO "$str" | $CUT -f $ind -d ' ') $ECHO $ret } # # Random select one of item from arguments which include NONE string # function random_get_with_non { typeset -i cnt=$# ((cnt =+ 1)) _random_get "$cnt" "$@" } # # Random select one of item from arguments which doesn't include NONE string # function random_get { _random_get "$#" "$@" } # # Detect if the current system support slog # function verify_slog_support { typeset dir=$TMPDIR/disk.${TESTCASE_ID} typeset pool=foo.${TESTCASE_ID} typeset vdev=$dir/a typeset sdev=$dir/b $MKDIR -p $dir $MKFILE 64M $vdev $sdev typeset -i ret=0 if ! $ZPOOL create -n $pool $vdev log $sdev > /dev/null 2>&1; then ret=1 fi $RM -r $dir return $ret } # # The function will generate a dataset name with specific length # $1, the length of the name # $2, the base string to construct the name # function gen_dataset_name { typeset -i len=$1 typeset basestr="$2" typeset -i baselen=${#basestr} typeset -i iter=0 typeset l_name="" if (( len % baselen == 0 )); then (( iter = len / baselen )) else (( iter = len / baselen + 1 )) fi while (( iter > 0 )); do l_name="${l_name}$basestr" (( iter -= 1 )) done $ECHO $l_name } # # Get cksum tuple of dataset # $1 dataset name # # zdb output is like below # " Dataset pool/fs [ZPL], ID 978, cr_txg 2277, 19.0K, 5 objects, # rootbp [L0 DMU objset] 400L/200P DVA[0]=<0:1880c00:200> # DVA[1]=<0:341880c00:200> fletcher4 lzjb LE contiguous birth=2292 fill=5 # cksum=989930ccf:4014fe00c83:da5e388e58b4:1f7332052252ac " # function datasetcksum { typeset cksum $SYNC cksum=$($ZDB -vvv $1 | $GREP "^Dataset $1 \[" | $GREP "cksum" \ | $AWK -F= '{print $6}') $ECHO $cksum } # # Get cksum of file # #1 file path # function checksum { typeset cksum cksum=$($CKSUM $1 | $AWK '{print $1}') $ECHO $cksum } # # Get the given disk/slice state from the specific field of the pool # function get_device_state #pool disk field("", "spares","logs") { typeset pool=$1 typeset disk=${2#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk#/dev/} typeset field=${3:-$pool} state=$($ZPOOL status -v "$pool" 2>/dev/null | \ $NAWK -v device=$disk -v pool=$pool -v field=$field \ 'BEGIN {startconfig=0; startfield=0; } /config:/ {startconfig=1} (startconfig==1)&&($1==field) {startfield=1; next;} (startfield==1)&&($1==device) {print $2; exit;} (startfield==1)&&(NF>=3)&&($(NF-1)=="was")&&($NF==device) {print $2; exit;} (startfield==1)&&($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}') print $state } # # print the given directory filesystem type # # $1 directory name # function get_fstype { typeset dir=$1 if [[ -z $dir ]]; then log_fail "Usage: get_fstype " fi # # $ df -n / # / : ufs # $DF -n $dir | $AWK '{print $3}' } # # Given a disk, label it to VTOC regardless what label was on the disk # $1 disk # function labelvtoc { typeset disk=$1 if [[ -z $disk ]]; then log_fail "The disk name is unspecified." fi typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID} typeset arch=$($UNAME -p) if [[ $arch == "i386" ]]; then $ECHO "label" > $label_file $ECHO "0" >> $label_file $ECHO "" >> $label_file $ECHO "q" >> $label_file $ECHO "q" >> $label_file $FDISK -B $disk >/dev/null 2>&1 # wait a while for fdisk finishes $SLEEP 60 elif [[ $arch == "sparc" ]]; then $ECHO "label" > $label_file $ECHO "0" >> $label_file $ECHO "" >> $label_file $ECHO "" >> $label_file $ECHO "" >> $label_file $ECHO "q" >> $label_file else log_fail "unknown arch type" fi $FORMAT -e -s -d $disk -f $label_file typeset -i ret_val=$? $RM -f $label_file # # wait the format to finish # $SLEEP 60 if (( ret_val != 0 )); then log_fail "unable to label $disk as VTOC." fi return 0 } # # Detect if the given filesystem property is supported in this release # # 0 Yes, it is supported # !0 No, it is not supported # function fs_prop_exist { typeset prop=$1 if [[ -z $prop ]]; then log_fail "Usage: fs_prop_exist " return 1 fi # # If the property is shortened column name, # convert it to the standard name # case $prop in avail) prop=available ;; refer) prop=referenced ;; volblock) prop=volblocksize ;; compress) prop=compression ;; rdonly) prop=readonly ;; recsize) prop=recordsize ;; reserv) prop=reservation ;; refreserv) prop=refreservation ;; esac # # The zfs get output looks like the following # # # The following properties are supported: # # PROPERTY EDIT INHERIT VALUES # # available NO NO # compressratio NO NO <1.00x or higher if compressed> # creation NO NO # ... ... # zoned YES YES on | off # # Sizes are specified in bytes with standard units such as K, M, G, etc. # # # Start to extract property from the first blank line after 'PROPERTY' # and stop at the next blank line # $ZFS get 2>&1 | \ $AWK '/PROPERTY/ {start=1; next} /Sizes/ {start=0} start==1 {print $1}' | \ $GREP -w "$prop" > /dev/null 2>&1 return $? } # # Detect if the given pool property is supported in this release # # 0 Yes, it is supported # !0 No, it is not supported # function pool_prop_exist { typeset prop=$1 if [[ -z $prop ]]; then log_fail "Usage: pool_prop_exist " return 1 fi # # If the property is shortened column name, # convert it to the standard name # case $prop in avail) prop=available ;; cap) prop=capacity ;; replace) prop=autoreplace ;; esac # # The zpool get output looks like the following # # usage: # get <"all" | property[,...]> ... # # the following properties are supported: # # PROPERTY EDIT VALUES # # available NO # capacity NO # guid NO # health NO # size NO # used NO # altroot YES # autoreplace YES on | off # bootfs YES # cachefile YES | none # delegation YES on | off # failmode YES wait | continue | panic # version YES $ZPOOL get 2>&1 | \ $AWK '/PROPERTY/ {start=1; next} start==1 {print $1}' | \ $GREP -w "$prop" > /dev/null 2>&1 return $? } # # check if the system was installed as zfsroot or not # return: 0 ture, otherwise false # function is_zfsroot { $DF -n / | $GREP zfs > /dev/null 2>&1 return $? } # # get the root filesystem name if it's zfsroot system. # # return: root filesystem name function get_rootfs { typeset rootfs="" rootfs=$($MOUNT | $AWK '$3 == "\/" && $4~/zfs/ {print $1}') if [[ -z "$rootfs" ]]; then log_fail "Can not get rootfs" fi $ZFS list $rootfs > /dev/null 2>&1 if (( $? == 0 )); then $ECHO $rootfs else log_fail "This is not a zfsroot system." fi } # # get the rootfs's pool name # return: # rootpool name # function get_rootpool { typeset rootfs="" typeset rootpool="" rootfs=$(get_rootfs) rootpool=`$ECHO $rootfs | awk -F\/ '{print $1}'` echo $rootpool } # # Get the sub string from specified source string # # $1 source string # $2 start position. Count from 1 # $3 offset # function get_substr #src_str pos offset { typeset pos offset $ECHO $1 | \ $NAWK -v pos=$2 -v offset=$3 '{print substr($0, pos, offset)}' } # # Check if the given device is physical device # function is_physical_device #device { dev_file=`find_disks $1` [ -c "${dev_file}" -o -b "${dev_file}" ] return $? } # # Get the directory path of given device # function get_device_dir #device { typeset device=$1 if ! $(is_physical_device $device) ; then if [[ $device != "/" ]]; then device=${device%/*} fi $ECHO $device else $ECHO "/dev" fi } # # Get the package name # function get_package_name { typeset dirpath=${1:-$STC_NAME} print "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g" } # # Get the word numbers from a string separated by white space # function get_word_count { $ECHO $1 | $WC -w } # # To verify if the require numbers of disks is given # function verify_disk_count { typeset -i min=${2:-1} typeset -i count=$(get_word_count "$1") if (( count < min )); then log_untested "A minimum of $min disks is required to run." \ " You specified $count disk(s)" fi } # # bsdmap disk/slice number to a device path # function bsddevmap { typeset arg=$1 echo $arg | egrep "*s[0-9]$" > /dev/null 2>&1 if [ $? -eq 0 ] then n=`echo $arg| wc -c` set -A map a b c d e f g h i j s=`echo $arg | cut -c $((n-1))` arg=${arg%s[0-9]}${map[$s]} fi echo $arg } # # Get the name of the snapshots directory. Traditionally .zfs/snapshots # function get_snapdir_name { if [[ `sysctl -n vfs.zfs.abbreviated_snapdir` = "1" ]]; then echo ".snapshot" else echo ".zfs/snapshot" fi } # # Unmount all ZFS filesystems except for those that are in the KEEP variable # function unmount_all_safe { echo $(all_pools) | \ $XARGS -n 1 $ZFS list -H -o name -t all -r | \ $XARGS -n 1 $ZFS unmount } # # Return the highest pool version that this OS can create # function get_zpool_version { # We assume output from zpool upgrade -v of the form: # # This system is currently running ZFS version 2. # . # . typeset ZPOOL_VERSION=$($ZPOOL upgrade -v | $HEAD -1 | \ $AWK '{print $NF}' | $SED -e 's/\.//g') # Starting with version 5000, the output format changes to: # This system supports ZFS pool feature flags. # . # . if [[ $ZPOOL_VERSION = "flags" ]]; then ZPOOL_VERSION=5000 fi echo $ZPOOL_VERSION } # Temporarily stops ZFSD, because it can interfere with some tests. If this # function is used, then restart_zfsd _must_ be called in the cleanup routine. function stop_zfsd { $RM -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests if [[ -n "$ZFSD" && -x "$ZFSD" ]]; then if /etc/rc.d/zfsd status > /dev/null; then log_note "Stopping zfsd" $TOUCH $TMPDIR/.zfsd_enabled_during_stf_zfs_tests /etc/rc.d/zfsd stop || /etc/rc.d/zfsd onestop fi fi } # Restarts zfsd after it has been stopped by stop_zfsd. Intelligently restarts # only iff zfsd was running at the time stop_zfsd was called. function restart_zfsd { if [[ -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests ]]; then log_note "Restarting zfsd" /etc/rc.d/zfsd start || /etc/rc.d/zfsd onestart fi $RM -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests } Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/Makefile =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/Makefile (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/Makefile (revision 292298) @@ -1,84 +1,93 @@ # $FreeBSD$ .include TESTSDIR= ${TESTSBASE}/sys/cddl/zfs/tests TESTS_SUBDIRS+= acl TESTS_SUBDIRS+= atime TESTS_SUBDIRS+= bootfs TESTS_SUBDIRS+= cache TESTS_SUBDIRS+= cachefile TESTS_SUBDIRS+= clean_mirror TESTS_SUBDIRS+= cli_root TESTS_SUBDIRS+= cli_user TESTS_SUBDIRS+= compression TESTS_SUBDIRS+= ctime TESTS_SUBDIRS+= delegate TESTS_SUBDIRS+= devices TESTS_SUBDIRS+= exec TESTS_SUBDIRS+= grow_pool TESTS_SUBDIRS+= grow_replicas TESTS_SUBDIRS+= history TESTS_SUBDIRS+= hotplug TESTS_SUBDIRS+= hotspare TESTS_SUBDIRS+= inheritance # Not yet ported to FreeBSD # TESTS_SUBDIRS+= interop TESTS_SUBDIRS+= inuse # Not yet ported to FreeBSD # TESTS_SUBDIRS+= iscsi TESTS_SUBDIRS+= large_files # Not yet ported to FreeBSD # TESTS_SUBDIRS+= largest_pool # link_count is not yet ported to FreeBSD. I'm not sure what its purpose is. # The assertion message contradicts with the log_fail message. # TESTS_SUBDIRS+= link_count TESTS_SUBDIRS+= mdb TESTS_SUBDIRS+= migration TESTS_SUBDIRS+= mmap TESTS_SUBDIRS+= mount TESTS_SUBDIRS+= mv_files TESTS_SUBDIRS+= nestedfs TESTS_SUBDIRS+= no_space TESTS_SUBDIRS+= online_offline TESTS_SUBDIRS+= pool_names TESTS_SUBDIRS+= poolversion TESTS_SUBDIRS+= privilege TESTS_SUBDIRS+= quota TESTS_SUBDIRS+= redundancy TESTS_SUBDIRS+= refquota TESTS_SUBDIRS+= refreserv # Not yet ported to FreeBSD # TESTS_SUBDIRS+= remote # Broken on every OS # TESTS_SUBDIRS+= rename_dirs TESTS_SUBDIRS+= replacement TESTS_SUBDIRS+= reservation TESTS_SUBDIRS+= rootpool # Not yet ported to FreeBSD # TESTS_SUBDIRS+= rsend TESTS_SUBDIRS+= sas_phy_thrash TESTS_SUBDIRS+= scrub_mirror TESTS_SUBDIRS+= slog TESTS_SUBDIRS+= snapshot TESTS_SUBDIRS+= snapused TESTS_SUBDIRS+= sparse TESTS_SUBDIRS+= threadsappend TESTS_SUBDIRS+= truncate TESTS_SUBDIRS+= txg_integrity TESTS_SUBDIRS+= userquota TESTS_SUBDIRS+= utils_test TESTS_SUBDIRS+= write_dirs # Not yet ported to FreeBSD # TESTS_SUBDIRS+= xattr TESTS_SUBDIRS+= zfsd TESTS_SUBDIRS+= zil # Not yet ported to FreeBSD # TESTS_SUBDIRS+= zinject # Not yet ported to FreeBSD # TESTS_SUBDIRS+= zones TESTS_SUBDIRS+= zvol TESTS_SUBDIRS+= zvol_thrash +# This is primarily useful for identifying which test a testid corresponds to. +# Sometimes all you might have is a pool name like 'testpool.1316'. +testids: + for i in `find ${.CURDIR} -name '*.sh' | xargs grep '^atf_test_case '|awk '{print $$2}'`; do \ + echo "$${i}: $$(echo $$i | cksum -o 2 | cut -d" " -f1)"; \ + done + +.PHONY: testids + .include Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh (revision 292298) @@ -1,106 +1,96 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_001_pos.ksh 1.4 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_001_pos # # DESCRIPTION: # # Valid datasets are accepted as bootfs property values # # STRATEGY: # 1. Create a set of datasets in a test pool # 2. Try setting them as boot filesystems # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if snapexists $TESTPOOL/$FS@snap ; then - log_must $ZFS destroy $TESTPOOL/$FS@snap - fi - - if datasetexists $TESTPOOL/$FS ; then - log_must $ZFS destroy $TESTPOOL/$FS - fi - - if poolexists $TESTPOOL ; then - log_must $ZPOOL destroy $TESTPOOL - fi + destroy_pool $TESTPOOL if [[ -f $VDEV ]]; then log_must $RM -f $VDEV fi } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Valid datasets are accepted as bootfs property values" log_onexit cleanup typeset VDEV=$TMPDIR/bootfs_001_pos_a.${TESTCASE_ID}.dat log_must $MKFILE 400m $VDEV create_pool "$TESTPOOL" "$VDEV" log_must $ZFS create $TESTPOOL/$FS enc=$(get_prop encryption $TESTPOOL/$FS) if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then log_unsupported "bootfs pool property not supported when \ encryption is set to on." fi log_must $ZFS snapshot $TESTPOOL/$FS@snap log_must $ZFS clone $TESTPOOL/$FS@snap $TESTPOOL/clone log_must $ZPOOL set bootfs=$TESTPOOL/$FS $TESTPOOL log_must $ZPOOL set bootfs=$TESTPOOL/$FS@snap $TESTPOOL log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL log_must $ZFS promote $TESTPOOL/clone log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL log_pass "Valid datasets are accepted as bootfs property values" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh (revision 292298) @@ -1,86 +1,79 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_002_neg.ksh 1.3 09/05/19 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_002_neg # # DESCRIPTION: # # Invalid datasets are rejected as boot property values # # STRATEGY: # # 1. Create a zvol # 2. Verify that we can't set the bootfs to those datasets # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if datasetexists $TESTPOOL/vol - then - log_must $ZFS destroy $TESTPOOL/vol - fi - if poolexists $TESTPOOL - then - log_must $ZPOOL destroy $TESTPOOL - fi + destroy_pool $TESTPOOL } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Invalid datasets are rejected as boot property values" log_onexit cleanup DISK=${DISKS%% *} log_must $ZPOOL create $TESTPOOL $DISK log_must $ZFS create -V 10m $TESTPOOL/vol log_mustnot $ZPOOL set bootfs=$TESTPOOL/vol $TESTPOOL log_pass "Invalid datasets are rejected as boot property values" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh (revision 292298) @@ -1,105 +1,107 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_003_pos.ksh 1.2 08/11/03 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_003_pos # # DESCRIPTION: # # Valid pool names are accepted # # STRATEGY: # 1. Using a list of valid pool names # 2. Create a filesystem in that pool # 2. Verify we can set the bootfs to that filesystem # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" set -A pools "pool.${TESTCASE_ID}" "pool123" "mypool" typeset VDEV=$TMPDIR/bootfs_003.${TESTCASE_ID}.dat function cleanup { - if poolexists $POOL ; then - log_must $ZPOOL destroy $POOL - fi + typeset -i=0 + while [ $i -lt "${#pools[@]}" ]; do + destroy_pool ${pools[$i]} + i=$(( $i + 1 )) + done $RM $VDEV } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_onexit cleanup log_assert "Valid pool names are accepted by zpool set bootfs" $MKFILE 64m $VDEV typeset -i i=0; while [ $i -lt "${#pools[@]}" ] do POOL=${pools[$i]} log_must $ZPOOL create $POOL $VDEV log_must $ZFS create $POOL/$FS enc=$(get_prop encryption $POOL/$FS) if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then log_unsupported "bootfs pool property not supported \ when encryption is set to on." fi log_must $ZPOOL set bootfs=$POOL/$FS $POOL RES=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) if [ $RES != "$POOL/$FS" ] then log_fail "Expected $RES == $POOL/$FS" fi log_must $ZPOOL destroy $POOL i=$(( $i + 1 )) done log_pass "Valid pool names are accepted by zpool set bootfs" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh (revision 292298) @@ -1,108 +1,110 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_004_neg.ksh 1.1 07/05/25 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_004_neg # # DESCRIPTION: # # Invalid pool names are rejected by zpool set bootfs # # STRATEGY: # 1. Try to set bootfs on some non-existent pools # # # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" set -A pools "pool//${TESTCASE_ID}" "pool%d123" "mirror" "c0t0d0s0" "pool*23*" "*po!l" \ "%s££%^" typeset VDEV=$TMPDIR/bootfs_004.${TESTCASE_ID}.dat function cleanup { - if poolexists $POOL; then - log_must $ZPOOL destroy $POOL - fi + typeset -i=0 + while [ $i -lt "${#pools[@]}" ]; do + destroy_pool ${pools[$i]} + i=$(( $i + 1 )) + done $RM $VDEV } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Invalid pool names are rejected by zpool set bootfs" log_onexit cleanup # here, we build up a large string and add it to the list of pool names # a word to the ksh-wary, ${#array[@]} gives you the # total number of entries in an array, so array[${#array[@]}] # will index the last entry+1, ksh arrays start at index 0. COUNT=0 while [ $COUNT -le 1025 ] do bigname="${bigname}o" COUNT=$(( $COUNT + 1 )) done pools[${#pools[@]}]="$bigname" $MKFILE 64m $VDEV typeset -i i=0; while [ $i -lt "${#pools[@]}" ] do POOL=${pools[$i]}/$FS log_mustnot $ZPOOL create $POOL $VDEV log_mustnot $ZFS create $POOL/$FS log_mustnot $ZPOOL set bootfs=$POOL/$FS $POOL i=$(( $i + 1 )) done log_pass "Invalid pool names are rejected by zpool set bootfs" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh (revision 292298) @@ -1,104 +1,101 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_005_neg.ksh 1.2 08/02/27 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.cfg . $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_005_neg # # DESCRIPTION: # # Boot properties cannot be set on pools with older versions # # STRATEGY: # 1. Copy and import some pools of older versions # 2. Create a filesystem on each # 3. Verify that zpool set bootfs fails on each # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { # # we need destroy pools that created on top of $TESTPOOL first # typeset pool_name for config in $CONFIGS; do pool_name=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME"\ | $AWK -F= '{print $2}') if poolexists $pool_name; then - log_must $ZPOOL destroy $pool_name + log_must $ZPOOL destroy -f $pool_name fi done - - if poolexists $TESTPOOL ; then - log_must $ZPOOL destroy $TESTPOOL - fi + destroy_pool $TESTPOOL } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Boot properties cannot be set on pools with older versions" # These are configs from zpool_upgrade.cfg - see that file for more info. CONFIGS="1 2 3" log_onexit cleanup log_must $ZPOOL create -f $TESTPOOL $DISKS for config in $CONFIGS do create_old_pool $config POOL_NAME=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME"\ | $AWK -F= '{print $2}') log_must $ZFS create $POOL_NAME/$FS log_mustnot $ZPOOL set bootfs=$POOL_NAME/$FS $POOL_NAME log_must destroy_upgraded_pool $config done log_pass "Boot properties cannot be set on pools with older versions" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh (revision 292298) @@ -1,163 +1,160 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_006_pos.ksh 1.3 08/11/03 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_006_pos # # DESCRIPTION: # # Pools of correct vdev types accept boot property # # STRATEGY: # 1. create pools of each vdev type (raid, raidz, raidz2, mirror + hotspares) # 2. verify we can set bootfs on each pool type according to design # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi VDEV1=$TMPDIR/bootfs_006_pos_a.${TESTCASE_ID}.dat VDEV2=$TMPDIR/bootfs_006_pos_b.${TESTCASE_ID}.dat VDEV3=$TMPDIR/bootfs_006_pos_c.${TESTCASE_ID}.dat VDEV4=$TMPDIR/bootfs_006_pos_d.${TESTCASE_ID}.dat function verify_bootfs { # $POOL POOL=$1 log_must $ZFS create $POOL/$FS enc=$(get_prop encryption $POOL/$FS) if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then log_unsupported "bootfs pool property not supported \ when encryption is set to on." fi log_must $ZPOOL set bootfs=$POOL/$FS $POOL VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) if [ $VAL != "$POOL/$FS" ] then log_must $ZPOOL status -v $POOL log_fail "set/get failed on $POOL - expected $VAL == $POOL/$FS" fi log_must $ZPOOL destroy $POOL } function verify_no_bootfs { # $POOL POOL=$1 log_must $ZFS create $POOL/$FS log_mustnot $ZPOOL set bootfs=$POOL/$FS $POOL VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) if [ $VAL == "$POOL/$FS" ] then log_must $ZPOOL status -v $POOL log_fail "set/get unexpectedly failed $VAL != $POOL/$FS" fi log_must $ZPOOL destroy $POOL } function cleanup { - if poolexists $TESTPOOL - then - log_must $ZPOOL destroy $TESTPOOL - fi + destroy_pool $TESTPOOL log_must $RM $VDEV1 $VDEV2 $VDEV3 $VDEV4 } log_assert "Pools of correct vdev types accept boot property" log_onexit cleanup log_must $MKFILE 64m $VDEV1 $VDEV2 $VDEV3 $VDEV4 ## the following configurations are supported bootable pools # normal log_must $ZPOOL create $TESTPOOL $VDEV1 verify_bootfs $TESTPOOL # normal + hotspare log_must $ZPOOL create $TESTPOOL $VDEV1 spare $VDEV2 verify_bootfs $TESTPOOL # mirror log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 verify_bootfs $TESTPOOL # mirror + hotspare log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3 verify_bootfs $TESTPOOL ## the following configurations are not supported as bootable pools in Solaris, ## but they are in FreeBSD # stripe log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 verify_bootfs $TESTPOOL # stripe + hotspare log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3 verify_bootfs $TESTPOOL # raidz log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 verify_bootfs $TESTPOOL # raidz + hotspare log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3 verify_bootfs $TESTPOOL # raidz2 log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 verify_bootfs $TESTPOOL # raidz2 + hotspare log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4 verify_bootfs $TESTPOOL log_pass "Pools of correct vdev types accept boot property" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh (revision 292298) @@ -1,97 +1,95 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)bootfs_009_neg.ksh 1.1 08/11/03 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: bootfs_009_neg # # DESCRIPTION: # # Valid encrypted datasets can't be set bootfs property values # # STRATEGY: # 1. Create encrypted datasets in a test pool # 2. Try setting encrypted datasets as boot filesystems # 3. Verify failures. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2008-07-29) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL ; then - log_must $ZPOOL destroy $TESTPOOL - fi + destroy_pool $TESTPOOL } $ZPOOL set 2>&1 | $GREP bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Valid encrypted datasets can't be set bootfs property values" log_onexit cleanup DISK=${DISKS%% *} log_must $ZPOOL create $TESTPOOL $DISK log_must $ZFS create $TESTPOOL/$FS enc=$(get_prop encryption $TESTPOOL/$FS) if [ $? -ne 0 ]; then log_unsupported "get_prop encryption $TESTPOOL/$FS failed." else if [ -z "$enc" ] || [ "$enc" = "off" ]; then log_unsupported "encryption isn't set to on, this test case \ is not supported." else log_mustnot $ZPOOL set bootfs=$TESTPOOL/$FS $TESTPOOL fi fi log_must $ZFS snapshot $TESTPOOL/$FS@snap log_must $ZFS clone $TESTPOOL/$FS@snap $TESTPOOL/clone log_must $ZFS promote $TESTPOOL/clone log_mustnot $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL log_pass "Encrypted datasets can't be set bootfs property" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache.kshlib (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache.kshlib (revision 292298) @@ -1,177 +1,173 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cache.kshlib 1.4 09/05/19 SMI" # . $STF_SUITE/include/libtest.kshlib function cleanup { - if datasetexists $TESTPOOL ; then - log_must $ZPOOL destroy -f $TESTPOOL - fi - if datasetexists $TESTPOOL2 ; then - log_must $ZPOOL destroy -f $TESTPOOL2 - fi + destroy_pool $TESTPOOL + destroy_pool $TESTPOOL2 } # # Try zpool status/iostat for given pool # # $1 pool # function display_status { typeset pool=$1 typeset -i ret=0 $ZPOOL status -xv $pool > /dev/null 2>&1 ret=$? $ZPOOL iostat > /dev/null 2>&1 ((ret |= $?)) typeset mntpnt=$(get_prop mountpoint $pool) $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} & typeset pid=$! $ZPOOL iostat -v 1 3 > /dev/null ((ret |= $?)) kill -9 $pid return $ret } # # Verify the give cache device have correct type and status # # $1 pool name # $2 device name # $3 device status # $4 device type # function verify_cache_device { typeset pool=$1 typeset device=$2 typeset status=$3 typeset type=$4 if [[ -z $pool || -z $device || -z $status ]]; then log_fail "Usage: verify_cache_device " \ " [type]" fi # Zpool status returns on the device name sans the /dev, so # if the device contains /dev/ remove it. if [[ $device =~ "^/dev/" ]]; then device=`basename ${device}` fi if [[ $WRAPPER == *"smi"* ]]; then $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 if (( $? == 0 )); then device=${device}s2 fi fi # # Get all the cache devices and status table like below # # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE # set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK ' function parse_name(status) { if (status == "OFFLINE") return substr($7,6,3) else if (status == "UNAVAIL") return substr($7,6,3) else return $1 } BEGIN {start=0} \ /\tcache/ {start=1} /\tmirror/ || /\tspares/ || /^$/ {start=0} (start==1) && /\t (\/|[0-9a-zA-Z])/ \ {print "stripe:" parse_name($2) " " $2} (start==1) && /\t (\/|[a-zA-Z])/ \ {print "mirror:" parse_name($2) " " $2} # When hotspare is replacing (start==1) && /\t (\/|[a-zA-Z])/ \ {print "mirror:" parse_name($2) " " $2}' ) typeset -i i=0 typeset find=0 while (( i < ${#dev_stat_tab[@]} )); do typeset dev=${dev_stat_tab[$i]} typeset stat=${dev_stat_tab[((i+1))]} case $dev in stripe:$device) if [[ "$type" == 'mirror' ]]; then log_note "Unexpected type: mirror" return 1 else if [[ $stat != $status ]]; then log_note "Status($stat) " \ "!= Expected stat($status)" return 1 fi return 0 fi ;; mirror:$device) if [[ -z "$type" || $type == 'stripe' ]]; then log_note "Unexpected type: stripe" return 1 else if [[ $stat != $status ]]; then log_note "Status($stat) " \ "!= Expected stat($status)" return 1 fi return 0 fi ;; esac ((i += 2)) done log_note "Can not find device: $device" return 1 } function verify_cache_support { $ZPOOL upgrade -v | $GREP "Cache devices" > /dev/null 2>&1 return $? } Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cleanup.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cleanup.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cleanup.ksh (revision 292298) @@ -1,51 +1,46 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cleanup.ksh 1.1 08/05/14 SMI" # . $STF_SUITE/tests/cache/cache.kshlib verify_runnable "global" if ! verify_cache_support ; then log_unsupported "This system doesn't support cache device" fi -if datasetexists $TESTPOOL ; then - log_must $ZPOOL destroy -f $TESTPOOL -fi -if datasetexists $TESTPOOL2 ; then - log_must $ZPOOL destroy -f $TESTPOOL2 -fi +cleanup if [[ -d $VDIR ]]; then log_must $RM -rf $VDIR fi if [[ -d $VDIR2 ]]; then log_must $RM -rf $VDIR2 fi log_pass Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh (revision 292298) @@ -1,107 +1,105 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cachefile_001_pos.ksh 1.1 08/02/29 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cachefile/cachefile.kshlib ################################################################################ # # __stc_assertion_start # # ID: cachefile_001_pos # # DESCRIPTION: # # Creating a pool with "cachefile" set doesn't update zpool.cache # # STRATEGY: # 1. Create a pool with the cachefile property set # 2. Verify that the pool doesn't have an entry in zpool.cache # 3. Verify the cachefile property is set # 4. Create a pool without the cachefile property # 5. Verify the cachefile property isn't set # 6. Verify that zpool.cache contains an entry for the pool # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-09-05) # # __stc_assertion_end # ################################################################################ function cleanup { typeset file - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL for file in $CPATH1 $CPATH2 ; do if [[ -f $file ]] ; then log_must $RM $file fi done } verify_runnable "global" log_assert "Creating a pool with \"cachefile\" set doesn't update zpool.cache" log_onexit cleanup CPATHARG="-" set -A opts "none" "false" "none" \ "$CPATH" "true" "$CPATHARG" \ "$CPATH1" "true" "$CPATH1" \ "$CPATH2" "true" "$CPATH2" typeset -i i=0 while (( i < ${#opts[*]} )); do log_must $ZPOOL create -o cachefile=${opts[i]} $TESTPOOL $DISKS case ${opts[((i+1))]} in false) log_mustnot pool_in_cache $TESTPOOL ;; true) log_must pool_in_cache $TESTPOOL ${opts[i]} ;; esac PROP=$(get_pool_prop cachefile $TESTPOOL) if [[ $PROP != ${opts[((i+2))]} ]]; then log_fail "cachefile property not set as expected. " \ "Expect: ${opts[((i+2))]}, Current: $PROP" fi log_must $ZPOOL destroy $TESTPOOL (( i = i + 3 )) done log_pass "Creating a pool with \"cachefile\" set doesn't update zpool.cache" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh (revision 292298) @@ -1,94 +1,92 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cachefile_002_pos.ksh 1.2 09/01/13 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cachefile/cachefile.kshlib ################################################################################ # # __stc_assertion_start # # ID: cachefile_002_pos # # DESCRIPTION: # # Importing a pool with "cachefile" set doesn't update zpool.cache # # STRATEGY: # 1. Create a pool with the cachefile property set # 2. Verify the pool doesn't have an entry in zpool.cache # 3. Export the pool # 4. Import the pool # 5. Verify the pool does have an entry in zpool.cache # 6. Export the pool # 7. Import the pool -o cachefile= # 8. Verify the pool doesn't have an entry in zpool.cache # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-09-05) # # __stc_assertion_end # ################################################################################ function cleanup { - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL } verify_runnable "global" log_assert "Importing a pool with \"cachefile\" set doesn't update zpool.cache" log_onexit cleanup log_must $ZPOOL create -o cachefile=none $TESTPOOL $DISKS typeset DEVICEDIR=$(get_device_dir $DISKS) log_mustnot pool_in_cache $TESTPOOL log_must $ZPOOL export $TESTPOOL log_must $ZPOOL import -d $DEVICEDIR $TESTPOOL log_must pool_in_cache $TESTPOOL log_must $ZPOOL export $TESTPOOL log_must $ZPOOL import -o cachefile=none -d $DEVICEDIR $TESTPOOL log_mustnot pool_in_cache $TESTPOOL log_must $ZPOOL export $TESTPOOL log_must $ZPOOL import -o cachefile=$CPATH -d $DEVICEDIR $TESTPOOL log_must pool_in_cache $TESTPOOL log_must $ZPOOL destroy $TESTPOOL log_pass "Importing a pool with \"cachefile\" set doesn't update zpool.cache" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh (revision 292298) @@ -1,113 +1,111 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cachefile_003_pos.ksh 1.1 08/02/29 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cachefile/cachefile.kshlib ################################################################################ # # __stc_assertion_start # # ID: cachefile_003_pos # # DESCRIPTION: # # Setting altroot= and cachefile=$CPATH for zpool create is succeed # # STRATEGY: # 1. Attempt to create a pool with -o altroot= -o cachefile= # 2. Verify the command succeed # # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-09-10) # # __stc_assertion_end # ################################################################################ TESTDIR=/altdir.${TESTCASE_ID} function cleanup { typeset file - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL for file in $CPATH1 $CPATH2 ; do if [[ -f $file ]] ; then log_must $RM $file fi done if [ -d $TESTDIR ] then $RMDIR $TESTDIR fi } verify_runnable "global" log_assert "Setting altroot=path and cachefile=$CPATH for zpool create succeed." log_onexit cleanup typeset -i i=0 CPATHARG="-" set -A opts "none" "none" \ "$CPATH" "$CPATHARG" \ "$CPATH1" "$CPATH1" \ "$CPATH2" "$CPATH2" while (( i < ${#opts[*]} )); do log_must $ZPOOL create -o altroot=$TESTDIR -o cachefile=${opts[i]} \ $TESTPOOL $DISKS if [[ ${opts[i]} != none ]]; then log_must pool_in_cache $TESTPOOL ${opts[i]} else log_mustnot pool_in_cache $TESTPOOL fi PROP=$(get_pool_prop cachefile $TESTPOOL) if [[ $PROP != ${opts[((i+1))]} ]]; then log_fail "cachefile property not set as expected. " \ "Expect: ${opts[((i+1))]}, Current: $PROP" fi log_must $ZPOOL destroy $TESTPOOL (( i = i + 2 )) done log_pass "Setting altroot=path and cachefile=$CPATH for zpool create succeed." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh (revision 292298) @@ -1,136 +1,134 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cachefile_004_pos.ksh 1.2 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cachefile/cachefile.kshlib ################################################################################# # # __stc_assertion_start # # ID: cachefile_004_pos # # DESCRIPTION: # Verify set, export and destroy when cachefile is set on pool. # # STRATEGY: # 1. Create two pools with one same cahcefile1. # 2. Set cachefile of the two pools to another same cachefile2. # 3. Verify cachefile1 not exist. # 4. Export the two pools. # 5. Verify cachefile2 not exist. # 6. Import the two pools and set cachefile to cachefile2. # 7. Destroy the two pools. # 8. Verify cachefile2 not exist. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-04-24) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 - poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL2 mntpnt=$(get_prop mountpoint $TESTPOOL) typeset -i i=0 while ((i < 2)); do if [[ -e $mntpnt/vdev$i ]]; then log_must $RM -f $mntpnt/vdev$i fi ((i += 1)) done - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL for file in $CPATH1 $CPATH2 ; do if [[ -f $file ]] ; then log_must $RM $file fi done } log_assert "Verify set, export and destroy when cachefile is set on pool." log_onexit cleanup log_must $ZPOOL create $TESTPOOL $DISKS mntpnt=$(get_prop mountpoint $TESTPOOL) typeset -i i=0 while ((i < 2)); do log_must $MKFILE 64M $mntpnt/vdev$i eval vdev$i=$mntpnt/vdev$i ((i += 1)) done log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0 log_must pool_in_cache $TESTPOOL1 $CPATH1 log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1 log_must pool_in_cache $TESTPOOL2 $CPATH1 log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1 log_must pool_in_cache $TESTPOOL1 $CPATH2 log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2 log_must pool_in_cache $TESTPOOL2 $CPATH2 if [[ -f $CPATH1 ]]; then log_fail "Verify set when cachefile is set on pool." fi log_must $ZPOOL export $TESTPOOL1 log_must $ZPOOL export $TESTPOOL2 if [[ -f $CPATH2 ]]; then log_fail "Verify export when cachefile is set on pool." fi log_must $ZPOOL import -d $mntpnt $TESTPOOL1 log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1 log_must pool_in_cache $TESTPOOL1 $CPATH2 log_must $ZPOOL import -d $mntpnt $TESTPOOL2 log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2 log_must pool_in_cache $TESTPOOL2 $CPATH2 log_must $ZPOOL destroy $TESTPOOL1 log_must $ZPOOL destroy $TESTPOOL2 if [[ -f $CPATH2 ]]; then log_fail "Verify destroy when cachefile is set on pool." fi log_pass "Verify set, export and destroy when cachefile is set on pool." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib (revision 292298) @@ -1,152 +1,151 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_add.kshlib 1.3 07/03/14 SMI" # . $STF_SUITE/include/libtest.kshlib # # check if the contains ... # # $1 pool # $2..n ... # # Return 0 if are contained in the ; 1 if not used; 2 if pool # name is missing # function iscontained { typeset pool=$1 typeset vdev if [[ -z $pool ]]; then log_note "Missing pool name." return 2 fi shift for vdev in $@; do # remove /dev/dsk in vdev if there is $ECHO $vdev | $GREP "^/dev/" >/dev/null 2>&1 (( $? == 0 )) && \ vdev=${vdev##*/} $ZPOOL status "$pool" | $AWK '$1 == vdevname {exit 1}' \ vdevname=$vdev >/dev/null 2>&1 (( $? != 1 )) && \ return 1 done return 0; } # # Find the storage device in /etc/fstab # function find_vfstab_dev { typeset vfstab="/etc/fstab" typeset tmpfile="$TMPDIR/fstab.tmp" typeset vfstabdev typeset vfstabdevs="" typeset line $CAT $vfstab | $GREP "^/dev/" >$tmpfile while read -r line do vfstabdev=`$ECHO "$line" | $AWK '{print $1}'` vfstabdev=${vfstabdev%%:} vfstabdevs="$vfstabdev $vfstabdevs" done <$tmpfile $RM -f $tmpfile $ECHO $vfstabdevs } # # Find the storage device in /etc/mnttab # function find_mnttab_dev { typeset mnttab="/etc/mnttab" typeset tmpfile="$TMPDIR/mnttab.tmp" typeset mnttabdev typeset mnttabdevs="" typeset line $MOUNT | $GREP "^/dev/" >$tmpfile while read -r line do mnttabdev=`$ECHO "$line" | $AWK '{print $1}'` mnttabdev=${mnttabdev%%:} mnttabdevs="$mnttabdev $mnttabdevs" done <$tmpfile $RM -f $tmpfile $ECHO $mnttabdevs } # # Save the systme current dump device configuration # function save_dump_dev { typeset dumpdev typeset swapdev typeset swapdevs="" typeset tmpfile="$TMPDIR/swapinfo.tmp" dumpdev=`readlink /dev/dumpdev` swapinfo | $GREP "^/dev/" >$tmpfile while read -r line do swapdev=`$ECHO "$line" | $AWK '{print $1}'` swapdev=${swapdev%%:} swapdevs="$swapdev $swapdevs" done <$tmpfile $ECHO "$dumpdev $swapdevs" } # # Common cleanup routine for partitions used in testing # function partition_cleanup { - - if [[ -n $DISK ]]; then - partition_disk $SIZE $DISK 7 - else - typeset disk="" - for disk in $DISK0 $DISK1; do - partition_disk $SIZE $disk 7 - done - fi - + log_note "Cleaning up partitions..." + if [[ -n $DISK ]]; then + partition_disk $SIZE $DISK 7 + else + typeset disk="" + for disk in $DISK0 $DISK1; do + partition_disk $SIZE $disk 7 + done + fi } Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh (revision 292298) @@ -1,168 +1,162 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_add_006_pos.ksh 1.5 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_add_006_pos # # DESCRIPTION: # 'zpool add [-f]' can add large numbers of file-in-zfs-filesystem-based vdevs # to the specified pool without any errors. # # STRATEGY: # 1. Create assigned number of files in ZFS filesystem as vdevs and use the first # file to create a pool # 2. Add other vdevs to the pool should get success # 3 Fill in the filesystem and create a partially written file # as vdev # 4. Add the new file into the pool should be failed. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-10-09) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { poolexists $TESTPOOL1 && \ destroy_pool $TESTPOOL1 datasetexists $TESTPOOL/$TESTFS && \ log_must $ZFS destroy -f $TESTPOOL/$TESTFS poolexists $TESTPOOL && \ destroy_pool $TESTPOOL if [[ -d $TESTDIR ]]; then log_must $RM -rf $TESTDIR fi partition_cleanup } # # Create a pool and fs on the assigned disk, and dynamically create large # numbers of files as vdevs.(the default value is ) # the first file will be used to create a pool for other vdevs to be added into # function setup_vdevs # { typeset disk=$1 typeset -i count=0 typeset -i largest_num=0 typeset -i slicesize=0 typeset vdev="" - - # - # Get disk size for zfs filesystem - # - create_pool foo $disk - log_must $ZFS create foo/fs - typeset -li fs_size=$(get_prop "available" foo/fs) - destroy_pool foo + fs_size=$(get_available_disk_size $disk) - (( largest_num = fs_size / (1024 * 1024 * 64) )) #64m is the minmum size for pool + # 64M is the minimum size for the pool + (( largest_num = fs_size / (1024 * 1024 * 64) )) if (( largest_num < $VDEVS_NUM )); then - (( vdevs_num=largest_num - largest_num/20 )) # minus $largest_num/20 to leave - #5% space for metadata. + # Minus $largest_num/20 to leave 5% space for metadata. + (( vdevs_num=largest_num - largest_num/20 )) file_size=64 vdev=$disk else vdevs_num=$VDEVS_NUM (( file_size = fs_size / (1024 * 1024 * (vdevs_num + vdevs_num/20)) )) if (( file_size > FILE_SIZE )); then file_size=$FILE_SIZE fi - (( slice_size = file_size * (vdevs_num + vdevs_num/20) )) # plus $vdevs_num/20 to provide - #enough space for metadata. + # Plus $vdevs_num/20 to provide enough space for metadata. + (( slice_size = file_size * (vdevs_num + vdevs_num/20) )) wipe_partition_table $disk set_partition 0 "" ${slice_size}m $disk vdev=${disk}p1 fi create_pool $TESTPOOL $vdev [[ -d $TESTDIR ]] && \ log_must $RM -rf $TESTDIR log_must $MKDIR -p $TESTDIR log_must $ZFS create $TESTPOOL/$TESTFS log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS # Create a pool first using the first file, and make subsequent files ready # as vdevs to add to the pool log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count create_pool "$TESTPOOL1" "${TESTDIR}/file.$count" log_must poolexists "$TESTPOOL1" while (( count < vdevs_num )); do # minus 1 to avoid space non-enough (( count = count + 1 )) log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count vdevs_list="$vdevs_list ${TESTDIR}/file.$count" done } log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \ " pool without any errors." log_onexit cleanup if [[ $DISK_ARRAY_NUM == 0 ]]; then disk=$DISK else disk=$DISK0 fi vdevs_list="" vdevs_num=$VDEVS_NUM file_size=$FILE_SIZE setup_vdevs $disk log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list log_must iscontained "$TESTPOOL1" "$vdevs_list" (( file_size = file_size * (vdevs_num/20 + 1 ) )) log_mustnot $MKFILE ${file_size}m ${TESTDIR}/broken_file log_mustnot $ZPOOL add -f "$TESTPOOL1" ${TESTDIR}/broken_file log_mustnot iscontained "$TESTPOOL1" "${TESTDIR}/broken_file" log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \ "specified pool without any errors." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh (revision 292298) @@ -1,228 +1,227 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_clear_001_pos.ksh 1.3 07/02/06 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_clear_001_pos # # DESCRIPTION: # Verify 'zpool clear' can clear pool errors. # # STRATEGY: # 1. Create various configuration pools # 2. Make errors to pool # 3. Use zpool clear to clear errors # 4. Verify the errors has been cleared. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2006-08-10) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - poolexists $TESTPOOL1 && \ - log_must $ZPOOL destroy -f $TESTPOOL1 + destroy_pool $TESTPOOL1 for file in `$LS $TMPDIR/file.*`; do log_must $RM -f $file done } log_assert "Verify 'zpool clear' can clear errors of a storage pool." log_onexit cleanup #make raw files to create various configuration pools typeset -i i=0 while (( i < 3 )); do log_must $MKFILE $FILESIZE $TMPDIR/file.$i (( i = i + 1 )) done fbase=$TMPDIR/file set -A poolconf "mirror $fbase.0 $fbase.1 $fbase.2" \ "raidz1 $fbase.0 $fbase.1 $fbase.2" \ "raidz2 $fbase.0 $fbase.1 $fbase.2" function check_err # [] { typeset pool=$1 shift if (( $# > 0 )); then typeset checkvdev=$1 else typeset checkvdev="" fi typeset -i errnum=0 typeset c_read=0 typeset c_write=0 typeset c_cksum=0 typeset tmpfile=$TMPDIR/file.${TESTCASE_ID} typeset healthstr="pool '$pool' is healthy" typeset output="`$ZPOOL status -x $pool`" [[ "$output" == "$healthstr" ]] && return $errnum $ZPOOL status -x $pool | $GREP -v "^$" | $GREP -v "pool:" \ | $GREP -v "state:" | $GREP -v "config:" \ | $GREP -v "errors:" > $tmpfile typeset line typeset -i fetchbegin=1 while read line; do if (( $fetchbegin != 0 )); then $ECHO $line | $GREP "NAME" >/dev/null 2>&1 (( $? == 0 )) && (( fetchbegin = 0 )) continue fi if [[ -n $checkvdev ]]; then $ECHO $line | $GREP $checkvdev >/dev/null 2>&1 (( $? != 0 )) && continue c_read=`$ECHO $line | $AWK '{print $3}'` c_write=`$ECHO $line | $AWK '{print $4}'` c_cksum=`$ECHO $line | $AWK '{print $5}'` if [ $c_read != 0 ] || [ $c_write != 0 ] || \ [ $c_cksum != 0 ] then (( errnum = errnum + 1 )) fi break fi c_read=`$ECHO $line | $AWK '{print $3}'` c_write=`$ECHO $line | $AWK '{print $4}'` c_cksum=`$ECHO $line | $AWK '{print $5}'` if [ $c_read != 0 ] || [ $c_write != 0 ] || \ [ $c_cksum != 0 ] then (( errnum = errnum + 1 )) fi done <$tmpfile return $errnum } function do_testing # { typeset FS=$TESTPOOL1/fs typeset file=/$FS/f typeset type=$1 shift typeset vdev="$@" log_must $ZPOOL create -f $TESTPOOL1 $vdev log_must $ZFS create $FS # # Fully fill up the zfs filesystem in order to make data block errors # zfs filesystem # typeset -i ret=0 typeset -i i=0 while $TRUE ; do $FILE_WRITE -o create -f $file.$i \ -b $BLOCKSZ -c $NUM_WRITES ret=$? (( $ret != 0 )) && break (( i = i + 1 )) done (( $ret != 28 )) && log_fail "$FILE_WRITE fails to fully fill up the $FS." # #Make errors to the testing pool by overwrite the vdev device with #/bin/dd command. We donot want to have a full overwrite. That #may cause the system panic. So, we should skip the vdev label space. # (( i = $RANDOM % 3 )) typeset -i wcount=0 typeset -i size case $FILESIZE in *g|*G) (( size = ${FILESIZE%%[g|G]} )) (( wcount = size*1024*1024 - 512 )) ;; *m|*M) (( size = ${FILESIZE%%[m|M]} )) (( wcount = size*1024 - 512 )) ;; *k|*K) (( size = ${FILESIZE%%[k|K]} )) (( wcount = size - 512 )) ;; *) (( wcount = FILESIZE/1024 - 512 )) ;; esac $DD if=/dev/zero of=$fbase.$i seek=512 bs=1024 count=$wcount conv=notrunc \ > /dev/null 2>&1 log_must $SYNC log_must $ZPOOL scrub $TESTPOOL1 # Wait for the completion of scrub operation while is_pool_scrubbing $TESTPOOL1; do $SLEEP 1 done check_err $TESTPOOL1 && \ log_fail "No error generated." if [[ $type == "device" ]]; then log_must $ZPOOL clear $TESTPOOL1 $fbase.$i ! check_err $TESTPOOL1 $fbase.$i && \ log_fail "'zpool clear' fails to clear error for $fbase.$i device." fi if [[ $type == "pool" ]]; then log_must $ZPOOL clear $TESTPOOL1 ! check_err $TESTPOOL1 && \ log_fail "'zpool clear' fails to clear error for pool $TESTPOOL1." fi log_must $ZPOOL destroy $TESTPOOL1 } log_note "'zpool clear' clears leaf-device error." for devconf in "${poolconf[@]}"; do do_testing "device" $devconf done log_note "'zpool clear' clears top-level pool error." for devconf in "${poolconf[@]}"; do do_testing "pool" $devconf done log_pass "'zpool clear' clears pool errors as expected." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh (revision 292298) @@ -1,104 +1,101 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2013 Spectra Logic Corp. All rights reserved. # Use is subject to license terms. # # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_clear_004_pos # # DESCRIPTION: # Verify 'zpool clear' can clear errors on spare devices. # # We don't need to check whether 'zpool clear' actually clears error counters. # zpool_clear_001_pos will do that. We just need to check that it doesn't # return an error when used on a spare vdev. This is really a test for whether # zpool_find_vdev() from libzfs can work on a spare vdev. Note that we're # talking about he mirror-like "spare-0" vdev, not the leaf hotspare vdev. # # STRATEGY: # 1. Create a pool # 2. Activate a spare # 3. Verify that "zpool clear" on the spare returns no errors # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2013-06-26) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - poolexists $TESTPOOL1 && \ - log_must $ZPOOL destroy -f $TESTPOOL1 + destroy_pool $TESTPOOL1 for file in `$LS $TMPDIR/file.*`; do log_must $RM -f $file done restart_zfsd } log_assert "Verify 'zpool clear' works on spare vdevs" log_onexit cleanup # Stop ZFSD so it won't interfere with our spare device. stop_zfsd #make raw files to create various configuration pools typeset -i i=0 while (( i < 3 )); do log_must $MKFILE $FILESIZE $TMPDIR/file.$i (( i = i + 1 )) done fbase=$TMPDIR/file VDEV1=$fbase.0 VDEV2=$fbase.1 SDEV=$fbase.2 typeset devlist="$VDEV1 $VDEV2 spare $SDEV" log_note "'zpool clear' clears leaf-device error." log_must $ZPOOL create -f $TESTPOOL1 $devlist log_must $ZPOOL replace $TESTPOOL1 $VDEV1 $SDEV log_must $ZPOOL clear $TESTPOOL1 "spare-0" - -log_must $ZPOOL destroy $TESTPOOL1 log_pass "'zpool clear' works on spare vdevs" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh (revision 292298) @@ -1,106 +1,101 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident "@(#)zpool_create_015_neg.ksh 1.2 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_015_neg # # # DESCRIPTION: # 'zpool create' will fail with zfs vol device in swap # # # STRATEGY: # 1. Create a zpool # 2. Create a zfs vol on zpool # 3. Add this zfs vol device to swap # 4. Try to create a new pool with devices in swap # 5. Verify the creation is failed. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-04-17) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { # cleanup zfs pool and dataset if datasetexists $vol_name; then $SWAP -l | $GREP /dev/zvol/$vol_name > /dev/null 2>&1 if [[ $? -eq 0 ]]; then $SWAP -d /dev/zvol/${vol_name} fi fi - for pool in $TESTPOOL1 $TESTPOOL; do - if poolexists $pool; then - destroy_pool $pool - fi - done - + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL } if [[ -n $DISK ]]; then disk=$DISK else disk=$DISK0 fi typeset pool_dev=${disk}p1 typeset vol_name=$TESTPOOL/$TESTVOL log_assert "'zpool create' should fail with zfs vol device in swap." log_onexit cleanup # # use zfs vol device in swap to create pool which should fail. # create_pool $TESTPOOL $pool_dev log_must $ZFS create -V 100m $vol_name log_must $SWAP -a /dev/zvol/$vol_name for opt in "-n" "" "-f"; do log_mustnot $ZPOOL create $opt $TESTPOOL1 /dev/zvol/${vol_name} done # cleanup log_must $SWAP -d /dev/zvol/${vol_name} log_must $ZFS destroy $vol_name -log_must $ZPOOL destroy $TESTPOOL log_pass "'zpool create' passed as expected with inapplicable scenario." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh (revision 292298) @@ -1,101 +1,98 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_create_016_pos.ksh 1.2 08/08/15 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_016_pos # # # DESCRIPTION: # 'zpool create' will success with no device in swap # # # STRATEGY: # 1. delete all devices in the swap # 2. create a zpool # 3. Verify the creation is successed. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-04-17) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL #recover swap devices FSTAB=$TMPDIR/fstab_${TESTCASE_ID} $RM -f $FSTAB for sdisk in $swap_disks; do $ECHO "$sdisk - - swap - no -" >> $FSTAB done if [ -e $FSTAB ] then log_must $SWAPADD $FSTAB fi $RM -f $FSTAB if [ $dump_device != "none" ] then log_must $DUMPADM -u -d $dump_device fi } if [[ -n $DISK ]]; then disk=$DISK else disk=$DISK0 fi typeset pool_dev=${disk}p1 typeset swap_disks=`$SWAP -l | $GREP -v "swapfile" | $AWK '{print $1}'` typeset dump_device=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'` log_assert "'zpool create' should success with no device in swap." log_onexit cleanup for sdisk in $swap_disks; do log_must $SWAP -d $sdisk done log_must $ZPOOL create $TESTPOOL $pool_dev -log_must $ZPOOL destroy $TESTPOOL log_pass "'zpool create' passed as expected with applicable scenario." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh (revision 292298) @@ -1,125 +1,118 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_create_018_pos.ksh 1.4 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_018_pos # # DESCRIPTION: # # zpool create can create pools with specified properties # # STRATEGY: # 1. Create a pool with all editable properties # 2. Verify those properties are set # 3. Create a pool with two properties set # 4. Verify both properties are set correctly # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-07-27) # # __stc_assertion_end # ################################################################################ function cleanup { - if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL if [[ -f $CPATH ]] ; then log_must $RM $CPATH fi } log_onexit cleanup log_assert "zpool create can create pools with specified properties" if [[ -n $DISK ]]; then disk=$DISK else disk=$DISK0 fi # we don't include "root" property in this list, as it requires both "cachefile" # and "root" to be set at the same time. A test for this is included in # ../../root. set -A props "autoreplace" "delegation" "cachefile" "version" set -A vals "off" "off" "$CPATH" "3" if pool_prop_exist autoexpand ; then set -A props ${props[*]} "autoexpand" set -A vals ${vals[*]} "on" fi typeset -i i=0; while [ $i -lt "${#props[@]}" ] do log_must $ZPOOL create -o ${props[$i]}=${vals[$i]} $TESTPOOL $disk RESULT=$(get_pool_prop ${props[$i]} $TESTPOOL) if [[ $RESULT != ${vals[$i]} ]] then $ZPOOL get all $TESTPOOL log_fail "Pool was created without setting the ${props[$i]} property" fi - log_must $ZPOOL destroy $TESTPOOL + destroy_pool $TESTPOOL (( i = i + 1 )) done -# Destroy our pool -if poolexists $TESTPOOL ; then - destroy_pool $TESTPOOL -fi - # pick two properties, and verify we can create with those as well log_must $ZPOOL create -o delegation=off -o cachefile=$CPATH $TESTPOOL $disk RESULT=$(get_pool_prop delegation $TESTPOOL) if [[ $RESULT != off ]] then - $ZPOOL get all $TESTPOOL - log_fail "Pool created without the delegation prop." + $ZPOOL get all $TESTPOOL + log_fail "Pool created without the delegation prop." fi RESULT=$(get_pool_prop cachefile $TESTPOOL) if [[ $RESULT != $CPATH ]] then - $ZPOOL get all $TESTPOOL - log_fail "Pool created without the cachefile prop." + $ZPOOL get all $TESTPOOL + log_fail "Pool created without the cachefile prop." fi log_pass "zpool create can create pools with specified properties" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh (revision 292298) @@ -1,104 +1,104 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_create_021_pos.ksh 1.2 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_021_pos # # DESCRIPTION: # 'zpool create -O property=value pool' can successfully create a pool # with correct filesystem property set. # # STRATEGY: # 1. Create a storage pool with -O option # 2. Verify the pool created successfully # 3. Verify the filesystem property is correctly set # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-04-27) # # __stc_assertion_end # ################################################################################ if ! $(check_zpool_opt_support "create" "-O") ; then log_unsupported "-O option is not supported yet." fi verify_runnable "global" function cleanup { - datasetexists $TESTPOOL && destroy_pool $TESTPOOL + destroy_pool $TESTPOOL } log_onexit cleanup log_assert "'zpool create -O property=value pool' can successfully create a pool \ with correct filesystem property set." set -A RW_FS_PROP "quota=512M" \ "reservation=512M" \ "recordsize=64K" \ "mountpoint=/tmp/mnt${TESTCASE_ID}" \ "checksum=fletcher2" \ "compression=lzjb" \ "atime=off" \ "devices=off" \ "exec=off" \ "setuid=off" \ "readonly=on" \ "snapdir=visible" \ "aclmode=discard" \ "aclinherit=discard" \ "canmount=off" \ "sharenfs=on" typeset -i i=0 while (( $i < ${#RW_FS_PROP[*]} )); do log_must $ZPOOL create -O ${RW_FS_PROP[$i]} -f $TESTPOOL $DISKS datasetexists $TESTPOOL || \ log_fail "zpool create $TESTPOOL fail." propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." - log_must $ZPOOL destroy $TESTPOOL + destroy_pool $TESTPOOL (( i = i + 1 )) done log_pass "'zpool create -O property=value pool' can successfully create a pool \ with correct filesystem property set." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh (revision 292298) @@ -1,111 +1,111 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_create_022_pos.ksh 1.1 09/05/19 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_022_pos # # DESCRIPTION: # 'zpool create -O property=value pool' can successfully create a pool # with multiple filesystem properties set. # # STRATEGY: # 1. Create a storage pool with multiple -O options # 2. Verify the pool created successfully # 3. Verify the properties are correctly set # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-04-27) # # __stc_assertion_end # ################################################################################ if ! $(check_zpool_opt_support "create" "-O") ; then log_unsupported "-O option is not supported yet." fi verify_runnable "global" function cleanup { - datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL + destroy_pool $TESTPOOL } log_onexit cleanup log_assert "'zpool create -O property=value pool' can successfully create a pool \ with multiple filesystem properties set." set -A RW_FS_PROP "quota=512M" \ "reservation=512M" \ "recordsize=64K" \ "mountpoint=/tmp/mnt${TESTCASE_ID}" \ "checksum=fletcher2" \ "compression=lzjb" \ "atime=off" \ "devices=off" \ "exec=off" \ "setuid=off" \ "readonly=on" \ "snapdir=visible" \ "aclmode=discard" \ "aclinherit=discard" \ "canmount=off" \ "sharenfs=on" typeset -i i=0 typeset opts="" while (( $i < ${#RW_FS_PROP[*]} )); do opts="$opts -O ${RW_FS_PROP[$i]}" (( i = i + 1 )) done log_must $ZPOOL create $opts -f $TESTPOOL $DISKS datasetexists $TESTPOOL || log_fail "zpool create $TESTPOOL fail." i=0 while (( $i < ${#RW_FS_PROP[*]} )); do propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." (( i = i + 1 )) done log_pass "'zpool create -O property=value pool' can successfully create a pool \ with multiple filesystem properties set." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh (revision 292298) @@ -1,100 +1,100 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_create_023_neg.ksh 1.1 09/05/19 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_create_023_neg # # DESCRIPTION: # 'zpool create -O' should return an error with badly formed parameters. # # STRATEGY: # 1. Create an array of parameters with '-O' # 2. For each parameter in the array, execute 'zpool create -O' # 3. Verify an error is returned. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-04-27) # # __stc_assertion_end # ################################################################################ if ! $(check_zpool_opt_support "create" "-O") ; then log_unsupported "-O option is not supported yet." fi verify_runnable "global" function cleanup { - datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL + destroy_pool $TESTPOOL } log_onexit cleanup set -A args "QuOta=none" "quota=non" "quota=abcd" "quota=0" "quota=" \ "ResErVaTi0n=none" "reserV=none" "reservation=abcd" "reserv=" \ "recorDSize=64k" "recordsize=256K" "recordsize=256" \ "recsize=" "recsize=zero" "recordsize=0" \ "mountPoint=/tmp/tmpfile${TESTCASE_ID}" "mountpoint=non0" "mountpoint=" \ "mountpoint=LEGACY" "mounpoint=none" \ "sharenfs=ON" "ShareNFS=off" "sharenfs=sss" \ "checkSUM=on" "checksum=SHA256" "chsum=off" "checksum=aaa" \ "compression=of" "ComPression=lzjb" "compress=ON" "compress=a" \ "atime=ON" "ATime=off" "atime=bbb" \ "deviCes=on" "devices=OFF" "devices=aaa" \ "exec=ON" "EXec=off" "exec=aaa" \ "readonly=ON" "reADOnly=off" "rdonly=OFF" "rdonly=aaa" \ "zoned=ON" "ZoNed=off" "zoned=aaa" \ "snapdIR=hidden" "snapdir=VISible" "snapdir=aaa" \ "aclmode=DIScard" "aclmODE=groupmask" "aclmode=aaa" \ "aclinherit=deny" "aclinHerit=secure" "aclinherit=aaa" \ "type=volume" "type=snapshot" "type=filesystem" \ "creation=aaa" "used=10K" "available=10K" \ "referenced=10K" "compressratio=1.00x" \ "version=0" "version=1.234" "version=10K" "version=-1" \ "version=aaa" "version=999" log_assert "'zpool create -O' should return an error with badly formed parameters." typeset -i i=0 while (( $i < ${#args[*]} )); do log_mustnot $ZPOOL create -O ${args[i]} -f $TESTPOOL $DISKS ((i = i + 1)) done log_pass "'zpool create -O' should return an error with badly formed parameters." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh (revision 292298) @@ -1,96 +1,90 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_destroy_001_pos.ksh 1.7 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_destroy_001_pos # # DESCRIPTION: # 'zpool destroy ' can successfully destroy the specified pool. # # STRATEGY: # 1. Create a storage pool # 2. Destroy the pool # 3. Verify the is destroyed successfully # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING STATUS: COMPLETED (2005-07-04) # # __stc_assertion_end # ############################################################################### verify_runnable "global" function cleanup { - poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 - datasetexists $TESTPOOL1/$TESTVOL && \ - log_must $ZFS destroy -f $TESTPOOL1/$TESTVOL - - typeset pool - for pool in $TESTPOOL1 $TESTPOOL; do - poolexists $pool && destroy_pool $pool - done - + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL wipe_partition_table $DISK } set -A datasets "$TESTPOOL" "$TESTPOOL2" if ! $(is_physical_device $DISKS) ; then log_unsupported "This case cannot be run on raw files." fi log_assert "'zpool destroy ' can destroy a specified pool." log_onexit cleanup partition_disk $PART_SIZE $DISK 2 create_pool "$TESTPOOL" "${DISK}p1" create_pool "$TESTPOOL1" "${DISK}p2" log_must $ZFS create -s -V $VOLSIZE $TESTPOOL1/$TESTVOL create_pool "$TESTPOOL2" "/dev/zvol/$TESTPOOL1/$TESTVOL" typeset -i i=0 while (( i < ${#datasets[*]} )); do log_must poolexists "${datasets[i]}" log_must $ZPOOL destroy "${datasets[i]}" log_mustnot poolexists "${datasets[i]}" ((i = i + 1)) done log_pass "'zpool destroy ' executes successfully" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh (revision 292298) @@ -1,127 +1,120 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_destroy_002_pos.ksh 1.3 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_destroy_002_pos # # DESCRIPTION: # 'zpool destroy -f ' can forcely destroy the specified pool. # # STRATEGY: # 1. Create a storage pool # 2. Create some datasets within the pool # 3. Change directory to any mountpoint of these datasets, # Verify 'zpool destroy' without '-f' will fail. # 4. 'zpool destroy -f' the pool # 5. Verify the pool is destroyed successfully # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-07-04) # # __stc_assertion_end # ############################################################################### verify_runnable "global" function cleanup { [[ -n $cwd ]] && log_must cd $cwd if [[ -d $TESTDIR ]]; then ismounted $TESTDIR (( $? == 0 )) && \ log_must $UNMOUNT $TESTDIR log_must $RM -rf $TESTDIR fi - typeset -i i=0 - while (( $i < ${#datasets[*]} )); do - datasetexists ${datasets[i]} && \ - log_must $ZFS destroy ${datasets[i]} - (( i = i + 1 )) - done - - poolexists $TESTPOOL && destroy_pool $TESTPOOL + destroy_pool $TESTPOOL } set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \ "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \ log_assert "'zpool destroy -f ' can forcely destroy the specified pool" log_onexit cleanup typeset cwd="" create_pool "$TESTPOOL" "$DISK" log_must $ZFS create $TESTPOOL/$TESTFS log_must $MKDIR -p $TESTDIR log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_must $ZFS create $TESTPOOL/$TESTCTR log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1 log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL typeset -i i=0 while (( $i < ${#datasets[*]} )); do datasetexists "${datasets[i]}" || \ log_fail "Create datasets fail." ((i = i + 1)) done cwd=$PWD log_note "'zpool destroy' without '-f' will fail " \ "while pool is busy." for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do log_must cd $dir log_mustnot $ZPOOL destroy $TESTPOOL # Need mount here, otherwise some dataset may be unmounted. log_must $ZFS mount -a i=0 while (( i < ${#datasets[*]} )); do datasetexists "${datasets[i]}" || \ log_fail "Dataset ${datasets[i]} removed unexpected." ((i = i + 1)) done done destroy_pool $TESTPOOL log_mustnot poolexists "$TESTPOOL" log_pass "'zpool destroy -f ' success." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh (revision 292298) @@ -1,138 +1,136 @@ #! /usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_expand_001_pos.ksh 1.2 09/08/06 SMI" # . $STF_SUITE/include/libtest.kshlib ############################################################################### # # __stc_assertion_start # # ID: zpool_expand_001_pos # # DESCRIPTION: # Once zpool set autoexpand=on poolname, zpool can autoexpand by # Dynamic LUN Expansion # # # STRATEGY: # 1) Create a pool # 2) Create volume on top of the pool # 3) Create pool by using the zvols and set autoexpand=on # 4) Expand the vol size by 'zfs set volsize' # 5) Check that the pool size was expanded # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-06-12) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL1; then - log_must $ZPOOL destroy $TESTPOOL1 - fi + destroy_pool $TESTPOOL1 for i in 1 2 3; do if datasetexists $VFS/vol$i; then log_must $ZFS destroy $VFS/vol$i fi done } log_onexit cleanup log_assert "zpool can be autoexpanded after set autoexpand=on on LUN expansion" for i in 1 2 3; do log_must $ZFS create -V $org_size $VFS/vol$i done for type in " " mirror raidz raidz2; do log_must $ZPOOL create -o autoexpand=on $TESTPOOL1 $type \ /dev/zvol/$VFS/vol1 \ /dev/zvol/$VFS/vol2 \ /dev/zvol/$VFS/vol3 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) if [[ $autoexp != "on" ]]; then log_fail "zpool $TESTPOOL1 autoexpand should on but is $autoexp" fi typeset prev_size=$(get_pool_prop size $TESTPOOL1) for i in 1 2 3; do log_must $ZFS set volsize=$exp_size $VFS/vol$i done $SYNC $SLEEP 10 $SYNC typeset expand_size=$(get_pool_prop size $TESTPOOL1) # check for zpool history for the pool size expansion if [[ $type == "mirror" ]]; then $ZPOOL history -il $TESTPOOL1 | \ $GREP "pool '$TESTPOOL1' size:" | \ $GREP "internal vdev online" | \ $GREP "(+${EX_1GB})" >/dev/null 2>&1 if [[ $? -ne 0 ]] ; then log_fail "pool $TESTPOOL1" \ " is not autoexpand after LUN expansion" fi else $ZPOOL history -il $TESTPOOL1 | \ $GREP "pool '$TESTPOOL1' size:" | \ $GREP "internal vdev online" | \ $GREP "(+${EX_3GB})" >/dev/null 2>&1 if [[ $? -ne 0 ]] ; then log_fail "pool $TESTPOOL1" \ " is not autoexpand after LUN expansion" fi fi log_must $ZPOOL destroy $TESTPOOL1 for i in 1 2 3; do log_must $ZFS set volsize=$org_size $VFS/vol$i done done log_pass "zpool can be autoexpanded after set autoexpand=on on LUN expansion" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh (revision 292298) @@ -1,142 +1,140 @@ #! /usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_expand_002_pos.ksh 1.1 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ############################################################################### # # __stc_assertion_start # # ID: zpool_expand_002_pos # # DESCRIPTION: # After zpool online -e poolname zvol vdevs, zpool can autoexpand by # Dynamic LUN Expansion # # # STRATEGY: # 1) Create a pool # 2) Create volume on top of the pool # 3) Create pool by using the zvols # 4) Expand the vol size by zfs set volsize # 5 Use zpool online -e to online the zvol vdevs # 6) Check that the pool size was expaned # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-06-12) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL1; then - log_must $ZPOOL destroy $TESTPOOL1 - fi + destroy_pool $TESTPOOL1 for i in 1 2 3; do if datasetexists $VFS/vol$i; then log_must $ZFS destroy $VFS/vol$i fi done } log_onexit cleanup log_assert "zpool can expand after zpool online -e zvol vdevs on LUN expansion" for i in 1 2 3; do log_must $ZFS create -V $org_size $VFS/vol$i done for type in " " mirror raidz raidz2; do log_must $ZPOOL create $TESTPOOL1 $type \ /dev/zvol/$VFS/vol1 \ /dev/zvol/$VFS/vol2 \ /dev/zvol/$VFS/vol3 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) if [[ $autoexp != "off" ]]; then log_fail "zpool $TESTPOOL1 autoexpand should off but is $autoexp" fi typeset prev_size=$(get_pool_prop size $TESTPOOL1) for i in 1 2 3; do log_must $ZFS set volsize=$exp_size $VFS/vol$i done for i in 1 2 3; do log_must $ZPOOL online -e $TESTPOOL1 /dev/zvol/$VFS/vol$i done $SYNC $SLEEP 10 $SYNC # check for zpool history for the pool size expansion if [[ $type == " " || $type == "mirror" ]]; then $ZPOOL history -il $TESTPOOL1 | \ $GREP "pool '$TESTPOOL1' size:" | \ $GREP "internal vdev online" | \ $GREP "(+${EX_1GB})" >/dev/null 2>&1 if [[ $? -ne 0 ]]; then log_fail "pool $TESTPOOL1" \ " is not autoexpand after LUN expansion" fi else $ZPOOL history -il $TESTPOOL1 | \ $GREP "pool '$TESTPOOL1' size:" | \ $GREP "internal vdev online" | \ $GREP "(+${EX_3GB})" >/dev/null 2>&1 if [[ $? -ne 0 ]] ; then log_fail "pool $TESTPOOL1" \ " is not autoexpand after LUN expansion" fi fi typeset expand_size=$(get_pool_prop size $TESTPOOL1) log_must $ZPOOL destroy $TESTPOOL1 for i in 1 2 3; do log_must $ZFS set volsize=$org_size $VFS/vol$i done done log_pass "zpool can expand after zpool online -e zvol vdevs on LUN expansion" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh (revision 292298) @@ -1,128 +1,126 @@ #! /usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_expand_003_neg.ksh 1.1 09/06/22 SMI" # . $STF_SUITE/include/libtest.kshlib ############################################################################### # # __stc_assertion_start # # ID: zpool_expand_003_neg # # Description: # Once set zpool autoexpand=off, zpool can *NOT* autoexpand by # Dynamic LUN Expansion # # # STRATEGY: # 1) Create a pool # 2) Create volumes on top of the pool # 3) Create pool by using the zvols and set autoexpand=off # 4) Expand the vol size by zfs set volsize # 5) Check that the pool size is not changed # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2009-06-12) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - if poolexists $TESTPOOL1; then - log_must $ZPOOL destroy $TESTPOOL1 - fi + destroy_pool $TESTPOOL1 for i in 1 2 3; do if datasetexists $VFS/vol$i; then log_must $ZFS destroy $VFS/vol$i fi done } log_onexit cleanup log_assert "zpool can not expand if set autoexpand=off after LUN expansion" for i in 1 2 3; do log_must $ZFS create -V $org_size $VFS/vol$i done for type in "" mirror raidz raidz2; do log_must $ZPOOL create $TESTPOOL1 $type \ /dev/zvol/$VFS/vol1 \ /dev/zvol/$VFS/vol2 \ /dev/zvol/$VFS/vol3 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) if [[ $autoexp != "off" ]]; then log_fail "zpool $TESTPOOL1 autoexpand should off but is $autoexp" fi typeset prev_size=$(get_pool_prop size $TESTPOOL1) for i in 1 2 3; do log_must $ZFS set volsize=$exp_size $VFS/vol$i done $SYNC $SLEEP 10 $SYNC # check for zpool history for the pool size expansion $ZPOOL history -il $TESTPOOL1 | \ $GREP "pool '$TESTPOOL1' size:" | \ $GREP "internal vdev online" >/dev/null 2>&1 if [[ $? -eq 0 ]]; then log_fail "pool $TESTPOOL1" \ " is not autoexpand after LUN expansion" fi typeset expand_size=$(get_pool_prop size $TESTPOOL1) if [[ "$prev_size" != "$expand_size" ]]; then log_fail "pool $TESTPOOL1 size changed after LUN expansion" fi log_must $ZPOOL destroy $TESTPOOL1 for i in 1 2 3; do log_must $ZFS set volsize=$org_size $VFS/vol$i done done log_pass "zpool can not expand if set autoexpand=off after LUN expansion" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh (revision 292298) @@ -1,112 +1,110 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_import_013_neg.ksh 1.1 07/10/09 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################# # # __stc_assertion_start # # ID: zpool_import_013_neg # # DESCRIPTION: # For pool may be in use from other system, # 'zpool import' will prompt the warning and fails. # # STRATEGY: # 1. Prepare rawfile that are created from other system. # 2. Verify 'zpool import' will fail. # 3. Verify 'zpool import -f' succeed. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-07-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" if (( ZPOOL_VERSION < 6 )); then log_unsupported "This case need zpool version >= 6" fi function create_old_pool { VERSION=$1 POOL_FILES=$($ENV | grep "ZPOOL_VERSION_${VERSION}_FILES"\ | $AWK -F= '{print $2}') POOL_NAME=$($ENV|grep "ZPOOL_VERSION_${VERSION}_NAME"\ | $AWK -F= '{print $2}') log_note "Creating $POOL_NAME from $POOL_FILES" for pool_file in $POOL_FILES; do $CP $STF_SUITE/tests/cli_root/zpool_upgrade/blockfiles/$pool_file.Z \ /$TESTPOOL $UNCOMPRESS /$TESTPOOL/$pool_file.Z done return 0 } function cleanup { if [[ -z $POOL_NAME ]]; then return 1 fi - if poolexists $POOL_NAME; then - log_must $ZPOOL destroy $POOL_NAME - fi + destroy_pool $POOL_NAME for file in $POOL_FILES; do if [[ -e /$TESTPOOL/$file ]]; then $RM /$TESTPOOL/$file fi done return 0 } log_assert "'zpool import' fail while pool may be in use from other system," \ "it need import forcefully." log_onexit cleanup typeset POOL_FILES typeset POOL_NAME # $CONFIGS gets set in the .cfg script for config in $CONFIGS do create_old_pool $config log_mustnot $ZPOOL import -d /$TESTPOOL $POOL_NAME log_must $ZPOOL import -d /$TESTPOOL -f $POOL_NAME destroy_upgraded_pool done log_pass "'zpool import' fail while pool may be in use from other system," \ "import forcefully succeed as expected." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh (revision 292298) @@ -1,79 +1,77 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_remove_002_pos.ksh 1.1 07/07/31 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_remove_002_pos # # DESCRIPTION: # Verify that 'zpool can only remove inactive hot spare devices from pool' # # STRATEGY: # 1. Create a hotspare pool # 2. Try to remove the inactive hotspare device from the pool # 3. Verify that the remove succeed. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-06-18) # # __stc_assertion_end # ################################################################################ function cleanup { - if poolexists $TESTPOOL; then - destroy_pool $TESTPOOL - fi + destroy_pool $TESTPOOL } log_onexit cleanup typeset disk=${DISK} typeset spare_devs1="${disk}p1" typeset spare_devs2="${disk}p2" log_assert "zpool remove can only remove inactive hotspare device from pool" log_note "check hotspare device which is created by zpool create" log_must $ZPOOL create $TESTPOOL $spare_devs1 spare $spare_devs2 log_must $ZPOOL remove $TESTPOOL $spare_devs2 log_note "check hotspare device which is created by zpool add" log_must $ZPOOL add $TESTPOOL spare $spare_devs2 log_must $ZPOOL remove $TESTPOOL $spare_devs2 log_must $ZPOOL destroy $TESTPOOL log_pass "zpool remove can only remove inactive hotspare device from pool" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh (revision 292298) @@ -1,142 +1,141 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_set_002_neg.ksh 1.3 09/01/12 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_set_002_neg # # DESCRIPTION: # # Malformed zpool set commands are rejected # # STRATEGY: # 1. Create an array of many different malformed zfs set arguments # 2. Run zpool set for each arg checking each will exit with status code 1 # # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-03-05) # # __stc_assertion_end # ################################################################################ verify_runnable "global" # note to self - need to make sure there isn't a pool called bootfs # before running this test... function cleanup { - - $ZPOOL destroy bootfs + destroy_pool bootfs $RM $TMPDIR/zpool_set_002.${TESTCASE_ID}.dat } $ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null if [ $? -ne 0 ] then log_unsupported "Pool properties not supported on this release." fi log_assert "Malformed zpool set commands are rejected" if poolexists bootfs then log_unsupported "Unable to run test on a machine with a pool called \ bootfs" fi log_onexit cleanup # build up an array of bad arguments. set -A arguments "rubbish " \ "foo@bar= " \ "@@@= +pool " \ "zpool bootfs " \ "bootfs " \ "bootfs +" \ "bootfs=bootfs/123 " \ "bootfs=bootfs@val " \ "Bootfs=bootfs " \ "- " \ "== " \ "set " \ "@@ " \ "12345 " \ "€にほんご " \ "/ " \ "bootfs=bootfs /" \ "bootfs=a%d%s " # here, we build up a large string. # a word to the ksh-wary, ${#array[@]} gives you the # total number of entries in an array, so array[${#array[@]}] # will index the last entry+1, ksh arrays start at index 0. COUNT=0 while [ $COUNT -le 1025 ] do bigname="${bigname}o" COUNT=$(( $COUNT + 1 )) done # add an argument of maximum length property name arguments[${#arguments[@]}]="$bigname=value" # add an argument of maximum length property value arguments[${#arguments[@]}]="bootfs=$bigname" # Create a pool called bootfs (so-called, so as to trip any clashes between # property name, and pool name) # Also create a filesystem in this pool log_must $MKFILE 64m $TMPDIR/zpool_set_002.${TESTCASE_ID}.dat log_must $ZPOOL create bootfs $TMPDIR/zpool_set_002.${TESTCASE_ID}.dat log_must $ZFS create bootfs/root typeset -i i=0; while [ $i -lt "${#arguments[@]}" ] do log_mustnot eval "$ZPOOL set ${arguments[$i]} > /dev/null 2>&1" # now also try with a valid pool in the argument list log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs > /dev/null 2>&1" # now also try with two valid pools in the argument list log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs bootfs > /dev/null" i=$(( $i + 1)) done log_pass "Malformed zpool set commands are rejected" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh (revision 292298) @@ -1,92 +1,92 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zpool_set_003_neg.ksh 1.1 07/10/09 SMI" # . $STF_SUITE/include/libtest.kshlib ################################################################################ # # __stc_assertion_start # # ID: zpool_set_003_neg # # DESCRIPTION: # # zpool set cannot set a readonly property # # STRATEGY: # 1. Create a pool # 2. Verify that we can't set readonly properties on that pool # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2007-08-24) # # __stc_assertion_end # ################################################################################ verify_runnable "global" function cleanup { - $ZPOOL destroy $TESTPOOL + destroy_pool $TESTPOOL $RM $TMPDIR/zpool_set_003.${TESTCASE_ID}.dat } set -A props "available" "capacity" "guid" "health" "size" "used" set -A vals "100" "10" "12345" "HEALTHY" "10" "10" $ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null if [ $? -ne 0 ] then log_unsupported "Pool properties not supported on this release." fi log_onexit cleanup log_assert "zpool set cannot set a readonly property" log_must $MKFILE 64m $TMPDIR/zpool_set_003.${TESTCASE_ID}.dat log_must $ZPOOL create $TESTPOOL $TMPDIR/zpool_set_003.${TESTCASE_ID}.dat typeset -i i=0; while [ $i -lt "${#props[@]}" ] do # try to set each property in the prop list with it's corresponding val log_mustnot eval "$ZPOOL set ${props[$i]}=${vals[$i]} $TESTPOOL \ > /dev/null 2>&1" i=$(( $i + 1)) done log_pass "zpool set cannot set a readonly property" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh (revision 292298) @@ -1,47 +1,40 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cleanup.ksh 1.2 08/02/27 SMI" # . $STF_SUITE/include/libtest.kshlib -if poolexists $TESTPOOL.virt -then - log_must $ZPOOL destroy $TESTPOOL.virt -fi - -if poolexists v1-pool -then - log_must $ZPOOL destroy v1-pool -fi +destroy_pool $TESTPOOL.virt +destroy_pool v1-pool if [[ -f $TMPDIR/zfstest_datastream.dat ]] then log_must $RM -f $TMPDIR/zfstest_datastream.dat fi default_cleanup Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh (revision 292298) @@ -1,126 +1,124 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)pool_names_001_pos.ksh 1.2 07/01/09 SMI" # . $STF_SUITE/include/libtest.kshlib ############################################################################### # # __stc_assertion_start # # ID: pool_names_001_pos # # DESCRIPTION: # # Test that a set of valid names can be used to create pools. Further # verify that the created pools can be destroyed. # # STRATEGY: # 1) For each valid character in the character set, try to create # and destroy the pool. # 2) Given a list of valid pool names, try to create and destroy # pools with the given names. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-11-21) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Ensure that pool names can use the ASCII subset of UTF-8" function cleanup { - if [[ -n $name ]] && poolexists $name ; then - log_must $ZPOOL destroy $name - fi + [[ -n "$name" ]] && destroy_pool $name if [[ -d $TESTDIR ]]; then log_must $RM -rf $TESTDIR fi } log_onexit cleanup if [[ ! -e $TESTDIR ]]; then log_must $MKDIR $TESTDIR fi log_note "Ensure letters of the alphabet are allowable" typeset name="" for name in A B C D E F G H I J K L M \ N O P Q R S T U V W X Y Z \ a b c d e f g h i j k l m \ n o p q r s t u v w x y z do log_must $ZPOOL create -m $TESTDIR $name $DISK if ! poolexists $name; then log_fail "Could not create a pool called '$name'" fi log_must $ZPOOL destroy $name done log_note "Ensure a variety of unusual names passes" name="" for name in "a.............................." "a_" "a-" "a:" \ "a." "a123456" "bc0t0d0" "m1rr0r_p00l" "ra1dz_p00l" \ "araidz2" "C0t2d0" "cc0t0" "raid2:-_." "mirr_:-." \ "m1rr0r-p00l" "ra1dz-p00l" "spar3_p00l" \ "spar3-p00l" "hiddenmirrorpool" "hiddenraidzpool" \ "hiddensparepool" do log_must $ZPOOL create -m $TESTDIR $name $DISK if ! poolexists $name; then log_fail "Could not create a pool called '$name'" fi # # Since the naming convention applies to datasets too, # create datasets with the same names as above. # log_must $ZFS create $name/$name log_must $ZFS snapshot $name/$name@$name log_must $ZFS clone $name/$name@$name $name/clone_$name log_must $ZFS create -V 150m $name/$name/$name log_must $ZPOOL destroy $name done log_pass "Valid pool names were accepted correctly." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh (revision 292298) @@ -1,157 +1,155 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)pool_names_002_neg.ksh 1.4 08/11/03 SMI" # . $STF_SUITE/include/libtest.kshlib ############################################################################### # # __stc_assertion_start # # ID: pool_names_002_neg # # DESCRIPTION: # # Ensure that a set of invalid names cannot be used to create pools. # # STRATEGY: # 1) For each invalid character in the character set, try to create # and destroy the pool. Verify it fails. # 2) Given a list of invalid pool names, ensure the pools are not # created. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-11-21) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Ensure that a set of invalid names cannot be used to create pools." # Global variable use to cleanup failures. POOLNAME="" function cleanup { - if poolexists $POOLNAME; then - log_must $ZPOOL destroy $POOLNAME - fi + destroy_pool $POOLNAME if [[ -d $TESTDIR ]]; then log_must $RM -rf $TESTDIR fi } log_onexit cleanup typeset exclude=`eval $ECHO \"'(${KEEP})'\"` for pool in $($ZPOOL list -H -o name | \ $EGREP -v "$exclude" | \ $GREP -v "$TESTPOOL" | \ $EGREP -v "$NO_POOLS"); do log_must $ZPOOL destroy $pool done if [[ ! -e $TESTDIR ]]; then log_must $MKDIR $TESTDIR fi log_note "Ensure invalid characters fail" for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \ "\*" "+" "," "-" "\." "/" "\\" \ ":" ";" "<" "=" ">" "\?" "@" \ "[" "]" "^" "_" "\`" "{" "|" "}" "~" do log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK if poolexists $POOLNAME; then log_fail "Unexpectedly created pool: '$POOLNAME'" fi log_mustnot $ZPOOL destroy $POOLNAME done # poolexists cannot be used to test pools with numeric names, because # "zpool list" will interpret the name as a repeat interval and never return. log_note "Ensure invalid characters fail" for POOLNAME in 0 1 2 3 4 5 6 7 8 9 2222222222222222222 do log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK log_mustnot $ZPOOL destroy $POOLNAME done log_note "Check that invalid octal values fail" for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \ "\010" "\011" "\012" "\013" "\014" "\015" "\017" \ "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \ "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \ "\040" "\177" do # Be careful not to print the poolname, because it might be a terminal # control character POOLNAME=`eval "print x | tr 'x' '$oct'"` $ZPOOL create -m $TESTDIR $POOLNAME $DISK > /dev/null 2>&1 if [ $? = 0 ]; then log_fail "Unexpectedly created pool: \"$oct\"" elif poolexists $POOLNAME; then log_fail "Unexpectedly created pool: \"$oct\"" fi $ZPOOL destroy $POOLNAME > /dev/null 2>&1 if [ $? = 0 ]; then log_fail "Unexpectedly destroyed pool: \"$oct\"" fi done log_note "Verify invalid pool names fail" set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \ "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \ "mirror_pool" "raidz_pool" \ "mirror-pool" "raidz-pool" "spare" "spare_pool" \ "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd" if verify_slog_support ; then POOLNAME[${#POOLNAME[@]}]='log' fi typeset -i i=0 while ((i < ${#POOLNAME[@]})); do log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK if poolexists ${POOLNAME[$i]}; then log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'" fi log_mustnot $ZPOOL destroy ${POOLNAME[$i]} ((i += 1)) done log_pass "Invalid names and characters were caught correctly" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh (revision 292298) @@ -1,43 +1,43 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cleanup.ksh 1.1 07/10/09 SMI" # . ${STF_SUITE}/include/libtest.kshlib verify_runnable "global" $ZPOOL set 2>&1 | $GREP version > /dev/null if [ $? -eq 1 ] then log_unsupported "zpool version property not supported on this system." fi -log_must $ZPOOL destroy $TESTPOOL -log_must $ZPOOL destroy $TESTPOOL2 +destroy_pool $TESTPOOL +destroy_pool $TESTPOOL2 default_cleanup Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh (revision 292298) @@ -1,101 +1,97 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)userquota_002_pos.ksh 1.1 09/06/22 SMI" # ################################################################################ # # __stc_assertion_start # # ID: userquota_002_pos # # DESCRIPTION: # the userquota and groupquota can be set during zpool or zfs creation" # # # STRATEGY: # 1. Set userquota and groupquota via "zpool -O or zfs create -o" # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING STATUS: COMPLETED (2009-04-16) # # __stc_assertion_end # ############################################################################### . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/userquota/userquota_common.kshlib verify_runnable "global" function cleanup { - if poolexists $TESTPOOL1; then - log_must $ZPOOL destroy $TESTPOOL1 - fi + destroy_pool $TESTPOOL1 if [[ -f $pool_vdev ]]; then $RM -f $pool_vdev fi } log_onexit cleanup log_assert \ "the userquota and groupquota can be set during zpool,zfs creation" typeset pool_vdev=$TMPDIR/pool_dev.${TESTCASE_ID} log_must $MKFILE 500m $pool_vdev -if poolexists $TESTPOOL1; then - $ZPOOL destroy $TESTPOOL1 -fi +destroy_pool $TESTPOOL1 log_must $ZPOOL create -O userquota@$QUSER1=$UQUOTA_SIZE \ -O groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1 $pool_vdev log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL1 > /dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL1 "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL1 "$GQUOTA_SIZE" log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \ -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1/fs log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL1 > /dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL1/fs "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL1/fs "$GQUOTA_SIZE" log_pass \ "the userquota and groupquota can be set during zpool,zfs creation" Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh (revision 292298) @@ -1,35 +1,35 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" # . $STF_SUITE/include/libtest.kshlib -log_must $ZPOOL destroy $TESTPOOL +destroy_pool $TESTPOOL log_must wipe_partition_table $DISKS log_must $RM -rf $TESTDIR log_pass Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh (revision 292297) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh (revision 292298) @@ -1,158 +1,157 @@ #! /usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zvol_misc_008_pos.ksh 1.3 08/05/14 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/zvol/zvol_common.kshlib ############################################################################### # # __stc_assertion_start # # ID: zvol_misc_008_pos # # DESCRIPTION: # Verify that device nodes are modified appropriately during zfs command # operations on volumes. # # STRATEGY: # For a certain number of iterations, with root setup for each test set: # - Recursively snapshot the root. # - Clone the volume to another name in the root. # - Promote the clone. # - Demote the original clone. # - Snapshot & clone the clone. # - Rename the root. # - Destroy the renamed root. # # At each stage, the device nodes are checked to match the expectations. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2008-03-04) # # __stc_assertion_end # ################################################################################ verify_runnable "global" log_assert "Verify that ZFS volume device nodes are handled properly (part 2)." ROOTPREFIX=$TESTPOOL/008 DIRS="dir0 dir1" VOLS="vol0 dir0/dvol0 dir1/dvol1" typeset -i NUM_ITERATIONS=10 function onexit_callback { log_must $ZFS list -t all log_note "Char devices in /dev/zvol:" find /dev/zvol -type c } log_onexit onexit_callback function root_setup { rootds=$1 log_must $ZFS create $rootds for dir in $DIRS; do log_must $ZFS create $rootds/$dir done for vol in $VOLS; do log_must $ZFS create -V 100M $rootds/$vol log_must test -c /dev/zvol/$rootds/$vol done } +function test_exists +{ + for zvolds in $*; do + log_must test -c /dev/zvol/${zvolds} + done +} + +function test_notexists +{ + for zvolds in $*; do + log_mustnot test -e /dev/zvol/${zvolds} + done +} + typeset -i i=0 while (( i != NUM_ITERATIONS )); do root=${ROOTPREFIX}_iter${i} # Test set 2: Recursive snapshot, cloning/promoting, and root-rename root_setup $root log_must $ZFS snapshot -r $root@snap log_must $ZFS clone $root/vol0@snap $root/vol1 - log_must test -c /dev/zvol/$root/vol1 - log_mustnot test -e /dev/zvol/$root/vol1@snap + test_exists $root/vol1 + test_notexists $root/vol1@snap log_must $ZFS promote $root/vol1 - log_must test -c /dev/zvol/$root/vol1 - log_must test -c /dev/zvol/$root/vol0 - log_mustnot test -e /dev/zvol/$root/vol0@snap - log_must test -c /dev/zvol/$root/vol1@snap + test_exists $root/vol0 $root/vol1 $root/vol1@snap + test_notexists $root/vol0@snap # Re-promote the original volume. log_must $ZFS promote $root/vol0 - log_must test -c /dev/zvol/$root/vol0 - log_must test -c /dev/zvol/$root/vol1 - log_must test -c /dev/zvol/$root/vol0@snap - log_mustnot test -e /dev/zvol/$root/vol1@snap + test_exists $root/vol0 $root/vol1 $root/vol0@snap + test_notexists $root/vol1@snap # Clone a clone's snapshot. log_must $ZFS snapshot $root/vol1@newsnap log_must $ZFS clone $root/vol1@newsnap $root/vol2 - log_must test -c /dev/zvol/$root/vol2 - log_mustnot test -e /dev/zvol/$root/vol2@snap + test_exists $root/vol2 + test_notexists $root/vol2@snap # Now promote *that* clone. log_must $ZFS promote $root/vol2 - log_must test -c /dev/zvol/$root/vol0 - log_must test -c /dev/zvol/$root/vol0@snap - log_must test -c /dev/zvol/$root/vol1 - log_mustnot test -e /dev/zvol/$root/vol1@snap - log_mustnot test -e /dev/zvol/$root/vol1@newsnap - log_must test -c /dev/zvol/$root/vol2 - log_must test -c /dev/zvol/$root/vol2@newsnap + test_exists $root/vol0 $root/vol0@snap \ + $root/vol1 $root/vol2 $root/vol2@newsnap + test_notexists $root/vol1@snap $root/vol1@newsnap renamed=${root}_renamed log_must $ZFS rename $root $renamed # Ensure that the root rename applies to clones and promoted clones. - log_mustnot test -e /dev/zvol/$root/vol1 - log_must test -c /dev/zvol/$renamed/vol1 - log_mustnot test -e /dev/zvol/$renamed/vol1@snap - log_mustnot test -e /dev/zvol/$renamed/vol1@newsnap - log_must test -c /dev/zvol/$renamed/vol2 - log_must test -c /dev/zvol/$renamed/vol2@newsnap + test_exists $renamed/vol1 $renamed/vol2 $renamed/vol2@newsnap + test_notexists $root/vol1 $renamed/vol1@snap $renamed/vol1@newsnap for vol in $VOLS; do - log_mustnot test -e /dev/zvol/$root/$vol - log_mustnot test -e /dev/zvol/$root/$vol@snap - log_must test -c /dev/zvol/$renamed/$vol - log_must test -c /dev/zvol/$renamed/$vol@snap + test_notexists $root/$vol $root/$vol@snap + test_exists $renamed/$vol $renamed/$vol@snap done + log_must $ZFS destroy -r $renamed - log_mustnot test -e /dev/zvol/$renamed/vol0 - log_mustnot test -e /dev/zvol/$renamed/vol1 - log_mustnot test -e /dev/zvol/$renamed/vol2 + test_notexists $renamed/vol0 $renamed/vol1 $renamed/vol2 (( i += 1 )) done log_pass "ZFS volume device nodes are handled properly (part 2)."