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