1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 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. 8# 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. 13# 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] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28. $STF_SUITE/tests/functional/slog/slog.kshlib 29 30# 31# DESCRIPTION: 32# Verify slogs are replayed correctly. This test is a direct 33# adaptation of the ziltest.sh script for the ZFS Test Suite. 34# 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. 39# 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: 46# 47# STRATEGY: 48# 1. Create an empty file system (TESTFS) 49# 2. Freeze 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 57# 58 59verify_runnable "global" 60 61# As long as we are not running slog_015_neg, the test pool could be hanging 62# around. 63poolexists $TESTPOOL && zpool destroy -f $TESTPOOL 64 65log_assert "Replay of intent log succeeds." 66log_onexit cleanup 67log_must setup 68 69# 70# 1. Create an empty file system (TESTFS) 71# 72log_must zpool create $TESTPOOL $VDEV log mirror $LDEV 73log_must zfs set compression=on $TESTPOOL 74log_must zfs create $TESTPOOL/$TESTFS 75 76# 77# This dd command works around an issue where ZIL records aren't created 78# after freezing the pool unless a ZIL header already exists. Create a file 79# synchronously to force ZFS to write one out. 80# 81log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/sync \ 82 oflag=dsync,sync bs=1 count=1 83 84# 85# 2. Freeze TESTFS 86# 87log_must zpool freeze $TESTPOOL 88 89# 90# 3. Run various user commands that create files, directories and ACLs 91# 92 93# TX_CREATE 94log_must touch /$TESTPOOL/$TESTFS/a 95 96# TX_RENAME 97log_must mv /$TESTPOOL/$TESTFS/a /$TESTPOOL/$TESTFS/b 98 99# TX_SYMLINK 100log_must touch /$TESTPOOL/$TESTFS/c 101log_must ln -s /$TESTPOOL/$TESTFS/c /$TESTPOOL/$TESTFS/d 102 103# TX_LINK 104log_must touch /$TESTPOOL/$TESTFS/e 105log_must ln /$TESTPOOL/$TESTFS/e /$TESTPOOL/$TESTFS/f 106 107# TX_MKDIR 108log_must mkdir /$TESTPOOL/$TESTFS/dir_to_delete 109 110# TX_RMDIR 111log_must rmdir /$TESTPOOL/$TESTFS/dir_to_delete 112 113# Create a simple validation payload 114log_must mkdir -p $TESTDIR 115log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/payload bs=1k count=8 116typeset checksum=$(sha256digest /$TESTPOOL/$TESTFS/payload) 117 118# TX_WRITE (small file with ordering) 119log_must mkfile 1k /$TESTPOOL/$TESTFS/small_file 120log_must mkfile 512b /$TESTPOOL/$TESTFS/small_file 121 122# TX_CREATE, TX_MKDIR, TX_REMOVE, TX_RMDIR 123log_must cp -R /usr/dict /$TESTPOOL/$TESTFS 124log_must rm -rf /$TESTPOOL/$TESTFS/dict 125 126# TX_SETATTR 127log_must touch /$TESTPOOL/$TESTFS/setattr 128log_must chmod 567 /$TESTPOOL/$TESTFS/setattr 129log_must chgrp root /$TESTPOOL/$TESTFS/setattr 130log_must touch -cm -t 201311271200 /$TESTPOOL/$TESTFS/setattr 131 132# TX_TRUNCATE (to zero) 133log_must mkfile 4k /$TESTPOOL/$TESTFS/truncated_file 134log_must truncate -s 0 /$TESTPOOL/$TESTFS/truncated_file 135 136# TX_WRITE (large file) 137log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/large \ 138 bs=128k count=64 oflag=sync 139 140# Write zeros, which compress to holes, in the middle of a file 141log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.1 bs=128k count=8 142log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.1 bs=128k count=2 143 144log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.2 bs=128k count=8 145log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.2 bs=128k count=2 seek=2 146 147log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/holes.3 bs=128k count=8 148log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.3 bs=128k count=2 \ 149 seek=2 conv=notrunc 150 151# TX_MKXATTR 152# log_must mkdir /$TESTPOOL/$TESTFS/xattr.dir 153# log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir 154# log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir 155# log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.dir 156 157# log_must touch /$TESTPOOL/$TESTFS/xattr.file 158# log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file 159# log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file 160# log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.file 161 162# TX_WRITE, TX_LINK, TX_REMOVE 163# Make sure TX_REMOVE won't affect TX_WRITE if file is not destroyed 164log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/link_and_unlink bs=128k \ 165 count=8 166log_must ln /$TESTPOOL/$TESTFS/link_and_unlink \ 167 /$TESTPOOL/$TESTFS/link_and_unlink.link 168log_must rm /$TESTPOOL/$TESTFS/link_and_unlink.link 169 170# 171# 4. Copy TESTFS to temporary location (TESTDIR/copy) 172# 173log_must mkdir -p $TESTDIR/copy 174log_must cp -a /$TESTPOOL/$TESTFS/* $TESTDIR/copy/ 175 176# 177# 5. Unmount filesystem and export the pool 178# 179# At this stage TESTFS is empty again and frozen, the intent log contains 180# a complete set of deltas to replay. 181# 182log_must zfs unmount /$TESTPOOL/$TESTFS 183 184log_note "Verify transactions to replay:" 185log_must zdb -iv $TESTPOOL/$TESTFS 186 187log_must zpool export $TESTPOOL 188 189# 190# 6. Remount TESTFS <which replays the intent log> 191# 192# Import the pool to unfreeze it and claim log blocks. It has to be 193# `zpool import -f` because we can't write a frozen pool's labels! 194# 195log_must zpool import -f -d $VDIR $TESTPOOL 196 197# 198# 7. Compare TESTFS against the TESTDIR/copy 199# 200log_note "Verify current block usage:" 201log_must zdb -bcv $TESTPOOL 202 203# log_note "Verify copy of xattrs:" 204# log_must attr -l /$TESTPOOL/$TESTFS/xattr.dir 205# log_must attr -l /$TESTPOOL/$TESTFS/xattr.file 206 207log_note "Verify working set diff:" 208log_must diff -r /$TESTPOOL/$TESTFS $TESTDIR/copy 209 210log_note "Verify file checksum:" 211typeset checksum1=$(sha256digest /$TESTPOOL/$TESTFS/payload) 212[[ "$checksum1" == "$checksum" ]] || \ 213 log_fail "checksum mismatch ($checksum1 != $checksum)" 214 215log_pass "Replay of intent log succeeds." 216