Skip to contentSkip to conversation

Device mapper log writes patches

PATCH In review Josef Bacik 7 participants 14 messages Mar 19, 2015 – Apr 7, 2015

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Device mapper log writes patches

Here are my patches for adding the dm-log-writes target to the kernel and the supporting xfstests to go along with it. The dm patch has a pretty detailed documentation file to describe the methodology behind the target and how to use it. The xfstest that is generic has been tested on btrfs, xfs and ext4 and currently fails on all of them in different ways with my kernel (which is just 3.19 so don't be too alarmed). The btrfs specific one passes currently, more evil tests will come later.

Basically the idea behind this target and these tests are to give our file systems a more thorough power fail scenario testing. The target logs writes in order that things would have made it safely to disk and then the tests replay that log in various ways and check the result.

You can find the supporting userspace program here

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

I apologize for it being ugly, I was trying to get it working as quickly as possible. There is an example script in there that you can use to do an exhaustive step by step through a log to make sure your file system is always consistent. Thanks,

Josef

#1 lore raw

PATCH 1/3 dm: log writes target

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

---
 Documentation/device-mapper/dm-log-writes.txt | 136 +++++
 drivers/md/Kconfig                            |  16 +
 drivers/md/Makefile                           |   1 +
 drivers/md/dm-log-writes.c                    | 809 ++++++++++++++++++++++++++
 4 files changed, 962 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-log-writes.txt
 create mode 100644 drivers/md/dm-log-writes.c
Documentation/device-mapper/dm-log-writes.txt new file +136 -0
new file mode 100644
index 0000000..f3a9fa2
@@ -0,0 +1,136 @@
+dm-log-writes
+=============
+
+This target takes 2 devices, one to pass all IO to normally, and one to log all
+of the write operations to.  This is intended for file system developers wishing
+to verify the integrity of metadata or data as the file system is written to.
+There is a log_writes_entry written for every WRITE request and the target is
+able to take arbitrary data from userspace to insert into the log.  The data
+that is in the WRITE requests is copied into the log to make the replay happen
+exactly as it happened originally.
+
+Log Ordering
+============
+
+We log things in order of completion once we are sure the write is no longer in
+cache.  This means that normal WRITE requests are not actually logged until the
+next REQ_FLUSH request.  This is to make it easier for userspace to replay the
+log in a way that correlates to what is on disk and not what is in cache, to
+make it easier to detect improper waiting/flushing.
+
+This works by attaching all WRITE requests to a list once the write completes.
+Once we see a REQ_FLUSH request we splice this list onto the request and once
+the FLUSH request completes we log all of the WRITE's and then the FLUSH.  Only
+completeled WRITEs at the time of the issue of the REQ_FLUSH are added in order
+to simulate the worst case scenario with regard to power failures.  Consider the
+following example (W means write, C means complete)
+
+W1,W2,W3,C3,C2,Wflush,C1,Cflush
+
+The log would show the following
+
+W3,W2,flush,W1....
+
+Again this is to simulate what is actually on disk, this allows us to detect
+cases where a power failure at a particular point in time would create an
+inconsistent file system.
+
+Any REQ_FUA requests bypass this flushing mechanism and are logged as soon as
+they complete as those requests will obviously bypass the device cache.
+
+Any REQ_DISCARD requests are treated like WRITE requests.  This is because
+otherwise we would have all the DISCARD requests, and then the WRITE requests
+and then the FLUSH request.  Consider the following example
+
+WRITE block 1, DISCARD block 1, FLUSH
+
+If we logged DISCARD when it completed, the replay would look like this
+
+DISCARD 1, WRITE 1, FLUSH
+
+which isn't quite what happened and wouldn't be caught during the log replay.
+
+Marks
+=====
+
+You can use dmsetup to set an arbitrary mark in a log.  For example say you want
+to fsck an file system after every write, but first you need to replay up to the
+mkfs to make sure we're fsck'ing something reasonable, you would do something
+like this
+
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+<run test>
+
+This would allow you to replay the log up to the mkfs mark and then replay from
+that point on doing the fsck check in the interval that you want.
+
+Every log has a mark at the end labeled "log-writes-end".
+
+Userspace component
+===================
+
+There is a userspace tool that will replay the log for you in various ways.
+As of this writing the options are not well documented, they will be in the
+future.  It can be found here
+
+https://github.com/josefbacik/log-writes
+
+Example usage
+=============
+
+Say you want to test fsync on your file system.  You would do something like
+this
+
+TABLE="0 $(blockdev --getsz /dev/sdb) log-writes /dev/sdb /dev/sdc"
+dmsetup create log --table "$TABLE"
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+
+mount /dev/mapper/log /mnt/btrfs-test
+<some test that does fsync at the end>
+dmsetup message log 0 mark fsync
+md5sum /mnt/btrfs-test/foo
+umount /mnt/btrfs-test
+
+dmsetup remove log
+replay-log --log /dev/sdc --replay /dev/sdb --end-mark fsync
+mount /dev/sdb /mnt/btrfs-test
+md5sum /mnt/btrfs-test/foo
+<verify md5sum's are correct>
+
+Another option is to do a complicated file system operation and verify the file
+system is consistent during the entire operation.  You could do this by doing
+
+
+TABLE="0 $(blockdev --getsz /dev/sdb) log-writes /dev/sdb /dev/sdc"
+dmsetup create log --table "$TABLE"
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+
+mount /dev/mapper/log /mnt/btrfs-test
+<fsstress to dirty the fs>
+btrfs filesystem balance /mnt/btrfs-test
+umount /mnt/btrfs-test
+dmsetup remove log
+
+replay-log --log /dev/sdc --replay /dev/sdb --end-mark mkfs
+btrfsck /dev/sdb
+replay-log --log /dev/sdc --replay /dev/sdb --start-mark mkfs \
+	--fsck "btrfsck /dev/sdb" --check fua
+
+And that will replay the log until it sees a FUA request, run the fsck command
+and if the fsck passes it will replay to the next FUA, until it is completed or
+the fsck command exists abnormally.
+
+Table Parameters
+----------------
+  <dev path> <dev path for log>
+
+Mandatory parameters:
+  <dev path>: Full pathname to the underlying block-device, or a "major:minor"
+              device-number.  This device is the one that all of the IO will go
+              to normally, just think of it as a normal linear mapping.
+  <dev path for log>: Same format as <dev path>, this is the device where the
+                      log entries are written to.
+
drivers/md/Kconfig +16 -0
index 63e05e3..f928ad5 100644
@@ -432,4 +432,20 @@ config DM_SWITCH
 
 	  If unsure, say N.
 
+config DM_LOG_WRITES
+	tristate "Log writes target support"
+	depends on BLK_DEV_DM
+	---help---
+	  This device-mapper target takes two devices, one device to use
+	  normally, one to log all write operations done to the first device.
+	  This is for use by file system developers wishing to verify that
+	  their fs is writing a consitent file system at all times by allowing
+	  them to replay the log in a variety of ways and to check the
+	  contents.
+
+	  To compile this code as a module, choose M here: the module will
+	  be called dm-log-writes.
+
+	  If unsure, say N.
+
 endif # MD
drivers/md/Makefile +1 -0
index a2da532..1863fea 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_DM_CACHE)		+= dm-cache.o
 obj-$(CONFIG_DM_CACHE_MQ)	+= dm-cache-mq.o
 obj-$(CONFIG_DM_CACHE_CLEANER)	+= dm-cache-cleaner.o
 obj-$(CONFIG_DM_ERA)		+= dm-era.o
