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 https://opensource.org/licenses/CDDL-1.0. 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 && destroy_dataset $snap 57 done 58 59 datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \ 60 destroy_dataset $TESTPOOL/$TESTCTR/$TESTVOL -rf 61 62} 63 64log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. " 65log_onexit cleanup 66 67set -A args "" \ 68 "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \ 69 "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \ 70 "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \ 71 "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP" 72 73# setup preparations 74log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 75 76# testing 77typeset -i i=0 78while (( i < ${#args[*]} )); do 79 log_mustnot zfs snapshot -r ${args[i]} 80 81 ((i = i + 1)) 82done 83 84# Testing the invalid scenario: the child volume already has an 85# identical name snapshot, zfs snapshot -r should fail when 86# creating snapshot with -r for the parent 87log_must zfs destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 88if is_global_zone; then 89 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL 90else 91 log_must zfs create $TESTPOOL/$TESTCTR/$TESTVOL 92fi 93log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP 94 95log_mustnot zfs snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP 96 97log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected." 98