]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_006_pos.ksh
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
48 verify_runnable "global"
49
50 #
51 # cleanup defined in zfs_rename.kshlib
52 #
53 log_onexit cleanup
54
55 log_assert "'zfs rename' can successfully rename a volume snapshot."
56
57 vol=$TESTPOOL/$TESTVOL
58 snap=$TESTSNAP
59
60 log_must eval "dd if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT >/dev/null 2>&1"
61 if ! snapexists $vol@$snap; then
62         log_must zfs snapshot $vol@$snap
63 fi
64
65 rename_dataset $vol@$snap $vol@${snap}-new
66 rename_dataset $vol ${vol}-new
67 rename_dataset ${vol}-new@${snap}-new ${vol}-new@$snap
68 rename_dataset ${vol}-new $vol
69
70 clone=$TESTPOOL/${snap}_clone
71 create_clone $vol@$snap $clone
72 block_device_wait
73
74 #verify data integrity
75 for input in $VOL_R_PATH $ZVOL_RDEVDIR/$clone; do
76         log_must eval "dd if=$input of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
77         if ! cmp_data $VOLDATA $DATA ; then
78                 log_fail "$input gets corrupted after rename operation."
79         fi
80 done
81
82 destroy_clone $clone
83 log_must zfs destroy $vol@$snap
84
85 log_pass "'zfs rename' can rename volume snapshot as expected."