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