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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 19# 20 21. $STF_SUITE/include/libtest.shlib 22 23# 24# DESCRIPTION: 25# ZFS receive '-e' option can be used to discard all but the last element of 26# the sent snapshot's file system name 27# 28# STRATEGY: 29# 1. Create a filesystem with children and snapshots 30# 2. Verify 'zfs receive -e' rejects invalid options 31# 3. Verify 'zfs receive -e' can receive the root dataset 32# 4. Verify 'zfs receive -e' can receive a replication stream 33# 5. Verify 'zfs receive -e' can receive an incremental replication stream 34# 35 36verify_runnable "both" 37 38function cleanup 39{ 40 destroy_pool "$poolname" 41 log_must rm -f "$vdevfile" 42 log_must rm -f "$streamfile" 43} 44 45log_assert "ZFS receive '-e' option can be used to discard all but the last"\ 46 "element of the sent snapshot's file system name" 47log_onexit cleanup 48 49poolname="$TESTPOOL-zfsrecv" 50recvfs="$poolname/recv" 51vdevfile="$TEST_BASE_DIR/vdevfile.$$" 52streamfile="$TEST_BASE_DIR/streamfile.$$" 53 54# 55# 1. Create a filesystem with children and snapshots 56# NOTE: set "mountpoint=none" just to speed up the test process 57# 58log_must truncate -s $MINVDEVSIZE "$vdevfile" 59log_must zpool create -O mountpoint=none "$poolname" "$vdevfile" 60log_must zfs create -p "$poolname/fs/a/b" 61log_must zfs create "$recvfs" 62log_must zfs snapshot -r "$poolname@full" 63log_must zfs snapshot -r "$poolname@incr" 64 65# 66# 2. Verify 'zfs receive -e' rejects invalid options 67# 68log_must eval "zfs send $poolname/fs@full > $streamfile" 69log_mustnot eval "zfs receive -e < $streamfile" 70log_mustnot eval "zfs receive -e $recvfs@snap < $streamfile" 71log_mustnot eval "zfs receive -e $recvfs/1/2/3 < $streamfile" 72log_mustnot eval "zfs receive -A -e $recvfs < $streamfile" 73log_mustnot eval "zfs receive -e -d $recvfs < $streamfile" 74 75# 76# 3. 'zfs receive -e' can receive the root dataset 77# 78recvfs_rootds="$recvfs/rootds" 79log_must zfs create "$recvfs_rootds" 80log_must eval "zfs send $poolname@full > $streamfile" 81log_must eval "zfs receive -e $recvfs_rootds < $streamfile" 82log_must datasetexists "$recvfs_rootds/$poolname" 83log_must snapexists "$recvfs_rootds/$poolname@full" 84 85# 86# 4. 'zfs receive -e' can receive a replication stream 87# 88recvfs_fs="$recvfs/fs" 89log_must zfs create "$recvfs_fs" 90log_must eval "zfs send -R $poolname/fs/a@full > $streamfile" 91log_must eval "zfs receive -e $recvfs_fs < $streamfile" 92log_must datasetexists "$recvfs_fs/a" 93log_must datasetexists "$recvfs_fs/a/b" 94log_must snapexists "$recvfs_fs/a@full" 95log_must snapexists "$recvfs_fs/a/b@full" 96 97# 98# 5. 'zfs receive -e' can receive an incremental replication stream 99# 100log_must eval "zfs send -R -i full $poolname/fs/a@incr > $streamfile" 101log_must eval "zfs receive -e $recvfs_fs < $streamfile" 102log_must snapexists "$recvfs_fs/a@incr" 103log_must snapexists "$recvfs_fs/a/b@incr" 104 105log_pass "ZFS receive '-e' discards all but the last element of the sent"\ 106 "snapshot's file system name as expected" 107