On Wed, Nov 04, 2020 at 08:42:12PM +0000, Matthew Wilcox (Oracle) wrote: > Use AOP_TRUNCATED_PAGE to indicate that no error occurred, but the > page we looked up is no longer valid. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> > Reviewed-by: Kent Overstreet <kent.overstreet@xxxxxxxxx> > --- > mm/filemap.c | 42 +++++++++++++++++++----------------------- > 1 file changed, 19 insertions(+), 23 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 25945fefdd39..93c054f51677 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2231,24 +2231,21 @@ static int filemap_read_page(struct file *file, struct address_space *mapping, > return error; > } > > +static int filemap_update_page(struct kiocb *iocb, > + struct address_space *mapping, struct iov_iter *iter, > + struct page *page, loff_t pos, loff_t count) > { > struct inode *inode = mapping->host; > int error; > > if (iocb->ki_flags & IOCB_WAITQ) { > error = lock_page_async(page, iocb->ki_waitq); > + if (error) > + goto error; > } else { > if (!trylock_page(page)) { > put_and_wait_on_page_locked(page, TASK_KILLABLE); > + return AOP_TRUNCATED_PAGE; > } > } > > @@ -2267,25 +2264,24 @@ static struct page *filemap_update_page(struct kiocb *iocb, struct file *filp, > goto readpage; > uptodate: > unlock_page(page); > + return 0; > > readpage: > if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) { > unlock_page(page); > + error = -EAGAIN; > + } else { > + error = filemap_read_page(iocb->ki_filp, mapping, page); > + if (!error) > + return 0; > } > +error: > put_page(page); > + return error; > truncated: > unlock_page(page); > put_page(page); > + return AOP_TRUNCATED_PAGE; We could still consolidate the page unlocking by having another label. Or even better move the put_page into the caller like I did in my series, which would conceputally fit in pretty nicely here: > + err = filemap_update_page(iocb, mapping, iter, page, > pg_pos, pg_count); > + if (err) > pvec->nr--; But otherwise this looks good: Reviewed-by: Christoph Hellwig <hch@xxxxxx>