]>
git.proxmox.com Git - mirror_zfs-debian.git/blob - scripts/ziltest.sh
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # To run just type ziltest.sh
31 # - creates a 200MB pool in /var/tmp/
32 # - prints information on:
36 # verification results
37 # - returns status of 0 on success
39 ##########################################################################
41 # Here's how it all works:
43 # The general idea is to build up
44 # an intent log from a bunch of diverse user commands
45 # without actually committing them to the file system.
46 # Then copy the file system, replay the intent
47 # log and compare the file system and the copy.
49 # To enable this automated testing of the intent log
50 # requires some but minimal support from the file system.
51 # In particular, a "freeze" command is required to flush
52 # the in-flight transactions; to stop the actual
53 # committing of transactions; and to ensure no deltas are
54 # discarded. All deltas past a freeze point are kept for
55 # replay and comparison later. Here is the flow:
57 # create an empty file system (FS)
59 # run various user commands that create files, directories and ACLs
60 # copy FS to temporary location (COPY)
62 # <at this stage FS is empty again and unfrozen, and the
63 # intent log contains a complete set of deltas to replay it>
64 # remount FS <which replays the intent log>
65 # compare FS against the COPY
74 # ====================================================================
76 # ====================================================================
79 DEVSIZE
=${DEVSIZE-200m}
81 POOLFILE
=$POOLDIR/ziltest_poolfile.$$
82 SLOGFILE
=$POOLDIR/ziltest_slog.$$
91 echo "$CMD: pool I/O summary & status:"
92 echo "----------------------------------------------------"
96 echo "----------------------------------------------------"
98 zpool destroy
-f $POOL
100 rm $POOLFILE $SLOGFILE
105 test $KEEP = no
&& cleanup
110 test $# -eq 0 || bail
"usage: $CMD"
112 # ====================================================================
115 # Create a pool using a file based vdev
116 # Create a destination for runtime copy of FS
117 # Freeze transaction syncing in the pool
118 # ====================================================================
119 truncate
-s "$DEVSIZE" $POOLFILE || bail
"can't make $POOLFILE"
120 truncate
-s "$DEVSIZE" $SLOGFILE || bail
"can't make $SLOGFILE"
121 zpool create
$POOL $POOLFILE log
$SLOGFILE || bail
"can't create pool
125 zfs
set compression
=on
$POOL || bail
"can't enable compression on $POOL"
126 zfs create
$FS || bail
"can't create $FS"
127 mkdir
-p $COPY || bail
"can't create $COPY"
130 # This dd command works around an issue where ZIL records aren't created
131 # after freezing the pool unless a ZIL header already exists. Create a file
132 # synchronously to force ZFS to write one out.
134 dd if=/dev
/zero of
=$ROOT/sync conv
=fdatasync
,fsync bs
=1 count
=1 2> /dev
/null
136 zpool freeze
$POOL || bail
"can't freeze $POOL"
138 # ====================================================================
141 # Add operations here that will add commit records to the ZIL
143 # Use $ROOT for all file name prefixes
144 # ====================================================================
160 ln -s $ROOT/c
$ROOT/d
171 mkdir
$ROOT/dir_to_delete
176 rmdir $ROOT/dir_to_delete
179 # Create a simple validation payload
181 PAYLOAD
=$
(modinfo
-F filename zfs
)
182 cp "$PAYLOAD" "$ROOT/payload"
183 CHECKSUM_BEFORE
=$
(sha256sum
-b "$PAYLOAD")
186 # TX_WRITE (small file with ordering)
188 cp /etc
/mtab
$ROOT/small_file
189 cp /etc
/profile
$ROOT/small_file
192 # TX_CREATE, TX_MKDIR, TX_REMOVE, TX_RMDIR
194 cp -R /usr
/share
/dict
$ROOT
201 chmod 567 $ROOT/setattr
202 chgrp root
$ROOT/setattr
203 touch -cm -t 201311271200 $ROOT/setattr
206 # TX_TRUNCATE (to zero)
208 cp /etc
/services
$ROOT/truncated_file
209 > $ROOT/truncated_file
212 # Write to an open but removed file
214 (sleep 2; date) > $ROOT/date & sleep 1; rm $ROOT/date; wait
217 # TX_WRITE (large file)
219 dd if=/usr
/share
/lib
/termcap of
=$ROOT/large bs
=128k oflag
=sync
2> /dev
/null
222 # Write zeroes, which compresss to holes, in the middle of a file
224 dd if=$POOLFILE of
=$ROOT/holes
.1 bs
=128k count
=8 2> /dev
/null
225 dd if=/dev
/zero of
=$ROOT/holes
.1 bs
=128k count
=2 2> /dev
/null
227 dd if=$POOLFILE of
=$ROOT/holes
.2 bs
=128k count
=8 2> /dev
/null
228 dd if=/dev
/zero of
=$ROOT/holes
.2 bs
=128k count
=2 oseek
=2 2> /dev
/null
230 dd if=$POOLFILE of
=$ROOT/holes
.3 bs
=128k count
=8 2> /dev
/null
231 dd if=/dev
/zero of
=$ROOT/holes
.3 bs
=128k count
=2 oseek
=2 conv
=notrunc
2> /dev
/null
236 mkdir
$ROOT/xattr.dir
237 attr
-qs fileattr
-V HelloWorld
$ROOT/xattr.dir
238 attr
-qs tmpattr
-V HelloWorld
$ROOT/xattr.dir
239 attr
-qr tmpattr
$ROOT/xattr.dir
241 touch $ROOT/xattr.
file
242 attr
-qs fileattr
-V HelloWorld
$ROOT/xattr.
file
243 attr
-qs tmpattr
-V HelloWorld
$ROOT/xattr.
file
244 attr
-qr tmpattr
$ROOT/xattr.
file
248 # ====================================================================
250 # ====================================================================
252 KEEP
=yes # keep stuff around if we fail, so we can look at it
255 find . |
cpio -pdmu --quiet $COPY
259 zfs unmount
$FS || bail
"can't unmount $FS"
261 echo "$CMD: transactions to replay:"
262 echo "----------------------------------------------------"
263 zdb
-ivv $FS || bail
"can't run zdb on $POOL"
264 echo "----------------------------------------------------"
268 # Export and reimport the pool to unfreeze it and claim log blocks.
269 # It has to be import -f because we can't write a frozen pool's labels!
271 zpool
export $POOL || bail
"can't export $POOL"
272 zpool import
-f -d $POOLDIR $POOL || bail
"can't import $POOL"
274 # ====================================================================
276 # ====================================================================
278 echo "$CMD: current block usage:"
279 echo "----------------------------------------------------"
280 zdb
-bcv $POOL || bail
"blocks were leaked!"
281 echo "----------------------------------------------------"
284 echo "$CMD: Copy of xattrs:"
285 echo "----------------------------------------------------"
286 attr
-l $ROOT/xattr.dir || bail
"can't list xattrs"
287 echo "----------------------------------------------------"
290 echo "$CMD: Results of workingset diff:"
291 echo "----------------------------------------------------"
292 diff -r $ROOT $COPY > /dev
/null ||
diff -r $ROOT $COPY || bail
"replay diffs!"
294 echo "$CHECKSUM_BEFORE" | sha256sum
-c || bail
"payload checksums don't match"
295 echo "payload checksum matched"
296 echo "----------------------------------------------------"