fstests: add a generic test to verify direct IO writes with buffer contents change
There is a long existing btrfs problem that if some one is modifying the
buffer of an on-going direct IO write, it has a very high chance causing
permanent data checksum mismatch.
This is caused by the following factors:
- Direct IO buffer is out of the control of filesystem
Thus user space can modify the contents during writeback.
- Btrfs generate its data checksum just before submitting the bio
This means if the contents happens after the checksum is generated,
the data written to disk will no longer match the checksum.
Btrfs later fixes the problem by forcing the direct IO to fallback to
buffered IO (if the inode requires data checksum), so that btrfs can
have a consistent view of the buffer.
This test case will verify the behavior by:
- Create a helper program 'dio-writeback-race'
Which does direct IO writes block-by-block, and the buffer is always
initialized to all 0xff before write,
Then starting two threads:
- One to submit the direct IO
- One to modify the buffer to 0x00
The program uses 4K as default block size, and 64MiB as the default
file size.
Which is more than enough to trigger tons of btrfs checksum errors
on unpatched kernels.
- New test case generic/761
Which will:
* Use above program to create a 64MiB file
* Do buffered read on that file
Since above program is doing direct IO, there is no page cache
populated.
And the buffered read will need to read out all data from the disk,
and if the filesystem supports data checksum, then the data checksum
will also be verified against the data.
The test case passes on the following fses:
- ext4
- xfs
- btrfs with "nodatasum" mount option
No data checksum to bother.
- btrfs with default "datasum" mount option and the fix "btrfs: always
fallback to buffered write if the inode requires checksum"
This makes btrfs to fallback on buffered IO so the contents won't
change during writeback of page cache.
And fails on the following fses:
- btrfs with default "datasum" mount option and without the fix
Expected.
Suggested-by: Christoph Hellwig <hch@infradead.org> Reviewed-by: David Disseldorp <ddiss@suse.de> Reviewed-by: Zorro Lang <zlang@redhat.com> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Zorro Lang <zlang@kernel.org>