Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Li Zetao <lizetao1@huawei.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Li Zetao and committed by
David Sterba
faad57ae aeb6d881

+18 -17
+18 -17
fs/btrfs/reflink.c
··· 66 66 const size_t inline_size = size - btrfs_file_extent_calc_inline_size(0); 67 67 char *data_start = inline_data + btrfs_file_extent_calc_inline_size(0); 68 68 struct extent_changeset *data_reserved = NULL; 69 - struct page *page = NULL; 69 + struct folio *folio = NULL; 70 70 struct address_space *mapping = inode->vfs_inode.i_mapping; 71 71 int ret; 72 72 ··· 83 83 if (ret) 84 84 goto out; 85 85 86 - page = find_or_create_page(mapping, file_offset >> PAGE_SHIFT, 87 - btrfs_alloc_write_mask(mapping)); 88 - if (!page) { 86 + folio = __filemap_get_folio(mapping, file_offset >> PAGE_SHIFT, 87 + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, 88 + btrfs_alloc_write_mask(mapping)); 89 + if (IS_ERR(folio)) { 89 90 ret = -ENOMEM; 90 91 goto out_unlock; 91 92 } 92 93 93 - ret = set_page_extent_mapped(page); 94 + ret = set_folio_extent_mapped(folio); 94 95 if (ret < 0) 95 96 goto out_unlock; 96 97 ··· 116 115 set_bit(BTRFS_INODE_NO_DELALLOC_FLUSH, &inode->runtime_flags); 117 116 118 117 if (comp_type == BTRFS_COMPRESS_NONE) { 119 - memcpy_to_page(page, offset_in_page(file_offset), data_start, 120 - datal); 118 + memcpy_to_folio(folio, offset_in_folio(folio, file_offset), data_start, 119 + datal); 121 120 } else { 122 - ret = btrfs_decompress(comp_type, data_start, page_folio(page), 123 - offset_in_page(file_offset), 121 + ret = btrfs_decompress(comp_type, data_start, folio, 122 + offset_in_folio(folio, file_offset), 124 123 inline_size, datal); 125 124 if (ret) 126 125 goto out_unlock; 127 - flush_dcache_page(page); 126 + flush_dcache_folio(folio); 128 127 } 129 128 130 129 /* ··· 140 139 * So what's in the range [500, 4095] corresponds to zeroes. 141 140 */ 142 141 if (datal < block_size) 143 - memzero_page(page, datal, block_size - datal); 142 + folio_zero_range(folio, datal, block_size - datal); 144 143 145 - btrfs_folio_set_uptodate(fs_info, page_folio(page), file_offset, block_size); 146 - btrfs_folio_clear_checked(fs_info, page_folio(page), file_offset, block_size); 147 - btrfs_folio_set_dirty(fs_info, page_folio(page), file_offset, block_size); 144 + btrfs_folio_set_uptodate(fs_info, folio, file_offset, block_size); 145 + btrfs_folio_clear_checked(fs_info, folio, file_offset, block_size); 146 + btrfs_folio_set_dirty(fs_info, folio, file_offset, block_size); 148 147 out_unlock: 149 - if (page) { 150 - unlock_page(page); 151 - put_page(page); 148 + if (!IS_ERR(folio)) { 149 + folio_unlock(folio); 150 + folio_put(folio); 152 151 } 153 152 if (ret) 154 153 btrfs_delalloc_release_space(inode, data_reserved, file_offset,