[PATCH 06/12] iomap: Introduce read_inline() function hook

From: Goldwyn Rodrigues
Date: Fri Oct 04 2024 - 16:22:00 EST


From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>

Introduce read_inline() function hook for reading inline extents. This
is performed for filesystems such as btrfs which may compress the data
in the inline extents.

This is added in struct iomap_folio_ops, since folio is available at
this point.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>
---
fs/iomap/buffered-io.c | 12 +++++++++---
include/linux/iomap.h | 7 +++++++
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 4c734899a8e5..ef805730125a 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -359,6 +359,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
const struct iomap *iomap = iomap_iter_srcmap(iter);
size_t size = i_size_read(iter->inode) - iomap->offset;
size_t offset = offset_in_folio(folio, iomap->offset);
+ int ret = 0;

if (folio_test_uptodate(folio))
return 0;
@@ -368,9 +369,14 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
if (offset > 0)
ifs_alloc(iter->inode, folio, iter->flags);

- folio_fill_tail(folio, offset, iomap->inline_data, size);
- iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
- return 0;
+ if (iomap->folio_ops && iomap->folio_ops->read_inline)
+ ret = iomap->folio_ops->read_inline(iomap, folio);
+ else
+ folio_fill_tail(folio, offset, iomap->inline_data, size);
+
+ if (!ret)
+ iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
+ return ret;
}

static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index a5cf00a01f23..82dabc0369cd 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -163,6 +163,13 @@ struct iomap_folio_ops {
* locked by the iomap code.
*/
bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap);
+
+ /*
+ * Custom read_inline function for filesystem such as btrfs
+ * that may store data in compressed form.
+ */
+
+ int (*read_inline)(const struct iomap *iomap, struct folio *folio);
};

/*
--
2.46.1