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 slog replay correctly when TX_REMOVEs are followed by
36 # 1. Create a file system (TESTFS) with a lot of files
38 # 3. Remove all files then create a lot of files
39 # 4. Copy TESTFS to temporary location (TESTDIR/copy)
40 # 5. Unmount filesystem
41 # <at this stage TESTFS is empty again and unfrozen, and the
42 # intent log contains a complete set of deltas to replay it>
43 # 6. Remount TESTFS <which replays the intent log>
44 # 7. Compare TESTFS against the TESTDIR/copy
47 verify_runnable "global"
54 log_assert "Replay of intent log succeeds."
59 # 1. Create a file system (TESTFS) with a lot of files
61 log_must zpool create $TESTPOOL $VDEV log mirror $LDEV
62 log_must zfs set compression=on $TESTPOOL
63 log_must zfs create $TESTPOOL/$TESTFS
65 # Prep for the test of TX_REMOVE followed by TX_CREATE
66 dnsize=(legacy auto 1k 2k 4k 8k 16k)
68 log_must mkdir /$TESTPOOL/$TESTFS/dir0
69 log_must eval 'for i in $(seq $NFILES); do zfs set dnodesize=${dnsize[$RANDOM % ${#dnsize[@]}]} $TESTPOOL/$TESTFS; touch /$TESTPOOL/$TESTFS/dir0/file.$i; done'
72 # Reimport to reset dnode allocation pointer.
73 # This is to make sure we will have TX_REMOVE and TX_CREATE on same id
75 log_must zpool export $TESTPOOL
76 log_must zpool import -f -d $VDIR $TESTPOOL
79 # This dd command works around an issue where ZIL records aren't created
80 # after freezing the pool unless a ZIL header already exists. Create a file
81 # synchronously to force ZFS to write one out.
83 log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/sync \
84 conv=fdatasync,fsync bs=1 count=1
89 log_must zpool freeze $TESTPOOL
92 # 3. Remove all files then create a lot of files
94 # TX_REMOVE followed by TX_CREATE
95 log_must eval 'rm -f /$TESTPOOL/$TESTFS/dir0/*'
96 log_must eval 'for i in $(seq $NFILES); do zfs set dnodesize=${dnsize[$RANDOM % ${#dnsize[@]}]} $TESTPOOL/$TESTFS; touch /$TESTPOOL/$TESTFS/dir0/file.$i; done'
99 # 4. Copy TESTFS to temporary location (TESTDIR/copy)
101 log_must mkdir -p $TESTDIR/copy
102 log_must cp -a /$TESTPOOL/$TESTFS/* $TESTDIR/copy/
105 # 5. Unmount filesystem and export the pool
107 # At this stage TESTFS is empty again and frozen, the intent log contains
108 # a complete set of deltas to replay.
110 log_must zfs unmount /$TESTPOOL/$TESTFS
112 log_note "Verify transactions to replay:"
113 log_must zdb -iv $TESTPOOL/$TESTFS
115 log_must zpool export $TESTPOOL
118 # 6. Remount TESTFS <which replays the intent log>
120 # Import the pool to unfreeze it and claim log blocks. It has to be
121 # `zpool import -f` because we can't write a frozen pool's labels!
123 log_must zpool import -f -d $VDIR $TESTPOOL
126 # 7. Compare TESTFS against the TESTDIR/copy
128 log_note "Verify current block usage:"
129 log_must zdb -bcv $TESTPOOL
131 log_note "Verify number of files"
132 log_must test "$(ls /$TESTPOOL/$TESTFS/dir0 | wc -l)" -eq $NFILES
134 log_note "Verify working set diff:"
135 log_must diff -r /$TESTPOOL/$TESTFS $TESTDIR/copy
137 log_pass "Replay of intent log succeeds."