diff options
Diffstat (limited to 'drivers/md/raid5.c')
-rw-r--r-- | drivers/md/raid5.c | 205 |
1 files changed, 112 insertions, 93 deletions
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 04348d76bb30..259f519814ca 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
@@ -99,34 +99,40 @@ static inline struct bio *r5_next_bio(struct bio *bio, sector_t sector) | |||
99 | * We maintain a biased count of active stripes in the bottom 16 bits of | 99 | * We maintain a biased count of active stripes in the bottom 16 bits of |
100 | * bi_phys_segments, and a count of processed stripes in the upper 16 bits | 100 | * bi_phys_segments, and a count of processed stripes in the upper 16 bits |
101 | */ | 101 | */ |
102 | static inline int raid5_bi_phys_segments(struct bio *bio) | 102 | static inline int raid5_bi_processed_stripes(struct bio *bio) |
103 | { | 103 | { |
104 | return bio->bi_phys_segments & 0xffff; | 104 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
105 | return (atomic_read(segments) >> 16) & 0xffff; | ||
105 | } | 106 | } |
106 | 107 | ||
107 | static inline int raid5_bi_hw_segments(struct bio *bio) | 108 | static inline int raid5_dec_bi_active_stripes(struct bio *bio) |
108 | { | 109 | { |
109 | return (bio->bi_phys_segments >> 16) & 0xffff; | 110 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
111 | return atomic_sub_return(1, segments) & 0xffff; | ||
110 | } | 112 | } |
111 | 113 | ||
112 | static inline int raid5_dec_bi_phys_segments(struct bio *bio) | 114 | static inline void raid5_inc_bi_active_stripes(struct bio *bio) |
113 | { | 115 | { |
114 | --bio->bi_phys_segments; | 116 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
115 | return raid5_bi_phys_segments(bio); | 117 | atomic_inc(segments); |
116 | } | 118 | } |
117 | 119 | ||
118 | static inline int raid5_dec_bi_hw_segments(struct bio *bio) | 120 | static inline void raid5_set_bi_processed_stripes(struct bio *bio, |
121 | unsigned int cnt) | ||
119 | { | 122 | { |
120 | unsigned short val = raid5_bi_hw_segments(bio); | 123 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
124 | int old, new; | ||
121 | 125 | ||
122 | --val; | 126 | do { |
123 | bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio); | 127 | old = atomic_read(segments); |
124 | return val; | 128 | new = (old & 0xffff) | (cnt << 16); |
129 | } while (atomic_cmpxchg(segments, old, new) != old); | ||
125 | } | 130 | } |
126 | 131 | ||
127 | static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt) | 132 | static inline void raid5_set_bi_stripes(struct bio *bio, unsigned int cnt) |
128 | { | 133 | { |
129 | bio->bi_phys_segments = raid5_bi_phys_segments(bio) | (cnt << 16); | 134 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
135 | atomic_set(segments, cnt); | ||
130 | } | 136 | } |
131 | 137 | ||
132 | /* Find first data disk in a raid6 stripe */ | 138 | /* Find first data disk in a raid6 stripe */ |
@@ -190,49 +196,56 @@ static int stripe_operations_active(struct stripe_head *sh) | |||
190 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); | 196 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
191 | } | 197 | } |
192 | 198 | ||
193 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) | 199 | static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh) |
194 | { | 200 | { |
195 | if (atomic_dec_and_test(&sh->count)) { | 201 | BUG_ON(!list_empty(&sh->lru)); |
196 | BUG_ON(!list_empty(&sh->lru)); | 202 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
197 | BUG_ON(atomic_read(&conf->active_stripes)==0); | 203 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
198 | if (test_bit(STRIPE_HANDLE, &sh->state)) { | 204 | if (test_bit(STRIPE_DELAYED, &sh->state) && |
199 | if (test_bit(STRIPE_DELAYED, &sh->state) && | 205 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
200 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) | 206 | list_add_tail(&sh->lru, &conf->delayed_list); |
201 | list_add_tail(&sh->lru, &conf->delayed_list); | 207 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
202 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && | 208 | sh->bm_seq - conf->seq_write > 0) |
203 | sh->bm_seq - conf->seq_write > 0) | 209 | list_add_tail(&sh->lru, &conf->bitmap_list); |
204 | list_add_tail(&sh->lru, &conf->bitmap_list); | 210 | else { |
205 | else { | 211 | clear_bit(STRIPE_DELAYED, &sh->state); |
206 | clear_bit(STRIPE_DELAYED, &sh->state); | 212 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
207 | clear_bit(STRIPE_BIT_DELAY, &sh->state); | 213 | list_add_tail(&sh->lru, &conf->handle_list); |
208 | list_add_tail(&sh->lru, &conf->handle_list); | 214 | } |
209 | } | 215 | md_wakeup_thread(conf->mddev->thread); |
210 | md_wakeup_thread(conf->mddev->thread); | 216 | } else { |
211 | } else { | 217 | BUG_ON(stripe_operations_active(sh)); |
212 | BUG_ON(stripe_operations_active(sh)); | 218 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
213 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) | 219 | if (atomic_dec_return(&conf->preread_active_stripes) |
214 | if (atomic_dec_return(&conf->preread_active_stripes) | 220 | < IO_THRESHOLD) |
215 | < IO_THRESHOLD) | 221 | md_wakeup_thread(conf->mddev->thread); |
216 | md_wakeup_thread(conf->mddev->thread); | 222 | atomic_dec(&conf->active_stripes); |
217 | atomic_dec(&conf->active_stripes); | 223 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
218 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { | 224 | list_add_tail(&sh->lru, &conf->inactive_list); |
219 | list_add_tail(&sh->lru, &conf->inactive_list); | 225 | wake_up(&conf->wait_for_stripe); |
220 | wake_up(&conf->wait_for_stripe); | 226 | if (conf->retry_read_aligned) |
221 | if (conf->retry_read_aligned) | 227 | md_wakeup_thread(conf->mddev->thread); |
222 | md_wakeup_thread(conf->mddev->thread); | ||
223 | } | ||
224 | } | 228 | } |
225 | } | 229 | } |
226 | } | 230 | } |
227 | 231 | ||
232 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) | ||
233 | { | ||
234 | if (atomic_dec_and_test(&sh->count)) | ||
235 | do_release_stripe(conf, sh); | ||
236 | } | ||
237 | |||
228 | static void release_stripe(struct stripe_head *sh) | 238 | static void release_stripe(struct stripe_head *sh) |
229 | { | 239 | { |
230 | struct r5conf *conf = sh->raid_conf; | 240 | struct r5conf *conf = sh->raid_conf; |
231 | unsigned long flags; | 241 | unsigned long flags; |
232 | 242 | ||
233 | spin_lock_irqsave(&conf->device_lock, flags); | 243 | local_irq_save(flags); |
234 | __release_stripe(conf, sh); | 244 | if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) { |
235 | spin_unlock_irqrestore(&conf->device_lock, flags); | 245 | do_release_stripe(conf, sh); |
246 | spin_unlock(&conf->device_lock); | ||
247 | } | ||
248 | local_irq_restore(flags); | ||
236 | } | 249 | } |
237 | 250 | ||
238 | static inline void remove_hash(struct stripe_head *sh) | 251 | static inline void remove_hash(struct stripe_head *sh) |
@@ -640,6 +653,9 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) | |||
640 | else | 653 | else |
641 | bi->bi_sector = (sh->sector | 654 | bi->bi_sector = (sh->sector |
642 | + rdev->data_offset); | 655 | + rdev->data_offset); |
656 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) | ||
657 | bi->bi_rw |= REQ_FLUSH; | ||
658 | |||
643 | bi->bi_flags = 1 << BIO_UPTODATE; | 659 | bi->bi_flags = 1 << BIO_UPTODATE; |
644 | bi->bi_idx = 0; | 660 | bi->bi_idx = 0; |
645 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; | 661 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
@@ -749,14 +765,12 @@ static void ops_complete_biofill(void *stripe_head_ref) | |||
749 | { | 765 | { |
750 | struct stripe_head *sh = stripe_head_ref; | 766 | struct stripe_head *sh = stripe_head_ref; |
751 | struct bio *return_bi = NULL; | 767 | struct bio *return_bi = NULL; |
752 | struct r5conf *conf = sh->raid_conf; | ||
753 | int i; | 768 | int i; |
754 | 769 | ||
755 | pr_debug("%s: stripe %llu\n", __func__, | 770 | pr_debug("%s: stripe %llu\n", __func__, |
756 | (unsigned long long)sh->sector); | 771 | (unsigned long long)sh->sector); |
757 | 772 | ||
758 | /* clear completed biofills */ | 773 | /* clear completed biofills */ |
759 | spin_lock_irq(&conf->device_lock); | ||
760 | for (i = sh->disks; i--; ) { | 774 | for (i = sh->disks; i--; ) { |
761 | struct r5dev *dev = &sh->dev[i]; | 775 | struct r5dev *dev = &sh->dev[i]; |
762 | 776 | ||
@@ -774,7 +788,7 @@ static void ops_complete_biofill(void *stripe_head_ref) | |||
774 | while (rbi && rbi->bi_sector < | 788 | while (rbi && rbi->bi_sector < |
775 | dev->sector + STRIPE_SECTORS) { | 789 | dev->sector + STRIPE_SECTORS) { |
776 | rbi2 = r5_next_bio(rbi, dev->sector); | 790 | rbi2 = r5_next_bio(rbi, dev->sector); |
777 | if (!raid5_dec_bi_phys_segments(rbi)) { | 791 | if (!raid5_dec_bi_active_stripes(rbi)) { |
778 | rbi->bi_next = return_bi; | 792 | rbi->bi_next = return_bi; |
779 | return_bi = rbi; | 793 | return_bi = rbi; |
780 | } | 794 | } |
@@ -782,7 +796,6 @@ static void ops_complete_biofill(void *stripe_head_ref) | |||
782 | } | 796 | } |
783 | } | 797 | } |
784 | } | 798 | } |
785 | spin_unlock_irq(&conf->device_lock); | ||
786 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); | 799 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
787 | 800 | ||
788 | return_io(return_bi); | 801 | return_io(return_bi); |
@@ -794,7 +807,6 @@ static void ops_complete_biofill(void *stripe_head_ref) | |||
794 | static void ops_run_biofill(struct stripe_head *sh) | 807 | static void ops_run_biofill(struct stripe_head *sh) |
795 | { | 808 | { |
796 | struct dma_async_tx_descriptor *tx = NULL; | 809 | struct dma_async_tx_descriptor *tx = NULL; |
797 | struct r5conf *conf = sh->raid_conf; | ||
798 | struct async_submit_ctl submit; | 810 | struct async_submit_ctl submit; |
799 | int i; | 811 | int i; |
800 | 812 | ||
@@ -805,10 +817,10 @@ static void ops_run_biofill(struct stripe_head *sh) | |||
805 | struct r5dev *dev = &sh->dev[i]; | 817 | struct r5dev *dev = &sh->dev[i]; |
806 | if (test_bit(R5_Wantfill, &dev->flags)) { | 818 | if (test_bit(R5_Wantfill, &dev->flags)) { |
807 | struct bio *rbi; | 819 | struct bio *rbi; |
808 | spin_lock_irq(&conf->device_lock); | 820 | spin_lock_irq(&sh->stripe_lock); |
809 | dev->read = rbi = dev->toread; | 821 | dev->read = rbi = dev->toread; |
810 | dev->toread = NULL; | 822 | dev->toread = NULL; |
811 | spin_unlock_irq(&conf->device_lock); | 823 | spin_unlock_irq(&sh->stripe_lock); |
812 | while (rbi && rbi->bi_sector < | 824 | while (rbi && rbi->bi_sector < |
813 | dev->sector + STRIPE_SECTORS) { | 825 | dev->sector + STRIPE_SECTORS) { |
814 | tx = async_copy_data(0, rbi, dev->page, | 826 | tx = async_copy_data(0, rbi, dev->page, |
@@ -1144,12 +1156,12 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx) | |||
1144 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { | 1156 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
1145 | struct bio *wbi; | 1157 | struct bio *wbi; |
1146 | 1158 | ||
1147 | spin_lock_irq(&sh->raid_conf->device_lock); | 1159 | spin_lock_irq(&sh->stripe_lock); |
1148 | chosen = dev->towrite; | 1160 | chosen = dev->towrite; |
1149 | dev->towrite = NULL; | 1161 | dev->towrite = NULL; |
1150 | BUG_ON(dev->written); | 1162 | BUG_ON(dev->written); |
1151 | wbi = dev->written = chosen; | 1163 | wbi = dev->written = chosen; |
1152 | spin_unlock_irq(&sh->raid_conf->device_lock); | 1164 | spin_unlock_irq(&sh->stripe_lock); |
1153 | 1165 | ||
1154 | while (wbi && wbi->bi_sector < | 1166 | while (wbi && wbi->bi_sector < |
1155 | dev->sector + STRIPE_SECTORS) { | 1167 | dev->sector + STRIPE_SECTORS) { |
@@ -1454,6 +1466,8 @@ static int grow_one_stripe(struct r5conf *conf) | |||
1454 | init_waitqueue_head(&sh->ops.wait_for_ops); | 1466 | init_waitqueue_head(&sh->ops.wait_for_ops); |
1455 | #endif | 1467 | #endif |
1456 | 1468 | ||
1469 | spin_lock_init(&sh->stripe_lock); | ||
1470 | |||
1457 | if (grow_buffers(sh)) { | 1471 | if (grow_buffers(sh)) { |
1458 | shrink_buffers(sh); | 1472 | shrink_buffers(sh); |
1459 | kmem_cache_free(conf->slab_cache, sh); | 1473 | kmem_cache_free(conf->slab_cache, sh); |
@@ -1739,7 +1753,9 @@ static void raid5_end_read_request(struct bio * bi, int error) | |||
1739 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); | 1753 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
1740 | clear_bit(R5_ReadError, &sh->dev[i].flags); | 1754 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
1741 | clear_bit(R5_ReWrite, &sh->dev[i].flags); | 1755 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
1742 | } | 1756 | } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
1757 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); | ||
1758 | |||
1743 | if (atomic_read(&rdev->read_errors)) | 1759 | if (atomic_read(&rdev->read_errors)) |
1744 | atomic_set(&rdev->read_errors, 0); | 1760 | atomic_set(&rdev->read_errors, 0); |
1745 | } else { | 1761 | } else { |
@@ -1784,7 +1800,11 @@ static void raid5_end_read_request(struct bio * bi, int error) | |||
1784 | else | 1800 | else |
1785 | retry = 1; | 1801 | retry = 1; |
1786 | if (retry) | 1802 | if (retry) |
1787 | set_bit(R5_ReadError, &sh->dev[i].flags); | 1803 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { |
1804 | set_bit(R5_ReadError, &sh->dev[i].flags); | ||
1805 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); | ||
1806 | } else | ||
1807 | set_bit(R5_ReadNoMerge, &sh->dev[i].flags); | ||
1788 | else { | 1808 | else { |
1789 | clear_bit(R5_ReadError, &sh->dev[i].flags); | 1809 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
1790 | clear_bit(R5_ReWrite, &sh->dev[i].flags); | 1810 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
@@ -2340,11 +2360,18 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in | |||
2340 | (unsigned long long)bi->bi_sector, | 2360 | (unsigned long long)bi->bi_sector, |
2341 | (unsigned long long)sh->sector); | 2361 | (unsigned long long)sh->sector); |
2342 | 2362 | ||
2343 | 2363 | /* | |
2344 | spin_lock_irq(&conf->device_lock); | 2364 | * If several bio share a stripe. The bio bi_phys_segments acts as a |
2365 | * reference count to avoid race. The reference count should already be | ||
2366 | * increased before this function is called (for example, in | ||
2367 | * make_request()), so other bio sharing this stripe will not free the | ||
2368 | * stripe. If a stripe is owned by one stripe, the stripe lock will | ||
2369 | * protect it. | ||
2370 | */ | ||
2371 | spin_lock_irq(&sh->stripe_lock); | ||
2345 | if (forwrite) { | 2372 | if (forwrite) { |
2346 | bip = &sh->dev[dd_idx].towrite; | 2373 | bip = &sh->dev[dd_idx].towrite; |
2347 | if (*bip == NULL && sh->dev[dd_idx].written == NULL) | 2374 | if (*bip == NULL) |
2348 | firstwrite = 1; | 2375 | firstwrite = 1; |
2349 | } else | 2376 | } else |
2350 | bip = &sh->dev[dd_idx].toread; | 2377 | bip = &sh->dev[dd_idx].toread; |
@@ -2360,7 +2387,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in | |||
2360 | if (*bip) | 2387 | if (*bip) |
2361 | bi->bi_next = *bip; | 2388 | bi->bi_next = *bip; |
2362 | *bip = bi; | 2389 | *bip = bi; |
2363 | bi->bi_phys_segments++; | 2390 | raid5_inc_bi_active_stripes(bi); |
2364 | 2391 | ||
2365 | if (forwrite) { | 2392 | if (forwrite) { |
2366 | /* check if page is covered */ | 2393 | /* check if page is covered */ |
@@ -2375,7 +2402,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in | |||
2375 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) | 2402 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
2376 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); | 2403 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
2377 | } | 2404 | } |
2378 | spin_unlock_irq(&conf->device_lock); | 2405 | spin_unlock_irq(&sh->stripe_lock); |
2379 | 2406 | ||
2380 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", | 2407 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
2381 | (unsigned long long)(*bip)->bi_sector, | 2408 | (unsigned long long)(*bip)->bi_sector, |
@@ -2391,7 +2418,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in | |||
2391 | 2418 | ||
2392 | overlap: | 2419 | overlap: |
2393 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); | 2420 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
2394 | spin_unlock_irq(&conf->device_lock); | 2421 | spin_unlock_irq(&sh->stripe_lock); |
2395 | return 0; | 2422 | return 0; |
2396 | } | 2423 | } |
2397 | 2424 | ||
@@ -2441,10 +2468,11 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, | |||
2441 | rdev_dec_pending(rdev, conf->mddev); | 2468 | rdev_dec_pending(rdev, conf->mddev); |
2442 | } | 2469 | } |
2443 | } | 2470 | } |
2444 | spin_lock_irq(&conf->device_lock); | 2471 | spin_lock_irq(&sh->stripe_lock); |
2445 | /* fail all writes first */ | 2472 | /* fail all writes first */ |
2446 | bi = sh->dev[i].towrite; | 2473 | bi = sh->dev[i].towrite; |
2447 | sh->dev[i].towrite = NULL; | 2474 | sh->dev[i].towrite = NULL; |
2475 | spin_unlock_irq(&sh->stripe_lock); | ||
2448 | if (bi) { | 2476 | if (bi) { |
2449 | s->to_write--; | 2477 | s->to_write--; |
2450 | bitmap_end = 1; | 2478 | bitmap_end = 1; |
@@ -2457,13 +2485,17 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, | |||
2457 | sh->dev[i].sector + STRIPE_SECTORS) { | 2485 | sh->dev[i].sector + STRIPE_SECTORS) { |
2458 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); | 2486 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
2459 | clear_bit(BIO_UPTODATE, &bi->bi_flags); | 2487 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
2460 | if (!raid5_dec_bi_phys_segments(bi)) { | 2488 | if (!raid5_dec_bi_active_stripes(bi)) { |
2461 | md_write_end(conf->mddev); | 2489 | md_write_end(conf->mddev); |
2462 | bi->bi_next = *return_bi; | 2490 | bi->bi_next = *return_bi; |
2463 | *return_bi = bi; | 2491 | *return_bi = bi; |
2464 | } | 2492 | } |
2465 | bi = nextbi; | 2493 | bi = nextbi; |
2466 | } | 2494 | } |
2495 | if (bitmap_end) | ||
2496 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, | ||
2497 | STRIPE_SECTORS, 0, 0); | ||
2498 | bitmap_end = 0; | ||
2467 | /* and fail all 'written' */ | 2499 | /* and fail all 'written' */ |
2468 | bi = sh->dev[i].written; | 2500 | bi = sh->dev[i].written; |
2469 | sh->dev[i].written = NULL; | 2501 | sh->dev[i].written = NULL; |
@@ -2472,7 +2504,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, | |||
2472 | sh->dev[i].sector + STRIPE_SECTORS) { | 2504 | sh->dev[i].sector + STRIPE_SECTORS) { |
2473 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); | 2505 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
2474 | clear_bit(BIO_UPTODATE, &bi->bi_flags); | 2506 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
2475 | if (!raid5_dec_bi_phys_segments(bi)) { | 2507 | if (!raid5_dec_bi_active_stripes(bi)) { |
2476 | md_write_end(conf->mddev); | 2508 | md_write_end(conf->mddev); |
2477 | bi->bi_next = *return_bi; | 2509 | bi->bi_next = *return_bi; |
2478 | *return_bi = bi; | 2510 | *return_bi = bi; |
@@ -2496,14 +2528,13 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, | |||
2496 | struct bio *nextbi = | 2528 | struct bio *nextbi = |
2497 | r5_next_bio(bi, sh->dev[i].sector); | 2529 | r5_next_bio(bi, sh->dev[i].sector); |
2498 | clear_bit(BIO_UPTODATE, &bi->bi_flags); | 2530 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
2499 | if (!raid5_dec_bi_phys_segments(bi)) { | 2531 | if (!raid5_dec_bi_active_stripes(bi)) { |
2500 | bi->bi_next = *return_bi; | 2532 | bi->bi_next = *return_bi; |
2501 | *return_bi = bi; | 2533 | *return_bi = bi; |
2502 | } | 2534 | } |
2503 | bi = nextbi; | 2535 | bi = nextbi; |
2504 | } | 2536 | } |
2505 | } | 2537 | } |
2506 | spin_unlock_irq(&conf->device_lock); | ||
2507 | if (bitmap_end) | 2538 | if (bitmap_end) |
2508 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, | 2539 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
2509 | STRIPE_SECTORS, 0, 0); | 2540 | STRIPE_SECTORS, 0, 0); |
@@ -2707,30 +2738,23 @@ static void handle_stripe_clean_event(struct r5conf *conf, | |||
2707 | test_bit(R5_UPTODATE, &dev->flags)) { | 2738 | test_bit(R5_UPTODATE, &dev->flags)) { |
2708 | /* We can return any write requests */ | 2739 | /* We can return any write requests */ |
2709 | struct bio *wbi, *wbi2; | 2740 | struct bio *wbi, *wbi2; |
2710 | int bitmap_end = 0; | ||
2711 | pr_debug("Return write for disc %d\n", i); | 2741 | pr_debug("Return write for disc %d\n", i); |
2712 | spin_lock_irq(&conf->device_lock); | ||
2713 | wbi = dev->written; | 2742 | wbi = dev->written; |
2714 | dev->written = NULL; | 2743 | dev->written = NULL; |
2715 | while (wbi && wbi->bi_sector < | 2744 | while (wbi && wbi->bi_sector < |
2716 | dev->sector + STRIPE_SECTORS) { | 2745 | dev->sector + STRIPE_SECTORS) { |
2717 | wbi2 = r5_next_bio(wbi, dev->sector); | 2746 | wbi2 = r5_next_bio(wbi, dev->sector); |
2718 | if (!raid5_dec_bi_phys_segments(wbi)) { | 2747 | if (!raid5_dec_bi_active_stripes(wbi)) { |
2719 | md_write_end(conf->mddev); | 2748 | md_write_end(conf->mddev); |
2720 | wbi->bi_next = *return_bi; | 2749 | wbi->bi_next = *return_bi; |
2721 | *return_bi = wbi; | 2750 | *return_bi = wbi; |
2722 | } | 2751 | } |
2723 | wbi = wbi2; | 2752 | wbi = wbi2; |
2724 | } | 2753 | } |
2725 | if (dev->towrite == NULL) | 2754 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
2726 | bitmap_end = 1; | 2755 | STRIPE_SECTORS, |
2727 | spin_unlock_irq(&conf->device_lock); | ||
2728 | if (bitmap_end) | ||
2729 | bitmap_endwrite(conf->mddev->bitmap, | ||
2730 | sh->sector, | ||
2731 | STRIPE_SECTORS, | ||
2732 | !test_bit(STRIPE_DEGRADED, &sh->state), | 2756 | !test_bit(STRIPE_DEGRADED, &sh->state), |
2733 | 0); | 2757 | 0); |
2734 | } | 2758 | } |
2735 | } | 2759 | } |
2736 | 2760 | ||
@@ -3182,7 +3206,6 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) | |||
3182 | 3206 | ||
3183 | /* Now to look around and see what can be done */ | 3207 | /* Now to look around and see what can be done */ |
3184 | rcu_read_lock(); | 3208 | rcu_read_lock(); |
3185 | spin_lock_irq(&conf->device_lock); | ||
3186 | for (i=disks; i--; ) { | 3209 | for (i=disks; i--; ) { |
3187 | struct md_rdev *rdev; | 3210 | struct md_rdev *rdev; |
3188 | sector_t first_bad; | 3211 | sector_t first_bad; |
@@ -3328,7 +3351,6 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) | |||
3328 | do_recovery = 1; | 3351 | do_recovery = 1; |
3329 | } | 3352 | } |
3330 | } | 3353 | } |
3331 | spin_unlock_irq(&conf->device_lock); | ||
3332 | if (test_bit(STRIPE_SYNCING, &sh->state)) { | 3354 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
3333 | /* If there is a failed device being replaced, | 3355 | /* If there is a failed device being replaced, |
3334 | * we must be recovering. | 3356 | * we must be recovering. |
@@ -3791,7 +3813,7 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf) | |||
3791 | * this sets the active strip count to 1 and the processed | 3813 | * this sets the active strip count to 1 and the processed |
3792 | * strip count to zero (upper 8 bits) | 3814 | * strip count to zero (upper 8 bits) |
3793 | */ | 3815 | */ |
3794 | bi->bi_phys_segments = 1; /* biased count of active stripes */ | 3816 | raid5_set_bi_stripes(bi, 1); /* biased count of active stripes */ |
3795 | } | 3817 | } |
3796 | 3818 | ||
3797 | return bi; | 3819 | return bi; |
@@ -4113,7 +4135,7 @@ static void make_request(struct mddev *mddev, struct bio * bi) | |||
4113 | finish_wait(&conf->wait_for_overlap, &w); | 4135 | finish_wait(&conf->wait_for_overlap, &w); |
4114 | set_bit(STRIPE_HANDLE, &sh->state); | 4136 | set_bit(STRIPE_HANDLE, &sh->state); |
4115 | clear_bit(STRIPE_DELAYED, &sh->state); | 4137 | clear_bit(STRIPE_DELAYED, &sh->state); |
4116 | if ((bi->bi_rw & REQ_SYNC) && | 4138 | if ((bi->bi_rw & REQ_NOIDLE) && |
4117 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) | 4139 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
4118 | atomic_inc(&conf->preread_active_stripes); | 4140 | atomic_inc(&conf->preread_active_stripes); |
4119 | mddev_check_plugged(mddev); | 4141 | mddev_check_plugged(mddev); |
@@ -4126,9 +4148,7 @@ static void make_request(struct mddev *mddev, struct bio * bi) | |||
4126 | } | 4148 | } |
4127 | } | 4149 | } |
4128 | 4150 | ||
4129 | spin_lock_irq(&conf->device_lock); | 4151 | remaining = raid5_dec_bi_active_stripes(bi); |
4130 | remaining = raid5_dec_bi_phys_segments(bi); | ||
4131 | spin_unlock_irq(&conf->device_lock); | ||
4132 | if (remaining == 0) { | 4152 | if (remaining == 0) { |
4133 | 4153 | ||
4134 | if ( rw == WRITE ) | 4154 | if ( rw == WRITE ) |
@@ -4484,7 +4504,7 @@ static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio) | |||
4484 | sector += STRIPE_SECTORS, | 4504 | sector += STRIPE_SECTORS, |
4485 | scnt++) { | 4505 | scnt++) { |
4486 | 4506 | ||
4487 | if (scnt < raid5_bi_hw_segments(raid_bio)) | 4507 | if (scnt < raid5_bi_processed_stripes(raid_bio)) |
4488 | /* already done this stripe */ | 4508 | /* already done this stripe */ |
4489 | continue; | 4509 | continue; |
4490 | 4510 | ||
@@ -4492,25 +4512,24 @@ static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio) | |||
4492 | 4512 | ||
4493 | if (!sh) { | 4513 | if (!sh) { |
4494 | /* failed to get a stripe - must wait */ | 4514 | /* failed to get a stripe - must wait */ |
4495 | raid5_set_bi_hw_segments(raid_bio, scnt); | 4515 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
4496 | conf->retry_read_aligned = raid_bio; | 4516 | conf->retry_read_aligned = raid_bio; |
4497 | return handled; | 4517 | return handled; |
4498 | } | 4518 | } |
4499 | 4519 | ||
4500 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { | 4520 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
4501 | release_stripe(sh); | 4521 | release_stripe(sh); |
4502 | raid5_set_bi_hw_segments(raid_bio, scnt); | 4522 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
4503 | conf->retry_read_aligned = raid_bio; | 4523 | conf->retry_read_aligned = raid_bio; |
4504 | return handled; | 4524 | return handled; |
4505 | } | 4525 | } |
4506 | 4526 | ||
4527 | set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); | ||
4507 | handle_stripe(sh); | 4528 | handle_stripe(sh); |
4508 | release_stripe(sh); | 4529 | release_stripe(sh); |
4509 | handled++; | 4530 | handled++; |
4510 | } | 4531 | } |
4511 | spin_lock_irq(&conf->device_lock); | 4532 | remaining = raid5_dec_bi_active_stripes(raid_bio); |
4512 | remaining = raid5_dec_bi_phys_segments(raid_bio); | ||
4513 | spin_unlock_irq(&conf->device_lock); | ||
4514 | if (remaining == 0) | 4533 | if (remaining == 0) |
4515 | bio_endio(raid_bio, 0); | 4534 | bio_endio(raid_bio, 0); |
4516 | if (atomic_dec_and_test(&conf->active_aligned_reads)) | 4535 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |