#! /bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2021 Oracle. All Rights Reserved. # # FS QA Test No. 628 # # Make sure that reflink forces the log out if we open the file with O_SYNC or # set FS_XFLAG_SYNC on the file. We test that it actually forced the log by # using dm-error to shut down the fs without flushing the log and then # remounting to check file contents. This is a regression test for commit # 5ffce3cc22a0 ("xfs: force the log after remapping a synchronous-writes file") . ./common/preamble _begin_fstest auto quick rw clone eio # Override the default cleanup function. _cleanup() { cd / rm -f $tmp.* _dmerror_unmount _dmerror_cleanup } # Import common functions. . ./common/filter . ./common/reflink . ./common/dmerror # real QA test starts here _supported_fs generic _require_scratch_reflink _require_dm_target error _require_xfs_io_command "chattr" "s" _require_cp_reflink # Format filesystem and set up quota limits _scratch_mkfs > $seqres.full _require_metadata_journaling $SCRATCH_DEV _dmerror_init _dmerror_mount # Test that O_SYNC actually results in file data being written even if the # fs immediately dies echo "test o_sync write" $XFS_IO_PROG -x -f -s -c "pwrite -S 0x58 0 1m -b 1m" $SCRATCH_MNT/0 >> $seqres.full _dmerror_load_error_table _dmerror_unmount _dmerror_load_working_table _dmerror_mount md5sum $SCRATCH_MNT/0 | _filter_scratch # Set up initial files for reflink test $XFS_IO_PROG -f -c 'pwrite -S 0x58 0 1m -b 1m' $SCRATCH_MNT/a >> $seqres.full $XFS_IO_PROG -f -c 'pwrite -S 0x59 0 1m -b 1m' $SCRATCH_MNT/c >> $seqres.full _cp_reflink $SCRATCH_MNT/a $SCRATCH_MNT/e _cp_reflink $SCRATCH_MNT/c $SCRATCH_MNT/d touch $SCRATCH_MNT/b sync # Test that reflink forces dirty data/metadata to disk when destination file # opened with O_SYNC echo "test reflink flag not set o_sync" $XFS_IO_PROG -x -s -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full _dmerror_load_error_table _dmerror_unmount _dmerror_load_working_table _dmerror_mount md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch # Test that reflink to a shared file forces dirty data/metadata to disk when # destination is opened with O_SYNC echo "test reflink flag already set o_sync" $XFS_IO_PROG -x -s -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/d >> $seqres.full _dmerror_load_error_table _dmerror_unmount _dmerror_load_working_table _dmerror_mount md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch # Set up the two files with chattr +S rm -f $SCRATCH_MNT/b $SCRATCH_MNT/d _cp_reflink $SCRATCH_MNT/c $SCRATCH_MNT/d touch $SCRATCH_MNT/b chattr +S $SCRATCH_MNT/b $SCRATCH_MNT/d sync # Test that reflink forces dirty data/metadata to disk when destination file # has the sync iflag set echo "test reflink flag not set iflag" $XFS_IO_PROG -x -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full _dmerror_load_error_table _dmerror_unmount _dmerror_load_working_table _dmerror_mount md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch # Test that reflink to a shared file forces dirty data/metadata to disk when # destination file has the sync iflag set echo "test reflink flag already set iflag" $XFS_IO_PROG -x -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/d >> $seqres.full _dmerror_load_error_table _dmerror_unmount _dmerror_load_working_table _dmerror_mount md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch # success, all done status=0 exit