+obj-$(CONFIG_DM_LOG_WRITES)	+= dm-log-writes.o
 
 ifeq ($(CONFIG_DM_UEVENT),y)
 dm-mod-objs			+= dm-uevent.o
drivers/md/dm-log-writes.c new file +809 -0

809 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 2/3 fstests: add dm-log-writes test and supporting code

In reply to Josef Bacik

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,

---
 README                |   2 +
 common/config         |   1 +
 common/dmlogwrites    |  80 ++++++++++++++++++++++++++++++
 common/rc             |  46 ++++++++++++++++++
 ltp/fsx.c             | 131 ++++++++++++++++++++++++++++++++++++++++++--------
 tests/generic/326     | 130 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/326.out |   2 +
 tests/generic/group   |   1 +
 8 files changed, 374 insertions(+), 19 deletions(-)
 create mode 100644 common/dmlogwrites
 create mode 100644 tests/generic/326
 create mode 100644 tests/generic/326.out
README +2 -0
index 0c9449a..112478e 100644
@@ -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
common/config +1 -0
index e5c3579..563e48e 100644
@@ -190,6 +190,7 @@ export DMSETUP_PROG="`set_prog_path dmsetup`"
 export WIPEFS_PROG="`set_prog_path wipefs`"
 export DUMP_PROG="`set_prog_path dump`"
 export RESTORE_PROG="`set_prog_path restore`"
+export REPLAYLOG_PROG="`set_prog_path replay-log`"
 
 # Generate a comparable xfsprogs version number in the form of
 # major * 10000 + minor * 100 + release
common/dmlogwrites new file +80 -0

80 lines not on this page · raw message

common/rc +46 -0

