]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jffs2: Convert jffs2_write_begin() to use a folio
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 11 Jul 2024 20:58:06 +0000 (16:58 -0400)
committerChristian Brauner <brauner@kernel.org>
Wed, 7 Aug 2024 09:32:01 +0000 (11:32 +0200)
Fetch a folio from the page cache instead of a page and use it throughout
removing several calls to compound_head().  We still have to convert
back to a page for calling internal jffs2 functions, but hopefully they
will be converted soon.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/jffs2/file.c

index 1a7dbf846c7cdfa5bb3fdc33a5c813b94b6d1e39..ee8f7f029b459b4ab35f93a64ad80fcbe28991c6 100644 (file)
@@ -127,7 +127,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
                        loff_t pos, unsigned len,
                        struct page **pagep, void **fsdata)
 {
-       struct page *pg;
+       struct folio *folio;
        struct inode *inode = mapping->host;
        struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
        struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
@@ -206,29 +206,30 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
         * page in read_cache_page(), which causes a deadlock.
         */
        mutex_lock(&c->alloc_sem);
-       pg = grab_cache_page_write_begin(mapping, index);
-       if (!pg) {
-               ret = -ENOMEM;
+       folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
+                       mapping_gfp_mask(mapping));
+       if (IS_ERR(folio)) {
+               ret = PTR_ERR(folio);
                goto release_sem;
        }
-       *pagep = pg;
+       *pagep = &folio->page;
 
        /*
-        * Read in the page if it wasn't already present. Cannot optimize away
-        * the whole page write case until jffs2_write_end can handle the
+        * Read in the folio if it wasn't already present. Cannot optimize away
+        * the whole folio write case until jffs2_write_end can handle the
         * case of a short-copy.
         */
-       if (!PageUptodate(pg)) {
+       if (!folio_test_uptodate(folio)) {
                mutex_lock(&f->sem);
-               ret = jffs2_do_readpage_nolock(inode, pg);
+               ret = jffs2_do_readpage_nolock(inode, &folio->page);
                mutex_unlock(&f->sem);
                if (ret) {
-                       unlock_page(pg);
-                       put_page(pg);
+                       folio_unlock(folio);
+                       folio_put(folio);
                        goto release_sem;
                }
        }
-       jffs2_dbg(1, "end write_begin(). pg->flags %lx\n", pg->flags);
+       jffs2_dbg(1, "end write_begin(). folio->flags %lx\n", folio->flags);
 
 release_sem:
        mutex_unlock(&c->alloc_sem);