xfs: use iomap_valid method to detect stale cached iomaps
authorDave Chinner <dchinner@redhat.com>
Mon, 28 Nov 2022 22:09:17 +0000 (09:09 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 28 Nov 2022 22:09:17 +0000 (09:09 +1100)
commit304a68b9c63bbfc1f6e159d68e8892fc54a06067
treeb3e4a82479f6e67701679f2fd3b7b8702a81dbd3
parentd7b64041164ca177170191d2ad775da074ab2926
xfs: use iomap_valid method to detect stale cached iomaps

Now that iomap supports a mechanism to validate cached iomaps for
buffered write operations, hook it up to the XFS buffered write ops
so that we can avoid data corruptions that result from stale cached
iomaps. See:

https://lore.kernel.org/linux-xfs/20220817093627.GZ3600936@dread.disaster.area/

or the ->iomap_valid() introduction commit for exact details of the
corruption vector.

The validity cookie we store in the iomap is based on the type of
iomap we return. It is expected that the iomap->flags we set in
xfs_bmbt_to_iomap() is not perturbed by the iomap core and are
returned to us in the iomap passed via the .iomap_valid() callback.
This ensures that the validity cookie is always checking the correct
inode fork sequence numbers to detect potential changes that affect
the extent cached by the iomap.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/xfs_aops.c
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_pnfs.c