Merge tag 'gfs2-v6.4-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-rpi.git] / fs / gfs2 / aops.c
index b11ec19..ae49256 100644 (file)
 
 
 void gfs2_trans_add_databufs(struct gfs2_inode *ip, struct folio *folio,
-                            unsigned int from, unsigned int len)
+                            size_t from, size_t len)
 {
        struct buffer_head *head = folio_buffers(folio);
        unsigned int bsize = head->b_size;
        struct buffer_head *bh;
-       unsigned int to = from + len;
-       unsigned int start, end;
+       size_t to = from + len;
+       size_t start, end;
 
        for (bh = head, start = 0; bh != head || !start;
             bh = bh->b_this_page, start = end) {
@@ -82,61 +82,61 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
 }
 
 /**
- * gfs2_write_jdata_page - gfs2 jdata-specific version of block_write_full_page
- * @page: The page to write
+ * gfs2_write_jdata_folio - gfs2 jdata-specific version of block_write_full_page
+ * @folio: The folio to write
  * @wbc: The writeback control
  *
  * This is the same as calling block_write_full_page, but it also
  * writes pages outside of i_size
  */
-static int gfs2_write_jdata_page(struct page *page,
+static int gfs2_write_jdata_folio(struct folio *folio,
                                 struct writeback_control *wbc)
 {
-       struct inode * const inode = page->mapping->host;
+       struct inode * const inode = folio->mapping->host;
        loff_t i_size = i_size_read(inode);
-       const pgoff_t end_index = i_size >> PAGE_SHIFT;
-       unsigned offset;
 
        /*
-        * The page straddles i_size.  It must be zeroed out on each and every
+        * The folio straddles i_size.  It must be zeroed out on each and every
         * writepage invocation because it may be mmapped.  "A file is mapped
         * in multiples of the page size.  For a file that is not a multiple of
-        * the  page size, the remaining memory is zeroed when mapped, and
+        * the page size, the remaining memory is zeroed when mapped, and
         * writes to that region are not written out to the file."
         */
-       offset = i_size & (PAGE_SIZE - 1);
-       if (page->index == end_index && offset)
-               zero_user_segment(page, offset, PAGE_SIZE);
+       if (folio_pos(folio) < i_size &&
+           i_size < folio_pos(folio) + folio_size(folio))
+               folio_zero_segment(folio, offset_in_folio(folio, i_size),
+                               folio_size(folio));
 
-       return __block_write_full_page(inode, page, gfs2_get_block_noalloc, wbc,
-                                      end_buffer_async_write);
+       return __block_write_full_folio(inode, folio, gfs2_get_block_noalloc,
+                       wbc, end_buffer_async_write);
 }
 
 /**
- * __gfs2_jdata_writepage - The core of jdata writepage
- * @page: The page to write
+ * __gfs2_jdata_write_folio - The core of jdata writepage
+ * @folio: The folio to write
  * @wbc: The writeback control
  *
  * This is shared between writepage and writepages and implements the
  * core of the writepage operation. If a transaction is required then
- * PageChecked will have been set and the transaction will have
+ * the checked flag will have been set and the transaction will have
  * already been started before this is called.
  */
-
-static int __gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
+static int __gfs2_jdata_write_folio(struct folio *folio,
+               struct writeback_control *wbc)
 {
-       struct inode *inode = page->mapping->host;
+       struct inode *inode = folio->mapping->host;
        struct gfs2_inode *ip = GFS2_I(inode);
 
-       if (PageChecked(page)) {
-               ClearPageChecked(page);
-               if (!page_has_buffers(page)) {
-                       create_empty_buffers(page, inode->i_sb->s_blocksize,
-                                            BIT(BH_Dirty)|BIT(BH_Uptodate));
+       if (folio_test_checked(folio)) {
+               folio_clear_checked(folio);
+               if (!folio_buffers(folio)) {
+                       folio_create_empty_buffers(folio,
+                                       inode->i_sb->s_blocksize,
+                                       BIT(BH_Dirty)|BIT(BH_Uptodate));
                }
-               gfs2_trans_add_databufs(ip, page_folio(page), 0, PAGE_SIZE);
+               gfs2_trans_add_databufs(ip, folio, 0, folio_size(folio));
        }
-       return gfs2_write_jdata_page(page, wbc);
+       return gfs2_write_jdata_folio(folio, wbc);
 }
 
 /**
@@ -150,20 +150,21 @@ static int __gfs2_jdata_writepage(struct page *page, struct writeback_control *w
 
 static int gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
 {
+       struct folio *folio = page_folio(page);
        struct inode *inode = page->mapping->host;
        struct gfs2_inode *ip = GFS2_I(inode);
        struct gfs2_sbd *sdp = GFS2_SB(inode);
 
        if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl)))
                goto out;
-       if (PageChecked(page) || current->journal_info)
+       if (folio_test_checked(folio) || current->journal_info)
                goto out_ignore;
-       return __gfs2_jdata_writepage(page, wbc);
+       return __gfs2_jdata_write_folio(folio, wbc);
 
 out_ignore:
-       redirty_page_for_writepage(wbc, page);
+       folio_redirty_for_writepage(wbc, folio);
 out:
-       unlock_page(page);
+       folio_unlock(folio);
        return 0;
 }
 
@@ -255,7 +256,7 @@ continue_unlock:
 
                trace_wbc_writepage(wbc, inode_to_bdi(inode));
 
-               ret = __gfs2_jdata_writepage(&folio->page, wbc);
+               ret = __gfs2_jdata_write_folio(folio, wbc);
                if (unlikely(ret)) {
                        if (ret == AOP_WRITEPAGE_ACTIVATE) {
                                folio_unlock(folio);