1#!/bin/ksh -p 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright (c) 2018 by Delphix. All rights reserved. 15# 16 17. $STF_SUITE/include/libtest.shlib 18. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib 19 20# 21# DESCRIPTION: 22# 'zpool wait' works when waiting for checkpoint discard to complete. 23# 24# STRATEGY: 25# 1. Create a pool. 26# 2. Add some data to the pool. 27# 3. Checkpoint the pool and delete the data so that the space is unique to the 28# checkpoint. 29# 4. Discard the checkpoint using the '-w' flag. 30# 5. Monitor the waiting process to make sure it returns neither too soon nor 31# too late. 32# 6. Repeat 2-5, but using 'zpool wait' instead of the '-w' flag. 33# 34 35function cleanup 36{ 37 log_must zinject -c all 38 poolexists $TESTPOOL && destroy_pool $TESTPOOL 39 kill_if_running $pid 40 41 [[ $default_mem_limit ]] && log_must set_tunable64 \ 42 SPA_DISCARD_MEMORY_LIMIT $default_mem_limit 43} 44 45function do_test 46{ 47 typeset use_wait_flag=$1 48 49 log_must dd if=/dev/urandom of="$TESTFILE" bs=128k count=1k 50 log_must zpool checkpoint $TESTPOOL 51 52 # Make sure bulk of space is unique to checkpoint 53 log_must rm "$TESTFILE" 54 55 log_must zinject -d $DISK1 -D20:1 $TESTPOOL 56 57 if $use_wait_flag; then 58 log_bkgrnd zpool checkpoint -dw $TESTPOOL 59 pid=$! 60 61 while ! is_pool_discarding $TESTPOOL && proc_exists $pid; do 62 log_must sleep .5 63 done 64 else 65 log_must zpool checkpoint -d $TESTPOOL 66 log_bkgrnd zpool wait -t discard $TESTPOOL 67 pid=$! 68 fi 69 70 check_while_waiting $pid "is_pool_discarding $TESTPOOL" 71 log_must zinject -c all 72} 73 74typeset -r TESTFILE="/$TESTPOOL/testfile" 75typeset pid default_mem_limit 76 77log_onexit cleanup 78 79default_mem_limit=$(get_tunable SPA_DISCARD_MEMORY_LIMIT) 80log_must set_tunable64 SPA_DISCARD_MEMORY_LIMIT 32 81 82log_must zpool create $TESTPOOL $DISK1 83 84do_test true 85do_test false 86 87log_pass "'zpool wait -t discard' and 'zpool checkpoint -dw' work." 88