1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2019, Datto Inc. All rights reserved.
16# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
17#
18
19. $STF_SUITE/include/libtest.shlib
20. $STF_SUITE/tests/functional/replacement/replacement.cfg
21
22#
23# Description:
24# Verify device_rebuild feature flags.
25#
26# Strategy:
27# 1. Create a pool with all features disabled.
28# 2. Verify 'zpool replace -s' fails and the feature is disabled.
29# 3. Enable the device_rebuild feature.
30# 4. Verify 'zpool replace -s' works and the feature is active.
31# 5. Wait for the feature to return to enabled.
32#
33
34function cleanup
35{
36	log_must set_tunable32 SCAN_SUSPEND_PROGRESS \
37	    $ORIG_SCAN_SUSPEND_PROGRESS
38	destroy_pool $TESTPOOL1
39	rm -f ${VDEV_FILES[@]} $SPARE_VDEV_FILE
40}
41
42function check_feature_flag
43{
44	feature=$1
45	pool=$2
46	expected_value=$3
47
48	value="$(zpool get -H -o property,value all $pool | awk -v f="$feature" '$0 ~ f {print $2}')"
49	if [ "$value" = "$expected_value" ]; then
50		log_note "$feature verified to be $value"
51	else
52		log_fail "$feature should be $expected_value but is $value"
53	fi
54}
55
56log_assert "Verify device_rebuild feature flags."
57
58ORIG_SCAN_SUSPEND_PROGRESS=$(get_tunable SCAN_SUSPEND_PROGRESS)
59
60log_onexit cleanup
61
62log_must truncate -s $VDEV_FILE_SIZE ${VDEV_FILES[@]} $SPARE_VDEV_FILE
63log_must zpool create -d $TESTPOOL1 ${VDEV_FILES[@]}
64
65log_mustnot zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE
66check_feature_flag "feature@device_rebuild" "$TESTPOOL1" "disabled"
67
68log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1
69log_must zpool set feature@device_rebuild=enabled $TESTPOOL1
70log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE
71check_feature_flag "feature@device_rebuild" "$TESTPOOL1" "active"
72
73log_must set_tunable32 SCAN_SUSPEND_PROGRESS $ORIG_SCAN_SUSPEND_PROGRESS
74log_must zpool wait -t resilver $TESTPOOL1
75check_feature_flag "feature@device_rebuild" "$TESTPOOL1" "enabled"
76
77log_pass "Verify device_rebuild feature flags."
78