Skip to content

Commit 8295efb

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid1-10: factor out a helper to submit normal write
There are multiple places to do the same thing, factor out a helper to prevent redundant code, and the helper will be used in following patch as well. Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5ec6ca1 commit 8295efb

File tree

3 files changed

+23
-33
lines changed

3 files changed

+23
-33
lines changed

drivers/md/raid1-10.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
111111
} while (idx++ < RESYNC_PAGES && size > 0);
112112
}
113113

114+
115+
static inline void raid1_submit_write(struct bio *bio)
116+
{
117+
struct md_rdev *rdev = (struct md_rdev *)bio->bi_bdev;
118+
119+
bio->bi_next = NULL;
120+
bio_set_dev(bio, rdev->bdev);
121+
if (test_bit(Faulty, &rdev->flags))
122+
bio_io_error(bio);
123+
else if (unlikely(bio_op(bio) == REQ_OP_DISCARD &&
124+
!bdev_max_discard_sectors(bio->bi_bdev)))
125+
/* Just ignore it */
126+
bio_endio(bio);
127+
else
128+
submit_bio_noacct(bio);
129+
}
130+
114131
static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
115132
blk_plug_cb_fn unplug)
116133
{

drivers/md/raid1.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,8 @@ static void flush_bio_list(struct r1conf *conf, struct bio *bio)
799799

800800
while (bio) { /* submit pending writes */
801801
struct bio *next = bio->bi_next;
802-
struct md_rdev *rdev = (void *)bio->bi_bdev;
803-
bio->bi_next = NULL;
804-
bio_set_dev(bio, rdev->bdev);
805-
if (test_bit(Faulty, &rdev->flags)) {
806-
bio_io_error(bio);
807-
} else if (unlikely((bio_op(bio) == REQ_OP_DISCARD) &&
808-
!bdev_max_discard_sectors(bio->bi_bdev)))
809-
/* Just ignore it */
810-
bio_endio(bio);
811-
else
812-
submit_bio_noacct(bio);
802+
803+
raid1_submit_write(bio);
813804
bio = next;
814805
cond_resched();
815806
}

drivers/md/raid10.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -917,17 +917,8 @@ static void flush_pending_writes(struct r10conf *conf)
917917

918918
while (bio) { /* submit pending writes */
919919
struct bio *next = bio->bi_next;
920-
struct md_rdev *rdev = (void*)bio->bi_bdev;
921-
bio->bi_next = NULL;
922-
bio_set_dev(bio, rdev->bdev);
923-
if (test_bit(Faulty, &rdev->flags)) {
924-
bio_io_error(bio);
925-
} else if (unlikely((bio_op(bio) == REQ_OP_DISCARD) &&
926-
!bdev_max_discard_sectors(bio->bi_bdev)))
927-
/* Just ignore it */
928-
bio_endio(bio);
929-
else
930-
submit_bio_noacct(bio);
920+
921+
raid1_submit_write(bio);
931922
bio = next;
932923
cond_resched();
933924
}
@@ -1142,17 +1133,8 @@ static void raid10_unplug(struct blk_plug_cb *cb, bool from_schedule)
11421133

11431134
while (bio) { /* submit pending writes */
11441135
struct bio *next = bio->bi_next;
1145-
struct md_rdev *rdev = (void*)bio->bi_bdev;
1146-
bio->bi_next = NULL;
1147-
bio_set_dev(bio, rdev->bdev);
1148-
if (test_bit(Faulty, &rdev->flags)) {
1149-
bio_io_error(bio);
1150-
} else if (unlikely((bio_op(bio) == REQ_OP_DISCARD) &&
1151-
!bdev_max_discard_sectors(bio->bi_bdev)))
1152-
/* Just ignore it */
1153-
bio_endio(bio);
1154-
else
1155-
submit_bio_noacct(bio);
1136+
1137+
raid1_submit_write(bio);
11561138
bio = next;
11571139
cond_resched();
11581140
}

0 commit comments

Comments
 (0)