58 lines not on this page · raw message

ltp/fsx.c +112 -19

255 lines not on this page · raw message

tests/generic/326 new file +130 -0

130 lines not on this page · raw message

tests/generic/326.out new file +2 -0
new file mode 100644
index 0000000..4ac0db5
@@ -0,0 +1,2 @@
+QA output created by 326
+Silence is golden
tests/generic/group +1 -0
index d56d3ce..31e5f7d 100644
@@ -183,3 +183,4 @@
 323 auto aio stress
 324 auto fsr quick
 325 auto quick data log
+326 auto log
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 3/3 fstests: btrfs balance with dm log writes test

In reply to Josef Bacik

This test runs fsstress+balance+defrag and then replays every FUA in the log and mounts, scrubs and then fscks the fs to make sure it does the balance recovery properly. Thanks,

---
 tests/btrfs/083     | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/083.out |   1 +
 tests/btrfs/group   |   1 +
 3 files changed, 137 insertions(+)
 create mode 100644 tests/btrfs/083
 create mode 100644 tests/btrfs/083.out
tests/btrfs/083 new file +135 -0
new file mode 100644
index 0000000..66118b9
@@ -0,0 +1,135 @@
+#! /bin/bash
+# FSQA Test No. btrfs/083
+#
+# Run btrfs balance and defrag operations simultaneously with fsstress
+# running in background on top of dm-log-writes.
+#
+#-----------------------------------------------------------------------
+# Copyright (C) 2015 Facebook. 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
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmlogwrites
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+# we check scratch dev after each loop
+_need_to_be_root
+_require_scratch_nocheck
+_require_dm_log_writes
+
+rm -f $seqres.full
+
+_wait_balance()
+{
+	while [ 1 ]
+	do
+		$BTRFS_UTIL_PROG filesystem balance status $SCRATCH_MNT \
+			| grep "No balance" >> $seqres.full
+		[ $? -eq 0 ] && break
+		sleep 1
+	done
+}
+
+run_test()
+{
+	args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
+	echo "Run fsstress $args" >>$seqres.full
+	$FSSTRESS_PROG $args >/dev/null 2>&1 &
+	fsstress_pid=$!
+
+	echo -n "Start balance worker: " >>$seqres.full
+	_btrfs_stress_balance $SCRATCH_MNT >/dev/null 2>&1 &
+	balance_pid=$!
+	echo "$balance_pid" >>$seqres.full
+
+	echo -n "Start defrag worker: " >>$seqres.full
+	_btrfs_stress_defrag $SCRATCH_MNT $with_compress >/dev/null 2>&1 &
+	defrag_pid=$!
+	echo "$defrag_pid" >>$seqres.full
+
+	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
+	wait $fsstress_pid
+	kill $balance_pid $defrag_pid
+	wait
+	# wait for the balance and defrag operations to finish
+	while ps aux | grep "balance start" | grep -qv grep; do
+		sleep 1
+	done
+	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
+		sleep 1
+	done
+}
+
+_init_log_writes
+
+_log_writes_mkfs >> $seqres.full 2>&1
+
+_mount_log_writes
+
+run_test "$t" nocompress
+
+_unmount_log_writes
+_log_writes_remove
+
+# Get the number of entries in the log
+NUM_ENTRIES=$($REPLAYLOG_PROG --log $LOGWRITES_DEV --num-entries)
+
+# Start at the first FUA after the mkfs
+ENTRY=$($REPLAYLOG_PROG --log $LOGWRITES_DEV --start-mark mkfs \
+	--find --next-fua)
+
+while [ $ENTRY -lt $NUM_ENTRIES ];
+do
+	echo "Replaying to $ENTRY" >> $seqres.full
+	$REPLAYLOG_PROG --log $LOGWRITES_DEV --replay $SCRATCH_DEV --limit \
+		$ENTRY > /dev/null 2>&1
+	[ $? -ne 0 ] && _fatal "replay failed"
+	btrfsck $SCRATCH_DEV >> $seqres.full 2>&1 || _fatal "btrfsck failed"
+	_scratch_mount || _fatal "mount failed"
+	_wait_balance
+	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
+	[ $? -ne 0 ] && _fatal "scrub failed"
+	_scratch_unmount
+	btrfsck $SCRATCH_DEV >> $seqres.full 2>&1 || _fatal "btrfsck failed"
+	let ENTRY+=1
+	ENTRY=$($REPLAYLOG_PROG --find --start-entry $ENTRY --log \
+		$LOGWRITES_DEV --next-fua)
+done
+
+status=0
+exit
+
tests/btrfs/083.out new file +1 -0
new file mode 100644
index 0000000..b675a31
@@ -0,0 +1 @@
+QA output created by 083
tests/btrfs/group +1 -0
index fd2fa76..88719ca 100644
@@ -85,3 +85,4 @@
 080 auto snapshot
 081 auto quick clone
 082 auto quick remount
