]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_snapshot / zfs_snapshot_005_neg.ksh
1 #!/bin/ksh -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
28 #
29 # Copyright (c) 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33
34 #
35 # DESCRIPTION:
36 #       Long name filesystem with snapshot should not break ZFS.
37 #
38 # STRATEGY:
39 #       1. Create filesystem and snapshot.
40 #       2. When the snapshot length is 256, rename the filesystem.
41 #       3. Verify it does not break ZFS
42 #
43
44 verify_runnable "both"
45
46 function cleanup
47 {
48         if datasetexists $initfs ; then
49                 log_must zfs destroy -rf $initfs
50         fi
51 }
52
53 log_assert "Verify long name filesystem with snapshot should not break ZFS."
54 log_onexit cleanup
55
56 initfs=$TESTPOOL/$TESTFS/$TESTFS
57 basefs=$initfs
58 typeset -i ret=0 len snaplen
59 while ((ret == 0)); do
60         zfs create $basefs
61         zfs snapshot $basefs@snap1
62         ret=$?
63
64         if ((ret != 0)); then
65                 len=$(echo $basefs | wc -c)
66                 log_note "The deeply-nested filesystem len: $len"
67
68                 #
69                 # Make sure there are at lease 2 characters left
70                 # for snapshot name space, otherwise snapshot name
71                 # is incorrect
72                 #
73                 if ((len >= 255)); then
74                         if datasetexists $basefs; then
75                                 log_must zfs destroy -r $basefs
76                         fi
77                         basefs=${basefs%/*}
78                         len=$(echo $basefs| wc -c)
79                 fi
80                 break
81         fi
82
83         basefs=$basefs/$TESTFS
84 done
85
86 # Make snapshot name length match the longest one
87 ((snaplen = 256 - len - 1)) # 1: @
88 snap=$(gen_dataset_name $snaplen "s")
89 log_must zfs snapshot $basefs@$snap
90
91 log_mustnot zfs rename $basefs ${basefs}a
92 log_mustnot zfs rename $basefs ${basefs}-new
93 log_mustnot zfs rename $initfs ${initfs}-new
94 log_mustnot zfs rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS-new
95
96 log_pass "Verify long name filesystem with snapshot should not break ZFS."