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