diff mbox series

[12/26] nilfs2: Convert nilfs_mdt_forget_block() to use a folio

Message ID 20230919045135.3635437-13-willy@infradead.org
State Not Applicable
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 | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

Comments

Ryusuke Konishi Sept. 20, 2023, 7:25 a.m. UTC | #1
On Tue, Sep 19, 2023 at 3:04 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 | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
> index db2260d6e44d..11b7cf4acc92 100644
> --- a/fs/nilfs2/mdt.c
> +++ b/fs/nilfs2/mdt.c
> @@ -356,30 +356,28 @@ int nilfs_mdt_delete_block(struct inode *inode, unsigned long block)
>   */
>  int nilfs_mdt_forget_block(struct inode *inode, unsigned long block)
>  {
> -       pgoff_t index = (pgoff_t)block >>
> -               (PAGE_SHIFT - inode->i_blkbits);
> -       struct page *page;
> -       unsigned long first_block;
> +       pgoff_t index = block >> (PAGE_SHIFT - inode->i_blkbits);
> +       struct folio *folio;
> +       struct buffer_head *bh;
>         int ret = 0;
>         int still_dirty;
>
> -       page = find_lock_page(inode->i_mapping, index);
> -       if (!page)
> +       folio = filemap_lock_folio(inode->i_mapping, index);
> +       if (IS_ERR(folio))
>                 return -ENOENT;
>
> -       wait_on_page_writeback(page);
> +       folio_wait_writeback(folio);
>
> -       first_block = (unsigned long)index <<
> -               (PAGE_SHIFT - inode->i_blkbits);
> -       if (page_has_buffers(page)) {
> -               struct buffer_head *bh;
> -
> -               bh = nilfs_page_get_nth_block(page, block - first_block);
> +       bh = folio_buffers(folio);
> +       if (bh) {
> +               unsigned long first_block = index <<
> +                               (PAGE_SHIFT - inode->i_blkbits);
> +               bh = get_nth_bh(bh, block - first_block);
>                 nilfs_forget_buffer(bh);
>         }
> -       still_dirty = PageDirty(page);
> -       unlock_page(page);
> -       put_page(page);
> +       still_dirty = folio_test_dirty(folio);
> +       folio_unlock(folio);
> +       folio_put(folio);
>
>         if (still_dirty ||
>             invalidate_inode_pages2_range(inode->i_mapping, index, index) != 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 db2260d6e44d..11b7cf4acc92 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -356,30 +356,28 @@  int nilfs_mdt_delete_block(struct inode *inode, unsigned long block)
  */
 int nilfs_mdt_forget_block(struct inode *inode, unsigned long block)
 {
-	pgoff_t index = (pgoff_t)block >>
-		(PAGE_SHIFT - inode->i_blkbits);
-	struct page *page;
-	unsigned long first_block;
+	pgoff_t index = block >> (PAGE_SHIFT - inode->i_blkbits);
+	struct folio *folio;
+	struct buffer_head *bh;
 	int ret = 0;
 	int still_dirty;
 
-	page = find_lock_page(inode->i_mapping, index);
-	if (!page)
+	folio = filemap_lock_folio(inode->i_mapping, index);
+	if (IS_ERR(folio))
 		return -ENOENT;
 
-	wait_on_page_writeback(page);
+	folio_wait_writeback(folio);
 
-	first_block = (unsigned long)index <<
-		(PAGE_SHIFT - inode->i_blkbits);
-	if (page_has_buffers(page)) {
-		struct buffer_head *bh;
-
-		bh = nilfs_page_get_nth_block(page, block - first_block);
+	bh = folio_buffers(folio);
+	if (bh) {
+		unsigned long first_block = index <<
+				(PAGE_SHIFT - inode->i_blkbits);
+		bh = get_nth_bh(bh, block - first_block);
 		nilfs_forget_buffer(bh);
 	}
-	still_dirty = PageDirty(page);
-	unlock_page(page);
-	put_page(page);
+	still_dirty = folio_test_dirty(folio);
+	folio_unlock(folio);
+	folio_put(folio);
 
 	if (still_dirty ||
 	    invalidate_inode_pages2_range(inode->i_mapping, index, index) != 0)