[PATCH 11/12] btrfs: add read_inline for folio operations for read() calls

From: Goldwyn Rodrigues
Date: Fri Oct 04 2024 - 16:23:57 EST


From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>

Use the iomap read_inline() hook to fill data into the folio passed.
Just call btrfs_get_extent() again, because this time read_inline()
function has the folio present.

Comment:
Another way to do this is to bounce around btrfs_path all the way to
read_inline() function. This was getting too complicated with cleanup,
but should reduce the number of operations to fetch an inline extent.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>
---
fs/btrfs/extent_io.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index ee0d37388441..01408bc5b04e 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -909,8 +909,26 @@ static void btrfs_put_folio(struct inode *inode, loff_t pos,
folio_put(folio);
}

+static int btrfs_iomap_read_inline(const struct iomap *iomap, struct folio *folio)
+{
+ int ret = 0;
+ struct inode *inode = folio->mapping->host;
+ struct extent_map *em;
+ struct extent_state *cached_state = NULL;
+
+ lock_extent(&BTRFS_I(inode)->io_tree, 0, folio_size(folio) - 1, &cached_state);
+ em = btrfs_get_extent(BTRFS_I(inode), folio, 0, folio_size(folio));
+ unlock_extent(&BTRFS_I(inode)->io_tree, 0, folio_size(folio) - 1, &cached_state);
+ if (IS_ERR(em))
+ ret = PTR_ERR(em);
+ free_extent_map(em);
+ return ret;
+}
+
+
static const struct iomap_folio_ops btrfs_iomap_folio_ops = {
.put_folio = btrfs_put_folio,
+ .read_inline = btrfs_iomap_read_inline,
};

static void btrfs_em_to_iomap(struct inode *inode,
--
2.46.1