]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/persist_l2arc/persist_l2arc_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / persist_l2arc / persist_l2arc_001_pos.ksh
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/persist_l2arc/persist_l2arc.cfg
23
24 #
25 # DESCRIPTION:
26 #       Persistent L2ARC with an unencrypted ZFS file system succeeds
27 #
28 # STRATEGY:
29 #       1. Create pool with a cache device.
30 #       2. Export and re-import pool without writing any data.
31 #       3. Create a random file in that pool and random read for 30 sec.
32 #       4. Export pool.
33 #       5. Read the amount of log blocks written from the header of the
34 #               L2ARC device.
35 #       6. Import pool.
36 #       7. Read the amount of log blocks rebuilt in arcstats and compare to
37 #               (4).
38 #       8. Check if the labels of the L2ARC device are intact.
39 #
40 #       * We can predict the minimum bytes of L2ARC restored if we subtract
41 #       from the effective size of the cache device the bytes l2arc_evict()
42 #       evicts:
43 #       l2: L2ARC device size - VDEV_LABEL_START_SIZE - l2ad_dev_hdr_asize
44 #       wr_sz: l2arc_write_max + l2arc_write_boost (worst case)
45 #       blk_overhead: wr_sz / SPA_MINBLOCKSIZE / (l2 / SPA_MAXBLOCKSIZE) *
46 #               sizeof (l2arc_log_blk_phys_t)
47 #       min restored size: l2 - (wr_sz + blk_overhead)
48 #
49
50 verify_runnable "global"
51
52 log_assert "Persistent L2ARC with an unencrypted ZFS file system succeeds."
53
54 function cleanup
55 {
56         if poolexists $TESTPOOL ; then
57                 destroy_pool $TESTPOOL
58         fi
59
60         log_must set_tunable32 L2ARC_NOPREFETCH $noprefetch
61         log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE \
62                 $rebuild_blocks_min_l2size
63 }
64 log_onexit cleanup
65
66 # L2ARC_NOPREFETCH is set to 0 to let L2ARC handle prefetches
67 typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH)
68 typeset rebuild_blocks_min_l2size=$(get_tunable L2ARC_REBUILD_BLOCKS_MIN_L2SIZE)
69 log_must set_tunable32 L2ARC_NOPREFETCH 0
70 log_must set_tunable32 L2ARC_REBUILD_BLOCKS_MIN_L2SIZE 0
71
72 typeset fill_mb=800
73 typeset cache_sz=$(( floor($fill_mb / 2) ))
74 export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
75
76 log_must truncate -s ${cache_sz}M $VDEV_CACHE
77
78 log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
79
80 log_must zpool export $TESTPOOL
81 log_must zpool import -d $VDIR $TESTPOOL
82
83 log_must fio $FIO_SCRIPTS/mkfiles.fio
84 log_must fio $FIO_SCRIPTS/random_reads.fio
85
86 log_must zpool export $TESTPOOL
87
88 typeset l2_dh_log_blk=$(zdb -l $VDEV_CACHE | grep log_blk_count | \
89         awk '{print $2}')
90
91 typeset l2_rebuild_log_blk_start=$(get_arcstat l2_rebuild_log_blks)
92
93 log_must zpool import -d $VDIR $TESTPOOL
94
95 sleep 2
96
97 typeset l2_rebuild_log_blk_end=$(get_arcstat l2_rebuild_log_blks)
98
99 log_must test $l2_dh_log_blk -eq $(( $l2_rebuild_log_blk_end - $l2_rebuild_log_blk_start ))
100 log_must test $l2_dh_log_blk -gt 0
101
102 log_must zdb -lll $VDEV_CACHE
103
104 log_must zpool destroy -f $TESTPOOL
105
106 log_pass "Persistent L2ARC with an unencrypted ZFS file system succeeds."