@@ -34,9 +34,6 @@
#define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G)
#define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G)
-#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET)
-#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET)
-
/* Number of superblock log zones */
#define BTRFS_NR_SB_LOG_ZONES 2
@@ -153,15 +150,23 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
/*
* Get the first zone number of the superblock mirror
*/
-static inline u32 sb_zone_number(int shift, int mirror)
+static inline u32 sb_zone_number(struct block_device *bdev, int mirror)
{
u64 zone;
ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX);
switch (mirror) {
- case 0: zone = 0; break;
- case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break;
- case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
+ case 0:
+ zone = 0;
+ break;
+ case 1:
+ zone = bdev_zone_no(bdev,
+ BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT);
+ break;
+ case 2:
+ zone = bdev_zone_no(bdev,
+ BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT);
+ break;
}
ASSERT(zone <= U32_MAX);
@@ -515,7 +520,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
/* Cache the sb zone number */
for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) {
zone_info->sb_zone_location[i] =
- sb_zone_number(zone_info->zone_size_shift, i);
+ sb_zone_number(bdev, i);
}
/* Validate superblock log */
nr_zones = BTRFS_NR_SB_LOG_ZONES;
@@ -840,7 +845,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
nr_sectors = bdev_nr_sectors(bdev);
nr_zones = nr_sectors >> zone_sectors_shift;
- sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror);
+ sb_zone = sb_zone_number(bdev, mirror);
if (sb_zone + 1 >= nr_zones)
return -ENOENT;
@@ -964,7 +969,7 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror)
nr_sectors = bdev_nr_sectors(bdev);
nr_zones = nr_sectors >> zone_sectors_shift;
- sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror);
+ sb_zone = sb_zone_number(bdev, mirror);
if (sb_zone + 1 >= nr_zones)
return -ENOENT;