xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh (revision 48bbca816818409505a6e214d0911fda44e622e3)
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#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
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
43verify_runnable "both"
44
45function cleanup
46{
47	if datasetexists $initfs ; then
48		log_must zfs destroy -rf $initfs
49	fi
50}
51
52log_assert "Verify recursive snapshotting could not break ZFS."
53log_onexit cleanup
54
55initfs=$TESTPOOL/$TESTFS/$TESTFS
56basefs=$initfs
57typeset -i ret=0 len snaplen
58while ((ret == 0)); do
59	zfs create $basefs
60	zfs snapshot $basefs@snap1
61	ret=$?
62
63	if ((ret != 0)); then
64		len=$(echo $basefs| wc -c)
65		log_note "The deeply-nested filesystem len: $len"
66
67		#
68		# Make sure there are at lease 2 characters left
69		# for snapshot name space, otherwise snapshot name
70		# is incorrect
71		#
72		if ((len >= 255)); then
73			if datasetexists $basefs; then
74				log_must zfs destroy -r $basefs
75			fi
76			basefs=${basefs%/*}
77			len=$(echo $basefs| wc -c)
78		fi
79		break
80	fi
81
82	basefs=$basefs/$TESTFS
83done
84
85# Make snapshot name is longer than the max length
86((snaplen = 256 - len + 10))
87snap=$(gen_dataset_name $snaplen "s")
88log_mustnot zfs snapshot -r $TESTPOOL@$snap
89
90log_must datasetnonexists $TESTPOOL@$snap
91while [[ $basefs != $TESTPOOL ]]; do
92	log_must datasetnonexists $basefs@$snap
93	basefs=${basefs%/*}
94done
95
96log_pass "Verify recursive snapshotting could not break ZFS."
97