Lines Matching full:sh
26 * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq
112 static inline int raid6_d0(struct stripe_head *sh) in raid6_d0() argument
114 if (sh->ddf_layout) in raid6_d0()
118 if (sh->qd_idx == sh->disks - 1) in raid6_d0()
121 return sh->qd_idx + 1; in raid6_d0()
134 static int raid6_idx_to_slot(int idx, struct stripe_head *sh, in raid6_idx_to_slot() argument
139 if (sh->ddf_layout) in raid6_idx_to_slot()
141 if (idx == sh->pd_idx) in raid6_idx_to_slot()
143 if (idx == sh->qd_idx) in raid6_idx_to_slot()
145 if (!sh->ddf_layout) in raid6_idx_to_slot()
152 static int stripe_operations_active(struct stripe_head *sh) in stripe_operations_active() argument
154 return sh->check_state || sh->reconstruct_state || in stripe_operations_active()
155 test_bit(STRIPE_BIOFILL_RUN, &sh->state) || in stripe_operations_active()
156 test_bit(STRIPE_COMPUTE_RUN, &sh->state); in stripe_operations_active()
159 static bool stripe_is_lowprio(struct stripe_head *sh) in stripe_is_lowprio() argument
161 return (test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) || in stripe_is_lowprio()
162 test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) && in stripe_is_lowprio()
163 !test_bit(STRIPE_R5C_CACHING, &sh->state); in stripe_is_lowprio()
166 static void raid5_wakeup_stripe_thread(struct stripe_head *sh) in raid5_wakeup_stripe_thread() argument
168 struct r5conf *conf = sh->raid_conf; in raid5_wakeup_stripe_thread()
171 int i, cpu = sh->cpu; in raid5_wakeup_stripe_thread()
175 sh->cpu = cpu; in raid5_wakeup_stripe_thread()
178 if (list_empty(&sh->lru)) { in raid5_wakeup_stripe_thread()
181 if (stripe_is_lowprio(sh)) in raid5_wakeup_stripe_thread()
182 list_add_tail(&sh->lru, &group->loprio_list); in raid5_wakeup_stripe_thread()
184 list_add_tail(&sh->lru, &group->handle_list); in raid5_wakeup_stripe_thread()
186 sh->group = group; in raid5_wakeup_stripe_thread()
194 group = conf->worker_groups + cpu_to_group(sh->cpu); in raid5_wakeup_stripe_thread()
198 queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); in raid5_wakeup_stripe_thread()
205 queue_work_on(sh->cpu, raid5_wq, in raid5_wakeup_stripe_thread()
212 static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, in do_release_stripe() argument
218 BUG_ON(!list_empty(&sh->lru)); in do_release_stripe()
222 for (i = sh->disks; i--; ) in do_release_stripe()
223 if (test_bit(R5_InJournal, &sh->dev[i].flags)) in do_release_stripe()
232 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) || in do_release_stripe()
234 !test_bit(STRIPE_HANDLE, &sh->state) && injournal != 0)) { in do_release_stripe()
235 if (test_bit(STRIPE_R5C_CACHING, &sh->state)) in do_release_stripe()
236 r5c_make_stripe_write_out(sh); in do_release_stripe()
237 set_bit(STRIPE_HANDLE, &sh->state); in do_release_stripe()
240 if (test_bit(STRIPE_HANDLE, &sh->state)) { in do_release_stripe()
241 if (test_bit(STRIPE_DELAYED, &sh->state) && in do_release_stripe()
242 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in do_release_stripe()
243 list_add_tail(&sh->lru, &conf->delayed_list); in do_release_stripe()
244 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && in do_release_stripe()
245 sh->bm_seq - conf->seq_write > 0) in do_release_stripe()
246 list_add_tail(&sh->lru, &conf->bitmap_list); in do_release_stripe()
248 clear_bit(STRIPE_DELAYED, &sh->state); in do_release_stripe()
249 clear_bit(STRIPE_BIT_DELAY, &sh->state); in do_release_stripe()
251 if (stripe_is_lowprio(sh)) in do_release_stripe()
252 list_add_tail(&sh->lru, in do_release_stripe()
255 list_add_tail(&sh->lru, in do_release_stripe()
258 raid5_wakeup_stripe_thread(sh); in do_release_stripe()
264 BUG_ON(stripe_operations_active(sh)); in do_release_stripe()
265 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in do_release_stripe()
270 if (!test_bit(STRIPE_EXPANDING, &sh->state)) { in do_release_stripe()
272 list_add_tail(&sh->lru, temp_inactive_list); in do_release_stripe()
274 WARN_ON(test_bit(R5_InJournal, &sh->dev[sh->pd_idx].flags)); in do_release_stripe()
276 list_add_tail(&sh->lru, temp_inactive_list); in do_release_stripe()
279 if (!test_and_set_bit(STRIPE_R5C_FULL_STRIPE, &sh->state)) in do_release_stripe()
281 if (test_and_clear_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) in do_release_stripe()
283 list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); in do_release_stripe()
291 list_add_tail(&sh->lru, &conf->r5c_partial_stripe_list); in do_release_stripe()
297 static void __release_stripe(struct r5conf *conf, struct stripe_head *sh, in __release_stripe() argument
300 if (atomic_dec_and_test(&sh->count)) in __release_stripe()
301 do_release_stripe(conf, sh, temp_inactive_list); in __release_stripe()
357 struct stripe_head *sh, *t; in release_stripe_list() local
363 llist_for_each_entry_safe(sh, t, head, release_list) { in release_stripe_list()
366 /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ in release_stripe_list()
368 clear_bit(STRIPE_ON_RELEASE_LIST, &sh->state); in release_stripe_list()
374 hash = sh->hash_lock_index; in release_stripe_list()
375 __release_stripe(conf, sh, &temp_inactive_list[hash]); in release_stripe_list()
382 void raid5_release_stripe(struct stripe_head *sh) in raid5_release_stripe() argument
384 struct r5conf *conf = sh->raid_conf; in raid5_release_stripe()
392 if (atomic_add_unless(&sh->count, -1, 1)) in raid5_release_stripe()
396 test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state)) in raid5_release_stripe()
398 wakeup = llist_add(&sh->release_list, &conf->released_stripes); in raid5_release_stripe()
404 if (atomic_dec_and_lock_irqsave(&sh->count, &conf->device_lock, flags)) { in raid5_release_stripe()
406 hash = sh->hash_lock_index; in raid5_release_stripe()
407 do_release_stripe(conf, sh, &list); in raid5_release_stripe()
413 static inline void remove_hash(struct stripe_head *sh) in remove_hash() argument
416 (unsigned long long)sh->sector); in remove_hash()
418 hlist_del_init(&sh->hash); in remove_hash()
421 static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) in insert_hash() argument
423 struct hlist_head *hp = stripe_hash(conf, sh->sector); in insert_hash()
426 (unsigned long long)sh->sector); in insert_hash()
428 hlist_add_head(&sh->hash, hp); in insert_hash()
434 struct stripe_head *sh = NULL; in get_free_stripe() local
440 sh = list_entry(first, struct stripe_head, lru); in get_free_stripe()
442 remove_hash(sh); in get_free_stripe()
444 BUG_ON(hash != sh->hash_lock_index); in get_free_stripe()
448 return sh; in get_free_stripe()
452 static void free_stripe_pages(struct stripe_head *sh) in free_stripe_pages() argument
458 if (!sh->pages) in free_stripe_pages()
461 for (i = 0; i < sh->nr_pages; i++) { in free_stripe_pages()
462 p = sh->pages[i]; in free_stripe_pages()
465 sh->pages[i] = NULL; in free_stripe_pages()
469 static int alloc_stripe_pages(struct stripe_head *sh, gfp_t gfp) in alloc_stripe_pages() argument
474 for (i = 0; i < sh->nr_pages; i++) { in alloc_stripe_pages()
476 if (sh->pages[i]) in alloc_stripe_pages()
481 free_stripe_pages(sh); in alloc_stripe_pages()
484 sh->pages[i] = p; in alloc_stripe_pages()
490 init_stripe_shared_pages(struct stripe_head *sh, struct r5conf *conf, int disks) in init_stripe_shared_pages() argument
494 if (sh->pages) in init_stripe_shared_pages()
497 /* Each of the sh->dev[i] need one conf->stripe_size */ in init_stripe_shared_pages()
501 sh->pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); in init_stripe_shared_pages()
502 if (!sh->pages) in init_stripe_shared_pages()
504 sh->nr_pages = nr_pages; in init_stripe_shared_pages()
505 sh->stripes_per_page = cnt; in init_stripe_shared_pages()
510 static void shrink_buffers(struct stripe_head *sh) in shrink_buffers() argument
513 int num = sh->raid_conf->pool_size; in shrink_buffers()
519 WARN_ON(sh->dev[i].page != sh->dev[i].orig_page); in shrink_buffers()
520 p = sh->dev[i].page; in shrink_buffers()
523 sh->dev[i].page = NULL; in shrink_buffers()
528 sh->dev[i].page = NULL; in shrink_buffers()
529 free_stripe_pages(sh); /* Free pages */ in shrink_buffers()
533 static int grow_buffers(struct stripe_head *sh, gfp_t gfp) in grow_buffers() argument
536 int num = sh->raid_conf->pool_size; in grow_buffers()
545 sh->dev[i].page = page; in grow_buffers()
546 sh->dev[i].orig_page = page; in grow_buffers()
547 sh->dev[i].offset = 0; in grow_buffers()
550 if (alloc_stripe_pages(sh, gfp)) in grow_buffers()
554 sh->dev[i].page = raid5_get_dev_page(sh, i); in grow_buffers()
555 sh->dev[i].orig_page = sh->dev[i].page; in grow_buffers()
556 sh->dev[i].offset = raid5_get_page_offset(sh, i); in grow_buffers()
563 struct stripe_head *sh);
565 static void init_stripe(struct stripe_head *sh, sector_t sector, int previous) in init_stripe() argument
567 struct r5conf *conf = sh->raid_conf; in init_stripe()
570 BUG_ON(atomic_read(&sh->count) != 0); in init_stripe()
571 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); in init_stripe()
572 BUG_ON(stripe_operations_active(sh)); in init_stripe()
573 BUG_ON(sh->batch_head); in init_stripe()
579 sh->generation = conf->generation - previous; in init_stripe()
580 sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; in init_stripe()
581 sh->sector = sector; in init_stripe()
582 stripe_set_idx(sector, conf, previous, sh); in init_stripe()
583 sh->state = 0; in init_stripe()
585 for (i = sh->disks; i--; ) { in init_stripe()
586 struct r5dev *dev = &sh->dev[i]; in init_stripe()
591 (unsigned long long)sh->sector, i, dev->toread, in init_stripe()
597 dev->sector = raid5_compute_blocknr(sh, i, previous); in init_stripe()
601 sh->overwrite_disks = 0; in init_stripe()
602 insert_hash(conf, sh); in init_stripe()
603 sh->cpu = smp_processor_id(); in init_stripe()
604 set_bit(STRIPE_BATCH_READY, &sh->state); in init_stripe()
610 struct stripe_head *sh; in __find_stripe() local
613 hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) in __find_stripe()
614 if (sh->sector == sector && sh->generation == generation) in __find_stripe()
615 return sh; in __find_stripe()
706 struct stripe_head *sh; in raid5_get_active_stripe() local
718 sh = __find_stripe(conf, sector, conf->generation - previous); in raid5_get_active_stripe()
719 if (!sh) { in raid5_get_active_stripe()
721 sh = get_free_stripe(conf, hash); in raid5_get_active_stripe()
722 if (!sh && !test_bit(R5_DID_ALLOC, in raid5_get_active_stripe()
727 if (noblock && sh == NULL) in raid5_get_active_stripe()
731 if (!sh) { in raid5_get_active_stripe()
746 init_stripe(sh, sector, previous); in raid5_get_active_stripe()
747 atomic_inc(&sh->count); in raid5_get_active_stripe()
749 } else if (!atomic_inc_not_zero(&sh->count)) { in raid5_get_active_stripe()
751 if (!atomic_read(&sh->count)) { in raid5_get_active_stripe()
752 if (!test_bit(STRIPE_HANDLE, &sh->state)) in raid5_get_active_stripe()
754 BUG_ON(list_empty(&sh->lru) && in raid5_get_active_stripe()
755 !test_bit(STRIPE_EXPANDING, &sh->state)); in raid5_get_active_stripe()
759 list_del_init(&sh->lru); in raid5_get_active_stripe()
762 if (sh->group) { in raid5_get_active_stripe()
763 sh->group->stripes_cnt--; in raid5_get_active_stripe()
764 sh->group = NULL; in raid5_get_active_stripe()
767 atomic_inc(&sh->count); in raid5_get_active_stripe()
770 } while (sh == NULL); in raid5_get_active_stripe()
773 return sh; in raid5_get_active_stripe()
776 static bool is_full_stripe_write(struct stripe_head *sh) in is_full_stripe_write() argument
778 BUG_ON(sh->overwrite_disks > (sh->disks - sh->raid_conf->max_degraded)); in is_full_stripe_write()
779 return sh->overwrite_disks == (sh->disks - sh->raid_conf->max_degraded); in is_full_stripe_write()
804 static bool stripe_can_batch(struct stripe_head *sh) in stripe_can_batch() argument
806 struct r5conf *conf = sh->raid_conf; in stripe_can_batch()
810 return test_bit(STRIPE_BATCH_READY, &sh->state) && in stripe_can_batch()
811 !test_bit(STRIPE_BITMAP_PENDING, &sh->state) && in stripe_can_batch()
812 is_full_stripe_write(sh); in stripe_can_batch()
816 static void stripe_add_to_batch_list(struct r5conf *conf, struct stripe_head *sh) in stripe_add_to_batch_list() argument
825 tmp_sec = sh->sector; in stripe_add_to_batch_list()
828 head_sector = sh->sector - RAID5_STRIPE_SECTORS(conf); in stripe_add_to_batch_list()
861 lock_two_stripes(head, sh); in stripe_add_to_batch_list()
863 if (!stripe_can_batch(head) || !stripe_can_batch(sh)) in stripe_add_to_batch_list()
866 if (sh->batch_head) in stripe_add_to_batch_list()
870 while (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) in stripe_add_to_batch_list()
872 if (head->dev[dd_idx].towrite->bi_opf != sh->dev[dd_idx].towrite->bi_opf || in stripe_add_to_batch_list()
873 bio_op(head->dev[dd_idx].towrite) != bio_op(sh->dev[dd_idx].towrite)) in stripe_add_to_batch_list()
890 sh->batch_head = head->batch_head; in stripe_add_to_batch_list()
896 list_add(&sh->batch_list, &head->batch_list); in stripe_add_to_batch_list()
900 sh->batch_head = head->batch_head; in stripe_add_to_batch_list()
902 list_add_tail(&sh->batch_list, &head->batch_list); in stripe_add_to_batch_list()
906 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in stripe_add_to_batch_list()
911 if (test_and_clear_bit(STRIPE_BIT_DELAY, &sh->state)) { in stripe_add_to_batch_list()
912 int seq = sh->bm_seq; in stripe_add_to_batch_list()
913 if (test_bit(STRIPE_BIT_DELAY, &sh->batch_head->state) && in stripe_add_to_batch_list()
914 sh->batch_head->bm_seq > seq) in stripe_add_to_batch_list()
915 seq = sh->batch_head->bm_seq; in stripe_add_to_batch_list()
916 set_bit(STRIPE_BIT_DELAY, &sh->batch_head->state); in stripe_add_to_batch_list()
917 sh->batch_head->bm_seq = seq; in stripe_add_to_batch_list()
920 atomic_inc(&sh->count); in stripe_add_to_batch_list()
922 unlock_two_stripes(head, sh); in stripe_add_to_batch_list()
930 static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) in use_new_offset() argument
940 if (sh->generation == conf->generation - 1) in use_new_offset()
1057 static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) in ops_run_io() argument
1059 struct r5conf *conf = sh->raid_conf; in ops_run_io()
1060 int i, disks = sh->disks; in ops_run_io()
1061 struct stripe_head *head_sh = sh; in ops_run_io()
1067 if (log_stripe(sh, s) == 0) in ops_run_io()
1078 sh = head_sh; in ops_run_io()
1079 if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { in ops_run_io()
1081 if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) in ops_run_io()
1083 if (test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_io()
1085 } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) in ops_run_io()
1088 &sh->dev[i].flags)) { in ops_run_io()
1093 if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) in ops_run_io()
1097 bi = &sh->dev[i].req; in ops_run_io()
1098 rbi = &sh->dev[i].rreq; /* For writing to replacement */ in ops_run_io()
1138 int bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in ops_run_io()
1172 set_bit(STRIPE_IO_STARTED, &sh->state); in ops_run_io()
1179 bi->bi_private = sh; in ops_run_io()
1182 __func__, (unsigned long long)sh->sector, in ops_run_io()
1184 atomic_inc(&sh->count); in ops_run_io()
1185 if (sh != head_sh) in ops_run_io()
1187 if (use_new_offset(conf, sh)) in ops_run_io()
1188 bi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1191 bi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1196 if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) in ops_run_io()
1197 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in ops_run_io()
1200 test_bit(R5_InJournal, &sh->dev[i].flags)) in ops_run_io()
1206 sh->dev[i].vec.bv_page = sh->dev[i].orig_page; in ops_run_io()
1208 sh->dev[i].vec.bv_page = sh->dev[i].page; in ops_run_io()
1211 bi->bi_io_vec[0].bv_offset = sh->dev[i].offset; in ops_run_io()
1213 bi->bi_write_hint = sh->dev[i].write_hint; in ops_run_io()
1215 sh->dev[i].write_hint = RWH_WRITE_LIFE_NOT_SET; in ops_run_io()
1223 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); in ops_run_io()
1228 sh->dev[i].sector); in ops_run_io()
1239 set_bit(STRIPE_IO_STARTED, &sh->state); in ops_run_io()
1245 rbi->bi_private = sh; in ops_run_io()
1249 __func__, (unsigned long long)sh->sector, in ops_run_io()
1251 atomic_inc(&sh->count); in ops_run_io()
1252 if (sh != head_sh) in ops_run_io()
1254 if (use_new_offset(conf, sh)) in ops_run_io()
1255 rbi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1258 rbi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1260 if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) in ops_run_io()
1261 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in ops_run_io()
1262 sh->dev[i].rvec.bv_page = sh->dev[i].page; in ops_run_io()
1265 rbi->bi_io_vec[0].bv_offset = sh->dev[i].offset; in ops_run_io()
1267 rbi->bi_write_hint = sh->dev[i].write_hint; in ops_run_io()
1268 sh->dev[i].write_hint = RWH_WRITE_LIFE_NOT_SET; in ops_run_io()
1278 sh->dev[i].sector); in ops_run_io()
1286 set_bit(STRIPE_DEGRADED, &sh->state); in ops_run_io()
1288 bi->bi_opf, i, (unsigned long long)sh->sector); in ops_run_io()
1289 clear_bit(R5_LOCKED, &sh->dev[i].flags); in ops_run_io()
1290 set_bit(STRIPE_HANDLE, &sh->state); in ops_run_io()
1295 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_io()
1297 if (sh != head_sh) in ops_run_io()
1308 struct stripe_head *sh, int no_skipcopy) in async_copy_data() argument
1316 struct r5conf *conf = sh->raid_conf; in async_copy_data()
1372 struct stripe_head *sh = stripe_head_ref; in ops_complete_biofill() local
1374 struct r5conf *conf = sh->raid_conf; in ops_complete_biofill()
1377 (unsigned long long)sh->sector); in ops_complete_biofill()
1380 for (i = sh->disks; i--; ) { in ops_complete_biofill()
1381 struct r5dev *dev = &sh->dev[i]; in ops_complete_biofill()
1402 clear_bit(STRIPE_BIOFILL_RUN, &sh->state); in ops_complete_biofill()
1404 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_biofill()
1405 raid5_release_stripe(sh); in ops_complete_biofill()
1408 static void ops_run_biofill(struct stripe_head *sh) in ops_run_biofill() argument
1413 struct r5conf *conf = sh->raid_conf; in ops_run_biofill()
1415 BUG_ON(sh->batch_head); in ops_run_biofill()
1417 (unsigned long long)sh->sector); in ops_run_biofill()
1419 for (i = sh->disks; i--; ) { in ops_run_biofill()
1420 struct r5dev *dev = &sh->dev[i]; in ops_run_biofill()
1423 spin_lock_irq(&sh->stripe_lock); in ops_run_biofill()
1426 spin_unlock_irq(&sh->stripe_lock); in ops_run_biofill()
1431 dev->sector, tx, sh, 0); in ops_run_biofill()
1437 atomic_inc(&sh->count); in ops_run_biofill()
1438 init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); in ops_run_biofill()
1442 static void mark_target_uptodate(struct stripe_head *sh, int target) in mark_target_uptodate() argument
1449 tgt = &sh->dev[target]; in mark_target_uptodate()
1457 struct stripe_head *sh = stripe_head_ref; in ops_complete_compute() local
1460 (unsigned long long)sh->sector); in ops_complete_compute()
1463 mark_target_uptodate(sh, sh->ops.target); in ops_complete_compute()
1464 mark_target_uptodate(sh, sh->ops.target2); in ops_complete_compute()
1466 clear_bit(STRIPE_COMPUTE_RUN, &sh->state); in ops_complete_compute()
1467 if (sh->check_state == check_state_compute_run) in ops_complete_compute()
1468 sh->check_state = check_state_compute_result; in ops_complete_compute()
1469 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_compute()
1470 raid5_release_stripe(sh); in ops_complete_compute()
1480 static addr_conv_t *to_addr_conv(struct stripe_head *sh, in to_addr_conv() argument
1483 return (void *) (to_addr_page(percpu, i) + sh->disks + 2); in to_addr_conv()
1490 to_addr_offs(struct stripe_head *sh, struct raid5_percpu *percpu) in to_addr_offs() argument
1492 return (unsigned int *) (to_addr_conv(sh, percpu, 0) + sh->disks + 2); in to_addr_offs()
1496 ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute5() argument
1498 int disks = sh->disks; in ops_run_compute5()
1500 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_compute5()
1501 int target = sh->ops.target; in ops_run_compute5()
1502 struct r5dev *tgt = &sh->dev[target]; in ops_run_compute5()
1510 BUG_ON(sh->batch_head); in ops_run_compute5()
1513 __func__, (unsigned long long)sh->sector, target); in ops_run_compute5()
1518 off_srcs[count] = sh->dev[i].offset; in ops_run_compute5()
1519 xor_srcs[count++] = sh->dev[i].page; in ops_run_compute5()
1523 atomic_inc(&sh->count); in ops_run_compute5()
1526 ops_complete_compute, sh, to_addr_conv(sh, percpu, 0)); in ops_run_compute5()
1529 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute5()
1532 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute5()
1538 * @srcs - (struct page *) array of size sh->disks
1540 * @sh - stripe_head to parse
1549 struct stripe_head *sh, in set_syndrome_sources() argument
1552 int disks = sh->disks; in set_syndrome_sources()
1553 int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); in set_syndrome_sources()
1554 int d0_idx = raid6_d0(sh); in set_syndrome_sources()
1564 int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); in set_syndrome_sources()
1565 struct r5dev *dev = &sh->dev[i]; in set_syndrome_sources()
1567 if (i == sh->qd_idx || i == sh->pd_idx || in set_syndrome_sources()
1576 srcs[slot] = sh->dev[i].orig_page; in set_syndrome_sources()
1578 srcs[slot] = sh->dev[i].page; in set_syndrome_sources()
1584 offs[slot] = sh->dev[i].offset; in set_syndrome_sources()
1593 ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute6_1() argument
1595 int disks = sh->disks; in ops_run_compute6_1()
1597 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_compute6_1()
1599 int qd_idx = sh->qd_idx; in ops_run_compute6_1()
1608 BUG_ON(sh->batch_head); in ops_run_compute6_1()
1609 if (sh->ops.target < 0) in ops_run_compute6_1()
1610 target = sh->ops.target2; in ops_run_compute6_1()
1611 else if (sh->ops.target2 < 0) in ops_run_compute6_1()
1612 target = sh->ops.target; in ops_run_compute6_1()
1618 __func__, (unsigned long long)sh->sector, target); in ops_run_compute6_1()
1620 tgt = &sh->dev[target]; in ops_run_compute6_1()
1625 atomic_inc(&sh->count); in ops_run_compute6_1()
1628 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_ALL); in ops_run_compute6_1()
1632 ops_complete_compute, sh, in ops_run_compute6_1()
1633 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_1()
1635 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute6_1()
1642 offs[count] = sh->dev[i].offset; in ops_run_compute6_1()
1643 blocks[count++] = sh->dev[i].page; in ops_run_compute6_1()
1647 NULL, ops_complete_compute, sh, in ops_run_compute6_1()
1648 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_1()
1650 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute6_1()
1657 ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute6_2() argument
1659 int i, count, disks = sh->disks; in ops_run_compute6_2()
1660 int syndrome_disks = sh->ddf_layout ? disks : disks-2; in ops_run_compute6_2()
1661 int d0_idx = raid6_d0(sh); in ops_run_compute6_2()
1663 int target = sh->ops.target; in ops_run_compute6_2()
1664 int target2 = sh->ops.target2; in ops_run_compute6_2()
1665 struct r5dev *tgt = &sh->dev[target]; in ops_run_compute6_2()
1666 struct r5dev *tgt2 = &sh->dev[target2]; in ops_run_compute6_2()
1669 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_compute6_2()
1672 BUG_ON(sh->batch_head); in ops_run_compute6_2()
1674 __func__, (unsigned long long)sh->sector, target, target2); in ops_run_compute6_2()
1689 int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); in ops_run_compute6_2()
1691 offs[slot] = sh->dev[i].offset; in ops_run_compute6_2()
1692 blocks[slot] = sh->dev[i].page; in ops_run_compute6_2()
1705 __func__, (unsigned long long)sh->sector, faila, failb); in ops_run_compute6_2()
1707 atomic_inc(&sh->count); in ops_run_compute6_2()
1714 ops_complete_compute, sh, in ops_run_compute6_2()
1715 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1717 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1723 int qd_idx = sh->qd_idx; in ops_run_compute6_2()
1735 offs[count] = sh->dev[i].offset; in ops_run_compute6_2()
1736 blocks[count++] = sh->dev[i].page; in ops_run_compute6_2()
1738 dest = sh->dev[data_target].page; in ops_run_compute6_2()
1739 dest_off = sh->dev[data_target].offset; in ops_run_compute6_2()
1743 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1745 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1748 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_ALL); in ops_run_compute6_2()
1750 ops_complete_compute, sh, in ops_run_compute6_2()
1751 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1753 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1758 ops_complete_compute, sh, in ops_run_compute6_2()
1759 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1763 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1769 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1778 struct stripe_head *sh = stripe_head_ref; in ops_complete_prexor() local
1781 (unsigned long long)sh->sector); in ops_complete_prexor()
1783 if (r5c_is_writeback(sh->raid_conf->log)) in ops_complete_prexor()
1788 r5c_release_extra_page(sh); in ops_complete_prexor()
1792 ops_run_prexor5(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_prexor5() argument
1795 int disks = sh->disks; in ops_run_prexor5()
1797 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_prexor5()
1798 int count = 0, pd_idx = sh->pd_idx, i; in ops_run_prexor5()
1802 unsigned int off_dest = off_srcs[count] = sh->dev[pd_idx].offset; in ops_run_prexor5()
1803 struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; in ops_run_prexor5()
1805 BUG_ON(sh->batch_head); in ops_run_prexor5()
1807 (unsigned long long)sh->sector); in ops_run_prexor5()
1810 struct r5dev *dev = &sh->dev[i]; in ops_run_prexor5()
1826 ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); in ops_run_prexor5()
1828 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_prexor5()
1834 ops_run_prexor6(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_prexor6() argument
1838 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_prexor6()
1843 (unsigned long long)sh->sector); in ops_run_prexor6()
1845 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_WANT_DRAIN); in ops_run_prexor6()
1848 ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); in ops_run_prexor6()
1850 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_prexor6()
1856 ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx) in ops_run_biodrain() argument
1858 struct r5conf *conf = sh->raid_conf; in ops_run_biodrain()
1859 int disks = sh->disks; in ops_run_biodrain()
1861 struct stripe_head *head_sh = sh; in ops_run_biodrain()
1864 (unsigned long long)sh->sector); in ops_run_biodrain()
1870 sh = head_sh; in ops_run_biodrain()
1875 dev = &sh->dev[i]; in ops_run_biodrain()
1881 spin_lock_irq(&sh->stripe_lock); in ops_run_biodrain()
1884 sh->overwrite_disks = 0; in ops_run_biodrain()
1887 spin_unlock_irq(&sh->stripe_lock); in ops_run_biodrain()
1901 dev->sector, tx, sh, in ops_run_biodrain()
1914 sh = list_first_entry(&sh->batch_list, in ops_run_biodrain()
1917 if (sh == head_sh) in ops_run_biodrain()
1929 struct stripe_head *sh = stripe_head_ref; in ops_complete_reconstruct() local
1930 int disks = sh->disks; in ops_complete_reconstruct()
1931 int pd_idx = sh->pd_idx; in ops_complete_reconstruct()
1932 int qd_idx = sh->qd_idx; in ops_complete_reconstruct()
1937 (unsigned long long)sh->sector); in ops_complete_reconstruct()
1940 fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); in ops_complete_reconstruct()
1941 sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); in ops_complete_reconstruct()
1942 discard |= test_bit(R5_Discard, &sh->dev[i].flags); in ops_complete_reconstruct()
1946 struct r5dev *dev = &sh->dev[i]; in ops_complete_reconstruct()
1951 if (test_bit(STRIPE_EXPAND_READY, &sh->state)) in ops_complete_reconstruct()
1961 if (sh->reconstruct_state == reconstruct_state_drain_run) in ops_complete_reconstruct()
1962 sh->reconstruct_state = reconstruct_state_drain_result; in ops_complete_reconstruct()
1963 else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) in ops_complete_reconstruct()
1964 sh->reconstruct_state = reconstruct_state_prexor_drain_result; in ops_complete_reconstruct()
1966 BUG_ON(sh->reconstruct_state != reconstruct_state_run); in ops_complete_reconstruct()
1967 sh->reconstruct_state = reconstruct_state_result; in ops_complete_reconstruct()
1970 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_reconstruct()
1971 raid5_release_stripe(sh); in ops_complete_reconstruct()
1975 ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_reconstruct5() argument
1978 int disks = sh->disks; in ops_run_reconstruct5()
1982 int count, pd_idx = sh->pd_idx, i; in ops_run_reconstruct5()
1988 struct stripe_head *head_sh = sh; in ops_run_reconstruct5()
1992 (unsigned long long)sh->sector); in ops_run_reconstruct5()
1994 for (i = 0; i < sh->disks; i++) { in ops_run_reconstruct5()
1997 if (!test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_reconstruct5()
2000 if (i >= sh->disks) { in ops_run_reconstruct5()
2001 atomic_inc(&sh->count); in ops_run_reconstruct5()
2002 set_bit(R5_Discard, &sh->dev[pd_idx].flags); in ops_run_reconstruct5()
2003 ops_complete_reconstruct(sh); in ops_run_reconstruct5()
2009 off_srcs = to_addr_offs(sh, percpu); in ops_run_reconstruct5()
2015 off_dest = off_srcs[count] = sh->dev[pd_idx].offset; in ops_run_reconstruct5()
2016 xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; in ops_run_reconstruct5()
2018 struct r5dev *dev = &sh->dev[i]; in ops_run_reconstruct5()
2026 xor_dest = sh->dev[pd_idx].page; in ops_run_reconstruct5()
2027 off_dest = sh->dev[pd_idx].offset; in ops_run_reconstruct5()
2029 struct r5dev *dev = &sh->dev[i]; in ops_run_reconstruct5()
2043 list_first_entry(&sh->batch_list, in ops_run_reconstruct5()
2051 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct5()
2055 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct5()
2060 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct5()
2063 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct5()
2066 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_reconstruct5()
2073 ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_reconstruct6() argument
2080 struct stripe_head *head_sh = sh; in ops_run_reconstruct6()
2085 pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); in ops_run_reconstruct6()
2087 for (i = 0; i < sh->disks; i++) { in ops_run_reconstruct6()
2088 if (sh->pd_idx == i || sh->qd_idx == i) in ops_run_reconstruct6()
2090 if (!test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_reconstruct6()
2093 if (i >= sh->disks) { in ops_run_reconstruct6()
2094 atomic_inc(&sh->count); in ops_run_reconstruct6()
2095 set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); in ops_run_reconstruct6()
2096 set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); in ops_run_reconstruct6()
2097 ops_complete_reconstruct(sh); in ops_run_reconstruct6()
2103 offs = to_addr_offs(sh, percpu); in ops_run_reconstruct6()
2105 if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { in ops_run_reconstruct6()
2113 count = set_syndrome_sources(blocks, offs, sh, synflags); in ops_run_reconstruct6()
2115 list_first_entry(&sh->batch_list, in ops_run_reconstruct6()
2121 head_sh, to_addr_conv(sh, percpu, j)); in ops_run_reconstruct6()
2124 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct6()
2126 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct6()
2129 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_reconstruct6()
2137 struct stripe_head *sh = stripe_head_ref; in ops_complete_check() local
2140 (unsigned long long)sh->sector); in ops_complete_check()
2142 sh->check_state = check_state_check_result; in ops_complete_check()
2143 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_check()
2144 raid5_release_stripe(sh); in ops_complete_check()
2147 static void ops_run_check_p(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_check_p() argument
2149 int disks = sh->disks; in ops_run_check_p()
2150 int pd_idx = sh->pd_idx; in ops_run_check_p()
2151 int qd_idx = sh->qd_idx; in ops_run_check_p()
2155 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_check_p()
2162 (unsigned long long)sh->sector); in ops_run_check_p()
2164 BUG_ON(sh->batch_head); in ops_run_check_p()
2166 xor_dest = sh->dev[pd_idx].page; in ops_run_check_p()
2167 off_dest = sh->dev[pd_idx].offset; in ops_run_check_p()
2173 off_srcs[count] = sh->dev[i].offset; in ops_run_check_p()
2174 xor_srcs[count++] = sh->dev[i].page; in ops_run_check_p()
2178 to_addr_conv(sh, percpu, 0)); in ops_run_check_p()
2180 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_check_p()
2181 &sh->ops.zero_sum_result, &submit); in ops_run_check_p()
2183 atomic_inc(&sh->count); in ops_run_check_p()
2184 init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); in ops_run_check_p()
2188 static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) in ops_run_check_pq() argument
2191 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_check_pq()
2196 (unsigned long long)sh->sector, checkp); in ops_run_check_pq()
2198 BUG_ON(sh->batch_head); in ops_run_check_pq()
2199 count = set_syndrome_sources(srcs, offs, sh, SYNDROME_SRC_ALL); in ops_run_check_pq()
2203 atomic_inc(&sh->count); in ops_run_check_pq()
2205 sh, to_addr_conv(sh, percpu, 0)); in ops_run_check_pq()
2207 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_check_pq()
2208 &sh->ops.zero_sum_result, percpu->spare_page, 0, &submit); in ops_run_check_pq()
2211 static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) in raid_run_ops() argument
2213 int overlap_clear = 0, i, disks = sh->disks; in raid_run_ops()
2215 struct r5conf *conf = sh->raid_conf; in raid_run_ops()
2223 ops_run_biofill(sh); in raid_run_ops()
2229 tx = ops_run_compute5(sh, percpu); in raid_run_ops()
2231 if (sh->ops.target2 < 0 || sh->ops.target < 0) in raid_run_ops()
2232 tx = ops_run_compute6_1(sh, percpu); in raid_run_ops()
2234 tx = ops_run_compute6_2(sh, percpu); in raid_run_ops()
2243 tx = ops_run_prexor5(sh, percpu, tx); in raid_run_ops()
2245 tx = ops_run_prexor6(sh, percpu, tx); in raid_run_ops()
2249 tx = ops_run_partial_parity(sh, percpu, tx); in raid_run_ops()
2252 tx = ops_run_biodrain(sh, tx); in raid_run_ops()
2258 ops_run_reconstruct5(sh, percpu, tx); in raid_run_ops()
2260 ops_run_reconstruct6(sh, percpu, tx); in raid_run_ops()
2264 if (sh->check_state == check_state_run) in raid_run_ops()
2265 ops_run_check_p(sh, percpu); in raid_run_ops()
2266 else if (sh->check_state == check_state_run_q) in raid_run_ops()
2267 ops_run_check_pq(sh, percpu, 0); in raid_run_ops()
2268 else if (sh->check_state == check_state_run_pq) in raid_run_ops()
2269 ops_run_check_pq(sh, percpu, 1); in raid_run_ops()
2274 if (overlap_clear && !sh->batch_head) in raid_run_ops()
2276 struct r5dev *dev = &sh->dev[i]; in raid_run_ops()
2278 wake_up(&sh->raid_conf->wait_for_overlap); in raid_run_ops()
2283 static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh) in free_stripe() argument
2286 kfree(sh->pages); in free_stripe()
2288 if (sh->ppl_page) in free_stripe()
2289 __free_page(sh->ppl_page); in free_stripe()
2290 kmem_cache_free(sc, sh); in free_stripe()
2296 struct stripe_head *sh; in alloc_stripe() local
2299 sh = kmem_cache_zalloc(sc, gfp); in alloc_stripe()
2300 if (sh) { in alloc_stripe()
2301 spin_lock_init(&sh->stripe_lock); in alloc_stripe()
2302 spin_lock_init(&sh->batch_lock); in alloc_stripe()
2303 INIT_LIST_HEAD(&sh->batch_list); in alloc_stripe()
2304 INIT_LIST_HEAD(&sh->lru); in alloc_stripe()
2305 INIT_LIST_HEAD(&sh->r5c); in alloc_stripe()
2306 INIT_LIST_HEAD(&sh->log_list); in alloc_stripe()
2307 atomic_set(&sh->count, 1); in alloc_stripe()
2308 sh->raid_conf = conf; in alloc_stripe()
2309 sh->log_start = MaxSector; in alloc_stripe()
2311 struct r5dev *dev = &sh->dev[i]; in alloc_stripe()
2318 sh->ppl_page = alloc_page(gfp); in alloc_stripe()
2319 if (!sh->ppl_page) { in alloc_stripe()
2320 free_stripe(sc, sh); in alloc_stripe()
2325 if (init_stripe_shared_pages(sh, conf, disks)) { in alloc_stripe()
2326 free_stripe(sc, sh); in alloc_stripe()
2331 return sh; in alloc_stripe()
2335 struct stripe_head *sh; in grow_one_stripe() local
2337 sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size, conf); in grow_one_stripe()
2338 if (!sh) in grow_one_stripe()
2341 if (grow_buffers(sh, gfp)) { in grow_one_stripe()
2342 shrink_buffers(sh); in grow_one_stripe()
2343 free_stripe(conf->slab_cache, sh); in grow_one_stripe()
2346 sh->hash_lock_index = in grow_one_stripe()
2351 raid5_release_stripe(sh); in grow_one_stripe()
2637 struct stripe_head *sh; in drop_one_stripe() local
2641 sh = get_free_stripe(conf, hash); in drop_one_stripe()
2643 if (!sh) in drop_one_stripe()
2645 BUG_ON(atomic_read(&sh->count)); in drop_one_stripe()
2646 shrink_buffers(sh); in drop_one_stripe()
2647 free_stripe(conf->slab_cache, sh); in drop_one_stripe()
2665 struct stripe_head *sh = bi->bi_private; in raid5_end_read_request() local
2666 struct r5conf *conf = sh->raid_conf; in raid5_end_read_request()
2667 int disks = sh->disks, i; in raid5_end_read_request()
2673 if (bi == &sh->dev[i].req) in raid5_end_read_request()
2677 (unsigned long long)sh->sector, i, atomic_read(&sh->count), in raid5_end_read_request()
2684 if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) in raid5_end_read_request()
2694 if (use_new_offset(conf, sh)) in raid5_end_read_request()
2695 s = sh->sector + rdev->new_data_offset; in raid5_end_read_request()
2697 s = sh->sector + rdev->data_offset; in raid5_end_read_request()
2699 set_bit(R5_UPTODATE, &sh->dev[i].flags); in raid5_end_read_request()
2700 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { in raid5_end_read_request()
2711 clear_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2712 clear_bit(R5_ReWrite, &sh->dev[i].flags); in raid5_end_read_request()
2713 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) in raid5_end_read_request()
2714 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2716 if (test_bit(R5_InJournal, &sh->dev[i].flags)) in raid5_end_read_request()
2721 set_bit(R5_OrigPageUPTDODATE, &sh->dev[i].flags); in raid5_end_read_request()
2730 clear_bit(R5_UPTODATE, &sh->dev[i].flags); in raid5_end_read_request()
2733 if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) in raid5_end_read_request()
2746 } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { in raid5_end_read_request()
2767 && !test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) in raid5_end_read_request()
2770 if (sh->qd_idx >= 0 && sh->pd_idx == i) in raid5_end_read_request()
2771 set_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2772 else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { in raid5_end_read_request()
2773 set_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2774 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2776 set_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2778 clear_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2779 clear_bit(R5_ReWrite, &sh->dev[i].flags); in raid5_end_read_request()
2783 rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0))) in raid5_end_read_request()
2789 clear_bit(R5_LOCKED, &sh->dev[i].flags); in raid5_end_read_request()
2790 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_read_request()
2791 raid5_release_stripe(sh); in raid5_end_read_request()
2796 struct stripe_head *sh = bi->bi_private; in raid5_end_write_request() local
2797 struct r5conf *conf = sh->raid_conf; in raid5_end_write_request()
2798 int disks = sh->disks, i; in raid5_end_write_request()
2805 if (bi == &sh->dev[i].req) { in raid5_end_write_request()
2809 if (bi == &sh->dev[i].rreq) { in raid5_end_write_request()
2823 (unsigned long long)sh->sector, i, atomic_read(&sh->count), in raid5_end_write_request()
2834 else if (is_badblock(rdev, sh->sector, in raid5_end_write_request()
2837 set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); in raid5_end_write_request()
2840 set_bit(STRIPE_DEGRADED, &sh->state); in raid5_end_write_request()
2842 set_bit(R5_WriteError, &sh->dev[i].flags); in raid5_end_write_request()
2846 } else if (is_badblock(rdev, sh->sector, in raid5_end_write_request()
2849 set_bit(R5_MadeGood, &sh->dev[i].flags); in raid5_end_write_request()
2850 if (test_bit(R5_ReadError, &sh->dev[i].flags)) in raid5_end_write_request()
2855 set_bit(R5_ReWrite, &sh->dev[i].flags); in raid5_end_write_request()
2860 if (sh->batch_head && bi->bi_status && !replacement) in raid5_end_write_request()
2861 set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state); in raid5_end_write_request()
2864 if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) in raid5_end_write_request()
2865 clear_bit(R5_LOCKED, &sh->dev[i].flags); in raid5_end_write_request()
2866 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_write_request()
2867 raid5_release_stripe(sh); in raid5_end_write_request()
2869 if (sh->batch_head && sh != sh->batch_head) in raid5_end_write_request()
2870 raid5_release_stripe(sh->batch_head); in raid5_end_write_request()
2917 struct stripe_head *sh) in raid5_compute_sector() argument
3105 if (sh) { in raid5_compute_sector()
3106 sh->pd_idx = pd_idx; in raid5_compute_sector()
3107 sh->qd_idx = qd_idx; in raid5_compute_sector()
3108 sh->ddf_layout = ddf_layout; in raid5_compute_sector()
3117 sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous) in raid5_compute_blocknr() argument
3119 struct r5conf *conf = sh->raid_conf; in raid5_compute_blocknr()
3120 int raid_disks = sh->disks; in raid5_compute_blocknr()
3122 sector_t new_sector = sh->sector, check; in raid5_compute_blocknr()
3137 if (i == sh->pd_idx) in raid5_compute_blocknr()
3145 if (i > sh->pd_idx) in raid5_compute_blocknr()
3150 if (i < sh->pd_idx) in raid5_compute_blocknr()
3152 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3164 if (i == sh->qd_idx) in raid5_compute_blocknr()
3171 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3173 else if (i > sh->pd_idx) in raid5_compute_blocknr()
3178 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3182 if (i < sh->pd_idx) in raid5_compute_blocknr()
3184 i -= (sh->pd_idx + 2); in raid5_compute_blocknr()
3194 if (sh->pd_idx == 0) in raid5_compute_blocknr()
3198 if (i < sh->pd_idx) in raid5_compute_blocknr()
3200 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3205 if (i > sh->pd_idx) in raid5_compute_blocknr()
3210 if (i < sh->pd_idx) in raid5_compute_blocknr()
3212 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3228 if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx in raid5_compute_blocknr()
3229 || sh2.qd_idx != sh->qd_idx) { in raid5_compute_blocknr()
3294 schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, in schedule_reconstruction() argument
3297 int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx, disks = sh->disks; in schedule_reconstruction()
3298 struct r5conf *conf = sh->raid_conf; in schedule_reconstruction()
3308 r5c_release_extra_page(sh); in schedule_reconstruction()
3311 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3332 sh->reconstruct_state = reconstruct_state_drain_run; in schedule_reconstruction()
3335 sh->reconstruct_state = reconstruct_state_run; in schedule_reconstruction()
3340 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) in schedule_reconstruction()
3343 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || in schedule_reconstruction()
3344 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); in schedule_reconstruction()
3346 (!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) || in schedule_reconstruction()
3347 test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags)))); in schedule_reconstruction()
3350 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3369 sh->reconstruct_state = reconstruct_state_prexor_drain_run; in schedule_reconstruction()
3378 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3379 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3383 int qd_idx = sh->qd_idx; in schedule_reconstruction()
3384 struct r5dev *dev = &sh->dev[qd_idx]; in schedule_reconstruction()
3391 if (raid5_has_ppl(sh->raid_conf) && sh->ppl_page && in schedule_reconstruction()
3393 !test_bit(STRIPE_FULL_WRITE, &sh->state) && in schedule_reconstruction()
3394 test_bit(R5_Insync, &sh->dev[pd_idx].flags)) in schedule_reconstruction()
3398 __func__, (unsigned long long)sh->sector, in schedule_reconstruction()
3407 static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in add_stripe_bio() argument
3411 struct r5conf *conf = sh->raid_conf; in add_stripe_bio()
3416 (unsigned long long)sh->sector); in add_stripe_bio()
3418 spin_lock_irq(&sh->stripe_lock); in add_stripe_bio()
3419 sh->dev[dd_idx].write_hint = bi->bi_write_hint; in add_stripe_bio()
3421 if (sh->batch_head) in add_stripe_bio()
3424 bip = &sh->dev[dd_idx].towrite; in add_stripe_bio()
3428 bip = &sh->dev[dd_idx].toread; in add_stripe_bio()
3451 for (i = 0; i < sh->disks; i++) { in add_stripe_bio()
3452 if (i != sh->pd_idx && in add_stripe_bio()
3453 (i == dd_idx || sh->dev[i].towrite)) { in add_stripe_bio()
3454 sector = sh->dev[i].sector; in add_stripe_bio()
3468 clear_bit(STRIPE_BATCH_READY, &sh->state); in add_stripe_bio()
3479 sector_t sector = sh->dev[dd_idx].sector; in add_stripe_bio()
3480 for (bi=sh->dev[dd_idx].towrite; in add_stripe_bio()
3481 sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && in add_stripe_bio()
3483 bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { in add_stripe_bio()
3487 if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) in add_stripe_bio()
3488 if (!test_and_set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags)) in add_stripe_bio()
3489 sh->overwrite_disks++; in add_stripe_bio()
3494 (unsigned long long)sh->sector, dd_idx); in add_stripe_bio()
3509 set_bit(STRIPE_BITMAP_PENDING, &sh->state); in add_stripe_bio()
3510 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3511 md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, in add_stripe_bio()
3513 spin_lock_irq(&sh->stripe_lock); in add_stripe_bio()
3514 clear_bit(STRIPE_BITMAP_PENDING, &sh->state); in add_stripe_bio()
3515 if (!sh->batch_head) { in add_stripe_bio()
3516 sh->bm_seq = conf->seq_flush+1; in add_stripe_bio()
3517 set_bit(STRIPE_BIT_DELAY, &sh->state); in add_stripe_bio()
3520 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3522 if (stripe_can_batch(sh)) in add_stripe_bio()
3523 stripe_add_to_batch_list(conf, sh); in add_stripe_bio()
3527 set_bit(R5_Overlap, &sh->dev[dd_idx].flags); in add_stripe_bio()
3528 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3535 struct stripe_head *sh) in stripe_set_idx() argument
3547 &dd_idx, sh); in stripe_set_idx()
3551 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, in handle_failed_stripe() argument
3555 BUG_ON(sh->batch_head); in handle_failed_stripe()
3560 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { in handle_failed_stripe()
3573 sh->sector, in handle_failed_stripe()
3579 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3581 bi = sh->dev[i].towrite; in handle_failed_stripe()
3582 sh->dev[i].towrite = NULL; in handle_failed_stripe()
3583 sh->overwrite_disks = 0; in handle_failed_stripe()
3584 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3588 log_stripe_write_finished(sh); in handle_failed_stripe()
3590 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3594 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3595 struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3602 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3606 bi = sh->dev[i].written; in handle_failed_stripe()
3607 sh->dev[i].written = NULL; in handle_failed_stripe()
3608 if (test_and_clear_bit(R5_SkipCopy, &sh->dev[i].flags)) { in handle_failed_stripe()
3609 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_failed_stripe()
3610 sh->dev[i].page = sh->dev[i].orig_page; in handle_failed_stripe()
3615 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3616 struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3626 if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && in handle_failed_stripe()
3628 (!test_bit(R5_Insync, &sh->dev[i].flags) || in handle_failed_stripe()
3629 test_bit(R5_ReadError, &sh->dev[i].flags))) { in handle_failed_stripe()
3630 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3631 bi = sh->dev[i].toread; in handle_failed_stripe()
3632 sh->dev[i].toread = NULL; in handle_failed_stripe()
3633 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3634 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3639 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3641 r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3648 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3653 clear_bit(R5_LOCKED, &sh->dev[i].flags); in handle_failed_stripe()
3658 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_failed_stripe()
3664 handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, in handle_failed_sync() argument
3670 BUG_ON(sh->batch_head); in handle_failed_sync()
3671 clear_bit(STRIPE_SYNCING, &sh->state); in handle_failed_sync()
3672 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_failed_sync()
3693 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3700 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3712 static int want_replace(struct stripe_head *sh, int disk_idx) in want_replace() argument
3718 rdev = rcu_dereference(sh->raid_conf->disks[disk_idx].replacement); in want_replace()
3722 && (rdev->recovery_offset <= sh->sector in want_replace()
3723 || rdev->mddev->recovery_cp <= sh->sector)) in want_replace()
3729 static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s, in need_this_block() argument
3732 struct r5dev *dev = &sh->dev[disk_idx]; in need_this_block()
3733 struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], in need_this_block()
3734 &sh->dev[s->failed_num[1]] }; in need_this_block()
3736 bool force_rcw = (sh->raid_conf->rmw_level == PARITY_DISABLE_RMW); in need_this_block()
3752 (s->replacing && want_replace(sh, disk_idx))) in need_this_block()
3777 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in need_this_block()
3798 s->failed_num[i] == sh->pd_idx || in need_this_block()
3799 s->failed_num[i] == sh->qd_idx) && in need_this_block()
3816 sh->sector < sh->raid_conf->mddev->recovery_cp) in need_this_block()
3820 if (s->failed_num[i] != sh->pd_idx && in need_this_block()
3821 s->failed_num[i] != sh->qd_idx && in need_this_block()
3836 static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, in fetch_block() argument
3839 struct r5dev *dev = &sh->dev[disk_idx]; in fetch_block()
3842 if (need_this_block(sh, s, disk_idx, disks)) { in fetch_block()
3848 BUG_ON(sh->batch_head); in fetch_block()
3860 ((sh->qd_idx >= 0 && sh->pd_idx == disk_idx) || in fetch_block()
3867 (unsigned long long)sh->sector, disk_idx); in fetch_block()
3868 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3871 sh->ops.target = disk_idx; in fetch_block()
3872 sh->ops.target2 = -1; /* no 2nd target */ in fetch_block()
3891 &sh->dev[other].flags)) in fetch_block()
3896 (unsigned long long)sh->sector, in fetch_block()
3898 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3900 set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); in fetch_block()
3901 set_bit(R5_Wantcompute, &sh->dev[other].flags); in fetch_block()
3902 sh->ops.target = disk_idx; in fetch_block()
3903 sh->ops.target2 = other; in fetch_block()
3922 static void handle_stripe_fill(struct stripe_head *sh, in handle_stripe_fill() argument
3932 if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && in handle_stripe_fill()
3933 !sh->reconstruct_state) { in handle_stripe_fill()
3943 if (test_bit(STRIPE_R5C_CACHING, &sh->state)) in handle_stripe_fill()
3944 r5c_make_stripe_write_out(sh); in handle_stripe_fill()
3949 if (fetch_block(sh, s, i, disks)) in handle_stripe_fill()
3953 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_fill()
3964 struct stripe_head *sh, int disks) in handle_stripe_clean_event() argument
3969 struct stripe_head *head_sh = sh; in handle_stripe_clean_event()
3973 if (sh->dev[i].written) { in handle_stripe_clean_event()
3974 dev = &sh->dev[i]; in handle_stripe_clean_event()
4000 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_stripe_clean_event()
4002 !test_bit(STRIPE_DEGRADED, &sh->state), in handle_stripe_clean_event()
4005 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4008 if (sh != head_sh) { in handle_stripe_clean_event()
4009 dev = &sh->dev[i]; in handle_stripe_clean_event()
4013 sh = head_sh; in handle_stripe_clean_event()
4014 dev = &sh->dev[i]; in handle_stripe_clean_event()
4019 log_stripe_write_finished(sh); in handle_stripe_clean_event()
4022 test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_clean_event()
4024 clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4025 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4026 if (sh->qd_idx >= 0) { in handle_stripe_clean_event()
4027 clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4028 clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4031 clear_bit(STRIPE_DISCARD, &sh->state); in handle_stripe_clean_event()
4038 hash = sh->hash_lock_index; in handle_stripe_clean_event()
4040 remove_hash(sh); in handle_stripe_clean_event()
4043 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4045 if (sh != head_sh) in handle_stripe_clean_event()
4048 sh = head_sh; in handle_stripe_clean_event()
4050 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) in handle_stripe_clean_event()
4051 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_clean_event()
4055 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_stripe_clean_event()
4079 struct stripe_head *sh, in handle_stripe_dirtying() argument
4094 (recovery_cp < MaxSector && sh->sector >= recovery_cp && in handle_stripe_dirtying()
4100 pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n", in handle_stripe_dirtying()
4102 (unsigned long long)sh->sector); in handle_stripe_dirtying()
4105 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4107 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4119 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4131 (unsigned long long)sh->sector, sh->state, rmw, rcw); in handle_stripe_dirtying()
4132 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_dirtying()
4138 (unsigned long long)sh->sector, rmw); in handle_stripe_dirtying()
4140 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4143 !test_bit(R5_LOCKED, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_dirtying()
4158 r5c_use_extra_page(sh); in handle_stripe_dirtying()
4163 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4170 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4172 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4179 &sh->state)) { in handle_stripe_dirtying()
4186 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4195 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4197 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4204 &sh->state)) { in handle_stripe_dirtying()
4212 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4217 (unsigned long long)sh->sector, in handle_stripe_dirtying()
4218 rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); in handle_stripe_dirtying()
4222 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe_dirtying()
4223 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4235 if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && in handle_stripe_dirtying()
4237 !test_bit(STRIPE_BIT_DELAY, &sh->state))) in handle_stripe_dirtying()
4238 schedule_reconstruction(sh, s, rcw == 0, 0); in handle_stripe_dirtying()
4242 static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks5() argument
4247 BUG_ON(sh->batch_head); in handle_parity_checks5()
4248 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks5()
4250 switch (sh->check_state) { in handle_parity_checks5()
4255 sh->check_state = check_state_run; in handle_parity_checks5()
4257 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4261 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks5()
4264 sh->check_state = check_state_idle; in handle_parity_checks5()
4266 dev = &sh->dev[sh->pd_idx]; in handle_parity_checks5()
4269 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks5()
4280 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks5()
4281 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4286 sh->check_state = check_state_idle; in handle_parity_checks5()
4298 if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) in handle_parity_checks5()
4302 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4307 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4310 (unsigned long long) sh->sector, in handle_parity_checks5()
4311 (unsigned long long) sh->sector + in handle_parity_checks5()
4314 sh->check_state = check_state_compute_run; in handle_parity_checks5()
4315 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks5()
4318 &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4319 sh->ops.target = sh->pd_idx; in handle_parity_checks5()
4320 sh->ops.target2 = -1; in handle_parity_checks5()
4329 __func__, sh->check_state, in handle_parity_checks5()
4330 (unsigned long long) sh->sector); in handle_parity_checks5()
4335 static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks6() argument
4339 int pd_idx = sh->pd_idx; in handle_parity_checks6()
4340 int qd_idx = sh->qd_idx; in handle_parity_checks6()
4343 BUG_ON(sh->batch_head); in handle_parity_checks6()
4344 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks6()
4354 switch (sh->check_state) { in handle_parity_checks6()
4362 sh->check_state = check_state_run; in handle_parity_checks6()
4368 if (sh->check_state == check_state_run) in handle_parity_checks6()
4369 sh->check_state = check_state_run_pq; in handle_parity_checks6()
4371 sh->check_state = check_state_run_q; in handle_parity_checks6()
4375 sh->ops.zero_sum_result = 0; in handle_parity_checks6()
4377 if (sh->check_state == check_state_run) { in handle_parity_checks6()
4379 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in handle_parity_checks6()
4382 if (sh->check_state >= check_state_run && in handle_parity_checks6()
4383 sh->check_state <= check_state_run_pq) { in handle_parity_checks6()
4395 sh->check_state = check_state_idle; in handle_parity_checks6()
4398 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks6()
4406 dev = &sh->dev[s->failed_num[1]]; in handle_parity_checks6()
4412 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks6()
4417 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4418 dev = &sh->dev[pd_idx]; in handle_parity_checks6()
4423 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4424 dev = &sh->dev[qd_idx]; in handle_parity_checks6()
4432 dev - (struct r5dev *) &sh->dev)) { in handle_parity_checks6()
4437 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks6()
4439 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4446 sh->check_state = check_state_idle; in handle_parity_checks6()
4452 if (sh->ops.zero_sum_result == 0) { in handle_parity_checks6()
4455 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4461 sh->check_state = check_state_compute_result; in handle_parity_checks6()
4472 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4475 (unsigned long long) sh->sector, in handle_parity_checks6()
4476 (unsigned long long) sh->sector + in handle_parity_checks6()
4479 int *target = &sh->ops.target; in handle_parity_checks6()
4481 sh->ops.target = -1; in handle_parity_checks6()
4482 sh->ops.target2 = -1; in handle_parity_checks6()
4483 sh->check_state = check_state_compute_run; in handle_parity_checks6()
4484 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks6()
4486 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4488 &sh->dev[pd_idx].flags); in handle_parity_checks6()
4490 target = &sh->ops.target2; in handle_parity_checks6()
4493 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4495 &sh->dev[qd_idx].flags); in handle_parity_checks6()
4506 __func__, sh->check_state, in handle_parity_checks6()
4507 (unsigned long long) sh->sector); in handle_parity_checks6()
4512 static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) in handle_stripe_expansion() argument
4520 BUG_ON(sh->batch_head); in handle_stripe_expansion()
4521 clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); in handle_stripe_expansion()
4522 for (i = 0; i < sh->disks; i++) in handle_stripe_expansion()
4523 if (i != sh->pd_idx && i != sh->qd_idx) { in handle_stripe_expansion()
4528 sector_t bn = raid5_compute_blocknr(sh, i, 1); in handle_stripe_expansion()
4548 sh->dev[i].page, sh2->dev[dd_idx].offset, in handle_stripe_expansion()
4549 sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), in handle_stripe_expansion()
4584 static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) in analyse_stripe() argument
4586 struct r5conf *conf = sh->raid_conf; in analyse_stripe()
4587 int disks = sh->disks; in analyse_stripe()
4594 s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state) && !sh->batch_head; in analyse_stripe()
4595 s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state) && !sh->batch_head; in analyse_stripe()
4608 dev = &sh->dev[i]; in analyse_stripe()
4619 !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) in analyse_stripe()
4648 rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && in analyse_stripe()
4649 !is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4663 is_bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4690 else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) in analyse_stripe()
4760 if (test_bit(STRIPE_SYNCING, &sh->state)) { in analyse_stripe()
4770 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4783 static int clear_batch_ready(struct stripe_head *sh) in clear_batch_ready() argument
4786 if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) in clear_batch_ready()
4787 return (sh->batch_head && sh->batch_head != sh); in clear_batch_ready()
4788 spin_lock(&sh->stripe_lock); in clear_batch_ready()
4789 if (!sh->batch_head) { in clear_batch_ready()
4790 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4798 if (sh->batch_head != sh) { in clear_batch_ready()
4799 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4802 spin_lock(&sh->batch_lock); in clear_batch_ready()
4803 list_for_each_entry(tmp, &sh->batch_list, batch_list) in clear_batch_ready()
4805 spin_unlock(&sh->batch_lock); in clear_batch_ready()
4806 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4818 struct stripe_head *sh, *next; in break_stripe_batch_list() local
4822 list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { in break_stripe_batch_list()
4824 list_del_init(&sh->batch_list); in break_stripe_batch_list()
4826 WARN_ONCE(sh->state & ((1 << STRIPE_ACTIVE) | in break_stripe_batch_list()
4838 "stripe state: %lx\n", sh->state); in break_stripe_batch_list()
4843 set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | in break_stripe_batch_list()
4849 sh->check_state = head_sh->check_state; in break_stripe_batch_list()
4850 sh->reconstruct_state = head_sh->reconstruct_state; in break_stripe_batch_list()
4851 spin_lock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4852 sh->batch_head = NULL; in break_stripe_batch_list()
4853 spin_unlock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4854 for (i = 0; i < sh->disks; i++) { in break_stripe_batch_list()
4855 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in break_stripe_batch_list()
4857 sh->dev[i].flags = head_sh->dev[i].flags & in break_stripe_batch_list()
4861 sh->state & handle_flags) in break_stripe_batch_list()
4862 set_bit(STRIPE_HANDLE, &sh->state); in break_stripe_batch_list()
4863 raid5_release_stripe(sh); in break_stripe_batch_list()
4878 static void handle_stripe(struct stripe_head *sh) in handle_stripe() argument
4881 struct r5conf *conf = sh->raid_conf; in handle_stripe()
4884 int disks = sh->disks; in handle_stripe()
4887 clear_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4895 if (clear_batch_ready(sh)) in handle_stripe()
4898 if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { in handle_stripe()
4901 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4905 if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) in handle_stripe()
4906 break_stripe_batch_list(sh, 0); in handle_stripe()
4908 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { in handle_stripe()
4909 spin_lock(&sh->stripe_lock); in handle_stripe()
4914 if (!test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state) && in handle_stripe()
4915 !test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) && in handle_stripe()
4916 !test_bit(STRIPE_DISCARD, &sh->state) && in handle_stripe()
4917 test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { in handle_stripe()
4918 set_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
4919 clear_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
4920 clear_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
4922 spin_unlock(&sh->stripe_lock); in handle_stripe()
4924 clear_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
4928 (unsigned long long)sh->sector, sh->state, in handle_stripe()
4929 atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, in handle_stripe()
4930 sh->check_state, sh->reconstruct_state); in handle_stripe()
4932 analyse_stripe(sh, &s); in handle_stripe()
4934 if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) in handle_stripe()
4939 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4946 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4954 if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { in handle_stripe()
4956 set_bit(STRIPE_BIOFILL_RUN, &sh->state); in handle_stripe()
4972 sh->check_state = 0; in handle_stripe()
4973 sh->reconstruct_state = 0; in handle_stripe()
4974 break_stripe_batch_list(sh, 0); in handle_stripe()
4976 handle_failed_stripe(conf, sh, &s, disks); in handle_stripe()
4978 handle_failed_sync(conf, sh, &s); in handle_stripe()
4985 if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) in handle_stripe()
4987 if (sh->reconstruct_state == reconstruct_state_drain_result || in handle_stripe()
4988 sh->reconstruct_state == reconstruct_state_prexor_drain_result) { in handle_stripe()
4989 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
4994 BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && in handle_stripe()
4995 !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); in handle_stripe()
4996 BUG_ON(sh->qd_idx >= 0 && in handle_stripe()
4997 !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && in handle_stripe()
4998 !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); in handle_stripe()
5000 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
5002 (i == sh->pd_idx || i == sh->qd_idx || in handle_stripe()
5012 ((i == sh->pd_idx || i == sh->qd_idx) && in handle_stripe()
5014 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5017 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe()
5025 pdev = &sh->dev[sh->pd_idx]; in handle_stripe()
5026 s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) in handle_stripe()
5027 || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); in handle_stripe()
5028 qdev = &sh->dev[sh->qd_idx]; in handle_stripe()
5029 s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) in handle_stripe()
5030 || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) in handle_stripe()
5042 handle_stripe_clean_event(conf, sh, disks); in handle_stripe()
5045 r5c_handle_cached_data_endio(conf, sh, disks); in handle_stripe()
5046 log_stripe_write_finished(sh); in handle_stripe()
5057 handle_stripe_fill(sh, &s, disks); in handle_stripe()
5064 r5c_finish_stripe_write_out(conf, sh, &s); in handle_stripe()
5075 if (!sh->reconstruct_state && !sh->check_state && !sh->log_io) { in handle_stripe()
5078 handle_stripe_dirtying(conf, sh, &s, disks); in handle_stripe()
5084 ret = r5c_try_caching_write(conf, sh, &s, in handle_stripe()
5095 (!test_bit(STRIPE_R5C_CACHING, &sh->state) && in handle_stripe()
5097 ret = handle_stripe_dirtying(conf, sh, &s, in handle_stripe()
5110 if (sh->check_state || in handle_stripe()
5112 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5113 !test_bit(STRIPE_INSYNC, &sh->state))) { in handle_stripe()
5115 handle_parity_checks6(conf, sh, &s, disks); in handle_stripe()
5117 handle_parity_checks5(conf, sh, &s, disks); in handle_stripe()
5121 && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) in handle_stripe()
5122 && !test_bit(STRIPE_REPLACED, &sh->state)) { in handle_stripe()
5125 if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { in handle_stripe()
5126 WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_stripe()
5127 set_bit(R5_WantReplace, &sh->dev[i].flags); in handle_stripe()
5128 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5132 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5133 set_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
5136 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5137 test_bit(STRIPE_INSYNC, &sh->state)) { in handle_stripe()
5139 clear_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
5140 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_stripe()
5149 struct r5dev *dev = &sh->dev[s.failed_num[i]]; in handle_stripe()
5166 if (sh->reconstruct_state == reconstruct_state_result) { in handle_stripe()
5168 = raid5_get_active_stripe(conf, sh->sector, 1, 1, 1); in handle_stripe()
5170 /* sh cannot be written until sh_src has been read. in handle_stripe()
5171 * so arrange for sh to be delayed a little in handle_stripe()
5173 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
5174 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
5184 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
5185 clear_bit(STRIPE_EXPANDING, &sh->state); in handle_stripe()
5187 set_bit(R5_Wantwrite, &sh->dev[i].flags); in handle_stripe()
5188 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5193 if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && in handle_stripe()
5194 !sh->reconstruct_state) { in handle_stripe()
5196 sh->disks = conf->raid_disks; in handle_stripe()
5197 stripe_set_idx(sh->sector, conf, 0, sh); in handle_stripe()
5198 schedule_reconstruction(sh, &s, 1, 1); in handle_stripe()
5199 } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { in handle_stripe()
5200 clear_bit(STRIPE_EXPAND_READY, &sh->state); in handle_stripe()
5207 !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) in handle_stripe()
5208 handle_stripe_expansion(conf, sh); in handle_stripe()
5228 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
5232 if (!rdev_set_badblocks(rdev, sh->sector, in handle_stripe()
5239 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5248 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5255 raid_run_ops(sh, s.ops_request); in handle_stripe()
5257 ops_run_io(sh, &s); in handle_stripe()
5270 clear_bit_unlock(STRIPE_ACTIVE, &sh->state); in handle_stripe()
5278 struct stripe_head *sh; in raid5_activate_delayed() local
5279 sh = list_entry(l, struct stripe_head, lru); in raid5_activate_delayed()
5281 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_activate_delayed()
5282 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_activate_delayed()
5284 list_add_tail(&sh->lru, &conf->hold_list); in raid5_activate_delayed()
5285 raid5_wakeup_stripe_thread(sh); in raid5_activate_delayed()
5298 struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); in activate_bit_delay() local
5300 list_del_init(&sh->lru); in activate_bit_delay()
5301 atomic_inc(&sh->count); in activate_bit_delay()
5302 hash = sh->hash_lock_index; in activate_bit_delay()
5303 __release_stripe(conf, sh, &temp_inactive_list[hash]); in activate_bit_delay()
5519 struct stripe_head *sh, *tmp; in __get_priority_stripe() local
5529 sh = NULL; in __get_priority_stripe()
5555 sh = list_entry(handle_list->next, typeof(*sh), lru); in __get_priority_stripe()
5559 else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { in __get_priority_stripe()
5579 sh = tmp; in __get_priority_stripe()
5584 if (sh) { in __get_priority_stripe()
5592 if (!sh) { in __get_priority_stripe()
5602 sh->group = NULL; in __get_priority_stripe()
5604 list_del_init(&sh->lru); in __get_priority_stripe()
5605 BUG_ON(atomic_inc_return(&sh->count) != 1); in __get_priority_stripe()
5606 return sh; in __get_priority_stripe()
5619 struct stripe_head *sh; in raid5_unplug() local
5628 sh = list_first_entry(&cb->list, struct stripe_head, lru); in raid5_unplug()
5629 list_del_init(&sh->lru); in raid5_unplug()
5636 clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); in raid5_unplug()
5641 hash = sh->hash_lock_index; in raid5_unplug()
5642 __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); in raid5_unplug()
5655 struct stripe_head *sh) in release_stripe_plug() argument
5663 raid5_release_stripe(sh); in release_stripe_plug()
5676 if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) in release_stripe_plug()
5677 list_add_tail(&sh->lru, &cb->list); in release_stripe_plug()
5679 raid5_release_stripe(sh); in release_stripe_plug()
5686 struct stripe_head *sh; in make_discard_request() local
5712 sh = raid5_get_active_stripe(conf, logical_sector, 0, 0, 0); in make_discard_request()
5715 set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5716 if (test_bit(STRIPE_SYNCING, &sh->state)) { in make_discard_request()
5717 raid5_release_stripe(sh); in make_discard_request()
5721 clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5722 spin_lock_irq(&sh->stripe_lock); in make_discard_request()
5724 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5726 if (sh->dev[d].towrite || sh->dev[d].toread) { in make_discard_request()
5727 set_bit(R5_Overlap, &sh->dev[d].flags); in make_discard_request()
5728 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5729 raid5_release_stripe(sh); in make_discard_request()
5734 set_bit(STRIPE_DISCARD, &sh->state); in make_discard_request()
5736 sh->overwrite_disks = 0; in make_discard_request()
5738 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5740 sh->dev[d].towrite = bi; in make_discard_request()
5741 set_bit(R5_OVERWRITE, &sh->dev[d].flags); in make_discard_request()
5744 sh->overwrite_disks++; in make_discard_request()
5746 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5752 sh->sector, in make_discard_request()
5755 sh->bm_seq = conf->seq_flush + 1; in make_discard_request()
5756 set_bit(STRIPE_BIT_DELAY, &sh->state); in make_discard_request()
5759 set_bit(STRIPE_HANDLE, &sh->state); in make_discard_request()
5760 clear_bit(STRIPE_DELAYED, &sh->state); in make_discard_request()
5761 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in make_discard_request()
5763 release_stripe_plug(mddev, sh); in make_discard_request()
5775 struct stripe_head *sh; in raid5_make_request() local
5869 sh = raid5_get_active_stripe(conf, new_sector, previous, in raid5_make_request()
5871 if (sh) { in raid5_make_request()
5877 * 'sh', we know that if that happens, in raid5_make_request()
5890 raid5_release_stripe(sh); in raid5_make_request()
5900 raid5_release_stripe(sh); in raid5_make_request()
5904 if (test_bit(STRIPE_EXPANDING, &sh->state) || in raid5_make_request()
5905 !add_stripe_bio(sh, bi, dd_idx, rw, previous)) { in raid5_make_request()
5911 raid5_release_stripe(sh); in raid5_make_request()
5917 set_bit(STRIPE_R5C_PREFLUSH, &sh->state); in raid5_make_request()
5922 set_bit(STRIPE_HANDLE, &sh->state); in raid5_make_request()
5923 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_make_request()
5924 if ((!sh->batch_head || sh == sh->batch_head) && in raid5_make_request()
5926 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_make_request()
5928 release_stripe_plug(mddev, sh); in raid5_make_request()
5957 struct stripe_head *sh; in reshape_request() local
6108 sh = raid5_get_active_stripe(conf, stripe_addr+i, 0, 0, 1); in reshape_request()
6109 set_bit(STRIPE_EXPANDING, &sh->state); in reshape_request()
6114 for (j=sh->disks; j--;) { in reshape_request()
6116 if (j == sh->pd_idx) in reshape_request()
6119 j == sh->qd_idx) in reshape_request()
6121 s = raid5_compute_blocknr(sh, j, 0); in reshape_request()
6126 memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); in reshape_request()
6127 set_bit(R5_Expanded, &sh->dev[j].flags); in reshape_request()
6128 set_bit(R5_UPTODATE, &sh->dev[j].flags); in reshape_request()
6131 set_bit(STRIPE_EXPAND_READY, &sh->state); in reshape_request()
6132 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6134 list_add(&sh->lru, &stripes); in reshape_request()
6157 sh = raid5_get_active_stripe(conf, first_sector, 1, 0, 1); in reshape_request()
6158 set_bit(STRIPE_EXPAND_SOURCE, &sh->state); in reshape_request()
6159 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6160 raid5_release_stripe(sh); in reshape_request()
6167 sh = list_entry(stripes.next, struct stripe_head, lru); in reshape_request()
6168 list_del_init(&sh->lru); in reshape_request()
6169 raid5_release_stripe(sh); in reshape_request()
6218 struct stripe_head *sh; in raid5_sync_request() local
6277 sh = raid5_get_active_stripe(conf, sector_nr, 0, 1, 0); in raid5_sync_request()
6278 if (sh == NULL) { in raid5_sync_request()
6279 sh = raid5_get_active_stripe(conf, sector_nr, 0, 0, 0); in raid5_sync_request()
6300 set_bit(STRIPE_SYNC_REQUESTED, &sh->state); in raid5_sync_request()
6301 set_bit(STRIPE_HANDLE, &sh->state); in raid5_sync_request()
6303 raid5_release_stripe(sh); in raid5_sync_request()
6321 struct stripe_head *sh; in retry_aligned_read() local
6342 sh = raid5_get_active_stripe(conf, sector, 0, 1, 1); in retry_aligned_read()
6344 if (!sh) { in retry_aligned_read()
6351 if (!add_stripe_bio(sh, raid_bio, dd_idx, 0, 0)) { in retry_aligned_read()
6352 raid5_release_stripe(sh); in retry_aligned_read()
6358 set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); in retry_aligned_read()
6359 handle_stripe(sh); in retry_aligned_read()
6360 raid5_release_stripe(sh); in retry_aligned_read()
6377 struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; in handle_active_stripes() local
6382 (sh = __get_priority_stripe(conf, group)) != NULL) in handle_active_stripes()
6383 batch[batch_size++] = sh; in handle_active_stripes()