[PATCH 7/8] reiserfs: Convert convert_tail_for_hole() to use folios

"Matthew Wilcox (Oracle)" <[email protected]>
Newsgroups gmane.comp.file-systems.reiserfs.general,gmane.linux.file-systems
Message-ID <[email protected]>
It's not clear to me that reiserfs will ever support large folios, but
now this function will operate correctly if they are enabled.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
---
 fs/reiserfs/inode.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index b79848111957..008855ddb365 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -571,57 +571,58 @@ static int convert_tail_for_hole(struct inode *inode,
 	unsigned long index;
 	unsigned long tail_end;
 	unsigned long tail_start;
-	struct page *tail_page;
-	struct page *hole_page = bh_result->b_page;
+	struct folio *tail_folio;
+	struct folio *hole_folio = bh_result->b_folio;
 	int retval = 0;
 
 	if ((tail_offset & (bh_result->b_size - 1)) != 1)
 		return -EIO;
 
-	/* always try to read until the end of the block */
-	tail_start = tail_offset & (PAGE_SIZE - 1);
-	tail_end = (tail_start | (bh_result->b_size - 1)) + 1;
-
 	index = tail_offset >> PAGE_SHIFT;
 	/*
-	 * hole_page can be zero in case of direct_io, we are sure
+	 * hole_folio can be zero in case of direct_io, we are sure
 	 * that we cannot get here if we write with O_DIRECT into tail page
 	 */
-	if (!hole_page || index != hole_page->index) {
-		tail_page = grab_cache_page(inode->i_mapping, index);
+	if (!hole_folio || !folio_contains(hole_folio, index)) {
+		tail_folio = __filemap_get_folio(inode->i_mapping, index,
+				FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
+				mapping_gfp_mask(inode->i_mapping));
 		retval = -ENOMEM;
-		if (!tail_page) {
+		if (!tail_folio)
 			goto out;
-		}
 	} else {
-		tail_page = hole_page;
+		tail_folio = hole_folio;
 	}
 
+	/* always try to read until the end of the block */
+	tail_start = offset_in_folio(tail_folio, tail_offset);
+	tail_end = (tail_start | (bh_result->b_size - 1)) + 1;
+
 	/*
 	 * we don't have to make sure the conversion did not happen while
-	 * we were locking the page because anyone that could convert
+	 * we were locking the folio because anyone that could convert
 	 * must first take i_mutex.
 	 *
-	 * We must fix the tail page for writing because it might have buffers
+	 * We must fix the tail folio for writing because it might have buffers
 	 * that are mapped, but have a block number of 0.  This indicates tail
-	 * data that has been read directly into the page, and
+	 * data that has been read directly into the folio, and
 	 * __block_write_begin won't trigger a get_block in this case.
 	 */
-	fix_tail_page_for_writing(tail_page);
-	retval = __reiserfs_write_begin(tail_page, tail_start,
+	fix_tail_page_for_writing(&tail_folio->page);
+	retval = __reiserfs_write_begin(&tail_folio->page, tail_start,
 				      tail_end - tail_start);
 	if (retval)
 		goto unlock;
 
 	/* tail conversion might change the data in the page */
-	flush_dcache_page(tail_page);
+	flush_dcache_folio(tail_folio);
 
-	retval = reiserfs_commit_write(NULL, tail_page, tail_start, tail_end);
+	retval = reiserfs_commit_write(NULL, &tail_folio->page, tail_start, tail_end);
 
 unlock:
-	if (tail_page != hole_page) {
-		unlock_page(tail_page);
-		put_page(tail_page);
+	if (tail_folio != hole_folio) {
+		folio_unlock(tail_folio);
+		folio_put(tail_folio);
 	}
 out:
 	return retval;
-- 
2.35.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.