+083 auto log
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 1/3] dm: log writes target

In reply to Josef Bacik
Quoted 2 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system.

Hi Josef, just a quick drive-by review for stuff that jumps out at me..

Review

Quoted 2 lines
(quoted diff) +2 -0
+	atomic_dec(&lc->io_blocks);
+	wake_up(&lc->wait);

This waitqueue is only used by the destructor? Seems worth putting this off in a helper that tests the waitqueue so that it avoids taking locks in the common case where nothing is waiting.

	atomic_dec(&lc->io_blocks);
	smp_mb__after_atomic(); /* see wake_up_bit() comment */
	if (waitqueue_active(&lc->wait))
		wake_up(&lc->wait);

drivers/md/dm-log-writes.c line 206

Quoted 6 lines
drivers/md/dm-log-writes.c new file +6 -0
+	ptr = kmap_atomic(page);
+	memset(ptr, 0, lc->sectorsize);
+	memcpy(ptr, entry, entrylen);
+	if (datalen)
+		memcpy(ptr + entrylen, data, datalen);
+	kunmap_atomic(ptr);

Drop the initial zeroing and only zero a remaining tail fragment?

memset(ptr + entry + data, 0, sector - (entry + data))

drivers/md/dm-log-writes.c line 235

Quoted 4 lines
drivers/md/dm-log-writes.c new file +4 -0
+	entry.sector = cpu_to_le64(block->sector);
+	entry.nr_sectors = cpu_to_le64(block->nr_sectors);
+	entry.flags = cpu_to_le64(block->flags);
+	entry.data_len = block->datalen;

Missing cpu_to_le64? Build with sparse?

drivers/md/dm-log-writes.c line 261

