/* For RAID5/6 adjust to a full IO stripe length */
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
- io_stripe_size = btrfs_stripe_nr_to_offset(nr_data_stripes(map));
+ io_stripe_size = btrfs_stripe_nr_to_offset(nr_data_stripes(map),
+ map->stripe_len);
buf = kzalloc_objs(u64, map->num_stripes, GFP_NOFS);
if (!buf) {
u32 stripe_index;
u32 rot;
- *offset = last_offset + btrfs_stripe_nr_to_offset(i);
+ *offset = last_offset + btrfs_stripe_nr_to_offset(i,
+ map->stripe_len);
stripe_nr = (u32)(*offset >> map->stripe_shift) / data_stripes;
if (stripe_index < num)
j++;
}
- *offset = last_offset + btrfs_stripe_nr_to_offset(j);
+ *offset = last_offset + btrfs_stripe_nr_to_offset(j, map->stripe_len);
return 1;
}
ASSERT(first_slot + nr_stripes <= SCRUB_TOTAL_STRIPES);
scrub_throttle_dev_io(sctx, sctx->stripes[0].dev,
- btrfs_stripe_nr_to_offset(nr_stripes));
+ btrfs_stripe_nr_to_offset(nr_stripes,
+ sctx->stripes[0].stripe_len));
blk_start_plug(&plug);
for (int i = 0; i < nr_stripes; i++) {
struct scrub_stripe *stripe = &sctx->stripes[first_slot + i];
struct btrfs_raid_bio *rbio;
struct bio bio;
const int data_stripes = nr_data_stripes(map);
- u64 length = btrfs_stripe_nr_to_offset(data_stripes);
+ u64 length = btrfs_stripe_nr_to_offset(data_stripes, map->stripe_len);
int ret;
bio_init(&bio, NULL, NULL, 0, REQ_OP_READ);
BTRFS_PATH_AUTO_RELEASE(csum_path);
struct scrub_stripe *stripe;
bool all_empty = true;
+ const u32 stripe_len = map->stripe_len;
const int data_stripes = nr_data_stripes(map);
unsigned long extent_bitmap = 0;
int ret;
data_stripes) >> map->stripe_shift;
stripe_index = (i + rot) % map->num_stripes;
physical = map->stripes[stripe_index].physical +
- btrfs_stripe_nr_to_offset(rot);
+ btrfs_stripe_nr_to_offset(rot, stripe_len);
scrub_reset_stripe(stripe);
set_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state);
ret = scrub_find_fill_first_stripe(bg, &extent_path, &csum_path,
map->stripes[stripe_index].dev, physical, 1,
- full_stripe_start + btrfs_stripe_nr_to_offset(i),
- map->stripe_len, stripe);
+ full_stripe_start +
+ btrfs_stripe_nr_to_offset(i, stripe_len),
+ stripe_len, stripe);
if (ret < 0)
return ret;
/*
*/
if (ret > 0) {
stripe->logical = full_stripe_start +
- btrfs_stripe_nr_to_offset(i);
+ btrfs_stripe_nr_to_offset(i, stripe_len);
stripe->dev = map->stripes[stripe_index].dev;
stripe->mirror_num = 1;
set_bit(SCRUB_STRIPE_FLAG_INITIALIZED, &stripe->state);
ASSERT(map->type & (BTRFS_BLOCK_GROUP_RAID0 |
BTRFS_BLOCK_GROUP_RAID10));
- return btrfs_stripe_nr_to_offset(map->num_stripes / map->sub_stripes);
+ return btrfs_stripe_nr_to_offset(map->num_stripes / map->sub_stripes,
+ map->stripe_len);
}
/* Get the logical bytenr for the stripe */
* (stripe_index / sub_stripes) gives how many data stripes we need to
* skip.
*/
- return btrfs_stripe_nr_to_offset(stripe_index / map->sub_stripes) +
- bg->start;
+ return btrfs_stripe_nr_to_offset(stripe_index / map->sub_stripes,
+ map->stripe_len) + bg->start;
}
/* Get the mirror number for the stripe */
}
if (profile & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
ret = scrub_simple_stripe(sctx, bg, map, scrub_dev, stripe_index);
- offset = btrfs_stripe_nr_to_offset(stripe_index / map->sub_stripes);
+ offset = btrfs_stripe_nr_to_offset(stripe_index / map->sub_stripes,
+ stripe_len);
goto out;
}
/* Initialize @offset in case we need to go to out: label */
get_raid56_logic_offset(physical, stripe_index, map, &offset, NULL);
- increment = btrfs_stripe_nr_to_offset(nr_data_stripes(map));
+ increment = btrfs_stripe_nr_to_offset(nr_data_stripes(map), stripe_len);
/*
* Due to the rotation, for RAID56 it's better to iterate each stripe
/* We don't want a chunk larger than 10% of writable space */
ctl->max_chunk_size = min(mult_perc(fs_devices->total_rw_bytes, 10),
ctl->max_chunk_size);
- ctl->dev_extent_min = btrfs_stripe_nr_to_offset(ctl->dev_stripes);
+ ctl->dev_extent_min = btrfs_stripe_nr_to_offset(ctl->dev_stripes,
+ BTRFS_STRIPE_LEN);
}
static void init_alloc_chunk_ctl_policy_zoned(
if (!WARN_ON(IS_ERR(map))) {
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
- len = btrfs_stripe_nr_to_offset(nr_data_stripes(map));
+ len = btrfs_stripe_nr_to_offset(nr_data_stripes(map),
+ map->stripe_len);
btrfs_free_chunk_map(map);
}
return len;
u64 stripe_end_offset;
u64 stripe_offset;
u32 stripe_index;
+ u32 stripe_len;
u32 factor = 0;
u32 sub_stripes = 0;
u32 stripes_per_dev = 0;
goto out_free_map;
}
+ stripe_len = map->stripe_len;
offset = logical - map->start;
length = min_t(u64, map->start + map->chunk_len - logical, length);
*length_ret = length;
stripe_nr = offset >> BTRFS_STRIPE_LEN_SHIFT;
/* stripe_offset is the offset of this block in its stripe */
- stripe_offset = offset - btrfs_stripe_nr_to_offset(stripe_nr);
+ stripe_offset = offset - btrfs_stripe_nr_to_offset(stripe_nr,
+ stripe_len);
stripe_nr_end = round_up(offset + length, BTRFS_STRIPE_LEN) >>
BTRFS_STRIPE_LEN_SHIFT;
stripe_cnt = stripe_nr_end - stripe_nr;
- stripe_end_offset = btrfs_stripe_nr_to_offset(stripe_nr_end) -
+ stripe_end_offset = btrfs_stripe_nr_to_offset(stripe_nr_end, stripe_len) -
(offset + length);
/*
* after this, stripe_nr is the number of stripes on this
for (i = 0; i < *num_stripes; i++) {
stripes[i].physical =
map->stripes[stripe_index].physical +
- stripe_offset + btrfs_stripe_nr_to_offset(stripe_nr);
+ stripe_offset + btrfs_stripe_nr_to_offset(stripe_nr,
+ stripe_len);
stripes[i].dev = map->stripes[stripe_index].dev;
if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |
BTRFS_BLOCK_GROUP_RAID10)) {
- stripes[i].length = btrfs_stripe_nr_to_offset(stripes_per_dev);
+ stripes[i].length = btrfs_stripe_nr_to_offset(stripes_per_dev,
+ stripe_len);
if (i / sub_stripes < remaining_stripes)
stripes[i].length += BTRFS_STRIPE_LEN;
static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, u64 offset,
struct btrfs_io_geometry *io_geom)
{
+ const u32 stripe_len = map->stripe_len;
+
/*
* Stripe_nr is the stripe where this block falls. stripe_offset is
* the offset of this block in its stripe.
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
unsigned long full_stripe_len =
- btrfs_stripe_nr_to_offset(nr_data_stripes(map));
+ btrfs_stripe_nr_to_offset(nr_data_stripes(map),
+ stripe_len);
/*
* For full stripe start, we use previously calculated
* not ensured to be power of 2.
*/
io_geom->raid56_full_stripe_start = btrfs_stripe_nr_to_offset(
- rounddown(io_geom->stripe_nr, nr_data_stripes(map)));
+ rounddown(io_geom->stripe_nr, nr_data_stripes(map)),
+ stripe_len);
ASSERT(io_geom->raid56_full_stripe_start + full_stripe_len > offset,
"raid56_full_stripe_start=%llu full_stripe_len=%lu offset=%llu",
dst->physical = map->stripes[io_geom->stripe_index].physical +
io_geom->stripe_offset +
- btrfs_stripe_nr_to_offset(io_geom->stripe_nr);
+ btrfs_stripe_nr_to_offset(io_geom->stripe_nr,
+ map->stripe_len);
return 0;
}
/* Return the length to the full stripe end. */
*length = min(logical + *length,
io_geom->raid56_full_stripe_start + map->start +
- btrfs_stripe_nr_to_offset(data_stripes)) -
+ btrfs_stripe_nr_to_offset(data_stripes, map->stripe_len)) -
logical;
io_geom->stripe_index = 0;
io_geom->stripe_offset = 0;
*/
bioc->full_stripe_logical = map->start +
btrfs_stripe_nr_to_offset(io_geom.stripe_nr *
- nr_data_stripes(map));
+ nr_data_stripes(map),
+ map->stripe_len);
for (int i = 0; i < io_geom.num_stripes; i++) {
struct btrfs_io_stripe *dst = &bioc->stripes[i];
u32 stripe_index;
dst->physical =
map->stripes[stripe_index].physical +
io_geom.stripe_offset +
- btrfs_stripe_nr_to_offset(io_geom.stripe_nr);
+ btrfs_stripe_nr_to_offset(io_geom.stripe_nr,
+ map->stripe_len);
}
} else {
/*
for (i = 0; i < data_stripes; i++) {
u64 stripe_start = bioc->full_stripe_logical +
- btrfs_stripe_nr_to_offset(i);
+ btrfs_stripe_nr_to_offset(i, bioc->stripe_len);
if (logical >= stripe_start &&
logical < stripe_start + BTRFS_STRIPE_LEN)
* @stripe_nr is u32, with left shift it can overflow u32 for chunks larger
* than 4G. This does the proper type cast to avoid overflow.
*/
-static inline u64 btrfs_stripe_nr_to_offset(u32 stripe_nr)
+static inline u64 btrfs_stripe_nr_to_offset(u32 stripe_nr, u32 stripe_len)
{
- return (u64)stripe_nr << BTRFS_STRIPE_LEN_SHIFT;
+ ASSERT(is_power_of_2(stripe_len) && stripe_len <= BTRFS_STRIPE_LEN);
+ return (u64)stripe_nr << ilog2(stripe_len);
}
void btrfs_get_bioc(struct btrfs_io_context *bioc);
if (zone_info[i].alloc_offset == WP_CONVENTIONAL) {
has_conventional = true;
- zone_info[i].alloc_offset = btrfs_stripe_nr_to_offset(stripe_nr);
+ zone_info[i].alloc_offset =
+ btrfs_stripe_nr_to_offset(stripe_nr,
+ map->stripe_len);
if (stripe_index > i)
zone_info[i].alloc_offset += BTRFS_STRIPE_LEN;
if (raid0_allocs[idx] == WP_CONVENTIONAL) {
has_conventional = true;
- raid0_allocs[idx] = btrfs_stripe_nr_to_offset(stripe_nr);
+ raid0_allocs[idx] = btrfs_stripe_nr_to_offset(stripe_nr,
+ map->stripe_len);
if (stripe_index > idx)
raid0_allocs[idx] += BTRFS_STRIPE_LEN;