@@ -5930,7 +5930,7 @@ static bool need_full_stripe(enum btrfs_map_op op)
59305930 * usually shouldn't happen unless @logical is corrupted, 0 otherwise.
59315931 */
59325932int btrfs_get_io_geometry (struct btrfs_fs_info * fs_info , enum btrfs_map_op op ,
5933- u64 logical , u64 len , struct btrfs_io_geometry * io_geom )
5933+ u64 logical , u64 len , struct btrfs_io_geometry * io_geom )
59345934{
59355935 struct extent_map * em ;
59365936 struct map_lookup * map ;
@@ -6037,78 +6037,30 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
60376037 int patch_the_first_stripe_for_dev_replace = 0 ;
60386038 u64 physical_to_patch_in_first_stripe = 0 ;
60396039 u64 raid56_full_stripe_start = (u64 )- 1 ;
6040+ struct btrfs_io_geometry geom ;
6041+
6042+ ASSERT (bbio_ret );
60406043
60416044 if (op == BTRFS_MAP_DISCARD )
60426045 return __btrfs_map_block_for_discard (fs_info , logical ,
60436046 * length , bbio_ret );
60446047
6045- em = btrfs_get_chunk_map (fs_info , logical , * length );
6046- if (IS_ERR ( em ) )
6047- return PTR_ERR ( em ) ;
6048+ ret = btrfs_get_io_geometry (fs_info , op , logical , * length , & geom );
6049+ if (ret < 0 )
6050+ return ret ;
60486051
6052+ em = btrfs_get_chunk_map (fs_info , logical , * length );
6053+ ASSERT (em );
60496054 map = em -> map_lookup ;
6050- offset = logical - em -> start ;
60516055
6052- stripe_len = map -> stripe_len ;
6053- stripe_nr = offset ;
6054- /*
6055- * stripe_nr counts the total number of stripes we have to stride
6056- * to get to this block
6057- */
6058- stripe_nr = div64_u64 (stripe_nr , stripe_len );
6056+ * length = geom .len ;
6057+ offset = geom .offset ;
6058+ stripe_len = geom .stripe_len ;
6059+ stripe_nr = geom .stripe_nr ;
6060+ stripe_offset = geom .stripe_offset ;
6061+ raid56_full_stripe_start = geom .raid56_stripe_offset ;
60596062 data_stripes = nr_data_stripes (map );
60606063
6061- stripe_offset = stripe_nr * stripe_len ;
6062- if (offset < stripe_offset ) {
6063- btrfs_crit (fs_info ,
6064- "stripe math has gone wrong, stripe_offset=%llu, offset=%llu, start=%llu, logical=%llu, stripe_len=%llu" ,
6065- stripe_offset , offset , em -> start , logical ,
6066- stripe_len );
6067- free_extent_map (em );
6068- return - EINVAL ;
6069- }
6070-
6071- /* stripe_offset is the offset of this block in its stripe*/
6072- stripe_offset = offset - stripe_offset ;
6073-
6074- /* if we're here for raid56, we need to know the stripe aligned start */
6075- if (map -> type & BTRFS_BLOCK_GROUP_RAID56_MASK ) {
6076- unsigned long full_stripe_len = stripe_len * data_stripes ;
6077- raid56_full_stripe_start = offset ;
6078-
6079- /* allow a write of a full stripe, but make sure we don't
6080- * allow straddling of stripes
6081- */
6082- raid56_full_stripe_start = div64_u64 (raid56_full_stripe_start ,
6083- full_stripe_len );
6084- raid56_full_stripe_start *= full_stripe_len ;
6085- }
6086-
6087- if (map -> type & BTRFS_BLOCK_GROUP_PROFILE_MASK ) {
6088- u64 max_len ;
6089- /* For writes to RAID[56], allow a full stripeset across all disks.
6090- For other RAID types and for RAID[56] reads, just allow a single
6091- stripe (on a single disk). */
6092- if ((map -> type & BTRFS_BLOCK_GROUP_RAID56_MASK ) &&
6093- (op == BTRFS_MAP_WRITE )) {
6094- max_len = stripe_len * data_stripes -
6095- (offset - raid56_full_stripe_start );
6096- } else {
6097- /* we limit the length of each bio to what fits in a stripe */
6098- max_len = stripe_len - stripe_offset ;
6099- }
6100- * length = min_t (u64 , em -> len - offset , max_len );
6101- } else {
6102- * length = em -> len - offset ;
6103- }
6104-
6105- /*
6106- * This is for when we're called from btrfs_bio_fits_in_stripe and all
6107- * it cares about is the length
6108- */
6109- if (!bbio_ret )
6110- goto out ;
6111-
61126064 down_read (& dev_replace -> rwsem );
61136065 dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing (dev_replace );
61146066 /*
0 commit comments