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 "@(#)rsend_012_pos.ksh 1.2 09/05/19 SMI" 30# 31 32. $STF_SUITE/tests/rsend/rsend.kshlib 33 34################################################################################# 35# 36# __stc_assertion_start 37# 38# ID: rsend_012_pos 39# 40# DESCRIPTION: 41# zfs send -R will backup all the filesystem properties correctly. 42# 43# STRATEGY: 44# 1. Setting properties for all the filesystem and volumes randomly 45# 2. Backup all the data from POOL by send -R 46# 3. Restore all the data in POOL2 47# 4. Verify all the perperties in two pools are same 48# 49# TESTABILITY: explicit 50# 51# TEST_AUTOMATION_LEVEL: automated 52# 53# CODING_STATUS: COMPLETED (2007-08-27) 54# 55# __stc_assertion_end 56# 57################################################################################ 58 59verify_runnable "global" 60 61function rand_set_prop 62{ 63 typeset dtst=$1 64 typeset prop=$2 65 shift 2 66 typeset value=$(random_get $@) 67 68 log_must eval "$ZFS set $prop='$value' $dtst" 69} 70 71function edited_prop 72{ 73 typeset behaviour=$1 74 typeset ds=$2 75 typeset backfile=$TESTDIR/edited_prop_$ds 76 77 case $behaviour in 78 "get") 79 typeset props=$($ZFS inherit 2>&1 | \ 80 $AWK '$2=="YES" {print $1}' | \ 81 $EGREP -v "^vol|\.\.\.$") 82 for item in $props ; do 83 $ZFS get -H -o property,value $item $ds >> \ 84 $backfile 85 if (($? != 0)); then 86 log_fail "zfs get -H -o property,value"\ 87 "$item $ds > $backfile" 88 fi 89 done 90 ;; 91 "set") 92 if [[ ! -f $backfile ]] ; then 93 log_fail "$ds need backup properties firstly." 94 fi 95 96 typeset prop value 97 while read prop value ; do 98 eval $ZFS set $prop='$value' $ds 99 if (($? != 0)); then 100 log_fail "$ZFS set $prop=$value $ds" 101 fi 102 done < $backfile 103 ;; 104 *) 105 log_fail "Unrecognized behaviour: $behaviour" 106 esac 107} 108 109function cleanup 110{ 111 log_must cleanup_pool $POOL 112 log_must cleanup_pool $POOL2 113 114 log_must edited_prop "set" $POOL 115 log_must edited_prop "set" $POOL2 116 117 typeset prop 118 for prop in $(fs_inherit_prop) ; do 119 log_must $ZFS inherit $prop $POOL 120 log_must $ZFS inherit $prop $POOL2 121 done 122 123 #if is_shared $POOL; then 124 # log_must $ZFS set sharenfs=off $POOL 125 #fi 126 log_must setup_test_model $POOL 127 128 if [[ -d $TESTDIR ]]; then 129 log_must $RM -rf $TESTDIR/* 130 fi 131} 132 133log_assert "Verify zfs send -R will backup all the filesystem properties " \ 134 "correctly." 135log_onexit cleanup 136 137log_must edited_prop "get" $POOL 138log_must edited_prop "get" $POOL2 139 140for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \ 141 "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do 142 rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough" 143 rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" 144 rand_set_prop $fs aclmode "discard" "groupmask" "passthrough" 145 rand_set_prop $fs atime "on" "off" 146 rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" 147 rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \ 148 "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ 149 "gzip-7" "gzip-8" "gzip-9" 150 rand_set_prop $fs copies "1" "2" "3" 151 rand_set_prop $fs devices "on" "off" 152 rand_set_prop $fs exec "on" "off" 153 rand_set_prop $fs quota "512M" "1024M" 154 rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K" 155 rand_set_prop $fs setuid "on" "off" 156 rand_set_prop $fs snapdir "hidden" "visible" 157 rand_set_prop $fs xattr "on" "off" 158 rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?" 159done 160 161for vol in "$POOL/vol" "$POOL/$FS/vol" ; do 162 rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256" 163 rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \ 164 "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ 165 "gzip-7" "gzip-8" "gzip-9" 166 rand_set_prop $vol readonly "on" "off" 167 rand_set_prop $vol copies "1" "2" "3" 168 rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?" 169done 170 171 172# Verify inherited property can be received 173rand_set_prop $POOL sharenfs "on" "off" "rw" 174 175# 176# Duplicate POOL2 for testing 177# 178log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" 179log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" 180 181# 182# Define all the POOL/POOL2 datasets pair 183# 184set -A pair "$POOL" "$POOL2" \ 185 "$POOL/$FS" "$POOL2/$FS" \ 186 "$POOL/$FS/fs1" "$POOL2/$FS/fs1" \ 187 "$POOL/$FS/fs1/fs2" "$POOL2/$FS/fs1/fs2" \ 188 "$POOL/pclone" "$POOL2/pclone" \ 189 "$POOL/$FS/fs1/fclone" "$POOL2/$FS/fs1/fclone" \ 190 "$POOL/vol" "$POOL2/vol" \ 191 "$POOL/$FS/vol" "$POOL2/$FS/vol" 192 193typeset -i i=0 194while ((i < ${#pair[@]})); do 195 log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]} 196 197 ((i += 2)) 198done 199 200 201$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1 202if (( $? == 0 )) ; then 203 i=0 204 while ((i < ${#pair[@]})); do 205 log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final 206 ((i += 2)) 207 done 208fi 209 210log_pass "Verify zfs send -R will backup all the filesystem properties " \ 211 "correctly." 212