Skip to content

Commit f4d22ac

Browse files
committed
Merge tag 'md-6.16-20250530' of https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux into block-6.16
Pull MD fixes from Yu: "- fix REQ_RAHEAD and REQ_NOWAIT IO err handling for raid1/10 - fix max_write_behind setting for dm-raid - some minor cleanups" * tag 'md-6.16-20250530' of https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux: md/md-bitmap: remove parameter slot from bitmap_create() md/md-bitmap: cleanup bitmap_ops->startwrite() md/dm-raid: remove max_write_behind setting limit md/md-bitmap: fix dm-raid max_write_behind setting md/raid1,raid10: don't handle IO error for REQ_RAHEAD and REQ_NOWAIT
2 parents 39d86db + 01bf468 commit f4d22ac

File tree

7 files changed

+60
-52
lines changed

7 files changed

+60
-52
lines changed

drivers/md/dm-raid.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
13561356
return -EINVAL;
13571357
}
13581358

1359-
/*
1360-
* In device-mapper, we specify things in sectors, but
1361-
* MD records this value in kB
1362-
*/
1363-
if (value < 0 || value / 2 > COUNTER_MAX) {
1359+
if (value < 0) {
13641360
rs->ti->error = "Max write-behind limit out of range";
13651361
return -EINVAL;
13661362
}

drivers/md/md-bitmap.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,19 @@
105105
*
106106
*/
107107

108+
typedef __u16 bitmap_counter_t;
109+
108110
#define PAGE_BITS (PAGE_SIZE << 3)
109111
#define PAGE_BIT_SHIFT (PAGE_SHIFT + 3)
110112

113+
#define COUNTER_BITS 16
114+
#define COUNTER_BIT_SHIFT 4
115+
#define COUNTER_BYTE_SHIFT (COUNTER_BIT_SHIFT - 3)
116+
117+
#define NEEDED_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 1)))
118+
#define RESYNC_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 2)))
119+
#define COUNTER_MAX ((bitmap_counter_t) RESYNC_MASK - 1)
120+
111121
#define NEEDED(x) (((bitmap_counter_t) x) & NEEDED_MASK)
112122
#define RESYNC(x) (((bitmap_counter_t) x) & RESYNC_MASK)
113123
#define COUNTER(x) (((bitmap_counter_t) x) & COUNTER_MAX)
@@ -789,7 +799,7 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap)
789799
* is a good choice? We choose COUNTER_MAX / 2 arbitrarily.
790800
*/
791801
write_behind = bitmap->mddev->bitmap_info.max_write_behind;
792-
if (write_behind > COUNTER_MAX)
802+
if (write_behind > COUNTER_MAX / 2)
793803
write_behind = COUNTER_MAX / 2;
794804
sb->write_behind = cpu_to_le32(write_behind);
795805
bitmap->mddev->bitmap_info.max_write_behind = write_behind;
@@ -1672,13 +1682,13 @@ __acquires(bitmap->lock)
16721682
&(bitmap->bp[page].map[pageoff]);
16731683
}
16741684

1675-
static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
1676-
unsigned long sectors)
1685+
static void bitmap_start_write(struct mddev *mddev, sector_t offset,
1686+
unsigned long sectors)
16771687
{
16781688
struct bitmap *bitmap = mddev->bitmap;
16791689

16801690
if (!bitmap)
1681-
return 0;
1691+
return;
16821692

16831693
while (sectors) {
16841694
sector_t blocks;
@@ -1688,7 +1698,7 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
16881698
bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 1);
16891699
if (!bmc) {
16901700
spin_unlock_irq(&bitmap->counts.lock);
1691-
return 0;
1701+
return;
16921702
}
16931703

16941704
if (unlikely(COUNTER(*bmc) == COUNTER_MAX)) {
@@ -1724,11 +1734,10 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
17241734
else
17251735
sectors = 0;
17261736
}
1727-
return 0;
17281737
}
17291738

1730-
static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
1731-
unsigned long sectors)
1739+
static void bitmap_end_write(struct mddev *mddev, sector_t offset,
1740+
unsigned long sectors)
17321741
{
17331742
struct bitmap *bitmap = mddev->bitmap;
17341743

@@ -2205,9 +2214,9 @@ static struct bitmap *__bitmap_create(struct mddev *mddev, int slot)
22052214
return ERR_PTR(err);
22062215
}
22072216

2208-
static int bitmap_create(struct mddev *mddev, int slot)
2217+
static int bitmap_create(struct mddev *mddev)
22092218
{
2210-
struct bitmap *bitmap = __bitmap_create(mddev, slot);
2219+
struct bitmap *bitmap = __bitmap_create(mddev, -1);
22112220

22122221
if (IS_ERR(bitmap))
22132222
return PTR_ERR(bitmap);
@@ -2670,7 +2679,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
26702679
}
26712680

