1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2020, George Amanakis. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/l2arc/l2arc.cfg
23. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
24
25#
26# DESCRIPTION:
27#	Persistent L2ARC with an encrypted ZFS file system succeeds
28#
29# STRATEGY:
30#	1. Create pool with a cache device.
31#	2. Create a an encrypted ZFS file system.
32#	3. Create a random file in the encyrpted file system and random
33#		read for 10 sec.
34#	4. Export pool.
35#	5. Read the amount of log blocks written from the header of the
36#		L2ARC device.
37#	5. Import pool.
38#	6. Mount the encypted ZFS file system.
39#	7. Read the amount of log blocks rebuilt in arcstats and compare to
40#		(5).
41#	8. Check if the labels of the L2ARC device are intact.
42#
43#	* We can predict the minimum bytes of L2ARC restored if we subtract
44#	from the effective size of the cache device the bytes l2arc_evict()
45#	evicts:
46#	l2: L2ARC device size - VDEV_LABEL_START_SIZE - l2ad_dev_hdr_asize
47#	wr_sz: l2arc_write_max + l2arc_write_boost (worst case)
48#	blk_overhead: wr_sz / SPA_MINBLOCKSIZE / (l2 / SPA_MAXBLOCKSIZE) *
49#		sizeof (l2arc_log_blk_phys_t)
50#	min restored size: l2 - (wr_sz + blk_overhead)
51#
52
53verify_runnable "global"
54
55log_assert "Persistent L2ARC with an encrypted ZFS file system succeeds."
56
57function cleanup
58{
59	if poolexists $TESTPOOL ; then
60		destroy_pool $TESTPOOL
61	fi
62
63	log_must set_tunable32 l2arc_noprefetch $noprefetch
64	log_must set_tunable32 l2arc_rebuild_blocks_min_l2size \
65		$rebuild_blocks_min_l2size
66}
67log_onexit cleanup
68
69# l2arc_noprefetch is set to 0 to let L2ARC handle prefetches
70typeset noprefetch=$(get_tunable l2arc_noprefetch)
71typeset rebuild_blocks_min_l2size=$(get_tunable l2arc_rebuild_blocks_min_l2size)
72log_must set_tunable32 l2arc_noprefetch 0
73log_must set_tunable32 l2arc_rebuild_blocks_min_l2size 0
74
75typeset fill_mb=800
76typeset cache_sz=$(( floor($fill_mb / 2) ))
77export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
78
79log_must truncate -s ${cache_sz}M $VDEV_CACHE
80
81log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
82
83log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
84	"-o keyformat=passphrase $TESTPOOL/$TESTFS1"
85
86log_must fio $FIO_SCRIPTS/mkfiles.fio
87log_must fio $FIO_SCRIPTS/random_reads.fio
88
89arcstat_quiescence_noecho l2_size
90log_must zpool export $TESTPOOL
91arcstat_quiescence_noecho l2_feeds
92
93typeset l2_dh_log_blk=$(zdb -l $VDEV_CACHE | grep log_blk_count | \
94	awk '{print $2}')
95
96typeset l2_rebuild_log_blk_start=$(get_arcstat l2_rebuild_log_blks)
97
98log_must zpool import -d $VDIR $TESTPOOL
99log_must eval "echo $PASSPHRASE | zfs mount -l $TESTPOOL/$TESTFS1"
100arcstat_quiescence_noecho l2_size
101
102typeset l2_rebuild_log_blk_end=$(arcstat_quiescence_echo l2_rebuild_log_blks)
103
104log_must test $l2_dh_log_blk -eq $(( $l2_rebuild_log_blk_end - \
105	$l2_rebuild_log_blk_start ))
106log_must test $l2_dh_log_blk -gt 0
107
108log_must zpool offline $TESTPOOL $VDEV_CACHE
109arcstat_quiescence_noecho l2_size
110
111log_must zdb -lq $VDEV_CACHE
112
113log_must zpool destroy -f $TESTPOOL
114
115log_pass "Persistent L2ARC with an encrypted ZFS file system succeeds."
116