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