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