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, 2016 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 edited_prop 48{ 49 typeset behaviour=$1 50 typeset ds=$2 51 typeset backfile=$TESTDIR/edited_prop_$ds 52 53 case $behaviour in 54 "get") 55 typeset props=$(zfs inherit 2>&1 | \ 56 awk '$2=="YES" {print $1}' | \ 57 egrep -v "^vol|\.\.\.$") 58 for item in $props ; do 59 if [[ $item == "mlslabel" ]] && \ 60 ! is_te_enabled ; then 61 continue 62 fi 63 zfs get -H -o property,value $item $ds >> \ 64 $backfile 65 if (($? != 0)); then 66 log_fail "zfs get -H -o property,value"\ 67 "$item $ds > $backfile" 68 fi 69 done 70 ;; 71 "set") 72 if [[ ! -f $backfile ]] ; then 73 log_fail "$ds need backup properties firstly." 74 fi 75 76 typeset prop value 77 while read prop value ; do 78 eval zfs set $prop='$value' $ds 79 if (($? != 0)); then 80 log_fail "zfs set $prop=$value $ds" 81 fi 82 done < $backfile 83 ;; 84 *) 85 log_fail "Unrecognized behaviour: $behaviour" 86 esac 87} 88 89function cleanup 90{ 91 log_must cleanup_pool $POOL 92 log_must cleanup_pool $POOL2 93 94 log_must edited_prop "set" $POOL 95 log_must edited_prop "set" $POOL2 96 97 typeset prop 98 for prop in $(fs_inherit_prop) ; do 99 log_must zfs inherit $prop $POOL 100 log_must zfs inherit $prop $POOL2 101 done 102 103 #if is_shared $POOL; then 104 # log_must zfs set sharenfs=off $POOL 105 #fi 106 log_must setup_test_model $POOL 107 108 if [[ -d $TESTDIR ]]; then 109 log_must rm -rf $TESTDIR/* 110 fi 111} 112 113log_assert "Verify zfs send -R will backup all the filesystem properties " \ 114 "correctly." 115log_onexit cleanup 116 117log_must edited_prop "get" $POOL 118log_must edited_prop "get" $POOL2 119 120for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \ 121 "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do 122 rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough" 123 rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" 124 rand_set_prop $fs aclmode "discard" "groupmask" "passthrough" 125 rand_set_prop $fs atime "on" "off" 126 rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" 127 rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \ 128 "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ 129 "gzip-7" "gzip-8" "gzip-9" 130 rand_set_prop $fs copies "1" "2" "3" 131 rand_set_prop $fs devices "on" "off" 132 rand_set_prop $fs exec "on" "off" 133 rand_set_prop $fs quota "512M" "1024M" 134 rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K" 135 rand_set_prop $fs dnodesize "legacy" "auto" "1k" "2k" "4k" "8k" "16k" 136 rand_set_prop $fs setuid "on" "off" 137 rand_set_prop $fs snapdir "hidden" "visible" 138 rand_set_prop $fs xattr "on" "off" 139 rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?" 140done 141 142for vol in "$POOL/vol" "$POOL/$FS/vol" ; do 143 rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256" 144 rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \ 145 "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ 146 "gzip-7" "gzip-8" "gzip-9" 147 rand_set_prop $vol readonly "on" "off" 148 rand_set_prop $vol copies "1" "2" "3" 149 rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?" 150done 151 152 153# Verify inherited property can be received 154rand_set_prop $POOL sharenfs "on" "off" "rw" 155 156# 157# Duplicate POOL2 for testing 158# 159log_must eval "zfs send -R $POOL@final > $BACKDIR/pool-final-R" 160log_must eval "zfs receive -d -F $POOL2 < $BACKDIR/pool-final-R" 161 162# 163# Define all the POOL/POOL2 datasets pair 164# 165set -A pair "$POOL" "$POOL2" \ 166 "$POOL/$FS" "$POOL2/$FS" \ 167 "$POOL/$FS/fs1" "$POOL2/$FS/fs1" \ 168 "$POOL/$FS/fs1/fs2" "$POOL2/$FS/fs1/fs2" \ 169 "$POOL/pclone" "$POOL2/pclone" \ 170 "$POOL/$FS/fs1/fclone" "$POOL2/$FS/fs1/fclone" \ 171 "$POOL/vol" "$POOL2/vol" \ 172 "$POOL/$FS/vol" "$POOL2/$FS/vol" 173 174typeset -i i=0 175while ((i < ${#pair[@]})); do 176 log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]} 177 178 ((i += 2)) 179done 180 181 182zpool upgrade -v | grep "Snapshot properties" > /dev/null 2>&1 183if (( $? == 0 )) ; then 184 i=0 185 while ((i < ${#pair[@]})); do 186 log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final 187 ((i += 2)) 188 done 189fi 190 191log_pass "Verify zfs send -R will backup all the filesystem properties " \ 192 "correctly." 193