Skip to content

Commit 954894e

Browse files
oshogboamotin
authored andcommitted
scrub: generate scrub_finish event
The `scn_min_txg` can now be used not only with resilver. Instead of checking `scn_min_txg` to determine whether it’s a resilver or a scrub, simply check which function is defined. Thanks to this change, a scrub_finish event is generated when performing a scrub from the saved txg. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Mariusz Zaborski <[email protected]> Closes #17432
1 parent a4e775d commit 954894e

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

module/zfs/dsl_scan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ static uint_t zfs_resilver_defer_percent = 10;
235235
#define DSL_SCAN_IS_SCRUB(scn) \
236236
((scn)->scn_phys.scn_func == POOL_SCAN_SCRUB)
237237

238+
#define DSL_SCAN_IS_RESILVER(scn) \
239+
((scn)->scn_phys.scn_func == POOL_SCAN_RESILVER)
240+
238241
/*
239242
* Enable/disable the processing of the free_bpobj object.
240243
*/
@@ -1169,7 +1172,7 @@ dsl_scan_done(dsl_scan_t *scn, boolean_t complete, dmu_tx_t *tx)
11691172
vdev_dtl_reassess(spa->spa_root_vdev, tx->tx_txg,
11701173
scn->scn_phys.scn_max_txg, B_TRUE, B_FALSE);
11711174

1172-
if (scn->scn_phys.scn_min_txg) {
1175+
if (DSL_SCAN_IS_RESILVER(scn)) {
11731176
nvlist_t *aux = fnvlist_alloc();
11741177
fnvlist_add_string(aux, ZFS_EV_RESILVER_TYPE,
11751178
"healing");

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
10851085
functional/cli_root/zpool_events/zpool_events_errors.ksh \
10861086
functional/cli_root/zpool_events/zpool_events_follow.ksh \
10871087
functional/cli_root/zpool_events/zpool_events_poolname.ksh \
1088+
functional/cli_root/zpool_events/zpool_events_scrub_txg_continue_from_last.ksh \
10881089
functional/cli_root/zpool_expand/cleanup.ksh \
10891090
functional/cli_root/zpool_expand/setup.ksh \
10901091
functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh \
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
#
4+
# CDDL HEADER START
5+
#
6+
# The contents of this file are subject to the terms of the
7+
# Common Development and Distribution License (the "License").
8+
# You may not use this file except in compliance with the License.
9+
#
10+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11+
# or https://opensource.org/licenses/CDDL-1.0.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# When distributing Covered Code, include this CDDL HEADER in each
16+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17+
# If applicable, add the following below this CDDL HEADER, with the
18+
# fields enclosed by brackets "[]" replaced with your own identifying
19+
# information: Portions Copyright [yyyy] [name of copyright owner]
20+
#
21+
# CDDL HEADER END
22+
#
23+
24+
# Copyright (c) 2025, Klara Inc.
25+
#
26+
# This software was developed by
27+
# Mariusz Zaborski <[email protected]>
28+
# under sponsorship from Wasabi Technology, Inc. and Klara Inc.
29+
30+
. $STF_SUITE/include/libtest.shlib
31+
. $STF_SUITE/tests/functional/cli_root/zpool_events/zpool_events.kshlib
32+
33+
#
34+
# DESCRIPTION:
35+
# Verify that using “zpool scrub -C” correctly generates events.
36+
#
37+
# STRATEGY:
38+
# 1. Run an initial “zpool scrub” on the test pool to generate a txg.
39+
# 2. Clear existing pool events.
40+
# 3. Run “zpool scrub -C” to scrub from the last txg.
41+
# 4. Capture the event log and confirm it contains both “scrub_start” and
42+
# “scrub_finish” entries.
43+
#
44+
45+
verify_runnable "global"
46+
47+
function cleanup
48+
{
49+
rm -f $EVENTS_FILE
50+
}
51+
52+
EVENTS_FILE="$TESTDIR/zpool_events.$$"
53+
log_onexit cleanup
54+
55+
log_assert "Verify scrub -C events."
56+
57+
# Run an initial “zpool scrub”
58+
log_must zpool scrub -w $TESTPOOL
59+
60+
# Clear existing pool events.
61+
log_must zpool events -c
62+
63+
# Generate new scrub events.
64+
log_must zpool scrub -Cw $TESTPOOL
65+
66+
# Verify events.
67+
log_must eval "zpool events -H > $EVENTS_FILE"
68+
log_must grep "scrub_start" $EVENTS_FILE
69+
log_must grep "scrub_finish" $EVENTS_FILE
70+
71+
log_pass "Verified scrub -C generate correct events."

0 commit comments

Comments
 (0)