Skip to content
Permalink
Browse files

fstests: add dm-log-writes test and supporting code

This patch adds the supporting code for using the dm-log-writes target.  The
bash stuff is similar to the dmflakey code, it just gives us functions to build
and tear down a dm-log-writes target.  We add a new LOGWRITES_DEV variable to
take in the device we will use as the log and add checks for that.

I've rigged up fsx to have an integrity check mode.  Basically it works like it
normally works, but when it fsync()'s it marks the log with a unique mark and
dumps it's buffer to a file with the mark in the filename.  I did this with a
system() call simply because it was the fastest.  I can link the device-mapper
libraries and do it programatically if that would be preferred, but this works
pretty well.

The test itself just runs 200 ops and exits, then finds all of the good buffers
in the directory we provided and replays up to the mark given, mounts the file
system and compares the md5sum, unmounts and fsck's to check for metadata
integrity.  dm-log-writes will pretend to do discard and the replay tool will
replay it properly depending on the underlying device, either by writing 0's or
actually calling the discard ioctl, so I've enabled discard in the test for
maximum fun.

This test relies on the supporting userspace code I've written for
dm-logs-writes.  It can be found here

https://github.com/josefbacik/log-writes.git

Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
  • Loading branch information
Josef Bacik
Josef Bacik committed May 18, 2015
1 parent c3d3e1e commit 70d41e17164b2afc9a3f2ae532f084bf64cb4a07
Showing with 374 additions and 19 deletions.
  1. +2 −0 README
  2. +1 −0 common/config
  3. +80 −0 common/dmlogwrites
  4. +46 −0 common/rc
  5. +112 −19 ltp/fsx.c
  6. +130 −0 tests/generic/326
  7. +2 −0 tests/generic/326.out
  8. +1 −0 tests/generic/group
2 README
@@ -78,6 +78,8 @@ Preparing system for tests (IRIX and Linux):
added to the end of fsstresss and fsx invocations, respectively,
in case you wish to exclude certain operational modes from these
tests.
- setenv LOGWRITES_DEV to a block device to use for power fail
testing.

- or add a case to the switch in common/config assigning
these variables based on the hostname of your test
@@ -191,6 +191,7 @@ export WIPEFS_PROG="`set_prog_path wipefs`"
export DUMP_PROG="`set_prog_path dump`"
export RESTORE_PROG="`set_prog_path restore`"
export LVM_PROG="`set_prog_path lvm`"
export REPLAYLOG_PROG="`set_prog_path replay-log`"

# Generate a comparable xfsprogs version number in the form of
# major * 10000 + minor * 100 + release
@@ -0,0 +1,80 @@
##/bin/bash
#
# Copyright (c) 2015 Facebook, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
#
# common functions for setting up and tearing down a dm log-writes device

_init_log_writes()
{
local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
LOGWRITES_NAME=logwrites-test
LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME
LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $SCRATCH_DEV $LOGWRITES_DEV"
$DMSETUP_PROG create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \
_fatal "failed to create log-writes device"
$DMSETUP_PROG mknodes > /dev/null 2>&1
}

_log_writes_mark()
{
[ $# -ne 1 ] && _fatal "_log_writes_mark takes one argument"
$DMSETUP_PROG message $LOGWRITES_NAME 0 mark $1
}

_log_writes_mkfs()
{
_scratch_options mkfs
_mkfs_dev $SCRATCH_OPTIONS $LOGWRITES_DMDEV
_log_writes_mark mkfs
}

_mount_log_writes()
{
mount -t $FSTYP $MOUNT_OPTIONS $* $LOGWRITES_DMDEV $SCRATCH_MNT
}

_unmount_log_writes()
{
$UMOUNT_PROG $SCRATCH_MNT
}

# _replay_log <mark>
#
# This replays the log contained on $INTEGRITY_DEV onto $SCRATCH_DEV upto the
# mark passed in.
_replay_log()
{
_mark=$1

$REPLAYLOG_PROG --log $LOGWRITES_DEV --replay $SCRATCH_DEV \
--end-mark $_mark > /dev/null 2>&1
[ $? -ne 0 ] && _fatal "replay failed"
}

_log_writes_remove()
{
$DMSETUP_PROG remove $LOGWRITES_NAME > /dev/null 2>&1
$DMSETUP_PROG mknodes > /dev/null 2>&1
}

_cleanup_log_writes()
{
# If dmsetup load fails then we need to make sure to do resume here
# otherwise the umount will hang
$UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
_log_writes_remove
}
@@ -1357,6 +1357,24 @@ _require_dm_snapshot()
fi
}

# this test requires the device mapper log-writes target
#
_require_dm_log_writes()
{
[ -z $LOGWRITES_DEV ] && _notrun "This test requires a logwrites dev"
_require_block_device $SCRATCH_DEV
_require_block_device $LOGWRITES_DEV
_require_command $DMSETUP_PROG
_require_command $REPLAYLOG_PROG

modprobe dm-log-writes >/dev/null 2>&1
$DMSETUP_PROG targets | grep "log-writes" > /dev/null 2>&1
if [ $? -ne 0 ]
then
_notrun "This test requires dm log-writes support"
fi
}

# this test requires the projid32bit feature to be available in mkfs.xfs.
#
_require_projid32bit()
@@ -1591,6 +1609,34 @@ _require_xfs_io_command()
_notrun "xfs_io $command failed (old kernel/wrong fs?)"
}

_test_falloc_support()
{
if [ $# -ne 1 ]
then
echo "Usage: _test_falloc_support command" 1>&2
exit 1
fi
command=$1

testfile=$TEST_DIR/$$.xfs_io
case $command in
"fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "$command 4k 8k" $testfile 2>&1`
;;
*)
echo "Not a valid falloc command" 1>&2
exit 1
esac

rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
return 0
echo $testio | grep -q "Operation not supported" && \
return 0
return 1
}

# check that kernel and filesystem support direct I/O
_require_odirect()
{

0 comments on commit 70d41e1

Please sign in to comment.
You can’t perform that action at this time.