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 # Use is subject to license terms.
28 . $STF_SUITE/tests/functional/slog/slog.kshlib
32 # Verify slogs are replayed correctly. This test is a direct
33 # adaptation of the ziltest.sh script for the ZFS Test Suite.
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 copy the file system, replay the intent
38 # log and compare the file system and the copy.
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 file system (TESTFS)
50 # 3. Run various user commands that create files, directories and ACLs
51 # 4. Copy TESTFS to temporary location (TESTDIR/copy)
52 # 5. Unmount filesystem
53 # <at this stage TESTFS is empty again and unfrozen, and the
54 # intent log contains a complete set of deltas to replay it>
55 # 6. Remount TESTFS <which replays the intent log>
56 # 7. Compare TESTFS against the TESTDIR/copy
59 verify_runnable "global"
61 log_assert "Replay of intent log succeeds."
66 # 1. Create an empty file system (TESTFS)
68 log_must zpool create $TESTPOOL $VDEV log mirror $LDEV
69 log_must zfs set compression=on $TESTPOOL
70 log_must zfs create $TESTPOOL/$TESTFS
73 # This dd command works around an issue where ZIL records aren't created
74 # after freezing the pool unless a ZIL header already exists. Create a file
75 # synchronously to force ZFS to write one out.
77 log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/sync \
78 conv=fdatasync,fsync bs=1 count=1
83 log_must zpool freeze $TESTPOOL
86 # 3. Run various user commands that create files, directories and ACLs
90 log_must touch /$TESTPOOL/$TESTFS/a
93 log_must mv /$TESTPOOL/$TESTFS/a /$TESTPOOL/$TESTFS/b
96 log_must touch /$TESTPOOL/$TESTFS/c
97 log_must ln -s /$TESTPOOL/$TESTFS/c /$TESTPOOL/$TESTFS/d
100 log_must touch /$TESTPOOL/$TESTFS/e
101 log_must ln /$TESTPOOL/$TESTFS/e /$TESTPOOL/$TESTFS/f
104 log_must mkdir /$TESTPOOL/$TESTFS/dir_to_delete
107 log_must rmdir /$TESTPOOL/$TESTFS/dir_to_delete
109 # Create a simple validation payload
110 log_must mkdir -p $TESTDIR
111 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/payload \
112 oflag=sync bs=1k count=8
113 typeset checksum=$(sha256digest /$TESTPOOL/$TESTFS/payload)
115 # TX_WRITE (small file with ordering)
116 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/small_file \
117 oflag=sync bs=1k count=1
118 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/small_file \
119 oflag=sync bs=512 count=1
121 # TX_CREATE, TX_MKDIR, TX_REMOVE, TX_RMDIR
122 log_must cp -R /usr/share/dict /$TESTPOOL/$TESTFS
123 log_must rm -rf /$TESTPOOL/$TESTFS/dict
126 log_must touch /$TESTPOOL/$TESTFS/setattr
127 log_must chmod 567 /$TESTPOOL/$TESTFS/setattr
129 log_must chgrp wheel /$TESTPOOL/$TESTFS/setattr
131 log_must chgrp root /$TESTPOOL/$TESTFS/setattr
133 log_must touch -cm -t 201311271200 /$TESTPOOL/$TESTFS/setattr
135 # TX_TRUNCATE (to zero)
136 log_must mkfile 4k /$TESTPOOL/$TESTFS/truncated_file
137 log_must truncate -s 0 /$TESTPOOL/$TESTFS/truncated_file
139 # TX_WRITE (large file)
140 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/large \
141 oflag=sync bs=128k count=64
143 # Write zeros, which compress to holes, in the middle of a file
144 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.1 \
145 oflag=sync bs=128k count=8
146 log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.1 \
147 oflag=sync bs=128k count=2
149 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.2 \
150 oflag=sync bs=128k count=8
151 log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.2 \
152 oflag=sync bs=128k count=2 seek=2
154 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.3 \
155 oflag=sync bs=128k count=8
156 log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.3 \
157 oflag=sync bs=128k count=2 seek=2 conv=notrunc
160 log_must mkdir /$TESTPOOL/$TESTFS/xattr.dir
161 log_must touch /$TESTPOOL/$TESTFS/xattr.file
162 log_must set_xattr fileattr HelloWorld /$TESTPOOL/$TESTFS/xattr.dir
163 log_must set_xattr tmpattr HelloWorld /$TESTPOOL/$TESTFS/xattr.dir
164 log_must rm_xattr fileattr /$TESTPOOL/$TESTFS/xattr.dir
166 log_must set_xattr fileattr HelloWorld /$TESTPOOL/$TESTFS/xattr.file
167 log_must set_xattr tmpattr HelloWorld /$TESTPOOL/$TESTFS/xattr.file
168 log_must rm_xattr tmpattr /$TESTPOOL/$TESTFS/xattr.file
170 # TX_WRITE, TX_LINK, TX_REMOVE
171 # Make sure TX_REMOVE won't affect TX_WRITE if file is not destroyed
172 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/link_and_unlink \
173 oflag=sync bs=128k count=8
174 log_must ln /$TESTPOOL/$TESTFS/link_and_unlink \
175 /$TESTPOOL/$TESTFS/link_and_unlink.link
176 log_must rm /$TESTPOOL/$TESTFS/link_and_unlink.link
179 # 4. Copy TESTFS to temporary location (TESTDIR/copy)
181 log_must mkdir -p $TESTDIR/copy
182 log_must cp -a /$TESTPOOL/$TESTFS/* $TESTDIR/copy/
185 # 5. Unmount filesystem and export the pool
187 # At this stage TESTFS is empty again and frozen, the intent log contains
188 # a complete set of deltas to replay.
190 log_must zfs unmount /$TESTPOOL/$TESTFS
192 log_note "Verify transactions to replay:"
193 log_must zdb -iv $TESTPOOL/$TESTFS
195 log_must zpool export $TESTPOOL
198 # 6. Remount TESTFS <which replays the intent log>
200 # Import the pool to unfreeze it and claim log blocks. It has to be
201 # `zpool import -f` because we can't write a frozen pool's labels!
203 log_must zpool import -f -d $VDIR $TESTPOOL
206 # 7. Compare TESTFS against the TESTDIR/copy
208 log_note "Verify current block usage:"
209 log_must zdb -bcv $TESTPOOL
211 log_note "Verify copy of xattrs:"
212 log_must ls_xattr /$TESTPOOL/$TESTFS/xattr.dir
213 log_must ls_xattr /$TESTPOOL/$TESTFS/xattr.file
215 log_note "Verify working set diff:"
216 log_must diff -r /$TESTPOOL/$TESTFS $TESTDIR/copy
218 log_note "Verify file checksum:"
219 typeset checksum1=$(sha256digest /$TESTPOOL/$TESTFS/payload)
220 [[ "$checksum1" == "$checksum" ]] || \
221 log_fail "checksum mismatch ($checksum1 != $checksum)"
223 log_pass "Replay of intent log succeeds."