mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
fcc3f3b9c3
Test that if we do a buffered write to a file, fsync it, clone a range from another file into our file that overlaps the previously written range, fsync the file again and then power fail, after we mount again the filesystem, no file data was lost or corrupted. This test is motivated by a bug found in btrfs, which is fixed by a patch for the linux kernel titled: "Btrfs: fix file data corruption after cloning a range and fsync" Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
71 lines
1.8 KiB
Bash
Executable File
71 lines
1.8 KiB
Bash
Executable File
#! /bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
|
|
#
|
|
# FS QA Test No. 501
|
|
#
|
|
# Test that if we do a buffered write to a file, fsync it, clone a range from
|
|
# another file into our file that overlaps the previously written range, fsync
|
|
# the file again and then power fail, after we mount again the filesystem, no
|
|
# file data was lost or corrupted.
|
|
#
|
|
seq=`basename $0`
|
|
seqres=$RESULT_DIR/$seq
|
|
echo "QA output created by $seq"
|
|
tmp=/tmp/$$
|
|
status=1 # failure is the default!
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
_cleanup()
|
|
{
|
|
_cleanup_flakey
|
|
cd /
|
|
rm -f $tmp.*
|
|
}
|
|
|
|
# get standard environment, filters and checks
|
|
. ./common/rc
|
|
. ./common/filter
|
|
. ./common/reflink
|
|
. ./common/dmflakey
|
|
|
|
# real QA test starts here
|
|
_supported_fs generic
|
|
_supported_os Linux
|
|
_require_scratch_reflink
|
|
_require_dm_target flakey
|
|
|
|
rm -f $seqres.full
|
|
|
|
_scratch_mkfs >>$seqres.full 2>&1
|
|
_require_metadata_journaling $SCRATCH_DEV
|
|
_init_flakey
|
|
_mount_flakey
|
|
|
|
$XFS_IO_PROG -f -c "pwrite -S 0x18 9000K 6908K" $SCRATCH_MNT/foo >>$seqres.full
|
|
$XFS_IO_PROG -f -c "pwrite -S 0x20 2572K 156K" $SCRATCH_MNT/bar >>$seqres.full
|
|
|
|
# We clone from file foo into a range of file bar that overlaps the existing
|
|
# extent at file bar. The destination offset of the reflink operation matches
|
|
# the eof position of file bar minus 4Kb.
|
|
$XFS_IO_PROG -c "fsync" \
|
|
-c "reflink ${SCRATCH_MNT}/foo 0 2724K 15908K" \
|
|
-c "fsync" \
|
|
$SCRATCH_MNT/bar >>$seqres.full
|
|
|
|
echo "File bar digest before power failure:"
|
|
md5sum $SCRATCH_MNT/bar | _filter_scratch
|
|
|
|
# Simulate a power failure and mount the filesystem to check that no file data
|
|
# was lost or corrupted.
|
|
_flakey_drop_and_remount
|
|
|
|
echo "File bar digest after power failure:"
|
|
md5sum $SCRATCH_MNT/bar | _filter_scratch
|
|
|
|
_unmount_flakey
|
|
_cleanup_flakey
|
|
|
|
status=0
|
|
exit
|