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 restores all written log blocks with encryption 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 entrypted file system, 33# smaller than the cache device, and random read for 10 sec. 34# 4. Export pool. 35# 5. Read amount of log blocks written. 36# 6. Import pool. 37# 7. Mount the encypted ZFS file system. 38# 8. Read amount of log blocks built. 39# 9. Compare the two amounts. 40# 10. Read the file written in (3) and check if l2_hits in 41# /proc/spl/kstat/zfs/arcstats increased. 42# 11. Check if the labels of the L2ARC device are intact. 43# 44 45verify_runnable "global" 46 47log_assert "Persistent L2ARC restores all written log blocks with encryption." 48 49function cleanup 50{ 51 if poolexists $TESTPOOL ; then 52 destroy_pool $TESTPOOL 53 fi 54 55 log_must set_tunable32 l2arc_noprefetch $noprefetch 56} 57log_onexit cleanup 58 59# l2arc_noprefetch is set to 0 to let L2ARC handle prefetches 60typeset noprefetch=$(get_tunable l2arc_noprefetch) 61log_must set_tunable32 l2arc_noprefetch 0 62 63typeset fill_mb=800 64typeset cache_sz=$(( 2 * $fill_mb )) 65export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M 66 67log_must truncate -s ${cache_sz}M $VDEV_CACHE 68 69typeset log_blk_start=$(get_arcstat l2_log_blk_writes) 70 71log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE 72 73log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ 74 "-o keyformat=passphrase $TESTPOOL/$TESTFS1" 75 76log_must fio $FIO_SCRIPTS/mkfiles.fio 77log_must fio $FIO_SCRIPTS/random_reads.fio 78 79arcstat_quiescence_noecho l2_size 80log_must zpool export $TESTPOOL 81arcstat_quiescence_noecho l2_feeds 82 83typeset log_blk_end=$(get_arcstat l2_log_blk_writes) 84typeset log_blk_rebuild_start=$(get_arcstat l2_rebuild_log_blks) 85 86log_must zpool import -d $VDIR $TESTPOOL 87log_must eval "echo $PASSPHRASE | zfs mount -l $TESTPOOL/$TESTFS1" 88 89typeset l2_hits_start=$(get_arcstat l2_hits) 90 91log_must fio $FIO_SCRIPTS/random_reads.fio 92arcstat_quiescence_noecho l2_size 93 94typeset log_blk_rebuild_end=$(arcstat_quiescence_echo l2_rebuild_log_blks) 95typeset l2_hits_end=$(get_arcstat l2_hits) 96 97log_must test $(( $log_blk_rebuild_end - $log_blk_rebuild_start )) -eq \ 98 $(( $log_blk_end - $log_blk_start )) 99 100log_must test $l2_hits_end -gt $l2_hits_start 101 102log_must zpool offline $TESTPOOL $VDEV_CACHE 103arcstat_quiescence_noecho l2_size 104 105log_must zdb -lq $VDEV_CACHE 106 107log_must zpool destroy -f $TESTPOOL 108 109log_pass "Persistent L2ARC restores all written log blocks with encryption." 110