1*f38cb554SJohn Wren Kennedy#!/usr/bin/ksh -p 2*f38cb554SJohn Wren Kennedy# 3*f38cb554SJohn Wren Kennedy# CDDL HEADER START 4*f38cb554SJohn Wren Kennedy# 5*f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 6*f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 7*f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 8*f38cb554SJohn Wren Kennedy# 9*f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 11*f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 12*f38cb554SJohn Wren Kennedy# and limitations under the License. 13*f38cb554SJohn Wren Kennedy# 14*f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 15*f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 17*f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 18*f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 19*f38cb554SJohn Wren Kennedy# 20*f38cb554SJohn Wren Kennedy# CDDL HEADER END 21*f38cb554SJohn Wren Kennedy# 22*f38cb554SJohn Wren Kennedy 23*f38cb554SJohn Wren Kennedy# 24*f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25*f38cb554SJohn Wren Kennedy# Use is subject to license terms. 26*f38cb554SJohn Wren Kennedy# 27*f38cb554SJohn Wren Kennedy 28*f38cb554SJohn Wren Kennedy# 29*f38cb554SJohn Wren Kennedy# Copyright (c) 2013 by Delphix. All rights reserved. 30*f38cb554SJohn Wren Kennedy# 31*f38cb554SJohn Wren Kennedy 32*f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg 33*f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 34*f38cb554SJohn Wren Kennedy 35*f38cb554SJohn Wren Kennedy# This setup script is moderately complex, as it creates scenarios for all 36*f38cb554SJohn Wren Kennedy# of the tests included in this directory. Usually we'd want each test case 37*f38cb554SJohn Wren Kennedy# to setup/teardown it's own configuration, but this would be time consuming 38*f38cb554SJohn Wren Kennedy# given the nature of these tests. However, as a side-effect, one test 39*f38cb554SJohn Wren Kennedy# leaving the system in an unknown state could impact other test cases. 40*f38cb554SJohn Wren Kennedy 41*f38cb554SJohn Wren Kennedy 42*f38cb554SJohn Wren KennedyDISK=${DISKS%% *} 43*f38cb554SJohn Wren KennedyVOLSIZE=150m 44*f38cb554SJohn Wren KennedyTESTVOL=testvol 45*f38cb554SJohn Wren Kennedy 46*f38cb554SJohn Wren Kennedy# Create a default setup that includes a volume 47*f38cb554SJohn Wren Kennedydefault_setup_noexit "$DISK" "" "volume" 48*f38cb554SJohn Wren Kennedy 49*f38cb554SJohn Wren Kennedy# 50*f38cb554SJohn Wren Kennedy# The rest of this setup script creates a ZFS filesystem configuration 51*f38cb554SJohn Wren Kennedy# that is used to test the rest of the zfs subcommands in this directory. 52*f38cb554SJohn Wren Kennedy# 53*f38cb554SJohn Wren Kennedy 54*f38cb554SJohn Wren Kennedy# create a snapshot and a clone to test clone promote 55*f38cb554SJohn Wren Kennedylog_must $ZFS snapshot $TESTPOOL/$TESTFS@snap 56*f38cb554SJohn Wren Kennedylog_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone 57*f38cb554SJohn Wren Kennedy# create a file in the filesystem that isn't in the above snapshot 58*f38cb554SJohn Wren Kennedy$TOUCH /$TESTDIR/file.txt 59*f38cb554SJohn Wren Kennedy 60*f38cb554SJohn Wren Kennedy 61*f38cb554SJohn Wren Kennedy# create a non-default property and a child we can use to test inherit 62*f38cb554SJohn Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2 63*f38cb554SJohn Wren Kennedylog_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS 64*f38cb554SJohn Wren Kennedy 65*f38cb554SJohn Wren Kennedy 66*f38cb554SJohn Wren Kennedy# create an unmounted filesystem to test unmount 67*f38cb554SJohn Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted 68*f38cb554SJohn Wren Kennedylog_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted 69*f38cb554SJohn Wren Kennedy 70*f38cb554SJohn Wren Kennedy 71*f38cb554SJohn Wren Kennedy# send our snapshot to a known file in /tmp 72*f38cb554SJohn Wren Kennedy$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat 73*f38cb554SJohn Wren Kennedyif [ ! -s /tmp/zfstest_datastream.dat ] 74*f38cb554SJohn Wren Kennedythen 75*f38cb554SJohn Wren Kennedy log_fail "ZFS send datafile was not created!" 76*f38cb554SJohn Wren Kennedyfi 77*f38cb554SJohn Wren Kennedylog_must $CHMOD 644 /tmp/zfstest_datastream.dat 78*f38cb554SJohn Wren Kennedy 79*f38cb554SJohn Wren Kennedy 80*f38cb554SJohn Wren Kennedy# create a filesystem that has particular properties to test set/get 81*f38cb554SJohn Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop 82*f38cb554SJohn Wren Kennedyset -A props $PROP_NAMES 83*f38cb554SJohn Wren Kennedyset -A prop_vals $PROP_VALS 84*f38cb554SJohn Wren Kennedytypeset -i i=0 85*f38cb554SJohn Wren Kennedy 86*f38cb554SJohn Wren Kennedywhile [[ $i -lt ${#props[*]} ]] 87*f38cb554SJohn Wren Kennedydo 88*f38cb554SJohn Wren Kennedy prop_name=${props[$i]} 89*f38cb554SJohn Wren Kennedy prop_val=${prop_vals[$i]} 90*f38cb554SJohn Wren Kennedy log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop 91*f38cb554SJohn Wren Kennedy i=$(( $i + 1 )) 92*f38cb554SJohn Wren Kennedydone 93*f38cb554SJohn Wren Kennedy 94*f38cb554SJohn Wren Kennedy# create a filesystem we don't mind renaming 95*f38cb554SJohn Wren Kennedylog_must $ZFS create $TESTPOOL/$TESTFS/renameme 96*f38cb554SJohn Wren Kennedy 97*f38cb554SJohn Wren Kennedy 98*f38cb554SJohn Wren Kennedyif is_global_zone 99*f38cb554SJohn Wren Kennedythen 100*f38cb554SJohn Wren Kennedy # create a filesystem we can share 101*f38cb554SJohn Wren Kennedy log_must $ZFS create $TESTPOOL/$TESTFS/unshared 102*f38cb554SJohn Wren Kennedy log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared 103*f38cb554SJohn Wren Kennedy 104*f38cb554SJohn Wren Kennedy # create a filesystem that we can unshare 105*f38cb554SJohn Wren Kennedy log_must $ZFS create $TESTPOOL/$TESTFS/shared 106*f38cb554SJohn Wren Kennedy log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared 107*f38cb554SJohn Wren Kennedyfi 108*f38cb554SJohn Wren Kennedy 109*f38cb554SJohn Wren Kennedy 110*f38cb554SJohn Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1 111*f38cb554SJohn Wren Kennedylog_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed 112*f38cb554SJohn Wren Kennedylog_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed 113*f38cb554SJohn Wren Kennedy 114*f38cb554SJohn Wren Kennedyif is_global_zone 115*f38cb554SJohn Wren Kennedythen 116*f38cb554SJohn Wren Kennedy 117*f38cb554SJohn Wren Kennedy # Now create several virtual disks to test zpool with 118*f38cb554SJohn Wren Kennedy 119*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk1.dat 120*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk2.dat 121*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk3.dat 122*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk-additional.dat 123*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk-export.dat 124*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk-offline.dat 125*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk-spare1.dat 126*f38cb554SJohn Wren Kennedy $MKFILE 100m /$TESTDIR/disk-spare2.dat 127*f38cb554SJohn Wren Kennedy 128*f38cb554SJohn Wren Kennedy # and create a pool we can perform attach remove replace, 129*f38cb554SJohn Wren Kennedy # etc. operations with 130*f38cb554SJohn Wren Kennedy log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \ 131*f38cb554SJohn Wren Kennedy /$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \ 132*f38cb554SJohn Wren Kennedy spare /$TESTDIR/disk-spare1.dat 133*f38cb554SJohn Wren Kennedy 134*f38cb554SJohn Wren Kennedy 135*f38cb554SJohn Wren Kennedy # Offline one of the disks to test online 136*f38cb554SJohn Wren Kennedy log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat 137*f38cb554SJohn Wren Kennedy 138*f38cb554SJohn Wren Kennedy 139*f38cb554SJohn Wren Kennedy # create an exported pool to test import 140*f38cb554SJohn Wren Kennedy log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat 141*f38cb554SJohn Wren Kennedy log_must $ZPOOL export $TESTPOOL.exported 142*f38cb554SJohn Wren Kennedy 143*f38cb554SJohn Wren Kennedy set -A props $POOL_PROPS 144*f38cb554SJohn Wren Kennedy set -A prop_vals $POOL_VALS 145*f38cb554SJohn Wren Kennedy typeset -i i=0 146*f38cb554SJohn Wren Kennedy 147*f38cb554SJohn Wren Kennedy while [[ $i -lt ${#props[*]} ]] 148*f38cb554SJohn Wren Kennedy do 149*f38cb554SJohn Wren Kennedy prop_name=${props[$i]} 150*f38cb554SJohn Wren Kennedy prop_val=${prop_vals[$i]} 151*f38cb554SJohn Wren Kennedy log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL 152*f38cb554SJohn Wren Kennedy i=$(( $i + 1 )) 153*f38cb554SJohn Wren Kennedy done 154*f38cb554SJohn Wren Kennedy 155*f38cb554SJohn Wren Kennedy # copy a v1 pool from cli_root 156*f38cb554SJohn Wren Kennedy $CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \ 157*f38cb554SJohn Wren Kennedy /$TESTDIR 158*f38cb554SJohn Wren Kennedy log_must $BUNZIP2 /$TESTDIR/zfs-pool-v1.dat.bz2 159*f38cb554SJohn Wren Kennedy log_must $ZPOOL import -d /$TESTDIR v1-pool 160*f38cb554SJohn Wren Kennedyfi 161*f38cb554SJohn Wren Kennedylog_pass 162