diff mbox series

[05/10] btrfs: pass a btrfs_bio to btrfs_submit_compressed_read

Message ID 20230301134244.1378533-6-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/10] btrfs: remove unused members from struct btrfs_encoded_read_private | expand

Commit Message

Christoph Hellwig March 1, 2023, 1:42 p.m. UTC
btrfs_submit_compressed_read expects the bio passed to it to be embedded
into a btrfs_bio structure.  Pass the btrfs_bio directly to inrease type
safety and make the code self-documenting.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/compression.c | 16 ++++++++--------
 fs/btrfs/compression.h |  2 +-
 fs/btrfs/extent_io.c   |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

Comments

Johannes Thumshirn March 2, 2023, 1 p.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Qu Wenruo March 2, 2023, 11:27 p.m. UTC | #2
On 2023/3/1 21:42, Christoph Hellwig wrote:
> btrfs_submit_compressed_read expects the bio passed to it to be embedded
> into a btrfs_bio structure.  Pass the btrfs_bio directly to inrease type
> safety and make the code self-documenting.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/compression.c | 16 ++++++++--------
>   fs/btrfs/compression.h |  2 +-
>   fs/btrfs/extent_io.c   |  2 +-
>   3 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 27bea05cab1a1b..c12e317e133624 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -498,15 +498,15 @@ static noinline int add_ra_bio_pages(struct inode *inode,
>    * After the compressed pages are read, we copy the bytes into the
>    * bio we were passed and then call the bio end_io calls
>    */
> -void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
> +void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num)
>   {
> -	struct btrfs_inode *inode = btrfs_bio(bio)->inode;
> +	struct btrfs_inode *inode = bbio->inode;
>   	struct btrfs_fs_info *fs_info = inode->root->fs_info;
>   	struct extent_map_tree *em_tree = &inode->extent_tree;
>   	struct compressed_bio *cb;
>   	unsigned int compressed_len;
> -	const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
> -	u64 file_offset = btrfs_bio(bio)->file_offset;
> +	const u64 disk_bytenr = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
> +	u64 file_offset = bbio->file_offset;
>   	u64 em_len;
>   	u64 em_start;
>   	struct extent_map *em;
> @@ -534,10 +534,10 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
>   	em_len = em->len;
>   	em_start = em->start;
>   
> -	cb->len = bio->bi_iter.bi_size;
> +	cb->len = bbio->bio.bi_iter.bi_size;
>   	cb->compressed_len = compressed_len;
>   	cb->compress_type = em->compress_type;
> -	cb->orig_bio = bio;
> +	cb->orig_bio = &bbio->bio;
>   
>   	free_extent_map(em);
>   
> @@ -558,7 +558,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
>   			 &pflags);
>   
>   	/* include any pages we added in add_ra-bio_pages */
> -	cb->len = bio->bi_iter.bi_size;
> +	cb->len = bbio->bio.bi_iter.bi_size;
>   
>   	btrfs_add_compressed_bio_pages(cb, disk_bytenr);
>   
> @@ -573,7 +573,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
>   out_free_bio:
>   	bio_put(&cb->bbio.bio);
>   out:
> -	btrfs_bio_end_io(btrfs_bio(bio), ret);
> +	btrfs_bio_end_io(bbio, ret);
>   }
>   
>   /*
> diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
> index 95d2e85c6e4eea..692bafa1050e8e 100644
> --- a/fs/btrfs/compression.h
> +++ b/fs/btrfs/compression.h
> @@ -94,7 +94,7 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
>   				  blk_opf_t write_flags,
>   				  struct cgroup_subsys_state *blkcg_css,
>   				  bool writeback);
> -void btrfs_submit_compressed_read(struct bio *bio, int mirror_num);
> +void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num);
>   
>   unsigned int btrfs_compress_str2level(unsigned int type, const char *str);
>   
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 77de129db364c9..6ea6f2c057ac3e 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -155,7 +155,7 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
>   
>   	if (btrfs_op(bio) == BTRFS_MAP_READ &&
>   	    bio_ctrl->compress_type != BTRFS_COMPRESS_NONE)
> -		btrfs_submit_compressed_read(bio, mirror_num);
> +		btrfs_submit_compressed_read(btrfs_bio(bio), mirror_num);
>   	else
>   		btrfs_submit_bio(btrfs_bio(bio), mirror_num);
>
Anand Jain March 3, 2023, 9:15 a.m. UTC | #3
On 01/03/2023 21:42, Christoph Hellwig wrote:
> btrfs_submit_compressed_read expects the bio passed to it to be embedded
> into a btrfs_bio structure.  Pass the btrfs_bio directly to inrease type

Typo: inrease->increase

> safety and make the code self-documenting.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Anand Jain <anand.jain@oracle.com>

A nit is below..

> ---
>   fs/btrfs/compression.c | 16 ++++++++--------
>   fs/btrfs/compression.h |  2 +-
>   fs/btrfs/extent_io.c   |  2 +-
>   3 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 27bea05cab1a1b..c12e317e133624 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -498,15 +498,15 @@ static noinline int add_ra_bio_pages(struct inode *inode,
>    * After the compressed pages are read, we copy the bytes into the
>    * bio we were passed and then call the bio end_io calls
>    */
> -void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
> +void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num)
>   {
> -	struct btrfs_inode *inode = btrfs_bio(bio)->inode;
> +	struct btrfs_inode *inode = bbio->inode;
>   	struct btrfs_fs_info *fs_info = inode->root->fs_info;
>   	struct extent_map_tree *em_tree = &inode->extent_tree;
>   	struct compressed_bio *cb;
>   	unsigned int compressed_len;

Simplify by declaring and assigning bio directly:
         struct bio *bio = bbio->bio;
This eliminates the need to dereference bbio->bio three times
later in the code.

1.
> -	const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
> -	u64 file_offset = btrfs_bio(bio)->file_offset;
> +	const u64 disk_bytenr = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
> +	u64 file_offset = bbio->file_offset;


>   	u64 em_len;
>   	u64 em_start;
>   	struct extent_map *em;
> @@ -534,10 +534,10 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
>   	em_len = em->len;
>   	em_start = em->start;
>   

2.
> -	cb->len = bio->bi_iter.bi_size;
> +	cb->len = bbio->bio.bi_iter.bi_size;


>   	cb->compressed_len = compressed_len;
>   	cb->compress_type = em->compress_type > -	cb->orig_bio = bio;
> +	cb->orig_bio = &bbio->bio;
>   
>   	free_extent_map(em);
>   
> @@ -558,7 +558,7 @@ void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
>   			 &pflags);
>   
>   	/* include any pages we added in add_ra-bio_pages */

