1#!/bin/ksh -p
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2017 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# DESCRIPTION:
22#	When a snapshot is destroyed, we used to recurse all clones
23#	that are downstream of the destroyed snapshot (e.g. to remove
24#	its key and merge its deadlist entries to the previous one).
25#	This recursion would break the stack on deeply nested clone
26#	hierarchies. To avoid this problem today, we keep heap-allocated
27#	records of all the clones as we traverse their hierarchy.
28#
29#	This test ensures and showcases that our new method works with
30#	deeply nested clone hierarchies.
31#
32# STRATEGY:
33#	1. Create an fs and take a snapshot of it (snapshot foo)
34#	2. Take a second snapshot of the same fs (snapshot bar) on
35#	   top of snapshot foo
36#	3. Create a clone of snapshot bar and then take a snapshot
37#	   of it.
38#	4. Create a clone of the newly-created snapshot and then
39#	   take a snapshot of it.
40#	5. Repeat step [4] many times to create a deeply nested hierarchy.
41#	6. Destroy snapshot foo.
42#
43
44verify_runnable "both"
45
46typeset FS0=$TESTPOOL/0
47typeset FOO=foo
48typeset BAR=BAR
49
50typeset FS0SNAPFOO=$FS0@$FOO
51typeset FS0SNAPBAR=$FS0@$BAR
52
53typeset -i numds=300
54
55log_must zfs create $FS0
56
57function test_cleanup
58{
59	log_must zfs destroy -Rf $FS0
60
61	return 0
62}
63
64log_must zfs snapshot $FS0SNAPFOO
65log_must zfs snapshot $FS0SNAPBAR
66
67log_onexit test_cleanup
68
69for (( i=1; i<numds; i++ )); do
70	log_must zfs clone $TESTPOOL/$((i-1))@$BAR $TESTPOOL/$i
71	log_must zfs snapshot $TESTPOOL/$i@$BAR
72done
73
74log_must zfs destroy $FS0SNAPFOO
75
76log_pass "Snapshot deletion doesn't break the stack in deeply nested " \
77    "clone hierarchies."
78