1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33 34# 35# DESCRIPTION: 36# "zfs snapshot -r" fails with invalid arguments or scenarios. 37# The invalid scenarios may include: 38# (1) The child filesystem already has snapshot with the same name 39# (2) The child volume already has snapshot with the same name 40# 41# STRATEGY: 42# 1. Create an array of invalid arguments 43# 2. Execute 'zfs snapshot -r' with each argument in the array, 44# 3. Verify an error is returned. 45# 46 47verify_runnable "both" 48 49function cleanup 50{ 51 typeset snap 52 53 for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \ 54 $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP; 55 do 56 snapexists $snap && \ 57 log_must zfs destroy $snap 58 done 59 60 datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \ 61 log_must zfs destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL 62 63} 64 65log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. " 66log_onexit cleanup 67 68set -A args "" \ 69 "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \ 70 "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \ 71 "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \ 72 "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP" 73 74# setup preparations 75log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 76 77# testing 78typeset -i i=0 79while (( i < ${#args[*]} )); do 80 log_mustnot zfs snapshot -r ${args[i]} 81 82 ((i = i + 1)) 83done 84 85# Testing the invalid senario: the child volume already has an 86# identical name snapshot, zfs snapshot -r should fail when 87# creating snapshot with -r for the parent 88log_must zfs destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 89if is_global_zone; then 90 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL 91else 92 log_must zfs create $TESTPOOL/$TESTCTR/$TESTVOL 93fi 94log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP 95 96log_mustnot zfs snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP 97 98log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected." 99