summaryrefslogtreecommitdiff
path: root/tests/btrfs/159
blob: 0cbf5be142dca16ac52aebeee03e2e33e6d14730 (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
86
87
88
89
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 159
#
# Test that when we have the no-holes mode enabled and a specific metadata
# layout, if we punch a hole and fsync the file, at replay time the whole
# hole was preserved.
#
. ./common/preamble
_begin_fstest auto quick punch log

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

. ./common/filter
. ./common/dmflakey

_supported_fs btrfs
_require_scratch
_require_dm_target flakey
_require_xfs_io_command "fpunch"
_require_odirect

run_test()
{
	local punch_offset=$1

	# We create the filesystem with a node size of 64Kb because we need to
	# create a specific metadata layout in order to trigger the bug we are
	# testing. At the moment the node size can not be smaller then the
	# system's page size, so given that the largest possible page size is
	# 64Kb and by default the node size is set to the system's page size
	# value, we explicitly create a filesystem with a 64Kb node size.
	_scratch_mkfs -O no-holes -n $((64 * 1024)) >>$seqres.full 2>&1
	_require_metadata_journaling $SCRATCH_DEV
	_init_flakey
	_mount_flakey

	# Create our test file with 832 extents of 256Kb each. Before each
	# extent, there is a 256Kb hole (except for the first extent, which
	# starts at offset 0). This creates two leafs in the filesystem tree.
	# We use direct IO to ensure we get exactly 256K extents (with buffered
	# IO we can get writeback triggered at any time and therefore get
	# extents smaller than 256K).
	for ((i = 0; i <= 831; i++)); do
		local offset=$((i * 2 * 256 * 1024))
		$XFS_IO_PROG -f -d -c "pwrite -S 0xab -b 256K $offset 256K" \
			$SCRATCH_MNT/foobar >/dev/null
	done

	# Make sure everything done so far is durably persisted.
	sync

	# Now punch a hole that covers part of the extent at offset
	# "$punch_offset".
	# We want to punch a hole that starts in the middle of the last extent
	# item in the first leaf. On a system without selinux enabled that is
	# the extent that starts at offset 216530944, while on a system with it
	# enabled it is the extent that starts at offset 216006656 (because
	# selinux causes a xattr item to be added to our test file).
	$XFS_IO_PROG -c "fpunch $((punch_offset + 128 * 1024 - 4000)) 256K" \
		     -c "fsync" \
		     $SCRATCH_MNT/foobar

	echo "File digest before power failure:"
	md5sum $SCRATCH_MNT/foobar | _filter_scratch
	# Simulate a power failure and mount the filesystem to check that
	# replaying the fsync log/journal succeeds and our test file has the
	# expected content.
	_flakey_drop_and_remount
	echo "File digest after power failure and log replay:"
	md5sum $SCRATCH_MNT/foobar | _filter_scratch

	_unmount_flakey
	_cleanup_flakey
}

run_test 216006656
run_test 216530944

status=0
exit