blob: 76750c335d8950586456f5bbdb62cfc8cd5df14c (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 101
#
# Test that if we truncate a file to a smaller size, then truncate it to its
# original size or a larger size, then fsyncing it and a power failure happens,
# the file will have the range [first_truncate_size, last_size[ with all bytes
# having a value of 0x00 if we read it the next time the filesystem is mounted.
#
# This test is motivated by a bug found in btrfs.
#
. ./common/preamble
_begin_fstest auto quick metadata log
# Override the default cleanup function.
_cleanup()
{
_cleanup_flakey
rm -f $tmp.*
}
# Import common functions.
. ./common/filter
. ./common/dmflakey
# real QA test starts here
_supported_fs generic
_require_scratch
_require_dm_target flakey
# This test was motivated by an issue found in btrfs when the btrfs no-holes
# feature is enabled (introduced in kernel 3.14). So enable the feature if the
# fs being tested is btrfs.
if [ $FSTYP == "btrfs" ]; then
_require_btrfs_fs_feature "no_holes"
_require_btrfs_mkfs_feature "no-holes"
MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
fi
_scratch_mkfs >>$seqres.full 2>&1
_require_metadata_journaling $SCRATCH_DEV
_init_flakey
_mount_flakey
# Create our test files and make sure everything is durably persisted.
$XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" \
-c "pwrite -S 0xbb 64K 61K" \
$SCRATCH_MNT/foo | _filter_xfs_io
$XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K" \
-c "pwrite -S 0xff 64K 61K" \
$SCRATCH_MNT/bar | _filter_xfs_io
sync
# Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
# size it had before the shrinking truncate (125Kb). Then fsync our file. If a
# power failure happens after the fsync, we expect our file to have a size of
# 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
# of data having the value 0x00.
$XFS_IO_PROG -c "truncate 64K" \
-c "truncate 125K" \
-c "fsync" \
$SCRATCH_MNT/foo
# Do something similar to our file bar, but the first truncation sets the file
# size to 0 and the second truncation expands the size to the double of what it
# was initially.
$XFS_IO_PROG -c "truncate 0" \
-c "truncate 253K" \
-c "fsync" \
$SCRATCH_MNT/bar
_flakey_drop_and_remount
# We expect foo to have a size of 125Kb, the first 64Kb of data all having the
# value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
echo "File foo content after log replay:"
od -t x1 $SCRATCH_MNT/foo
# We expect bar to have a size of 253Kb and no extents (any byte read from bar
# has the value 0x00).
echo "File bar content after log replay:"
od -t x1 $SCRATCH_MNT/bar
status=0
exit
|