summaryrefslogtreecommitdiff
path: root/tests/generic/484
blob: 4f413352b6bfe7ffd32192244c6838c39598795f (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2020, Jeff Layton. All rights reserved.
# FS QA Test No. 484
#
# Open a file and write to it and fsync. Then, flip the data device to throw
# errors, write to it again and do an fdatasync. Then open an O_RDONLY fd on
# the same file and call syncfs against it and ensure that an error is reported.
# Then call syncfs again and ensure that no error is reported. Finally, repeat
# the open and syncfs and ensure that there is no error reported.
#
# Kernel with the following patches should pass the test:
#
#    vfs: track per-sb writeback errors and report them to syncfs
#    buffer: record blockdev write errors in super_block that it backs

. ./common/preamble
_begin_fstest auto quick eio

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

# Import common functions.
. ./common/filter
. ./common/dmerror

# real QA test starts here
_require_scratch_nocheck
_require_dm_target error
_require_xfs_io_command "syncfs"

# Disable the scratch rt device to avoid test failures relating to the rt
# bitmap consuming all the free space in our small data device.
unset SCRATCH_RTDEV

echo "Format and mount"
_scratch_mkfs > $seqres.full 2>&1
_dmerror_init
_dmerror_mount

# create file
testfile=$SCRATCH_MNT/syncfs-reports-errors
touch $testfile

# write a page of data to file, and call fsync
datalen=$(getconf PAGE_SIZE)
$XFS_IO_PROG -c "pwrite -W -q 0 $datalen" $testfile

# flip device to non-working mode
_dmerror_load_error_table

# rewrite the data and call fdatasync
$XFS_IO_PROG -c "pwrite -w -q 0 $datalen" $testfile

# heal the device error
_dmerror_load_working_table

# open again and call syncfs twice
echo "One of the following syncfs calls should fail with EIO:"
$XFS_IO_PROG -r -c syncfs -c syncfs $testfile
echo "done"

echo "This syncfs call should succeed:"
$XFS_IO_PROG -r -c syncfs $testfile
echo "done"

# success, all done
_dmerror_cleanup

status=0
exit