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) 2014, 2017 by Delphix. All rights reserved. 19# Copyright (c) 2018 by Lawrence Livermore National Security, LLC. 20# 21 22. $STF_SUITE/include/libtest.shlib 23. $STF_SUITE/tests/functional/removal/removal.kshlib 24 25# 26# DESCRIPTION: 27# 28# This test ensures that even when child vdevs are unavailable the 29# device removal process copies from readable source children to 30# writable destination children. This may be different than the 31# default mapping which preferentially pairs up source and destination 32# child vdevs based on their child ids. 33# 34# Default Mapping: 35# mirror-0 mirror-1 36# DISK0 (child 0) ------> DISK2 (child 0) 37# DISK1 (child 1) ------> DISK3 (child 1) 38# 39# We want to setup a scenario where the default mapping would make 40# it impossible to copy any data during the removal process. This 41# is done by faulting both the mirror-0 (child 0) source vdev and 42# mirror-1 (child 1) destination vdev. As shown below the default 43# mapping cannot be used due to the FAULTED vdevs. Verify that an 44# alternate mapping is selected and all the readable data is copied. 45# 46# Default Mapping (BAD): 47# mirror-0 mirror-1 48# DISK0 (FAULTED) ------> DISK2 49# DISK1 ----------------> DISK3 (FAULTED) 50# 51# Required Mapping (GOOD): 52# mirror-0 mirror-1 53# DISK0 (FAULTED) +---> DISK2 54# DISK1 ------------+ DISK3 (FAULTED) 55# 56# STRATEGY: 57# 58# 1. We create a pool with two top-level mirror vdevs. 59# 2. We write some test data to the pool. 60# 3. We fault two children to force the scenario described above. 61# 4. We remove the mirror-0 device. 62# 5. We verify that the device has been removed and that all of the 63# data is still intact. 64# 65 66TMPDIR=${TMPDIR:-$TEST_BASE_DIR} 67DISK0=$TMPDIR/dsk0 68DISK1=$TMPDIR/dsk1 69DISK2=$TMPDIR/dsk2 70DISK3=$TMPDIR/dsk3 71 72log_must truncate -s $MINVDEVSIZE $DISK0 $DISK1 73log_must truncate -s $((MINVDEVSIZE * 4)) $DISK2 $DISK3 74 75function cleanup 76{ 77 default_cleanup_noexit 78 log_must rm -f $DISK0 $DISK1 $DISK2 $DISK3 79} 80 81default_setup_noexit "mirror $DISK0 $DISK1 mirror $DISK2 $DISK3" 82log_onexit cleanup 83 84log_must zpool offline -f $TESTPOOL $DISK0 85log_must zpool offline -f $TESTPOOL $DISK3 86 87FILE_CONTENTS="Leeloo Dallas mul-ti-pass." 88 89echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 90log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] 91log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7)) 92sync_pool $TESTPOOL 93 94log_must zpool remove $TESTPOOL mirror-0 95log_must wait_for_removal $TESTPOOL 96log_mustnot vdevs_in_pool $TESTPOOL mirror-0 97 98verify_pool $TESTPOOL 99 100log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null 101log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] 102log_must dd if=$TESTDIR/$TESTFILE1 of=/dev/null 103 104log_pass "Can remove with faulted vdevs" 105