summaryrefslogtreecommitdiff
path: root/tests/generic/177
blob: ff55a79f97263a303dbe775288b447fc6cb35bae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 177
#
# Test that a file fsync works after punching a hole for the same file range
# multiple times and that after log/journal replay the file's content is
# correct.
#
# This test is motivated by a bug found in btrfs.
#
. ./common/preamble
_begin_fstest auto quick prealloc metadata punch log fiemap

# Override the default cleanup function.
_cleanup()
{
	_cleanup_flakey
	cd /
	rm -f $tmp.*
}

# Import common functions.
. ./common/filter
. ./common/punch
. ./common/dmflakey

# real QA test starts here
_supported_fs generic
_require_scratch
_require_xfs_io_command "fpunch"
_require_xfs_io_command "fiemap"
_require_dm_target flakey

_scratch_mkfs >>$seqres.full 2>&1
_require_metadata_journaling $SCRATCH_DEV
_init_flakey
_mount_flakey

BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)

# Create out test file with some data and then fsync it.
# We do the fsync only to make sure the last fsync we do in this test triggers
# the fast code path of btrfs' fsync implementation, a condition necessary to
# trigger the bug btrfs had.
$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $(($BLOCK_SIZE * 32))" \
		-c "fsync"                  \
		$SCRATCH_MNT/foobar | _filter_xfs_io_blocks_modified

# Now punch a hole against the range [96K, 128K[.
$XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 24)) $(($BLOCK_SIZE * 8))" $SCRATCH_MNT/foobar

# Punch another hole against a range that overlaps the previous range and ends
# beyond eof.
$XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 16)) $(($BLOCK_SIZE * 32))" $SCRATCH_MNT/foobar

# Punch another hole against a range that overlaps the first range ([96K, 128K[)
# and ends at eof.
$XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 8)) $(($BLOCK_SIZE * 24))" $SCRATCH_MNT/foobar

# Fsync our file. We want to verify that, after a power failure and mounting the
# filesystem again, the file content reflects all the hole punch operations.
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar

echo "File digest before power failure:"
od -t x1 $SCRATCH_MNT/foobar | _filter_od

echo "Fiemap before power failure:"
$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap $BLOCK_SIZE

_flakey_drop_and_remount

echo "File digest after log replay:"
# Must match the same digest we got before the power failure.
od -t x1 $SCRATCH_MNT/foobar | _filter_od

echo "Fiemap after log replay:"
# Must match the same extent listing we got before the power failure.
$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap $BLOCK_SIZE

_unmount_flakey

status=0
exit