1eda14cbcSMatt Macy#
2eda14cbcSMatt Macy# CDDL HEADER START
3eda14cbcSMatt Macy#
4eda14cbcSMatt Macy# This file and its contents are supplied under the terms of the
5eda14cbcSMatt Macy# Common Development and Distribution License ("CDDL"), version 1.0.
6eda14cbcSMatt Macy# You may only use this file in accordance with the terms of version
7eda14cbcSMatt Macy# 1.0 of the CDDL.
8eda14cbcSMatt Macy#
9eda14cbcSMatt Macy# A full copy of the text of the CDDL should have accompanied this
10eda14cbcSMatt Macy# source.  A copy of the CDDL is also available via the Internet at
11eda14cbcSMatt Macy# http://www.illumos.org/license/CDDL.
12eda14cbcSMatt Macy#
13eda14cbcSMatt Macy# CDDL HEADER END
14eda14cbcSMatt Macy#
15eda14cbcSMatt Macy
16eda14cbcSMatt Macy#
17eda14cbcSMatt Macy# Copyright (c) 2016 by Delphix. All rights reserved.
18eda14cbcSMatt Macy# Copyright (c) 2019 by Lawrence Livermore National Security, LLC.
19eda14cbcSMatt Macy#
20eda14cbcSMatt Macy
21eda14cbcSMatt Macyfunction trim_prog_line # pool disk
22eda14cbcSMatt Macy{
23eda14cbcSMatt Macy	typeset pool="$1"
24eda14cbcSMatt Macy	typeset disk="$2"
25eda14cbcSMatt Macy	zpool status -t "$pool" | grep "$disk" | grep "[[:digit:]]* trimmed"
26eda14cbcSMatt Macy}
27eda14cbcSMatt Macy
28eda14cbcSMatt Macyfunction trim_progress # pool disk
29eda14cbcSMatt Macy{
30eda14cbcSMatt Macy	trim_prog_line "$1" "$2" | sed 's/.*(\([0-9]\{1,\}\)% trimmed.*/\1/g'
31eda14cbcSMatt Macy}
32eda14cbcSMatt Macy
337877fdebSMatt Macy#
347877fdebSMatt Macy# Write a bit of data and sync several times.
357877fdebSMatt Macy#
367877fdebSMatt Macyfunction sync_and_rewrite_some_data_a_few_times
377877fdebSMatt Macy{
387877fdebSMatt Macy	typeset pool=$1
397877fdebSMatt Macy	typeset -i a_few_times=${2:-20}
407877fdebSMatt Macy
417877fdebSMatt Macy	typeset file="/$pool/tmpfile"
427877fdebSMatt Macy	for i in {0..$a_few_times}; do
437877fdebSMatt Macy		dd if=/dev/urandom of=${file} bs=128k count=10
447877fdebSMatt Macy		sync_pool "$pool"
457877fdebSMatt Macy	done
467877fdebSMatt Macy
477877fdebSMatt Macy	return 0
487877fdebSMatt Macy}
497877fdebSMatt Macy
50eda14cbcSMatt Macyfunction cleanup
51eda14cbcSMatt Macy{
52eda14cbcSMatt Macy	if poolexists $TESTPOOL; then
53eda14cbcSMatt Macy		destroy_pool $TESTPOOL
54eda14cbcSMatt Macy	fi
55eda14cbcSMatt Macy
56eda14cbcSMatt Macy	if poolexists $TESTPOOL1; then
57eda14cbcSMatt Macy		destroy_pool $TESTPOOL1
58eda14cbcSMatt Macy	fi
59eda14cbcSMatt Macy}
60eda14cbcSMatt Macylog_onexit cleanup
61