diff mbox series

[09/26] nilfs2: Convert nilfs_mdt_freeze_buffer to use a folio

Message ID 20230919045135.3635437-10-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Finish the create_empty_buffers() transition | expand

Commit Message

Matthew Wilcox Sept. 19, 2023, 4:51 a.m. UTC
Remove a number of folio->page->folio conversions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/nilfs2/mdt.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Ryusuke Konishi Sept. 20, 2023, 3:42 a.m. UTC | #1
On Tue, Sep 19, 2023 at 6:09 PM Matthew Wilcox (Oracle) wrote:
>
> Remove a number of folio->page->folio conversions.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  fs/nilfs2/mdt.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
> index 19c8158605ed..db2260d6e44d 100644
> --- a/fs/nilfs2/mdt.c
> +++ b/fs/nilfs2/mdt.c
> @@ -560,17 +560,19 @@ int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
>  {
>         struct nilfs_shadow_map *shadow = NILFS_MDT(inode)->mi_shadow;
>         struct buffer_head *bh_frozen;
> -       struct page *page;
> +       struct folio *folio;
>         int blkbits = inode->i_blkbits;
>
> -       page = grab_cache_page(shadow->inode->i_mapping, bh->b_folio->index);
> -       if (!page)
> -               return -ENOMEM;
> +       folio = filemap_grab_folio(shadow->inode->i_mapping,
> +                       bh->b_folio->index);
> +       if (IS_ERR(folio))
> +               return PTR_ERR(folio);
>
> -       if (!page_has_buffers(page))
> -               create_empty_buffers(page, 1 << blkbits, 0);
> +       bh_frozen = folio_buffers(folio);
> +       if (!bh_frozen)
> +               bh_frozen = folio_create_empty_buffers(folio, 1 << blkbits, 0);
>
> -       bh_frozen = nilfs_page_get_nth_block(page, bh_offset(bh) >> blkbits);
> +       bh_frozen = get_nth_bh(bh_frozen, bh_offset(bh) >> blkbits);
>
>         if (!buffer_uptodate(bh_frozen))
>                 nilfs_copy_buffer(bh_frozen, bh);
> @@ -582,8 +584,8 @@ int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
>                 brelse(bh_frozen); /* already frozen */
>         }
>
> -       unlock_page(page);
> -       put_page(page);
> +       folio_unlock(folio);
> +       folio_put(folio);
>         return 0;
>  }
>
> --
> 2.40.1
>

Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>

Looks good to me.

Thanks,
Ryusuke Konishi
diff mbox series

Patch

diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index 19c8158605ed..db2260d6e44d 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -560,17 +560,19 @@  int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
 {
 	struct nilfs_shadow_map *shadow = NILFS_MDT(inode)->mi_shadow;
 	struct buffer_head *bh_frozen;
-	struct page *page;
+	struct folio *folio;
 	int blkbits = inode->i_blkbits;
 
-	page = grab_cache_page(shadow->inode->i_mapping, bh->b_folio->index);
-	if (!page)
-		return -ENOMEM;
+	folio = filemap_grab_folio(shadow->inode->i_mapping,
+			bh->b_folio->index);
+	if (IS_ERR(folio))
+		return PTR_ERR(folio);
 
-	if (!page_has_buffers(page))
-		create_empty_buffers(page, 1 << blkbits, 0);
+	bh_frozen = folio_buffers(folio);
+	if (!bh_frozen)
+		bh_frozen = folio_create_empty_buffers(folio, 1 << blkbits, 0);
 
-	bh_frozen = nilfs_page_get_nth_block(page, bh_offset(bh) >> blkbits);
+	bh_frozen = get_nth_bh(bh_frozen, bh_offset(bh) >> blkbits);
 
 	if (!buffer_uptodate(bh_frozen))
 		nilfs_copy_buffer(bh_frozen, bh);
@@ -582,8 +584,8 @@  int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
 		brelse(bh_frozen); /* already frozen */
 	}
 
-	unlock_page(page);
-	put_page(page);
+	folio_unlock(folio);
+	folio_put(folio);
 	return 0;
 }