@@ -81,14 +81,7 @@ static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
81
81
#define raid1_log (md , fmt , args ...) \
82
82
do { if ((md)->queue) blk_add_trace_msg((md)->queue, "raid1 " fmt, ##args); } while (0)
83
83
84
- /*
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
- */
88
- static inline struct resync_pages * get_resync_pages (struct bio * bio )
89
- {
90
- return bio -> bi_private ;
91
- }
84
+ #include "raid1-10.c"
92
85
93
86
/*
94
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
163
resync_get_all_pages (rp );
171
164
}
172
165
173
- rp -> idx = 0 ;
174
166
rp -> raid_bio = r1_bio ;
175
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
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
487
if (test_bit (WriteMostly , & rdev -> flags ))
500
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
790
bio -> bi_next = NULL ;
803
791
bio -> bi_bdev = rdev -> bdev ;
804
792
if (test_bit (Faulty , & rdev -> flags )) {
805
- bio -> bi_status = BLK_STS_IOERR ;
806
- bio_endio (bio );
793
+ bio_io_error (bio );
807
794
} else if (unlikely ((bio_op (bio ) == REQ_OP_DISCARD ) &&
808
795
!blk_queue_discard (bdev_get_queue (bio -> bi_bdev ))))
809
796
/* Just ignore it */
@@ -1088,7 +1075,7 @@ static void unfreeze_array(struct r1conf *conf)
1088
1075
wake_up (& conf -> wait_barrier );
1089
1076
}
1090
1077
1091
- static struct bio * alloc_behind_master_bio (struct r1bio * r1_bio ,
1078
+ static void alloc_behind_master_bio (struct r1bio * r1_bio ,
1092
1079
struct bio * bio )
1093
1080
{
1094
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
1086
behind_bio = bio_alloc_mddev (GFP_NOIO , vcnt , r1_bio -> mddev );
1100
1087
if (!behind_bio )
1101
- goto fail ;
1088
+ return ;
1102
1089
1103
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
1093
goto skip_copy ;
1094
+ }
1106
1095
1107
1096
while (i < vcnt && size ) {
1108
1097
struct page * page ;
@@ -1123,14 +1112,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio,
1123
1112
r1_bio -> behind_master_bio = behind_bio ;;
1124
1113
set_bit (R1BIO_BehindIO , & r1_bio -> state );
1125
1114
1126
- return behind_bio ;
1115
+ return ;
1127
1116
1128
1117
free_pages :
1129
1118
pr_debug ("%dB behind alloc failed, doing sync I/O\n" ,
1130
1119
bio -> bi_iter .bi_size );
1131
1120
bio_free_pages (behind_bio );
1132
- fail :
1133
- return behind_bio ;
1121
+ bio_put (behind_bio );
1134
1122
}
1135
1123
1136
1124
struct raid1_plug_cb {
@@ -1483,7 +1471,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
1483
1471
(atomic_read (& bitmap -> behind_writes )
1484
1472
< mddev -> bitmap_info .max_write_behind ) &&
1485
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
1477
bitmap_startwrite (bitmap , r1_bio -> sector ,
@@ -1493,14 +1481,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
1493
1481
first_clone = 0 ;
1494
1482
}
1495
1483
1496
- if (!mbio ) {
1497
- if (r1_bio -> behind_master_bio )
1498
- mbio = bio_clone_fast (r1_bio -> behind_master_bio ,
1499
- GFP_NOIO ,
1500
- mddev -> bio_set );
1501
- else
1502
- mbio = bio_clone_fast (bio , GFP_NOIO , mddev -> bio_set );
1503
- }
1484
+ if (r1_bio -> behind_master_bio )
1485
+ mbio = bio_clone_fast (r1_bio -> behind_master_bio ,
1486
+ GFP_NOIO , mddev -> bio_set );
1487
+ else
1488
+ mbio = bio_clone_fast (bio , GFP_NOIO , mddev -> bio_set );
1504
1489
1505
1490
if (r1_bio -> behind_master_bio ) {
1506
1491
if (test_bit (WriteMostly , & conf -> mirrors [i ].rdev -> flags ))
@@ -2086,10 +2071,7 @@ static void process_checks(struct r1bio *r1_bio)
2086
2071
/* Fix variable parts of all bios */
2087
2072
vcnt = (r1_bio -> sectors + PAGE_SIZE / 512 - 1 ) >> (PAGE_SHIFT - 9 );
2088
2073
for (i = 0 ; i < conf -> raid_disks * 2 ; i ++ ) {
2089
- int j ;
2090
- int size ;
2091
2074
blk_status_t status ;
2092
- struct bio_vec * bi ;
2093
2075
struct bio * b = r1_bio -> bios [i ];
2094
2076
struct resync_pages * rp = get_resync_pages (b );
2095
2077
if (b -> bi_end_io != end_sync_read )
@@ -2098,24 +2080,15 @@ static void process_checks(struct r1bio *r1_bio)
2098
2080
status = b -> bi_status ;
2099
2081
bio_reset (b );
2100
2082
b -> bi_status = status ;
2101
- b -> bi_vcnt = vcnt ;
2102
- b -> bi_iter .bi_size = r1_bio -> sectors << 9 ;
2103
2083
b -> bi_iter .bi_sector = r1_bio -> sector +
2104
2084
conf -> mirrors [i ].rdev -> data_offset ;
2105
2085
b -> bi_bdev = conf -> mirrors [i ].rdev -> bdev ;
2106
2086
b -> bi_end_io = end_sync_read ;
2107
2087
rp -> raid_bio = r1_bio ;
2108
2088
b -> bi_private = rp ;
2109
2089
2110
- size = b -> bi_iter .bi_size ;
2111
- bio_for_each_segment_all (bi , b , j ) {
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
- }
2090
+ /* initialize bvec table again */
2091
+ md_bio_reset_resync_pages (b , rp , r1_bio -> sectors << 9 );
2119
2092
}
2120
2093
for (primary = 0 ; primary < conf -> raid_disks * 2 ; primary ++ )
2121
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
2339
wbio = bio_clone_fast (r1_bio -> behind_master_bio ,
2367
2340
GFP_NOIO ,
2368
2341
mddev -> bio_set );
2369
- /* We really need a _all clone */
2370
- wbio -> bi_iter = (struct bvec_iter ){ 0 };
2371
2342
} else {
2372
2343
wbio = bio_clone_fast (r1_bio -> master_bio , GFP_NOIO ,
2373
2344
mddev -> bio_set );
@@ -2619,6 +2590,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
2619
2590
int good_sectors = RESYNC_SECTORS ;
2620
2591
int min_bad = 0 ; /* number of sectors that are bad in all devices */
2621
2592
int idx = sector_to_idx (sector_nr );
2593
+ int page_idx = 0 ;
2622
2594
2623
2595
if (!conf -> r1buf_pool )
2624
2596
if (init_resync (conf ))
@@ -2846,7 +2818,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
2846
2818
bio = r1_bio -> bios [i ];
2847
2819
rp = get_resync_pages (bio );
2848
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
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
2830
nr_sectors += len >>9 ;
2859
2831
sector_nr += len >>9 ;
2860
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
2835
r1_bio -> sectors = nr_sectors ;
2864
2836
0 commit comments