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