Skip to content

Commit 33eb1e5

Browse files
adam900710kdave
authored andcommitted
btrfs: factor out stripe length calculation into a helper
Currently there are two locations which need to calculate the real length of a stripe (which can be at the end of a chunk, and the chunk size may not always be 64K aligned). Factor them into a helper as we're going to have a third user soon. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b8e947e commit 33eb1e5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

fs/btrfs/scrub.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,20 @@ static void scrub_reset_stripe(struct scrub_stripe *stripe)
16481648
}
16491649
}
16501650

1651+
static u32 stripe_length(const struct scrub_stripe *stripe)
1652+
{
1653+
ASSERT(stripe->bg);
1654+
1655+
return min(BTRFS_STRIPE_LEN,
1656+
stripe->bg->start + stripe->bg->length - stripe->logical);
1657+
}
1658+
16511659
static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
16521660
struct scrub_stripe *stripe)
16531661
{
16541662
struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
16551663
struct btrfs_bio *bbio = NULL;
1656-
unsigned int nr_sectors = min(BTRFS_STRIPE_LEN, stripe->bg->start +
1657-
stripe->bg->length - stripe->logical) >>
1658-
fs_info->sectorsize_bits;
1664+
unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
16591665
u64 stripe_len = BTRFS_STRIPE_LEN;
16601666
int mirror = stripe->mirror_num;
16611667
int i;
@@ -1729,9 +1735,7 @@ static void scrub_submit_initial_read(struct scrub_ctx *sctx,
17291735
{
17301736
struct btrfs_fs_info *fs_info = sctx->fs_info;
17311737
struct btrfs_bio *bbio;
1732-
unsigned int nr_sectors = min(BTRFS_STRIPE_LEN, stripe->bg->start +
1733-
stripe->bg->length - stripe->logical) >>
1734-
fs_info->sectorsize_bits;
1738+
unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
17351739
int mirror = stripe->mirror_num;
17361740

17371741
ASSERT(stripe->bg);

0 commit comments

Comments
 (0)