1#!/usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_snapshot_005_neg
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# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2007-08-09)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55log_assert "Verify long name filesystem with snapshot should not break ZFS."
56
57initfs=$TESTPOOL/$TESTFS/$TESTFS
58basefs=$initfs
59typeset -i ret=0 len snaplen
60while ((ret == 0)); do
61	$ZFS create $basefs
62	$ZFS snapshot $basefs@snap1
63	ret=$?
64
65	if ((ret != 0)); then
66		len=$($ECHO $basefs | $WC -c)
67		log_note "The deeply-nested filesystem len: $len"
68
69		#
70		# Make sure there are at lease 2 characters left
71		# for snapshot name space, otherwise snapshot name
72		# is incorrect
73		#
74		if ((len >= 255)); then
75			if datasetexists $basefs; then
76				log_must $ZFS destroy -r $basefs
77			fi
78			basefs=${basefs%/*}
79			len=$($ECHO $basefs| $WC -c)
80		fi
81		break
82	fi
83
84	basefs=$basefs/$TESTFS
85done
86
87# Make snapshot name length match the longest one
88((snaplen = 256 - len - 1)) # 1: @
89snap=$(gen_dataset_name $snaplen "s")
90log_must $ZFS snapshot $basefs@$snap
91
92log_mustnot $ZFS rename $basefs ${basefs}a
93log_mustnot $ZFS rename $basefs ${basefs}-new
94log_mustnot $ZFS rename $initfs ${initfs}-new
95log_mustnot $ZFS rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS-new
96
97log_pass "Verify long name filesystem with snapshot should not break ZFS."
98