1# SPDX-License-Identifier: CDDL-1.0 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) 2016 by Delphix. All rights reserved. 19# Copyright (c) 2019 by Lawrence Livermore National Security, LLC. 20# 21 22function trim_prog_line # pool disk 23{ 24 typeset pool="$1" 25 typeset disk="$2" 26 zpool status -t "$pool" | grep "$disk" | grep "[[:digit:]]* trimmed" 27} 28 29function trim_progress # pool disk 30{ 31 trim_prog_line "$1" "$2" | sed 's/.*(\([0-9]\{1,\}\)% trimmed.*/\1/g' 32} 33 34# 35# Write a bit of data and sync several times. 36# 37function sync_and_rewrite_some_data_a_few_times 38{ 39 typeset pool=$1 40 typeset -i a_few_times=${2:-20} 41 42 typeset file="/$pool/tmpfile" 43 for i in {0..$a_few_times}; do 44 dd if=/dev/urandom of=${file} bs=128k count=10 45 sync_pool "$pool" 46 done 47 48 return 0 49} 50 51function cleanup 52{ 53 if poolexists $TESTPOOL; then 54 destroy_pool $TESTPOOL 55 fi 56 57 if poolexists $TESTPOOL1; then 58 destroy_pool $TESTPOOL1 59 fi 60} 61log_onexit cleanup 62