@@ -1277,7 +1277,7 @@ struct zone_info {
12771277
12781278static int btrfs_load_zone_info (struct btrfs_fs_info * fs_info , int zone_idx ,
12791279 struct zone_info * info , unsigned long * active ,
1280- struct btrfs_chunk_map * map )
1280+ struct btrfs_chunk_map * map , bool new )
12811281{
12821282 struct btrfs_dev_replace * dev_replace = & fs_info -> dev_replace ;
12831283 struct btrfs_device * device ;
@@ -1307,6 +1307,8 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
13071307 return 0 ;
13081308 }
13091309
1310+ ASSERT (!new || btrfs_dev_is_empty_zone (device , info -> physical ));
1311+
13101312 /* This zone will be used for allocation, so mark this zone non-empty. */
13111313 btrfs_dev_clear_zone_empty (device , info -> physical );
13121314
@@ -1319,6 +1321,18 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
13191321 * to determine the allocation offset within the zone.
13201322 */
13211323 WARN_ON (!IS_ALIGNED (info -> physical , fs_info -> zone_size ));
1324+
1325+ if (new ) {
1326+ sector_t capacity ;
1327+
1328+ capacity = bdev_zone_capacity (device -> bdev , info -> physical >> SECTOR_SHIFT );
1329+ up_read (& dev_replace -> rwsem );
1330+ info -> alloc_offset = 0 ;
1331+ info -> capacity = capacity << SECTOR_SHIFT ;
1332+
1333+ return 0 ;
1334+ }
1335+
13221336 nofs_flag = memalloc_nofs_save ();
13231337 ret = btrfs_get_dev_zone (device , info -> physical , & zone );
13241338 memalloc_nofs_restore (nofs_flag );
@@ -1588,7 +1602,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
15881602 }
15891603
15901604 for (i = 0 ; i < map -> num_stripes ; i ++ ) {
1591- ret = btrfs_load_zone_info (fs_info , i , & zone_info [i ], active , map );
1605+ ret = btrfs_load_zone_info (fs_info , i , & zone_info [i ], active , map , new );
15921606 if (ret )
15931607 goto out ;
15941608
0 commit comments