1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 25# Copyright 2019 Joyent, Inc. 26# 27 28. $STF_SUITE/include/libtest.shlib 29. $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib 30. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg 31 32# 33# DESCRIPTION: 34# Scrubbing a pool with offline devices correctly preserves DTL entries 35# 36# STRATEGY: 37# 1. Create the pool 38# 2. Offline the first device 39# 3. Write to the pool 40# 4. Scrub the pool 41# 5. Online the first device and offline the second device 42# 6. Scrub the pool again 43# 7. Verify data integrity 44# 45# NOTE: 46# Ported from script used to reproduce issue #5806 47# 48 49verify_runnable "global" 50 51function cleanup 52{ 53 poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 54 log_must rm -f $DISK1 $DISK2 $DISK3 $DISK4 55} 56 57# 58# Update to [online|offline] $device status on $pool synchronously 59# 60function zpool_do_sync # <status> <pool> <device> 61{ 62 status="$1" 63 pool="$2" 64 device="$3" 65 66 if [[ $status != "online" && $status != "offline" ]]; then 67 log_fail "zpool_do_sync: invalid status $status" 68 fi 69 70 log_must zpool $status $pool $device 71 for i in {1..10}; do 72 check_state $pool $device $status && return 0 73 done 74 log_fail "Failed to $status device $device" 75} 76 77# 78# Start a scrub on $pool and wait for its completion 79# 80function zpool_scrub_sync # <pool> 81{ 82 pool="$1" 83 84 log_must zpool scrub $pool 85 while ! is_pool_scrubbed $pool; do 86 sleep 1 87 done 88} 89 90log_assert "Scrubbing a pool with offline devices correctly preserves DTLs" 91log_onexit cleanup 92 93DEVSIZE='128m' 94FILESIZE='100m' 95TESTDIR="$TEST_BASE_DIR/zpool_scrub_offline_device" 96DISK1="$TEST_BASE_DIR/zpool_disk1.dat" 97DISK2="$TEST_BASE_DIR/zpool_disk2.dat" 98DISK3="$TEST_BASE_DIR/zpool_disk3.dat" 99DISK4="$TEST_BASE_DIR/zpool_disk4.dat" 100RESILVER_TIMEOUT=40 101 102# 1. Create the pool 103log_must truncate -s $DEVSIZE $DISK1 104log_must truncate -s $DEVSIZE $DISK2 105log_must truncate -s $DEVSIZE $DISK3 106log_must truncate -s $DEVSIZE $DISK4 107poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 108log_must zpool create -O mountpoint=$TESTDIR $TESTPOOL2 \ 109 raidz2 $DISK1 $DISK2 $DISK3 $DISK4 110 111# 2. Offline the first device 112zpool_do_sync 'offline' $TESTPOOL2 $DISK1 113 114# 3. Write to the pool 115log_must mkfile $FILESIZE "$TESTDIR/data.bin" 116 117# 4. Scrub the pool 118zpool_scrub_sync $TESTPOOL2 119 120# 5. Online the first device and offline the second device 121zpool_do_sync 'online' $TESTPOOL2 $DISK1 122zpool_do_sync 'offline' $TESTPOOL2 $DISK2 123log_must wait_for_resilver_end $TESTPOOL2 $RESILVER_TIMEOUT 124 125# 6. Scrub the pool again 126zpool_scrub_sync $TESTPOOL2 127 128# 7. Verify data integrity 129cksum=$(zpool status $TESTPOOL2 | awk '{if ($NF == "CKSUM") {fnd=1; next} \ 130 if (fnd && NF < 1) {fnd=0; next} if (fnd) csum += $NF} END {print csum}') 131if [[ $cksum != 0 ]]; then 132 log_fail "Unexpected CKSUM errors found on $TESTPOOL2 ($cksum)" 133fi 134 135log_pass "Scrubbing a pool with offline devices correctly preserves DTLs" 136