xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/l2arc/persist_l2arc_005_pos.ksh (revision 9e3493cb8a0cfe96c9aef9b7da42c6c9b5c24b43)
1*9e3493cbSJason King#!/bin/ksh -p
2*9e3493cbSJason King#
3*9e3493cbSJason King# CDDL HEADER START
4*9e3493cbSJason King#
5*9e3493cbSJason King# This file and its contents are supplied under the terms of the
6*9e3493cbSJason King# Common Development and Distribution License ("CDDL"), version 1.0.
7*9e3493cbSJason King# You may only use this file in accordance with the terms of version
8*9e3493cbSJason King# 1.0 of the CDDL.
9*9e3493cbSJason King#
10*9e3493cbSJason King# A full copy of the text of the CDDL should have accompanied this
11*9e3493cbSJason King# source.  A copy of the CDDL is also available via the Internet at
12*9e3493cbSJason King# http://www.illumos.org/license/CDDL.
13*9e3493cbSJason King#
14*9e3493cbSJason King# CDDL HEADER END
15*9e3493cbSJason King#
16*9e3493cbSJason King
17*9e3493cbSJason King#
18*9e3493cbSJason King# Copyright (c) 2020, George Amanakis. All rights reserved.
19*9e3493cbSJason King#
20*9e3493cbSJason King
21*9e3493cbSJason King. $STF_SUITE/include/libtest.shlib
22*9e3493cbSJason King. $STF_SUITE/tests/functional/l2arc/l2arc.cfg
23*9e3493cbSJason King. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
24*9e3493cbSJason King
25*9e3493cbSJason King#
26*9e3493cbSJason King# DESCRIPTION:
27*9e3493cbSJason King#	Persistent L2ARC restores all written log blocks with encryption
28*9e3493cbSJason King#
29*9e3493cbSJason King# STRATEGY:
30*9e3493cbSJason King#	1. Create pool with a cache device.
31*9e3493cbSJason King#	2. Create a an encrypted ZFS file system.
32*9e3493cbSJason King#	3. Create a random file in the entrypted file system,
33*9e3493cbSJason King#		smaller than the cache device, and random read for 10 sec.
34*9e3493cbSJason King#	4. Export pool.
35*9e3493cbSJason King#	5. Read amount of log blocks written.
36*9e3493cbSJason King#	6. Import pool.
37*9e3493cbSJason King#	7. Mount the encypted ZFS file system.
38*9e3493cbSJason King#	8. Read amount of log blocks built.
39*9e3493cbSJason King#	9. Compare the two amounts.
40*9e3493cbSJason King#	10. Read the file written in (3) and check if l2_hits in
41*9e3493cbSJason King#		/proc/spl/kstat/zfs/arcstats increased.
42*9e3493cbSJason King#	11. Check if the labels of the L2ARC device are intact.
43*9e3493cbSJason King#
44*9e3493cbSJason King
45*9e3493cbSJason Kingverify_runnable "global"
46*9e3493cbSJason King
47*9e3493cbSJason Kinglog_assert "Persistent L2ARC restores all written log blocks with encryption."
48*9e3493cbSJason King
49*9e3493cbSJason Kingfunction cleanup
50*9e3493cbSJason King{
51*9e3493cbSJason King	if poolexists $TESTPOOL ; then
52*9e3493cbSJason King		destroy_pool $TESTPOOL
53*9e3493cbSJason King	fi
54*9e3493cbSJason King
55*9e3493cbSJason King	log_must set_tunable32 l2arc_noprefetch $noprefetch
56*9e3493cbSJason King}
57*9e3493cbSJason Kinglog_onexit cleanup
58*9e3493cbSJason King
59*9e3493cbSJason King# l2arc_noprefetch is set to 0 to let L2ARC handle prefetches
60*9e3493cbSJason Kingtypeset noprefetch=$(get_tunable l2arc_noprefetch)
61*9e3493cbSJason Kinglog_must set_tunable32 l2arc_noprefetch 0
62*9e3493cbSJason King
63*9e3493cbSJason Kingtypeset fill_mb=800
64*9e3493cbSJason Kingtypeset cache_sz=$(( 2 * $fill_mb ))
65*9e3493cbSJason Kingexport FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
66*9e3493cbSJason King
67*9e3493cbSJason Kinglog_must truncate -s ${cache_sz}M $VDEV_CACHE
68*9e3493cbSJason King
69*9e3493cbSJason Kingtypeset log_blk_start=$(get_arcstat l2_log_blk_writes)
70*9e3493cbSJason King
71*9e3493cbSJason Kinglog_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
72*9e3493cbSJason King
73*9e3493cbSJason Kinglog_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
74*9e3493cbSJason King	"-o keyformat=passphrase $TESTPOOL/$TESTFS1"
75*9e3493cbSJason King
76*9e3493cbSJason Kinglog_must fio $FIO_SCRIPTS/mkfiles.fio
77*9e3493cbSJason Kinglog_must fio $FIO_SCRIPTS/random_reads.fio
78*9e3493cbSJason King
79*9e3493cbSJason Kingarcstat_quiescence_noecho l2_size
80*9e3493cbSJason Kinglog_must zpool export $TESTPOOL
81*9e3493cbSJason Kingarcstat_quiescence_noecho l2_feeds
82*9e3493cbSJason King
83*9e3493cbSJason Kingtypeset log_blk_end=$(get_arcstat l2_log_blk_writes)
84*9e3493cbSJason Kingtypeset log_blk_rebuild_start=$(get_arcstat l2_rebuild_log_blks)
85*9e3493cbSJason King
86*9e3493cbSJason Kinglog_must zpool import -d $VDIR $TESTPOOL
87*9e3493cbSJason Kinglog_must eval "echo $PASSPHRASE | zfs mount -l $TESTPOOL/$TESTFS1"
88*9e3493cbSJason King
89*9e3493cbSJason Kingtypeset l2_hits_start=$(get_arcstat l2_hits)
90*9e3493cbSJason King
91*9e3493cbSJason Kinglog_must fio $FIO_SCRIPTS/random_reads.fio
92*9e3493cbSJason Kingarcstat_quiescence_noecho l2_size
93*9e3493cbSJason King
94*9e3493cbSJason Kingtypeset log_blk_rebuild_end=$(arcstat_quiescence_echo l2_rebuild_log_blks)
95*9e3493cbSJason Kingtypeset l2_hits_end=$(get_arcstat l2_hits)
96*9e3493cbSJason King
97*9e3493cbSJason Kinglog_must test $(( $log_blk_rebuild_end - $log_blk_rebuild_start )) -eq \
98*9e3493cbSJason King	$(( $log_blk_end - $log_blk_start ))
99*9e3493cbSJason King
100*9e3493cbSJason Kinglog_must test $l2_hits_end -gt $l2_hits_start
101*9e3493cbSJason King
102*9e3493cbSJason Kinglog_must zpool offline $TESTPOOL $VDEV_CACHE
103*9e3493cbSJason Kingarcstat_quiescence_noecho l2_size
104*9e3493cbSJason King
105*9e3493cbSJason Kinglog_must zdb -lq $VDEV_CACHE
106*9e3493cbSJason King
107*9e3493cbSJason Kinglog_must zpool destroy -f $TESTPOOL
108*9e3493cbSJason King
109*9e3493cbSJason Kinglog_pass "Persistent L2ARC restores all written log blocks with encryption."
110