ocfs2: use a folio in ocfs2_write_end_nolock()
authorMark Tinguely <mark.tinguely@oracle.com>
Thu, 5 Dec 2024 17:16:39 +0000 (17:16 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Jan 2025 04:21:11 +0000 (20:21 -0800)
Remove an access to page->index.  Remove some PAGE_SIZE assumptions.

Link: https://lkml.kernel.org/r/20241205171653.3179945-12-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 2b3a3f5566d5eec82c470e8aaef2817aaab52f22..47c48f4e707c0a3166de8c536c8b6e4c0953ee13 100644 (file)
@@ -1952,17 +1952,16 @@ static void ocfs2_write_end_inline(struct inode *inode, loff_t pos,
             le16_to_cpu(di->i_dyn_features));
 }
 
-int ocfs2_write_end_nolock(struct address_space *mapping,
-                          loff_t pos, unsigned len, unsigned copied, void *fsdata)
+int ocfs2_write_end_nolock(struct address_space *mapping, loff_t pos,
+               unsigned len, unsigned copied, void *fsdata)
 {
        int i, ret;
-       unsigned from, to, start = pos & (PAGE_SIZE - 1);
+       size_t from, to, start = pos & (PAGE_SIZE - 1);
        struct inode *inode = mapping->host;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        struct ocfs2_write_ctxt *wc = fsdata;
        struct ocfs2_dinode *di = (struct ocfs2_dinode *)wc->w_di_bh->b_data;
        handle_t *handle = wc->w_handle;
-       struct page *tmppage;
 
        BUG_ON(!list_empty(&wc->w_unwritten_list));
 
@@ -1993,32 +1992,32 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                                               start+len);
                else {
                        /*
-                        * When page is fully beyond new isize (data copy
-                        * failed), do not bother zeroing the page. Invalidate
+                        * When folio is fully beyond new isize (data copy
+                        * failed), do not bother zeroing the folio. Invalidate
                         * it instead so that writeback does not get confused
                         * put page & buffer dirty bits into inconsistent
                         * state.
                         */
-                       block_invalidate_folio(wc->w_target_folio,
-                                               0, PAGE_SIZE);
+                       block_invalidate_folio(wc->w_target_folio, 0,
+                                       folio_size(wc->w_target_folio));
                }
        }
        if (wc->w_target_folio)
                flush_dcache_folio(wc->w_target_folio);
 
        for (i = 0; i < wc->w_num_folios; i++) {
-               tmppage = &wc->w_folios[i]->page;
+               struct folio *folio = wc->w_folios[i];
 
-               /* This is the direct io target page. */
-               if (tmppage == NULL)
+               /* This is the direct io target folio */
+               if (folio == NULL)
                        continue;
 
-               if (tmppage == &wc->w_target_folio->page) {
+               if (folio == wc->w_target_folio) {
                        from = wc->w_target_from;
                        to = wc->w_target_to;
 
-                       BUG_ON(from > PAGE_SIZE ||
-                              to > PAGE_SIZE ||
+                       BUG_ON(from > folio_size(folio) ||
+                              to > folio_size(folio) ||
                               to < from);
                } else {
                        /*
@@ -2027,19 +2026,17 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                         * to flush their entire range.
                         */
                        from = 0;
-                       to = PAGE_SIZE;
+                       to = folio_size(folio);
                }
 
-               if (page_has_buffers(tmppage)) {
+               if (folio_buffers(folio)) {
                        if (handle && ocfs2_should_order_data(inode)) {
-                               loff_t start_byte =
-                                       ((loff_t)tmppage->index << PAGE_SHIFT) +
-                                       from;
+                               loff_t start_byte = folio_pos(folio) + from;
                                loff_t length = to - from;
                                ocfs2_jbd2_inode_add_write(handle, inode,
                                                           start_byte, length);
                        }
-                       block_commit_write(tmppage, from, to);
+                       block_commit_write(&folio->page, from, to);
                }
        }