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# 66mdb_ctf_set_int zfs_spa_discard_memory_limit 0t128 67 68log_must zpool checkpoint $NESTEDPOOL 69 70fragment_after_checkpoint_and_verify 71 72log_must zpool checkpoint -d $NESTEDPOOL 73 74log_must zpool export $NESTEDPOOL 75 76# 77# Verify on-disk state while pool is exported 78# 79log_must zdb -e -p $FILEDISKDIR $NESTEDPOOL 80 81# 82# Attempt to rewind on a pool that is discarding 83# a checkpoint. 84# 85log_mustnot zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL 86 87log_must zpool import -d $FILEDISKDIR $NESTEDPOOL 88 89# 90# Discarding should continue after import, so 91# all the following operations should fail. 92# 93log_mustnot zpool checkpoint $NESTEDPOOL 94log_mustnot zpool checkpoint -d $NESTEDPOOL 95log_mustnot zpool remove $NESTEDPOOL $FILEDISK1 96log_mustnot zpool reguid $NESTEDPOOL 97 98# reset memory limit to 16M 99mdb_ctf_set_int zfs_spa_discard_memory_limit 1000000 100 101nested_wait_discard_finish 102 103log_must zdb $NESTEDPOOL 104 105log_pass "Can export/import but not rewind/checkpoint/discard or " \ 106 "change pool's config while discarding." 107