Commit faad57ae authored by Li Zetao's avatar Li Zetao Committed by David Sterba

btrfs: convert copy_inline_to_page() to use folio

The old page API is being gradually replaced and converted to use folio
to improve code readability and avoid repeated conversion between page
and folio. Moreover find_or_create_page() is compatible API, and it can
replaced with __filemap_get_folio(). Some interfaces have been converted
to use folio before, so the conversion operation from page can be
eliminated here.
Signed-off-by: default avatarLi Zetao <lizetao1@huawei.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent aeb6d881
...@@ -66,7 +66,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode, ...@@ -66,7 +66,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
const size_t inline_size = size - btrfs_file_extent_calc_inline_size(0); const size_t inline_size = size - btrfs_file_extent_calc_inline_size(0);
char *data_start = inline_data + btrfs_file_extent_calc_inline_size(0); char *data_start = inline_data + btrfs_file_extent_calc_inline_size(0);
struct extent_changeset *data_reserved = NULL; struct extent_changeset *data_reserved = NULL;
struct page *page = NULL; struct folio *folio = NULL;
struct address_space *mapping = inode->vfs_inode.i_mapping; struct address_space *mapping = inode->vfs_inode.i_mapping;
int ret; int ret;
...@@ -83,14 +83,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode, ...@@ -83,14 +83,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
if (ret) if (ret)
goto out; goto out;
page = find_or_create_page(mapping, file_offset >> PAGE_SHIFT, folio = __filemap_get_folio(mapping, file_offset >> PAGE_SHIFT,
btrfs_alloc_write_mask(mapping)); FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
if (!page) { btrfs_alloc_write_mask(mapping));
if (IS_ERR(folio)) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_unlock; goto out_unlock;
} }
ret = set_page_extent_mapped(page); ret = set_folio_extent_mapped(folio);
if (ret < 0) if (ret < 0)
goto out_unlock; goto out_unlock;
...@@ -115,15 +116,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode, ...@@ -115,15 +116,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
set_bit(BTRFS_INODE_NO_DELALLOC_FLUSH, &inode->runtime_flags); set_bit(BTRFS_INODE_NO_DELALLOC_FLUSH, &inode->runtime_flags);
if (comp_type == BTRFS_COMPRESS_NONE) { if (comp_type == BTRFS_COMPRESS_NONE) {
memcpy_to_page(page, offset_in_page(file_offset), data_start, memcpy_to_folio(folio, offset_in_folio(folio, file_offset), data_start,
datal); datal);
} else { } else {
ret = btrfs_decompress(comp_type, data_start, page_folio(page), ret = btrfs_decompress(comp_type, data_start, folio,
offset_in_page(file_offset), offset_in_folio(folio, file_offset),
inline_size, datal); inline_size, datal);
if (ret) if (ret)
goto out_unlock; goto out_unlock;
flush_dcache_page(page); flush_dcache_folio(folio);
} }
/* /*
...@@ -139,15 +140,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode, ...@@ -139,15 +140,15 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
* So what's in the range [500, 4095] corresponds to zeroes. * So what's in the range [500, 4095] corresponds to zeroes.
*/ */
if (datal < block_size) if (datal < block_size)
memzero_page(page, datal, block_size - datal); folio_zero_range(folio, datal, block_size - datal);
btrfs_folio_set_uptodate(fs_info, page_folio(page), file_offset, block_size); btrfs_folio_set_uptodate(fs_info, folio, file_offset, block_size);
btrfs_folio_clear_checked(fs_info, page_folio(page), file_offset, block_size); btrfs_folio_clear_checked(fs_info, folio, file_offset, block_size);
btrfs_folio_set_dirty(fs_info, page_folio(page), file_offset, block_size); btrfs_folio_set_dirty(fs_info, folio, file_offset, block_size);
out_unlock: out_unlock:
if (page) { if (!IS_ERR(folio)) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
if (ret) if (ret)
btrfs_delalloc_release_space(inode, data_reserved, file_offset, btrfs_delalloc_release_space(inode, data_reserved, file_offset,
......
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