xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_discard_busy.ksh (revision 4e8d558c9d1cf3e7e424e3fb123b01979c3d57f2)
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, 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
41log_unsupported "Skipping, issue https://github.com/openzfs/zfs/issues/12053"
42
43function test_cleanup
44{
45	# reset memory limit to 16M
46	set_tunable64 SPA_DISCARD_MEMORY_LIMIT 1000000
47	cleanup_nested_pools
48}
49
50setup_nested_pool_state
51log_onexit test_cleanup
52
53#
54# Force discard to happen slower so it spans over
55# multiple txgs.
56#
57# Set memory limit to 128 bytes. Assuming that we
58# use 64-bit words for encoding space map entries,
59# ZFS will discard 8 non-debug entries per txg
60# (so at most 16 space map entries in debug-builds
61# due to debug entries).
62#
63# That should give us more than enough txgs to be
64# discarding the checkpoint for a long time as with
65# the current setup the checkpoint space maps should
66# have tens of thousands of entries.
67#
68# Note: If two-words entries are used in the space
69#	map, we should have even more time to
70#	verify this.
71#
72set_tunable64 SPA_DISCARD_MEMORY_LIMIT 128
73
74log_must zpool checkpoint $NESTEDPOOL
75
76fragment_after_checkpoint_and_verify
77
78log_must zpool checkpoint -d $NESTEDPOOL
79
80log_must zpool export $NESTEDPOOL
81
82#
83# Verify on-disk state while pool is exported
84#
85log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
86
87#
88# Attempt to rewind on a pool that is discarding
89# a checkpoint.
90#
91log_mustnot zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
92
93log_must zpool import -d $FILEDISKDIR $NESTEDPOOL
94
95#
96# Discarding should continue after import, so
97# all the following operations should fail.
98#
99log_mustnot zpool checkpoint $NESTEDPOOL
100log_mustnot zpool checkpoint -d $NESTEDPOOL
101log_mustnot zpool remove $NESTEDPOOL $FILEDISK1
102log_mustnot zpool reguid $NESTEDPOOL
103
104# reset memory limit to 16M
105set_tunable64 SPA_DISCARD_MEMORY_LIMIT 16777216
106
107nested_wait_discard_finish
108
109log_must zpool export $NESTEDPOOL
110log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
111
112log_pass "Can export/import but not rewind/checkpoint/discard or " \
113    "change pool's config while discarding."
114