diff mbox series

[RFC,29/31] btrfs: Use iomap_readpage_ops to allocate and submit bio

Message ID a4c3d7874e487e6902126b6bc905ae9da249f9f5.1623567940.git.rgoldwyn@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs buffered iomap support | expand

Commit Message

Goldwyn Rodrigues June 13, 2021, 1:39 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

Set the alloc_io() and submit_io() functions of iomap_readpage_ops
While performing readpage, the an btrfs_io_bio is allocated to fill
csums and check data csums.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/ctree.h     |  1 +
 fs/btrfs/extent_io.c | 10 ++++++++++
 fs/btrfs/extent_io.h |  3 +++
 fs/btrfs/inode.c     |  9 +++++++--
 4 files changed, 21 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index d4567c7a93cb..5826933ba4d2 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3214,6 +3214,7 @@  void btrfs_inode_unlock(struct inode *inode, unsigned int ilock_flags);
 void btrfs_update_inode_bytes(struct btrfs_inode *inode,
 			      const u64 add_bytes,
 			      const u64 del_bytes);
+void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio);
 
 /* ioctl.c */
 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index b0a01e3e4e7f..88a8fbf467b0 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -7284,3 +7284,13 @@  void btrfs_readahead_node_child(struct extent_buffer *node, int slot)
 				   btrfs_node_ptr_generation(node, slot),
 				   btrfs_header_level(node) - 1);
 }
+
+static struct bio *btrfs_readpage_alloc_bio(gfp_t gfp_mask, unsigned short nr)
+{
+	return btrfs_io_bio_alloc(nr);
+}
+
+const struct iomap_readpage_ops btrfs_iomap_readpage_ops = {
+	.alloc_bio = btrfs_readpage_alloc_bio,
+	.submit_io = btrfs_buffered_submit_io,
+};
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index e3685b071eba..8cb79f8d1af8 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -7,6 +7,7 @@ 
 #include <linux/refcount.h>
 #include <linux/fiemap.h>
 #include <linux/btrfs_tree.h>
+#include <linux/iomap.h>
 #include "ulist.h"
 
 /*
@@ -313,6 +314,8 @@  int btrfs_repair_one_sector(struct inode *inode,
 			    u64 start, int failed_mirror,
 			    submit_bio_hook_t *submit_bio_hook);
 
+extern const struct iomap_readpage_ops btrfs_iomap_readpage_ops;
+
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 bool find_lock_delalloc_range(struct inode *inode,
 			     struct page *locked_page, u64 *start,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 6b9b238837b8..1ca83c11e8b9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -35,6 +35,7 @@ 
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
+#include "extent_io.h"
 #include "transaction.h"
 #include "btrfs_inode.h"
 #include "print-tree.h"
@@ -8431,7 +8432,7 @@  static void btrfs_writepage_endio(struct bio *bio)
 	iomap_writepage_end_bio(bio);
 }
 
-static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio)
+void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio)
 {
 	struct bio_vec *bvec;
 	struct bvec_iter_all iter_all;
@@ -8440,7 +8441,11 @@  static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio)
 		bio_for_each_segment_all(bvec, bio, iter_all)
 			set_page_extent_mapped(bvec->bv_page);
 
-	bio->bi_end_io = btrfs_writepage_endio;
+	if (bio_op(bio) == REQ_OP_WRITE)
+		bio->bi_end_io = btrfs_writepage_endio;
+	else
+		bio->bi_end_io = btrfs_readpage_endio;
+
 	if (is_data_inode(inode))
 		btrfs_submit_data_bio(inode, bio, 0, 0);
 	else