Re: [PATCH 6/6] xfs: refactor xfs_file_fallocate
From: Brian Foster <hidden>
Date: 2024-08-21 12:43:48
Also in:
linux-ext4, linux-fsdevel, linux-xfs
On Wed, Aug 21, 2024 at 08:30:32AM +0200, Christoph Hellwig wrote:
quoted hunk ↗ jump to hunk
Refactor xfs_file_fallocate into separate helpers for each mode, two factors for i_size handling and a single switch statement over the supported modes. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/xfs/xfs_file.c | 327 +++++++++++++++++++++++++++++----------------- 1 file changed, 205 insertions(+), 122 deletions(-)diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 489bc1b173c268..9d3bac7731bdcb 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c@@ -852,6 +852,189 @@ static inline bool xfs_file_sync_writes(struct file *filp) return false; }
...
+
+static int
+xfs_falloc_unshare_range(
+ struct file *file,
+ int mode,
+ loff_t offset,
+ loff_t len)
+{
+ struct inode *inode = file_inode(file);
+ loff_t new_size = 0;
+ int error;
+
+ error = xfs_falloc_newsize(file, mode, offset, len, &new_size);
+ if (error)
+ return error;
+
+ error = xfs_reflink_unshare(XFS_I(inode), offset, len);
+ if (error)
+ return error;
+Doesn't unshare imply alloc?
+ return xfs_falloc_setsize(file, new_size); +} +
...
quoted hunk ↗ jump to hunk
@@ -894,129 +1075,31 @@ xfs_file_fallocate( if (error) goto out_unlock; - if (mode & FALLOC_FL_PUNCH_HOLE) { + switch (mode & FALLOC_FL_MODE_MASK) { + case FALLOC_FL_PUNCH_HOLE: error = xfs_free_file_space(ip, offset, len);
...
+ break; + case FALLOC_FL_COLLAPSE_RANGE: + error = xfs_falloc_collapse_range(file, offset, len); + break; + case FALLOC_FL_INSERT_RANGE: + error = xfs_falloc_insert_range(file, offset, len); + break; + case FALLOC_FL_ZERO_RANGE: + error = xfs_falloc_zero_range(file, mode, offset, len); + break; + case FALLOC_FL_UNSHARE_RANGE: + error = xfs_falloc_unshare_range(file, mode, offset, len); + break; + case FALLOC_FL_ALLOCATE_RANGE: + error = xfs_falloc_allocate_range(file, mode, offset, len); + break; + default: + error = -EOPNOTSUPP; + break; } - if (xfs_file_sync_writes(file)) + if (!error && xfs_file_sync_writes(file)) error = xfs_log_force_inode(ip);
I'd think if you hit -ENOSPC or something after doing a partial alloc to a sync inode, you'd still want to flush the changes that were made..? Brian
out_unlock: -- 2.43.0