1#!/usr/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/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
19
20#
21# DESCRIPTION:
22#	Ensure that checkpoint verification within zdb works as
23#	we expect.
24#
25# STRATEGY:
26#	1. Create pool
27#	2. Populate it
28#	3. Take checkpoint
29#	4. Modify data (include at least one destructive change)
30#	5. Verify zdb finds checkpoint when run on current state
31#	6. Verify zdb finds old dataset when run on checkpointed
32#	   state
33#	7. Export pool, and verify the same things with zdb to
34#	   test the -e option.
35#	8. Import pool and discard checkpoint
36#	9. Verify zdb does not find the checkpoint anymore in the
37#	   current state.
38#	10.Verify that zdb cannot find the checkpointed state
39#	   anymore when trying to open it for verification.
40#
41
42verify_runnable "global"
43
44#
45# zdb does this thing where it imports the checkpointed state of the
46# pool under a new pool with a different name, alongside the pool
47# with the current state. The name of this temporary pool is the
48# name of the actual pool with the suffix below appended to it.
49#
50CHECKPOINT_SUFFIX="_CHECKPOINTED_UNIVERSE"
51CHECKPOINTED_FS1=$TESTPOOL$CHECKPOINT_SUFFIX/$TESTFS1
52
53setup_test_pool
54log_onexit cleanup_test_pool
55
56populate_test_pool
57log_must zpool checkpoint $TESTPOOL
58
59test_change_state_after_checkpoint
60
61zdb $TESTPOOL | grep "Checkpointed uberblock found" || \
62	log_fail "zdb could not find checkpointed uberblock"
63
64zdb -k $TESTPOOL | grep "Checkpointed uberblock found" && \
65	log_fail "zdb found checkpointed uberblock in checkpointed state"
66
67zdb $TESTPOOL | grep "Dataset $FS1" && \
68	log_fail "zdb found destroyed dataset in current state"
69
70zdb -k $TESTPOOL | grep "Dataset $CHECKPOINTED_FS1" || \
71	log_fail "zdb could not find destroyed dataset in checkpoint"
72
73log_must zpool export $TESTPOOL
74
75zdb -e $TESTPOOL | grep "Checkpointed uberblock found" || \
76	log_fail "zdb could not find checkpointed uberblock"
77
78zdb -k -e $TESTPOOL | grep "Checkpointed uberblock found" && \
79	log_fail "zdb found checkpointed uberblock in checkpointed state"
80
81zdb -e $TESTPOOL | grep "Dataset $FS1" && \
82	log_fail "zdb found destroyed dataset in current state"
83
84zdb -k -e $TESTPOOL | grep "Dataset $CHECKPOINTED_FS1" || \
85	log_fail "zdb could not find destroyed dataset in checkpoint"
86
87log_must zpool import $TESTPOOL
88
89log_must zpool checkpoint -d $TESTPOOL
90
91zdb $TESTPOOL | grep "Checkpointed uberblock found" && \
92	log_fail "zdb found checkpointed uberblock after discarding " \
93	"the checkpoint"
94
95zdb -k $TESTPOOL && \
96	log_fail "zdb opened checkpointed state that was discarded"
97
98log_pass "zdb can analyze checkpointed pools."
99