xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_discard_busy.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14
15#
16# Copyright (c) 2017, 2018 by Delphix. All rights reserved.
17#
18
19. $STF_SUITE/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
20
21#
22# DESCRIPTION:
23#	Discard checkpoint on a stressed pool. Ensure that we can
24#	export and import the pool while discarding but not run any
25#	operations that have to do with the checkpoint or change the
26#	pool's config.
27#
28# STRATEGY:
29#	1. Import pools that's slightly fragmented
30#	2. Take checkpoint
31#	3. Do more random writes to "free" checkpointed blocks
32#	4. Start discarding checkpoint
33#	5. Export pool while discarding checkpoint
34#	6. Attempt to rewind (should fail)
35#	7. Import pool and ensure that discard is still running
36#	8. Attempt to run checkpoint commands, or commands that
37#	   change the pool's config (should fail)
38#
39
40verify_runnable "global"
41
42log_unsupported "Skipping, issue https://github.com/openzfs/zfs/issues/12053"
43
44function test_cleanup
45{
46	# reset to original value
47	log_must restore_tunable SPA_DISCARD_MEMORY_LIMIT
48	cleanup_nested_pools
49}
50
51setup_nested_pool_state
52log_onexit test_cleanup
53
54#
55# Force discard to happen slower so it spans over
56# multiple txgs.
57#
58# Set memory limit to 128 bytes. Assuming that we
59# use 64-bit words for encoding space map entries,
60# ZFS will discard 8 non-debug entries per txg
61# (so at most 16 space map entries in debug-builds
62# due to debug entries).
63#
64# That should give us more than enough txgs to be
65# discarding the checkpoint for a long time as with
66# the current setup the checkpoint space maps should
67# have tens of thousands of entries.
68#
69# Note: If two-words entries are used in the space
70#	map, we should have even more time to
71#	verify this.
72#
73log_must save_tunable SPA_DISCARD_MEMORY_LIMIT
74set_tunable64 SPA_DISCARD_MEMORY_LIMIT 128
75
76log_must zpool checkpoint $NESTEDPOOL
77
78fragment_after_checkpoint_and_verify
79
80log_must zpool checkpoint -d $NESTEDPOOL
81
82log_must zpool export $NESTEDPOOL
83
84#
85# Verify on-disk state while pool is exported
86#
87log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
88
89#
90# Attempt to rewind on a pool that is discarding
91# a checkpoint.
92#
93log_mustnot zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
94
95log_must zpool import -d $FILEDISKDIR $NESTEDPOOL
96
97#
98# Discarding should continue after import, so
99# all the following operations should fail.
100#
101log_mustnot zpool checkpoint $NESTEDPOOL
102log_mustnot zpool checkpoint -d $NESTEDPOOL
103log_mustnot zpool remove $NESTEDPOOL $FILEDISK1
104log_mustnot zpool reguid $NESTEDPOOL
105
106# reset to original value
107log_must restore_tunable SPA_DISCARD_MEMORY_LIMIT
108
109nested_wait_discard_finish
110
111log_must zpool export $NESTEDPOOL
112log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
113
114log_pass "Can export/import but not rewind/checkpoint/discard or " \
115    "change pool's config while discarding."
116