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# -w flag for 'zpool initialize' waits for the completion of all and only those 23# initializations kicked off by that invocation. 24# 25# STRATEGY: 26# 1. Create a pool with 3 disks. 27# 2. Start initializing disks 1 and 2 with one invocation of 28# 'zpool initialize -w' 29# 3. Start initializing disk 3 with a second invocation of 'zpool initialize -w' 30# 4. Cancel the initialization of disk 1. Check that neither waiting process 31# exits. 32# 5. Cancel the initialization of disk 3. Check that only the second waiting 33# process exits. 34# 6. Cancel the initialization of disk 2. Check that the first waiting process 35# exits. 36# 37 38function cleanup 39{ 40 kill_if_running $init12_pid 41 kill_if_running $init3_pid 42 poolexists $TESTPOOL && destroy_pool $TESTPOOL 43 44 [[ "$default_chunk_sz" ]] && 45 log_must set_tunable64 INITIALIZE_CHUNK_SIZE $default_chunk_sz 46} 47 48typeset init12_pid init3_pid default_chunk_sz 49 50log_onexit cleanup 51 52log_must zpool create -f $TESTPOOL $DISK1 $DISK2 $DISK3 53 54# Make sure the initialization takes a while 55default_chunk_sz=$(get_tunable INITIALIZE_CHUNK_SIZE) 56log_must set_tunable64 INITIALIZE_CHUNK_SIZE 512 57 58log_bkgrnd zpool initialize -w $TESTPOOL $DISK1 $DISK2 59init12_pid=$! 60log_bkgrnd zpool initialize -w $TESTPOOL $DISK3 61init3_pid=$! 62 63# Make sure that we are really waiting 64log_must sleep 3 65proc_must_exist $init12_pid 66proc_must_exist $init3_pid 67 68# 69# Cancel initialization of one of disks started by init12, make sure neither 70# process exits 71# 72log_must zpool initialize -c $TESTPOOL $DISK1 73proc_must_exist $init12_pid 74proc_must_exist $init3_pid 75 76# 77# Cancel initialization started by init3, make sure that process exits, but 78# init12 doesn't 79# 80log_must zpool initialize -c $TESTPOOL $DISK3 81proc_must_exist $init12_pid 82bkgrnd_proc_succeeded $init3_pid 83 84# Cancel last initialization started by init12, make sure it returns. 85log_must zpool initialize -c $TESTPOOL $DISK2 86bkgrnd_proc_succeeded $init12_pid 87 88log_pass "'zpool initialize -w' works." 89