Quoted 3 lines
drivers/md/dm-log-writes.c new file +3 -0
+	for (i = 0; i < block->vec_cnt; i++) {
+		ret = bio_add_page(bio, block->vecs[i].bv_page,
+				   block->vecs[i].bv_len, 0);

It took me a minute to figure out that the offsets are always 0 because each page starts with a copy of one bvec segment.

Quoted 4 lines
drivers/md/dm-log-writes.c new file +4 -0
+			sector = lc->next_sector;
+			if (block->flags & LOG_DISCARD_FLAG)
+				lc->next_sector++;
+			else

drivers/md/dm-log-writes.c line 356

Quoted 10 lines
drivers/md/dm-log-writes.c new file +10 -0
+				lc->next_sector += block->nr_sectors + 1;
+
+			/*
+			 * Apparently the size of the device may not be known
+			 * right away, so handle this properly.
+			 */
+			if (!lc->end_sector)
+				lc->end_sector = logdev_last_sector(lc);
+			if (lc->end_sector &&
+			    lc->next_sector > lc->end_sector) {

Does that need to be >= to avoid trying to write to the sector at the device's i_size?

- z

#3 lore raw

PATCH 1/3 dm: log writes target V2

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

---
V1->V2: fixed up stuff based on Zachs review.

 Documentation/device-mapper/dm-log-writes.txt | 136 +++++
 drivers/md/Kconfig                            |  16 +
 drivers/md/Makefile                           |   1 +
 drivers/md/dm-log-writes.c                    | 826 ++++++++++++++++++++++++++
 4 files changed, 979 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-log-writes.txt
 create mode 100644 drivers/md/dm-log-writes.c
Documentation/device-mapper/dm-log-writes.txt new file +136 -0
new file mode 100644
index 0000000..f3a9fa2
@@ -0,0 +1,136 @@
+dm-log-writes
+=============
+
+This target takes 2 devices, one to pass all IO to normally, and one to log all
+of the write operations to.  This is intended for file system developers wishing
+to verify the integrity of metadata or data as the file system is written to.
+There is a log_writes_entry written for every WRITE request and the target is
+able to take arbitrary data from userspace to insert into the log.  The data
+that is in the WRITE requests is copied into the log to make the replay happen
+exactly as it happened originally.
+
+Log Ordering
+============
+
+We log things in order of completion once we are sure the write is no longer in
+cache.  This means that normal WRITE requests are not actually logged until the
+next REQ_FLUSH request.  This is to make it easier for userspace to replay the
+log in a way that correlates to what is on disk and not what is in cache, to
+make it easier to detect improper waiting/flushing.
+
+This works by attaching all WRITE requests to a list once the write completes.
+Once we see a REQ_FLUSH request we splice this list onto the request and once
+the FLUSH request completes we log all of the WRITE's and then the FLUSH.  Only
+completeled WRITEs at the time of the issue of the REQ_FLUSH are added in order
+to simulate the worst case scenario with regard to power failures.  Consider the
+following example (W means write, C means complete)
+
+W1,W2,W3,C3,C2,Wflush,C1,Cflush
+
+The log would show the following
+
+W3,W2,flush,W1....
+
+Again this is to simulate what is actually on disk, this allows us to detect
+cases where a power failure at a particular point in time would create an
+inconsistent file system.
+
+Any REQ_FUA requests bypass this flushing mechanism and are logged as soon as
+they complete as those requests will obviously bypass the device cache.
+
+Any REQ_DISCARD requests are treated like WRITE requests.  This is because
+otherwise we would have all the DISCARD requests, and then the WRITE requests
+and then the FLUSH request.  Consider the following example
+
+WRITE block 1, DISCARD block 1, FLUSH
+
+If we logged DISCARD when it completed, the replay would look like this
+
+DISCARD 1, WRITE 1, FLUSH
+
+which isn't quite what happened and wouldn't be caught during the log replay.
+
+Marks
+=====
+
+You can use dmsetup to set an arbitrary mark in a log.  For example say you want
+to fsck an file system after every write, but first you need to replay up to the
+mkfs to make sure we're fsck'ing something reasonable, you would do something
+like this
+
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+<run test>
+
+This would allow you to replay the log up to the mkfs mark and then replay from
+that point on doing the fsck check in the interval that you want.
+
+Every log has a mark at the end labeled "log-writes-end".
+
+Userspace component
+===================
+
+There is a userspace tool that will replay the log for you in various ways.
+As of this writing the options are not well documented, they will be in the
+future.  It can be found here
+
+https://github.com/josefbacik/log-writes
+
+Example usage
+=============
+
+Say you want to test fsync on your file system.  You would do something like
+this
+
+TABLE="0 $(blockdev --getsz /dev/sdb) log-writes /dev/sdb /dev/sdc"
+dmsetup create log --table "$TABLE"
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+
+mount /dev/mapper/log /mnt/btrfs-test
+<some test that does fsync at the end>
+dmsetup message log 0 mark fsync
+md5sum /mnt/btrfs-test/foo
+umount /mnt/btrfs-test
+
+dmsetup remove log
+replay-log --log /dev/sdc --replay /dev/sdb --end-mark fsync
+mount /dev/sdb /mnt/btrfs-test
+md5sum /mnt/btrfs-test/foo
+<verify md5sum's are correct>
+
+Another option is to do a complicated file system operation and verify the file
+system is consistent during the entire operation.  You could do this by doing
+
+
+TABLE="0 $(blockdev --getsz /dev/sdb) log-writes /dev/sdb /dev/sdc"
+dmsetup create log --table "$TABLE"
+mkfs.btrfs -f /dev/mapper/log
+dmsetup message log 0 mark mkfs
+
+mount /dev/mapper/log /mnt/btrfs-test
+<fsstress to dirty the fs>
+btrfs filesystem balance /mnt/btrfs-test
+umount /mnt/btrfs-test
+dmsetup remove log
+
+replay-log --log /dev/sdc --replay /dev/sdb --end-mark mkfs
+btrfsck /dev/sdb
+replay-log --log /dev/sdc --replay /dev/sdb --start-mark mkfs \
+	--fsck "btrfsck /dev/sdb" --check fua
+
+And that will replay the log until it sees a FUA request, run the fsck command
+and if the fsck passes it will replay to the next FUA, until it is completed or
+the fsck command exists abnormally.
+
+Table Parameters
+----------------
+  <dev path> <dev path for log>
+
+Mandatory parameters:
+  <dev path>: Full pathname to the underlying block-device, or a "major:minor"
+              device-number.  This device is the one that all of the IO will go
+              to normally, just think of it as a normal linear mapping.
+  <dev path for log>: Same format as <dev path>, this is the device where the
+                      log entries are written to.
+
drivers/md/Kconfig +16 -0
index 63e05e3..f928ad5 100644
@@ -432,4 +432,20 @@ config DM_SWITCH
 
 	  If unsure, say N.
 
+config DM_LOG_WRITES
+	tristate "Log writes target support"
+	depends on BLK_DEV_DM
+	---help---
+	  This device-mapper target takes two devices, one device to use
+	  normally, one to log all write operations done to the first device.
+	  This is for use by file system developers wishing to verify that
+	  their fs is writing a consitent file system at all times by allowing
+	  them to replay the log in a variety of ways and to check the
+	  contents.
+
+	  To compile this code as a module, choose M here: the module will
+	  be called dm-log-writes.
+
+	  If unsure, say N.
+
 endif # MD
drivers/md/Makefile +1 -0
index a2da532..1863fea 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_DM_CACHE)		+= dm-cache.o
 obj-$(CONFIG_DM_CACHE_MQ)	+= dm-cache-mq.o
 obj-$(CONFIG_DM_CACHE_CLEANER)	+= dm-cache-cleaner.o
 obj-$(CONFIG_DM_ERA)		+= dm-era.o
+obj-$(CONFIG_DM_LOG_WRITES)	+= dm-log-writes.o
 
 ifeq ($(CONFIG_DM_UEVENT),y)
 dm-mod-objs			+= dm-uevent.o
drivers/md/dm-log-writes.c new file +826 -0

826 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] dm: log writes target V2

