diff mbox series

[07/10] btrfs: simplify finding the inode in submit_one_bio

Message ID 20230301134244.1378533-8-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
struct btrfs_bio now has an always valid inode pointer that can be used
to find the inode in submit_one_bio, so use that and initialize all
variables for which it is possible at declaration time.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/extent_io.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

Comments

Johannes Thumshirn March 2, 2023, 1:10 p.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Qu Wenruo March 2, 2023, 11:30 p.m. UTC | #2
On 2023/3/1 21:42, Christoph Hellwig wrote:
> struct btrfs_bio now has an always valid inode pointer that can be used
> to find the inode in submit_one_bio, so use that and initialize all
> variables for which it is possible at declaration time.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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

Initially I want to recommend to also make bio_ctrl->bio to be 
btrfs_bio, but that would be done in the next patch already.

Thanks,
Qu
> ---
>   fs/btrfs/extent_io.c | 15 ++++-----------
>   1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 6ea6f2c057ac3e..05b96a77fba104 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -123,23 +123,16 @@ struct btrfs_bio_ctrl {
>   
>   static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
>   {
> -	struct bio *bio;
> -	struct bio_vec *bv;
> -	struct inode *inode;
> -	int mirror_num;
> +	struct bio *bio = bio_ctrl->bio;
> +	int mirror_num = bio_ctrl->mirror_num;
>   
> -	if (!bio_ctrl->bio)
> +	if (!bio)
>   		return;
>   
> -	bio = bio_ctrl->bio;
> -	bv = bio_first_bvec_all(bio);
> -	inode = bv->bv_page->mapping->host;
> -	mirror_num = bio_ctrl->mirror_num;
> -
>   	/* Caller should ensure the bio has at least some range added */
>   	ASSERT(bio->bi_iter.bi_size);
>   
> -	if (!is_data_inode(inode)) {
> +	if (!is_data_inode(&btrfs_bio(bio)->inode->vfs_inode)) {
>   		if (btrfs_op(bio) != BTRFS_MAP_WRITE) {
>   			/*
>   			 * For metadata read, we should have the parent_check,
Anand Jain March 3, 2023, 9:16 a.m. UTC | #3
On 01/03/2023 21:42, Christoph Hellwig wrote:
> struct btrfs_bio now has an always valid inode pointer that can be used
> to find the inode in submit_one_bio, so use that and initialize all
> variables for which it is possible at declaration time.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 6ea6f2c057ac3e..05b96a77fba104 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -123,23 +123,16 @@  struct btrfs_bio_ctrl {
 
 static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
 {
-	struct bio *bio;
-	struct bio_vec *bv;
-	struct inode *inode;
-	int mirror_num;
+	struct bio *bio = bio_ctrl->bio;
+	int mirror_num = bio_ctrl->mirror_num;
 
-	if (!bio_ctrl->bio)
+	if (!bio)
 		return;
 
-	bio = bio_ctrl->bio;
-	bv = bio_first_bvec_all(bio);
-	inode = bv->bv_page->mapping->host;
-	mirror_num = bio_ctrl->mirror_num;
-
 	/* Caller should ensure the bio has at least some range added */
 	ASSERT(bio->bi_iter.bi_size);
 
-	if (!is_data_inode(inode)) {
+	if (!is_data_inode(&btrfs_bio(bio)->inode->vfs_inode)) {
 		if (btrfs_op(bio) != BTRFS_MAP_WRITE) {
 			/*
 			 * For metadata read, we should have the parent_check,