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# Sequential reconstruction (unlike healing reconstruction) operate on the 29# top-level vdev. This means that a sequential resilver operation can be 30# started/stopped on a different top-level vdev without impacting other 31# sequential resilvers. 32# 33# STRATEGY: 34# 1. Create a mirrored pool. 35# 36 37function cleanup 38{ 39 log_must set_tunable32 SCAN_SUSPEND_PROGRESS \ 40 $ORIG_SCAN_SUSPEND_PROGRESS 41 destroy_pool $TESTPOOL1 42 rm -f ${VDEV_FILES[@]} $SPARE_VDEV_FILE $SPARE_VDEV_FILE2 43} 44 45function check_history 46{ 47 pool=$1 48 msg=$2 49 exp=$3 50 51 count=$(zpool history -i $pool | grep "rebuild" | grep -c "$msg") 52 if [[ "$count" -ne "$exp" ]]; then 53 log_fail "Expected $exp rebuild '$msg' messages, found $count" 54 else 55 log_note "Found $count/$exp rebuild '$msg' messages" 56 fi 57} 58 59log_assert "Rebuilds operate on the top-level vdevs" 60 61ORIG_SCAN_SUSPEND_PROGRESS=$(get_tunable SCAN_SUSPEND_PROGRESS) 62 63log_onexit cleanup 64 65log_must truncate -s $VDEV_FILE_SIZE ${VDEV_FILES[@]} \ 66 $SPARE_VDEV_FILE $SPARE_VDEV_FILE2 67 68# Verify two sequential resilvers can run concurrently. 69log_must zpool create -f $TESTPOOL1 \ 70 mirror ${VDEV_FILES[0]} ${VDEV_FILES[1]} \ 71 mirror ${VDEV_FILES[2]} ${VDEV_FILES[3]} 72log_must zfs create $TESTPOOL1/$TESTFS 73 74mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS) 75log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=32 76sync_pool $TESTPOOL1 77 78log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1 79 80log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE 81log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[3]} $SPARE_VDEV_FILE2 82 83check_history $TESTPOOL1 "started" 2 84check_history $TESTPOOL1 "reset" 0 85check_history $TESTPOOL1 "complete" 0 86check_history $TESTPOOL1 "canceled" 0 87 88log_must set_tunable32 SCAN_SUSPEND_PROGRESS $ORIG_SCAN_SUSPEND_PROGRESS 89log_must zpool wait -t resilver $TESTPOOL1 90 91check_history $TESTPOOL1 "complete" 2 92destroy_pool $TESTPOOL1 93 94# Verify canceling one resilver (zpool detach) does not impact others. 95log_must zpool create -f $TESTPOOL1 \ 96 mirror ${VDEV_FILES[0]} ${VDEV_FILES[1]} \ 97 mirror ${VDEV_FILES[2]} ${VDEV_FILES[3]} 98log_must zfs create $TESTPOOL1/$TESTFS 99 100mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS) 101log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=32 102sync_pool $TESTPOOL1 103 104log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1 105 106log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE 107log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[3]} $SPARE_VDEV_FILE2 108 109check_history $TESTPOOL1 "started" 2 110check_history $TESTPOOL1 "reset" 0 111check_history $TESTPOOL1 "complete" 0 112check_history $TESTPOOL1 "canceled" 0 113 114log_must zpool detach $TESTPOOL1 $SPARE_VDEV_FILE2 115 116check_history $TESTPOOL1 "complete" 0 117check_history $TESTPOOL1 "canceled" 1 118 119log_must set_tunable32 SCAN_SUSPEND_PROGRESS $ORIG_SCAN_SUSPEND_PROGRESS 120log_must zpool wait -t resilver $TESTPOOL1 121 122check_history $TESTPOOL1 "complete" 1 123check_history $TESTPOOL1 "canceled" 1 124destroy_pool $TESTPOOL1 125 126log_pass "Rebuilds operate on the top-level vdevs" 127