1#!/usr/local/bin/ksh93
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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_rename_006_pos
34#
35# DESCRIPTION:
36#       'zfs rename' can successfully rename a volume snapshot.
37#
38# STRATEGY:
39#       1. Create a snapshot of volume.
40#       2. Rename volume snapshot to a new one.
41#	3. Rename volume to a new one.
42#       5. Verify that the rename operations are successful and zfs list can
43#	   list them.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2007-02-05)
50#
51# __stc_assertion_end
52#
53###############################################################################
54
55verify_runnable "global"
56
57#
58# cleanup defined in zfs_rename.kshlib
59#
60log_onexit cleanup
61
62log_assert "'zfs rename' can successfully rename a volume snapshot."
63
64vol=$TESTPOOL/$TESTVOL
65snap=$TESTSNAP
66
67log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT >/dev/null 2>&1"
68if ! snapexists $vol@$snap; then
69	log_must $ZFS snapshot $vol@$snap
70fi
71
72rename_dataset $vol@$snap $vol@${snap}-new
73rename_dataset $vol ${vol}-new
74rename_dataset ${vol}-new@${snap}-new ${vol}-new@$snap
75rename_dataset ${vol}-new $vol
76
77#verify data integrity
78for input in $VOL_R_PATH ${VOL_R_PATH}@$snap; do
79	log_must eval "$DD if=$input of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
80	if ! cmp_data $VOLDATA $DATA ; then
81		log_fail "$input gets corrupted after rename operation."
82	fi
83done
84
85log_must $ZFS destroy $vol@$snap
86
87log_pass "'zfs rename' can rename volume snapshot as expected."
88