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

btrfs: convert read_key_bytes() to take a 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, use kmap_local_folio() instead of kmap_local_page(),
which is more consistent with folio usage.
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 b8ae2bfa
...@@ -284,7 +284,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, ...@@ -284,7 +284,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
* page and ignore dest, but it must still be non-NULL to avoid the * page and ignore dest, but it must still be non-NULL to avoid the
* counting-only behavior. * counting-only behavior.
* @len: length in bytes to read * @len: length in bytes to read
* @dest_page: copy into this page instead of the dest buffer * @dest_folio: copy into this folio instead of the dest buffer
* *
* Helper function to read items from the btree. This returns the number of * Helper function to read items from the btree. This returns the number of
* bytes read or < 0 for errors. We can return short reads if the items don't * bytes read or < 0 for errors. We can return short reads if the items don't
...@@ -294,7 +294,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, ...@@ -294,7 +294,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
* Returns number of bytes read or a negative error code on failure. * Returns number of bytes read or a negative error code on failure.
*/ */
static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
char *dest, u64 len, struct page *dest_page) char *dest, u64 len, struct folio *dest_folio)
{ {
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_root *root = inode->root; struct btrfs_root *root = inode->root;
...@@ -314,7 +314,7 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, ...@@ -314,7 +314,7 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
if (dest_page) if (dest_folio)
path->reada = READA_FORWARD; path->reada = READA_FORWARD;
key.objectid = btrfs_ino(inode); key.objectid = btrfs_ino(inode);
...@@ -371,15 +371,15 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, ...@@ -371,15 +371,15 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
copy_offset = offset - key.offset; copy_offset = offset - key.offset;
if (dest) { if (dest) {
if (dest_page) if (dest_folio)
kaddr = kmap_local_page(dest_page); kaddr = kmap_local_folio(dest_folio, 0);
data = btrfs_item_ptr(leaf, path->slots[0], void); data = btrfs_item_ptr(leaf, path->slots[0], void);
read_extent_buffer(leaf, kaddr + dest_offset, read_extent_buffer(leaf, kaddr + dest_offset,
(unsigned long)data + copy_offset, (unsigned long)data + copy_offset,
copy_bytes); copy_bytes);
if (dest_page) if (dest_folio)
kunmap_local(kaddr); kunmap_local(kaddr);
} }
...@@ -762,7 +762,7 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode, ...@@ -762,7 +762,7 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode,
* [ inode objectid, BTRFS_MERKLE_ITEM_KEY, offset in bytes ] * [ inode objectid, BTRFS_MERKLE_ITEM_KEY, offset in bytes ]
*/ */
ret = read_key_bytes(BTRFS_I(inode), BTRFS_VERITY_MERKLE_ITEM_KEY, off, ret = read_key_bytes(BTRFS_I(inode), BTRFS_VERITY_MERKLE_ITEM_KEY, off,
folio_address(folio), PAGE_SIZE, &folio->page); folio_address(folio), PAGE_SIZE, folio);
if (ret < 0) { if (ret < 0) {
folio_put(folio); folio_put(folio);
return ERR_PTR(ret); return ERR_PTR(ret);
......
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