]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/fault/auto_spare_shared.ksh
Distributed Spare (dRAID) Feature
[mirror_zfs.git] / tests / zfs-tests / tests / functional / fault / auto_spare_shared.ksh
CommitLineData
2e550344 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/include/math.shlib
23. $STF_SUITE/tests/functional/fault/fault.cfg
24
25#
26# DESCRIPTION:
27# Spare devices (both files and disks) can be shared among different ZFS pools.
28#
29# STRATEGY:
30# 1. Create two pools
31# 2. Add the same spare device to different pools
32# 3. Inject IO errors with a zinject error handler
33# 4. Start a scrub
34# 5. Verify the ZED kicks in a hot spare and check pool/device status
35# 6. Clear the fault
36# 7. Verify the hot spare is available and check pool/device status
37#
38
39verify_runnable "both"
40
41if is_linux; then
42 # Add one 512b spare device (4Kn would generate IO errors on replace)
43 # NOTE: must be larger than other "file" vdevs and minimum SPA devsize:
44 # add 32m of fudge
b2255edc 45 load_scsi_debug $(($MINVDEVSIZE/1024/1024+32)) 1 1 1 '512b'
2e550344 46else
47 log_unsupported "scsi debug module unsupported"
48fi
49
50function cleanup
51{
52 log_must zinject -c all
53 destroy_pool $TESTPOOL
54 destroy_pool $TESTPOOL1
55 unload_scsi_debug
56 rm -f $SAFE_FILEDEVPOOL1 $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL1 \
57 $FAIL_FILEDEVPOOL2 $SPARE_FILEDEV
58}
59
60log_assert "Spare devices can be shared among different ZFS pools"
61log_onexit cleanup
62
63# Clear events from previous runs
64zed_events_drain
65
66SAFE_FILEDEVPOOL1="$TEST_BASE_DIR/file-safe-dev1"
67FAIL_FILEDEVPOOL1="$TEST_BASE_DIR/file-fail-dev1"
68SAFE_FILEDEVPOOL2="$TEST_BASE_DIR/file-safe-dev2"
69FAIL_FILEDEVPOOL2="$TEST_BASE_DIR/file-fail-dev2"
70SPARE_FILEDEV="$TEST_BASE_DIR/file-spare-dev"
71SPARE_DISKDEV="$(get_debug_device)"
72
73for vdev in $SAFE_FILEDEVPOOL1 $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL1 \
74 $FAIL_FILEDEVPOOL2 $SPARE_FILEDEV; do
b2255edc 75 log_must truncate -s $MINVDEVSIZE $vdev
2e550344 76done
77
78for spare in $SPARE_FILEDEV $SPARE_DISKDEV; do
79 # 1. Create two pools
80 log_must zpool create -f $TESTPOOL mirror $SAFE_FILEDEVPOOL1 $FAIL_FILEDEVPOOL1
81 log_must zpool create -f $TESTPOOL1 mirror $SAFE_FILEDEVPOOL2 $FAIL_FILEDEVPOOL2
82
83 # 2. Add the same spare device to different pools
84 log_must_busy zpool add $TESTPOOL spare $spare
85 log_must_busy zpool add $TESTPOOL1 spare $spare
86 log_must wait_hotspare_state $TESTPOOL $spare "AVAIL"
87 log_must wait_hotspare_state $TESTPOOL1 $spare "AVAIL"
88
89 # 3. Inject IO errors with a zinject error handler
90 log_must zinject -d $FAIL_FILEDEVPOOL1 -e io -T all -f 100 $TESTPOOL
91 log_must zinject -d $FAIL_FILEDEVPOOL2 -e io -T all -f 100 $TESTPOOL1
92
93 # 4. Start a scrub
94 log_must zpool scrub $TESTPOOL
95 log_must zpool scrub $TESTPOOL1
96
97 # 5. Verify the ZED kicks in a hot spare and check pool/device status
98 log_note "Wait for ZED to auto-spare"
99 log_must wait_vdev_state $TESTPOOL $FAIL_FILEDEVPOOL1 "FAULTED" 60
100 log_must wait_vdev_state $TESTPOOL $spare "ONLINE" 60
101 log_must wait_hotspare_state $TESTPOOL $spare "INUSE"
102 log_must check_state $TESTPOOL "" "DEGRADED"
103
104 # 6. Clear the fault
105 log_must zinject -c all
106 log_must zpool clear $TESTPOOL $FAIL_FILEDEVPOOL1
107
108 # 7. Verify the hot spare is available and check pool/device status
109 log_must wait_vdev_state $TESTPOOL $FAIL_FILEDEVPOOL1 "ONLINE" 60
110 log_must wait_hotspare_state $TESTPOOL $spare "AVAIL"
111 log_must is_pool_resilvered $TESTPOOL
112 log_must check_state $TESTPOOL "" "ONLINE"
113
114 # Cleanup
115 destroy_pool $TESTPOOL
116 destroy_pool $TESTPOOL1
117done
118
119log_pass "Spare devices can be shared among different ZFS pools"