$DMSETUP_PROG resume flakey-test
[ $? -ne 0 ] && _fatal "failed to resumeflakey-test"
}
+
+# Silently drop all writes and unmount/remount to simulate a crash/power
+# failure.
+_flakey_drop_and_remount()
+{
+ _load_flakey_table $FLAKEY_DROP_WRITES
+ _unmount_flakey
+
+ if [ "x$1" = "xyes" ]; then
+ _check_scratch_fs $FLAKEY_DEV
+ fi
+
+ _load_flakey_table $FLAKEY_ALLOW_WRITES
+ _mount_flakey
+}
$CLONER_PROG -s 0 -d 0 -l 3500 $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar2
- _load_flakey_table $FLAKEY_DROP_WRITES
- _unmount_flakey
-
- # Verify that there are no consistency errors.
- _check_scratch_fs $FLAKEY_DEV
-
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount yes
# Verify the cloned range was persisted by fsync and the log recovery
# code did its work well.
echo "File digest before power failure:"
md5sum $SCRATCH_MNT/foo | _filter_scratch
-# Silently drop all writes and ummount to simulate a crash/power failure.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again, mount to trigger log replay and validate file contents.
# During log replay, the btrfs delayed references implementation used to run the
# deletion of back references before the addition of new back references, which
# made the addition fail as it didn't find the key in the extent tree that it
# log replay - when running the delayed references at transaction commit time,
# btrfs was applying the deletion before the insertion, resulting in a failure
# of the insertion that ended up turning the fs into read-only mode.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
echo "File digest after log replay:"
md5sum $SCRATCH_MNT/foo | _filter_scratch
echo "File digest before power failure:"
md5sum $SCRATCH_MNT/foo | _filter_scratch
-# Silently drop all writes and ummount to simulate a crash/power failure.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again, mount to trigger log replay and validate file contents.
# The fsync log replay first processes the file extent item corresponding to the
# file offset 400K (the one which refers to the [20K, 40K[ sub-range of our 100K
# extent) and then processes the file extent item for file offset 800K. It used
# "BTRFS warning (device dm-0): csum failed ino 257 off 917504 csum 1322675045\
# expected csum 0"
#
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
echo "File digest after log replay:"
# Must match the same digest he had after cloning the extent and before the
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/test_dir
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/test_dir/bar
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
# In the original btrfs bug, log replay would update the directory's inode
# i_size incorrectly - it would sum again the size of dentry 'foo' (3) to
# the inode's i_size, which is incorrect because the dentry was already
# persisted before (in the fs/subvol tree).
-_mount_flakey
+_flakey_drop_and_remount
[ -f $SCRATCH_MNT/test_dir/foo ] || echo "file foo is missing"
[ -f $SCRATCH_MNT/test_dir/bar ] || echo "file bar is missing"
rm -f $SCRATCH_MNT/a/b/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/b/foo
-# Simulate a crash/power loss. This makes sure the next mount
-# will see an fsync log and will replay that log.
-
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Remove the last hard link of the file and attempt to remove its parent
# directory - this failed in btrfs because the fsync log and replay code
ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_3001
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
-# Simulate a crash/power loss. This makes sure the next mount
-# will see an fsync log and will replay that log.
-
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Now after the fsync log replay btrfs left our inode with a wrong link count N,
# which was smaller than the correct link count M (N < M).
ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_3003
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
-# Simulate a crash/power loss. This makes sure the next mount
-# will see an fsync log and will replay that log.
-
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Check that the number of hard links is correct, we are able to remove all
# the hard links and read the file's data. This is just to verify we don't
echo "File content before:"
od -t x1 $SCRATCH_MNT/foo
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# After the fsync log replay, because the fsync log had a value of 0 for our
# inode's i_size, we couldn't read anymore the 4Kb of data that we previously
echo "File content before:"
od -t x1 $SCRATCH_MNT/foo
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# After mounting the fs again, the fsync log was replayed.
# The btrfs fsync log replay code didn't update the i_size of the persisted
echo "File content before:"
od -t x1 $SCRATCH_MNT/foo
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Enable writes and mount the fs. This makes the fsync log replay code run.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Because the last fsync didn't do anything, here the file content matched what
# it was after the first fsync, before the holes were punched, and not what it
# no bad influence on this fsync.
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/hello
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Verify the content of our file 'foo' remains the same as before, 8192 bytes,
# all with the value 0xaa.
_require_attrs
_require_metadata_journaling $SCRATCH_DEV
-_crash_and_mount()
-{
- # Simulate a crash/power loss.
- _load_flakey_table $FLAKEY_DROP_WRITES
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
-}
-
rm -f $seqres.full
_scratch_mkfs >> $seqres.full 2>&1
$SETFATTR_PROG -x user.attr2 $SCRATCH_MNT/foobar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
-_crash_and_mount
+_flakey_drop_and_remount
# After the fsync log is replayed, the file should have only 2 xattrs, the ones
# named user.attr1 and user.attr3. The btrfs fsync log replay bug left the file
touch $SCRATCH_MNT/qwerty
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/qwerty
-_crash_and_mount
+_flakey_drop_and_remount
# Now only the xattr with name user.attr3 should be set in our file.
echo "xattr names and values after second fsync log replay:"
# happened when we fsynced the parent directory.
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Now check that all data we wrote before are available.
echo "File content after log replay:"
echo "File content after fsync and before crash:"
od -t x1 $SCRATCH_MNT/foo
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again and mount. This makes the fs replay its fsync log.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
echo "File content after crash and log replay:"
od -t x1 $SCRATCH_MNT/foo
-c "fsync" \
$SCRATCH_MNT/bar
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again, mount to trigger log replay and validate file contents.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# We expect foo to have a size of 125Kb, the first 64Kb of data all having the
# value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/foo_link
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
-# Silently drop all writes on our scratch device to simulate a power failure.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again and mount the fs to trigger log/journal replay.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Now verify both our files have a link count of 2.
echo "Link count for file foo: $(stat -c %h $SCRATCH_MNT/testdir/foo)"
echo 2 > /proc/sys/vm/drop_caches
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/foo
-# Silently drop all writes on our scratch device to simulate a power failure.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again and mount the fs to trigger log/journal replay.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# Now verify our directory entries.
echo "Entries in testdir:"
# is not the directory "testdir".
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
-# Silently drop all writes and unmount to simulate a crash/power failure.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again and mount the fs to trigger log/journal replay.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
# After the journal/log is replayed we expect to not see the "foo3" link anymore
# and we should be able to remove all names in the directory "testdir" and then
_mount_flakey
mkdir $SCRATCH_MNT/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
- _load_flakey_table $FLAKEY_DROP_WRITES
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount
+
_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
_unmount_flakey
_check_scratch_fs $FLAKEY_DEV
mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
- _load_flakey_table $FLAKEY_DROP_WRITES
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount\
+
_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
_unmount_flakey
setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
- _load_flakey_table $FLAKEY_DROP_WRITES
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount
+
_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
_unmount_flakey
> $seqres.full 2>&1 || _fail "xfs_io failed"
mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
- _load_flakey_table $FLAKEY_DROP_WRITES
md5sum $SCRATCH_MNT/bar | _filter_scratch
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount
+
md5sum $SCRATCH_MNT/bar | _filter_scratch
_unmount_flakey
_check_scratch_fs $FLAKEY_DEV
-c "sync_range -b" $SCRATCH_MNT/foo > $seqres.full 2>&1 || _fail "xfs_io failed"
mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
- _load_flakey_table $FLAKEY_DROP_WRITES
md5sum $SCRATCH_MNT/bar | _filter_scratch
- _unmount_flakey
- _load_flakey_table $FLAKEY_ALLOW_WRITES
- _mount_flakey
+ _flakey_drop_and_remount
+
md5sum $SCRATCH_MNT/bar | _filter_scratch
_unmount_flakey
}
echo "File content before crash/reboot:"
od -t x1 $SCRATCH_MNT/foo
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
echo "File content after crash/reboot and fs mount:"
od -t x1 $SCRATCH_MNT/foo
-c "fsync" \
$SCRATCH_MNT/foo | _filter_xfs_io
-# Simulate a crash/power loss.
-_load_flakey_table $FLAKEY_DROP_WRITES
-_unmount_flakey
-
-# Allow writes again and mount. This makes the fs replay its fsync log.
-_load_flakey_table $FLAKEY_ALLOW_WRITES
-_mount_flakey
+_flakey_drop_and_remount
echo "File content after crash and log replay:"
od -t x1 $SCRATCH_MNT/foo