xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/pool_checkpoint/checkpoint_discard_busy.ksh (revision 77c6489aa82fd0cbcd71cb2714a2b72e6154378d)
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, 2018 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
19
20#
21# DESCRIPTION:
22#	Discard checkpoint on a stressed pool. Ensure that we can
23#	export and import the pool while discarding but not run any
24#	operations that have to do with the checkpoint or change the
25#	pool's config.
26#
27# STRATEGY:
28#	1. Import pools that's slightly fragmented
29#	2. Take checkpoint
30#	3. Do more random writes to "free" checkpointed blocks
31#	4. Start discarding checkpoint
32#	5. Export pool while discarding checkpoint
33#	6. Attempt to rewind (should fail)
34#	7. Import pool and ensure that discard is still running
35#	8. Attempt to run checkpoint commands, or commands that
36#	   change the pool's config (should fail)
37#
38
39verify_runnable "global"
40
41function test_cleanup
42{
43	# reset memory limit to 16M
44	mdb_ctf_set_int zfs_spa_discard_memory_limit 1000000
45	cleanup_nested_pools
46}
47
48setup_nested_pool_state
49log_onexit test_cleanup
50
51#
52# Force discard to happen slower so it spans over
53# multiple txgs.
54#
55# Set memory limit to 128 bytes. Assuming that we
56# use 64-bit words for encoding space map entries,
57# ZFS will discard 8 non-debug entries per txg
58# (so at most 16 space map entries in debug-builds
59# due to debug entries).
60#
61# That should give us more than enough txgs to be
62# discarding the checkpoint for a long time as with
63# the current setup the checkpoint space maps should
64# have tens of thousands of entries.
65#
66# Note: If two-words entries are used in the space
67#	map, we should have even more time to
68#	verify this.
69#
70mdb_ctf_set_int zfs_spa_discard_memory_limit 0t128
71
72log_must zpool checkpoint $NESTEDPOOL
73
74fragment_after_checkpoint_and_verify
75
76log_must zpool checkpoint -d $NESTEDPOOL
77
78log_must zpool export $NESTEDPOOL
79
80#
81# Verify on-disk state while pool is exported
82#
83log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
84
85#
86# Attempt to rewind on a pool that is discarding
87# a checkpoint.
88#
89log_mustnot zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
90
91log_must zpool import -d $FILEDISKDIR $NESTEDPOOL
92
93#
94# Discarding should continue after import, so
95# all the following operations should fail.
96#
97log_mustnot zpool checkpoint $NESTEDPOOL
98log_mustnot zpool checkpoint -d $NESTEDPOOL
99log_mustnot zpool remove $NESTEDPOOL $FILEDISK1
100log_mustnot zpool reguid $NESTEDPOOL
101
102# reset memory limit to 16M
103mdb_ctf_set_int zfs_spa_discard_memory_limit 1000000
104
105nested_wait_discard_finish
106
107log_must zpool export $NESTEDPOOL
108log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
109
110log_pass "Can export/import but not rewind/checkpoint/discard or " \
111    "change pool's config while discarding."
112