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 an initialization operation is canceled. 23# 24# STRATEGY: 25# 1. Create a pool. 26# 2. Modify a tunable to make sure initializing is slow enough that it won't 27# complete before the test finishes. 28# 3. Start initializing the vdev in the pool. 29# 4. Start 'zpool wait'. 30# 5. Wait a few seconds and then check that the wait process is actually 31# waiting. 32# 6. Cancel the initialization of the device. 33# 7. Check that the wait process returns reasonably promptly. 34# 8. Repeat 3-7, except pause the initialization instead of canceling it. 35# 36 37function cleanup 38{ 39 kill_if_running $pid 40 poolexists $TESTPOOL && destroy_pool $TESTPOOL 41 42 [[ "$default_chunk_sz" ]] && 43 log_must set_tunable64 INITIALIZE_CHUNK_SIZE $default_chunk_sz 44} 45 46function do_test 47{ 48 typeset stop_cmd=$1 49 50 log_must zpool initialize $TESTPOOL $DISK1 51 52 log_bkgrnd zpool wait -t initialize $TESTPOOL 53 pid=$! 54 55 # Make sure that we are really waiting 56 log_must sleep 3 57 proc_must_exist $pid 58 59 # Stop initialization and make sure process returns 60 log_must eval "$stop_cmd" 61 bkgrnd_proc_succeeded $pid 62} 63 64typeset pid default_chunk_sz 65 66log_onexit cleanup 67 68# Make sure the initialization takes a while 69default_chunk_sz=$(get_tunable INITIALIZE_CHUNK_SIZE) 70log_must set_tunable64 INITIALIZE_CHUNK_SIZE 512 71 72log_must zpool create $TESTPOOL $DISK1 73 74do_test "zpool initialize -c $TESTPOOL $DISK1" 75do_test "zpool initialize -s $TESTPOOL $DISK1" 76 77log_pass "'zpool wait' works when initialization is stopped before completion." 78