Skip to content

Commit 5ec6ca1

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid1-10: factor out a helper to add bio to plug
The code in raid1 and raid10 is identical, prepare to limit the number of plugged bios. Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0104446 commit 5ec6ca1

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

drivers/md/raid1-10.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,19 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
110110
size -= len;
111111
} while (idx++ < RESYNC_PAGES && size > 0);
112112
}
113+
114+
static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
115+
blk_plug_cb_fn unplug)
116+
{
117+
struct raid1_plug_cb *plug = NULL;
118+
struct blk_plug_cb *cb = blk_check_plugged(unplug, mddev,
119+
sizeof(*plug));
120+
121+
if (!cb)
122+
return false;
123+
124+
plug = container_of(cb, struct raid1_plug_cb, cb);
125+
bio_list_add(&plug->pending, bio);
126+
127+
return true;
128+
}

drivers/md/raid1.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,6 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
13461346
struct bitmap *bitmap = mddev->bitmap;
13471347
unsigned long flags;
13481348
struct md_rdev *blocked_rdev;
1349-
struct blk_plug_cb *cb;
1350-
struct raid1_plug_cb *plug = NULL;
13511349
int first_clone;
13521350
int max_sectors;
13531351
bool write_behind = false;
@@ -1576,15 +1574,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
15761574
r1_bio->sector);
15771575
/* flush_pending_writes() needs access to the rdev so...*/
15781576
mbio->bi_bdev = (void *)rdev;
1579-
1580-
cb = blk_check_plugged(raid1_unplug, mddev, sizeof(*plug));
1581-
if (cb)
1582-
plug = container_of(cb, struct raid1_plug_cb, cb);
1583-
else
1584-
plug = NULL;
1585-
if (plug) {
1586-
bio_list_add(&plug->pending, mbio);
1587-
} else {
1577+
if (!raid1_add_bio_to_plug(mddev, mbio, raid1_unplug)) {
15881578
spin_lock_irqsave(&conf->device_lock, flags);
15891579
bio_list_add(&conf->pending_bio_list, mbio);
15901580
spin_unlock_irqrestore(&conf->device_lock, flags);

drivers/md/raid10.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,8 +1295,6 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
12951295
const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
12961296
const blk_opf_t do_fua = bio->bi_opf & REQ_FUA;
12971297
unsigned long flags;
1298-
struct blk_plug_cb *cb;
1299-
struct raid1_plug_cb *plug = NULL;
13001298
struct r10conf *conf = mddev->private;
13011299
struct md_rdev *rdev;
13021300
int devnum = r10_bio->devs[n_copy].devnum;
@@ -1336,14 +1334,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
13361334

13371335
atomic_inc(&r10_bio->remaining);
13381336

1339-
cb = blk_check_plugged(raid10_unplug, mddev, sizeof(*plug));
1340-
if (cb)
1341-
plug = container_of(cb, struct raid1_plug_cb, cb);
1342-
else
1343-
plug = NULL;
1344-
if (plug) {
1345-
bio_list_add(&plug->pending, mbio);
1346-
} else {
1337+
if (!raid1_add_bio_to_plug(mddev, mbio, raid10_unplug)) {
13471338
spin_lock_irqsave(&conf->device_lock, flags);
13481339
bio_list_add(&conf->pending_bio_list, mbio);
13491340
spin_unlock_irqrestore(&conf->device_lock, flags);

0 commit comments

Comments
 (0)