3.
> -	cb->len = bio->bi_iter.bi_size;
> +	cb->len = bbio->bio.bi_iter.bi_size;


Thanks.
Anand
diff mbox series

Patch

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 27bea05cab1a1b..c12e317e133624 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -498,15 +498,15 @@  static noinline int add_ra_bio_pages(struct inode *inode,
  * After the compressed pages are read, we copy the bytes into the
  * bio we were passed and then call the bio end_io calls
  */
-void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
+void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num)
 {
-	struct btrfs_inode *inode = btrfs_bio(bio)->inode;
+	struct btrfs_inode *inode = bbio->inode;
 	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 	struct extent_map_tree *em_tree = &inode->extent_tree;
 	struct compressed_bio *cb;
 	unsigned int compressed_len;
-	const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
-	u64 file_offset = btrfs_bio(bio)->file_offset;
+	const u64 disk_bytenr = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
+	u64 file_offset = bbio->file_offset;
 	u64 em_len;
 	u64 em_start;
 	struct extent_map *em;
@@ -534,10 +534,10 @@  void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
 	em_len = em->len;
 	em_start = em->start;
 
-	cb->len = bio->bi_iter.bi_size;
+	cb->len = bbio->bio.bi_iter.bi_size;
 	cb->compressed_len = compressed_len;
 	cb->compress_type = em->compress_type;
-	cb->orig_bio = bio;
+	cb->orig_bio = &bbio->bio;
 
 	free_extent_map(em);
 
@@ -558,7 +558,7 @@  void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
 			 &pflags);
 
 	/* include any pages we added in add_ra-bio_pages */
-	cb->len = bio->bi_iter.bi_size;
+	cb->len = bbio->bio.bi_iter.bi_size;
 
 	btrfs_add_compressed_bio_pages(cb, disk_bytenr);
 
@@ -573,7 +573,7 @@  void btrfs_submit_compressed_read(struct bio *bio, int mirror_num)
 out_free_bio:
 	bio_put(&cb->bbio.bio);
 out:
-	btrfs_bio_end_io(btrfs_bio(bio), ret);
+	btrfs_bio_end_io(bbio, ret);
 }
 
 /*
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index 95d2e85c6e4eea..692bafa1050e8e 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -94,7 +94,7 @@  void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
 				  blk_opf_t write_flags,
 				  struct cgroup_subsys_state *blkcg_css,
 				  bool writeback);
-void btrfs_submit_compressed_read(struct bio *bio, int mirror_num);
+void btrfs_submit_compressed_read(struct btrfs_bio *bbio, int mirror_num);
 
 unsigned int btrfs_compress_str2level(unsigned int type, const char *str);
 
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 77de129db364c9..6ea6f2c057ac3e 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -155,7 +155,7 @@  static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
 
 	if (btrfs_op(bio) == BTRFS_MAP_READ &&
 	    bio_ctrl->compress_type != BTRFS_COMPRESS_NONE)
-		btrfs_submit_compressed_read(bio, mirror_num);
+		btrfs_submit_compressed_read(btrfs_bio(bio), mirror_num);
 	else
 		btrfs_submit_bio(btrfs_bio(bio), mirror_num);