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 https://opensource.org/licenses/CDDL-1.0.
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
44verify_runnable "both"
45
46function cleanup
47{
48	datasetexists $initfs && destroy_dataset $initfs -rf
49}
50
51log_assert "Verify long name filesystem with snapshot should not break ZFS."
52log_onexit cleanup
53
54initfs=$TESTPOOL/$TESTFS/$TESTFS
55basefs=$initfs
56typeset -i ret=0 len snaplen
57while ((ret == 0)); do
58	zfs create $basefs
59	zfs snapshot $basefs@snap1
60	ret=$?
61
62	if ((ret != 0)); then
63		len=$(( ${#basefs} + 1 )) # +1 for NUL
64		log_note "The deeply-nested filesystem len: $len"
65
66		#
67		# Make sure there are at lease 2 characters left
68		# for snapshot name space, otherwise snapshot name
69		# is incorrect
70		#
71		if ((len >= 255)); then
72			datasetexists $basefs && destroy_dataset $basefs -r
73			basefs=${basefs%/*}
74			len=$(( ${#basefs} + 1 ))
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