1#! /usr/local/bin/ksh93 -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# $FreeBSD$ 24 25# 26# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)clone_001_pos.ksh 1.6 09/06/22 SMI" 30# 31. $STF_SUITE/include/libtest.kshlib 32 33################################################################################ 34# 35# __stc_assertion_start 36# 37# ID: clone_001_pos 38# 39# DESCRIPTION: 40# Create a snapshot from regular filesystem, volume, 41# or filesystem upon volume, Build a clone file system 42# from the snapshot and verify new files can be written. 43# 44# STRATEGY: 45# 1. Create snapshot use 3 combination: 46# - Regular filesystem 47# - Regular volume 48# - Filesystem upon volume 49# 2. Clone a new file system from the snapshot 50# 3. Verify the cloned file system is writable 51# 52# TESTABILITY: explicit 53# 54# TEST_AUTOMATION_LEVEL: automated 55# 56# CODING_STATUS: COMPLETED (2005-08-25) 57# 58# __stc_assertion_end 59# 60################################################################################ 61 62verify_runnable "both" 63 64# Setup array, 4 elements as a group, refer to: 65# i+0: name of a snapshot 66# i+1: mountpoint of the snapshot 67# i+2: clone created from the snapshot 68# i+3: mountpoint of the clone 69 70set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \ 71 "$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \ 72 "$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2" 73 74function setup_all 75{ 76 create_pool $TESTPOOL1 /dev/zvol/$TESTPOOL/$TESTVOL 77 log_must $ZFS create $TESTPOOL1/$TESTFS 78 log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS 79 80 return 0 81} 82 83function cleanup_all 84{ 85 destroy_pool $TESTPOOL1 86 87 [[ -d $TESTDIR2 ]] && \ 88 log_must $RM -rf $TESTDIR2 89 90 return 0 91} 92 93log_assert "Verify a cloned file system is writable." 94 95log_onexit cleanup_all 96 97setup_all 98 99[[ -n $TESTDIR ]] && \ 100 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 101 102typeset -i COUNT=10 103 104for mtpt in $TESTDIR $TESTDIR2 ; do 105 log_note "Populate the $mtpt directory (prior to snapshot)" 106 populate_dir $mtpt/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER 107done 108 109typeset -i i=0 110while (( i < ${#args[*]} )); do 111 # 112 # Take a snapshot of the test file system. 113 # 114 log_must $ZFS snapshot ${args[i]} 115 116 # 117 # Clone a new file system from the snapshot 118 # 119 log_must $ZFS clone ${args[i]} ${args[i+2]} 120 if [[ -n ${args[i+3]} ]] ; then 121 log_must $ZFS set mountpoint=${args[i+3]} ${args[i+2]} 122 123 FILE_COUNT=`$LS -Al ${args[i+3]} | $GREP -v "total" | wc -l` 124 if [[ $FILE_COUNT -ne $COUNT ]]; then 125 $LS -Al ${args[i+3]} 126 log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)." 127 fi 128 129 log_note "Verify the ${args[i+3]} directory is writable" 130 populate_dir ${args[i+3]}/after_file $COUNT $NUM_WRITES \ 131 $BLOCKSZ ITER 132 133 FILE_COUNT=`$LS -Al ${args[i+3]}/after* | $GREP -v "total" | wc -l` 134 if [[ $FILE_COUNT -ne $COUNT ]]; then 135 $LS -Al ${args[i+3]} 136 log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)." 137 fi 138 fi 139 140 (( i = i + 4 )) 141done 142 143log_pass "The clone file system is writable." 144