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_004_neg
34#
35# DESCRIPTION:
36#	Verify recursive snapshotting could not break ZFS.
37#
38# STRATEGY:
39#	1. Create deeply-nested filesystems until it is too long to create snap
40#	2. Verify zfs snapshot -r pool@snap will not break ZFS
41#
42# TESTABILITY: explicit
43#
44# TEST_AUTOMATION_LEVEL: automated
45#
46# CODING_STATUS: COMPLETED (2007-08-08)
47#
48# __stc_assertion_end
49#
50################################################################################
51
52verify_runnable "both"
53
54function cleanup
55{
56	if datasetexists $initfs ; then
57		log_must $ZFS destroy -rf $initfs
58	fi
59}
60
61log_assert "Verify recursive snapshotting could not break ZFS."
62log_onexit cleanup
63
64initfs=$TESTPOOL/$TESTFS/$TESTFS
65basefs=$initfs
66typeset -i ret=0 len snaplen
67while ((ret == 0)); do
68	$ZFS create $basefs
69	$ZFS snapshot $basefs@snap1
70	ret=$?
71
72	len=$($ECHO $basefs| $WC -c)
73	if ((ret != 0)); then
74		log_note "The deeply-nested filesystem len: $len"
75		#
76		# Make sure there are at lease 2 characters left
77		# for snapshot name space, otherwise snapshot name
78		# is incorrect
79		#
80		if ((len >= 255)); then
81			if datasetexists $basefs; then
82				log_must $ZFS destroy -r $basefs
83			fi
84			basefs=${basefs%/*}
85			len=$($ECHO $basefs| $WC -c)
86		fi
87		break
88	else
89		log_note "ZFS snapshot suceeded.  len: $len"
90	fi
91
92	basefs=$basefs/$TESTFS
93done
94
95# Make snapshot name is longer than the max length
96((snaplen = 256 - len + 10))
97snap=$(gen_dataset_name $snaplen "s")
98log_mustnot $ZFS snapshot -r $TESTPOOL@$snap
99
100log_must datasetnonexists $TESTPOOL@$snap
101while [[ $basefs != $TESTPOOL ]]; do
102	log_must datasetnonexists $basefs@$snap
103	basefs=${basefs%/*}
104done
105
106log_pass "Verify recursive snapshotting could not break ZFS."
107