Skip to content

Commit fb0eb5d

Browse files
Ming Leishligit
authored andcommitted
md: raid1/raid10: initialize bvec table via bio_add_page()
We will support multipage bvec soon, so initialize bvec table using the standardy way instead of writing the talbe directly. Otherwise it won't work any more once multipage bvec is enabled. Acked-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Shaohua Li <shli@fb.com>
1 parent 022e510 commit fb0eb5d

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

drivers/md/raid1-10.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* generally called after bio_reset() for reseting bvec */
2+
static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp,
3+
int size)
4+
{
5+
int idx = 0;
6+
7+
/* initialize bvec table again */
8+
do {
9+
struct page *page = resync_fetch_page(rp, idx);
10+
int len = min_t(int, size, PAGE_SIZE);
11+
12+
/*
13+
* won't fail because the vec table is big
14+
* enough to hold all these pages
15+
*/
16+
bio_add_page(bio, page, len, 0);
17+
size -= len;
18+
} while (idx++ < RESYNC_PAGES && size > 0);
19+
}

drivers/md/raid1.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
8181
#define raid1_log(md, fmt, args...) \
8282
do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0)
8383

84+
#include "raid1-10.c"
85+
8486
/*
8587
* 'strct resync_pages' stores actual pages used for doing the resync
8688
* IO, and it is per-bio, so make .bi_private points to it.
@@ -2085,10 +2087,7 @@ static void process_checks(struct r1bio *r1_bio)
20852087
/* Fix variable parts of all bios */
20862088
vcnt = (r1_bio->sectors + PAGE_SIZE / 512 - 1) >> (PAGE_SHIFT - 9);
20872089
for (i = 0; i < conf->raid_disks * 2; i++) {
2088-
int j;
2089-
int size;
20902090
blk_status_t status;
2091-
struct bio_vec *bi;
20922091
struct bio *b = r1_bio->bios[i];
20932092
struct resync_pages *rp = get_resync_pages(b);
20942093
if (b->bi_end_io != end_sync_read)
@@ -2097,24 +2096,15 @@ static void process_checks(struct r1bio *r1_bio)
20972096
status = b->bi_status;
20982097
bio_reset(b);
20992098
b->bi_status = status;
2100-
b->bi_vcnt = vcnt;
2101-
b->bi_iter.bi_size = r1_bio->sectors << 9;
21022099
b->bi_iter.bi_sector = r1_bio->sector +
21032100
conf->mirrors[i].rdev->data_offset;
21042101
b->bi_bdev = conf->mirrors[i].rdev->bdev;
21052102
b->bi_end_io = end_sync_read;
21062103
rp->raid_bio = r1_bio;
21072104
b->bi_private = rp;
21082105

2109-
size = b->bi_iter.bi_size;
2110-
bio_for_each_segment_all(bi, b, j) {
2111-
bi->bv_offset = 0;
2112-
if (size > PAGE_SIZE)
2113-
bi->bv_len = PAGE_SIZE;
2114-
else
2115-
bi->bv_len = size;
2116-
size -= PAGE_SIZE;
2117-
}
2106+
/* initialize bvec table again */
2107+
md_bio_reset_resync_pages(b, rp, r1_bio->sectors << 9);
21182108
}
21192109
for (primary = 0; primary < conf->raid_disks * 2; primary++)
21202110
if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&

drivers/md/raid10.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ static void end_reshape(struct r10conf *conf);
110110
#define raid10_log(md, fmt, args...) \
111111
do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid10 " fmt, ##args); } while (0)
112112

113+
#include "raid1-10.c"
114+
113115
/*
114116
* 'strct resync_pages' stores actual pages used for doing the resync
115117
* IO, and it is per-bio, so make .bi_private points to it.
@@ -2086,8 +2088,8 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
20862088
rp = get_resync_pages(tbio);
20872089
bio_reset(tbio);
20882090

2089-
tbio->bi_vcnt = vcnt;
2090-
tbio->bi_iter.bi_size = fbio->bi_iter.bi_size;
2091+
md_bio_reset_resync_pages(tbio, rp, fbio->bi_iter.bi_size);
2092+
20912093
rp->raid_bio = r10_bio;
20922094
tbio->bi_private = rp;
20932095
tbio->bi_iter.bi_sector = r10_bio->devs[i].addr;

0 commit comments

Comments
 (0)