From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
xfs <linux-xfs@vger.kernel.org>,
Christoph Hellwig <hch@infradead.org>,
sunjunchao2870@gmail.com, jack@suse.cz
Subject: Re: [PATCH 2/2] iomap: constrain the file range passed to iomap_file_unshare
Date: Wed, 2 Oct 2024 12:01:39 -0400 [thread overview]
Message-ID: <Zv1uY_fH_L-MWU25@bfoster> (raw)
In-Reply-To: <20241002150213.GC21853@frogsfrogsfrogs>
On Wed, Oct 02, 2024 at 08:02:13AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> File contents can only be shared (i.e. reflinked) below EOF, so it makes
> no sense to try to unshare ranges beyond EOF. Constrain the file range
> parameters here so that we don't have to do that in the callers.
>
> Fixes: 5f4e5752a8a3 ("fs: add iomap_file_dirty")
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/dax.c | 6 +++++-
> fs/iomap/buffered-io.c | 6 +++++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/fs/dax.c b/fs/dax.c
> index becb4a6920c6a..c62acd2812f8d 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -1305,11 +1305,15 @@ int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len,
> struct iomap_iter iter = {
> .inode = inode,
> .pos = pos,
> - .len = len,
> .flags = IOMAP_WRITE | IOMAP_UNSHARE | IOMAP_DAX,
> };
> + loff_t size = i_size_read(inode);
> int ret;
>
> + if (pos < 0 || pos >= size)
> + return 0;
> +
> + iter.len = min(len, size - pos);
> while ((ret = iomap_iter(&iter, ops)) > 0)
> iter.processed = dax_unshare_iter(&iter);
> return ret;
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index c1c559e0cc07c..78ebd265f4259 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -1375,11 +1375,15 @@ iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
> struct iomap_iter iter = {
> .inode = inode,
> .pos = pos,
> - .len = len,
> .flags = IOMAP_WRITE | IOMAP_UNSHARE,
> };
> + loff_t size = i_size_read(inode);
> int ret;
>
> + if (pos < 0 || pos >= size)
> + return 0;
> +
> + iter.len = min(len, size - pos);
> while ((ret = iomap_iter(&iter, ops)) > 0)
> iter.processed = iomap_unshare_iter(&iter);
> return ret;
>
Heh. This was pretty much my local fix when I was testing fsx unshare
range, so LGTM. Apologies, I probably should have just sent it out. It
just seemed like Julian was 90% there, but then review went off the
rails and I guess I lost interest. Anyways, thanks for the fix:
Reviewed-by: Brian Foster <bfoster@redhat.com>
next prev parent reply other threads:[~2024-10-02 16:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 15:00 [PATCH 1/2] iomap: don't bother unsharing delalloc extents Darrick J. Wong
2024-10-02 15:02 ` [PATCH 2/2] iomap: constrain the file range passed to iomap_file_unshare Darrick J. Wong
2024-10-02 15:15 ` Christoph Hellwig
2024-10-02 16:01 ` Brian Foster [this message]
2024-10-03 11:02 ` Julian Sun
2024-10-02 15:14 ` [PATCH 1/2] iomap: don't bother unsharing delalloc extents Christoph Hellwig
2024-10-02 16:01 ` Brian Foster
2024-10-02 16:57 ` Darrick J. Wong
2024-10-03 8:23 ` Christian Brauner
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=Zv1uY_fH_L-MWU25@bfoster \
--to=bfoster@redhat.com \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sunjunchao2870@gmail.com \
/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).