1d583b39bSJohn Wren Kennedy# !/bin/ksh 2d583b39bSJohn Wren Kennedy# 3d583b39bSJohn Wren Kennedy# This file and its contents are supplied under the terms of the 4d583b39bSJohn Wren Kennedy# Common Development and Distribution License ("CDDL"), version 1.0. 5d583b39bSJohn Wren Kennedy# You may only use this file in accordance with the terms of version 6d583b39bSJohn Wren Kennedy# 1.0 of the CDDL. 7d583b39bSJohn Wren Kennedy# 8d583b39bSJohn Wren Kennedy# A full copy of the text of the CDDL should have accompanied this 9d583b39bSJohn Wren Kennedy# source. A copy of the CDDL is also available via the Internet at 10d583b39bSJohn Wren Kennedy# http://www.illumos.org/license/CDDL. 11d583b39bSJohn Wren Kennedy# 12d583b39bSJohn Wren Kennedy 13d583b39bSJohn Wren Kennedy# 14*1d32ba66SJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 15d583b39bSJohn Wren Kennedy# 16d583b39bSJohn Wren Kennedy 17d583b39bSJohn Wren Kennedy# DESCRIPTION 18d583b39bSJohn Wren Kennedy# Verify zfs destroy test for range of snapshots by giving a list 19d583b39bSJohn Wren Kennedy# of valid and invalid arguments. 20d583b39bSJohn Wren Kennedy 21d583b39bSJohn Wren Kennedy# STRATEGY 22d583b39bSJohn Wren Kennedy# 1. Create a list of valid and invalid arguments for range snapshot 23d583b39bSJohn Wren Kennedy# destroy. 24d583b39bSJohn Wren Kennedy# 2. Set up a filesystem and a volume with multiple snapshots 25d583b39bSJohn Wren Kennedy# 3. Run zfs destroy for all the arguments and verify existence of snapshots 26d583b39bSJohn Wren Kennedy# 4. Verify the destroy for snapshots with clones and hold 27d583b39bSJohn Wren Kennedy 28d583b39bSJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 29d583b39bSJohn Wren Kennedy 30d583b39bSJohn Wren Kennedyfunction cleanup 31d583b39bSJohn Wren Kennedy{ 32d583b39bSJohn Wren Kennedy datasetexists $TESTPOOL/$TESTFS1 && \ 33*1d32ba66SJohn Wren Kennedy log_must zfs destroy -R $TESTPOOL/$TESTFS1 34d583b39bSJohn Wren Kennedy datasetexists $TESTPOOL/$TESTVOL && \ 35*1d32ba66SJohn Wren Kennedy log_must zfs destroy -Rf $TESTPOOL/$TESTVOL 36d583b39bSJohn Wren Kennedy} 37d583b39bSJohn Wren Kennedy 38d583b39bSJohn Wren Kennedyfunction setup_snapshots 39d583b39bSJohn Wren Kennedy{ 40d583b39bSJohn Wren Kennedy for i in $snaps; do 41d583b39bSJohn Wren Kennedy datasetexists $TESTPOOL/$TESTFS1@snap$i && \ 42*1d32ba66SJohn Wren Kennedy log_must zfs destroy $TESTPOOL/$TESTFS1@snap$i 43d583b39bSJohn Wren Kennedy datasetexists $TESTPOOL/$TESTVOL@snap$i && \ 44*1d32ba66SJohn Wren Kennedy log_must zfs destroy $TESTPOOL/$TESTVOL@snap$i 45*1d32ba66SJohn Wren Kennedy log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i 46*1d32ba66SJohn Wren Kennedy log_must zfs snapshot $TESTPOOL/$TESTVOL@snap$i 47d583b39bSJohn Wren Kennedy done 48d583b39bSJohn Wren Kennedy} 49d583b39bSJohn Wren Kennedy 50d583b39bSJohn Wren Kennedyfunction verify_snapshots 51d583b39bSJohn Wren Kennedy{ 52d583b39bSJohn Wren Kennedy typeset snap_exists=${1:-0} 53d583b39bSJohn Wren Kennedy if [[ $snap_exists == 1 ]]; then 54d583b39bSJohn Wren Kennedy for i in $range; do 55d583b39bSJohn Wren Kennedy snapexists $TESTPOOL/$TESTFS1@snap$i || \ 56d583b39bSJohn Wren Kennedy log_fail "zfs destroy should not have destroyed" \ 57d583b39bSJohn Wren Kennedy "$TESTPOOL/$TESTFS1@snap$i" 58d583b39bSJohn Wren Kennedy snapexists $TESTPOOL/$TESTVOL@snap$i || \ 59d583b39bSJohn Wren Kennedy log_fail "zfs destroy should not have destroyed" \ 60d583b39bSJohn Wren Kennedy "$TESTPOOL/$TESTVOL@snap$i" 61d583b39bSJohn Wren Kennedy done 62d583b39bSJohn Wren Kennedy else 63d583b39bSJohn Wren Kennedy for i in $range; do 64d583b39bSJohn Wren Kennedy snapexists $TESTPOOL/$TESTFS1@snap$i && \ 65d583b39bSJohn Wren Kennedy log_fail "zfs destroy should have destroyed" \ 66d583b39bSJohn Wren Kennedy "$TESTPOOL/$TESTFS1@snap$i" 67d583b39bSJohn Wren Kennedy snapexists $TESTPOOL/$TESTVOL@snap$i && \ 68d583b39bSJohn Wren Kennedy log_fail "zfs destroy should have destroyed" \ 69d583b39bSJohn Wren Kennedy "$TESTPOOL/$TESTVOL@snap$i" 70d583b39bSJohn Wren Kennedy done 71d583b39bSJohn Wren Kennedy fi 72d583b39bSJohn Wren Kennedy} 73d583b39bSJohn Wren Kennedy 74d583b39bSJohn Wren Kennedyinvalid_args="@snap0%snap5 @snap1%snap6 @snap0%snap6 @snap5%snap1 \ 75d583b39bSJohn Wren Kennedy @snap1%$TESTPOOL/$TESTFS1@snap5 @snap1%%snap5 @snap1%@snap5 \ 76d583b39bSJohn Wren Kennedy @@snap1%snap5 snap1%snap5 snap1%snap3%snap5" 77d583b39bSJohn Wren Kennedyvalid_args="@snap1%snap5 @%" 78d583b39bSJohn Wren Kennedylog_assert "zfs destroy deletes ranges of snapshots" 79d583b39bSJohn Wren Kennedylog_onexit cleanup 80d583b39bSJohn Wren Kennedy 81*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1 82*1d32ba66SJohn Wren Kennedylog_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL 83d583b39bSJohn Wren Kennedysnaps="1 2 3 4 5" 84d583b39bSJohn Wren Kennedylog_note "Verify the valid arguments" 85d583b39bSJohn Wren Kennedyrange="1 2 3 4 5" 86d583b39bSJohn Wren Kennedyfor args in $valid_args; do 87d583b39bSJohn Wren Kennedy setup_snapshots 88*1d32ba66SJohn Wren Kennedy log_must zfs destroy $TESTPOOL/$TESTFS1$args 89*1d32ba66SJohn Wren Kennedy log_must zfs destroy $TESTPOOL/$TESTVOL$args 90d583b39bSJohn Wren Kennedy verify_snapshots 91d583b39bSJohn Wren Kennedydone 92d583b39bSJohn Wren Kennedy 93d583b39bSJohn Wren Kennedylog_note "Verify invalid arguements" 94d583b39bSJohn Wren Kennedysetup_snapshots 95d583b39bSJohn Wren Kennedyfor args in $invalid_args; do 96*1d32ba66SJohn Wren Kennedy log_mustnot zfs destroy $TESTPOOL/$TESTFS1$args 97*1d32ba66SJohn Wren Kennedy log_mustnot zfs destroy $TESTPOOL/$TESTVOL$args 98d583b39bSJohn Wren Kennedy log_must verify_snapshots 1 99d583b39bSJohn Wren Kennedydone 100d583b39bSJohn Wren Kennedy 101d583b39bSJohn Wren Kennedylog_note "Destroy the begining range" 102d583b39bSJohn Wren Kennedy 103*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@%snap3 104*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@%snap3 105d583b39bSJohn Wren Kennedyrange="1 2 3" 106d583b39bSJohn Wren Kennedyverify_snapshots 107d583b39bSJohn Wren Kennedyrange="4 5" 108d583b39bSJohn Wren Kennedyverify_snapshots 1 109d583b39bSJohn Wren Kennedy 110d583b39bSJohn Wren Kennedysetup_snapshots 111d583b39bSJohn Wren Kennedylog_note "Destroy the mid range" 112*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap2%snap4 113*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap2%snap4 114d583b39bSJohn Wren Kennedyrange="2 3 4" 115d583b39bSJohn Wren Kennedyverify_snapshots 116*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 117*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 118d583b39bSJohn Wren Kennedyrange="1 5" 119d583b39bSJohn Wren Kennedyverify_snapshots 120d583b39bSJohn Wren Kennedy 121d583b39bSJohn Wren Kennedysetup_snapshots 122d583b39bSJohn Wren Kennedylog_note "Destroy the end range" 123*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap3% 124*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap3% 125d583b39bSJohn Wren Kennedyrange="1 2" 126d583b39bSJohn Wren Kennedyverify_snapshots 1 127d583b39bSJohn Wren Kennedyrange="3 4 5" 128d583b39bSJohn Wren Kennedyverify_snapshots 129d583b39bSJohn Wren Kennedy 130d583b39bSJohn Wren Kennedysetup_snapshots 131d583b39bSJohn Wren Kennedylog_note "Destroy a simple list" 132*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap2,snap4 133*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap2,snap4 134d583b39bSJohn Wren Kennedyrange="2 4" 135d583b39bSJohn Wren Kennedyverify_snapshots 136d583b39bSJohn Wren Kennedyrange="1 3 5" 137d583b39bSJohn Wren Kennedyverify_snapshots 1 138d583b39bSJohn Wren Kennedy 139d583b39bSJohn Wren Kennedysetup_snapshots 140d583b39bSJohn Wren Kennedylog_note "Destroy a list and range together" 141*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5 142*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5 143d583b39bSJohn Wren Kennedyrange="1 2 3 5" 144d583b39bSJohn Wren Kennedyverify_snapshots 145d583b39bSJohn Wren Kennedyrange=4 146d583b39bSJohn Wren Kennedyverify_snapshots 1 147d583b39bSJohn Wren Kennedy 148d583b39bSJohn Wren Kennedysnaps="1 2 3 5 6 7 8 9 10" 149d583b39bSJohn Wren Kennedysetup_snapshots 150d583b39bSJohn Wren Kennedylog_note "Destroy a list of ranges" 151*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5 152*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5 153d583b39bSJohn Wren Kennedyrange="1 2 3 5" 154d583b39bSJohn Wren Kennedyverify_snapshots 155d583b39bSJohn Wren Kennedyrange=4 156d583b39bSJohn Wren Kennedyverify_snapshots 1 157d583b39bSJohn Wren Kennedy 158d583b39bSJohn Wren Kennedysnaps="1 2 3 4 5" 159d583b39bSJohn Wren Kennedysetup_snapshots 160d583b39bSJohn Wren Kennedylog_note "Snapshot destory with hold" 161d583b39bSJohn Wren Kennedyrange="1 2 3 4 5" 162d583b39bSJohn Wren Kennedyfor i in 1 2 3 4 5; do 163*1d32ba66SJohn Wren Kennedy log_must zfs hold keep $TESTPOOL/$TESTFS1@snap$i 164*1d32ba66SJohn Wren Kennedy log_must zfs hold keep $TESTPOOL/$TESTVOL@snap$i 165d583b39bSJohn Wren Kennedydone 166*1d32ba66SJohn Wren Kennedylog_mustnot zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 167*1d32ba66SJohn Wren Kennedylog_mustnot zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 168d583b39bSJohn Wren Kennedyverify_snapshots 1 169d583b39bSJohn Wren Kennedyfor i in 1 2 3 4 5; do 170*1d32ba66SJohn Wren Kennedy log_must zfs release keep $TESTPOOL/$TESTFS1@snap$i 171*1d32ba66SJohn Wren Kennedy log_must zfs release keep $TESTPOOL/$TESTVOL@snap$i 172d583b39bSJohn Wren Kennedydone 173*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 174*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 175d583b39bSJohn Wren Kennedyverify_snapshots 176d583b39bSJohn Wren Kennedy 177d583b39bSJohn Wren Kennedylog_note "Range destroy for snapshots having clones" 178d583b39bSJohn Wren Kennedysetup_snapshots 179d583b39bSJohn Wren Kennedyfor i in 1 2 3 4 5; do 180*1d32ba66SJohn Wren Kennedy log_must zfs clone $TESTPOOL/$TESTFS1@snap$i $TESTPOOL/$TESTFS1/clone$i 181d583b39bSJohn Wren Kennedydone 182*1d32ba66SJohn Wren Kennedylog_must zfs destroy -R $TESTPOOL/$TESTFS1@snap1%snap5 183*1d32ba66SJohn Wren Kennedylog_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 184d583b39bSJohn Wren Kennedyverify_snapshots 185d583b39bSJohn Wren Kennedy 186d583b39bSJohn Wren Kennedylog_pass "'zfs destroy' successfully destroys ranges of snapshots" 187