Quoted 10 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

---
V1->V2: fixed up stuff based on Zachs review.

Cool,

- z

#7 lore raw

Re: [PATCH 1/3] dm: log writes target

In reply to Josef Bacik
Quoted 23 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

---
 Documentation/device-mapper/dm-log-writes.txt | 136 +++++
 drivers/md/Kconfig                            |  16 +
 drivers/md/Makefile                           |   1 +
 drivers/md/dm-log-writes.c                    | 809 ++++++++++++++++++++++++++
 4 files changed, 962 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-log-writes.txt
 create mode 100644 drivers/md/dm-log-writes.c
Documentation/device-mapper/dm-log-writes.txt new file +0 -0
new file mode 100644
index 0000000..f3a9fa2

Documentation/device-mapper/dm-log-writes.txt line 10

Quoted 10 lines
Documentation/device-mapper/dm-log-writes.txt new file +10 -0
@@ -0,0 +1,136 @@
+dm-log-writes
+=============
+
+This target takes 2 devices, one to pass all IO to normally, and one to log all
+of the write operations to.  This is intended for file system developers wishing
+to verify the integrity of metadata or data as the file system is written to.
+There is a log_writes_entry written for every WRITE request and the target is
+able to take arbitrary data from userspace to insert into the log.  The data
+that is in the WRITE requests is copied into the log to make the replay happen
+exactly as it happened originally.

Hmm - terminology thing here - "log writes" have specific meaning to any application that does write ahead logging. E.g. journalling filesystems, databases, etc. So I find this name extremely confusing because a dm-log-write device has nothing to do with write ahead logging, log writes or journalling...

I'm sure lots of other people are going to have the same problem understanding what this device is for because of that.

I know this is effectively bikeshedding, but I think a less ambiguous name would be a good thing to have. e.g. dm-iotracer. Nobody will get confused that way....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#9 lore raw

Re: [dm-devel] [PATCH 1/3] dm: log writes target

In reply to Josef Bacik

On Thu, Mar 19, 2015 at 04:31:08PM -0400, Josef Bacik wrote:

[..]

Quoted 10 lines

+ * We log writes only after they have been flushed, this makes the log describe
+ * close to the order in which the data hits the actual disk, not its cache. So
+ * for example the following sequence (W means write, C means complete)
+ *
+ * Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
+ *
+ * Would result in the log looking like this
+ *
+ * c,a,flush,fuad,b,<other writes>,<next flush>
+ *

A minor nit, Should this sequence be following.

c,a,b, flush,fuad,<other writes>,<next flush>

when flush completed by that time write of b has completed too. So it should be written first?

Thanks
Vivek

#5 lore raw

Re: [PATCH 1/3] dm: log writes target V2

In reply to Josef Bacik
Quoted 8 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

Hey Josef,

Nice job with this target, you need to contribute to DM more ;)

I've staged your target for the 4.1 merge in linux-dm.git's 'for-next' branch (with a few small fixes for nits/typos).

FYI, I'll likely rebase 'for-next' once more for 4.1 given a conflicting 4.0 change to DM core still needs to land upstream (you can see the merge conflict in 'for-next' at the moment). But that won't impact your target at all (other than changing the 4.1 commit id).

Thanks,
Mike

#13 lore raw

Re: [PATCH 3/3] fstests: btrfs balance with dm log writes test

In reply to Josef Bacik
Quoted 5 lines · Josef Bacik

This test runs fsstress+balance+defrag and then replays every FUA in the log and mounts, scrubs and then fscks the fs to make sure it does the balance recovery properly. Thanks,

Looks good, only some minor comments below.
Thanks.

Quoted 63 lines
---
 tests/btrfs/083     | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/083.out |   1 +
 tests/btrfs/group   |   1 +
 3 files changed, 137 insertions(+)
 create mode 100644 tests/btrfs/083
 create mode 100644 tests/btrfs/083.out
