1#!/usr/local/bin/ksh93 -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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: snapshot_016_pos
34#
35# DESCRIPTION:
36#	Verify renamed snapshots via mv can be destroyed
37#
38# STRATEGY:
39#	1. Create snapshot
40#	2. Rename the snapshot via mv command
41#	2. Verify destroying the renamed snapshot via 'zfs destroy' succeeds
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2007-01-26)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55function cleanup
56{
57	datasetexists $SNAPFS && \
58		log_must $ZFS destroy -Rf $SNAPFS
59	datasetexists $TESTPOOL/$TESTFS@snap_a && \
60		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS@snap_a
61	datasetexists $TESTPOOL/$TESTCLONE@snap_a && \
62		log_must $ZFS destroy -Rf $TESTPOOL/$TESTCLONE@snap_a
63
64	datasetexists $TESTPOOL/$TESTCLONE && \
65		log_must $ZFS destroy $TESTPOOL/$TESTCLONE
66	datasetexists $TESTPOOL/$TESTFS && \
67		log_must $ZFS destroy $TESTPOOL/$TESTFS
68
69	log_must $ZFS create $TESTPOOL/$TESTFS
70	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
71}
72
73log_assert "Verify renamed snapshots via mv can be destroyed."
74log_onexit cleanup
75
76[[ $os_name == "FreeBSD" ]] && \
77	log_uninitiated "Directory operations on the $(get_snapdir_name) directory are not yet supported in FreeBSD"
78
79# scenario 1
80
81log_must $ZFS snapshot $SNAPFS
82log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
83
84datasetexists $TESTPOOL/$TESTFS@snap_a || \
85	log_fail "rename snapshot via mv in $(get_snapdir_name) fails."
86log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
87
88# scenario 2
89
90log_must $ZFS snapshot $SNAPFS
91log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
92log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
93
94datasetexists $TESTPOOL/$TESTFS@snap_a || \
95	log_fail "rename snapshot via mv in $(get_snapdir_name) fails."
96log_must $ZFS promote $TESTPOOL/$TESTCLONE
97# promote back to $TESTPOOL/$TESTFS for scenario 3
98log_must $ZFS promote $TESTPOOL/$TESTFS
99log_must $ZFS destroy $TESTPOOL/$TESTCLONE
100log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
101
102# scenario 3
103
104log_must $ZFS snapshot $SNAPFS
105log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
106log_must $ZFS rename $SNAPFS $TESTPOOL/$TESTFS@snap_a
107log_must $ZFS promote $TESTPOOL/$TESTCLONE
108log_must $ZFS destroy $TESTPOOL/$TESTFS
109log_must $ZFS destroy $TESTPOOL/$TESTCLONE@snap_a
110
111log_pass "Verify renamed snapshots via mv can be destroyed."
112