@@ -41,13 +41,17 @@ static bool bbio_has_ordered_extent(const struct btrfs_bio *bbio)
4141 * Initialize a btrfs_bio structure. This skips the embedded bio itself as it
4242 * is already initialized by the block layer.
4343 */
44- void btrfs_bio_init (struct btrfs_bio * bbio , struct btrfs_fs_info * fs_info ,
44+ void btrfs_bio_init (struct btrfs_bio * bbio , struct btrfs_inode * inode , u64 file_offset ,
4545 btrfs_bio_end_io_t end_io , void * private )
4646{
47+ /* @inode parameter is mandatory. */
48+ ASSERT (inode );
49+
4750 memset (bbio , 0 , offsetof(struct btrfs_bio , bio ));
48- bbio -> fs_info = fs_info ;
51+ bbio -> inode = inode ;
4952 bbio -> end_io = end_io ;
5053 bbio -> private = private ;
54+ bbio -> file_offset = file_offset ;
5155 atomic_set (& bbio -> pending_ios , 1 );
5256 WRITE_ONCE (bbio -> status , BLK_STS_OK );
5357}
@@ -60,15 +64,15 @@ void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
6064 * a mempool.
6165 */
6266struct btrfs_bio * btrfs_bio_alloc (unsigned int nr_vecs , blk_opf_t opf ,
63- struct btrfs_fs_info * fs_info ,
67+ struct btrfs_inode * inode , u64 file_offset ,
6468 btrfs_bio_end_io_t end_io , void * private )
6569{
6670 struct btrfs_bio * bbio ;
6771 struct bio * bio ;
6872
6973 bio = bio_alloc_bioset (NULL , nr_vecs , opf , GFP_NOFS , & btrfs_bioset );
7074 bbio = btrfs_bio (bio );
71- btrfs_bio_init (bbio , fs_info , end_io , private );
75+ btrfs_bio_init (bbio , inode , file_offset , end_io , private );
7276 return bbio ;
7377}
7478
@@ -85,9 +89,7 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
8589 return ERR_CAST (bio );
8690
8791 bbio = btrfs_bio (bio );
88- btrfs_bio_init (bbio , fs_info , NULL , orig_bbio );
89- bbio -> inode = orig_bbio -> inode ;
90- bbio -> file_offset = orig_bbio -> file_offset ;
92+ btrfs_bio_init (bbio , orig_bbio -> inode , orig_bbio -> file_offset , NULL , orig_bbio );
9193 orig_bbio -> file_offset += map_length ;
9294 if (bbio_has_ordered_extent (bbio )) {
9395 refcount_inc (& orig_bbio -> ordered -> refs );
@@ -244,9 +246,8 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
244246 bio_add_folio_nofail (repair_bio , folio , sectorsize , foff );
245247
246248 repair_bbio = btrfs_bio (repair_bio );
247- btrfs_bio_init (repair_bbio , fs_info , NULL , fbio );
248- repair_bbio -> inode = failed_bbio -> inode ;
249- repair_bbio -> file_offset = failed_bbio -> file_offset + bio_offset ;
249+ btrfs_bio_init (repair_bbio , failed_bbio -> inode , failed_bbio -> file_offset + bio_offset ,
250+ NULL , fbio );
250251
251252 mirror = next_repair_mirror (fbio , failed_bbio -> mirror_num );
252253 btrfs_debug (fs_info , "submitting repair read to mirror %d" , mirror );
@@ -332,7 +333,7 @@ static void btrfs_simple_end_io(struct bio *bio)
332333{
333334 struct btrfs_bio * bbio = btrfs_bio (bio );
334335 struct btrfs_device * dev = bio -> bi_private ;
335- struct btrfs_fs_info * fs_info = bbio -> fs_info ;
336+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
336337
337338 btrfs_bio_counter_dec (fs_info );
338339
@@ -581,10 +582,11 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
581582
582583static bool should_async_write (struct btrfs_bio * bbio )
583584{
585+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
584586 bool auto_csum_mode = true;
585587
586588#ifdef CONFIG_BTRFS_EXPERIMENTAL
587- struct btrfs_fs_devices * fs_devices = bbio -> fs_info -> fs_devices ;
589+ struct btrfs_fs_devices * fs_devices = fs_info -> fs_devices ;
588590 enum btrfs_offload_csum_mode csum_mode = READ_ONCE (fs_devices -> offload_csum_mode );
589591
590592 if (csum_mode == BTRFS_OFFLOAD_CSUM_FORCE_OFF )
@@ -594,7 +596,7 @@ static bool should_async_write(struct btrfs_bio *bbio)
594596#endif
595597
596598 /* Submit synchronously if the checksum implementation is fast. */
597- if (auto_csum_mode && test_bit (BTRFS_FS_CSUM_IMPL_FAST , & bbio -> fs_info -> flags ))
599+ if (auto_csum_mode && test_bit (BTRFS_FS_CSUM_IMPL_FAST , & fs_info -> flags ))
598600 return false;
599601
600602 /*
@@ -605,7 +607,7 @@ static bool should_async_write(struct btrfs_bio *bbio)
605607 return false;
606608
607609 /* Zoned devices require I/O to be submitted in order. */
608- if ((bbio -> bio .bi_opf & REQ_META ) && btrfs_is_zoned (bbio -> fs_info ))
610+ if ((bbio -> bio .bi_opf & REQ_META ) && btrfs_is_zoned (fs_info ))
609611 return false;
610612
611613 return true;
@@ -620,7 +622,7 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio,
620622 struct btrfs_io_context * bioc ,
621623 struct btrfs_io_stripe * smap , int mirror_num )
622624{
623- struct btrfs_fs_info * fs_info = bbio -> fs_info ;
625+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
624626 struct async_submit_bio * async ;
625627
626628 async = kmalloc (sizeof (* async ), GFP_NOFS );
@@ -639,27 +641,28 @@ static bool btrfs_wq_submit_bio(struct btrfs_bio *bbio,
639641
640642static u64 btrfs_append_map_length (struct btrfs_bio * bbio , u64 map_length )
641643{
644+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
642645 unsigned int nr_segs ;
643646 int sector_offset ;
644647
645- map_length = min (map_length , bbio -> fs_info -> max_zone_append_size );
646- sector_offset = bio_split_rw_at (& bbio -> bio , & bbio -> fs_info -> limits ,
648+ map_length = min (map_length , fs_info -> max_zone_append_size );
649+ sector_offset = bio_split_rw_at (& bbio -> bio , & fs_info -> limits ,
647650 & nr_segs , map_length );
648651 if (sector_offset ) {
649652 /*
650653 * bio_split_rw_at() could split at a size smaller than our
651654 * sectorsize and thus cause unaligned I/Os. Fix that by
652655 * always rounding down to the nearest boundary.
653656 */
654- return ALIGN_DOWN (sector_offset << SECTOR_SHIFT , bbio -> fs_info -> sectorsize );
657+ return ALIGN_DOWN (sector_offset << SECTOR_SHIFT , fs_info -> sectorsize );
655658 }
656659 return map_length ;
657660}
658661
659662static bool btrfs_submit_chunk (struct btrfs_bio * bbio , int mirror_num )
660663{
661664 struct btrfs_inode * inode = bbio -> inode ;
662- struct btrfs_fs_info * fs_info = bbio -> fs_info ;
665+ struct btrfs_fs_info * fs_info = inode -> root -> fs_info ;
663666 struct bio * bio = & bbio -> bio ;
664667 u64 logical = bio -> bi_iter .bi_sector << SECTOR_SHIFT ;
665668 u64 length = bio -> bi_iter .bi_size ;
@@ -670,7 +673,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
670673 blk_status_t status ;
671674 int ret ;
672675
673- if (! bbio -> inode || btrfs_is_data_reloc_root (inode -> root ))
676+ if (bbio -> is_scrub || btrfs_is_data_reloc_root (inode -> root ))
674677 smap .rst_search_commit_root = true;
675678 else
676679 smap .rst_search_commit_root = false;
@@ -782,7 +785,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
782785static void assert_bbio_alignment (struct btrfs_bio * bbio )
783786{
784787#ifdef CONFIG_BTRFS_ASSERT
785- struct btrfs_fs_info * fs_info = bbio -> fs_info ;
788+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
786789 struct bio_vec bvec ;
787790 struct bvec_iter iter ;
788791 const u32 blocksize = fs_info -> sectorsize ;
@@ -885,16 +888,16 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
885888 */
886889void btrfs_submit_repair_write (struct btrfs_bio * bbio , int mirror_num , bool dev_replace )
887890{
888- struct btrfs_fs_info * fs_info = bbio -> fs_info ;
891+ struct btrfs_fs_info * fs_info = bbio -> inode -> root -> fs_info ;
889892 u64 logical = bbio -> bio .bi_iter .bi_sector << SECTOR_SHIFT ;
890893 u64 length = bbio -> bio .bi_iter .bi_size ;
891894 struct btrfs_io_stripe smap = { 0 };
892895 int ret ;
893896
894- ASSERT (fs_info );
895897 ASSERT (mirror_num > 0 );
896898 ASSERT (btrfs_op (& bbio -> bio ) == BTRFS_MAP_WRITE );
897- ASSERT (!bbio -> inode );
899+ ASSERT (!is_data_inode (bbio -> inode ));
900+ ASSERT (bbio -> is_scrub );
898901
899902 btrfs_bio_counter_inc_blocked (fs_info );
900903 ret = btrfs_map_repair_block (fs_info , & smap , logical , length , mirror_num );
0 commit comments