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# Copyright (c) 2017 by Intel Corporation. All rights reserved. 24# 25 26. $STF_SUITE/include/libtest.shlib 27. $STF_SUITE/tests/functional/fault/fault.cfg 28 29# 30# DESCRIPTION: 31# Testing Fault Management Agent ZED Logic - Automated Auto-Replace Test. 32# 33# STRATEGY: 34# 1. Update /etc/zfs/vdev_id.conf with scsidebug alias for a persistent path. 35# This creates keys ID_VDEV and ID_VDEV_PATH and set phys_path="scsidebug". 36# 2. Create a pool and set autoreplace=on (auto-replace is opt-in) 37# 3. Export a pool 38# 4. Wipe and offline the scsi_debug disk 39# 5. Import pool with missing disk 40# 6. Re-online the wiped scsi_debug disk 41# 7. Verify the ZED detects the new unused disk and adds it back to the pool 42# 43# Creates a raidz1 zpool using persistent disk path names 44# (ie not /dev/sdc) 45# 46# Auto-replace is opt in, and matches by phys_path. 47# 48 49verify_runnable "both" 50 51if ! is_physical_device $DISKS; then 52 log_unsupported "Unsupported disks for this test." 53fi 54 55function cleanup 56{ 57 zpool status $TESTPOOL 58 destroy_pool $TESTPOOL 59 sed -i '/alias scsidebug/d' $VDEVID_CONF 60 unload_scsi_debug 61} 62 63log_assert "Testing automated auto-replace FMA test" 64log_onexit cleanup 65 66load_scsi_debug $SDSIZE $SDHOSTS $SDTGTS $SDLUNS '512b' 67SD=$(get_debug_device) 68SD_DEVICE_ID=$(get_persistent_disk_name $SD) 69SD_HOST=$(get_scsi_host $SD) 70 71# Register vdev_id alias for scsi_debug device to create a persistent path 72echo "alias scsidebug /dev/disk/by-id/$SD_DEVICE_ID" >>$VDEVID_CONF 73block_device_wait 74 75SD_DEVICE=$(udevadm info -q all -n $DEV_DSKDIR/$SD | \ 76 awk -F'=' '/ID_VDEV=/ {print $2; exit}') 77[ -z $SD_DEVICE ] && log_fail "vdev rule was not registered properly" 78 79log_must zpool events -c 80log_must zpool create -f $TESTPOOL raidz1 $SD_DEVICE $DISK1 $DISK2 $DISK3 81 82# Auto-replace is opt-in so need to set property 83log_must zpool set autoreplace=on $TESTPOOL 84 85# Add some data to the pool 86log_must mkfile $FSIZE /$TESTPOOL/data 87log_must zpool export $TESTPOOL 88 89# Wipe and offline the disk 90log_must dd if=/dev/zero of=/dev/disk/by-id/$SD_DEVICE_ID bs=1M count=$SDSIZE 91remove_disk $SD 92block_device_wait 93 94# Re-import pool with drive missing 95log_must zpool import $TESTPOOL 96log_must check_state $TESTPOOL "" "DEGRADED" 97block_device_wait 98 99# Online an empty disk in the same physical location 100insert_disk $SD $SD_HOST 101 102# Wait for the new disk to be online and replaced 103log_must wait_vdev_state $TESTPOOL "scsidebug" "ONLINE" 60 104log_must wait_replacing $TESTPOOL 60 105 106# Validate auto-replace was successful 107log_must check_state $TESTPOOL "" "ONLINE" 108 109log_pass "Auto-replace test successful" 110