5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
26 # Use is subject to license terms.
29 .
$STF_SUITE/tests
/functional
/slog
/slog.kshlib
33 # Verify slogs are replayed correctly for a volume.
35 # The general idea is to build up an intent log from a bunch of
36 # diverse user commands without actually committing them to the
37 # file system. Then generate checksums for files and volume,
38 # replay the intent log and verify the checksums.
40 # To enable this automated testing of the intent log some minimal
41 # support is required of the file system. In particular, a
42 # "freeze" command is required to flush the in-flight transactions;
43 # to stop the actual committing of transactions; and to ensure no
44 # deltas are discarded. All deltas past a freeze point are kept
45 # for replay and comparison later. Here is the flow:
48 # 1. Create an empty volume (TESTVOL), set sync=always, and format
49 # it with an ext4 filesystem and mount it.
51 # 3. Create log records of various types to verify replay.
52 # 4. Generate checksums for all ext4 files.
53 # 5. Unmount filesystem and export the pool
54 # <at this stage TESTVOL is empty again and unfrozen, and the
55 # intent log contains a complete set of deltas to replay it>
56 # 6. Import TESTVOL <which replays the intent log> and mount it.
57 # 7. Verify the stored checksums
60 verify_runnable
"global"
62 VOLUME
=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL
63 MNTPNT
=$TESTDIR/$TESTVOL
66 function cleanup_volume
68 if ismounted
$MNTPNT $FSTYPE; then
69 log_must umount
$MNTPNT
73 rm -f $TESTDIR/checksum.files
78 log_assert
"Replay of intent log succeeds."
79 log_onexit cleanup_volume
83 # 1. Create an empty volume (TESTVOL), set sync=always, and format
84 # it with an ext4 filesystem and mount it.
86 log_must zpool create
$TESTPOOL ${DISKS%% *}
87 log_must zfs create
-V 128M
$TESTPOOL/$TESTVOL
88 log_must zfs
set compression
=on
$TESTPOOL/$TESTVOL
89 log_must zfs
set sync
=always
$TESTPOOL/$TESTVOL
90 log_must mkdir
-p $TESTDIR
94 log_must new_fs
-t ext4
-v $VOLUME
95 log_must mkdir
-p $MNTPNT
96 log_must mount
-o discard
$VOLUME $MNTPNT
98 log_must
rmdir $MNTPNT/lost
+found
100 log_must new_fs
$VOLUME
101 log_must mkdir
-p $MNTPNT
102 log_must mount
$VOLUME $MNTPNT
103 FSTYPE
=$NEWFS_DEFAULT_FS
110 log_must zpool freeze
$TESTPOOL
113 # 3. Create log records of various types to verify replay.
117 log_must
dd if=/dev
/urandom of
=$MNTPNT/latency-8k bs
=8k count
=1 oflag
=sync
118 log_must
dd if=/dev
/urandom of
=$MNTPNT/latency-128k bs
=128k count
=1 oflag
=sync
120 # TX_WRITE (WR_INDIRECT)
121 log_must zfs
set logbias
=throughput
$TESTPOOL/$TESTVOL
122 log_must
dd if=/dev
/urandom of
=$MNTPNT/throughput-8k bs
=8k count
=1
123 log_must
dd if=/dev
/urandom of
=$MNTPNT/throughput-128k bs
=128k count
=1
126 log_must
dd if=/dev
/urandom of
=$MNTPNT/holes bs
=128k count
=8
127 log_must
dd if=/dev
/zero of
=$MNTPNT/holes bs
=128k count
=2 seek
=2 conv
=notrunc
131 if fallocate
--punch-hole 2>&1 |
grep -q "unrecognized option"; then
132 log_note
"fallocate(1) does not support --punch-hole"
134 log_must
dd if=/dev
/urandom of
=$MNTPNT/discard bs
=128k count
=16
135 log_must fallocate
--punch-hole -l 128K
-o 512K
$MNTPNT/discard
136 log_must fallocate
--punch-hole -l 512K
-o 1M
$MNTPNT/discard
141 # 4. Generate checksums for all ext4 files.
143 typeset checksum
=$
(cat $MNTPNT/* | sha256digest
)
146 # 5. Unmount filesystem and export the pool
148 # At this stage TESTVOL is initialized with the random data and frozen,
149 # the intent log contains a complete set of deltas to replay.
151 log_must umount
$MNTPNT
153 log_note
"Verify transactions to replay:"
154 log_must zdb
-iv $TESTPOOL/$TESTVOL
156 log_must zpool
export $TESTPOOL
159 # 6. Import TESTPOOL, the intent log is replayed during minor creation.
161 # Import the pool to unfreeze it and claim log blocks. It has to be
162 # `zpool import -f` because we can't write a frozen pool's labels!
164 log_must zpool import
-f $TESTPOOL
166 log_must mount
$VOLUME $MNTPNT
169 # 7. Verify the stored checksums
171 log_note
"Verify current block usage:"
172 log_must zdb
-bcv $TESTPOOL
174 log_note
"Verify checksums"
175 typeset checksum1
=$
(cat $MNTPNT/* | sha256digest
)
176 [[ "$checksum1" == "$checksum" ]] || \
177 log_fail
"checksum mismatch ($checksum1 != $checksum)"
179 log_pass
"Replay of intent log succeeds."