Skip to content

Commit 9c89f60

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
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>
1 parent 0c984a2 commit 9c89f60

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)
@@ -8966,6 +9014,7 @@ static struct md_personality raid6_personality =
89669014
.takeover = raid6_takeover,
89679015
.change_consistency_policy = raid5_change_consistency_policy,
89689016
.prepare_suspend = raid5_prepare_suspend,
9017+
.bitmap_sector = raid5_bitmap_sector,
89699018
};
89709019
static struct md_personality raid5_personality =
89719020
{
@@ -8991,6 +9040,7 @@ static struct md_personality raid5_personality =
89919040
.takeover = raid5_takeover,
89929041
.change_consistency_policy = raid5_change_consistency_policy,
89939042
.prepare_suspend = raid5_prepare_suspend,
9043+
.bitmap_sector = raid5_bitmap_sector,
89949044
};
89959045

89969046
static struct md_personality raid4_personality =
@@ -9017,6 +9067,7 @@ static struct md_personality raid4_personality =
90179067
.takeover = raid4_takeover,
90189068
.change_consistency_policy = raid5_change_consistency_policy,
90199069
.prepare_suspend = raid5_prepare_suspend,
9070+
.bitmap_sector = raid5_bitmap_sector,
90209071
};
90219072

90229073
static int __init raid5_init(void)

0 commit comments

Comments
 (0)