1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 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) 2020 by Delphix. All rights reserved. 16# 17 18. $STF_SUITE/include/libtest.shlib 19. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib 20 21# 22# DESCRIPTION: 23# 'zpool wait' works when waiting for devices to finish being trimmed 24# 25# STRATEGY: 26# 1. Create a pool. 27# 2. Start trimming the vdev in the pool, making sure the rate is slow enough 28# that the trim can be observed. 29# 3. Start 'zpool wait'. 30# 4. Monitor the waiting process to make sure it returns neither too soon nor 31# too late. 32# 33 34function cleanup 35{ 36 kill_if_running $pid 37 poolexists $TESTPOOL && destroy_pool $TESTPOOL 38 39 [[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR" 40} 41 42# Check whether any vdevs in given pool are being trimmed 43function trim_in_progress 44{ 45 typeset pool="$1" 46 zpool status -t "$pool" | grep "trimmed, started" 47} 48 49if is_freebsd; then 50 log_unsupported "FreeBSD has no hole punching mechanism for the time being." 51fi 52 53typeset -r FILE_VDEV="$TESTDIR/file_vdev" 54typeset pid 55 56log_onexit cleanup 57 58log_must mkdir "$TESTDIR" 59log_must truncate -s 10G "$FILE_VDEV" 60log_must zpool create -f $TESTPOOL "$FILE_VDEV" 61 62log_must zpool trim -r 2G $TESTPOOL "$FILE_VDEV" 63 64log_bkgrnd zpool wait -t trim $TESTPOOL 65pid=$! 66 67check_while_waiting $pid "trim_in_progress $TESTPOOL" 68 69log_pass "'zpool wait -t trim' works." 70