blob: 1c330f9dcb4a293a85e52f8e78c6e20b32677579 [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 412
#
# Test that if we have a file with a hole, do a mix of direct IO and buffered
# writes to it and truncate the file to a size that lies in the middle of the
# hole, after unmounting and mounting again the filesystem, the file has a
# correct size and no data loss happened.
#
. ./common/preamble
_begin_fstest auto quick metadata
# Import common functions.
. ./common/filter
_require_scratch
_require_odirect
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount
# Create out test file with two extents and a hole between those extents.
# The extent that lies beyond the hole must be written using direct IO and later
# we truncate the file to a size that lies within the hole's range.
$XFS_IO_PROG -f -c "pwrite -S 0x01 0K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
$XFS_IO_PROG -d -c "pwrite -S 0x02 -b 32K 64K 32K" $SCRATCH_MNT/foo \
| _filter_xfs_io
# Now truncate our file to a smaller size that lies behind the offset used by
# the previous direct IO write and that lies in a file hole.
$XFS_IO_PROG -c "truncate 60K" $SCRATCH_MNT/foo
# Now get file digests before unmounting the filesystem and after mounting it
# again. The digests should match (same file data and size in both cases).
echo "File digest before unmounting the filesystem:"
md5sum $SCRATCH_MNT/foo | _filter_scratch
_scratch_cycle_mount
echo "File digest after mounting again the filesystem:"
md5sum $SCRATCH_MNT/foo | _filter_scratch
status=0
exit