26722681
mddev->bitmap_info.offset = offset;
2673-
rv = bitmap_create(mddev, -1);
2682+
rv = bitmap_create(mddev);
26742683
if (rv)
26752684
goto out;
26762685

@@ -3003,8 +3012,8 @@ static struct bitmap_operations bitmap_ops = {
30033012
.end_behind_write = bitmap_end_behind_write,
30043013
.wait_behind_writes = bitmap_wait_behind_writes,
30053014

3006-
.startwrite = bitmap_startwrite,
3007-
.endwrite = bitmap_endwrite,
3015+
.start_write = bitmap_start_write,
3016+
.end_write = bitmap_end_write,
30083017
.start_sync = bitmap_start_sync,
30093018
.end_sync = bitmap_end_sync,
30103019
.cond_end_sync = bitmap_cond_end_sync,

drivers/md/md-bitmap.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99

1010
#define BITMAP_MAGIC 0x6d746962
1111

12-
typedef __u16 bitmap_counter_t;
13-
#define COUNTER_BITS 16
14-
#define COUNTER_BIT_SHIFT 4
15-
#define COUNTER_BYTE_SHIFT (COUNTER_BIT_SHIFT - 3)
16-
17-
#define NEEDED_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 1)))
18-
#define RESYNC_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 2)))
19-
#define COUNTER_MAX ((bitmap_counter_t) RESYNC_MASK - 1)
20-
2112
/* use these for bitmap->flags and bitmap->sb->state bit-fields */
2213
enum bitmap_state {
2314
BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */
@@ -72,7 +63,7 @@ struct md_bitmap_stats {
7263

7364
struct bitmap_operations {
7465
bool (*enabled)(struct mddev *mddev);
75-
int (*create)(struct mddev *mddev, int slot);
66+
int (*create)(struct mddev *mddev);
7667
int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize,
7768
bool init);
7869

@@ -89,10 +80,10 @@ struct bitmap_operations {
8980
void (*end_behind_write)(struct mddev *mddev);
9081
void (*wait_behind_writes)(struct mddev *mddev);
9182

92-
int (*startwrite)(struct mddev *mddev, sector_t offset,
83+
void (*start_write)(struct mddev *mddev, sector_t offset,
84+
unsigned long sectors);
85+
void (*end_write)(struct mddev *mddev, sector_t offset,
9386
unsigned long sectors);
94-
void (*endwrite)(struct mddev *mddev, sector_t offset,
95-
unsigned long sectors);
9687
bool (*start_sync)(struct mddev *mddev, sector_t offset,
9788
sector_t *blocks, bool degraded);
9889
void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);

drivers/md/md.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6225,7 +6225,7 @@ int md_run(struct mddev *mddev)
62256225
}
62266226
if (err == 0 && pers->sync_request &&
62276227
(mddev->bitmap_info.file || mddev->bitmap_info.offset)) {
6228-
err = mddev->bitmap_ops->create(mddev, -1);
6228+
err = mddev->bitmap_ops->create(mddev);
62296229
if (err)
62306230
pr_warn("%s: failed to create bitmap (%d)\n",
62316231
mdname(mddev), err);
@@ -7285,7 +7285,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
72857285
err = 0;
72867286
if (mddev->pers) {
72877287
if (fd >= 0) {
7288-
err = mddev->bitmap_ops->create(mddev, -1);
7288+
err = mddev->bitmap_ops->create(mddev);
72897289
if (!err)
72907290
err = mddev->bitmap_ops->load(mddev);
72917291

@@ -7601,7 +7601,7 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
76017601
mddev->bitmap_info.default_offset;
76027602
mddev->bitmap_info.space =
76037603
mddev->bitmap_info.default_space;
7604-
rv = mddev->bitmap_ops->create(mddev, -1);
7604+
rv = mddev->bitmap_ops->create(mddev);
76057605
if (!rv)
76067606
rv = mddev->bitmap_ops->load(mddev);
76077607

@@ -8799,14 +8799,14 @@ static void md_bitmap_start(struct mddev *mddev,
87998799
mddev->pers->bitmap_sector(mddev, &md_io_clone->offset,
88008800
&md_io_clone->sectors);
88018801

8802-
mddev->bitmap_ops->startwrite(mddev, md_io_clone->offset,
8803-
md_io_clone->sectors);
8802+
mddev->bitmap_ops->start_write(mddev, md_io_clone->offset,
8803+
md_io_clone->sectors);
88048804
}
88058805

88068806
static void md_bitmap_end(struct mddev *mddev, struct md_io_clone *md_io_clone)
88078807
{
8808-
mddev->bitmap_ops->endwrite(mddev, md_io_clone->offset,
8809-
md_io_clone->sectors);
8808+
mddev->bitmap_ops->end_write(mddev, md_io_clone->offset,
8809+
md_io_clone->sectors);
88108810
}
88118811

88128812
static void md_end_clone_io(struct bio *bio)

drivers/md/raid1-10.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ static inline bool raid1_should_read_first(struct mddev *mddev,
293293

294294
return false;
295295
}
296+
297+
/*
298+
* bio with REQ_RAHEAD or REQ_NOWAIT can fail at anytime, before such IO is
299+
* submitted to the underlying disks, hence don't record badblocks or retry
300+
* in this case.
301+
*/
302+
static inline bool raid1_should_handle_error(struct bio *bio)
303+
{
304+
return !(bio->bi_opf & (REQ_RAHEAD | REQ_NOWAIT));
305+
}

drivers/md/raid1.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,16 @@ static void raid1_end_read_request(struct bio *bio)
373373
*/
374374
update_head_pos(r1_bio->read_disk, r1_bio);
375375

376-
if (uptodate)
376+
if (uptodate) {
377377
set_bit(R1BIO_Uptodate, &r1_bio->state);
378-
else if (test_bit(FailFast, &rdev->flags) &&
379-
test_bit(R1BIO_FailFast, &r1_bio->state))
378+
} else if (test_bit(FailFast, &rdev->flags) &&
379+
test_bit(R1BIO_FailFast, &r1_bio->state)) {
380380
/* This was a fail-fast read so we definitely
381381
* want to retry */
382382
;
383-
else {
383+
} else if (!raid1_should_handle_error(bio)) {
384+
uptodate = 1;
385+
} else {
384386
/* If all other devices have failed, we want to return
385387
* the error upwards rather than fail the last device.
386388
* Here we redefine "uptodate" to mean "Don't want to retry"
@@ -451,16 +453,15 @@ static void raid1_end_write_request(struct bio *bio)
451453
struct bio *to_put = NULL;
452454
int mirror = find_bio_disk(r1_bio, bio);
453455
struct md_rdev *rdev = conf->mirrors[mirror].rdev;
454-
bool discard_error;
455456
sector_t lo = r1_bio->sector;
456457
sector_t hi = r1_bio->sector + r1_bio->sectors;
457-
458-
discard_error = bio->bi_status && bio_op(bio) == REQ_OP_DISCARD;
458+
bool ignore_error = !raid1_should_handle_error(bio) ||
459+
(bio->bi_status && bio_op(bio) == REQ_OP_DISCARD);
459460

460461
/*
461462
* 'one mirror IO has finished' event handler:
462463
*/
463-
if (bio->bi_status && !discard_error) {
464+
if (bio->bi_status && !ignore_error) {
464465
set_bit(WriteErrorSeen, &rdev->flags);
465466
if (!test_and_set_bit(WantReplacement, &rdev->flags))
466467
set_bit(MD_RECOVERY_NEEDED, &
@@ -511,7 +512,7 @@ static void raid1_end_write_request(struct bio *bio)
511512

512513
/* Maybe we can clear some bad blocks. */
513514
if (rdev_has_badblock(rdev, r1_bio->sector, r1_bio->sectors) &&
514-
!discard_error) {
515+
!ignore_error) {
515516
r1_bio->bios[mirror] = IO_MADE_GOOD;
516517
set_bit(R1BIO_MadeGood, &r1_bio->state);
517518
}

drivers/md/raid10.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ static void raid10_end_read_request(struct bio *bio)
399399
* wait for the 'master' bio.
400400
*/
401401
set_bit(R10BIO_Uptodate, &r10_bio->state);
402+
} else if (!raid1_should_handle_error(bio)) {
403+
uptodate = 1;
402404
} else {
403405
/* If all other devices that store this block have
404406
* failed, we want to return the error upwards rather
@@ -456,9 +458,8 @@ static void raid10_end_write_request(struct bio *bio)
456458
int slot, repl;
457459
struct md_rdev *rdev = NULL;
458460
struct bio *to_put = NULL;
459-
bool discard_error;
460-
461-
discard_error = bio->bi_status && bio_op(bio) == REQ_OP_DISCARD;
461+
bool ignore_error = !raid1_should_handle_error(bio) ||
462+
(bio->bi_status && bio_op(bio) == REQ_OP_DISCARD);
462463

463464
dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl);
464465

@@ -472,7 +473,7 @@ static void raid10_end_write_request(struct bio *bio)
472473
/*
473474
* this branch is our 'one mirror IO has finished' event handler:
474475
*/
475-
if (bio->bi_status && !discard_error) {
476+
if (bio->bi_status && !ignore_error) {
476477
if (repl)
477478
/* Never record new bad blocks to replacement,
478479
* just fail it.
@@ -527,7 +528,7 @@ static void raid10_end_write_request(struct bio *bio)
527528
/* Maybe we can clear some bad blocks. */
528529
if (rdev_has_badblock(rdev, r10_bio->devs[slot].addr,
529530
r10_bio->sectors) &&
530-
!discard_error) {
531+
!ignore_error) {
531532
bio_put(bio);
532533
if (repl)
533534
r10_bio->devs[slot].repl_bio = IO_MADE_GOOD;

0 commit comments

Comments
 (0)