1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or https://opensource.org/licenses/CDDL-1.0. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23# 24# Copyright (c) 2017 by Intel Corporation. All rights reserved. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/fault/fault.cfg 29 30# 31# DESCRIPTION: 32# Testing Fault Management Agent ZED Logic - Automated Auto-Replace Test. 33# 34# STRATEGY: 35# 1. Update /etc/zfs/vdev_id.conf with scsidebug alias for a persistent path. 36# This creates keys ID_VDEV and ID_VDEV_PATH and set phys_path="scsidebug". 37# 2. Create a pool and set autoreplace=on (auto-replace is opt-in) 38# 3. Export the pool 39# 4. Wipe and offline the scsi_debug disk 40# 5. Import the pool with missing disk 41# 6. Re-online the wiped scsi_debug disk 42# 7. Verify ZED detects the new blank disk and replaces the missing vdev 43# 8. Verify that the scsi_debug disk was re-partitioned 44# 45# Creates a raidz1 zpool using persistent /dev/disk/by-vdev path names 46# (ie not /dev/sdc) 47# 48# Auto-replace is opt in, and matches by phys_path. 49# 50 51verify_runnable "both" 52 53if ! is_physical_device $DISKS; then 54 log_unsupported "Unsupported disks for this test." 55fi 56 57function cleanup 58{ 59 zpool status $TESTPOOL 60 destroy_pool $TESTPOOL 61 sed -i '/alias scsidebug/d' $VDEVID_CONF 62 unload_scsi_debug 63} 64 65log_assert "Testing automated auto-replace FMA test" 66log_onexit cleanup 67 68load_scsi_debug $SDSIZE $SDHOSTS $SDTGTS $SDLUNS '512b' 69SD=$(get_debug_device) 70SD_DEVICE_ID=$(get_persistent_disk_name $SD) 71SD_HOST=$(get_scsi_host $SD) 72 73# Register vdev_id alias for scsi_debug device to create a persistent path 74echo "alias scsidebug /dev/disk/by-id/$SD_DEVICE_ID" >>$VDEVID_CONF 75block_device_wait 76 77SD_DEVICE=$(udevadm info -q all -n $DEV_DSKDIR/$SD | \ 78 awk -F'=' '/ID_VDEV=/ {print $2; exit}') 79[ -z $SD_DEVICE ] && log_fail "vdev rule was not registered properly" 80 81log_must zpool events -c 82log_must zpool create -f $TESTPOOL raidz1 $SD_DEVICE $DISK1 $DISK2 $DISK3 83 84# Auto-replace is opt-in so need to set property 85log_must zpool set autoreplace=on $TESTPOOL 86 87# Add some data to the pool 88log_must zfs create $TESTPOOL/fs 89log_must fill_fs /$TESTPOOL/fs 4 100 4096 512 Z 90log_must zpool export $TESTPOOL 91 92# Record the partition UUID for later comparison 93part_uuid=$(udevadm info --query=property --property=ID_PART_TABLE_UUID \ 94 --value /dev/disk/by-id/$SD_DEVICE_ID) 95[[ -z "$part_uuid" ]] || log_note original disk GPT uuid ${part_uuid} 96 97# 98# Wipe and offline the disk 99# 100# Note that it is not enough to zero the disk to expunge the partitions. 101# You also need to inform the kernel (e.g., 'hdparm -z' or 'partprobe'). 102# 103# Using partprobe is overkill and hdparm is not as common as wipefs. So 104# we use wipefs which lets the kernel know the partition was removed 105# from the device (i.e., calls BLKRRPART ioctl). 106# 107log_must dd if=/dev/zero of=/dev/disk/by-id/$SD_DEVICE_ID bs=1M count=$SDSIZE 108log_must /usr/sbin/wipefs -a /dev/disk/by-id/$SD_DEVICE_ID 109remove_disk $SD 110block_device_wait 111 112# Re-import pool with drive missing 113log_must zpool import $TESTPOOL 114log_must check_state $TESTPOOL "" "DEGRADED" 115block_device_wait 116 117# Online an empty disk in the same physical location 118insert_disk $SD $SD_HOST 119 120# Wait for the new disk to be online and replaced 121log_must wait_vdev_state $TESTPOOL "scsidebug" "ONLINE" 60 122log_must wait_replacing $TESTPOOL 60 123 124# Validate auto-replace was successful 125log_must check_state $TESTPOOL "" "ONLINE" 126 127# 128# Confirm the partition UUID changed so we know the new disk was relabeled 129# 130# Note: some older versions of udevadm don't support "--property" option so 131# we'll # skip this test when it is not supported 132# 133if [ ! -z "$part_uuid" ]; then 134 new_uuid=$(udevadm info --query=property --property=ID_PART_TABLE_UUID \ 135 --value /dev/disk/by-id/$SD_DEVICE_ID) 136 log_note new disk GPT uuid ${new_uuid} 137 [[ "$part_uuid" = "$new_uuid" ]] && \ 138 log_fail "The new disk was not relabeled as expected" 139fi 140 141log_pass "Auto-replace test successful" 142