1#!/bin/ksh -p 2 3# 4# CDDL HEADER START 5# 6# This file and its contents are supplied under the terms of the 7# Common Development and Distribution License ("CDDL"), version 1.0. 8# You may only use this file in accordance with the terms of version 9# 1.0 of the CDDL. 10# 11# A full copy of the text of the CDDL should have accompanied this 12# source. A copy of the CDDL is also available via the Internet at 13# http://www.illumos.org/license/CDDL. 14# 15# CDDL HEADER END 16# 17 18# 19# Copyright (c) 2019, Datto Inc. All rights reserved. 20# Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 21# 22 23. $STF_SUITE/include/libtest.shlib 24. $STF_SUITE/tests/functional/replacement/replacement.cfg 25 26# 27# DESCRIPTION: 28# Verify scrub behaves as intended when contending with a healing or 29# sequential resilver. 30# 31# STRATEGY: 32# 1. Create a pool 33# 2. Add a modest amount of data to the pool. 34# 3. For healing and sequential resilver: 35# a. Start scrubbing. 36# b. Verify a resilver can be started and it cancels the scrub. 37# c. Verify a scrub cannot be started when resilvering 38# 39 40function cleanup 41{ 42 log_must set_tunable32 RESILVER_MIN_TIME_MS $ORIG_RESILVER_MIN_TIME 43 log_must set_tunable32 SCAN_SUSPEND_PROGRESS \ 44 $ORIG_SCAN_SUSPEND_PROGRESS 45 destroy_pool $TESTPOOL1 46 rm -f ${VDEV_FILES[@]} $SPARE_VDEV_FILE 47} 48 49log_assert "Scrub was cancelled by resilver" 50 51ORIG_RESILVER_MIN_TIME=$(get_tunable RESILVER_MIN_TIME_MS) 52ORIG_SCAN_SUSPEND_PROGRESS=$(get_tunable SCAN_SUSPEND_PROGRESS) 53 54log_onexit cleanup 55 56log_must truncate -s $VDEV_FILE_SIZE ${VDEV_FILES[@]} $SPARE_VDEV_FILE 57 58log_must zpool create -f $TESTPOOL1 ${VDEV_FILES[@]} 59log_must zfs create $TESTPOOL1/$TESTFS 60 61mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS) 62log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=64 63sync_pool $TESTPOOL1 64 65# Request a healing or sequential resilver 66for replace_mode in "healing" "sequential"; do 67 68 # 69 # Healing resilvers abort the dsl_scan and reconfigure it for 70 # resilvering. Sequential resilvers cancel the dsl_scan and start 71 # the vdev_rebuild thread. 72 # 73 if [[ "$replace_mode" = "healing" ]]; then 74 history_msg="scan aborted, restarting" 75 flags="" 76 else 77 history_msg="scan cancelled" 78 flags="-s" 79 fi 80 81 # Limit scanning time and suspend the scan as soon as possible. 82 log_must set_tunable32 RESILVER_MIN_TIME_MS 50 83 log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1 84 85 # Initiate a scrub. 86 log_must zpool scrub $TESTPOOL1 87 88 # Initiate a resilver to cancel the scrub. 89 log_must zpool replace $flags $TESTPOOL1 ${VDEV_FILES[1]} \ 90 $SPARE_VDEV_FILE 91 92 # Verify the scrub was canceled, it may take a few seconds to exit. 93 while is_pool_scrubbing $TESTPOOL1; do 94 sleep 1 95 done 96 log_mustnot is_pool_scrubbing $TESTPOOL1 97 98 # Verify a scrub cannot be started while resilvering. 99 log_must is_pool_resilvering $TESTPOOL1 100 log_mustnot zpool scrub $TESTPOOL1 101 102 # Unsuspend resilver. 103 log_must set_tunable32 SCAN_SUSPEND_PROGRESS 0 104 log_must set_tunable32 RESILVER_MIN_TIME_MS 3000 105 106 # Wait for resilver to finish then put the original back. 107 log_must zpool wait $TESTPOOL1 108 log_must zpool replace $flags -w $TESTPOOL1 $SPARE_VDEV_FILE \ 109 ${VDEV_FILES[1]} 110done 111log_pass "Scrub was cancelled by resilver" 112 113