From: Brian Foster <bfoster@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Chandan Babu R <chandan.babu@oracle.com>,
Jens Axboe <axboe@kernel.dk>, Jan Kara <jack@suse.cz>,
"Darrick J. Wong" <djwong@kernel.org>,
Theodore Ts'o <tytso@mit.edu>,
linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: Re: [PATCH 6/6] xfs: refactor xfs_file_fallocate
Date: Wed, 21 Aug 2024 08:44:31 -0400 [thread overview]
Message-ID: <ZsXhL_pJhq2qyy-l@bfoster> (raw)
In-Reply-To: <20240821063108.650126-7-hch@lst.de>
On Wed, Aug 21, 2024 at 08:30:32AM +0200, Christoph Hellwig wrote:
> 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);
> +}
> +
...
> @@ -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
>
>
next prev parent reply other threads:[~2024-08-21 12:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 6:30 sort out the fallocate mode mess Christoph Hellwig
2024-08-21 6:30 ` [PATCH 1/6] block: remove checks for FALLOC_FL_NO_HIDE_STALE Christoph Hellwig
2024-08-21 6:30 ` [PATCH 2/6] ext4: remove tracing " Christoph Hellwig
2024-08-21 6:30 ` [PATCH 3/6] fs: sort out the fallocate mode vs flag mess Christoph Hellwig
2024-08-21 12:43 ` Brian Foster
2024-08-21 13:14 ` Christoph Hellwig
2024-08-21 6:30 ` [PATCH 4/6] xfs: call xfs_flush_unmap_range from xfs_free_file_space Christoph Hellwig
2024-08-21 6:30 ` [PATCH 5/6] xfs: move the xfs_is_always_cow_inode check into xfs_alloc_file_space Christoph Hellwig
2024-08-21 6:30 ` [PATCH 6/6] xfs: refactor xfs_file_fallocate Christoph Hellwig
2024-08-21 12:44 ` Brian Foster [this message]
2024-08-21 12:57 ` Christoph Hellwig
2024-08-21 13:09 ` Brian Foster
2024-08-21 16:11 ` sort out the fallocate mode mess Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2024-08-27 6:50 sort out the fallocate mode mess v2 Christoph Hellwig
2024-08-27 6:50 ` [PATCH 6/6] xfs: refactor xfs_file_fallocate Christoph Hellwig
2024-08-27 16:07 ` Darrick J. Wong
2024-08-28 4:07 ` Christoph Hellwig
2024-08-29 3:11 ` Dave Chinner
2024-08-29 3:56 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZsXhL_pJhq2qyy-l@bfoster \
--to=bfoster@redhat.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=chandan.babu@oracle.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).