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# Detaching/attaching, adding/removing data devices works with trimming.
28#
29# STRATEGY:
30# 1. Create a single-disk pool.
31# 2. Start trimming.
32# 3. Attach a second disk, ensure trimming continues.
33# 4. Detach the second disk, ensure trimming continues.
34# 5. Add a second disk, ensure trimming continues.
35# 6. Remove the first disk, ensure trimming stops.
36#
37
38DISK1="$(echo $DISKS | cut -d' ' -f1)"
39DISK2="$(echo $DISKS | cut -d' ' -f2)"
40
41log_must zpool create -f $TESTPOOL $DISK1
42
43log_must zpool trim -r 128M $TESTPOOL $DISK1
44progress="$(trim_progress $TESTPOOL $DISK1)"
45[[ -z "$progress" ]] && log_fail "Trim did not start"
46
47log_must zpool attach $TESTPOOL $DISK1 $DISK2
48new_progress="$(trim_progress $TESTPOOL $DISK1)"
49[[ "$progress" -le "$new_progress" ]] || \
50        log_fail "Lost trimming progress on demotion to child vdev"
51progress="$new_progress"
52
53log_must zpool detach $TESTPOOL $DISK2
54new_progress="$(trim_progress $TESTPOOL $DISK1)"
55[[ "$progress" -le "$new_progress" ]] || \
56        log_fail "Lost trimming progress on promotion to top vdev"
57progress="$new_progress"
58
59log_must zpool add $TESTPOOL $DISK2
60log_must zpool remove $TESTPOOL $DISK1
61[[ -z "$(trim_prog_line $TESTPOOL $DISK1)" ]] || \
62        log_fail "Trimming continued after initiating removal"
63
64log_pass "Trimming worked as expected across attach/detach and add/remove"
65