Skip to content

Commit 51e28ba

Browse files
committed
md/raid5: implement pers->bitmap_sector()
JIRA: https://issues.redhat.com/browse/RHEL-73514 commit 9c89f60 Author: Yu Kuai <yukuai3@huawei.com> Date: Thu Jan 9 09:51:44 2025 +0800 md/raid5: implement pers->bitmap_sector() Bitmap is used for the whole array for raid1/raid10, hence IO for the array can be used directly for bitmap. However, bitmap is used for underlying disks for raid5, hence IO for the array can't be used directly for bitmap. Implement pers->bitmap_sector() for raid5 to convert IO ranges from the array to the underlying disks. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Link: https://lore.kernel.org/r/20250109015145.158868-5-yukuai1@huaweicloud.com Signed-off-by: Song Liu <song@kernel.org> Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
1 parent 7fe63ea commit 51e28ba

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

drivers/md/raid5.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,6 +5918,54 @@ static enum reshape_loc get_reshape_loc(struct mddev *mddev,
59185918
return LOC_BEHIND_RESHAPE;
59195919
}
59205920

5921+
static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
5922+
unsigned long *sectors)
5923+
{
5924+
struct r5conf *conf = mddev->private;
5925+
sector_t start = *offset;
5926+
sector_t end = start + *sectors;
5927+
sector_t prev_start = start;
5928+
sector_t prev_end = end;
5929+
int sectors_per_chunk;
5930+
enum reshape_loc loc;
5931+
int dd_idx;
5932+
5933+
sectors_per_chunk = conf->chunk_sectors *
5934+
(conf->raid_disks - conf->max_degraded);
5935+
start = round_down(start, sectors_per_chunk);
5936+
end = round_up(end, sectors_per_chunk);
5937+
5938+
start = raid5_compute_sector(conf, start, 0, &dd_idx, NULL);
5939+
end = raid5_compute_sector(conf, end, 0, &dd_idx, NULL);
5940+
5941+
/*
5942+
* For LOC_INSIDE_RESHAPE, this IO will wait for reshape to make
5943+
* progress, hence it's the same as LOC_BEHIND_RESHAPE.
5944+
*/
5945+
loc = get_reshape_loc(mddev, conf, prev_start);
5946+
if (likely(loc != LOC_AHEAD_OF_RESHAPE)) {
5947+
*offset = start;
5948+
*sectors = end - start;
5949+
return;
5950+
}
5951+
5952+
sectors_per_chunk = conf->prev_chunk_sectors *
5953+
(conf->previous_raid_disks - conf->max_degraded);
5954+
prev_start = round_down(prev_start, sectors_per_chunk);
5955+
prev_end = round_down(prev_end, sectors_per_chunk);
5956+
5957+
prev_start = raid5_compute_sector(conf, prev_start, 1, &dd_idx, NULL);
5958+
prev_end = raid5_compute_sector(conf, prev_end, 1, &dd_idx, NULL);
5959+
5960+
/*
5961+
* for LOC_AHEAD_OF_RESHAPE, reshape can make progress before this IO
5962+
* is handled in make_stripe_request(), we can't know this here hence
5963+
* we set bits for both.
5964+
*/
5965+
*offset = min(start, prev_start);
5966+
*sectors = max(end, prev_end) - *offset;
5967+
}
5968+
59215969
static enum stripe_result make_stripe_request(struct mddev *mddev,
59225970
struct r5conf *conf, struct stripe_request_ctx *ctx,
59235971
sector_t logical_sector, struct bio *bi)
@@ -8962,6 +9010,7 @@ static struct md_personality raid6_personality =
89629010
.takeover = raid6_takeover,
89639011
.change_consistency_policy = raid5_change_consistency_policy,
89649012
.prepare_suspend = raid5_prepare_suspend,
9013+
.bitmap_sector = raid5_bitmap_sector,
89659014
};
89669015
static struct md_personality raid5_personality =
89679016
{
@@ -8987,6 +9036,7 @@ static struct md_personality raid5_personality =
89879036
.takeover = raid5_takeover,
89889037
.change_consistency_policy = raid5_change_consistency_policy,
89899038
.prepare_suspend = raid5_prepare_suspend,
9039+
.bitmap_sector = raid5_bitmap_sector,
89909040
};
89919041

89929042
static struct md_personality raid4_personality =
@@ -9013,6 +9063,7 @@ static struct md_personality raid4_personality =
90139063
.takeover = raid4_takeover,
90149064
.change_consistency_policy = raid5_change_consistency_policy,
90159065
.prepare_suspend = raid5_prepare_suspend,
9066+
.bitmap_sector = raid5_bitmap_sector,
90169067
};
90179068

90189069
static int __init raid5_init(void)

0 commit comments

Comments
 (0)