xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_trim_flag.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
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
14#
15# Copyright (c) 2020 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
20
21#
22# DESCRIPTION:
23# -w flag for 'zpool trim' waits for trimming to complete for all and only those
24# vdevs kicked off by that invocation.
25#
26# STRATEGY:
27# 1. Create a pool with 3 vdevs.
28# 2. Start trimming vdevs 1 and 2 with one invocation of 'zpool trim -w'
29# 3. Start trimming vdev 3 with a second invocation of 'zpool trim -w'
30# 4. Cancel the trim of vdev 1. Check that neither waiting process exits.
31# 5. Cancel the trim of vdev 3. Check that only the second waiting process
32#    exits.
33# 6. Cancel the trim of vdev 2. Check that the first waiting process exits.
34#
35
36function cleanup
37{
38	kill_if_running $trim12_pid
39	kill_if_running $trim3_pid
40	poolexists $TESTPOOL && destroy_pool $TESTPOOL
41	[[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR"
42}
43
44if is_freebsd; then
45	log_unsupported "FreeBSD has no hole punching mechanism for the time being."
46fi
47
48typeset trim12_pid trim3_pid
49typeset -r VDEV1="$TESTDIR/file_vdev1"
50typeset -r VDEV2="$TESTDIR/file_vdev2"
51typeset -r VDEV3="$TESTDIR/file_vdev3"
52
53log_onexit cleanup
54
55log_must mkdir "$TESTDIR"
56log_must truncate -s 10G "$VDEV1" "$VDEV2" "$VDEV3"
57log_must zpool create -f $TESTPOOL "$VDEV1" "$VDEV2" "$VDEV3"
58
59log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV1" "$VDEV2"
60trim12_pid=$!
61log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV3"
62trim3_pid=$!
63
64# Make sure that we are really waiting
65log_must sleep 3
66proc_must_exist $trim12_pid
67proc_must_exist $trim3_pid
68
69#
70# Cancel trim of one of disks started by trim12, make sure neither
71# process exits
72#
73log_must zpool trim -c $TESTPOOL "$VDEV1"
74proc_must_exist $trim12_pid
75proc_must_exist $trim3_pid
76
77#
78# Cancel trim started by trim3, make sure that process exits, but
79# trim12 doesn't
80#
81log_must zpool trim -c $TESTPOOL "$VDEV3"
82proc_must_exist $trim12_pid
83bkgrnd_proc_succeeded $trim3_pid
84
85# Cancel last trim started by trim12, make sure it returns.
86log_must zpool trim -c $TESTPOOL "$VDEV2"
87bkgrnd_proc_succeeded $trim12_pid
88
89log_pass "'zpool trim -w' works."
90