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# Trimming automatically resumes across offline/online. 28# 29# STRATEGY: 30# 1. Create a pool with a two-way mirror, prepare blocks to trim. 31# 2. Start trimming one of the disks and verify that trimming is active. 32# 3. Offline the disk. 33# 4. Online the disk. 34# 5. Verify that trimming resumes and progress does not regress. 35# 6. Suspend trimming. 36# 7. Repeat steps 3-4 and verify that trimming does not resume. 37# 38 39DISK1=${DISKS%% *} 40DISK2="$(echo $DISKS | cut -d' ' -f2)" 41 42log_must zpool create -f $TESTPOOL mirror $DISK1 $DISK2 -O recordsize=4k 43sync_and_rewrite_some_data_a_few_times $TESTPOOL 44 45log_must zpool trim -r 1 $TESTPOOL $DISK1 46 47log_must zpool offline $TESTPOOL $DISK1 48 49progress="$(trim_progress $TESTPOOL $DISK1)" 50[[ -z "$progress" ]] && log_fail "Trimming did not start" 51 52log_must zpool online $TESTPOOL $DISK1 53 54new_progress="$(trim_progress $TESTPOOL $DISK1)" 55[[ -z "$new_progress" ]] && \ 56 log_fail "Trimming did not restart after onlining" 57[[ "$progress" -le "$new_progress" ]] || \ 58 log_fail "Trimming lost progress after onlining" 59log_mustnot eval "trim_prog_line $TESTPOOL $DISK1 | grep suspended" 60 61log_must zpool trim -s $TESTPOOL $DISK1 62action_date="$(trim_prog_line $TESTPOOL $DISK1 | \ 63 sed 's/.*ed at \(.*\)).*/\1/g')" 64log_must zpool offline $TESTPOOL $DISK1 65log_must zpool online $TESTPOOL $DISK1 66new_action_date=$(trim_prog_line $TESTPOOL $DISK1 | \ 67 sed 's/.*ed at \(.*\)).*/\1/g') 68[[ "$action_date" != "$new_action_date" ]] && \ 69 log_fail "Trimming action date did not persist across offline/online" 70log_must eval "trim_prog_line $TESTPOOL $DISK1 | grep suspended" 71 72log_pass "Trimming performs as expected across offline/online" 73