• Home
  • Raw
  • Download

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()
2868 if (sh->batch_head && sh != sh->batch_head) in raid5_end_write_request()
2869 raid5_release_stripe(sh->batch_head); in raid5_end_write_request()
2870 raid5_release_stripe(sh); in raid5_end_write_request()
2914 struct stripe_head *sh) in raid5_compute_sector() argument
3102 if (sh) { in raid5_compute_sector()
3103 sh->pd_idx = pd_idx; in raid5_compute_sector()
3104 sh->qd_idx = qd_idx; in raid5_compute_sector()
3105 sh->ddf_layout = ddf_layout; in raid5_compute_sector()
3114 sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous) in raid5_compute_blocknr() argument
3116 struct r5conf *conf = sh->raid_conf; in raid5_compute_blocknr()
3117 int raid_disks = sh->disks; in raid5_compute_blocknr()
3119 sector_t new_sector = sh->sector, check; in raid5_compute_blocknr()
3134 if (i == sh->pd_idx) in raid5_compute_blocknr()
3142 if (i > sh->pd_idx) in raid5_compute_blocknr()
3147 if (i < sh->pd_idx) in raid5_compute_blocknr()
3149 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3161 if (i == sh->qd_idx) in raid5_compute_blocknr()
3168 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3170 else if (i > sh->pd_idx) in raid5_compute_blocknr()
3175 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3179 if (i < sh->pd_idx) in raid5_compute_blocknr()
3181 i -= (sh->pd_idx + 2); in raid5_compute_blocknr()
3191 if (sh->pd_idx == 0) in raid5_compute_blocknr()
3195 if (i < sh->pd_idx) in raid5_compute_blocknr()
3197 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3202 if (i > sh->pd_idx) in raid5_compute_blocknr()
3207 if (i < sh->pd_idx) in raid5_compute_blocknr()
3209 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3225 if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx in raid5_compute_blocknr()
3226 || sh2.qd_idx != sh->qd_idx) { in raid5_compute_blocknr()
3291 schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, in schedule_reconstruction() argument
3294 int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx, disks = sh->disks; in schedule_reconstruction()
3295 struct r5conf *conf = sh->raid_conf; in schedule_reconstruction()
3305 r5c_release_extra_page(sh); in schedule_reconstruction()
3308 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3329 sh->reconstruct_state = reconstruct_state_drain_run; in schedule_reconstruction()
3332 sh->reconstruct_state = reconstruct_state_run; in schedule_reconstruction()
3337 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) in schedule_reconstruction()
3340 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || in schedule_reconstruction()
3341 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); in schedule_reconstruction()
3343 (!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) || in schedule_reconstruction()
3344 test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags)))); in schedule_reconstruction()
3347 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3366 sh->reconstruct_state = reconstruct_state_prexor_drain_run; in schedule_reconstruction()
3375 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3376 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3380 int qd_idx = sh->qd_idx; in schedule_reconstruction()
3381 struct r5dev *dev = &sh->dev[qd_idx]; in schedule_reconstruction()
3388 if (raid5_has_ppl(sh->raid_conf) && sh->ppl_page && in schedule_reconstruction()
3390 !test_bit(STRIPE_FULL_WRITE, &sh->state) && in schedule_reconstruction()
3391 test_bit(R5_Insync, &sh->dev[pd_idx].flags)) in schedule_reconstruction()
3395 __func__, (unsigned long long)sh->sector, in schedule_reconstruction()
3404 static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in add_stripe_bio() argument
3408 struct r5conf *conf = sh->raid_conf; in add_stripe_bio()
3413 (unsigned long long)sh->sector); in add_stripe_bio()
3415 spin_lock_irq(&sh->stripe_lock); in add_stripe_bio()
3416 sh->dev[dd_idx].write_hint = bi->bi_write_hint; in add_stripe_bio()
3418 if (sh->batch_head) in add_stripe_bio()
3421 bip = &sh->dev[dd_idx].towrite; in add_stripe_bio()
3425 bip = &sh->dev[dd_idx].toread; in add_stripe_bio()
3448 for (i = 0; i < sh->disks; i++) { in add_stripe_bio()
3449 if (i != sh->pd_idx && in add_stripe_bio()
3450 (i == dd_idx || sh->dev[i].towrite)) { in add_stripe_bio()
3451 sector = sh->dev[i].sector; in add_stripe_bio()
3465 clear_bit(STRIPE_BATCH_READY, &sh->state); in add_stripe_bio()
3476 sector_t sector = sh->dev[dd_idx].sector; in add_stripe_bio()
3477 for (bi=sh->dev[dd_idx].towrite; in add_stripe_bio()
3478 sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && in add_stripe_bio()
3480 bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { in add_stripe_bio()
3484 if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) in add_stripe_bio()
3485 if (!test_and_set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags)) in add_stripe_bio()
3486 sh->overwrite_disks++; in add_stripe_bio()
3491 (unsigned long long)sh->sector, dd_idx); in add_stripe_bio()
3506 set_bit(STRIPE_BITMAP_PENDING, &sh->state); in add_stripe_bio()
3507 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3508 md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, in add_stripe_bio()
3510 spin_lock_irq(&sh->stripe_lock); in add_stripe_bio()
3511 clear_bit(STRIPE_BITMAP_PENDING, &sh->state); in add_stripe_bio()
3512 if (!sh->batch_head) { in add_stripe_bio()
3513 sh->bm_seq = conf->seq_flush+1; in add_stripe_bio()
3514 set_bit(STRIPE_BIT_DELAY, &sh->state); in add_stripe_bio()
3517 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3519 if (stripe_can_batch(sh)) in add_stripe_bio()
3520 stripe_add_to_batch_list(conf, sh); in add_stripe_bio()
3524 set_bit(R5_Overlap, &sh->dev[dd_idx].flags); in add_stripe_bio()
3525 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3532 struct stripe_head *sh) in stripe_set_idx() argument
3544 &dd_idx, sh); in stripe_set_idx()
3548 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, in handle_failed_stripe() argument
3552 BUG_ON(sh->batch_head); in handle_failed_stripe()
3557 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { in handle_failed_stripe()
3570 sh->sector, in handle_failed_stripe()
3576 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3578 bi = sh->dev[i].towrite; in handle_failed_stripe()
3579 sh->dev[i].towrite = NULL; in handle_failed_stripe()
3580 sh->overwrite_disks = 0; in handle_failed_stripe()
3581 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3585 log_stripe_write_finished(sh); in handle_failed_stripe()
3587 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3591 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3592 struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3599 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3603 bi = sh->dev[i].written; in handle_failed_stripe()
3604 sh->dev[i].written = NULL; in handle_failed_stripe()
3605 if (test_and_clear_bit(R5_SkipCopy, &sh->dev[i].flags)) { in handle_failed_stripe()
3606 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_failed_stripe()
3607 sh->dev[i].page = sh->dev[i].orig_page; in handle_failed_stripe()
3612 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3613 struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3623 if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && in handle_failed_stripe()
3625 (!test_bit(R5_Insync, &sh->dev[i].flags) || in handle_failed_stripe()
3626 test_bit(R5_ReadError, &sh->dev[i].flags))) { in handle_failed_stripe()
3627 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3628 bi = sh->dev[i].toread; in handle_failed_stripe()
3629 sh->dev[i].toread = NULL; in handle_failed_stripe()
3630 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3631 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3636 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3638 r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3645 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3650 clear_bit(R5_LOCKED, &sh->dev[i].flags); in handle_failed_stripe()
3655 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_failed_stripe()
3661 handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, in handle_failed_sync() argument
3667 BUG_ON(sh->batch_head); in handle_failed_sync()
3668 clear_bit(STRIPE_SYNCING, &sh->state); in handle_failed_sync()
3669 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_failed_sync()
3690 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3697 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3709 static int want_replace(struct stripe_head *sh, int disk_idx) in want_replace() argument
3715 rdev = rcu_dereference(sh->raid_conf->disks[disk_idx].replacement); in want_replace()
3719 && (rdev->recovery_offset <= sh->sector in want_replace()
3720 || rdev->mddev->recovery_cp <= sh->sector)) in want_replace()
3726 static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s, in need_this_block() argument
3729 struct r5dev *dev = &sh->dev[disk_idx]; in need_this_block()
3730 struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], in need_this_block()
3731 &sh->dev[s->failed_num[1]] }; in need_this_block()
3733 bool force_rcw = (sh->raid_conf->rmw_level == PARITY_DISABLE_RMW); in need_this_block()
3749 (s->replacing && want_replace(sh, disk_idx))) in need_this_block()
3774 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in need_this_block()
3795 s->failed_num[i] == sh->pd_idx || in need_this_block()
3796 s->failed_num[i] == sh->qd_idx) && in need_this_block()
3813 sh->sector < sh->raid_conf->mddev->recovery_cp) in need_this_block()
3817 if (s->failed_num[i] != sh->pd_idx && in need_this_block()
3818 s->failed_num[i] != sh->qd_idx && in need_this_block()
3833 static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, in fetch_block() argument
3836 struct r5dev *dev = &sh->dev[disk_idx]; in fetch_block()
3839 if (need_this_block(sh, s, disk_idx, disks)) { in fetch_block()
3845 BUG_ON(sh->batch_head); in fetch_block()
3857 ((sh->qd_idx >= 0 && sh->pd_idx == disk_idx) || in fetch_block()
3864 (unsigned long long)sh->sector, disk_idx); in fetch_block()
3865 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3868 sh->ops.target = disk_idx; in fetch_block()
3869 sh->ops.target2 = -1; /* no 2nd target */ in fetch_block()
3888 &sh->dev[other].flags)) in fetch_block()
3893 (unsigned long long)sh->sector, in fetch_block()
3895 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3897 set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); in fetch_block()
3898 set_bit(R5_Wantcompute, &sh->dev[other].flags); in fetch_block()
3899 sh->ops.target = disk_idx; in fetch_block()
3900 sh->ops.target2 = other; in fetch_block()
3919 static void handle_stripe_fill(struct stripe_head *sh, in handle_stripe_fill() argument
3929 if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && in handle_stripe_fill()
3930 !sh->reconstruct_state) { in handle_stripe_fill()
3940 if (test_bit(STRIPE_R5C_CACHING, &sh->state)) in handle_stripe_fill()
3941 r5c_make_stripe_write_out(sh); in handle_stripe_fill()
3946 if (fetch_block(sh, s, i, disks)) in handle_stripe_fill()
3950 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_fill()
3961 struct stripe_head *sh, int disks) in handle_stripe_clean_event() argument
3966 struct stripe_head *head_sh = sh; in handle_stripe_clean_event()
3970 if (sh->dev[i].written) { in handle_stripe_clean_event()
3971 dev = &sh->dev[i]; in handle_stripe_clean_event()
3997 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_stripe_clean_event()
3999 !test_bit(STRIPE_DEGRADED, &sh->state), in handle_stripe_clean_event()
4002 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4005 if (sh != head_sh) { in handle_stripe_clean_event()
4006 dev = &sh->dev[i]; in handle_stripe_clean_event()
4010 sh = head_sh; in handle_stripe_clean_event()
4011 dev = &sh->dev[i]; in handle_stripe_clean_event()
4016 log_stripe_write_finished(sh); in handle_stripe_clean_event()
4019 test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_clean_event()
4021 clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4022 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4023 if (sh->qd_idx >= 0) { in handle_stripe_clean_event()
4024 clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4025 clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4028 clear_bit(STRIPE_DISCARD, &sh->state); in handle_stripe_clean_event()
4035 hash = sh->hash_lock_index; in handle_stripe_clean_event()
4037 remove_hash(sh); in handle_stripe_clean_event()
4040 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4042 if (sh != head_sh) in handle_stripe_clean_event()
4045 sh = head_sh; in handle_stripe_clean_event()
4047 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) in handle_stripe_clean_event()
4048 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_clean_event()
4052 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_stripe_clean_event()
4076 struct stripe_head *sh, in handle_stripe_dirtying() argument
4091 (recovery_cp < MaxSector && sh->sector >= recovery_cp && in handle_stripe_dirtying()
4097 pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n", in handle_stripe_dirtying()
4099 (unsigned long long)sh->sector); in handle_stripe_dirtying()
4102 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4104 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4116 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4128 (unsigned long long)sh->sector, sh->state, rmw, rcw); in handle_stripe_dirtying()
4129 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_dirtying()
4135 (unsigned long long)sh->sector, rmw); in handle_stripe_dirtying()
4137 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4140 !test_bit(R5_LOCKED, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_dirtying()
4155 r5c_use_extra_page(sh); in handle_stripe_dirtying()
4160 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4167 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4169 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4176 &sh->state)) { in handle_stripe_dirtying()
4183 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4192 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4194 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4201 &sh->state)) { in handle_stripe_dirtying()
4209 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4214 (unsigned long long)sh->sector, in handle_stripe_dirtying()
4215 rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); in handle_stripe_dirtying()
4219 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe_dirtying()
4220 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4232 if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && in handle_stripe_dirtying()
4234 !test_bit(STRIPE_BIT_DELAY, &sh->state))) in handle_stripe_dirtying()
4235 schedule_reconstruction(sh, s, rcw == 0, 0); in handle_stripe_dirtying()
4239 static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks5() argument
4244 BUG_ON(sh->batch_head); in handle_parity_checks5()
4245 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks5()
4247 switch (sh->check_state) { in handle_parity_checks5()
4252 sh->check_state = check_state_run; in handle_parity_checks5()
4254 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4258 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks5()
4261 sh->check_state = check_state_idle; in handle_parity_checks5()
4263 dev = &sh->dev[sh->pd_idx]; in handle_parity_checks5()
4266 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks5()
4277 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks5()
4278 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4283 sh->check_state = check_state_idle; in handle_parity_checks5()
4295 if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) in handle_parity_checks5()
4299 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4304 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4307 (unsigned long long) sh->sector, in handle_parity_checks5()
4308 (unsigned long long) sh->sector + in handle_parity_checks5()
4311 sh->check_state = check_state_compute_run; in handle_parity_checks5()
4312 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks5()
4315 &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4316 sh->ops.target = sh->pd_idx; in handle_parity_checks5()
4317 sh->ops.target2 = -1; in handle_parity_checks5()
4326 __func__, sh->check_state, in handle_parity_checks5()
4327 (unsigned long long) sh->sector); in handle_parity_checks5()
4332 static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks6() argument
4336 int pd_idx = sh->pd_idx; in handle_parity_checks6()
4337 int qd_idx = sh->qd_idx; in handle_parity_checks6()
4340 BUG_ON(sh->batch_head); in handle_parity_checks6()
4341 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks6()
4351 switch (sh->check_state) { in handle_parity_checks6()
4359 sh->check_state = check_state_run; in handle_parity_checks6()
4365 if (sh->check_state == check_state_run) in handle_parity_checks6()
4366 sh->check_state = check_state_run_pq; in handle_parity_checks6()
4368 sh->check_state = check_state_run_q; in handle_parity_checks6()
4372 sh->ops.zero_sum_result = 0; in handle_parity_checks6()
4374 if (sh->check_state == check_state_run) { in handle_parity_checks6()
4376 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in handle_parity_checks6()
4379 if (sh->check_state >= check_state_run && in handle_parity_checks6()
4380 sh->check_state <= check_state_run_pq) { in handle_parity_checks6()
4392 sh->check_state = check_state_idle; in handle_parity_checks6()
4395 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks6()
4403 dev = &sh->dev[s->failed_num[1]]; in handle_parity_checks6()
4409 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks6()
4414 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4415 dev = &sh->dev[pd_idx]; in handle_parity_checks6()
4420 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4421 dev = &sh->dev[qd_idx]; in handle_parity_checks6()
4429 dev - (struct r5dev *) &sh->dev)) { in handle_parity_checks6()
4434 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks6()
4436 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4443 sh->check_state = check_state_idle; in handle_parity_checks6()
4449 if (sh->ops.zero_sum_result == 0) { in handle_parity_checks6()
4452 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4458 sh->check_state = check_state_compute_result; in handle_parity_checks6()
4469 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4472 (unsigned long long) sh->sector, in handle_parity_checks6()
4473 (unsigned long long) sh->sector + in handle_parity_checks6()
4476 int *target = &sh->ops.target; in handle_parity_checks6()
4478 sh->ops.target = -1; in handle_parity_checks6()
4479 sh->ops.target2 = -1; in handle_parity_checks6()
4480 sh->check_state = check_state_compute_run; in handle_parity_checks6()
4481 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks6()
4483 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4485 &sh->dev[pd_idx].flags); in handle_parity_checks6()
4487 target = &sh->ops.target2; in handle_parity_checks6()
4490 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4492 &sh->dev[qd_idx].flags); in handle_parity_checks6()
4503 __func__, sh->check_state, in handle_parity_checks6()
4504 (unsigned long long) sh->sector); in handle_parity_checks6()
4509 static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) in handle_stripe_expansion() argument
4517 BUG_ON(sh->batch_head); in handle_stripe_expansion()
4518 clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); in handle_stripe_expansion()
4519 for (i = 0; i < sh->disks; i++) in handle_stripe_expansion()
4520 if (i != sh->pd_idx && i != sh->qd_idx) { in handle_stripe_expansion()
4525 sector_t bn = raid5_compute_blocknr(sh, i, 1); in handle_stripe_expansion()
4545 sh->dev[i].page, sh2->dev[dd_idx].offset, in handle_stripe_expansion()
4546 sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), in handle_stripe_expansion()
4581 static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) in analyse_stripe() argument
4583 struct r5conf *conf = sh->raid_conf; in analyse_stripe()
4584 int disks = sh->disks; in analyse_stripe()
4591 s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state) && !sh->batch_head; in analyse_stripe()
4592 s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state) && !sh->batch_head; in analyse_stripe()
4605 dev = &sh->dev[i]; in analyse_stripe()
4616 !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) in analyse_stripe()
4645 rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && in analyse_stripe()
4646 !is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4660 is_bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4687 else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) in analyse_stripe()
4757 if (test_bit(STRIPE_SYNCING, &sh->state)) { in analyse_stripe()
4767 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4780 static int clear_batch_ready(struct stripe_head *sh) in clear_batch_ready() argument
4783 if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) in clear_batch_ready()
4784 return (sh->batch_head && sh->batch_head != sh); in clear_batch_ready()
4785 spin_lock(&sh->stripe_lock); in clear_batch_ready()
4786 if (!sh->batch_head) { in clear_batch_ready()
4787 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4795 if (sh->batch_head != sh) { in clear_batch_ready()
4796 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4799 spin_lock(&sh->batch_lock); in clear_batch_ready()
4800 list_for_each_entry(tmp, &sh->batch_list, batch_list) in clear_batch_ready()
4802 spin_unlock(&sh->batch_lock); in clear_batch_ready()
4803 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4815 struct stripe_head *sh, *next; in break_stripe_batch_list() local
4819 list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { in break_stripe_batch_list()
4821 list_del_init(&sh->batch_list); in break_stripe_batch_list()
4823 WARN_ONCE(sh->state & ((1 << STRIPE_ACTIVE) | in break_stripe_batch_list()
4835 "stripe state: %lx\n", sh->state); in break_stripe_batch_list()
4840 set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | in break_stripe_batch_list()
4846 sh->check_state = head_sh->check_state; in break_stripe_batch_list()
4847 sh->reconstruct_state = head_sh->reconstruct_state; in break_stripe_batch_list()
4848 spin_lock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4849 sh->batch_head = NULL; in break_stripe_batch_list()
4850 spin_unlock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4851 for (i = 0; i < sh->disks; i++) { in break_stripe_batch_list()
4852 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in break_stripe_batch_list()
4854 sh->dev[i].flags = head_sh->dev[i].flags & in break_stripe_batch_list()
4858 sh->state & handle_flags) in break_stripe_batch_list()
4859 set_bit(STRIPE_HANDLE, &sh->state); in break_stripe_batch_list()
4860 raid5_release_stripe(sh); in break_stripe_batch_list()
4875 static void handle_stripe(struct stripe_head *sh) in handle_stripe() argument
4878 struct r5conf *conf = sh->raid_conf; in handle_stripe()
4881 int disks = sh->disks; in handle_stripe()
4884 clear_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4892 if (clear_batch_ready(sh)) in handle_stripe()
4895 if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { in handle_stripe()
4898 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4902 if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) in handle_stripe()
4903 break_stripe_batch_list(sh, 0); in handle_stripe()
4905 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { in handle_stripe()
4906 spin_lock(&sh->stripe_lock); in handle_stripe()
4911 if (!test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state) && in handle_stripe()
4912 !test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) && in handle_stripe()
4913 !test_bit(STRIPE_DISCARD, &sh->state) && in handle_stripe()
4914 test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { in handle_stripe()
4915 set_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
4916 clear_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
4917 clear_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
4919 spin_unlock(&sh->stripe_lock); in handle_stripe()
4921 clear_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
4925 (unsigned long long)sh->sector, sh->state, in handle_stripe()
4926 atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, in handle_stripe()
4927 sh->check_state, sh->reconstruct_state); in handle_stripe()
4929 analyse_stripe(sh, &s); in handle_stripe()
4931 if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) in handle_stripe()
4936 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4943 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4951 if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { in handle_stripe()
4953 set_bit(STRIPE_BIOFILL_RUN, &sh->state); in handle_stripe()
4969 sh->check_state = 0; in handle_stripe()
4970 sh->reconstruct_state = 0; in handle_stripe()
4971 break_stripe_batch_list(sh, 0); in handle_stripe()
4973 handle_failed_stripe(conf, sh, &s, disks); in handle_stripe()
4975 handle_failed_sync(conf, sh, &s); in handle_stripe()
4982 if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) in handle_stripe()
4984 if (sh->reconstruct_state == reconstruct_state_drain_result || in handle_stripe()
4985 sh->reconstruct_state == reconstruct_state_prexor_drain_result) { in handle_stripe()
4986 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
4991 BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && in handle_stripe()
4992 !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); in handle_stripe()
4993 BUG_ON(sh->qd_idx >= 0 && in handle_stripe()
4994 !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && in handle_stripe()
4995 !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); in handle_stripe()
4997 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
4999 (i == sh->pd_idx || i == sh->qd_idx || in handle_stripe()
5009 ((i == sh->pd_idx || i == sh->qd_idx) && in handle_stripe()
5011 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5014 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe()
5022 pdev = &sh->dev[sh->pd_idx]; in handle_stripe()
5023 s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) in handle_stripe()
5024 || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); in handle_stripe()
5025 qdev = &sh->dev[sh->qd_idx]; in handle_stripe()
5026 s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) in handle_stripe()
5027 || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) in handle_stripe()
5039 handle_stripe_clean_event(conf, sh, disks); in handle_stripe()
5042 r5c_handle_cached_data_endio(conf, sh, disks); in handle_stripe()
5043 log_stripe_write_finished(sh); in handle_stripe()
5054 handle_stripe_fill(sh, &s, disks); in handle_stripe()
5061 r5c_finish_stripe_write_out(conf, sh, &s); in handle_stripe()
5072 if (!sh->reconstruct_state && !sh->check_state && !sh->log_io) { in handle_stripe()
5075 handle_stripe_dirtying(conf, sh, &s, disks); in handle_stripe()
5081 ret = r5c_try_caching_write(conf, sh, &s, in handle_stripe()
5092 (!test_bit(STRIPE_R5C_CACHING, &sh->state) && in handle_stripe()
5094 ret = handle_stripe_dirtying(conf, sh, &s, in handle_stripe()
5107 if (sh->check_state || in handle_stripe()
5109 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5110 !test_bit(STRIPE_INSYNC, &sh->state))) { in handle_stripe()
5112 handle_parity_checks6(conf, sh, &s, disks); in handle_stripe()
5114 handle_parity_checks5(conf, sh, &s, disks); in handle_stripe()
5118 && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) in handle_stripe()
5119 && !test_bit(STRIPE_REPLACED, &sh->state)) { in handle_stripe()
5122 if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { in handle_stripe()
5123 WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_stripe()
5124 set_bit(R5_WantReplace, &sh->dev[i].flags); in handle_stripe()
5125 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5129 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5130 set_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
5133 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5134 test_bit(STRIPE_INSYNC, &sh->state)) { in handle_stripe()
5136 clear_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
5137 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_stripe()
5146 struct r5dev *dev = &sh->dev[s.failed_num[i]]; in handle_stripe()
5163 if (sh->reconstruct_state == reconstruct_state_result) { in handle_stripe()
5165 = raid5_get_active_stripe(conf, sh->sector, 1, 1, 1); in handle_stripe()
5167 /* sh cannot be written until sh_src has been read. in handle_stripe()
5168 * so arrange for sh to be delayed a little in handle_stripe()
5170 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
5171 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
5181 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
5182 clear_bit(STRIPE_EXPANDING, &sh->state); in handle_stripe()
5184 set_bit(R5_Wantwrite, &sh->dev[i].flags); in handle_stripe()
5185 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5190 if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && in handle_stripe()
5191 !sh->reconstruct_state) { in handle_stripe()
5193 sh->disks = conf->raid_disks; in handle_stripe()
5194 stripe_set_idx(sh->sector, conf, 0, sh); in handle_stripe()
5195 schedule_reconstruction(sh, &s, 1, 1); in handle_stripe()
5196 } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { in handle_stripe()
5197 clear_bit(STRIPE_EXPAND_READY, &sh->state); in handle_stripe()
5204 !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) in handle_stripe()
5205 handle_stripe_expansion(conf, sh); in handle_stripe()
5225 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
5229 if (!rdev_set_badblocks(rdev, sh->sector, in handle_stripe()
5236 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5245 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5252 raid_run_ops(sh, s.ops_request); in handle_stripe()
5254 ops_run_io(sh, &s); in handle_stripe()
5267 clear_bit_unlock(STRIPE_ACTIVE, &sh->state); in handle_stripe()
5275 struct stripe_head *sh; in raid5_activate_delayed() local
5276 sh = list_entry(l, struct stripe_head, lru); in raid5_activate_delayed()
5278 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_activate_delayed()
5279 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_activate_delayed()
5281 list_add_tail(&sh->lru, &conf->hold_list); in raid5_activate_delayed()
5282 raid5_wakeup_stripe_thread(sh); in raid5_activate_delayed()
5295 struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); in activate_bit_delay() local
5297 list_del_init(&sh->lru); in activate_bit_delay()
5298 atomic_inc(&sh->count); in activate_bit_delay()
5299 hash = sh->hash_lock_index; in activate_bit_delay()
5300 __release_stripe(conf, sh, &temp_inactive_list[hash]); in activate_bit_delay()
5514 struct stripe_head *sh, *tmp; in __get_priority_stripe() local
5524 sh = NULL; in __get_priority_stripe()
5550 sh = list_entry(handle_list->next, typeof(*sh), lru); in __get_priority_stripe()
5554 else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { in __get_priority_stripe()
5574 sh = tmp; in __get_priority_stripe()
5579 if (sh) { in __get_priority_stripe()
5587 if (!sh) { in __get_priority_stripe()
5597 sh->group = NULL; in __get_priority_stripe()
5599 list_del_init(&sh->lru); in __get_priority_stripe()
5600 BUG_ON(atomic_inc_return(&sh->count) != 1); in __get_priority_stripe()
5601 return sh; in __get_priority_stripe()
5614 struct stripe_head *sh; in raid5_unplug() local
5623 sh = list_first_entry(&cb->list, struct stripe_head, lru); in raid5_unplug()
5624 list_del_init(&sh->lru); in raid5_unplug()
5631 clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); in raid5_unplug()
5636 hash = sh->hash_lock_index; in raid5_unplug()
5637 __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); in raid5_unplug()
5650 struct stripe_head *sh) in release_stripe_plug() argument
5658 raid5_release_stripe(sh); in release_stripe_plug()
5671 if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) in release_stripe_plug()
5672 list_add_tail(&sh->lru, &cb->list); in release_stripe_plug()
5674 raid5_release_stripe(sh); in release_stripe_plug()
5681 struct stripe_head *sh; in make_discard_request() local
5707 sh = raid5_get_active_stripe(conf, logical_sector, 0, 0, 0); in make_discard_request()
5710 set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5711 if (test_bit(STRIPE_SYNCING, &sh->state)) { in make_discard_request()
5712 raid5_release_stripe(sh); in make_discard_request()
5716 clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5717 spin_lock_irq(&sh->stripe_lock); in make_discard_request()
5719 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5721 if (sh->dev[d].towrite || sh->dev[d].toread) { in make_discard_request()
5722 set_bit(R5_Overlap, &sh->dev[d].flags); in make_discard_request()
5723 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5724 raid5_release_stripe(sh); in make_discard_request()
5729 set_bit(STRIPE_DISCARD, &sh->state); in make_discard_request()
5731 sh->overwrite_disks = 0; in make_discard_request()
5733 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5735 sh->dev[d].towrite = bi; in make_discard_request()
5736 set_bit(R5_OVERWRITE, &sh->dev[d].flags); in make_discard_request()
5739 sh->overwrite_disks++; in make_discard_request()
5741 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5747 sh->sector, in make_discard_request()
5750 sh->bm_seq = conf->seq_flush + 1; in make_discard_request()
5751 set_bit(STRIPE_BIT_DELAY, &sh->state); in make_discard_request()
5754 set_bit(STRIPE_HANDLE, &sh->state); in make_discard_request()
5755 clear_bit(STRIPE_DELAYED, &sh->state); in make_discard_request()
5756 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in make_discard_request()
5758 release_stripe_plug(mddev, sh); in make_discard_request()
5770 struct stripe_head *sh; in raid5_make_request() local
5863 sh = raid5_get_active_stripe(conf, new_sector, previous, in raid5_make_request()
5865 if (sh) { in raid5_make_request()
5871 * 'sh', we know that if that happens, in raid5_make_request()
5884 raid5_release_stripe(sh); in raid5_make_request()
5894 raid5_release_stripe(sh); in raid5_make_request()
5898 if (test_bit(STRIPE_EXPANDING, &sh->state) || in raid5_make_request()
5899 !add_stripe_bio(sh, bi, dd_idx, rw, previous)) { in raid5_make_request()
5905 raid5_release_stripe(sh); in raid5_make_request()
5911 set_bit(STRIPE_R5C_PREFLUSH, &sh->state); in raid5_make_request()
5916 set_bit(STRIPE_HANDLE, &sh->state); in raid5_make_request()
5917 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_make_request()
5918 if ((!sh->batch_head || sh == sh->batch_head) && in raid5_make_request()
5920 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_make_request()
5922 release_stripe_plug(mddev, sh); in raid5_make_request()
5951 struct stripe_head *sh; in reshape_request() local
6102 sh = raid5_get_active_stripe(conf, stripe_addr+i, 0, 0, 1); in reshape_request()
6103 set_bit(STRIPE_EXPANDING, &sh->state); in reshape_request()
6108 for (j=sh->disks; j--;) { in reshape_request()
6110 if (j == sh->pd_idx) in reshape_request()
6113 j == sh->qd_idx) in reshape_request()
6115 s = raid5_compute_blocknr(sh, j, 0); in reshape_request()
6120 memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); in reshape_request()
6121 set_bit(R5_Expanded, &sh->dev[j].flags); in reshape_request()
6122 set_bit(R5_UPTODATE, &sh->dev[j].flags); in reshape_request()
6125 set_bit(STRIPE_EXPAND_READY, &sh->state); in reshape_request()
6126 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6128 list_add(&sh->lru, &stripes); in reshape_request()
6151 sh = raid5_get_active_stripe(conf, first_sector, 1, 0, 1); in reshape_request()
6152 set_bit(STRIPE_EXPAND_SOURCE, &sh->state); in reshape_request()
6153 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6154 raid5_release_stripe(sh); in reshape_request()
6161 sh = list_entry(stripes.next, struct stripe_head, lru); in reshape_request()
6162 list_del_init(&sh->lru); in reshape_request()
6163 raid5_release_stripe(sh); in reshape_request()
6212 struct stripe_head *sh; in raid5_sync_request() local
6271 sh = raid5_get_active_stripe(conf, sector_nr, 0, 1, 0); in raid5_sync_request()
6272 if (sh == NULL) { in raid5_sync_request()
6273 sh = raid5_get_active_stripe(conf, sector_nr, 0, 0, 0); in raid5_sync_request()
6294 set_bit(STRIPE_SYNC_REQUESTED, &sh->state); in raid5_sync_request()
6295 set_bit(STRIPE_HANDLE, &sh->state); in raid5_sync_request()
6297 raid5_release_stripe(sh); in raid5_sync_request()
6315 struct stripe_head *sh; in retry_aligned_read() local
6336 sh = raid5_get_active_stripe(conf, sector, 0, 1, 1); in retry_aligned_read()
6338 if (!sh) { in retry_aligned_read()
6345 if (!add_stripe_bio(sh, raid_bio, dd_idx, 0, 0)) { in retry_aligned_read()
6346 raid5_release_stripe(sh); in retry_aligned_read()
6352 set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); in retry_aligned_read()
6353 handle_stripe(sh); in retry_aligned_read()
6354 raid5_release_stripe(sh); in retry_aligned_read()
6371 struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; in handle_active_stripes() local
6376 (sh = __get_priority_stripe(conf, group)) != NULL) in handle_active_stripes()
6377 batch[batch_size++] = sh; in handle_active_stripes()