blob: 128c261a27b329557b7ffd7cf905ec9f5d4650a3 (
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014 Filipe Manana. All Rights Reserved.
#
# FS QA Test No. btrfs/056
#
# Regression test for btrfs ioctl clone operation + fsync + log recovery.
# The issue was that doing an fsync after cloning into a file didn't gave any
# persistence guarantees as it should. What happened was that the in memory
# metadata (extent maps) weren't updated, which made the fsync code not able
# to detect that file data has been changed.
#
# This issue is fixed by the following linux kernel btrfs patch:
#
# Btrfs: make fsync work after cloning into a file
#
. ./common/preamble
_begin_fstest auto quick clone log compress
# Override the default cleanup function.
_cleanup()
{
_cleanup_flakey
rm -fr $tmp
}
. ./common/filter
. ./common/dmflakey
_supported_fs btrfs
_require_scratch
_require_cloner
_require_btrfs_fs_feature "no_holes"
_require_btrfs_mkfs_feature "no-holes"
_require_dm_target flakey
test_btrfs_clone_fsync_log_recover()
{
_scratch_mkfs "$1" >/dev/null 2>&1
_init_flakey
SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
MOUNT_OPTIONS="$MOUNT_OPTIONS $2"
_mount_flakey
BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
EXTENT_SIZE=$((2 * $BLOCK_SIZE))
# Create a file with 4 extents and 1 hole, all with a size of
# 2 blocks each.
# The hole is in the block range [4, 5].
$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b $EXTENT_SIZE 0 $EXTENT_SIZE" \
-c "pwrite -S 0x02 -b $EXTENT_SIZE $((2 * $BLOCK_SIZE)) $EXTENT_SIZE" \
-c "pwrite -S 0x04 -b $EXTENT_SIZE $((6 * $BLOCK_SIZE)) $EXTENT_SIZE" \
-c "pwrite -S 0x05 -b $EXTENT_SIZE $((8 * $BLOCK_SIZE)) $EXTENT_SIZE" \
$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
# Clone destination file, 1 extent of 24 blocks.
$XFS_IO_PROG -f -c "pwrite -S 0xff -b $((24 * $BLOCK_SIZE)) 0 $((24 * $BLOCK_SIZE))" \
-c "fsync" $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
# Clone second half of the 2nd extent, the 2 block hole, the 3rd extent
# and the first half of the 4th extent into file bar.
$CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((6 * $BLOCK_SIZE)) \
$SCRATCH_MNT/foo $SCRATCH_MNT/bar
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
# Test small files too consisting of 1 inline extent
EXTENT_SIZE=$(($BLOCK_SIZE - 48))
$XFS_IO_PROG -f -c "pwrite -S 0x00 -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
$SCRATCH_MNT/foo2 | _filter_xfs_io_blocks_modified
EXTENT_SIZE=$(($BLOCK_SIZE - 1048))
$XFS_IO_PROG -f -c "pwrite -S 0xcc -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
$SCRATCH_MNT/bar2 | _filter_xfs_io_blocks_modified
# Clone the entire foo2 file into bar2, overwriting all data in bar2
# and increasing its size.
EXTENT_SIZE=$(($BLOCK_SIZE - 48))
$CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar2
_flakey_drop_and_remount yes
# Verify the cloned range was persisted by fsync and the log recovery
# code did its work well.
echo "Verifying file bar content"
od -t x1 $SCRATCH_MNT/bar | _filter_od
echo "Verifying file bar2 content"
od -t x1 $SCRATCH_MNT/bar2 | _filter_od
_unmount_flakey
# Verify that there are no consistency errors.
_check_scratch_fs $FLAKEY_DEV
_cleanup_flakey
MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
}
# Regardless of the NO_HOLES feature being enabled or not, the test results
# should be exactly the same for both cases.
echo "Testing without the NO_HOLES feature"
# As of btrfs-progs 3.14.x, the no-holes feature isn't enabled by default.
# But explicitly disable it at mkfs time as it might be enabled by default
# in future versions.
test_btrfs_clone_fsync_log_recover "-O ^no-holes"
echo "Testing without the NO_HOLES feature and compression (lzo)"
test_btrfs_clone_fsync_log_recover "-O ^no-holes" "-o compress-force=lzo"
echo "Testing with the NO_HOLES feature enabled"
test_btrfs_clone_fsync_log_recover "-O no-holes"
echo "Testing with the NO_HOLES feature enabled and compression (lzo)"
test_btrfs_clone_fsync_log_recover "-O no-holes" "-o compress-force=lzo"
status=0
exit
|