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
122
123
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. btrfs/226
#
# Test several (btrfs specific) scenarios with RWF_NOWAIT writes, cases where
# they should fail and cases where they should succeed.
#
. ./common/preamble
_begin_fstest auto quick rw snapshot clone prealloc punch
. ./common/filter
. ./common/reflink
_supported_fs btrfs
_require_scratch_reflink
_require_chattr C
_require_odirect
_require_xfs_io_command pwrite -N
_require_xfs_io_command falloc -k
_require_xfs_io_command fpunch
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount
# Test a write against COW file/extent - should fail with -EAGAIN. Disable the
# NOCOW attribute of the file just in case MOUNT_OPTIONS has "-o nodatacow".
echo "Testing write against COW file"
touch $SCRATCH_MNT/f1
$CHATTR_PROG -C $SCRATCH_MNT/f1
$XFS_IO_PROG -s -c "pwrite -S 0xab 0 128K" $SCRATCH_MNT/f1 | _filter_xfs_io
$XFS_IO_PROG -d -c "pwrite -N -V 1 -S 0xff 32K 64K" $SCRATCH_MNT/f1
# Check no data was written.
echo "File data after write attempt:"
od -A d -t x1 $SCRATCH_MNT/f1
# Create a file with two extents (NOCOW), then create a snapshot, unshare the
# first extent by writing to it without RWF_NOWAIT, and then attempt to write
# to a file range that includes both the non-shared and the shared extent -
# should fail with -EAGAIN.
echo
echo "Testing write against extent shared across snapshots"
touch $SCRATCH_MNT/f2
$CHATTR_PROG +C $SCRATCH_MNT/f2
$XFS_IO_PROG -s -c "pwrite -S 0xab 0 64K" \
-c "pwrite -S 0xcd 64K 64K" \
$SCRATCH_MNT/f2 | _filter_xfs_io
_btrfs subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
# Write into the range of the first extent so that that range no longer has a
# shared extent.
$XFS_IO_PROG -s -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/f2 | _filter_xfs_io
# Attempt to write into the file range, using RWF_NOWAIT, that covers the
# non-shared and the shared extents, should fail.
$XFS_IO_PROG -d -c "pwrite -N -V 1 -S 0xff -b 64K 32K 64K" $SCRATCH_MNT/f2
# Check no data was written.
echo "File data after write attempt:"
od -A d -t x1 $SCRATCH_MNT/f2
# Create a file that has an extent shared with file f2. Attempting to write
# into a range that covers the shared extent should fail with -EAGAIN.
echo
echo "Testing write against shared extent through reflink"
touch $SCRATCH_MNT/f3
$CHATTR_PROG +C $SCRATCH_MNT/f3
$XFS_IO_PROG -s -c "pwrite -S 0xab -b 64K 0 64K" \
-c "reflink $SCRATCH_MNT/f2 64K 64K 64K" \
$SCRATCH_MNT/f3 | _filter_xfs_io
# Should fail, range 64K to 96K has a shared extent.
$XFS_IO_PROG -d -c "pwrite -N -V 1 -S 0xff -b 64K 32K 64K" $SCRATCH_MNT/f3
# Check no data was written.
echo "File data after write attempt:"
od -A d -t x1 $SCRATCH_MNT/f3
# Create a file with a prealloc extent at eof and attempt to write to it, it
# should succeed.
echo
echo "Testing write against prealloc extent at eof"
$XFS_IO_PROG -f -s -c "pwrite -S 0xab 0 64K" \
-c "falloc -k 64K 64K" \
$SCRATCH_MNT/f4 | _filter_xfs_io
# Should succeed.
$XFS_IO_PROG -d -c "pwrite -N -V 1 -S 0xcd -b 64K 64K 64K" $SCRATCH_MNT/f4 \
| _filter_xfs_io
# Check the file has the expected data.
echo "File after write:"
od -A d -t x1 $SCRATCH_MNT/f4
# Attempts to write to ranges that have a hole, should fail with -EAGAIN.
echo
echo "Testing writes against ranges with holes"
touch $SCRATCH_MNT/f5
$CHATTR_PROG +C $SCRATCH_MNT/f5
# 3 64Kb extents, with a 64K hole at offset 128K.
$XFS_IO_PROG -s -d -c "pwrite -S 0xab -b 64K 0 64K" \
-s -d -c "pwrite -S 0xcd -b 64K 64K 64K" \
-s -d -c "pwrite -S 0xef -b 64K 192K 64K" \
$SCRATCH_MNT/f5 | _filter_xfs_io
# Should fail, second half of the range maps to a hole.
$XFS_IO_PROG -d -c "pwrite -N -V 1 -S 0x11 -b 128K 64K 128K" $SCRATCH_MNT/f5
# Now try with a range that starts with a hole and ends with an extent, should
# fail as well.
$XFS_IO_PROG -c "fpunch 0 64K" \
-d -c "pwrite -N -V 1 -S 0x22 -b 128K 0 128K" \
$SCRATCH_MNT/f5
# Check no data was written.
echo "File data after write attempt:"
od -A d -t x1 $SCRATCH_MNT/f5
status=0
exit
|