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