4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2015 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/rsend/rsend.cfg
35 # Set up test model which includes various datasets
45 # ||@final @final @snapC
46 # ||@snapC @snapC @snapB
47 # ||@snapA @snapB @snapA
50 # $pool -------- $FS ------- fs1 ------- fs2
52 # vol vol \____ \ @fsnap
54 # @init @vsnap | ------------ fclone
56 # @final @snapB \ | @init
57 # @snapC vclone @snapA
65 function setup_test_model
69 log_must $ZFS create -p $pool/$FS/fs1/fs2
71 log_must $ZFS snapshot $pool@psnap
72 log_must $ZFS clone $pool@psnap $pool/pclone
74 if is_global_zone ; then
75 log_must $ZFS create -V 16M $pool/vol
76 log_must $ZFS create -V 16M $pool/$FS/vol
78 log_must $ZFS snapshot $pool/$FS/vol@vsnap
79 log_must $ZFS clone $pool/$FS/vol@vsnap $pool/$FS/vclone
82 log_must snapshot_tree $pool/$FS/fs1/fs2@fsnap
83 log_must $ZFS clone $pool/$FS/fs1/fs2@fsnap $pool/$FS/fs1/fclone
84 log_must $ZFS snapshot -r $pool@init
86 log_must snapshot_tree $pool@snapA
87 log_must snapshot_tree $pool@snapC
88 log_must snapshot_tree $pool/pclone@snapB
89 log_must snapshot_tree $pool/$FS@snapB
90 log_must snapshot_tree $pool/$FS@snapC
91 log_must snapshot_tree $pool/$FS/fs1@snapA
92 log_must snapshot_tree $pool/$FS/fs1@snapB
93 log_must snapshot_tree $pool/$FS/fs1@snapC
94 log_must snapshot_tree $pool/$FS/fs1/fclone@snapA
96 if is_global_zone ; then
97 log_must $ZFS snapshot $pool/vol@snapA
98 log_must $ZFS snapshot $pool/$FS/vol@snapB
99 log_must $ZFS snapshot $pool/$FS/vol@snapC
100 log_must $ZFS snapshot $pool/$FS/vclone@snapC
103 log_must $ZFS snapshot -r $pool@final
109 # Cleanup the BACKDIR and given pool content and all the sub datasets
113 function cleanup_pool
116 log_must $RM -rf $BACKDIR/*
118 if is_global_zone ; then
119 log_must $ZFS destroy -Rf $pool
121 typeset list=$($ZFS list -H -r -t filesystem,snapshot,volume -o name $pool)
123 if [[ $ds != $pool ]] ; then
124 if datasetexists $ds ; then
125 log_must $ZFS destroy -Rf $ds
131 typeset mntpnt=$(get_prop mountpoint $pool)
132 if ! ismounted $pool ; then
133 # Make sure mountpoint directory is empty
134 if [[ -d $mntpnt ]]; then
135 log_must $RM -rf $mntpnt/*
138 log_must $ZFS mount $pool
140 if [[ -d $mntpnt ]]; then
141 log_must $RM -rf $mntpnt/*
148 # Detect if the given two filesystems have same sub-datasets
150 # $1 source filesystem
151 # $2 destination filesystem
158 $ZFS list -r -H -t filesystem,snapshot,volume -o name $src_fs > $BACKDIR/src1
159 $ZFS list -r -H -t filesystem,snapshot,volume -o name $dst_fs > $BACKDIR/dst1
161 eval $SED -e 's:^$src_fs:PREFIX:g' < $BACKDIR/src1 > $BACKDIR/src
162 eval $SED -e 's:^$dst_fs:PREFIX:g' < $BACKDIR/dst1 > $BACKDIR/dst
164 $DIFF $BACKDIR/src $BACKDIR/dst
167 $RM -f $BACKDIR/src $BACKDIR/dst $BACKDIR/src1 $BACKDIR/dst1
173 # Compare all the directores and files in two filesystems
175 # $1 source filesystem
176 # $2 destination filesystem
183 typeset srcdir dstdir
184 srcdir=$(get_prop mountpoint $src_fs)
185 dstdir=$(get_prop mountpoint $dst_fs)
187 $DIFF -r $srcdir $dstdir > /dev/null 2>&1
192 # Compare the given two dataset properties
202 for item in "type" "origin" "volblocksize" "aclinherit" "aclmode" \
203 "atime" "canmount" "checksum" "compression" "copies" "devices" \
204 "exec" "quota" "readonly" "recordsize" "reservation" "setuid" \
205 "sharenfs" "snapdir" "version" "volsize" "xattr" "zoned" \
208 $ZFS get -H -o property,value,source $item $dtst1 >> \
210 $ZFS get -H -o property,value,source $item $dtst2 >> \
214 eval $SED -e 's:$dtst1:PREFIX:g' < $BACKDIR/dtst1 > $BACKDIR/dtst1
215 eval $SED -e 's:$dtst2:PREFIX:g' < $BACKDIR/dtst2 > $BACKDIR/dtst2
217 $DIFF $BACKDIR/dtst1 $BACKDIR/dtst2
220 $RM -f $BACKDIR/dtst1 $BACKDIR/dtst2
227 # Random create directories and files
235 if [[ -d $dir ]]; then
242 ((nl = RANDOM % 6 + 1))
245 $MKTREE -b $dir -l $nl -d $nd -f $nf
252 # Put data in filesystem and take snapshot
256 function snapshot_tree
259 typeset ds=${snap%%@*}
260 typeset type=$(get_prop "type" $ds)
263 if [[ $type == "filesystem" ]]; then
264 typeset mntpnt=$(get_prop mountpoint $ds)
267 if ((ret == 0)) ; then
268 eval random_tree $mntpnt/${snap##$ds}
273 if ((ret == 0)) ; then
282 # Destroy the given snapshot and stuff
286 function destroy_tree
290 for snap in "$@" ; do
294 typeset ds=${snap%%@*}
295 typeset type=$(get_prop "type" $ds)
296 if [[ $type == "filesystem" ]]; then
297 typeset mntpnt=$(get_prop mountpoint $ds)
300 if ((ret != 0)); then
306 if ((ret != 0)); then
315 # Get all the sub-datasets of give dataset with specific suffix
320 function getds_with_suffix
325 typeset list=$($ZFS list -r -H -t filesystem,snapshot,volume -o name $ds \
332 # Output inherited properties whitch is edited for file system
334 function fs_inherit_prop
337 if is_global_zone ; then
338 fs_prop=$($ZFS inherit 2>&1 | \
339 $AWK '$2=="YES" && $3=="YES" {print $1}')
340 if ! is_te_enabled ; then
341 fs_prop=$(echo $fs_prop | $GREP -v "mlslabel")
344 fs_prop=$($ZFS inherit 2>&1 | \
345 $AWK '$2=="YES" && $3=="YES" {print $1}'|
346 $EGREP -v "devices|mlslabel|sharenfs|sharesmb|zoned")
353 # Output inherited properties for volume
355 function vol_inherit_prop
357 $ECHO "checksum readonly"
361 # Get the destination dataset to compare
369 # If the srcfs is not pool
371 if ! $ZPOOL list $srcfs > /dev/null 2>&1 ; then
372 eval dstfs="$dstfs/${srcfs#*/}"
381 # $1 Number of files to create
382 # $2 Maximum file size
384 # $4 File system to create the files on
393 for ((i=0; i<$nfiles; i=i+1)); do
394 $DD if=/dev/urandom \
395 of=/$fs/file-$maxsize-$((i+$file_id_offset)) \
396 bs=$(($RANDOM * $RANDOM % $maxsize)) \
397 count=1 >/dev/null 2>&1 || log_fail \
398 "Failed to create /$fs/file-$maxsize-$((i+$file_id_offset))"
400 $ECHO Created $nfiles files of random sizes up to $maxsize bytes
406 # $1 Number of files to remove
407 # $2 Maximum file size
409 # $4 File system to remove the files from
418 for ((i=0; i<$nfiles; i=i+1)); do
419 $RM -f /$fs/file-$maxsize-$((i+$file_id_offset))
421 $ECHO Removed $nfiles files of random sizes up to $maxsize bytes
425 # Mess up file contents
433 filesize=$($STAT -c '%s' $file)
434 offset=$(($RANDOM * $RANDOM % $filesize))
435 if (($RANDOM % 7 <= 1)); then
437 # We corrupt 2 bytes to minimize the chance that we
438 # write the same value that's already there.
440 log_must eval "$DD if=/dev/random of=$file conv=notrunc " \
441 "bs=1 count=2 oseek=$offset >/dev/null 2>&1"
443 log_must $TRUNCATE -s $offset $file
448 # Diff the send/receive filesystems
450 # $1 The sent filesystem
451 # $2 The received filesystem
458 if [[ -d /$recvfs/.zfs/snapshot/a && -d \
459 /$sendfs/.zfs/snapshot/a ]]; then
460 $DIFF -r /$recvfs/.zfs/snapshot/a /$sendfs/.zfs/snapshot/a
461 [[ $? -eq 0 ]] || log_fail "Differences found in snap a"
463 if [[ -d /$recvfs/.zfs/snapshot/b && -d \
464 /$sendfs/.zfs/snapshot/b ]]; then
465 $DIFF -r /$recvfs/.zfs/snapshot/b /$sendfs/.zfs/snapshot/b
466 [[ $? -eq 0 ]] || log_fail "Differences found in snap b"
473 # $1 The ZFS send command
474 # $2 The filesystem where the streams are sent
475 # $3 The receive filesystem
484 log_must eval "$sendcmd >/$streamfs/$stream_num"
486 for ((i=0; i<2; i=i+1)); do
487 mess_file /$streamfs/$stream_num
488 log_mustnot $ZFS recv -sv $recvfs </$streamfs/$stream_num
489 stream_num=$((stream_num+1))
491 token=$($ZFS get -Hp -o value receive_resume_token $recvfs)
492 log_must eval "$ZFS send -v -t $token >/$streamfs/$stream_num"
493 [[ -f /$streamfs/$stream_num ]] || \
494 log_fail "NO FILE /$streamfs/$stream_num"
496 log_must $ZFS recv -sv $recvfs </$streamfs/$stream_num
500 # Setup filesystems for the resumable send/receive tests
502 # $1 The pool to set up with the "send" filesystems
503 # $2 The pool for receive
505 function test_fs_setup
510 sendfs=$sendpool/sendfs
511 recvfs=$recvpool/recvfs
512 streamfs=$sendpool/stream
514 if datasetexists $recvfs; then
515 log_must $ZFS destroy -r $recvfs
517 if datasetexists $sendfs; then
518 log_must $ZFS destroy -r $sendfs
520 if $($ZFS create -o compress=lz4 $sendfs); then
521 mk_files 1000 256 0 $sendfs &
522 mk_files 1000 131072 0 $sendfs &
523 mk_files 100 1048576 0 $sendfs &
524 mk_files 10 10485760 0 $sendfs &
525 mk_files 1 104857600 0 $sendfs &
527 log_must $ZFS snapshot $sendfs@a
529 rm_files 200 256 0 $sendfs &
530 rm_files 200 131072 0 $sendfs &
531 rm_files 20 1048576 0 $sendfs &
532 rm_files 2 10485760 0 $sendfs &
535 mk_files 400 256 0 $sendfs &
536 mk_files 400 131072 0 $sendfs &
537 mk_files 40 1048576 0 $sendfs &
538 mk_files 4 10485760 0 $sendfs &
541 log_must $ZFS snapshot $sendfs@b
542 log_must eval "$ZFS send -v $sendfs@a >/$sendpool/initial.zsend"
543 log_must eval "$ZFS send -v -i @a $sendfs@b " \
544 ">/$sendpool/incremental.zsend"
547 if datasetexists $streamfs; then
548 log_must $ZFS destroy -r $streamfs
550 log_must $ZFS create -o compress=lz4 $sendpool/stream