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# Copyright (c) 2019 Datto, Inc. All rights reserved. 18# 19 20. $STF_SUITE/include/libtest.shlib 21 22# 23# DESCRIPTION: 24# Verify that 'zfs receive' produces an error when mixing 25# raw and non-raw sends in a way that would break IV set 26# consistency. 27# 28# STRATEGY: 29# 1. Create an initial dataset with 3 snapshots. 30# 2. Perform a raw send of the first snapshot to 2 other datasets. 31# 3. Perform a non-raw send of the second snapshot to one of 32# the other datasets. Perform a raw send from this dataset to 33# the last one. 34# 4. Attempt to raw send the final snapshot of the first dataset 35# to the other 2 datasets, which should fail. 36# 5. Repeat steps 1-4, but using bookmarks for incremental sends. 37# 38# 39# A B C notes 40# ------------------------------------------------------------------------------ 41# snap1 ---raw---> snap1 --raw--> snap1 # all snaps initialized via raw send 42# snap2 -non-raw-> snap2 --raw--> snap2 # A sends non-raw to B, B sends raw to C 43# snap3 ------------raw---------> snap3 # attempt send to C (should fail) 44# 45 46 47verify_runnable "both" 48 49function cleanup 50{ 51 datasetexists $TESTPOOL/$TESTFS3 && \ 52 destroy_dataset $TESTPOOL/$TESTFS3 -r 53 datasetexists $TESTPOOL/$TESTFS2 && \ 54 destroy_dataset $TESTPOOL/$TESTFS2 -r 55 datasetexists $TESTPOOL/$TESTFS1 && \ 56 destroy_dataset $TESTPOOL/$TESTFS1 -r 57} 58log_onexit cleanup 59 60log_assert "Mixing raw and non-raw receives should fail" 61 62typeset passphrase="password" 63 64log_must eval "echo $passphrase | zfs create -o encryption=on" \ 65 "-o keyformat=passphrase $TESTPOOL/$TESTFS1" 66 67log_must zfs snapshot $TESTPOOL/$TESTFS1@1 68log_must touch /$TESTPOOL/$TESTFS1/a 69log_must zfs snapshot $TESTPOOL/$TESTFS1@2 70log_must touch /$TESTPOOL/$TESTFS1/b 71log_must zfs snapshot $TESTPOOL/$TESTFS1@3 72 73# Testing with snapshots 74log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \ 75 "zfs receive $TESTPOOL/$TESTFS2" 76log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" 77log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \ 78 "zfs receive $TESTPOOL/$TESTFS3" 79log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3" 80 81log_must eval "zfs send -i $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1@2 |" \ 82 "zfs receive $TESTPOOL/$TESTFS2" 83log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2@2 |" \ 84 "zfs receive $TESTPOOL/$TESTFS3" 85 86log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1@3 |" \ 87 "zfs receive $TESTPOOL/$TESTFS2" 88log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS2@3 |" \ 89 "zfs receive $TESTPOOL/$TESTFS3" 90 91log_must zfs destroy -r $TESTPOOL/$TESTFS3 92log_must zfs destroy -r $TESTPOOL/$TESTFS2 93 94# Testing with bookmarks 95log_must zfs bookmark $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1#b1 96log_must zfs bookmark $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1#b2 97 98log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \ 99 "zfs receive $TESTPOOL/$TESTFS2" 100log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" 101 102log_must zfs bookmark $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2#b1 103 104log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \ 105 "zfs receive $TESTPOOL/$TESTFS3" 106log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3" 107 108log_must eval "zfs send -i $TESTPOOL/$TESTFS1#b1 $TESTPOOL/$TESTFS1@2 |" \ 109 "zfs receive $TESTPOOL/$TESTFS2" 110log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2#b1 $TESTPOOL/$TESTFS2@2 |" \ 111 "zfs receive $TESTPOOL/$TESTFS3" 112 113log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1#b2" \ 114 "$TESTPOOL/$TESTFS1@3 | zfs receive $TESTPOOL/$TESTFS2" 115log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2#b2" \ 116 "$TESTPOOL/$TESTFS2@3 | zfs receive $TESTPOOL/$TESTFS3" 117 118log_pass "Mixing raw and non-raw receives fail as expected" 119