xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh (revision 856f710c9dc323b39da5935194d7928ffb99b67f)
1#!/bin/ksh
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#
27
28#
29# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
30#
31. $STF_SUITE/include/libtest.shlib
32. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
33
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#       4. Create a clone of the snapshot.
43#       5. Verify that the rename operations are successful and zfs list can
44#	   list them.
45#
46###############################################################################
47
48verify_runnable "global"
49
50#
51# cleanup defined in zfs_rename.kshlib
52#
53log_onexit cleanup
54
55log_assert "'zfs rename' can successfully rename a volume snapshot."
56
57vol=$TESTPOOL/$TESTVOL
58snap=$TESTSNAP
59
60log_must eval "dd if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT >/dev/null 2>&1"
61if ! snapexists $vol@$snap; then
62	log_must zfs snapshot $vol@$snap
63fi
64
65rename_dataset $vol@$snap $vol@${snap}-new
66rename_dataset $vol ${vol}-new
67rename_dataset ${vol}-new@${snap}-new ${vol}-new@$snap
68rename_dataset ${vol}-new $vol
69
70clone=$TESTPOOL/${snap}_clone
71create_clone $vol@$snap $clone
72
73#verify data integrity
74for input in $VOL_R_PATH /dev/zvol/rdsk/$clone; do
75	log_must eval "dd if=$input of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
76	if ! cmp_data $VOLDATA $DATA ; then
77		log_fail "$input gets corrupted after rename operation."
78	fi
79done
80
81destroy_clone $clone
82log_must zfs destroy $vol@$snap
83
84log_pass "'zfs rename' can rename volume snapshot as expected."
85