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 24# 25# DESCRIPTION: 26# Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present. 27# 28# STRATEGY: 29# 1. Create pool with a cache device. 30# 2. Create a random file in that pool and random read for 10 sec. 31# 3. Offline the L2ARC device. 32# 4. Read the amount of log blocks written from the header of the 33# L2ARC device. 34# 5. Online the L2ARC device. 35# 6. Read the amount of log blocks rebuilt in arcstats and compare to 36# (4). 37# 7. Check if the labels of the L2ARC device are intact. 38# 39 40verify_runnable "global" 41 42command -v fio > /dev/null || log_unsupported "fio missing" 43 44log_assert "Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present." 45 46function cleanup 47{ 48 if poolexists $TESTPOOL ; then 49 destroy_pool $TESTPOOL 50 fi 51 52 log_must set_tunable32 L2ARC_NOPREFETCH $noprefetch 53 log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE \ 54 $rebuild_blocks_min_l2size 55} 56log_onexit cleanup 57 58# L2ARC_NOPREFETCH is set to 0 to let L2ARC handle prefetches 59typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH) 60typeset rebuild_blocks_min_l2size=$(get_tunable L2ARC_REBUILD_BLOCKS_MIN_L2SIZE) 61log_must set_tunable32 L2ARC_NOPREFETCH 0 62log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE 0 63 64typeset fill_mb=800 65typeset cache_sz=$(( floor($fill_mb / 2) )) 66export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M 67 68log_must truncate -s ${cache_sz}M $VDEV_CACHE 69 70log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE 71 72log_must fio $FIO_SCRIPTS/mkfiles.fio 73log_must fio $FIO_SCRIPTS/random_reads.fio 74 75arcstat_quiescence_noecho l2_size 76log_must zpool offline $TESTPOOL $VDEV_CACHE 77arcstat_quiescence_noecho l2_size 78 79typeset l2_rebuild_log_blk_start=$(get_arcstat l2_rebuild_log_blks) 80typeset l2_dh_log_blk=$(zdb -l $VDEV_CACHE | awk '/log_blk_count/ {print $2}') 81 82log_must zpool online $TESTPOOL $VDEV_CACHE 83arcstat_quiescence_noecho l2_size 84 85typeset l2_rebuild_log_blk_end=$(arcstat_quiescence_echo l2_rebuild_log_blks) 86 87# Upon onlining the cache device we might write additional blocks to it 88# before it is marked for rebuild as the l2ad_* parameters are not cleared 89# when offlining the device. See comment in l2arc_rebuild_vdev(). 90# So we cannot compare the amount of rebuilt log blocks to the amount of log 91# blocks read from the header of the device. 92log_must test $(( $l2_rebuild_log_blk_end - \ 93 $l2_rebuild_log_blk_start )) -gt 0 94log_must test $l2_dh_log_blk -gt 0 95 96log_must zpool offline $TESTPOOL $VDEV_CACHE 97arcstat_quiescence_noecho l2_size 98 99log_must zdb -lq $VDEV_CACHE 100 101log_must zpool destroy -f $TESTPOOL 102 103log_pass "Off/onlining an L2ARC device results in rebuilding L2ARC, vdev present." 104