1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17# 18# Copyright (c) 2018 by Datto Inc. All rights reserved. 19# 20 21. $STF_SUITE/tests/functional/rsend/rsend.kshlib 22 23# 24# DESCRIPTION: 25# Verify that a raw zfs send and receive can deal with several different 26# types of file layouts. 27# 28# STRATEGY: 29# 1. Create a new encrypted filesystem 30# 2. Add an empty file to the filesystem 31# 3. Add a small 512 byte file to the filesystem 32# 4. Add a larger 32M file to the filesystem 33# 5. Add a large sparse file to the filesystem 34# 6. Add 1000 empty files to the filesystem 35# 7. Add a file with a large xattr value 36# 8. Use xattrtest to create files with random xattrs (with and without xattrs=on) 37# 9. Take a snapshot of the filesystem 38# 10. Remove the 1000 empty files to the filesystem 39# 11. Take another snapshot of the filesystem 40# 12. Send and receive both snapshots 41# 13. Mount the filesystem and check the contents 42# 43 44verify_runnable "both" 45 46function cleanup 47{ 48 datasetexists $TESTPOOL/$TESTFS2 && \ 49 log_must zfs destroy -r $TESTPOOL/$TESTFS2 50 datasetexists $TESTPOOL/recv && \ 51 log_must zfs destroy -r $TESTPOOL/recv 52 [[ -f $keyfile ]] && log_must rm $keyfile 53 [[ -f $sendfile ]] && log_must rm $sendfile 54} 55log_onexit cleanup 56 57function recursive_cksum 58{ 59 find $1 -type f -exec sha256sum {} \; | \ 60 sort -k 2 | awk '{ print $1 }' | sha256sum 61} 62 63log_assert "Verify 'zfs send -w' works with many different file layouts" 64 65typeset keyfile=/$TESTPOOL/pkey 66typeset sendfile=/$TESTPOOL/sendfile 67typeset sendfile2=/$TESTPOOL/sendfile2 68 69# Create an encrypted dataset 70log_must eval "echo 'password' > $keyfile" 71log_must zfs create -o encryption=on -o keyformat=passphrase \ 72 -o keylocation=file://$keyfile $TESTPOOL/$TESTFS2 73 74# Create files with varied layouts on disk 75log_must touch /$TESTPOOL/$TESTFS2/empty 76log_must mkfile 512 /$TESTPOOL/$TESTFS2/small 77log_must mkfile 32M /$TESTPOOL/$TESTFS2/full 78log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/sparse \ 79 bs=512 count=1 seek=1048576 >/dev/null 2>&1 80 81log_must mkdir -p /$TESTPOOL/$TESTFS2/dir 82for i in {1..1000}; do 83 log_must mkfile 512 /$TESTPOOL/$TESTFS2/dir/file-$i 84done 85 86log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrondir 87log_must zfs set xattr=on $TESTPOOL/$TESTFS2 88 89# XXX - the lines below (through the end of the file) that are commented out 90# are differences from ZoL due to currently unsupported extended attribute code 91# on illumos. 92# log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrondir 93# log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrsadir 94# log_must zfs set xattr=sa $TESTPOOL/$TESTFS2 95# log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrsadir 96 97# ZoL issue #7432 98# log_must zfs set compression=on xattr=sa $TESTPOOL/$TESTFS2 99# log_must touch /$TESTPOOL/$TESTFS2/attrs 100# log_must eval "python -c 'print \"a\" * 4096' | \ 101# attr -s bigval /$TESTPOOL/$TESTFS2/attrs" 102# log_must zfs set compression=off xattr=on $TESTPOOL/$TESTFS2 103 104log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1 105 106# Remove the empty files created in the first snapshot 107for i in {1..1000}; do 108 log_must rm /$TESTPOOL/$TESTFS2/dir/file-$i 109done 110sync 111 112log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2 113expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2) 114 115log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile" 116log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2" 117 118log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile" 119log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2" 120log_must zfs load-key $TESTPOOL/recv 121 122log_must zfs mount -a 123actual_cksum=$(recursive_cksum /$TESTPOOL/recv) 124[[ "$expected_cksum" != "$actual_cksum" ]] && \ 125 log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)" 126 127# log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrondir 128# log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrsadir 129 130log_pass "Verified 'zfs send -w' works with many different file layouts" 131