tests/btrfs/083 new file +49 -0
new file mode 100644
index 0000000..66118b9
@@ -0,0 +1,135 @@
+#! /bin/bash
+# FSQA Test No. btrfs/083
+#
+# Run btrfs balance and defrag operations simultaneously with fsstress
+# running in background on top of dm-log-writes.
+#
+#-----------------------------------------------------------------------
+# Copyright (C) 2015 Facebook. 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
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmlogwrites
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+# we check scratch dev after each loop

tests/btrfs/083 line 59

Quoted 10 lines
tests/btrfs/083 new file +10 -0
+_need_to_be_root
+_require_scratch_nocheck
+_require_dm_log_writes
+
+rm -f $seqres.full
+
+_wait_balance()
+{
+       while [ 1 ]
+       do

Generally the style used in fstests is: while X; do

Quoted 34 lines
tests/btrfs/083 new file +34 -0
+               $BTRFS_UTIL_PROG filesystem balance status $SCRATCH_MNT \
+                       | grep "No balance" >> $seqres.full
+               [ $? -eq 0 ] && break
+               sleep 1
+       done
+}
+
+run_test()
+{
+       args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $SCRATCH_MNT/stressdir`
+       echo "Run fsstress $args" >>$seqres.full
+       $FSSTRESS_PROG $args >/dev/null 2>&1 &
+       fsstress_pid=$!
+
+       echo -n "Start balance worker: " >>$seqres.full
+       _btrfs_stress_balance $SCRATCH_MNT >/dev/null 2>&1 &
+       balance_pid=$!
+       echo "$balance_pid" >>$seqres.full
+
+       echo -n "Start defrag worker: " >>$seqres.full
+       _btrfs_stress_defrag $SCRATCH_MNT $with_compress >/dev/null 2>&1 &
+       defrag_pid=$!
+       echo "$defrag_pid" >>$seqres.full
+
+       echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
+       wait $fsstress_pid
+       kill $balance_pid $defrag_pid
+       wait
+       # wait for the balance and defrag operations to finish
+       while ps aux | grep "balance start" | grep -qv grep; do
+               sleep 1
+       done
+       while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
+               sleep 1

tests/btrfs/083 line 103

Quoted 10 lines
tests/btrfs/083 new file +10 -0
+       done
+}
+
+_init_log_writes
+
+_log_writes_mkfs >> $seqres.full 2>&1
+
+_mount_log_writes
+
+run_test "$t" nocompress

The arguments passed to run_test don't seem to be used anywhere (nor $t defined).

tests/btrfs/083 line 116

Quoted 13 lines
tests/btrfs/083 new file +13 -0
+
+_unmount_log_writes
+_log_writes_remove
+
+# Get the number of entries in the log
+NUM_ENTRIES=$($REPLAYLOG_PROG --log $LOGWRITES_DEV --num-entries)
+
+# Start at the first FUA after the mkfs
+ENTRY=$($REPLAYLOG_PROG --log $LOGWRITES_DEV --start-mark mkfs \
+       --find --next-fua)
+
+while [ $ENTRY -lt $NUM_ENTRIES ];
+do

Same as above.

tests/btrfs/083 line 121

Quoted 5 lines
tests/btrfs/083 new file +5 -0
+       echo "Replaying to $ENTRY" >> $seqres.full
+       $REPLAYLOG_PROG --log $LOGWRITES_DEV --replay $SCRATCH_DEV --limit \
+               $ENTRY > /dev/null 2>&1
+       [ $? -ne 0 ] && _fatal "replay failed"
+       btrfsck $SCRATCH_DEV >> $seqres.full 2>&1 || _fatal "btrfsck failed"

Any reason to not use _check_scratch_fs instead?

tests/btrfs/083 line 127

Quoted 6 lines
tests/btrfs/083 new file +6 -0
+       _scratch_mount || _fatal "mount failed"
+       _wait_balance
+       $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
+       [ $? -ne 0 ] && _fatal "scrub failed"
+       _scratch_unmount
+       btrfsck $SCRATCH_DEV >> $seqres.full 2>&1 || _fatal "btrfsck failed"

Same as above.

Quoted 31 lines
tests/btrfs/083 new file +8 -0
+       let ENTRY+=1
+       ENTRY=$($REPLAYLOG_PROG --find --start-entry $ENTRY --log \
+               $LOGWRITES_DEV --next-fua)
+done
+
+status=0
+exit
+
tests/btrfs/083.out new file +1 -0
new file mode 100644
index 0000000..b675a31
@@ -0,0 +1 @@
+QA output created by 083
tests/btrfs/group +1 -1
index fd2fa76..88719ca 100644
@@ -85,3 +85,4 @@
 080 auto snapshot
 081 auto quick clone
 082 auto quick remount
+083 auto log
--

1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
#6 lore raw

Re: [PATCH 1/3] dm: log writes target V2

In reply to Mike Snitzer
Quoted 16 lines · Mike Snitzer
Quoted 8 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

Hey Josef,

Nice job with this target, you need to contribute to DM more ;)

Quoted 8 lines

I've staged your target for the 4.1 merge in linux-dm.git's 'for-next' branch (with a few small fixes for nits/typos).

FYI, I'll likely rebase 'for-next' once more for 4.1 given a conflicting 4.0 change to DM core still needs to land upstream (you can see the merge conflict in 'for-next' at the moment). But that won't impact your target at all (other than changing the 4.1 commit id).

Great thanks Mike!

Josef

#8 lore raw

Re: [PATCH 1/3] dm: log writes target

In reply to Dave Chinner
Quoted 41 lines · Dave Chinner
Quoted 23 lines · Josef Bacik

This creates a new target that is meant for file system developers to test file system integrity at particular points in the life of a file system. We capture all write requests and the data and log the requests and the data to a separate device for later replay. There is a userspace utility to do this replay. The idea behind this is to give file system developers to verify that the file system is always consistent. Thanks,

---
  Documentation/device-mapper/dm-log-writes.txt | 136 +++++
  drivers/md/Kconfig                            |  16 +
  drivers/md/Makefile                           |   1 +
  drivers/md/dm-log-writes.c                    | 809 ++++++++++++++++++++++++++
  4 files changed, 962 insertions(+)

create mode 100644 Documentation/device-mapper/dm-log-writes.txt create mode 100644 drivers/md/dm-log-writes.c

Documentation/device-mapper/dm-log-writes.txt new file +0 -0
new file mode 100644
index 0000000..f3a9fa2

Documentation/device-mapper/dm-log-writes.txt line 10

Quoted 10 lines
Documentation/device-mapper/dm-log-writes.txt new file +10 -0
@@ -0,0 +1,136 @@
+dm-log-writes
+=============
+
+This target takes 2 devices, one to pass all IO to normally, and one to log all
+of the write operations to.  This is intended for file system developers wishing
+to verify the integrity of metadata or data as the file system is written to.
+There is a log_writes_entry written for every WRITE request and the target is
+able to take arbitrary data from userspace to insert into the log.  The data
+that is in the WRITE requests is copied into the log to make the replay happen
+exactly as it happened originally.

Hmm - terminology thing here - "log writes" have specific meaning to any application that does write ahead logging. E.g. journalling filesystems, databases, etc. So I find this name extremely confusing because a dm-log-write device has nothing to do with write ahead logging, log writes or journalling...

Quoted 7 lines

I'm sure lots of other people are going to have the same problem understanding what this device is for because of that.

I know this is effectively bikeshedding, but I think a less ambiguous name would be a good thing to have. e.g. dm-iotracer. Nobody will get confused that way....

Hey Dave,

Sorry I sent this patch and then promptly went on vacation. Mike has already pulled the patch in and I've already gotten all this tooling built around the original name. It is probably a little confusing, but since only a few of us are going to mess with it and it's mostly going to be used in an xfstests context I'm not too worried about it. Thanks,

Josef

#10 lore raw

Re: [dm-devel] [PATCH 1/3] dm: log writes target

In reply to Vivek Goyal
Quoted 14 lines · Vivek Goyal

On Thu, Mar 19, 2015 at 04:31:08PM -0400, Josef Bacik wrote:

[..]

Quoted 10 lines

+ * We log writes only after they have been flushed, this makes the log describe
+ * close to the order in which the data hits the actual disk, not its cache. So
+ * for example the following sequence (W means write, C means complete)
+ *
+ * Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
+ *
+ * Would result in the log looking like this
+ *
+ * c,a,flush,fuad,b,<other writes>,<next flush>
+ *

Quoted 7 lines

A minor nit, Should this sequence be following.

c,a,b, flush,fuad,<other writes>,<next flush>

when flush completed by that time write of b has completed too. So it should be written first?

So we want to catch file systems behaving badly by not waiting for the IO they care about to complete before issuing their flush, so we take the super pessimistic view that only IO that has completed by FLUSH issue time can truly be safe. For all we know the flush could have happened first and we just happen to get the endio called for b first instead of the flush, so to make it mostly likely that we catch fs bugs we enforce this idea that only completed IO can be sure to have been flushed at flush submit time. Thanks,

Josef