1f38cb554SJohn Wren Kennedy# 2f38cb554SJohn Wren Kennedy# CDDL HEADER START 3f38cb554SJohn Wren Kennedy# 4f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 5f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 6f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 7f38cb554SJohn Wren Kennedy# 8f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 10f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 11f38cb554SJohn Wren Kennedy# and limitations under the License. 12f38cb554SJohn Wren Kennedy# 13f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 14f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 16f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 17f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 18f38cb554SJohn Wren Kennedy# 19f38cb554SJohn Wren Kennedy# CDDL HEADER END 20f38cb554SJohn Wren Kennedy# 21f38cb554SJohn Wren Kennedy 22f38cb554SJohn Wren Kennedy# 23f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24f38cb554SJohn Wren Kennedy# Use is subject to license terms. 25f38cb554SJohn Wren Kennedy# 26f38cb554SJohn Wren Kennedy 27f38cb554SJohn Wren Kennedy# 28*9c3fd121SMatthew Ahrens# Copyright (c) 2013, 2015 by Delphix. All rights reserved. 29f38cb554SJohn Wren Kennedy# 30f38cb554SJohn Wren Kennedy 31f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 32f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/rsend/rsend.cfg 33f38cb554SJohn Wren Kennedy 34f38cb554SJohn Wren Kennedy# 35f38cb554SJohn Wren Kennedy# Set up test model which includes various datasets 36f38cb554SJohn Wren Kennedy# 37f38cb554SJohn Wren Kennedy# @final 38f38cb554SJohn Wren Kennedy# @snapB 39f38cb554SJohn Wren Kennedy# @init 40f38cb554SJohn Wren Kennedy# | 41f38cb554SJohn Wren Kennedy# ______ pclone 42f38cb554SJohn Wren Kennedy# | / 43f38cb554SJohn Wren Kennedy# |@psnap 44f38cb554SJohn Wren Kennedy# || @final 45f38cb554SJohn Wren Kennedy# ||@final @final @snapC 46f38cb554SJohn Wren Kennedy# ||@snapC @snapC @snapB 47f38cb554SJohn Wren Kennedy# ||@snapA @snapB @snapA 48f38cb554SJohn Wren Kennedy# ||@init @init @init 49f38cb554SJohn Wren Kennedy# ||| | | 50f38cb554SJohn Wren Kennedy# $pool -------- $FS ------- fs1 ------- fs2 51f38cb554SJohn Wren Kennedy# \ \\_____ \ | 52f38cb554SJohn Wren Kennedy# vol vol \____ \ @fsnap 53f38cb554SJohn Wren Kennedy# | | \ \ \ 54f38cb554SJohn Wren Kennedy# @init @vsnap | ------------ fclone 55f38cb554SJohn Wren Kennedy# @snapA @init \ | | 56f38cb554SJohn Wren Kennedy# @final @snapB \ | @init 57f38cb554SJohn Wren Kennedy# @snapC vclone @snapA 58f38cb554SJohn Wren Kennedy# @final | @final 59f38cb554SJohn Wren Kennedy# @init 60f38cb554SJohn Wren Kennedy# @snapC 61f38cb554SJohn Wren Kennedy# @final 62f38cb554SJohn Wren Kennedy# 63f38cb554SJohn Wren Kennedy# $1 pool name 64f38cb554SJohn Wren Kennedy# 65f38cb554SJohn Wren Kennedyfunction setup_test_model 66f38cb554SJohn Wren Kennedy{ 67f38cb554SJohn Wren Kennedy typeset pool=$1 68f38cb554SJohn Wren Kennedy 69f38cb554SJohn Wren Kennedy log_must $ZFS create -p $pool/$FS/fs1/fs2 70f38cb554SJohn Wren Kennedy 71f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool@psnap 72f38cb554SJohn Wren Kennedy log_must $ZFS clone $pool@psnap $pool/pclone 73f38cb554SJohn Wren Kennedy 74f38cb554SJohn Wren Kennedy if is_global_zone ; then 75f38cb554SJohn Wren Kennedy log_must $ZFS create -V 16M $pool/vol 76f38cb554SJohn Wren Kennedy log_must $ZFS create -V 16M $pool/$FS/vol 77f38cb554SJohn Wren Kennedy 78f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool/$FS/vol@vsnap 79f38cb554SJohn Wren Kennedy log_must $ZFS clone $pool/$FS/vol@vsnap $pool/$FS/vclone 80f38cb554SJohn Wren Kennedy fi 81f38cb554SJohn Wren Kennedy 82f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS/fs1/fs2@fsnap 83f38cb554SJohn Wren Kennedy log_must $ZFS clone $pool/$FS/fs1/fs2@fsnap $pool/$FS/fs1/fclone 84f38cb554SJohn Wren Kennedy log_must $ZFS snapshot -r $pool@init 85f38cb554SJohn Wren Kennedy 86f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool@snapA 87f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool@snapC 88f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/pclone@snapB 89f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS@snapB 90f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS@snapC 91f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS/fs1@snapA 92f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS/fs1@snapB 93f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS/fs1@snapC 94f38cb554SJohn Wren Kennedy log_must snapshot_tree $pool/$FS/fs1/fclone@snapA 95f38cb554SJohn Wren Kennedy 96f38cb554SJohn Wren Kennedy if is_global_zone ; then 97f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool/vol@snapA 98f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool/$FS/vol@snapB 99f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool/$FS/vol@snapC 100f38cb554SJohn Wren Kennedy log_must $ZFS snapshot $pool/$FS/vclone@snapC 101f38cb554SJohn Wren Kennedy fi 102f38cb554SJohn Wren Kennedy 103f38cb554SJohn Wren Kennedy log_must $ZFS snapshot -r $pool@final 104f38cb554SJohn Wren Kennedy 105f38cb554SJohn Wren Kennedy return 0 106f38cb554SJohn Wren Kennedy} 107f38cb554SJohn Wren Kennedy 108f38cb554SJohn Wren Kennedy# 109f38cb554SJohn Wren Kennedy# Cleanup the BACKDIR and given pool content and all the sub datasets 110f38cb554SJohn Wren Kennedy# 111f38cb554SJohn Wren Kennedy# $1 pool name 112f38cb554SJohn Wren Kennedy# 113f38cb554SJohn Wren Kennedyfunction cleanup_pool 114f38cb554SJohn Wren Kennedy{ 115f38cb554SJohn Wren Kennedy typeset pool=$1 116f38cb554SJohn Wren Kennedy log_must $RM -rf $BACKDIR/* 117f38cb554SJohn Wren Kennedy 118f38cb554SJohn Wren Kennedy if is_global_zone ; then 119f38cb554SJohn Wren Kennedy log_must $ZFS destroy -Rf $pool 120f38cb554SJohn Wren Kennedy else 121f38cb554SJohn Wren Kennedy typeset list=$($ZFS list -H -r -t filesystem,snapshot,volume -o name $pool) 122f38cb554SJohn Wren Kennedy for ds in $list ; do 123f38cb554SJohn Wren Kennedy if [[ $ds != $pool ]] ; then 124f38cb554SJohn Wren Kennedy if datasetexists $ds ; then 125f38cb554SJohn Wren Kennedy log_must $ZFS destroy -Rf $ds 126f38cb554SJohn Wren Kennedy fi 127f38cb554SJohn Wren Kennedy fi 128f38cb554SJohn Wren Kennedy done 129f38cb554SJohn Wren Kennedy fi 130f38cb554SJohn Wren Kennedy 131f38cb554SJohn Wren Kennedy typeset mntpnt=$(get_prop mountpoint $pool) 132f38cb554SJohn Wren Kennedy if ! ismounted $pool ; then 133f38cb554SJohn Wren Kennedy # Make sure mountpoint directory is empty 134f38cb554SJohn Wren Kennedy if [[ -d $mntpnt ]]; then 135f38cb554SJohn Wren Kennedy log_must $RM -rf $mntpnt/* 136f38cb554SJohn Wren Kennedy fi 137f38cb554SJohn Wren Kennedy 138f38cb554SJohn Wren Kennedy log_must $ZFS mount $pool 139f38cb554SJohn Wren Kennedy fi 140f38cb554SJohn Wren Kennedy if [[ -d $mntpnt ]]; then 141f38cb554SJohn Wren Kennedy log_must $RM -rf $mntpnt/* 142f38cb554SJohn Wren Kennedy fi 143f38cb554SJohn Wren Kennedy 144f38cb554SJohn Wren Kennedy return 0 145f38cb554SJohn Wren Kennedy} 146f38cb554SJohn Wren Kennedy 147f38cb554SJohn Wren Kennedy# 148f38cb554SJohn Wren Kennedy# Detect if the given two filesystems have same sub-datasets 149f38cb554SJohn Wren Kennedy# 150f38cb554SJohn Wren Kennedy# $1 source filesystem 151f38cb554SJohn Wren Kennedy# $2 destination filesystem 152f38cb554SJohn Wren Kennedy# 153f38cb554SJohn Wren Kennedyfunction cmp_ds_subs 154f38cb554SJohn Wren Kennedy{ 155f38cb554SJohn Wren Kennedy typeset src_fs=$1 156f38cb554SJohn Wren Kennedy typeset dst_fs=$2 157f38cb554SJohn Wren Kennedy 158f38cb554SJohn Wren Kennedy $ZFS list -r -H -t filesystem,snapshot,volume -o name $src_fs > $BACKDIR/src1 159f38cb554SJohn Wren Kennedy $ZFS list -r -H -t filesystem,snapshot,volume -o name $dst_fs > $BACKDIR/dst1 160f38cb554SJohn Wren Kennedy 161f38cb554SJohn Wren Kennedy eval $SED -e 's:^$src_fs:PREFIX:g' < $BACKDIR/src1 > $BACKDIR/src 162f38cb554SJohn Wren Kennedy eval $SED -e 's:^$dst_fs:PREFIX:g' < $BACKDIR/dst1 > $BACKDIR/dst 163f38cb554SJohn Wren Kennedy 164f38cb554SJohn Wren Kennedy $DIFF $BACKDIR/src $BACKDIR/dst 165f38cb554SJohn Wren Kennedy typeset -i ret=$? 166f38cb554SJohn Wren Kennedy 167f38cb554SJohn Wren Kennedy $RM -f $BACKDIR/src $BACKDIR/dst $BACKDIR/src1 $BACKDIR/dst1 168f38cb554SJohn Wren Kennedy 169f38cb554SJohn Wren Kennedy return $ret 170f38cb554SJohn Wren Kennedy} 171f38cb554SJohn Wren Kennedy 172f38cb554SJohn Wren Kennedy# 173f38cb554SJohn Wren Kennedy# Compare all the directores and files in two filesystems 174f38cb554SJohn Wren Kennedy# 175f38cb554SJohn Wren Kennedy# $1 source filesystem 176f38cb554SJohn Wren Kennedy# $2 destination filesystem 177f38cb554SJohn Wren Kennedy# 178f38cb554SJohn Wren Kennedyfunction cmp_ds_cont 179f38cb554SJohn Wren Kennedy{ 180f38cb554SJohn Wren Kennedy typeset src_fs=$1 181f38cb554SJohn Wren Kennedy typeset dst_fs=$2 182f38cb554SJohn Wren Kennedy 183f38cb554SJohn Wren Kennedy typeset srcdir dstdir 184f38cb554SJohn Wren Kennedy srcdir=$(get_prop mountpoint $src_fs) 185f38cb554SJohn Wren Kennedy dstdir=$(get_prop mountpoint $dst_fs) 186f38cb554SJohn Wren Kennedy 187f38cb554SJohn Wren Kennedy $DIFF -r $srcdir $dstdir > /dev/null 2>&1 188f38cb554SJohn Wren Kennedy echo $? 189f38cb554SJohn Wren Kennedy} 190f38cb554SJohn Wren Kennedy 191f38cb554SJohn Wren Kennedy# 192f38cb554SJohn Wren Kennedy# Compare the given two dataset properties 193f38cb554SJohn Wren Kennedy# 194f38cb554SJohn Wren Kennedy# $1 dataset 1 195f38cb554SJohn Wren Kennedy# $2 dataset 2 196f38cb554SJohn Wren Kennedy# 197f38cb554SJohn Wren Kennedyfunction cmp_ds_prop 198f38cb554SJohn Wren Kennedy{ 199f38cb554SJohn Wren Kennedy typeset dtst1=$1 200f38cb554SJohn Wren Kennedy typeset dtst2=$2 201f38cb554SJohn Wren Kennedy 202f38cb554SJohn Wren Kennedy for item in "type" "origin" "volblocksize" "aclinherit" "aclmode" \ 203f38cb554SJohn Wren Kennedy "atime" "canmount" "checksum" "compression" "copies" "devices" \ 204f38cb554SJohn Wren Kennedy "exec" "quota" "readonly" "recordsize" "reservation" "setuid" \ 205f38cb554SJohn Wren Kennedy "sharenfs" "snapdir" "version" "volsize" "xattr" "zoned" \ 206f38cb554SJohn Wren Kennedy "mountpoint"; 207f38cb554SJohn Wren Kennedy do 208f38cb554SJohn Wren Kennedy $ZFS get -H -o property,value,source $item $dtst1 >> \ 209f38cb554SJohn Wren Kennedy $BACKDIR/dtst1 210f38cb554SJohn Wren Kennedy $ZFS get -H -o property,value,source $item $dtst2 >> \ 211f38cb554SJohn Wren Kennedy $BACKDIR/dtst2 212f38cb554SJohn Wren Kennedy done 213f38cb554SJohn Wren Kennedy 214f38cb554SJohn Wren Kennedy eval $SED -e 's:$dtst1:PREFIX:g' < $BACKDIR/dtst1 > $BACKDIR/dtst1 215f38cb554SJohn Wren Kennedy eval $SED -e 's:$dtst2:PREFIX:g' < $BACKDIR/dtst2 > $BACKDIR/dtst2 216f38cb554SJohn Wren Kennedy 217f38cb554SJohn Wren Kennedy $DIFF $BACKDIR/dtst1 $BACKDIR/dtst2 218f38cb554SJohn Wren Kennedy typeset -i ret=$? 219f38cb554SJohn Wren Kennedy 220f38cb554SJohn Wren Kennedy $RM -f $BACKDIR/dtst1 $BACKDIR/dtst2 221f38cb554SJohn Wren Kennedy 222f38cb554SJohn Wren Kennedy return $ret 223f38cb554SJohn Wren Kennedy 224f38cb554SJohn Wren Kennedy} 225f38cb554SJohn Wren Kennedy 226f38cb554SJohn Wren Kennedy# 227f38cb554SJohn Wren Kennedy# Random create directories and files 228f38cb554SJohn Wren Kennedy# 229f38cb554SJohn Wren Kennedy# $1 directory 230f38cb554SJohn Wren Kennedy# 231f38cb554SJohn Wren Kennedyfunction random_tree 232f38cb554SJohn Wren Kennedy{ 233f38cb554SJohn Wren Kennedy typeset dir=$1 234f38cb554SJohn Wren Kennedy 235f38cb554SJohn Wren Kennedy if [[ -d $dir ]]; then 236f38cb554SJohn Wren Kennedy $RM -rf $dir 237f38cb554SJohn Wren Kennedy fi 238f38cb554SJohn Wren Kennedy $MKDIR -p $dir 239f38cb554SJohn Wren Kennedy typeset -i ret=$? 240f38cb554SJohn Wren Kennedy 241f38cb554SJohn Wren Kennedy typeset -i nl nd nf 242f38cb554SJohn Wren Kennedy ((nl = RANDOM % 6 + 1)) 243f38cb554SJohn Wren Kennedy ((nd = RANDOM % 3 )) 244f38cb554SJohn Wren Kennedy ((nf = RANDOM % 5 )) 245f38cb554SJohn Wren Kennedy $MKTREE -b $dir -l $nl -d $nd -f $nf 246f38cb554SJohn Wren Kennedy ((ret |= $?)) 247f38cb554SJohn Wren Kennedy 248f38cb554SJohn Wren Kennedy return $ret 249f38cb554SJohn Wren Kennedy} 250f38cb554SJohn Wren Kennedy 251f38cb554SJohn Wren Kennedy# 252f38cb554SJohn Wren Kennedy# Put data in filesystem and take snapshot 253f38cb554SJohn Wren Kennedy# 254f38cb554SJohn Wren Kennedy# $1 snapshot name 255f38cb554SJohn Wren Kennedy# 256f38cb554SJohn Wren Kennedyfunction snapshot_tree 257f38cb554SJohn Wren Kennedy{ 258f38cb554SJohn Wren Kennedy typeset snap=$1 259f38cb554SJohn Wren Kennedy typeset ds=${snap%%@*} 260f38cb554SJohn Wren Kennedy typeset type=$(get_prop "type" $ds) 261f38cb554SJohn Wren Kennedy 262f38cb554SJohn Wren Kennedy typeset -i ret=0 263f38cb554SJohn Wren Kennedy if [[ $type == "filesystem" ]]; then 264f38cb554SJohn Wren Kennedy typeset mntpnt=$(get_prop mountpoint $ds) 265f38cb554SJohn Wren Kennedy ((ret |= $?)) 266f38cb554SJohn Wren Kennedy 267f38cb554SJohn Wren Kennedy if ((ret == 0)) ; then 268f38cb554SJohn Wren Kennedy eval random_tree $mntpnt/${snap##$ds} 269f38cb554SJohn Wren Kennedy ((ret |= $?)) 270f38cb554SJohn Wren Kennedy fi 271f38cb554SJohn Wren Kennedy fi 272f38cb554SJohn Wren Kennedy 273f38cb554SJohn Wren Kennedy if ((ret == 0)) ; then 274f38cb554SJohn Wren Kennedy $ZFS snapshot $snap 275f38cb554SJohn Wren Kennedy ((ret |= $?)) 276f38cb554SJohn Wren Kennedy fi 277f38cb554SJohn Wren Kennedy 278f38cb554SJohn Wren Kennedy return $ret 279f38cb554SJohn Wren Kennedy} 280f38cb554SJohn Wren Kennedy 281f38cb554SJohn Wren Kennedy# 282f38cb554SJohn Wren Kennedy# Destroy the given snapshot and stuff 283f38cb554SJohn Wren Kennedy# 284f38cb554SJohn Wren Kennedy# $1 snapshot 285f38cb554SJohn Wren Kennedy# 286f38cb554SJohn Wren Kennedyfunction destroy_tree 287f38cb554SJohn Wren Kennedy{ 288f38cb554SJohn Wren Kennedy typeset -i ret=0 289f38cb554SJohn Wren Kennedy typeset snap 290f38cb554SJohn Wren Kennedy for snap in "$@" ; do 291f38cb554SJohn Wren Kennedy $ZFS destroy $snap 292f38cb554SJohn Wren Kennedy ret=$? 293f38cb554SJohn Wren Kennedy 294f38cb554SJohn Wren Kennedy typeset ds=${snap%%@*} 295f38cb554SJohn Wren Kennedy typeset type=$(get_prop "type" $ds) 296f38cb554SJohn Wren Kennedy if [[ $type == "filesystem" ]]; then 297f38cb554SJohn Wren Kennedy typeset mntpnt=$(get_prop mountpoint $ds) 298f38cb554SJohn Wren Kennedy ((ret |= $?)) 299f38cb554SJohn Wren Kennedy 300f38cb554SJohn Wren Kennedy if ((ret != 0)); then 301f38cb554SJohn Wren Kennedy $RM -r $mntpnt/$snap 302f38cb554SJohn Wren Kennedy ((ret |= $?)) 303f38cb554SJohn Wren Kennedy fi 304f38cb554SJohn Wren Kennedy fi 305f38cb554SJohn Wren Kennedy 306f38cb554SJohn Wren Kennedy if ((ret != 0)); then 307f38cb554SJohn Wren Kennedy return $ret 308f38cb554SJohn Wren Kennedy fi 309f38cb554SJohn Wren Kennedy done 310f38cb554SJohn Wren Kennedy 311f38cb554SJohn Wren Kennedy return 0 312f38cb554SJohn Wren Kennedy} 313f38cb554SJohn Wren Kennedy 314f38cb554SJohn Wren Kennedy# 315f38cb554SJohn Wren Kennedy# Get all the sub-datasets of give dataset with specific suffix 316f38cb554SJohn Wren Kennedy# 317f38cb554SJohn Wren Kennedy# $1 Given dataset 318f38cb554SJohn Wren Kennedy# $2 Suffix 319f38cb554SJohn Wren Kennedy# 320f38cb554SJohn Wren Kennedyfunction getds_with_suffix 321f38cb554SJohn Wren Kennedy{ 322f38cb554SJohn Wren Kennedy typeset ds=$1 323f38cb554SJohn Wren Kennedy typeset suffix=$2 324f38cb554SJohn Wren Kennedy 325f38cb554SJohn Wren Kennedy typeset list=$($ZFS list -r -H -t filesystem,snapshot,volume -o name $ds \ 326f38cb554SJohn Wren Kennedy | $GREP "$suffix$") 327f38cb554SJohn Wren Kennedy 328f38cb554SJohn Wren Kennedy $ECHO $list 329f38cb554SJohn Wren Kennedy} 330f38cb554SJohn Wren Kennedy 331f38cb554SJohn Wren Kennedy# 332f38cb554SJohn Wren Kennedy# Output inherited properties whitch is edited for file system 333f38cb554SJohn Wren Kennedy# 334f38cb554SJohn Wren Kennedyfunction fs_inherit_prop 335f38cb554SJohn Wren Kennedy{ 336f38cb554SJohn Wren Kennedy typeset fs_prop 337f38cb554SJohn Wren Kennedy if is_global_zone ; then 338f38cb554SJohn Wren Kennedy fs_prop=$($ZFS inherit 2>&1 | \ 339f38cb554SJohn Wren Kennedy $AWK '$2=="YES" && $3=="YES" {print $1}') 340f38cb554SJohn Wren Kennedy if ! is_te_enabled ; then 341f38cb554SJohn Wren Kennedy fs_prop=$(echo $fs_prop | $GREP -v "mlslabel") 342f38cb554SJohn Wren Kennedy fi 343f38cb554SJohn Wren Kennedy else 344f38cb554SJohn Wren Kennedy fs_prop=$($ZFS inherit 2>&1 | \ 345f38cb554SJohn Wren Kennedy $AWK '$2=="YES" && $3=="YES" {print $1}'| 346f38cb554SJohn Wren Kennedy $EGREP -v "devices|mlslabel|sharenfs|sharesmb|zoned") 347f38cb554SJohn Wren Kennedy fi 348f38cb554SJohn Wren Kennedy 349f38cb554SJohn Wren Kennedy $ECHO $fs_prop 350f38cb554SJohn Wren Kennedy} 351f38cb554SJohn Wren Kennedy 352f38cb554SJohn Wren Kennedy# 353f38cb554SJohn Wren Kennedy# Output inherited properties for volume 354f38cb554SJohn Wren Kennedy# 355f38cb554SJohn Wren Kennedyfunction vol_inherit_prop 356f38cb554SJohn Wren Kennedy{ 357f38cb554SJohn Wren Kennedy $ECHO "checksum readonly" 358f38cb554SJohn Wren Kennedy} 359f38cb554SJohn Wren Kennedy 360f38cb554SJohn Wren Kennedy# 361f38cb554SJohn Wren Kennedy# Get the destination dataset to compare 362f38cb554SJohn Wren Kennedy# 363f38cb554SJohn Wren Kennedyfunction get_dst_ds 364f38cb554SJohn Wren Kennedy{ 365f38cb554SJohn Wren Kennedy typeset srcfs=$1 366f38cb554SJohn Wren Kennedy typeset dstfs=$2 367f38cb554SJohn Wren Kennedy 368f38cb554SJohn Wren Kennedy # 369f38cb554SJohn Wren Kennedy # If the srcfs is not pool 370f38cb554SJohn Wren Kennedy # 371f38cb554SJohn Wren Kennedy if ! $ZPOOL list $srcfs > /dev/null 2>&1 ; then 372f38cb554SJohn Wren Kennedy eval dstfs="$dstfs/${srcfs#*/}" 373f38cb554SJohn Wren Kennedy fi 374f38cb554SJohn Wren Kennedy 375f38cb554SJohn Wren Kennedy $ECHO $dstfs 376f38cb554SJohn Wren Kennedy} 377*9c3fd121SMatthew Ahrens 378*9c3fd121SMatthew Ahrens# 379*9c3fd121SMatthew Ahrens# Make test files 380*9c3fd121SMatthew Ahrens# 381*9c3fd121SMatthew Ahrens# $1 Number of files to create 382*9c3fd121SMatthew Ahrens# $2 Maximum file size 383*9c3fd121SMatthew Ahrens# $3 File ID offset 384*9c3fd121SMatthew Ahrens# $4 File system to create the files on 385*9c3fd121SMatthew Ahrens# 386*9c3fd121SMatthew Ahrensfunction mk_files 387*9c3fd121SMatthew Ahrens{ 388*9c3fd121SMatthew Ahrens nfiles=$1 389*9c3fd121SMatthew Ahrens maxsize=$2 390*9c3fd121SMatthew Ahrens file_id_offset=$3 391*9c3fd121SMatthew Ahrens fs=$4 392*9c3fd121SMatthew Ahrens 393*9c3fd121SMatthew Ahrens for ((i=0; i<$nfiles; i=i+1)); do 394*9c3fd121SMatthew Ahrens $DD if=/dev/urandom \ 395*9c3fd121SMatthew Ahrens of=/$fs/file-$maxsize-$((i+$file_id_offset)) \ 396*9c3fd121SMatthew Ahrens bs=$(($RANDOM * $RANDOM % $maxsize)) \ 397*9c3fd121SMatthew Ahrens count=1 >/dev/null 2>&1 || log_fail \ 398*9c3fd121SMatthew Ahrens "Failed to create /$fs/file-$maxsize-$((i+$file_id_offset))" 399*9c3fd121SMatthew Ahrens done 400*9c3fd121SMatthew Ahrens $ECHO Created $nfiles files of random sizes up to $maxsize bytes 401*9c3fd121SMatthew Ahrens} 402*9c3fd121SMatthew Ahrens 403*9c3fd121SMatthew Ahrens# 404*9c3fd121SMatthew Ahrens# Remove test files 405*9c3fd121SMatthew Ahrens# 406*9c3fd121SMatthew Ahrens# $1 Number of files to remove 407*9c3fd121SMatthew Ahrens# $2 Maximum file size 408*9c3fd121SMatthew Ahrens# $3 File ID offset 409*9c3fd121SMatthew Ahrens# $4 File system to remove the files from 410*9c3fd121SMatthew Ahrens# 411*9c3fd121SMatthew Ahrensfunction rm_files 412*9c3fd121SMatthew Ahrens{ 413*9c3fd121SMatthew Ahrens nfiles=$1 414*9c3fd121SMatthew Ahrens maxsize=$2 415*9c3fd121SMatthew Ahrens file_id_offset=$3 416*9c3fd121SMatthew Ahrens fs=$4 417*9c3fd121SMatthew Ahrens 418*9c3fd121SMatthew Ahrens for ((i=0; i<$nfiles; i=i+1)); do 419*9c3fd121SMatthew Ahrens $RM -f /$fs/file-$maxsize-$((i+$file_id_offset)) 420*9c3fd121SMatthew Ahrens done 421*9c3fd121SMatthew Ahrens $ECHO Removed $nfiles files of random sizes up to $maxsize bytes 422*9c3fd121SMatthew Ahrens} 423*9c3fd121SMatthew Ahrens 424*9c3fd121SMatthew Ahrens# 425*9c3fd121SMatthew Ahrens# Mess up file contents 426*9c3fd121SMatthew Ahrens# 427*9c3fd121SMatthew Ahrens# $1 The file path 428*9c3fd121SMatthew Ahrens# 429*9c3fd121SMatthew Ahrensfunction mess_file 430*9c3fd121SMatthew Ahrens{ 431*9c3fd121SMatthew Ahrens file=$1 432*9c3fd121SMatthew Ahrens 433*9c3fd121SMatthew Ahrens filesize=$($STAT -c '%s' $file) 434*9c3fd121SMatthew Ahrens offset=$(($RANDOM * $RANDOM % $filesize)) 435*9c3fd121SMatthew Ahrens if (($RANDOM % 7 <= 1)); then 436*9c3fd121SMatthew Ahrens # 437*9c3fd121SMatthew Ahrens # We corrupt 2 bytes to minimize the chance that we 438*9c3fd121SMatthew Ahrens # write the same value that's already there. 439*9c3fd121SMatthew Ahrens # 440*9c3fd121SMatthew Ahrens log_must eval "$DD if=/dev/random of=$file conv=notrunc " \ 441*9c3fd121SMatthew Ahrens "bs=1 count=2 oseek=$offset >/dev/null 2>&1" 442*9c3fd121SMatthew Ahrens else 443*9c3fd121SMatthew Ahrens log_must $TRUNCATE -s $offset $file 444*9c3fd121SMatthew Ahrens fi 445*9c3fd121SMatthew Ahrens} 446*9c3fd121SMatthew Ahrens 447*9c3fd121SMatthew Ahrens# 448*9c3fd121SMatthew Ahrens# Diff the send/receive filesystems 449*9c3fd121SMatthew Ahrens# 450*9c3fd121SMatthew Ahrens# $1 The sent filesystem 451*9c3fd121SMatthew Ahrens# $2 The received filesystem 452*9c3fd121SMatthew Ahrens# 453*9c3fd121SMatthew Ahrensfunction file_check 454*9c3fd121SMatthew Ahrens{ 455*9c3fd121SMatthew Ahrens sendfs=$1 456*9c3fd121SMatthew Ahrens recvfs=$2 457*9c3fd121SMatthew Ahrens 458*9c3fd121SMatthew Ahrens if [[ -d /$recvfs/.zfs/snapshot/a && -d \ 459*9c3fd121SMatthew Ahrens /$sendfs/.zfs/snapshot/a ]]; then 460*9c3fd121SMatthew Ahrens $DIFF -r /$recvfs/.zfs/snapshot/a /$sendfs/.zfs/snapshot/a 461*9c3fd121SMatthew Ahrens [[ $? -eq 0 ]] || log_fail "Differences found in snap a" 462*9c3fd121SMatthew Ahrens fi 463*9c3fd121SMatthew Ahrens if [[ -d /$recvfs/.zfs/snapshot/b && -d \ 464*9c3fd121SMatthew Ahrens /$sendfs/.zfs/snapshot/b ]]; then 465*9c3fd121SMatthew Ahrens $DIFF -r /$recvfs/.zfs/snapshot/b /$sendfs/.zfs/snapshot/b 466*9c3fd121SMatthew Ahrens [[ $? -eq 0 ]] || log_fail "Differences found in snap b" 467*9c3fd121SMatthew Ahrens fi 468*9c3fd121SMatthew Ahrens} 469*9c3fd121SMatthew Ahrens 470*9c3fd121SMatthew Ahrens# 471*9c3fd121SMatthew Ahrens# Resume test helper 472*9c3fd121SMatthew Ahrens# 473*9c3fd121SMatthew Ahrens# $1 The ZFS send command 474*9c3fd121SMatthew Ahrens# $2 The filesystem where the streams are sent 475*9c3fd121SMatthew Ahrens# $3 The receive filesystem 476*9c3fd121SMatthew Ahrens# 477*9c3fd121SMatthew Ahrensfunction resume_test 478*9c3fd121SMatthew Ahrens{ 479*9c3fd121SMatthew Ahrens sendcmd=$1 480*9c3fd121SMatthew Ahrens streamfs=$2 481*9c3fd121SMatthew Ahrens recvfs=$3 482*9c3fd121SMatthew Ahrens 483*9c3fd121SMatthew Ahrens stream_num=1 484*9c3fd121SMatthew Ahrens log_must eval "$sendcmd >/$streamfs/$stream_num" 485*9c3fd121SMatthew Ahrens 486*9c3fd121SMatthew Ahrens for ((i=0; i<2; i=i+1)); do 487*9c3fd121SMatthew Ahrens mess_file /$streamfs/$stream_num 488*9c3fd121SMatthew Ahrens log_mustnot $ZFS recv -sv $recvfs </$streamfs/$stream_num 489*9c3fd121SMatthew Ahrens stream_num=$((stream_num+1)) 490*9c3fd121SMatthew Ahrens 491*9c3fd121SMatthew Ahrens token=$($ZFS get -Hp -o value receive_resume_token $recvfs) 492*9c3fd121SMatthew Ahrens log_must eval "$ZFS send -v -t $token >/$streamfs/$stream_num" 493*9c3fd121SMatthew Ahrens [[ -f /$streamfs/$stream_num ]] || \ 494*9c3fd121SMatthew Ahrens log_fail "NO FILE /$streamfs/$stream_num" 495*9c3fd121SMatthew Ahrens done 496*9c3fd121SMatthew Ahrens log_must $ZFS recv -sv $recvfs </$streamfs/$stream_num 497*9c3fd121SMatthew Ahrens} 498*9c3fd121SMatthew Ahrens 499*9c3fd121SMatthew Ahrens# 500*9c3fd121SMatthew Ahrens# Setup filesystems for the resumable send/receive tests 501*9c3fd121SMatthew Ahrens# 502*9c3fd121SMatthew Ahrens# $1 The pool to set up with the "send" filesystems 503*9c3fd121SMatthew Ahrens# $2 The pool for receive 504*9c3fd121SMatthew Ahrens# 505*9c3fd121SMatthew Ahrensfunction test_fs_setup 506*9c3fd121SMatthew Ahrens{ 507*9c3fd121SMatthew Ahrens sendpool=$1 508*9c3fd121SMatthew Ahrens recvpool=$2 509*9c3fd121SMatthew Ahrens 510*9c3fd121SMatthew Ahrens sendfs=$sendpool/sendfs 511*9c3fd121SMatthew Ahrens recvfs=$recvpool/recvfs 512*9c3fd121SMatthew Ahrens streamfs=$sendpool/stream 513*9c3fd121SMatthew Ahrens 514*9c3fd121SMatthew Ahrens if datasetexists $recvfs; then 515*9c3fd121SMatthew Ahrens log_must $ZFS destroy -r $recvfs 516*9c3fd121SMatthew Ahrens fi 517*9c3fd121SMatthew Ahrens if datasetexists $sendfs; then 518*9c3fd121SMatthew Ahrens log_must $ZFS destroy -r $sendfs 519*9c3fd121SMatthew Ahrens fi 520*9c3fd121SMatthew Ahrens if $($ZFS create -o compress=lz4 $sendfs); then 521*9c3fd121SMatthew Ahrens mk_files 1000 256 0 $sendfs & 522*9c3fd121SMatthew Ahrens mk_files 1000 131072 0 $sendfs & 523*9c3fd121SMatthew Ahrens mk_files 100 1048576 0 $sendfs & 524*9c3fd121SMatthew Ahrens mk_files 10 10485760 0 $sendfs & 525*9c3fd121SMatthew Ahrens mk_files 1 104857600 0 $sendfs & 526*9c3fd121SMatthew Ahrens log_must $WAIT 527*9c3fd121SMatthew Ahrens log_must $ZFS snapshot $sendfs@a 528*9c3fd121SMatthew Ahrens 529*9c3fd121SMatthew Ahrens rm_files 200 256 0 $sendfs & 530*9c3fd121SMatthew Ahrens rm_files 200 131072 0 $sendfs & 531*9c3fd121SMatthew Ahrens rm_files 20 1048576 0 $sendfs & 532*9c3fd121SMatthew Ahrens rm_files 2 10485760 0 $sendfs & 533*9c3fd121SMatthew Ahrens log_must $WAIT 534*9c3fd121SMatthew Ahrens 535*9c3fd121SMatthew Ahrens mk_files 400 256 0 $sendfs & 536*9c3fd121SMatthew Ahrens mk_files 400 131072 0 $sendfs & 537*9c3fd121SMatthew Ahrens mk_files 40 1048576 0 $sendfs & 538*9c3fd121SMatthew Ahrens mk_files 4 10485760 0 $sendfs & 539*9c3fd121SMatthew Ahrens log_must $WAIT 540*9c3fd121SMatthew Ahrens 541*9c3fd121SMatthew Ahrens log_must $ZFS snapshot $sendfs@b 542*9c3fd121SMatthew Ahrens log_must eval "$ZFS send -v $sendfs@a >/$sendpool/initial.zsend" 543*9c3fd121SMatthew Ahrens log_must eval "$ZFS send -v -i @a $sendfs@b " \ 544*9c3fd121SMatthew Ahrens ">/$sendpool/incremental.zsend" 545*9c3fd121SMatthew Ahrens fi 546*9c3fd121SMatthew Ahrens 547*9c3fd121SMatthew Ahrens if datasetexists $streamfs; then 548*9c3fd121SMatthew Ahrens log_must $ZFS destroy -r $streamfs 549*9c3fd121SMatthew Ahrens fi 550*9c3fd121SMatthew Ahrens log_must $ZFS create -o compress=lz4 $sendpool/stream 551*9c3fd121SMatthew Ahrens} 552