[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1760415.1636036338@warthog.procyon.org.uk>
Date: Thu, 04 Nov 2021 14:32:18 +0000
From: David Howells <dhowells@...hat.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: dhowells@...hat.com, Jeff Layton <jlayton@...nel.org>,
Marc Dionne <marc.dionne@...istor.com>,
Ilya Dryomov <idryomov@...il.com>,
Dominique Martinet <asmadeus@...ewreck.org>,
v9fs-developer@...ts.sourceforge.net,
linux-afs@...ts.infradead.org, ceph-devel@...r.kernel.org,
linux-cachefs@...hat.com, linux-fsdevel@...r.kernel.org,
linux-nfs@...r.kernel.org, linux-cifs@...r.kernel.org,
devel@...ts.orangefs.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 5/6] netfs, 9p, afs, ceph: Use folios
Matthew Wilcox <willy@...radead.org> wrote:
> On Wed, Nov 03, 2021 at 02:58:12PM +0000, David Howells wrote:
> > Matthew Wilcox <willy@...radead.org> wrote:
> >
> > > > + len = (size >= start + gran) ? gran : size - start;
> > >
> > > This seems like the most complicated way to write this ... how about:
> > >
> > > size_t len = min_t(loff_t, isize - start, folio_size(folio));
> >
> > I was trying to hedge against isize-start going negative. Can this code race
> > against truncate? truncate_setsize() changes i_size *before* invalidating the
> > pages.
>
> We should check for isize < start separately, and skip the writeback
> entirely.
So, something like the following
static int v9fs_vfs_write_folio_locked(struct folio *folio)
{
struct inode *inode = folio_inode(folio);
struct v9fs_inode *v9inode = V9FS_I(inode);
loff_t start = folio_pos(folio);
loff_t i_size = i_size_read(inode);
struct iov_iter from;
size_t len = folio_size(folio);
int err;
if (start >= i_size)
return 0; /* Simultaneous truncation occurred */
len = min_t(loff_t, i_size - start, len);
iov_iter_xarray(&from, ..., start, len);
...
}
David
Powered by blists - more mailing lists