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 http://www.opensolaris.org/os/licensing.
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 (c) 2021 by vStack. All rights reserved.
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31#	Check device replacement during raidz expansion.
32#
33# STRATEGY:
34#	1. Create block device files for the test raidz pool
35#	2. For each parity value [1..3]
36#	    - create raidz pool with minimum block device files required
37#	    - create couple of datasets with different recordsize and fill it
38#	    - attach new device to the pool
39#	    - offline and zero vdevs allowed by parity
40#	    - wait some time and start offlined vdevs replacement
41#	    - wait replacement completion and verify pool status
42
43typeset -r devs=10
44typeset -r dev_size_mb=128
45
46typeset -a disks
47
48embedded_slog_min_ms=$(get_tunable EMBEDDED_SLOG_MIN_MS)
49original_scrub_after_expand=$(get_tunable SCRUB_AFTER_EXPAND)
50
51function cleanup
52{
53	poolexists "$TESTPOOL" && log_must_busy zpool destroy "$TESTPOOL"
54
55	for i in {0..$devs}; do
56		log_must rm -f "$TEST_BASE_DIR/dev-$i"
57	done
58
59	log_must set_tunable32 EMBEDDED_SLOG_MIN_MS $embedded_slog_min_ms
60	log_must set_tunable32 SCRUB_AFTER_EXPAND $original_scrub_after_expand
61}
62
63log_onexit cleanup
64
65log_must set_tunable32 EMBEDDED_SLOG_MIN_MS 99999
66
67# Disk files which will be used by pool
68for i in {0..$(($devs))}; do
69	device=$TEST_BASE_DIR/dev-$i
70	log_must truncate -s ${dev_size_mb}M $device
71	disks[${#disks[*]}+1]=$device
72done
73
74nparity=$((RANDOM%(3) + 1))
75raid=raidz$nparity
76pool=$TESTPOOL
77opts="-o cachefile=none"
78
79log_must set_tunable32 SCRUB_AFTER_EXPAND 0
80
81log_must zpool create -f $opts $pool $raid ${disks[1..$(($nparity+1))]}
82
83log_must zfs create -o recordsize=8k $pool/fs
84log_must fill_fs /$pool/fs 1 128 100 1024 R
85
86log_must zfs create -o recordsize=128k $pool/fs2
87log_must fill_fs /$pool/fs2 1 128 100 1024 R
88
89for disk in ${disks[$(($nparity+2))..$devs]}; do
90	log_must zpool attach $pool ${raid}-0 $disk
91
92	sleep 10
93
94	for (( i=1; i<=$nparity; i=i+1 )); do
95		log_must zpool offline $pool ${disks[$i]}
96		log_must dd if=/dev/zero of=${disks[$i]} \
97		    bs=1024k count=$dev_size_mb conv=notrunc
98	done
99
100	sleep 3
101
102	for (( i=1; i<=$nparity; i=i+1 )); do
103		log_must zpool replace $pool ${disks[$i]}
104	done
105
106	log_must zpool wait -t replace $pool
107	log_must check_pool_status $pool "scan" "with 0 errors"
108
109	log_must zpool wait -t raidz_expand $pool
110
111	log_must zpool clear $pool
112	log_must zpool scrub -w $pool
113
114	log_must zpool status -v
115	log_must check_pool_status $pool "scan" "with 0 errors"
116done
117
118log_must zpool destroy "$pool"
119
120log_pass "raidz expansion test succeeded."
121
122