1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17# 18# Copyright (c) 2019 by Tim Chase. All rights reserved. 19# Copyright (c) 2019 Lawrence Livermore National Security, LLC. 20# 21 22. $STF_SUITE/include/libtest.shlib 23. $STF_SUITE/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib 24 25# 26# DESCRIPTION: 27# Verify 'zpool trim -r <rate>' rate limiting. 28# 29# STRATEGY: 30# 1. Create a pool on a single disk. 31# 2. Manually TRIM the pool with rate limiting. 32# 3. Verify the TRIM can be suspended. 33# 4. Restart the TRIM and verify the rate is preserved. 34# 35# NOTE: The tolerances and delays used in the test below are intentionally 36# set be to fairly large since we are capping the maximum trim rate. The 37# actual trim rate can be lower. The critical thing is that the trim rate 38# is limited, the rate is preserved when resuming, and it can be changed. 39# 40 41function cleanup 42{ 43 if poolexists $TESTPOOL; then 44 destroy_pool $TESTPOOL 45 fi 46 47 if [[ -d "$TESTDIR" ]]; then 48 rm -rf "$TESTDIR" 49 fi 50} 51log_onexit cleanup 52 53LARGEFILE="$TESTDIR/largefile" 54 55log_must mkdir "$TESTDIR" 56log_must truncate -s 10G "$LARGEFILE" 57log_must zpool create -f $TESTPOOL "$LARGEFILE" 58 59# Start trimming at 200M/s for 5 seconds (approximately 10% of the pool) 60log_must zpool trim -r 200M $TESTPOOL 61log_must sleep 4 62progress=$(trim_progress $TESTPOOL $LARGEFILE) 63log_must zpool trim -s $TESTPOOL 64log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended" 65log_must within_tolerance 10 $progress 5 66 67# Resuming trimming at 200M/s for 5 seconds (approximately 20% of the pool) 68log_must zpool trim $TESTPOOL 69log_must sleep 4 70progress=$(trim_progress $TESTPOOL $LARGEFILE) 71log_must zpool trim -s $TESTPOOL 72log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended" 73log_must within_tolerance 20 $progress 10 74 75# Increase trimming to 600M/s for 5 seconds (approximately 50% of the pool) 76log_must zpool trim -r 600M $TESTPOOL 77log_must sleep 4 78progress=$(trim_progress $TESTPOOL $LARGEFILE) 79log_must zpool trim -s $TESTPOOL 80log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended" 81log_must within_tolerance 50 $progress 15 82 83# Set maximum trim rate for 5 seconds (100% of the pool) 84log_must zpool trim -r 1T $TESTPOOL 85log_must sleep 4 86progress=$(trim_progress $TESTPOOL $LARGEFILE) 87log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep complete" 88log_must within_tolerance 100 $progress 0 89 90log_pass "Manual TRIM rate throttles as expected" 91