xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/l2arc/persist_l2arc_005_pos.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# This file and its contents are supplied under the terms of the
7# Common Development and Distribution License ("CDDL"), version 1.0.
8# You may only use this file in accordance with the terms of version
9# 1.0 of the CDDL.
10#
11# A full copy of the text of the CDDL should have accompanied this
12# source.  A copy of the CDDL is also available via the Internet at
13# http://www.illumos.org/license/CDDL.
14#
15# CDDL HEADER END
16#
17
18#
19# Copyright (c) 2020, George Amanakis. All rights reserved.
20#
21
22. $STF_SUITE/include/libtest.shlib
23. $STF_SUITE/tests/functional/l2arc/l2arc.cfg
24
25#
26# DESCRIPTION:
27#	Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present.
28#
29# STRATEGY:
30#	1. Create pool with a cache device.
31#	2. Create a random file in that pool and random read for 10 sec.
32#	3. Offline the L2ARC device.
33#	4. Read the amount of log blocks written from the header of the
34#		L2ARC device.
35#	5. Online the L2ARC device.
36#	6. Read the amount of log blocks rebuilt in arcstats and compare to
37#		(4).
38#	7. Check if the labels of the L2ARC device are intact.
39#
40
41verify_runnable "global"
42
43command -v fio > /dev/null || log_unsupported "fio missing"
44
45log_assert "Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present."
46
47function cleanup
48{
49	if poolexists $TESTPOOL ; then
50		destroy_pool $TESTPOOL
51	fi
52
53	log_must set_tunable32 L2ARC_NOPREFETCH $noprefetch
54	log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE \
55		$rebuild_blocks_min_l2size
56}
57log_onexit cleanup
58
59# L2ARC_NOPREFETCH is set to 0 to let L2ARC handle prefetches
60typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH)
61typeset rebuild_blocks_min_l2size=$(get_tunable L2ARC_REBUILD_BLOCKS_MIN_L2SIZE)
62log_must set_tunable32 L2ARC_NOPREFETCH 0
63log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE 0
64
65typeset fill_mb=800
66typeset cache_sz=$(( floor($fill_mb / 2) ))
67export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
68
69log_must truncate -s ${cache_sz}M $VDEV_CACHE
70
71log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
72
73log_must fio $FIO_SCRIPTS/mkfiles.fio
74log_must fio $FIO_SCRIPTS/random_reads.fio
75
76arcstat_quiescence_noecho l2_size
77log_must zpool offline $TESTPOOL $VDEV_CACHE
78arcstat_quiescence_noecho l2_size
79
80typeset l2_rebuild_log_blk_start=$(kstat arcstats.l2_rebuild_log_blks)
81typeset l2_dh_log_blk=$(zdb -l $VDEV_CACHE | awk '/log_blk_count/ {print $2}')
82
83log_must zpool online $TESTPOOL $VDEV_CACHE
84arcstat_quiescence_noecho l2_size
85
86typeset l2_rebuild_log_blk_end=$(arcstat_quiescence_echo l2_rebuild_log_blks)
87
88# Upon onlining the cache device we might write additional blocks to it
89# before it is marked for rebuild as the l2ad_* parameters are not cleared
90# when offlining the device. See comment in l2arc_rebuild_vdev().
91# So we cannot compare the amount of rebuilt log blocks to the amount of log
92# blocks read from the header of the device.
93log_must test $(( $l2_rebuild_log_blk_end - \
94	$l2_rebuild_log_blk_start )) -gt 0
95log_must test $l2_dh_log_blk -gt 0
96
97log_must zpool offline $TESTPOOL $VDEV_CACHE
98arcstat_quiescence_noecho l2_size
99
100log_must zdb -lq $VDEV_CACHE
101
102log_must zpool destroy -f $TESTPOOL
103
104log_pass "Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present."
105