aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/replacement/scrub_cancel.ksh
blob: da8a0a26e333e51ced99b703e9449b0fe7f823a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/ksh -p

#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2019, Datto Inc. All rights reserved.
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/replacement/replacement.cfg

#
# DESCRIPTION:
# Verify scrub behaves as intended when contending with a healing or
# sequential resilver.
#
# STRATEGY:
# 1. Create a pool
# 2. Add a modest amount of data to the pool.
# 3. For healing and sequential resilver:
#    a. Start scrubbing.
#    b. Verify a resilver can be started and it cancels the scrub.
#    c. Verify a scrub cannot be started when resilvering
#

function cleanup
{
	log_must set_tunable32 RESILVER_MIN_TIME_MS $ORIG_RESILVER_MIN_TIME
	log_must set_tunable32 SCAN_SUSPEND_PROGRESS \
	    $ORIG_SCAN_SUSPEND_PROGRESS
	destroy_pool $TESTPOOL1
	rm -f ${VDEV_FILES[@]} $SPARE_VDEV_FILE
}

log_assert "Scrub was cancelled by resilver"

ORIG_RESILVER_MIN_TIME=$(get_tunable RESILVER_MIN_TIME_MS)
ORIG_SCAN_SUSPEND_PROGRESS=$(get_tunable SCAN_SUSPEND_PROGRESS)

log_onexit cleanup

log_must truncate -s $VDEV_FILE_SIZE ${VDEV_FILES[@]} $SPARE_VDEV_FILE

log_must zpool create -f $TESTPOOL1 ${VDEV_FILES[@]}
log_must zfs create $TESTPOOL1/$TESTFS

mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS)
log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=64
log_must zpool sync $TESTPOOL1

# Request a healing or sequential resilver
for replace_mode in "healing" "sequential"; do

	#
	# Healing resilvers abort the dsl_scan and reconfigure it for
	# resilvering.  Sequential resilvers cancel the dsl_scan and start
	# the vdev_rebuild thread.
	#
	if [[ "$replace_mode" = "healing" ]]; then
		history_msg="scan aborted, restarting"
		flags=""
	else
		history_msg="scan cancelled"
		flags="-s"
	fi

	# Limit scanning time and suspend the scan as soon as possible.
	log_must set_tunable32 RESILVER_MIN_TIME_MS 50
	log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1

	# Initiate a scrub.
	log_must zpool scrub $TESTPOOL1

	# Initiate a resilver to cancel the scrub.
	log_must zpool replace $flags $TESTPOOL1 ${VDEV_FILES[1]} \
	    $SPARE_VDEV_FILE

	# Verify the scrub was canceled, it may take a few seconds to exit.
	while is_pool_scrubbing $TESTPOOL1; do
		sleep 1
	done
	log_mustnot is_pool_scrubbing $TESTPOOL1

	# Verify a scrub cannot be started while resilvering.
	log_must is_pool_resilvering $TESTPOOL1
	log_mustnot zpool scrub $TESTPOOL1

	# Unsuspend resilver.
	log_must set_tunable32 SCAN_SUSPEND_PROGRESS 0
	log_must set_tunable32 RESILVER_MIN_TIME_MS 3000

	# Wait for resilver to finish then put the original back.
	log_must zpool wait $TESTPOOL1
	log_must zpool replace $flags -w $TESTPOOL1 $SPARE_VDEV_FILE \
	    ${VDEV_FILES[1]}
done
log_pass "Scrub was cancelled by resilver"