filemap: Use filemap_read_folio() in do_read_cache_folio()

By passing ->read_folio to filemap_read_folio(), we can use
filemap_read_folio() in do_read_cache_folio().
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
parent 1dfa24a4
...@@ -2381,7 +2381,7 @@ static void filemap_get_read_batch(struct address_space *mapping, ...@@ -2381,7 +2381,7 @@ static void filemap_get_read_batch(struct address_space *mapping,
rcu_read_unlock(); rcu_read_unlock();
} }
static int filemap_read_folio(struct file *file, struct address_space *mapping, static int filemap_read_folio(struct file *file, filler_t filler,
struct folio *folio) struct folio *folio)
{ {
int error; int error;
...@@ -2393,7 +2393,7 @@ static int filemap_read_folio(struct file *file, struct address_space *mapping, ...@@ -2393,7 +2393,7 @@ static int filemap_read_folio(struct file *file, struct address_space *mapping,
*/ */
folio_clear_error(folio); folio_clear_error(folio);
/* Start the actual read. The read will unlock the page. */ /* Start the actual read. The read will unlock the page. */
error = mapping->a_ops->read_folio(file, folio); error = filler(file, folio);
if (error) if (error)
return error; return error;
...@@ -2402,6 +2402,7 @@ static int filemap_read_folio(struct file *file, struct address_space *mapping, ...@@ -2402,6 +2402,7 @@ static int filemap_read_folio(struct file *file, struct address_space *mapping,
return error; return error;
if (folio_test_uptodate(folio)) if (folio_test_uptodate(folio))
return 0; return 0;
if (file)
shrink_readahead_size_eio(&file->f_ra); shrink_readahead_size_eio(&file->f_ra);
return -EIO; return -EIO;
} }
...@@ -2475,7 +2476,8 @@ static int filemap_update_page(struct kiocb *iocb, ...@@ -2475,7 +2476,8 @@ static int filemap_update_page(struct kiocb *iocb,
if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ))
goto unlock; goto unlock;
error = filemap_read_folio(iocb->ki_filp, mapping, folio); error = filemap_read_folio(iocb->ki_filp, mapping->a_ops->read_folio,
folio);
goto unlock_mapping; goto unlock_mapping;
unlock: unlock:
folio_unlock(folio); folio_unlock(folio);
...@@ -2518,7 +2520,7 @@ static int filemap_create_folio(struct file *file, ...@@ -2518,7 +2520,7 @@ static int filemap_create_folio(struct file *file,
if (error) if (error)
goto error; goto error;
error = filemap_read_folio(file, mapping, folio); error = filemap_read_folio(file, mapping->a_ops->read_folio, folio);
if (error) if (error)
goto error; goto error;
...@@ -3202,7 +3204,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) ...@@ -3202,7 +3204,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
* and we need to check for errors. * and we need to check for errors.
*/ */
fpin = maybe_unlock_mmap_for_io(vmf, fpin); fpin = maybe_unlock_mmap_for_io(vmf, fpin);
error = filemap_read_folio(file, mapping, folio); error = filemap_read_folio(file, mapping->a_ops->read_folio, folio);
if (fpin) if (fpin)
goto out_retry; goto out_retry;
folio_put(folio); folio_put(folio);
...@@ -3515,15 +3517,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, ...@@ -3515,15 +3517,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
goto out; goto out;
} }
/*
* A previous I/O error may have been due to temporary
* failures.
* Clear page error before actual read, PG_error will be
* set again if read page fails.
*/
folio_clear_error(folio);
filler: filler:
err = filler(file, folio); err = filemap_read_folio(file, filler, folio);
if (err) { if (err) {
folio_put(folio); folio_put(folio);
if (err == AOP_TRUNCATED_PAGE) if (err == AOP_TRUNCATED_PAGE)
...@@ -3531,12 +3526,6 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, ...@@ -3531,12 +3526,6 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
return ERR_PTR(err); return ERR_PTR(err);
} }
folio_wait_locked(folio);
if (!folio_test_uptodate(folio)) {
folio_put(folio);
return ERR_PTR(-EIO);
}
out: out:
folio_mark_accessed(folio); folio_mark_accessed(folio);
return folio; return folio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment