blob: 69801295894eeeb1734710a17660d51463c87f9f (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 231
#
# Test that when using the NO_HOLES feature, if we truncate down a file, clone a
# file range covering only a hole into an offset beyond the current file size,
# and then fsync the file, after a power failure we get the expected file content
# and we do not get stale data corresponding to file extents that existed before
# truncating the file.
#
. ./common/preamble
_begin_fstest auto quick clone log replay
# Override the default cleanup function.
_cleanup()
{
_cleanup_flakey
cd /
rm -f $tmp.*
}
. ./common/filter
. ./common/dmflakey
_supported_fs btrfs
_require_scratch
_require_btrfs_fs_feature "no_holes"
_require_btrfs_mkfs_feature "no-holes"
_require_dm_target flakey
_scratch_mkfs -O no-holes >>$seqres.full 2>&1
_require_metadata_journaling $SCRATCH_DEV
_init_flakey
_mount_flakey
# Create our test file with 3 extents of 256K and a 256K hole at offset 256K.
# The file has a size of 1280K.
$XFS_IO_PROG -f -s \
-c "pwrite -S 0xab -b 256K 0 256K" \
-c "pwrite -S 0xcd -b 256K 512K 256K" \
-c "pwrite -S 0xef -b 256K 768K 256K" \
-c "pwrite -S 0x73 -b 256K 1024K 256K" \
$SCRATCH_MNT/foobar | _filter_xfs_io
# Make sure it's durably persisted. We want the last committed super block to
# point to this particular file extent layout.
sync
# Now truncate our file to a smaller size, falling within a position of the
# second extent. This sets the full sync runtime flag on the inode.
# Then fsync the file to log it and clear the full sync flag from the inode.
# The third extent is no longer part of the file and therefore it is not logged.
$XFS_IO_PROG -c "truncate 800K" -c "fsync" $SCRATCH_MNT/foobar
# Now do a clone operation that only clones the hole and sets back the file size
# to match the size it had before the truncate operation (1280K).
$XFS_IO_PROG \
-c "reflink $SCRATCH_MNT/foobar 256K 1024K 256K" \
-c "fsync" \
$SCRATCH_MNT/foobar | _filter_xfs_io
echo "File data before power failure:"
od -A d -t x1 $SCRATCH_MNT/foobar
# Simulate a power failure and then mount again the filesystem to replay the log
# tree.
_flakey_drop_and_remount
# This should match what we got before the power failure. The range from 1024K
# to 1280K should be a hole and not point to an extent full of bytes with a
# value of 0x73.
echo "File data after power failure:"
od -A d -t x1 $SCRATCH_MNT/foobar
_unmount_flakey
status=0
exit
|