linux/fs/xfs
Zhang Yi 5ce5674187 xfs: convert delayed extents to unwritten when zeroing post eof blocks
Current clone operation could be non-atomic if the destination of a file
is beyond EOF, user could get a file with corrupted (zeroed) data on
crash.

The problem is about preallocations. If you write some data into a file:

	[A...B)

and XFS decides to preallocate some post-eof blocks, then it can create
a delayed allocation reservation:

	[A.........D)

The writeback path tries to convert delayed extents to real ones by
allocating blocks. If there aren't enough contiguous free space, we can
end up with two extents, the first real and the second still delalloc:

	[A....C)[C.D)

After that, both the in-memory and the on-disk file sizes are still B.
If we clone into the range [E...F) from another file:

	[A....C)[C.D)      [E...F)

then xfs_reflink_zero_posteof() calls iomap_zero_range() to zero out the
range [B, E) beyond EOF and flush it. Since [C, D) is still a delalloc
extent, its pagecache will be zeroed and both the in-memory and on-disk
size will be updated to D after flushing but before cloning. This is
wrong, because the user can see the size change and read the zeroes
while the clone operation is ongoing.

We need to keep the in-memory and on-disk size before the clone
operation starts, so instead of writing zeroes through the page cache
for delayed ranges beyond EOF, we convert these ranges to unwritten and
invalidate any cached data over that range beyond EOF.

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
2024-04-29 17:23:11 +05:30
..
libxfs xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset 2024-04-29 17:23:11 +05:30
scrub xfs: refactor dir format helpers 2024-04-26 11:21:46 +05:30
Kconfig xfs: support in-memory btrees 2024-02-22 12:43:35 -08:00
Makefile xfs: fix corruptions in the directory tree 2024-04-23 16:55:17 -07:00
xfs_acl.c xfs: make attr removal an explicit operation 2024-04-23 07:46:51 -07:00
xfs_acl.h
xfs_aops.c xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset 2024-04-29 17:23:11 +05:30
xfs_aops.h
xfs_attr_inactive.c xfs: report dir/attr block corruption errors to the health system 2024-02-22 12:32:18 -08:00
xfs_attr_item.c xfs: add parent pointer validator functions 2024-04-23 07:46:57 -07:00
xfs_attr_item.h xfs: create attr log item opcodes and formats for parent pointers 2024-04-23 07:46:57 -07:00
xfs_attr_list.c xfs: pass the attr value to put_listent when possible 2024-04-23 07:47:00 -07:00
xfs_bio_io.c
xfs_bmap_item.c xfs: support recovering bmap intent items targetting realtime extents 2024-02-22 12:44:24 -08:00
xfs_bmap_item.h xfs: move xfs_bmap_defer_add to xfs_bmap_item.c 2024-02-22 12:44:21 -08:00
xfs_bmap_util.c xfs: hoist multi-fsb allocation unit detection to a helper 2024-04-15 14:54:11 -07:00
xfs_bmap_util.h xfs: indicate if xfs_bmap_adjacent changed ap->blkno 2023-12-22 11:18:11 +05:30
xfs_buf_item_recover.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_buf_item.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_buf_item.h
xfs_buf_mem.c xfs: fix dev_t usage in xmbuf tracepoints 2024-03-15 10:30:23 +05:30
xfs_buf_mem.h xfs: launder in-memory btree buffers before transaction commit 2024-02-22 12:43:36 -08:00
xfs_buf.c xfs: repair extended attributes 2024-04-15 14:58:53 -07:00
xfs_buf.h New code for 6.9: 2024-03-13 13:52:24 -07:00
xfs_dahash_test.c
xfs_dahash_test.h
xfs_dir2_readdir.c xfs: refactor dir format helpers 2024-04-26 11:21:46 +05:30
xfs_discard.c xfs: fix performance problems when fstrimming a subset of a fragmented AG 2024-04-15 14:59:00 -07:00
xfs_discard.h xfs: move log discard work to xfs_discard.c 2023-10-04 09:24:02 +11:00
xfs_dquot_item_recover.c xfs: dquot recovery does not validate the recovered dquot 2023-11-22 23:39:36 +05:30
xfs_dquot_item.c
xfs_dquot_item.h
xfs_dquot.c xfs: Increase XFS_QM_TRANS_MAXDQS to 5 2024-04-15 14:59:01 -07:00
xfs_dquot.h xfs: Increase XFS_QM_TRANS_MAXDQS to 5 2024-04-15 14:59:01 -07:00
xfs_drain.c
xfs_drain.h
xfs_error.c xfs: add error injection to test file mapping exchange recovery 2024-04-15 14:54:19 -07:00
xfs_error.h
xfs_exchmaps_item.c xfs: capture inode generation numbers in the ondisk exchmaps log item 2024-04-15 14:54:24 -07:00
xfs_exchmaps_item.h xfs: create deferred log items for file mapping exchanges 2024-04-15 14:54:17 -07:00
xfs_exchrange.c xfs: support non-power-of-two rtextsize with exchange-range 2024-04-15 14:54:23 -07:00
xfs_exchrange.h xfs: create deferred log items for file mapping exchanges 2024-04-15 14:54:17 -07:00
xfs_export.c xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_export.h xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_extent_busy.c xfs: unwind xfs_extent_busy_clear 2024-04-22 12:53:34 +05:30
xfs_extent_busy.h xfs: repair free space btrees 2023-12-15 10:03:32 -08:00
xfs_extfree_item.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_extfree_item.h
xfs_file.c xfs: refactor non-power-of-two alignment checks 2024-04-15 14:54:12 -07:00
xfs_file.h xfs: create a new helper to return a file's allocation unit 2024-04-15 14:54:10 -07:00
xfs_filestream.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_filestream.h
xfs_fsmap.c xfs: refactor realtime inode locking 2024-04-22 18:00:47 +05:30
xfs_fsmap.h
xfs_fsops.c xfs: split xfs_mod_freecounter 2024-04-22 18:00:47 +05:30
xfs_fsops.h xfs: split xfs_mod_freecounter 2024-04-22 18:00:47 +05:30
xfs_globals.c xfs: add debug knobs to control btree bulk load slack factors 2023-12-15 10:03:28 -08:00
xfs_handle.c xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_handle.h xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_health.c xfs: report directory tree corruption in the health information 2024-04-23 16:55:17 -07:00
xfs_hooks.c xfs: allow scrub to hook metadata updates in other writers 2024-02-22 12:30:45 -08:00
xfs_hooks.h xfs: allow scrub to hook metadata updates in other writers 2024-02-22 12:30:45 -08:00
xfs_icache.c xfs: don't use current->journal_info 2024-03-25 10:21:01 +05:30
xfs_icache.h xfs: use per-mount cpumask to track nonempty percpu inodegc lists 2023-09-11 08:39:03 -07:00
xfs_icreate_item.c xfs: convert kmem_free() for kvmalloc users to kvfree() 2024-02-13 18:07:34 +05:30
xfs_icreate_item.h
xfs_inode_item_recover.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_inode_item.c xfs: Replace xfs_isilocked with xfs_assert_ilocked 2024-02-19 21:19:33 +05:30
xfs_inode_item.h
xfs_inode.c xfs: fix corruptions in the directory tree 2024-04-23 16:55:17 -07:00
xfs_inode.h xfs: fix corruptions in the directory tree 2024-04-23 16:55:17 -07:00
xfs_ioctl.c xfs: introduce vectored scrub mode 2024-04-23 16:55:18 -07:00
xfs_ioctl.h xfs: move handle ioctl code to xfs_handle.c 2024-04-23 07:47:00 -07:00
xfs_ioctl32.c xfs: move handle ioctl code to xfs_handle.c 2024-04-23 07:47:00 -07:00
xfs_ioctl32.h arch: Remove Itanium (IA-64) architecture 2023-09-11 08:13:17 +00:00
xfs_iomap.c xfs: convert delayed extents to unwritten when zeroing post eof blocks 2024-04-29 17:23:11 +05:30
xfs_iomap.h
xfs_iops.c xfs: parent pointer attribute creation 2024-04-23 07:46:58 -07:00
xfs_iops.h xfs: declare xfs_file.c symbols in xfs_file.h 2024-04-15 14:54:09 -07:00
xfs_itable.c xfs: hide private inodes from bulkstat and handle functions 2024-04-15 14:58:48 -07:00
xfs_itable.h
xfs_iunlink_item.c
xfs_iunlink_item.h
xfs_iwalk.c xfs: pass xfs_buf lookup flags to xfs_*read_agi 2024-04-15 14:54:03 -07:00
xfs_iwalk.h
xfs_linux.h xfs: refactor non-power-of-two alignment checks 2024-04-15 14:54:12 -07:00
xfs_log_cil.c xfs: fix CIL sparse lock context warnings 2024-04-20 20:23:59 +05:30
xfs_log_priv.h xfs: Fix typo in comment 2024-04-22 12:51:43 +05:30
xfs_log_recover.c xfs: capture inode generation numbers in the ondisk exchmaps log item 2024-04-15 14:54:24 -07:00
xfs_log.c xfs: only clear log incompat flags at clean unmount 2024-04-15 14:54:06 -07:00
xfs_log.h xfs: only clear log incompat flags at clean unmount 2024-04-15 14:54:06 -07:00
xfs_message.c
xfs_message.h
xfs_mount.c xfs: use an XFS_OPSTATE_ flag for detecting if logged xattrs are available 2024-04-23 07:46:51 -07:00
xfs_mount.h xfs: use an XFS_OPSTATE_ flag for detecting if logged xattrs are available 2024-04-23 07:46:51 -07:00
xfs_mru_cache.c xfs: use GFP_KERNEL in pure transaction contexts 2024-02-13 18:07:35 +05:30
xfs_mru_cache.h
xfs_notify_failure.c mm, pmem, xfs: Introduce MF_MEM_PRE_REMOVE for unbind 2023-12-07 14:34:26 +05:30
xfs_pnfs.c
xfs_pnfs.h
xfs_pwork.c
xfs_pwork.h
xfs_qm_bhv.c xfs: track quota updates during live quotacheck 2024-02-22 12:30:55 -08:00
xfs_qm_syscalls.c
xfs_qm.c xfs: Hold inode locks in xfs_ialloc 2024-04-15 14:59:02 -07:00
xfs_qm.h xfs: Increase XFS_QM_TRANS_MAXDQS to 5 2024-04-15 14:59:01 -07:00
xfs_quota.h xfs: track quota updates during live quotacheck 2024-02-22 12:30:55 -08:00
xfs_quotaops.c
xfs_refcount_item.c xfs: place intent recovery under NOFS allocation context 2024-02-13 18:07:35 +05:30
xfs_refcount_item.h
xfs_reflink.c xfs: support deferred bmap updates on the attr fork 2024-02-22 12:44:32 -08:00
xfs_reflink.h
xfs_rmap_item.c xfs: place intent recovery under NOFS allocation context 2024-02-13 18:07:35 +05:30
xfs_rmap_item.h
xfs_rtalloc.c xfs: reinstate delalloc for RT inodes (if sb_rextsize == 1) 2024-04-22 18:00:50 +05:30
xfs_rtalloc.h xfs: move xfs_bmap_rtalloc to xfs_rtalloc.c 2023-12-22 11:18:11 +05:30
xfs_stats.c xfs: define an in-memory btree for storing refcount bag info during repairs 2024-02-22 12:43:40 -08:00
xfs_stats.h xfs: define an in-memory btree for storing refcount bag info during repairs 2024-02-22 12:43:40 -08:00
xfs_super.c xfs: add a incompat feature bit for parent pointers 2024-04-23 07:47:01 -07:00
xfs_super.h xfs: create scaffolding for creating debugfs entries 2023-08-10 07:48:07 -07:00
xfs_symlink.c xfs: add parent attributes to symlink 2024-04-23 07:46:58 -07:00
xfs_symlink.h xfs: move remote symlink target read function to libxfs 2024-02-22 12:45:17 -08:00
xfs_sysctl.c fs: Remove the now superfluous sentinel elements from ctl_table array 2023-12-28 04:57:57 -08:00
xfs_sysctl.h xfs: add debug knobs to control btree bulk load slack factors 2023-12-15 10:03:28 -08:00
xfs_sysfs.c xfs: remove duplicate ifdefs 2024-02-17 09:32:32 +05:30
xfs_sysfs.h
xfs_trace.c xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_trace.h xfs: add parent pointer ioctls 2024-04-23 07:47:00 -07:00
xfs_trans_ail.c xfs: convert remaining kmem_free() to kfree() 2024-02-13 18:07:34 +05:30
xfs_trans_buf.c xfs: launder in-memory btree buffers before transaction commit 2024-02-22 12:43:36 -08:00
xfs_trans_dquot.c xfs: Increase XFS_QM_TRANS_MAXDQS to 5 2024-04-15 14:59:01 -07:00
xfs_trans_priv.h
xfs_trans.c xfs: split xfs_mod_freecounter 2024-04-22 18:00:47 +05:30
xfs_trans.h xfs: don't use current->journal_info 2024-03-25 10:21:01 +05:30
xfs_xattr.c xfs: make the reserved block permission flag explicit in xfs_attr_set 2024-04-23 07:47:03 -07:00
xfs_xattr.h xfs: remove xfs_da_args.attr_flags 2024-04-23 07:46:50 -07:00
xfs.h