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# Copyright (c) 2019, Delphix. All rights reserved.
23# Copyright (c) 2023, George Amanakis. All rights reserved.
24#
25
26. $STF_SUITE/include/libtest.shlib
27. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
28
29#
30# DESCRIPTION:
31#	Verify regular scrub and error scrub can't run at the same time.
32#
33# STRATEGY:
34#	1. Create a pool and create a 10MB file in it.
35#	2. Start a scrub and verify it's doing a scrub.
36# 	3. Start a error scrub (-e) and verify it fails.
37#	4. Pause scrub (-p) and verify it's paused.
38#	5. Start a error scrub (-e) verify it fails again.
39#	6. Resume the paused scrub, verify it and cancel it.
40#	7. Start a error scrub (-e) and verify it's doing error scrub.
41# 	8. Start a scrub and verify it fails.
42# 	9. Cancel error scrub (-e) and verify it is canceled.
43# 	10. Start scrub, verify it, cancel it and verify it.
44#
45
46verify_runnable "global"
47
48function cleanup
49{
50	log_must set_tunable32 SCAN_SUSPEND_PROGRESS 0
51	log_must zinject -c all
52	rm -f /$TESTPOOL/10m_file
53}
54
55log_onexit cleanup
56
57log_assert "Verify regular scrub and error scrub can't run at the same time."
58
59log_must fio --rw=write --name=job --size=10M --filename=/$TESTPOOL/10m_file
60
61log_must zpool export $TESTPOOL
62log_must zpool import $TESTPOOL
63log_must zinject -t data -e checksum -f 100 -am /$TESTPOOL/10m_file
64
65# create some error blocks before error scrub is requested.
66dd if=/$TESTPOOL/10m_file bs=1M count=1 || true
67# sync error blocks to disk
68log_must sync_pool $TESTPOOL
69
70log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1
71
72log_must zpool scrub $TESTPOOL
73log_must is_pool_scrubbing $TESTPOOL true
74log_mustnot zpool scrub -e $TESTPOOL
75log_must zpool scrub -p $TESTPOOL
76log_must is_pool_scrub_paused $TESTPOOL true
77log_mustnot zpool scrub -e $TESTPOOL
78log_must zpool scrub $TESTPOOL
79log_must is_pool_scrubbing $TESTPOOL true
80log_must zpool scrub -s $TESTPOOL
81log_must is_pool_scrub_stopped $TESTPOOL true
82
83# create some error blocks before error scrub is requested.
84dd if=/$TESTPOOL/10m_file bs=1M count=1 || true
85# sync error blocks to disk
86log_must sync_pool $TESTPOOL
87
88log_must zpool scrub -e $TESTPOOL
89log_must is_pool_error_scrubbing $TESTPOOL true
90log_mustnot zpool scrub $TESTPOOL
91log_must zpool scrub -s $TESTPOOL
92log_must is_pool_error_scrub_stopped $TESTPOOL true
93
94log_must zpool scrub $TESTPOOL
95log_must is_pool_scrubbing $TESTPOOL true
96log_must zpool scrub -s $TESTPOOL
97log_must is_pool_scrub_stopped $TESTPOOL true
98
99log_pass "Verified regular scrub and error scrub can't run at the same time."
100