ocfs2: use a folio in ocfs2_write_begin_inline()
authorMark Tinguely <mark.tinguely@oracle.com>
Thu, 5 Dec 2024 17:16:33 +0000 (17:16 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Jan 2025 04:21:09 +0000 (20:21 -0800)
Retrieve a folio from the page cache instead of a page and use that
folio throught the function.  Saves a couple of calls to compound_head().

Link: https://lkml.kernel.org/r/20241205171653.3179945-6-willy@infradead.org
Signed-off-by: Mark Tinguely <mark.tinguely@oracle.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Mark Fasheh <mark@fasheh.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/aops.c

index 76400bb..46fb2b5 100644 (file)
@@ -1473,7 +1473,7 @@ static int ocfs2_write_begin_inline(struct address_space *mapping,
 {
        int ret;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
-       struct page *page;
+       struct folio *folio;
        handle_t *handle;
        struct ocfs2_dinode *di = (struct ocfs2_dinode *)wc->w_di_bh->b_data;
 
@@ -1484,19 +1484,20 @@ static int ocfs2_write_begin_inline(struct address_space *mapping,
                goto out;
        }
 
-       page = find_or_create_page(mapping, 0, GFP_NOFS);
-       if (!page) {
+       folio = __filemap_get_folio(mapping, 0,
+                       FGP_LOCK | FGP_ACCESSED | FGP_CREAT, GFP_NOFS);
+       if (IS_ERR(folio)) {
                ocfs2_commit_trans(osb, handle);
-               ret = -ENOMEM;
+               ret = PTR_ERR(folio);
                mlog_errno(ret);
                goto out;
        }
        /*
-        * If we don't set w_num_pages then this page won't get unlocked
+        * If we don't set w_num_pages then this folio won't get unlocked
         * and freed on cleanup of the write context.
         */
-       wc->w_target_folio = page_folio(page);
-       wc->w_pages[0] = page;
+       wc->w_target_folio = folio;
+       wc->w_pages[0] = &folio->page;
        wc->w_num_pages = 1;
 
        ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), wc->w_di_bh,
@@ -1511,8 +1512,8 @@ static int ocfs2_write_begin_inline(struct address_space *mapping,
        if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL))
                ocfs2_set_inode_data_inline(inode, di);
 
-       if (!PageUptodate(page)) {
-               ret = ocfs2_read_inline_data(inode, page, wc->w_di_bh);
+       if (!folio_test_uptodate(folio)) {
+               ret = ocfs2_read_inline_data(inode, &folio->page, wc->w_di_bh);
                if (ret) {
                        ocfs2_commit_trans(osb, handle);