diff mbox series

[v2,06/11] ntfs3: Convert attr_make_nonresident to use a folio

Message ID 20240422193203.3534108-7-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert (most of) ntfs3 to use folios | expand

Commit Message

Matthew Wilcox April 22, 2024, 7:31 p.m. UTC
Fetch a folio from the page cache instead of a page and operate on it.
Take advantage of the new helpers to avoid handling highmem ourselves,
and combine the uptodate + unlock operations into folio_end_read().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ntfs3/attrib.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 02fa3245850a..d253840c26cf 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -302,22 +302,20 @@  int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
 			if (err)
 				goto out2;
 		} else if (!page) {
-			char *kaddr;
-
-			page = grab_cache_page(ni->vfs_inode.i_mapping, 0);
-			if (!page) {
-				err = -ENOMEM;
+			struct address_space *mapping = ni->vfs_inode.i_mapping;
+			struct folio *folio;
+
+			folio = __filemap_get_folio(mapping, 0,
+					FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
+					mapping_gfp_mask(mapping));
+			if (IS_ERR(folio)) {
+				err = PTR_ERR(folio);
 				goto out2;
 			}
-			kaddr = kmap_atomic(page);
-			memcpy(kaddr, data, rsize);
-			memset(kaddr + rsize, 0, PAGE_SIZE - rsize);
-			kunmap_atomic(kaddr);
-			flush_dcache_page(page);
-			SetPageUptodate(page);
-			set_page_dirty(page);
-			unlock_page(page);
-			put_page(page);
+			folio_fill_tail(folio, 0, data, rsize);
+			folio_mark_dirty(folio);
+			folio_end_read(folio, true);
+			folio_put(folio);
 		}
 	}