12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers# $FreeBSD$
242fae26bdSAlan Somers
252fae26bdSAlan Somers#
262fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
272fae26bdSAlan Somers# Use is subject to license terms.
282fae26bdSAlan Somers#
292fae26bdSAlan Somers# ident	"@(#)zfs_rename_013_pos.ksh	1.1	09/05/19 SMI"
302fae26bdSAlan Somers#
312fae26bdSAlan Somers
322fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
332fae26bdSAlan Somers
342fae26bdSAlan Somers#################################################################################
352fae26bdSAlan Somers#
362fae26bdSAlan Somers# __stc_assertion_start
372fae26bdSAlan Somers#
382fae26bdSAlan Somers# ID: zfs_rename_013_pos
392fae26bdSAlan Somers#
402fae26bdSAlan Somers# DESCRIPTION:
412fae26bdSAlan Somers#	zfs rename -r can rename snapshot when child datasets
422fae26bdSAlan Somers#	don't have a snapshot of the given name.
432fae26bdSAlan Somers#
442fae26bdSAlan Somers# STRATEGY:
452fae26bdSAlan Somers#	1. Create snapshot.
462fae26bdSAlan Somers#	2. Rename snapshot recursively.
472fae26bdSAlan Somers#	3. Verify rename -r snapshot correctly.
482fae26bdSAlan Somers#
492fae26bdSAlan Somers# TESTABILITY: explicit
502fae26bdSAlan Somers#
512fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
522fae26bdSAlan Somers#
532fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2009-04-24)
542fae26bdSAlan Somers#
552fae26bdSAlan Somers# __stc_assertion_end
562fae26bdSAlan Somers#
572fae26bdSAlan Somers################################################################################
582fae26bdSAlan Somers
592fae26bdSAlan Somersverify_runnable "both"
602fae26bdSAlan Somers
612fae26bdSAlan Somers# Check if current system support recursive rename
622fae26bdSAlan Somers$ZFS rename 2>&1 | grep "rename -r" > /dev/null 2>&1
632fae26bdSAlan Somersif (($? != 0)); then
642fae26bdSAlan Somers	log_unsupported
652fae26bdSAlan Somersfi
662fae26bdSAlan Somers
672fae26bdSAlan Somersfunction cleanup
682fae26bdSAlan Somers{
692fae26bdSAlan Somers	if datasetexists $TESTPOOL/$TESTCTR@snap-new ; then
702fae26bdSAlan Somers		log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new
712fae26bdSAlan Somers	fi
722fae26bdSAlan Somers
732fae26bdSAlan Somers	if datasetexists $TESTPOOL/$TESTCTR@snap ; then
742fae26bdSAlan Somers		log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap
752fae26bdSAlan Somers	fi
762fae26bdSAlan Somers
772fae26bdSAlan Somers	if datasetexists $TESTPOOL@snap-new ; then
782fae26bdSAlan Somers		log_must $ZFS destroy -f $TESTPOOL@snap-new
792fae26bdSAlan Somers	fi
802fae26bdSAlan Somers
812fae26bdSAlan Somers	if datasetexists $TESTPOOL@snap ; then
822fae26bdSAlan Somers		log_must $ZFS destroy -f $TESTPOOL@snap
832fae26bdSAlan Somers	fi
842fae26bdSAlan Somers}
852fae26bdSAlan Somers
862fae26bdSAlan Somerslog_assert "zfs rename -r can rename snapshot when child datasets" \
872fae26bdSAlan Somers	"don't have a snapshot of the given name."
882fae26bdSAlan Somers
892fae26bdSAlan Somerslog_onexit cleanup
902fae26bdSAlan Somers
912fae26bdSAlan Somerslog_must $ZFS snapshot $TESTPOOL/$TESTCTR@snap
922fae26bdSAlan Somerslog_must $ZFS rename -r $TESTPOOL/$TESTCTR@snap $TESTPOOL/$TESTCTR@snap-new
932fae26bdSAlan Somerslog_must datasetexists $TESTPOOL/$TESTCTR@snap-new
942fae26bdSAlan Somers
952fae26bdSAlan Somerslog_must $ZFS snapshot $TESTPOOL@snap
962fae26bdSAlan Somerslog_must $ZFS rename -r $TESTPOOL@snap $TESTPOOL@snap-new
972fae26bdSAlan Somerslog_must datasetexists $TESTPOOL/$TESTCTR@snap-new
982fae26bdSAlan Somerslog_must datasetexists $TESTPOOL@snap-new
992fae26bdSAlan Somers
1002fae26bdSAlan Somerslog_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new
1012fae26bdSAlan Somerslog_must $ZFS destroy -f $TESTPOOL@snap-new
1022fae26bdSAlan Somers
1032fae26bdSAlan Somerslog_pass "Verify zfs rename -r passed when child datasets" \
1042fae26bdSAlan Somers	"don't have a snapshot of the given name."
1052fae26bdSAlan Somers
106