Commit 9d3973de authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Theodore Ts'o

ext4: Convert __ext4_block_zero_page_range() to use a folio

Use folio APIs throughout.  Saves many calls to compound_head().
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarRitesh Harjani (IBM) <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20230324180129.1220691-21-willy@infradead.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 86324a21
...@@ -3669,23 +3669,26 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3669,23 +3669,26 @@ static int __ext4_block_zero_page_range(handle_t *handle,
ext4_lblk_t iblock; ext4_lblk_t iblock;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
struct buffer_head *bh; struct buffer_head *bh;
struct page *page; struct folio *folio;
int err = 0; int err = 0;
page = find_or_create_page(mapping, from >> PAGE_SHIFT, folio = __filemap_get_folio(mapping, from >> PAGE_SHIFT,
mapping_gfp_constraint(mapping, ~__GFP_FS)); FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
if (!page) mapping_gfp_constraint(mapping, ~__GFP_FS));
if (!folio)
return -ENOMEM; return -ENOMEM;
blocksize = inode->i_sb->s_blocksize; blocksize = inode->i_sb->s_blocksize;
iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
if (!page_has_buffers(page)) bh = folio_buffers(folio);
create_empty_buffers(page, blocksize, 0); if (!bh) {
create_empty_buffers(&folio->page, blocksize, 0);
bh = folio_buffers(folio);
}
/* Find the buffer that contains "offset" */ /* Find the buffer that contains "offset" */
bh = page_buffers(page);
pos = blocksize; pos = blocksize;
while (offset >= pos) { while (offset >= pos) {
bh = bh->b_this_page; bh = bh->b_this_page;
...@@ -3707,7 +3710,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3707,7 +3710,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
} }
/* Ok, it's mapped. Make sure it's up-to-date */ /* Ok, it's mapped. Make sure it's up-to-date */
if (PageUptodate(page)) if (folio_test_uptodate(folio))
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
...@@ -3717,7 +3720,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3717,7 +3720,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
if (fscrypt_inode_uses_fs_layer_crypto(inode)) { if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
/* We expect the key to be set. */ /* We expect the key to be set. */
BUG_ON(!fscrypt_has_encryption_key(inode)); BUG_ON(!fscrypt_has_encryption_key(inode));
err = fscrypt_decrypt_pagecache_blocks(page_folio(page), err = fscrypt_decrypt_pagecache_blocks(folio,
blocksize, blocksize,
bh_offset(bh)); bh_offset(bh));
if (err) { if (err) {
...@@ -3733,7 +3736,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3733,7 +3736,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
if (err) if (err)
goto unlock; goto unlock;
} }
zero_user(page, offset, length); folio_zero_range(folio, offset, length);
BUFFER_TRACE(bh, "zeroed end of block"); BUFFER_TRACE(bh, "zeroed end of block");
if (ext4_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
...@@ -3747,8 +3750,8 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3747,8 +3750,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
} }
unlock: unlock:
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment