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