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 https://opensource.org/licenses/CDDL-1.0. 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# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib 29. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg 30 31# 32# DESCRIPTION: 33# Scrubbing a pool with offline devices correctly preserves DTL entries 34# 35# STRATEGY: 36# 1. Create the pool 37# 2. Offline the first device 38# 3. Write to the pool 39# 4. Scrub the pool 40# 5. Online the first device and offline the second device 41# 6. Scrub the pool again 42# 7. Verify data integrity 43# 44# NOTE: 45# Ported from script used to reproduce issue #5806 46# 47 48verify_runnable "global" 49 50function cleanup 51{ 52 poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 53 log_must rm -f $DISK1 $DISK2 $DISK3 $DISK4 54} 55 56# 57# Update to [online|offline] $device status on $pool synchronously 58# 59function zpool_do_sync # <status> <pool> <device> 60{ 61 status="$1" 62 pool="$2" 63 device="$3" 64 65 if [[ $status != "online" && $status != "offline" ]]; then 66 log_fail "zpool_do_sync: invalid status $status" 67 fi 68 69 log_must zpool $status $pool $device 70 for i in {1..10}; do 71 check_state $pool $device $status && return 0 72 done 73 log_fail "Failed to $status device $device" 74} 75 76# 77# Start a scrub on $pool and wait for its completion 78# 79function zpool_scrub_sync # <pool> 80{ 81 pool="$1" 82 83 log_must zpool scrub $pool 84 while ! is_pool_scrubbed $pool; do 85 sleep 1 86 done 87} 88 89log_assert "Scrubbing a pool with offline devices correctly preserves DTLs" 90log_onexit cleanup 91 92DEVSIZE='128m' 93FILESIZE='100m' 94TESTDIR="$TEST_BASE_DIR/zpool_scrub_offline_device" 95DISK1="$TEST_BASE_DIR/zpool_disk1.dat" 96DISK2="$TEST_BASE_DIR/zpool_disk2.dat" 97DISK3="$TEST_BASE_DIR/zpool_disk3.dat" 98DISK4="$TEST_BASE_DIR/zpool_disk4.dat" 99RESILVER_TIMEOUT=40 100 101# 1. Create the pool 102log_must truncate -s $DEVSIZE $DISK1 103log_must truncate -s $DEVSIZE $DISK2 104log_must truncate -s $DEVSIZE $DISK3 105log_must truncate -s $DEVSIZE $DISK4 106poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 107log_must zpool create -O mountpoint=$TESTDIR $TESTPOOL2 \ 108 raidz2 $DISK1 $DISK2 $DISK3 $DISK4 109 110# 2. Offline the first device 111zpool_do_sync 'offline' $TESTPOOL2 $DISK1 112 113# 3. Write to the pool 114log_must mkfile $FILESIZE "$TESTDIR/data.bin" 115 116# 4. Scrub the pool 117zpool_scrub_sync $TESTPOOL2 118 119# 5. Online the first device and offline the second device 120zpool_do_sync 'online' $TESTPOOL2 $DISK1 121zpool_do_sync 'offline' $TESTPOOL2 $DISK2 122log_must wait_for_resilver_end $TESTPOOL2 $RESILVER_TIMEOUT 123 124# 6. Scrub the pool again 125zpool_scrub_sync $TESTPOOL2 126 127# 7. Verify data integrity 128cksum=$(zpool status $TESTPOOL2 | awk 'L{print $NF;L=0} /CKSUM$/{L=1}') 129if [[ $cksum != 0 ]]; then 130 log_fail "Unexpected CKSUM errors found on $TESTPOOL2 ($cksum)" 131fi 132 133log_pass "Scrubbing a pool with offline devices correctly preserves DTLs" 134