aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r--drivers/md/raid1.c68
1 files changed, 20 insertions, 48 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3febfc8391fb..f50958ded9f0 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -81,14 +81,7 @@ static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
81#define raid1_log(md, fmt, args...) \ 81#define raid1_log(md, fmt, args...) \
82 do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0) 82 do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0)
83 83
84/* 84#include "raid1-10.c"
85 * 'strct resync_pages' stores actual pages used for doing the resync
86 * IO, and it is per-bio, so make .bi_private points to it.
87 */
88static inline struct resync_pages *get_resync_pages(struct bio *bio)
89{
90 return bio->bi_private;
91}
92 85
93/* 86/*
94 * for resync bio, r1bio pointer can be retrieved from the per-bio 87 * for resync bio, r1bio pointer can be retrieved from the per-bio
@@ -170,7 +163,6 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
170 resync_get_all_pages(rp); 163 resync_get_all_pages(rp);
171 } 164 }
172 165
173 rp->idx = 0;
174 rp->raid_bio = r1_bio; 166 rp->raid_bio = r1_bio;
175 bio->bi_private = rp; 167 bio->bi_private = rp;
176 } 168 }
@@ -492,10 +484,6 @@ static void raid1_end_write_request(struct bio *bio)
492 } 484 }
493 485
494 if (behind) { 486 if (behind) {
495 /* we release behind master bio when all write are done */
496 if (r1_bio->behind_master_bio == bio)
497 to_put = NULL;
498
499 if (test_bit(WriteMostly, &rdev->flags)) 487 if (test_bit(WriteMostly, &rdev->flags))
500 atomic_dec(&r1_bio->behind_remaining); 488 atomic_dec(&r1_bio->behind_remaining);
501 489
@@ -802,8 +790,7 @@ static void flush_bio_list(struct r1conf *conf, struct bio *bio)
802 bio->bi_next = NULL; 790 bio->bi_next = NULL;
803 bio->bi_bdev = rdev->bdev; 791 bio->bi_bdev = rdev->bdev;
804 if (test_bit(Faulty, &rdev->flags)) { 792 if (test_bit(Faulty, &rdev->flags)) {
805 bio->bi_status = BLK_STS_IOERR; 793 bio_io_error(bio);
806 bio_endio(bio);
807 } else if (unlikely((bio_op(bio) == REQ_OP_DISCARD) && 794 } else if (unlikely((bio_op(bio) == REQ_OP_DISCARD) &&
808 !blk_queue_discard(bdev_get_queue(bio->bi_bdev)))) 795 !blk_queue_discard(bdev_get_queue(bio->bi_bdev))))
809 /* Just ignore it */ 796 /* Just ignore it */
@@ -1088,7 +1075,7 @@ static void unfreeze_array(struct r1conf *conf)
1088 wake_up(&conf->wait_barrier); 1075 wake_up(&conf->wait_barrier);
1089} 1076}
1090 1077
1091static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio, 1078static void alloc_behind_master_bio(struct r1bio *r1_bio,
1092 struct bio *bio) 1079 struct bio *bio)
1093{ 1080{
1094 int size = bio->bi_iter.bi_size; 1081 int size = bio->bi_iter.bi_size;
@@ -1098,11 +1085,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio,
1098 1085
1099 behind_bio = bio_alloc_mddev(GFP_NOIO, vcnt, r1_bio->mddev); 1086 behind_bio = bio_alloc_mddev(GFP_NOIO, vcnt, r1_bio->mddev);
1100 if (!behind_bio) 1087 if (!behind_bio)
1101 goto fail; 1088 return;
1102 1089
1103 /* discard op, we don't support writezero/writesame yet */ 1090 /* discard op, we don't support writezero/writesame yet */
1104 if (!bio_has_data(bio)) 1091 if (!bio_has_data(bio)) {
1092 behind_bio->bi_iter.bi_size = size;
1105 goto skip_copy; 1093 goto skip_copy;
1094 }
1106 1095
1107 while (i < vcnt && size) { 1096 while (i < vcnt && size) {
1108 struct page *page; 1097 struct page *page;
@@ -1123,14 +1112,13 @@ skip_copy:
1123 r1_bio->behind_master_bio = behind_bio;; 1112 r1_bio->behind_master_bio = behind_bio;;
1124 set_bit(R1BIO_BehindIO, &r1_bio->state); 1113 set_bit(R1BIO_BehindIO, &r1_bio->state);
1125 1114
1126 return behind_bio; 1115 return;
1127 1116
1128free_pages: 1117free_pages:
1129 pr_debug("%dB behind alloc failed, doing sync I/O\n", 1118 pr_debug("%dB behind alloc failed, doing sync I/O\n",
1130 bio->bi_iter.bi_size); 1119 bio->bi_iter.bi_size);
1131 bio_free_pages(behind_bio); 1120 bio_free_pages(behind_bio);
1132fail: 1121 bio_put(behind_bio);
1133 return behind_bio;
1134} 1122}
1135 1123
1136struct raid1_plug_cb { 1124struct raid1_plug_cb {
@@ -1483,7 +1471,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
1483 (atomic_read(&bitmap->behind_writes) 1471 (atomic_read(&bitmap->behind_writes)
1484 < mddev->bitmap_info.max_write_behind) && 1472 < mddev->bitmap_info.max_write_behind) &&
1485 !waitqueue_active(&bitmap->behind_wait)) { 1473 !waitqueue_active(&bitmap->behind_wait)) {
1486 mbio = alloc_behind_master_bio(r1_bio, bio); 1474 alloc_behind_master_bio(r1_bio, bio);
1487 } 1475 }
1488 1476
1489 bitmap_startwrite(bitmap, r1_bio->sector, 1477 bitmap_startwrite(bitmap, r1_bio->sector,
@@ -1493,14 +1481,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
1493 first_clone = 0; 1481 first_clone = 0;
1494 } 1482 }
1495 1483
1496 if (!mbio) { 1484 if (r1_bio->behind_master_bio)
1497 if (r1_bio->behind_master_bio) 1485 mbio = bio_clone_fast(r1_bio->behind_master_bio,
1498 mbio = bio_clone_fast(r1_bio->behind_master_bio, 1486 GFP_NOIO, mddev->bio_set);
1499 GFP_NOIO, 1487 else
1500 mddev->bio_set); 1488 mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
1501 else
1502 mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
1503 }
1504 1489
1505 if (r1_bio->behind_master_bio) { 1490 if (r1_bio->behind_master_bio) {
1506 if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags)) 1491 if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
@@ -2086,10 +2071,7 @@ static void process_checks(struct r1bio *r1_bio)
2086 /* Fix variable parts of all bios */ 2071 /* Fix variable parts of all bios */
2087 vcnt = (r1_bio->sectors + PAGE_SIZE / 512 - 1) >> (PAGE_SHIFT - 9); 2072 vcnt = (r1_bio->sectors + PAGE_SIZE / 512 - 1) >> (PAGE_SHIFT - 9);
2088 for (i = 0; i < conf->raid_disks * 2; i++) { 2073 for (i = 0; i < conf->raid_disks * 2; i++) {
2089 int j;
2090 int size;
2091 blk_status_t status; 2074 blk_status_t status;
2092 struct bio_vec *bi;
2093 struct bio *b = r1_bio->bios[i]; 2075 struct bio *b = r1_bio->bios[i];
2094 struct resync_pages *rp = get_resync_pages(b); 2076 struct resync_pages *rp = get_resync_pages(b);
2095 if (b->bi_end_io != end_sync_read) 2077 if (b->bi_end_io != end_sync_read)
@@ -2098,8 +2080,6 @@ static void process_checks(struct r1bio *r1_bio)
2098 status = b->bi_status; 2080 status = b->bi_status;
2099 bio_reset(b); 2081 bio_reset(b);
2100 b->bi_status = status; 2082 b->bi_status = status;
2101 b->bi_vcnt = vcnt;
2102 b->bi_iter.bi_size = r1_bio->sectors << 9;
2103 b->bi_iter.bi_sector = r1_bio->sector + 2083 b->bi_iter.bi_sector = r1_bio->sector +
2104 conf->mirrors[i].rdev->data_offset; 2084 conf->mirrors[i].rdev->data_offset;
2105 b->bi_bdev = conf->mirrors[i].rdev->bdev; 2085 b->bi_bdev = conf->mirrors[i].rdev->bdev;
@@ -2107,15 +2087,8 @@ static void process_checks(struct r1bio *r1_bio)
2107 rp->raid_bio = r1_bio; 2087 rp->raid_bio = r1_bio;
2108 b->bi_private = rp; 2088 b->bi_private = rp;
2109 2089
2110 size = b->bi_iter.bi_size; 2090 /* initialize bvec table again */
2111 bio_for_each_segment_all(bi, b, j) { 2091 md_bio_reset_resync_pages(b, rp, r1_bio->sectors << 9);
2112 bi->bv_offset = 0;
2113 if (size > PAGE_SIZE)
2114 bi->bv_len = PAGE_SIZE;
2115 else
2116 bi->bv_len = size;
2117 size -= PAGE_SIZE;
2118 }
2119 } 2092 }
2120 for (primary = 0; primary < conf->raid_disks * 2; primary++) 2093 for (primary = 0; primary < conf->raid_disks * 2; primary++)
2121 if (r1_bio->bios[primary]->bi_end_io == end_sync_read && 2094 if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
@@ -2366,8 +2339,6 @@ static int narrow_write_error(struct r1bio *r1_bio, int i)
2366 wbio = bio_clone_fast(r1_bio->behind_master_bio, 2339 wbio = bio_clone_fast(r1_bio->behind_master_bio,
2367 GFP_NOIO, 2340 GFP_NOIO,
2368 mddev->bio_set); 2341 mddev->bio_set);
2369 /* We really need a _all clone */
2370 wbio->bi_iter = (struct bvec_iter){ 0 };
2371 } else { 2342 } else {
2372 wbio = bio_clone_fast(r1_bio->master_bio, GFP_NOIO, 2343 wbio = bio_clone_fast(r1_bio->master_bio, GFP_NOIO,
2373 mddev->bio_set); 2344 mddev->bio_set);
@@ -2619,6 +2590,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
2619 int good_sectors = RESYNC_SECTORS; 2590 int good_sectors = RESYNC_SECTORS;
2620 int min_bad = 0; /* number of sectors that are bad in all devices */ 2591 int min_bad = 0; /* number of sectors that are bad in all devices */
2621 int idx = sector_to_idx(sector_nr); 2592 int idx = sector_to_idx(sector_nr);
2593 int page_idx = 0;
2622 2594
2623 if (!conf->r1buf_pool) 2595 if (!conf->r1buf_pool)
2624 if (init_resync(conf)) 2596 if (init_resync(conf))
@@ -2846,7 +2818,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
2846 bio = r1_bio->bios[i]; 2818 bio = r1_bio->bios[i];
2847 rp = get_resync_pages(bio); 2819 rp = get_resync_pages(bio);
2848 if (bio->bi_end_io) { 2820 if (bio->bi_end_io) {
2849 page = resync_fetch_page(rp, rp->idx++); 2821 page = resync_fetch_page(rp, page_idx);
2850 2822
2851 /* 2823 /*
2852 * won't fail because the vec table is big 2824 * won't fail because the vec table is big
@@ -2858,7 +2830,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
2858 nr_sectors += len>>9; 2830 nr_sectors += len>>9;
2859 sector_nr += len>>9; 2831 sector_nr += len>>9;
2860 sync_blocks -= (len>>9); 2832 sync_blocks -= (len>>9);
2861 } while (get_resync_pages(r1_bio->bios[disk]->bi_private)->idx < RESYNC_PAGES); 2833 } while (++page_idx < RESYNC_PAGES);
2862 2834
2863 r1_bio->sectors = nr_sectors; 2835 r1_bio->sectors = nr_sectors;
2864 2836