Skip to content

Commit 3d8466b

Browse files
Christoph Hellwigliu-song-6
authored andcommitted
md/raid10: use the atomic queue limit update APIs
Build the queue limits outside the queue and apply them using queue_limits_set. To make the code more obvious also split the queue limits handling into separate helpers. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed--by: Song Liu <[email protected]> Tested-by: Song Liu <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f63f173 commit 3d8466b

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

drivers/md/raid10.c

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,10 +2106,9 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
21062106
continue;
21072107
}
21082108

2109-
if (!mddev_is_dm(mddev))
2110-
disk_stack_limits(mddev->gendisk, rdev->bdev,
2111-
rdev->data_offset << 9);
2112-
2109+
err = mddev_stack_new_rdev(mddev, rdev);
2110+
if (err)
2111+
return err;
21132112
p->head_position = 0;
21142113
p->recovery_disabled = mddev->recovery_disabled - 1;
21152114
rdev->raid_disk = mirror;
@@ -2125,10 +2124,9 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
21252124
clear_bit(In_sync, &rdev->flags);
21262125
set_bit(Replacement, &rdev->flags);
21272126
rdev->raid_disk = repl_slot;
2128-
err = 0;
2129-
if (!mddev_is_dm(mddev))
2130-
disk_stack_limits(mddev->gendisk, rdev->bdev,
2131-
rdev->data_offset << 9);
2127+
err = mddev_stack_new_rdev(mddev, rdev);
2128+
if (err)
2129+
return err;
21322130
conf->fullsync = 1;
21332131
WRITE_ONCE(p->replacement, rdev);
21342132
}
@@ -3969,14 +3967,26 @@ static struct r10conf *setup_conf(struct mddev *mddev)
39693967
return ERR_PTR(err);
39703968
}
39713969

3972-
static void raid10_set_io_opt(struct r10conf *conf)
3970+
static unsigned int raid10_nr_stripes(struct r10conf *conf)
39733971
{
3974-
int raid_disks = conf->geo.raid_disks;
3972+
unsigned int raid_disks = conf->geo.raid_disks;
3973+
3974+
if (conf->geo.raid_disks % conf->geo.near_copies)
3975+
return raid_disks;
3976+
return raid_disks / conf->geo.near_copies;
3977+
}
39753978

3976-
if (!(conf->geo.raid_disks % conf->geo.near_copies))
3977-
raid_disks /= conf->geo.near_copies;
3978-
blk_queue_io_opt(conf->mddev->queue, (conf->mddev->chunk_sectors << 9) *
3979-
raid_disks);
3979+
static int raid10_set_queue_limits(struct mddev *mddev)
3980+
{
3981+
struct r10conf *conf = mddev->private;
3982+
struct queue_limits lim;
3983+
3984+
blk_set_stacking_limits(&lim);
3985+
lim.max_write_zeroes_sectors = 0;
3986+
lim.io_min = mddev->chunk_sectors << 9;
3987+
lim.io_opt = lim.io_min * raid10_nr_stripes(conf);
3988+
mddev_stack_rdev_limits(mddev, &lim);
3989+
return queue_limits_set(mddev->queue, &lim);
39803990
}
39813991

39823992
static int raid10_run(struct mddev *mddev)
@@ -3988,6 +3998,7 @@ static int raid10_run(struct mddev *mddev)
39883998
sector_t size;
39893999
sector_t min_offset_diff = 0;
39904000
int first = 1;
4001+
int ret = -EIO;
39914002

39924003
if (mddev->private == NULL) {
39934004
conf = setup_conf(mddev);
@@ -4014,12 +4025,6 @@ static int raid10_run(struct mddev *mddev)
40144025
}
40154026
}
40164027

4017-
if (!mddev_is_dm(conf->mddev)) {
4018-
blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
4019-
blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
4020-
raid10_set_io_opt(conf);
4021-
}
4022-
40234028
rdev_for_each(rdev, mddev) {
40244029
long long diff;
40254030

@@ -4048,14 +4053,16 @@ static int raid10_run(struct mddev *mddev)
40484053
if (first || diff < min_offset_diff)
40494054
min_offset_diff = diff;
40504055

4051-
if (!mddev_is_dm(mddev))
4052-
disk_stack_limits(mddev->gendisk, rdev->bdev,
4053-
rdev->data_offset << 9);
4054-
40554056
disk->head_position = 0;
40564057
first = 0;
40574058
}
40584059

4060+
if (!mddev_is_dm(conf->mddev)) {
4061+
ret = raid10_set_queue_limits(mddev);
4062+
if (ret)
4063+
goto out_free_conf;
4064+
}
4065+
40594066
/* need to check that every block has at least one working mirror */
40604067
if (!enough(conf, -1)) {
40614068
pr_err("md/raid10:%s: not enough operational mirrors.\n",
@@ -4156,7 +4163,7 @@ static int raid10_run(struct mddev *mddev)
41564163
raid10_free_conf(conf);
41574164
mddev->private = NULL;
41584165
out:
4159-
return -EIO;
4166+
return ret;
41604167
}
41614168

41624169
static void raid10_free(struct mddev *mddev, void *priv)
@@ -4933,8 +4940,7 @@ static void end_reshape(struct r10conf *conf)
49334940
conf->reshape_safe = MaxSector;
49344941
spin_unlock_irq(&conf->device_lock);
49354942

4936-
if (!mddev_is_dm(conf->mddev))
4937-
raid10_set_io_opt(conf);
4943+
mddev_update_io_opt(conf->mddev, raid10_nr_stripes(conf));
49384944
conf->fullsync = 0;
49394945
}
49404946

0 commit comments

Comments
 (0)