Lines Matching full:sh
26 * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq
120 static inline int raid6_d0(struct stripe_head *sh) in raid6_d0() argument
122 if (sh->ddf_layout) in raid6_d0()
126 if (sh->qd_idx == sh->disks - 1) in raid6_d0()
129 return sh->qd_idx + 1; in raid6_d0()
142 static int raid6_idx_to_slot(int idx, struct stripe_head *sh, in raid6_idx_to_slot() argument
147 if (sh->ddf_layout) in raid6_idx_to_slot()
149 if (idx == sh->pd_idx) in raid6_idx_to_slot()
151 if (idx == sh->qd_idx) in raid6_idx_to_slot()
153 if (!sh->ddf_layout) in raid6_idx_to_slot()
160 static int stripe_operations_active(struct stripe_head *sh) in stripe_operations_active() argument
162 return sh->check_state || sh->reconstruct_state || in stripe_operations_active()
163 test_bit(STRIPE_BIOFILL_RUN, &sh->state) || in stripe_operations_active()
164 test_bit(STRIPE_COMPUTE_RUN, &sh->state); in stripe_operations_active()
167 static bool stripe_is_lowprio(struct stripe_head *sh) in stripe_is_lowprio() argument
169 return (test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) || in stripe_is_lowprio()
170 test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) && in stripe_is_lowprio()
171 !test_bit(STRIPE_R5C_CACHING, &sh->state); in stripe_is_lowprio()
174 static void raid5_wakeup_stripe_thread(struct stripe_head *sh) in raid5_wakeup_stripe_thread() argument
175 __must_hold(&sh->raid_conf->device_lock) in raid5_wakeup_stripe_thread()
177 struct r5conf *conf = sh->raid_conf; in raid5_wakeup_stripe_thread()
180 int i, cpu = sh->cpu; in raid5_wakeup_stripe_thread()
184 sh->cpu = cpu; in raid5_wakeup_stripe_thread()
187 if (list_empty(&sh->lru)) { in raid5_wakeup_stripe_thread()
190 if (stripe_is_lowprio(sh)) in raid5_wakeup_stripe_thread()
191 list_add_tail(&sh->lru, &group->loprio_list); in raid5_wakeup_stripe_thread()
193 list_add_tail(&sh->lru, &group->handle_list); in raid5_wakeup_stripe_thread()
195 sh->group = group; in raid5_wakeup_stripe_thread()
203 group = conf->worker_groups + cpu_to_group(sh->cpu); in raid5_wakeup_stripe_thread()
207 queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); in raid5_wakeup_stripe_thread()
214 queue_work_on(sh->cpu, raid5_wq, in raid5_wakeup_stripe_thread()
221 static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, in do_release_stripe() argument
228 BUG_ON(!list_empty(&sh->lru)); in do_release_stripe()
232 for (i = sh->disks; i--; ) in do_release_stripe()
233 if (test_bit(R5_InJournal, &sh->dev[i].flags)) in do_release_stripe()
242 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) || in do_release_stripe()
244 !test_bit(STRIPE_HANDLE, &sh->state) && injournal != 0)) { in do_release_stripe()
245 if (test_bit(STRIPE_R5C_CACHING, &sh->state)) in do_release_stripe()
246 r5c_make_stripe_write_out(sh); in do_release_stripe()
247 set_bit(STRIPE_HANDLE, &sh->state); in do_release_stripe()
250 if (test_bit(STRIPE_HANDLE, &sh->state)) { in do_release_stripe()
251 if (test_bit(STRIPE_DELAYED, &sh->state) && in do_release_stripe()
252 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in do_release_stripe()
253 list_add_tail(&sh->lru, &conf->delayed_list); in do_release_stripe()
254 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && in do_release_stripe()
255 sh->bm_seq - conf->seq_write > 0) in do_release_stripe()
256 list_add_tail(&sh->lru, &conf->bitmap_list); in do_release_stripe()
258 clear_bit(STRIPE_DELAYED, &sh->state); in do_release_stripe()
259 clear_bit(STRIPE_BIT_DELAY, &sh->state); in do_release_stripe()
261 if (stripe_is_lowprio(sh)) in do_release_stripe()
262 list_add_tail(&sh->lru, in do_release_stripe()
265 list_add_tail(&sh->lru, in do_release_stripe()
268 raid5_wakeup_stripe_thread(sh); in do_release_stripe()
274 BUG_ON(stripe_operations_active(sh)); in do_release_stripe()
275 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in do_release_stripe()
280 if (!test_bit(STRIPE_EXPANDING, &sh->state)) { in do_release_stripe()
282 list_add_tail(&sh->lru, temp_inactive_list); in do_release_stripe()
284 WARN_ON(test_bit(R5_InJournal, &sh->dev[sh->pd_idx].flags)); in do_release_stripe()
286 list_add_tail(&sh->lru, temp_inactive_list); in do_release_stripe()
289 if (!test_and_set_bit(STRIPE_R5C_FULL_STRIPE, &sh->state)) in do_release_stripe()
291 if (test_and_clear_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) in do_release_stripe()
293 list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); in do_release_stripe()
301 list_add_tail(&sh->lru, &conf->r5c_partial_stripe_list); in do_release_stripe()
307 static void __release_stripe(struct r5conf *conf, struct stripe_head *sh, in __release_stripe() argument
311 if (atomic_dec_and_test(&sh->count)) in __release_stripe()
312 do_release_stripe(conf, sh, temp_inactive_list); in __release_stripe()
368 struct stripe_head *sh, *t; in release_stripe_list() local
374 llist_for_each_entry_safe(sh, t, head, release_list) { in release_stripe_list()
377 /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ in release_stripe_list()
379 clear_bit(STRIPE_ON_RELEASE_LIST, &sh->state); in release_stripe_list()
385 hash = sh->hash_lock_index; in release_stripe_list()
386 __release_stripe(conf, sh, &temp_inactive_list[hash]); in release_stripe_list()
393 void raid5_release_stripe(struct stripe_head *sh) in raid5_release_stripe() argument
395 struct r5conf *conf = sh->raid_conf; in raid5_release_stripe()
403 if (atomic_add_unless(&sh->count, -1, 1)) in raid5_release_stripe()
407 test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state)) in raid5_release_stripe()
409 wakeup = llist_add(&sh->release_list, &conf->released_stripes); in raid5_release_stripe()
415 if (atomic_dec_and_lock_irqsave(&sh->count, &conf->device_lock, flags)) { in raid5_release_stripe()
417 hash = sh->hash_lock_index; in raid5_release_stripe()
418 do_release_stripe(conf, sh, &list); in raid5_release_stripe()
424 static inline void remove_hash(struct stripe_head *sh) in remove_hash() argument
427 (unsigned long long)sh->sector); in remove_hash()
429 hlist_del_init(&sh->hash); in remove_hash()
432 static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) in insert_hash() argument
434 struct hlist_head *hp = stripe_hash(conf, sh->sector); in insert_hash()
437 (unsigned long long)sh->sector); in insert_hash()
439 hlist_add_head(&sh->hash, hp); in insert_hash()
445 struct stripe_head *sh = NULL; in get_free_stripe() local
451 sh = list_entry(first, struct stripe_head, lru); in get_free_stripe()
453 remove_hash(sh); in get_free_stripe()
455 BUG_ON(hash != sh->hash_lock_index); in get_free_stripe()
459 return sh; in get_free_stripe()
463 static void free_stripe_pages(struct stripe_head *sh) in free_stripe_pages() argument
469 if (!sh->pages) in free_stripe_pages()
472 for (i = 0; i < sh->nr_pages; i++) { in free_stripe_pages()
473 p = sh->pages[i]; in free_stripe_pages()
476 sh->pages[i] = NULL; in free_stripe_pages()
480 static int alloc_stripe_pages(struct stripe_head *sh, gfp_t gfp) in alloc_stripe_pages() argument
485 for (i = 0; i < sh->nr_pages; i++) { in alloc_stripe_pages()
487 if (sh->pages[i]) in alloc_stripe_pages()
492 free_stripe_pages(sh); in alloc_stripe_pages()
495 sh->pages[i] = p; in alloc_stripe_pages()
501 init_stripe_shared_pages(struct stripe_head *sh, struct r5conf *conf, int disks) in init_stripe_shared_pages() argument
505 if (sh->pages) in init_stripe_shared_pages()
508 /* Each of the sh->dev[i] need one conf->stripe_size */ in init_stripe_shared_pages()
512 sh->pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); in init_stripe_shared_pages()
513 if (!sh->pages) in init_stripe_shared_pages()
515 sh->nr_pages = nr_pages; in init_stripe_shared_pages()
516 sh->stripes_per_page = cnt; in init_stripe_shared_pages()
521 static void shrink_buffers(struct stripe_head *sh) in shrink_buffers() argument
524 int num = sh->raid_conf->pool_size; in shrink_buffers()
530 WARN_ON(sh->dev[i].page != sh->dev[i].orig_page); in shrink_buffers()
531 p = sh->dev[i].page; in shrink_buffers()
534 sh->dev[i].page = NULL; in shrink_buffers()
539 sh->dev[i].page = NULL; in shrink_buffers()
540 free_stripe_pages(sh); /* Free pages */ in shrink_buffers()
544 static int grow_buffers(struct stripe_head *sh, gfp_t gfp) in grow_buffers() argument
547 int num = sh->raid_conf->pool_size; in grow_buffers()
556 sh->dev[i].page = page; in grow_buffers()
557 sh->dev[i].orig_page = page; in grow_buffers()
558 sh->dev[i].offset = 0; in grow_buffers()
561 if (alloc_stripe_pages(sh, gfp)) in grow_buffers()
565 sh->dev[i].page = raid5_get_dev_page(sh, i); in grow_buffers()
566 sh->dev[i].orig_page = sh->dev[i].page; in grow_buffers()
567 sh->dev[i].offset = raid5_get_page_offset(sh, i); in grow_buffers()
574 struct stripe_head *sh);
576 static void init_stripe(struct stripe_head *sh, sector_t sector, int previous) in init_stripe() argument
578 struct r5conf *conf = sh->raid_conf; in init_stripe()
581 BUG_ON(atomic_read(&sh->count) != 0); in init_stripe()
582 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); in init_stripe()
583 BUG_ON(stripe_operations_active(sh)); in init_stripe()
584 BUG_ON(sh->batch_head); in init_stripe()
590 sh->generation = conf->generation - previous; in init_stripe()
591 sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; in init_stripe()
592 sh->sector = sector; in init_stripe()
593 stripe_set_idx(sector, conf, previous, sh); in init_stripe()
594 sh->state = 0; in init_stripe()
596 for (i = sh->disks; i--; ) { in init_stripe()
597 struct r5dev *dev = &sh->dev[i]; in init_stripe()
602 (unsigned long long)sh->sector, i, dev->toread, in init_stripe()
608 dev->sector = raid5_compute_blocknr(sh, i, previous); in init_stripe()
612 sh->overwrite_disks = 0; in init_stripe()
613 insert_hash(conf, sh); in init_stripe()
614 sh->cpu = smp_processor_id(); in init_stripe()
615 set_bit(STRIPE_BATCH_READY, &sh->state); in init_stripe()
621 struct stripe_head *sh; in __find_stripe() local
624 hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) in __find_stripe()
625 if (sh->sector == sector && sh->generation == generation) in __find_stripe()
626 return sh; in __find_stripe()
635 struct stripe_head *sh; in find_get_stripe() local
637 sh = __find_stripe(conf, sector, generation); in find_get_stripe()
638 if (!sh) in find_get_stripe()
641 if (atomic_inc_not_zero(&sh->count)) in find_get_stripe()
642 return sh; in find_get_stripe()
646 * be on a list (sh->lru). Must remove the stripe from the list that in find_get_stripe()
651 if (!atomic_read(&sh->count)) { in find_get_stripe()
652 if (!test_bit(STRIPE_HANDLE, &sh->state)) in find_get_stripe()
654 BUG_ON(list_empty(&sh->lru) && in find_get_stripe()
655 !test_bit(STRIPE_EXPANDING, &sh->state)); in find_get_stripe()
659 list_del_init(&sh->lru); in find_get_stripe()
663 if (sh->group) { in find_get_stripe()
664 sh->group->stripes_cnt--; in find_get_stripe()
665 sh->group = NULL; in find_get_stripe()
668 atomic_inc(&sh->count); in find_get_stripe()
671 return sh; in find_get_stripe()
806 struct stripe_head *sh; in raid5_get_active_stripe() local
833 sh = find_get_stripe(conf, sector, conf->generation - previous, in raid5_get_active_stripe()
835 if (sh) in raid5_get_active_stripe()
839 sh = get_free_stripe(conf, hash); in raid5_get_active_stripe()
840 if (sh) { in raid5_get_active_stripe()
842 init_stripe(sh, sector, previous); in raid5_get_active_stripe()
843 atomic_inc(&sh->count); in raid5_get_active_stripe()
870 return sh; in raid5_get_active_stripe()
873 static bool is_full_stripe_write(struct stripe_head *sh) in is_full_stripe_write() argument
875 BUG_ON(sh->overwrite_disks > (sh->disks - sh->raid_conf->max_degraded)); in is_full_stripe_write()
876 return sh->overwrite_disks == (sh->disks - sh->raid_conf->max_degraded); in is_full_stripe_write()
901 static bool stripe_can_batch(struct stripe_head *sh) in stripe_can_batch() argument
903 struct r5conf *conf = sh->raid_conf; in stripe_can_batch()
907 return test_bit(STRIPE_BATCH_READY, &sh->state) && in stripe_can_batch()
908 !test_bit(STRIPE_BITMAP_PENDING, &sh->state) && in stripe_can_batch()
909 is_full_stripe_write(sh); in stripe_can_batch()
914 struct stripe_head *sh, struct stripe_head *last_sh) in stripe_add_to_batch_list() argument
922 tmp_sec = sh->sector; in stripe_add_to_batch_list()
925 head_sector = sh->sector - RAID5_STRIPE_SECTORS(conf); in stripe_add_to_batch_list()
942 lock_two_stripes(head, sh); in stripe_add_to_batch_list()
944 if (!stripe_can_batch(head) || !stripe_can_batch(sh)) in stripe_add_to_batch_list()
947 if (sh->batch_head) in stripe_add_to_batch_list()
951 while (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) in stripe_add_to_batch_list()
953 if (head->dev[dd_idx].towrite->bi_opf != sh->dev[dd_idx].towrite->bi_opf || in stripe_add_to_batch_list()
954 bio_op(head->dev[dd_idx].towrite) != bio_op(sh->dev[dd_idx].towrite)) in stripe_add_to_batch_list()
971 sh->batch_head = head->batch_head; in stripe_add_to_batch_list()
977 list_add(&sh->batch_list, &head->batch_list); in stripe_add_to_batch_list()
981 sh->batch_head = head->batch_head; in stripe_add_to_batch_list()
983 list_add_tail(&sh->batch_list, &head->batch_list); in stripe_add_to_batch_list()
987 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in stripe_add_to_batch_list()
992 if (test_and_clear_bit(STRIPE_BIT_DELAY, &sh->state)) { in stripe_add_to_batch_list()
993 int seq = sh->bm_seq; in stripe_add_to_batch_list()
994 if (test_bit(STRIPE_BIT_DELAY, &sh->batch_head->state) && in stripe_add_to_batch_list()
995 sh->batch_head->bm_seq > seq) in stripe_add_to_batch_list()
996 seq = sh->batch_head->bm_seq; in stripe_add_to_batch_list()
997 set_bit(STRIPE_BIT_DELAY, &sh->batch_head->state); in stripe_add_to_batch_list()
998 sh->batch_head->bm_seq = seq; in stripe_add_to_batch_list()
1001 atomic_inc(&sh->count); in stripe_add_to_batch_list()
1003 unlock_two_stripes(head, sh); in stripe_add_to_batch_list()
1011 static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) in use_new_offset() argument
1021 if (sh->generation == conf->generation - 1) in use_new_offset()
1138 static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) in ops_run_io() argument
1140 struct r5conf *conf = sh->raid_conf; in ops_run_io()
1141 int i, disks = sh->disks; in ops_run_io()
1142 struct stripe_head *head_sh = sh; in ops_run_io()
1149 if (log_stripe(sh, s) == 0) in ops_run_io()
1161 sh = head_sh; in ops_run_io()
1162 if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { in ops_run_io()
1164 if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) in ops_run_io()
1166 if (test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_io()
1168 } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) in ops_run_io()
1171 &sh->dev[i].flags)) { in ops_run_io()
1176 if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) in ops_run_io()
1180 dev = &sh->dev[i]; in ops_run_io()
1215 int bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in ops_run_io()
1249 set_bit(STRIPE_IO_STARTED, &sh->state); in ops_run_io()
1255 bi->bi_private = sh; in ops_run_io()
1258 __func__, (unsigned long long)sh->sector, in ops_run_io()
1260 atomic_inc(&sh->count); in ops_run_io()
1261 if (sh != head_sh) in ops_run_io()
1263 if (use_new_offset(conf, sh)) in ops_run_io()
1264 bi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1267 bi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1272 if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) in ops_run_io()
1273 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in ops_run_io()
1276 test_bit(R5_InJournal, &sh->dev[i].flags)) in ops_run_io()
1282 sh->dev[i].vec.bv_page = sh->dev[i].orig_page; in ops_run_io()
1284 sh->dev[i].vec.bv_page = sh->dev[i].page; in ops_run_io()
1287 bi->bi_io_vec[0].bv_offset = sh->dev[i].offset; in ops_run_io()
1296 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); in ops_run_io()
1301 sh->dev[i].sector); in ops_run_io()
1312 set_bit(STRIPE_IO_STARTED, &sh->state); in ops_run_io()
1317 rbi->bi_private = sh; in ops_run_io()
1321 __func__, (unsigned long long)sh->sector, in ops_run_io()
1323 atomic_inc(&sh->count); in ops_run_io()
1324 if (sh != head_sh) in ops_run_io()
1326 if (use_new_offset(conf, sh)) in ops_run_io()
1327 rbi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1330 rbi->bi_iter.bi_sector = (sh->sector in ops_run_io()
1332 if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) in ops_run_io()
1333 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in ops_run_io()
1334 sh->dev[i].rvec.bv_page = sh->dev[i].page; in ops_run_io()
1337 rbi->bi_io_vec[0].bv_offset = sh->dev[i].offset; in ops_run_io()
1348 sh->dev[i].sector); in ops_run_io()
1356 set_bit(STRIPE_DEGRADED, &sh->state); in ops_run_io()
1358 bi->bi_opf, i, (unsigned long long)sh->sector); in ops_run_io()
1359 clear_bit(R5_LOCKED, &sh->dev[i].flags); in ops_run_io()
1360 set_bit(STRIPE_HANDLE, &sh->state); in ops_run_io()
1365 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_io()
1367 if (sh != head_sh) in ops_run_io()
1378 struct stripe_head *sh, int no_skipcopy) in async_copy_data() argument
1386 struct r5conf *conf = sh->raid_conf; in async_copy_data()
1442 struct stripe_head *sh = stripe_head_ref; in ops_complete_biofill() local
1444 struct r5conf *conf = sh->raid_conf; in ops_complete_biofill()
1447 (unsigned long long)sh->sector); in ops_complete_biofill()
1450 for (i = sh->disks; i--; ) { in ops_complete_biofill()
1451 struct r5dev *dev = &sh->dev[i]; in ops_complete_biofill()
1472 clear_bit(STRIPE_BIOFILL_RUN, &sh->state); in ops_complete_biofill()
1474 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_biofill()
1475 raid5_release_stripe(sh); in ops_complete_biofill()
1478 static void ops_run_biofill(struct stripe_head *sh) in ops_run_biofill() argument
1483 struct r5conf *conf = sh->raid_conf; in ops_run_biofill()
1485 BUG_ON(sh->batch_head); in ops_run_biofill()
1487 (unsigned long long)sh->sector); in ops_run_biofill()
1489 for (i = sh->disks; i--; ) { in ops_run_biofill()
1490 struct r5dev *dev = &sh->dev[i]; in ops_run_biofill()
1493 spin_lock_irq(&sh->stripe_lock); in ops_run_biofill()
1496 spin_unlock_irq(&sh->stripe_lock); in ops_run_biofill()
1501 dev->sector, tx, sh, 0); in ops_run_biofill()
1507 atomic_inc(&sh->count); in ops_run_biofill()
1508 init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); in ops_run_biofill()
1512 static void mark_target_uptodate(struct stripe_head *sh, int target) in mark_target_uptodate() argument
1519 tgt = &sh->dev[target]; in mark_target_uptodate()
1527 struct stripe_head *sh = stripe_head_ref; in ops_complete_compute() local
1530 (unsigned long long)sh->sector); in ops_complete_compute()
1533 mark_target_uptodate(sh, sh->ops.target); in ops_complete_compute()
1534 mark_target_uptodate(sh, sh->ops.target2); in ops_complete_compute()
1536 clear_bit(STRIPE_COMPUTE_RUN, &sh->state); in ops_complete_compute()
1537 if (sh->check_state == check_state_compute_run) in ops_complete_compute()
1538 sh->check_state = check_state_compute_result; in ops_complete_compute()
1539 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_compute()
1540 raid5_release_stripe(sh); in ops_complete_compute()
1550 static addr_conv_t *to_addr_conv(struct stripe_head *sh, in to_addr_conv() argument
1553 return (void *) (to_addr_page(percpu, i) + sh->disks + 2); in to_addr_conv()
1560 to_addr_offs(struct stripe_head *sh, struct raid5_percpu *percpu) in to_addr_offs() argument
1562 return (unsigned int *) (to_addr_conv(sh, percpu, 0) + sh->disks + 2); in to_addr_offs()
1566 ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute5() argument
1568 int disks = sh->disks; in ops_run_compute5()
1570 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_compute5()
1571 int target = sh->ops.target; in ops_run_compute5()
1572 struct r5dev *tgt = &sh->dev[target]; in ops_run_compute5()
1580 BUG_ON(sh->batch_head); in ops_run_compute5()
1583 __func__, (unsigned long long)sh->sector, target); in ops_run_compute5()
1588 off_srcs[count] = sh->dev[i].offset; in ops_run_compute5()
1589 xor_srcs[count++] = sh->dev[i].page; in ops_run_compute5()
1593 atomic_inc(&sh->count); in ops_run_compute5()
1596 ops_complete_compute, sh, to_addr_conv(sh, percpu, 0)); in ops_run_compute5()
1599 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute5()
1602 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute5()
1608 * @srcs - (struct page *) array of size sh->disks
1610 * @sh - stripe_head to parse
1619 struct stripe_head *sh, in set_syndrome_sources() argument
1622 int disks = sh->disks; in set_syndrome_sources()
1623 int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); in set_syndrome_sources()
1624 int d0_idx = raid6_d0(sh); in set_syndrome_sources()
1634 int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); in set_syndrome_sources()
1635 struct r5dev *dev = &sh->dev[i]; in set_syndrome_sources()
1637 if (i == sh->qd_idx || i == sh->pd_idx || in set_syndrome_sources()
1646 srcs[slot] = sh->dev[i].orig_page; in set_syndrome_sources()
1648 srcs[slot] = sh->dev[i].page; in set_syndrome_sources()
1654 offs[slot] = sh->dev[i].offset; in set_syndrome_sources()
1663 ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute6_1() argument
1665 int disks = sh->disks; in ops_run_compute6_1()
1667 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_compute6_1()
1669 int qd_idx = sh->qd_idx; in ops_run_compute6_1()
1678 BUG_ON(sh->batch_head); in ops_run_compute6_1()
1679 if (sh->ops.target < 0) in ops_run_compute6_1()
1680 target = sh->ops.target2; in ops_run_compute6_1()
1681 else if (sh->ops.target2 < 0) in ops_run_compute6_1()
1682 target = sh->ops.target; in ops_run_compute6_1()
1688 __func__, (unsigned long long)sh->sector, target); in ops_run_compute6_1()
1690 tgt = &sh->dev[target]; in ops_run_compute6_1()
1695 atomic_inc(&sh->count); in ops_run_compute6_1()
1698 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_ALL); in ops_run_compute6_1()
1702 ops_complete_compute, sh, in ops_run_compute6_1()
1703 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_1()
1705 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute6_1()
1712 offs[count] = sh->dev[i].offset; in ops_run_compute6_1()
1713 blocks[count++] = sh->dev[i].page; in ops_run_compute6_1()
1717 NULL, ops_complete_compute, sh, in ops_run_compute6_1()
1718 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_1()
1720 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_compute6_1()
1727 ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_compute6_2() argument
1729 int i, count, disks = sh->disks; in ops_run_compute6_2()
1730 int syndrome_disks = sh->ddf_layout ? disks : disks-2; in ops_run_compute6_2()
1731 int d0_idx = raid6_d0(sh); in ops_run_compute6_2()
1733 int target = sh->ops.target; in ops_run_compute6_2()
1734 int target2 = sh->ops.target2; in ops_run_compute6_2()
1735 struct r5dev *tgt = &sh->dev[target]; in ops_run_compute6_2()
1736 struct r5dev *tgt2 = &sh->dev[target2]; in ops_run_compute6_2()
1739 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_compute6_2()
1742 BUG_ON(sh->batch_head); in ops_run_compute6_2()
1744 __func__, (unsigned long long)sh->sector, target, target2); in ops_run_compute6_2()
1759 int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); in ops_run_compute6_2()
1761 offs[slot] = sh->dev[i].offset; in ops_run_compute6_2()
1762 blocks[slot] = sh->dev[i].page; in ops_run_compute6_2()
1775 __func__, (unsigned long long)sh->sector, faila, failb); in ops_run_compute6_2()
1777 atomic_inc(&sh->count); in ops_run_compute6_2()
1784 ops_complete_compute, sh, in ops_run_compute6_2()
1785 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1787 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1793 int qd_idx = sh->qd_idx; in ops_run_compute6_2()
1805 offs[count] = sh->dev[i].offset; in ops_run_compute6_2()
1806 blocks[count++] = sh->dev[i].page; in ops_run_compute6_2()
1808 dest = sh->dev[data_target].page; in ops_run_compute6_2()
1809 dest_off = sh->dev[data_target].offset; in ops_run_compute6_2()
1813 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1815 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1818 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_ALL); in ops_run_compute6_2()
1820 ops_complete_compute, sh, in ops_run_compute6_2()
1821 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1823 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1828 ops_complete_compute, sh, in ops_run_compute6_2()
1829 to_addr_conv(sh, percpu, 0)); in ops_run_compute6_2()
1833 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1839 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_compute6_2()
1848 struct stripe_head *sh = stripe_head_ref; in ops_complete_prexor() local
1851 (unsigned long long)sh->sector); in ops_complete_prexor()
1853 if (r5c_is_writeback(sh->raid_conf->log)) in ops_complete_prexor()
1858 r5c_release_extra_page(sh); in ops_complete_prexor()
1862 ops_run_prexor5(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_prexor5() argument
1865 int disks = sh->disks; in ops_run_prexor5()
1867 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_prexor5()
1868 int count = 0, pd_idx = sh->pd_idx, i; in ops_run_prexor5()
1872 unsigned int off_dest = off_srcs[count] = sh->dev[pd_idx].offset; in ops_run_prexor5()
1873 struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; in ops_run_prexor5()
1875 BUG_ON(sh->batch_head); in ops_run_prexor5()
1877 (unsigned long long)sh->sector); in ops_run_prexor5()
1880 struct r5dev *dev = &sh->dev[i]; in ops_run_prexor5()
1896 ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); in ops_run_prexor5()
1898 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_prexor5()
1904 ops_run_prexor6(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_prexor6() argument
1908 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_prexor6()
1913 (unsigned long long)sh->sector); in ops_run_prexor6()
1915 count = set_syndrome_sources(blocks, offs, sh, SYNDROME_SRC_WANT_DRAIN); in ops_run_prexor6()
1918 ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); in ops_run_prexor6()
1920 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_prexor6()
1926 ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx) in ops_run_biodrain() argument
1928 struct r5conf *conf = sh->raid_conf; in ops_run_biodrain()
1929 int disks = sh->disks; in ops_run_biodrain()
1931 struct stripe_head *head_sh = sh; in ops_run_biodrain()
1934 (unsigned long long)sh->sector); in ops_run_biodrain()
1940 sh = head_sh; in ops_run_biodrain()
1945 dev = &sh->dev[i]; in ops_run_biodrain()
1951 spin_lock_irq(&sh->stripe_lock); in ops_run_biodrain()
1954 sh->overwrite_disks = 0; in ops_run_biodrain()
1957 spin_unlock_irq(&sh->stripe_lock); in ops_run_biodrain()
1971 dev->sector, tx, sh, in ops_run_biodrain()
1984 sh = list_first_entry(&sh->batch_list, in ops_run_biodrain()
1987 if (sh == head_sh) in ops_run_biodrain()
1999 struct stripe_head *sh = stripe_head_ref; in ops_complete_reconstruct() local
2000 int disks = sh->disks; in ops_complete_reconstruct()
2001 int pd_idx = sh->pd_idx; in ops_complete_reconstruct()
2002 int qd_idx = sh->qd_idx; in ops_complete_reconstruct()
2007 (unsigned long long)sh->sector); in ops_complete_reconstruct()
2010 fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); in ops_complete_reconstruct()
2011 sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); in ops_complete_reconstruct()
2012 discard |= test_bit(R5_Discard, &sh->dev[i].flags); in ops_complete_reconstruct()
2016 struct r5dev *dev = &sh->dev[i]; in ops_complete_reconstruct()
2021 if (test_bit(STRIPE_EXPAND_READY, &sh->state)) in ops_complete_reconstruct()
2031 if (sh->reconstruct_state == reconstruct_state_drain_run) in ops_complete_reconstruct()
2032 sh->reconstruct_state = reconstruct_state_drain_result; in ops_complete_reconstruct()
2033 else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) in ops_complete_reconstruct()
2034 sh->reconstruct_state = reconstruct_state_prexor_drain_result; in ops_complete_reconstruct()
2036 BUG_ON(sh->reconstruct_state != reconstruct_state_run); in ops_complete_reconstruct()
2037 sh->reconstruct_state = reconstruct_state_result; in ops_complete_reconstruct()
2040 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_reconstruct()
2041 raid5_release_stripe(sh); in ops_complete_reconstruct()
2045 ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_reconstruct5() argument
2048 int disks = sh->disks; in ops_run_reconstruct5()
2052 int count, pd_idx = sh->pd_idx, i; in ops_run_reconstruct5()
2058 struct stripe_head *head_sh = sh; in ops_run_reconstruct5()
2062 (unsigned long long)sh->sector); in ops_run_reconstruct5()
2064 for (i = 0; i < sh->disks; i++) { in ops_run_reconstruct5()
2067 if (!test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_reconstruct5()
2070 if (i >= sh->disks) { in ops_run_reconstruct5()
2071 atomic_inc(&sh->count); in ops_run_reconstruct5()
2072 set_bit(R5_Discard, &sh->dev[pd_idx].flags); in ops_run_reconstruct5()
2073 ops_complete_reconstruct(sh); in ops_run_reconstruct5()
2079 off_srcs = to_addr_offs(sh, percpu); in ops_run_reconstruct5()
2085 off_dest = off_srcs[count] = sh->dev[pd_idx].offset; in ops_run_reconstruct5()
2086 xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; in ops_run_reconstruct5()
2088 struct r5dev *dev = &sh->dev[i]; in ops_run_reconstruct5()
2096 xor_dest = sh->dev[pd_idx].page; in ops_run_reconstruct5()
2097 off_dest = sh->dev[pd_idx].offset; in ops_run_reconstruct5()
2099 struct r5dev *dev = &sh->dev[i]; in ops_run_reconstruct5()
2113 list_first_entry(&sh->batch_list, in ops_run_reconstruct5()
2121 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct5()
2125 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct5()
2130 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct5()
2133 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct5()
2136 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_reconstruct5()
2143 ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, in ops_run_reconstruct6() argument
2150 struct stripe_head *head_sh = sh; in ops_run_reconstruct6()
2155 pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); in ops_run_reconstruct6()
2157 for (i = 0; i < sh->disks; i++) { in ops_run_reconstruct6()
2158 if (sh->pd_idx == i || sh->qd_idx == i) in ops_run_reconstruct6()
2160 if (!test_bit(R5_Discard, &sh->dev[i].flags)) in ops_run_reconstruct6()
2163 if (i >= sh->disks) { in ops_run_reconstruct6()
2164 atomic_inc(&sh->count); in ops_run_reconstruct6()
2165 set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); in ops_run_reconstruct6()
2166 set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); in ops_run_reconstruct6()
2167 ops_complete_reconstruct(sh); in ops_run_reconstruct6()
2173 offs = to_addr_offs(sh, percpu); in ops_run_reconstruct6()
2175 if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { in ops_run_reconstruct6()
2183 count = set_syndrome_sources(blocks, offs, sh, synflags); in ops_run_reconstruct6()
2185 list_first_entry(&sh->batch_list, in ops_run_reconstruct6()
2191 head_sh, to_addr_conv(sh, percpu, j)); in ops_run_reconstruct6()
2194 to_addr_conv(sh, percpu, j)); in ops_run_reconstruct6()
2196 RAID5_STRIPE_SIZE(sh->raid_conf), &submit); in ops_run_reconstruct6()
2199 sh = list_first_entry(&sh->batch_list, struct stripe_head, in ops_run_reconstruct6()
2207 struct stripe_head *sh = stripe_head_ref; in ops_complete_check() local
2210 (unsigned long long)sh->sector); in ops_complete_check()
2212 sh->check_state = check_state_check_result; in ops_complete_check()
2213 set_bit(STRIPE_HANDLE, &sh->state); in ops_complete_check()
2214 raid5_release_stripe(sh); in ops_complete_check()
2217 static void ops_run_check_p(struct stripe_head *sh, struct raid5_percpu *percpu) in ops_run_check_p() argument
2219 int disks = sh->disks; in ops_run_check_p()
2220 int pd_idx = sh->pd_idx; in ops_run_check_p()
2221 int qd_idx = sh->qd_idx; in ops_run_check_p()
2225 unsigned int *off_srcs = to_addr_offs(sh, percpu); in ops_run_check_p()
2232 (unsigned long long)sh->sector); in ops_run_check_p()
2234 BUG_ON(sh->batch_head); in ops_run_check_p()
2236 xor_dest = sh->dev[pd_idx].page; in ops_run_check_p()
2237 off_dest = sh->dev[pd_idx].offset; in ops_run_check_p()
2243 off_srcs[count] = sh->dev[i].offset; in ops_run_check_p()
2244 xor_srcs[count++] = sh->dev[i].page; in ops_run_check_p()
2248 to_addr_conv(sh, percpu, 0)); in ops_run_check_p()
2250 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_check_p()
2251 &sh->ops.zero_sum_result, &submit); in ops_run_check_p()
2253 atomic_inc(&sh->count); in ops_run_check_p()
2254 init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); in ops_run_check_p()
2258 static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) in ops_run_check_pq() argument
2261 unsigned int *offs = to_addr_offs(sh, percpu); in ops_run_check_pq()
2266 (unsigned long long)sh->sector, checkp); in ops_run_check_pq()
2268 BUG_ON(sh->batch_head); in ops_run_check_pq()
2269 count = set_syndrome_sources(srcs, offs, sh, SYNDROME_SRC_ALL); in ops_run_check_pq()
2273 atomic_inc(&sh->count); in ops_run_check_pq()
2275 sh, to_addr_conv(sh, percpu, 0)); in ops_run_check_pq()
2277 RAID5_STRIPE_SIZE(sh->raid_conf), in ops_run_check_pq()
2278 &sh->ops.zero_sum_result, percpu->spare_page, 0, &submit); in ops_run_check_pq()
2281 static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) in raid_run_ops() argument
2283 int overlap_clear = 0, i, disks = sh->disks; in raid_run_ops()
2285 struct r5conf *conf = sh->raid_conf; in raid_run_ops()
2292 ops_run_biofill(sh); in raid_run_ops()
2298 tx = ops_run_compute5(sh, percpu); in raid_run_ops()
2300 if (sh->ops.target2 < 0 || sh->ops.target < 0) in raid_run_ops()
2301 tx = ops_run_compute6_1(sh, percpu); in raid_run_ops()
2303 tx = ops_run_compute6_2(sh, percpu); in raid_run_ops()
2312 tx = ops_run_prexor5(sh, percpu, tx); in raid_run_ops()
2314 tx = ops_run_prexor6(sh, percpu, tx); in raid_run_ops()
2318 tx = ops_run_partial_parity(sh, percpu, tx); in raid_run_ops()
2321 tx = ops_run_biodrain(sh, tx); in raid_run_ops()
2327 ops_run_reconstruct5(sh, percpu, tx); in raid_run_ops()
2329 ops_run_reconstruct6(sh, percpu, tx); in raid_run_ops()
2333 if (sh->check_state == check_state_run) in raid_run_ops()
2334 ops_run_check_p(sh, percpu); in raid_run_ops()
2335 else if (sh->check_state == check_state_run_q) in raid_run_ops()
2336 ops_run_check_pq(sh, percpu, 0); in raid_run_ops()
2337 else if (sh->check_state == check_state_run_pq) in raid_run_ops()
2338 ops_run_check_pq(sh, percpu, 1); in raid_run_ops()
2343 if (overlap_clear && !sh->batch_head) { in raid_run_ops()
2345 struct r5dev *dev = &sh->dev[i]; in raid_run_ops()
2347 wake_up(&sh->raid_conf->wait_for_overlap); in raid_run_ops()
2353 static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh) in free_stripe() argument
2356 kfree(sh->pages); in free_stripe()
2358 if (sh->ppl_page) in free_stripe()
2359 __free_page(sh->ppl_page); in free_stripe()
2360 kmem_cache_free(sc, sh); in free_stripe()
2366 struct stripe_head *sh; in alloc_stripe() local
2368 sh = kmem_cache_zalloc(sc, gfp); in alloc_stripe()
2369 if (sh) { in alloc_stripe()
2370 spin_lock_init(&sh->stripe_lock); in alloc_stripe()
2371 spin_lock_init(&sh->batch_lock); in alloc_stripe()
2372 INIT_LIST_HEAD(&sh->batch_list); in alloc_stripe()
2373 INIT_LIST_HEAD(&sh->lru); in alloc_stripe()
2374 INIT_LIST_HEAD(&sh->r5c); in alloc_stripe()
2375 INIT_LIST_HEAD(&sh->log_list); in alloc_stripe()
2376 atomic_set(&sh->count, 1); in alloc_stripe()
2377 sh->raid_conf = conf; in alloc_stripe()
2378 sh->log_start = MaxSector; in alloc_stripe()
2381 sh->ppl_page = alloc_page(gfp); in alloc_stripe()
2382 if (!sh->ppl_page) { in alloc_stripe()
2383 free_stripe(sc, sh); in alloc_stripe()
2388 if (init_stripe_shared_pages(sh, conf, disks)) { in alloc_stripe()
2389 free_stripe(sc, sh); in alloc_stripe()
2394 return sh; in alloc_stripe()
2398 struct stripe_head *sh; in grow_one_stripe() local
2400 sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size, conf); in grow_one_stripe()
2401 if (!sh) in grow_one_stripe()
2404 if (grow_buffers(sh, gfp)) { in grow_one_stripe()
2405 shrink_buffers(sh); in grow_one_stripe()
2406 free_stripe(conf->slab_cache, sh); in grow_one_stripe()
2409 sh->hash_lock_index = in grow_one_stripe()
2414 raid5_release_stripe(sh); in grow_one_stripe()
2698 struct stripe_head *sh; in drop_one_stripe() local
2702 sh = get_free_stripe(conf, hash); in drop_one_stripe()
2704 if (!sh) in drop_one_stripe()
2706 BUG_ON(atomic_read(&sh->count)); in drop_one_stripe()
2707 shrink_buffers(sh); in drop_one_stripe()
2708 free_stripe(conf->slab_cache, sh); in drop_one_stripe()
2726 struct stripe_head *sh = bi->bi_private; in raid5_end_read_request() local
2727 struct r5conf *conf = sh->raid_conf; in raid5_end_read_request()
2728 int disks = sh->disks, i; in raid5_end_read_request()
2733 if (bi == &sh->dev[i].req) in raid5_end_read_request()
2737 (unsigned long long)sh->sector, i, atomic_read(&sh->count), in raid5_end_read_request()
2743 if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) in raid5_end_read_request()
2753 if (use_new_offset(conf, sh)) in raid5_end_read_request()
2754 s = sh->sector + rdev->new_data_offset; in raid5_end_read_request()
2756 s = sh->sector + rdev->data_offset; in raid5_end_read_request()
2758 set_bit(R5_UPTODATE, &sh->dev[i].flags); in raid5_end_read_request()
2759 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { in raid5_end_read_request()
2770 clear_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2771 clear_bit(R5_ReWrite, &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 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2775 if (test_bit(R5_InJournal, &sh->dev[i].flags)) in raid5_end_read_request()
2780 set_bit(R5_OrigPageUPTDODATE, &sh->dev[i].flags); in raid5_end_read_request()
2788 clear_bit(R5_UPTODATE, &sh->dev[i].flags); in raid5_end_read_request()
2791 if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) in raid5_end_read_request()
2804 } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { in raid5_end_read_request()
2825 && !test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) in raid5_end_read_request()
2828 if (sh->qd_idx >= 0 && sh->pd_idx == i) in raid5_end_read_request()
2829 set_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2830 else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { in raid5_end_read_request()
2831 set_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2832 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2834 set_bit(R5_ReadNoMerge, &sh->dev[i].flags); in raid5_end_read_request()
2836 clear_bit(R5_ReadError, &sh->dev[i].flags); in raid5_end_read_request()
2837 clear_bit(R5_ReWrite, &sh->dev[i].flags); in raid5_end_read_request()
2841 rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0))) in raid5_end_read_request()
2847 clear_bit(R5_LOCKED, &sh->dev[i].flags); in raid5_end_read_request()
2848 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_read_request()
2849 raid5_release_stripe(sh); in raid5_end_read_request()
2854 struct stripe_head *sh = bi->bi_private; in raid5_end_write_request() local
2855 struct r5conf *conf = sh->raid_conf; in raid5_end_write_request()
2856 int disks = sh->disks, i; in raid5_end_write_request()
2863 if (bi == &sh->dev[i].req) { in raid5_end_write_request()
2867 if (bi == &sh->dev[i].rreq) { in raid5_end_write_request()
2881 (unsigned long long)sh->sector, i, atomic_read(&sh->count), in raid5_end_write_request()
2891 else if (is_badblock(rdev, sh->sector, in raid5_end_write_request()
2894 set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); in raid5_end_write_request()
2897 set_bit(STRIPE_DEGRADED, &sh->state); in raid5_end_write_request()
2899 set_bit(R5_WriteError, &sh->dev[i].flags); in raid5_end_write_request()
2903 } else if (is_badblock(rdev, sh->sector, in raid5_end_write_request()
2906 set_bit(R5_MadeGood, &sh->dev[i].flags); in raid5_end_write_request()
2907 if (test_bit(R5_ReadError, &sh->dev[i].flags)) in raid5_end_write_request()
2912 set_bit(R5_ReWrite, &sh->dev[i].flags); in raid5_end_write_request()
2917 if (sh->batch_head && bi->bi_status && !replacement) in raid5_end_write_request()
2918 set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state); in raid5_end_write_request()
2921 if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) in raid5_end_write_request()
2922 clear_bit(R5_LOCKED, &sh->dev[i].flags); in raid5_end_write_request()
2923 set_bit(STRIPE_HANDLE, &sh->state); in raid5_end_write_request()
2925 if (sh->batch_head && sh != sh->batch_head) in raid5_end_write_request()
2926 raid5_release_stripe(sh->batch_head); in raid5_end_write_request()
2927 raid5_release_stripe(sh); in raid5_end_write_request()
2970 struct stripe_head *sh) in raid5_compute_sector() argument
3158 if (sh) { in raid5_compute_sector()
3159 sh->pd_idx = pd_idx; in raid5_compute_sector()
3160 sh->qd_idx = qd_idx; in raid5_compute_sector()
3161 sh->ddf_layout = ddf_layout; in raid5_compute_sector()
3170 sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous) in raid5_compute_blocknr() argument
3172 struct r5conf *conf = sh->raid_conf; in raid5_compute_blocknr()
3173 int raid_disks = sh->disks; in raid5_compute_blocknr()
3175 sector_t new_sector = sh->sector, check; in raid5_compute_blocknr()
3190 if (i == sh->pd_idx) in raid5_compute_blocknr()
3198 if (i > sh->pd_idx) in raid5_compute_blocknr()
3203 if (i < sh->pd_idx) in raid5_compute_blocknr()
3205 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3217 if (i == sh->qd_idx) in raid5_compute_blocknr()
3224 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3226 else if (i > sh->pd_idx) in raid5_compute_blocknr()
3231 if (sh->pd_idx == raid_disks-1) in raid5_compute_blocknr()
3235 if (i < sh->pd_idx) in raid5_compute_blocknr()
3237 i -= (sh->pd_idx + 2); in raid5_compute_blocknr()
3247 if (sh->pd_idx == 0) in raid5_compute_blocknr()
3251 if (i < sh->pd_idx) in raid5_compute_blocknr()
3253 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3258 if (i > sh->pd_idx) in raid5_compute_blocknr()
3263 if (i < sh->pd_idx) in raid5_compute_blocknr()
3265 i -= (sh->pd_idx + 1); in raid5_compute_blocknr()
3281 if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx in raid5_compute_blocknr()
3282 || sh2.qd_idx != sh->qd_idx) { in raid5_compute_blocknr()
3347 schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, in schedule_reconstruction() argument
3350 int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx, disks = sh->disks; in schedule_reconstruction()
3351 struct r5conf *conf = sh->raid_conf; in schedule_reconstruction()
3361 r5c_release_extra_page(sh); in schedule_reconstruction()
3364 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3385 sh->reconstruct_state = reconstruct_state_drain_run; in schedule_reconstruction()
3388 sh->reconstruct_state = reconstruct_state_run; in schedule_reconstruction()
3393 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) in schedule_reconstruction()
3396 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || in schedule_reconstruction()
3397 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); in schedule_reconstruction()
3399 (!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) || in schedule_reconstruction()
3400 test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags)))); in schedule_reconstruction()
3403 struct r5dev *dev = &sh->dev[i]; in schedule_reconstruction()
3422 sh->reconstruct_state = reconstruct_state_prexor_drain_run; in schedule_reconstruction()
3431 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3432 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in schedule_reconstruction()
3436 int qd_idx = sh->qd_idx; in schedule_reconstruction()
3437 struct r5dev *dev = &sh->dev[qd_idx]; in schedule_reconstruction()
3444 if (raid5_has_ppl(sh->raid_conf) && sh->ppl_page && in schedule_reconstruction()
3446 !test_bit(STRIPE_FULL_WRITE, &sh->state) && in schedule_reconstruction()
3447 test_bit(R5_Insync, &sh->dev[pd_idx].flags)) in schedule_reconstruction()
3451 __func__, (unsigned long long)sh->sector, in schedule_reconstruction()
3455 static bool stripe_bio_overlaps(struct stripe_head *sh, struct bio *bi, in stripe_bio_overlaps() argument
3458 struct r5conf *conf = sh->raid_conf; in stripe_bio_overlaps()
3462 bi->bi_iter.bi_sector, sh->sector); in stripe_bio_overlaps()
3465 if (sh->batch_head) in stripe_bio_overlaps()
3469 bip = &sh->dev[dd_idx].towrite; in stripe_bio_overlaps()
3471 bip = &sh->dev[dd_idx].toread; in stripe_bio_overlaps()
3496 for (i = 0; i < sh->disks; i++) { in stripe_bio_overlaps()
3497 if (i != sh->pd_idx && in stripe_bio_overlaps()
3498 (i == dd_idx || sh->dev[i].towrite)) { in stripe_bio_overlaps()
3499 sector = sh->dev[i].sector; in stripe_bio_overlaps()
3515 static void __add_stripe_bio(struct stripe_head *sh, struct bio *bi, in __add_stripe_bio() argument
3518 struct r5conf *conf = sh->raid_conf; in __add_stripe_bio()
3523 bip = &sh->dev[dd_idx].towrite; in __add_stripe_bio()
3527 bip = &sh->dev[dd_idx].toread; in __add_stripe_bio()
3534 clear_bit(STRIPE_BATCH_READY, &sh->state); in __add_stripe_bio()
3545 sector_t sector = sh->dev[dd_idx].sector; in __add_stripe_bio()
3546 for (bi=sh->dev[dd_idx].towrite; in __add_stripe_bio()
3547 sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && in __add_stripe_bio()
3549 bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { in __add_stripe_bio()
3553 if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) in __add_stripe_bio()
3554 if (!test_and_set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags)) in __add_stripe_bio()
3555 sh->overwrite_disks++; in __add_stripe_bio()
3559 (*bip)->bi_iter.bi_sector, sh->sector, dd_idx, in __add_stripe_bio()
3560 sh->dev[dd_idx].sector); in __add_stripe_bio()
3575 set_bit(STRIPE_BITMAP_PENDING, &sh->state); in __add_stripe_bio()
3576 spin_unlock_irq(&sh->stripe_lock); in __add_stripe_bio()
3577 md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, in __add_stripe_bio()
3579 spin_lock_irq(&sh->stripe_lock); in __add_stripe_bio()
3580 clear_bit(STRIPE_BITMAP_PENDING, &sh->state); in __add_stripe_bio()
3581 if (!sh->batch_head) { in __add_stripe_bio()
3582 sh->bm_seq = conf->seq_flush+1; in __add_stripe_bio()
3583 set_bit(STRIPE_BIT_DELAY, &sh->state); in __add_stripe_bio()
3593 static bool add_stripe_bio(struct stripe_head *sh, struct bio *bi, in add_stripe_bio() argument
3596 spin_lock_irq(&sh->stripe_lock); in add_stripe_bio()
3598 if (stripe_bio_overlaps(sh, bi, dd_idx, forwrite)) { in add_stripe_bio()
3599 set_bit(R5_Overlap, &sh->dev[dd_idx].flags); in add_stripe_bio()
3600 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3604 __add_stripe_bio(sh, bi, dd_idx, forwrite, previous); in add_stripe_bio()
3605 spin_unlock_irq(&sh->stripe_lock); in add_stripe_bio()
3612 struct stripe_head *sh) in stripe_set_idx() argument
3624 &dd_idx, sh); in stripe_set_idx()
3628 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, in handle_failed_stripe() argument
3632 BUG_ON(sh->batch_head); in handle_failed_stripe()
3637 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { in handle_failed_stripe()
3648 sh->sector, in handle_failed_stripe()
3654 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3656 bi = sh->dev[i].towrite; in handle_failed_stripe()
3657 sh->dev[i].towrite = NULL; in handle_failed_stripe()
3658 sh->overwrite_disks = 0; in handle_failed_stripe()
3659 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3663 log_stripe_write_finished(sh); in handle_failed_stripe()
3665 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3669 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3670 struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3677 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3681 bi = sh->dev[i].written; in handle_failed_stripe()
3682 sh->dev[i].written = NULL; in handle_failed_stripe()
3683 if (test_and_clear_bit(R5_SkipCopy, &sh->dev[i].flags)) { in handle_failed_stripe()
3684 WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_failed_stripe()
3685 sh->dev[i].page = sh->dev[i].orig_page; in handle_failed_stripe()
3690 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3691 struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3701 if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && in handle_failed_stripe()
3703 (!test_bit(R5_Insync, &sh->dev[i].flags) || in handle_failed_stripe()
3704 test_bit(R5_ReadError, &sh->dev[i].flags))) { in handle_failed_stripe()
3705 spin_lock_irq(&sh->stripe_lock); in handle_failed_stripe()
3706 bi = sh->dev[i].toread; in handle_failed_stripe()
3707 sh->dev[i].toread = NULL; in handle_failed_stripe()
3708 spin_unlock_irq(&sh->stripe_lock); in handle_failed_stripe()
3709 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in handle_failed_stripe()
3714 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3716 r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3723 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3728 clear_bit(R5_LOCKED, &sh->dev[i].flags); in handle_failed_stripe()
3733 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_failed_stripe()
3739 handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, in handle_failed_sync() argument
3745 BUG_ON(sh->batch_head); in handle_failed_sync()
3746 clear_bit(STRIPE_SYNCING, &sh->state); in handle_failed_sync()
3747 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_failed_sync()
3768 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3776 && !rdev_set_badblocks(rdev, sh->sector, in handle_failed_sync()
3787 static int want_replace(struct stripe_head *sh, int disk_idx) in want_replace() argument
3792 rdev = sh->raid_conf->disks[disk_idx].replacement; in want_replace()
3796 && (rdev->recovery_offset <= sh->sector in want_replace()
3797 || rdev->mddev->recovery_cp <= sh->sector)) in want_replace()
3802 static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s, in need_this_block() argument
3805 struct r5dev *dev = &sh->dev[disk_idx]; in need_this_block()
3806 struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], in need_this_block()
3807 &sh->dev[s->failed_num[1]] }; in need_this_block()
3809 bool force_rcw = (sh->raid_conf->rmw_level == PARITY_DISABLE_RMW); in need_this_block()
3825 (s->replacing && want_replace(sh, disk_idx))) in need_this_block()
3850 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in need_this_block()
3871 s->failed_num[i] == sh->pd_idx || in need_this_block()
3872 s->failed_num[i] == sh->qd_idx) && in need_this_block()
3889 sh->sector < sh->raid_conf->mddev->recovery_cp) in need_this_block()
3893 if (s->failed_num[i] != sh->pd_idx && in need_this_block()
3894 s->failed_num[i] != sh->qd_idx && in need_this_block()
3909 static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, in fetch_block() argument
3912 struct r5dev *dev = &sh->dev[disk_idx]; in fetch_block()
3915 if (need_this_block(sh, s, disk_idx, disks)) { in fetch_block()
3921 BUG_ON(sh->batch_head); in fetch_block()
3933 ((sh->qd_idx >= 0 && sh->pd_idx == disk_idx) || in fetch_block()
3940 (unsigned long long)sh->sector, disk_idx); in fetch_block()
3941 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3944 sh->ops.target = disk_idx; in fetch_block()
3945 sh->ops.target2 = -1; /* no 2nd target */ in fetch_block()
3964 &sh->dev[other].flags)) in fetch_block()
3969 (unsigned long long)sh->sector, in fetch_block()
3971 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in fetch_block()
3973 set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); in fetch_block()
3974 set_bit(R5_Wantcompute, &sh->dev[other].flags); in fetch_block()
3975 sh->ops.target = disk_idx; in fetch_block()
3976 sh->ops.target2 = other; in fetch_block()
3995 static void handle_stripe_fill(struct stripe_head *sh, in handle_stripe_fill() argument
4005 if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && in handle_stripe_fill()
4006 !sh->reconstruct_state) { in handle_stripe_fill()
4016 if (test_bit(STRIPE_R5C_CACHING, &sh->state)) in handle_stripe_fill()
4017 r5c_make_stripe_write_out(sh); in handle_stripe_fill()
4022 if (fetch_block(sh, s, i, disks)) in handle_stripe_fill()
4026 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_fill()
4037 struct stripe_head *sh, int disks) in handle_stripe_clean_event() argument
4042 struct stripe_head *head_sh = sh; in handle_stripe_clean_event()
4046 if (sh->dev[i].written) { in handle_stripe_clean_event()
4047 dev = &sh->dev[i]; in handle_stripe_clean_event()
4073 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_stripe_clean_event()
4075 !test_bit(STRIPE_DEGRADED, &sh->state), in handle_stripe_clean_event()
4078 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4081 if (sh != head_sh) { in handle_stripe_clean_event()
4082 dev = &sh->dev[i]; in handle_stripe_clean_event()
4086 sh = head_sh; in handle_stripe_clean_event()
4087 dev = &sh->dev[i]; in handle_stripe_clean_event()
4092 log_stripe_write_finished(sh); in handle_stripe_clean_event()
4095 test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_clean_event()
4097 clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4098 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_stripe_clean_event()
4099 if (sh->qd_idx >= 0) { in handle_stripe_clean_event()
4100 clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4101 clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); in handle_stripe_clean_event()
4104 clear_bit(STRIPE_DISCARD, &sh->state); in handle_stripe_clean_event()
4111 hash = sh->hash_lock_index; in handle_stripe_clean_event()
4113 remove_hash(sh); in handle_stripe_clean_event()
4116 sh = list_first_entry(&sh->batch_list, in handle_stripe_clean_event()
4118 if (sh != head_sh) in handle_stripe_clean_event()
4121 sh = head_sh; in handle_stripe_clean_event()
4123 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) in handle_stripe_clean_event()
4124 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_clean_event()
4128 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) in handle_stripe_clean_event()
4152 struct stripe_head *sh, in handle_stripe_dirtying() argument
4167 (recovery_cp < MaxSector && sh->sector >= recovery_cp && in handle_stripe_dirtying()
4173 pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n", in handle_stripe_dirtying()
4175 (unsigned long long)sh->sector); in handle_stripe_dirtying()
4178 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4180 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4192 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4204 (unsigned long long)sh->sector, sh->state, rmw, rcw); in handle_stripe_dirtying()
4205 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe_dirtying()
4211 (unsigned long long)sh->sector, rmw); in handle_stripe_dirtying()
4213 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4216 !test_bit(R5_LOCKED, &sh->dev[sh->pd_idx].flags)) { in handle_stripe_dirtying()
4231 r5c_use_extra_page(sh); in handle_stripe_dirtying()
4236 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4243 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4245 i == sh->pd_idx || i == sh->qd_idx || in handle_stripe_dirtying()
4252 &sh->state)) { in handle_stripe_dirtying()
4259 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4268 struct r5dev *dev = &sh->dev[i]; in handle_stripe_dirtying()
4270 i != sh->pd_idx && i != sh->qd_idx && in handle_stripe_dirtying()
4277 &sh->state)) { in handle_stripe_dirtying()
4285 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4290 (unsigned long long)sh->sector, in handle_stripe_dirtying()
4291 rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); in handle_stripe_dirtying()
4295 !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe_dirtying()
4296 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe_dirtying()
4308 if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && in handle_stripe_dirtying()
4310 !test_bit(STRIPE_BIT_DELAY, &sh->state))) in handle_stripe_dirtying()
4311 schedule_reconstruction(sh, s, rcw == 0, 0); in handle_stripe_dirtying()
4315 static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks5() argument
4320 BUG_ON(sh->batch_head); in handle_parity_checks5()
4321 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks5()
4323 switch (sh->check_state) { in handle_parity_checks5()
4328 sh->check_state = check_state_run; in handle_parity_checks5()
4330 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4334 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks5()
4337 sh->check_state = check_state_idle; in handle_parity_checks5()
4339 dev = &sh->dev[sh->pd_idx]; in handle_parity_checks5()
4342 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks5()
4353 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks5()
4354 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4359 sh->check_state = check_state_idle; in handle_parity_checks5()
4371 if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) in handle_parity_checks5()
4375 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4380 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks5()
4383 (unsigned long long) sh->sector, in handle_parity_checks5()
4384 (unsigned long long) sh->sector + in handle_parity_checks5()
4387 sh->check_state = check_state_compute_run; in handle_parity_checks5()
4388 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks5()
4391 &sh->dev[sh->pd_idx].flags); in handle_parity_checks5()
4392 sh->ops.target = sh->pd_idx; in handle_parity_checks5()
4393 sh->ops.target2 = -1; in handle_parity_checks5()
4402 __func__, sh->check_state, in handle_parity_checks5()
4403 (unsigned long long) sh->sector); in handle_parity_checks5()
4408 static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks6() argument
4412 int pd_idx = sh->pd_idx; in handle_parity_checks6()
4413 int qd_idx = sh->qd_idx; in handle_parity_checks6()
4416 BUG_ON(sh->batch_head); in handle_parity_checks6()
4417 set_bit(STRIPE_HANDLE, &sh->state); in handle_parity_checks6()
4427 switch (sh->check_state) { in handle_parity_checks6()
4435 sh->check_state = check_state_run; in handle_parity_checks6()
4441 if (sh->check_state == check_state_run) in handle_parity_checks6()
4442 sh->check_state = check_state_run_pq; in handle_parity_checks6()
4444 sh->check_state = check_state_run_q; in handle_parity_checks6()
4448 sh->ops.zero_sum_result = 0; in handle_parity_checks6()
4450 if (sh->check_state == check_state_run) { in handle_parity_checks6()
4452 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); in handle_parity_checks6()
4455 if (sh->check_state >= check_state_run && in handle_parity_checks6()
4456 sh->check_state <= check_state_run_pq) { in handle_parity_checks6()
4468 sh->check_state = check_state_idle; in handle_parity_checks6()
4471 if (test_bit(STRIPE_INSYNC, &sh->state)) in handle_parity_checks6()
4479 dev = &sh->dev[s->failed_num[1]]; in handle_parity_checks6()
4485 dev = &sh->dev[s->failed_num[0]]; in handle_parity_checks6()
4490 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4491 dev = &sh->dev[pd_idx]; in handle_parity_checks6()
4496 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4497 dev = &sh->dev[qd_idx]; in handle_parity_checks6()
4505 dev - (struct r5dev *) &sh->dev)) { in handle_parity_checks6()
4510 clear_bit(STRIPE_DEGRADED, &sh->state); in handle_parity_checks6()
4512 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4519 sh->check_state = check_state_idle; in handle_parity_checks6()
4525 if (sh->ops.zero_sum_result == 0) { in handle_parity_checks6()
4528 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4534 sh->check_state = check_state_compute_result; in handle_parity_checks6()
4545 set_bit(STRIPE_INSYNC, &sh->state); in handle_parity_checks6()
4548 (unsigned long long) sh->sector, in handle_parity_checks6()
4549 (unsigned long long) sh->sector + in handle_parity_checks6()
4552 int *target = &sh->ops.target; in handle_parity_checks6()
4554 sh->ops.target = -1; in handle_parity_checks6()
4555 sh->ops.target2 = -1; in handle_parity_checks6()
4556 sh->check_state = check_state_compute_run; in handle_parity_checks6()
4557 set_bit(STRIPE_COMPUTE_RUN, &sh->state); in handle_parity_checks6()
4559 if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { in handle_parity_checks6()
4561 &sh->dev[pd_idx].flags); in handle_parity_checks6()
4563 target = &sh->ops.target2; in handle_parity_checks6()
4566 if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { in handle_parity_checks6()
4568 &sh->dev[qd_idx].flags); in handle_parity_checks6()
4579 __func__, sh->check_state, in handle_parity_checks6()
4580 (unsigned long long) sh->sector); in handle_parity_checks6()
4585 static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) in handle_stripe_expansion() argument
4593 BUG_ON(sh->batch_head); in handle_stripe_expansion()
4594 clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); in handle_stripe_expansion()
4595 for (i = 0; i < sh->disks; i++) in handle_stripe_expansion()
4596 if (i != sh->pd_idx && i != sh->qd_idx) { in handle_stripe_expansion()
4601 sector_t bn = raid5_compute_blocknr(sh, i, 1); in handle_stripe_expansion()
4622 sh->dev[i].page, sh2->dev[dd_idx].offset, in handle_stripe_expansion()
4623 sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), in handle_stripe_expansion()
4658 static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) in analyse_stripe() argument
4660 struct r5conf *conf = sh->raid_conf; in analyse_stripe()
4661 int disks = sh->disks; in analyse_stripe()
4668 s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state) && !sh->batch_head; in analyse_stripe()
4669 s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state) && !sh->batch_head; in analyse_stripe()
4681 dev = &sh->dev[i]; in analyse_stripe()
4692 !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) in analyse_stripe()
4721 rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && in analyse_stripe()
4722 !is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4736 is_bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4763 else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) in analyse_stripe()
4832 if (test_bit(STRIPE_SYNCING, &sh->state)) { in analyse_stripe()
4842 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4854 static int clear_batch_ready(struct stripe_head *sh) in clear_batch_ready() argument
4857 if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) in clear_batch_ready()
4858 return (sh->batch_head && sh->batch_head != sh); in clear_batch_ready()
4859 spin_lock(&sh->stripe_lock); in clear_batch_ready()
4860 if (!sh->batch_head) { in clear_batch_ready()
4861 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4869 if (sh->batch_head != sh) { in clear_batch_ready()
4870 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4873 spin_lock(&sh->batch_lock); in clear_batch_ready()
4874 list_for_each_entry(tmp, &sh->batch_list, batch_list) in clear_batch_ready()
4876 spin_unlock(&sh->batch_lock); in clear_batch_ready()
4877 spin_unlock(&sh->stripe_lock); in clear_batch_ready()
4889 struct stripe_head *sh, *next; in break_stripe_batch_list() local
4893 list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { in break_stripe_batch_list()
4895 list_del_init(&sh->batch_list); in break_stripe_batch_list()
4897 WARN_ONCE(sh->state & ((1 << STRIPE_ACTIVE) | in break_stripe_batch_list()
4909 "stripe state: %lx\n", sh->state); in break_stripe_batch_list()
4914 set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | in break_stripe_batch_list()
4920 sh->check_state = head_sh->check_state; in break_stripe_batch_list()
4921 sh->reconstruct_state = head_sh->reconstruct_state; in break_stripe_batch_list()
4922 spin_lock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4923 sh->batch_head = NULL; in break_stripe_batch_list()
4924 spin_unlock_irq(&sh->stripe_lock); in break_stripe_batch_list()
4925 for (i = 0; i < sh->disks; i++) { in break_stripe_batch_list()
4926 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) in break_stripe_batch_list()
4928 sh->dev[i].flags = head_sh->dev[i].flags & in break_stripe_batch_list()
4932 sh->state & handle_flags) in break_stripe_batch_list()
4933 set_bit(STRIPE_HANDLE, &sh->state); in break_stripe_batch_list()
4934 raid5_release_stripe(sh); in break_stripe_batch_list()
4949 static void handle_stripe(struct stripe_head *sh) in handle_stripe() argument
4952 struct r5conf *conf = sh->raid_conf; in handle_stripe()
4955 int disks = sh->disks; in handle_stripe()
4958 clear_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4966 if (clear_batch_ready(sh)) in handle_stripe()
4969 if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { in handle_stripe()
4972 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
4976 if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) in handle_stripe()
4977 break_stripe_batch_list(sh, 0); in handle_stripe()
4979 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { in handle_stripe()
4980 spin_lock(&sh->stripe_lock); in handle_stripe()
4985 if (!test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state) && in handle_stripe()
4986 !test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) && in handle_stripe()
4987 !test_bit(STRIPE_DISCARD, &sh->state) && in handle_stripe()
4988 test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { in handle_stripe()
4989 set_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
4990 clear_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
4991 clear_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
4993 spin_unlock(&sh->stripe_lock); in handle_stripe()
4995 clear_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
4999 (unsigned long long)sh->sector, sh->state, in handle_stripe()
5000 atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, in handle_stripe()
5001 sh->check_state, sh->reconstruct_state); in handle_stripe()
5003 analyse_stripe(sh, &s); in handle_stripe()
5005 if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) in handle_stripe()
5010 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
5017 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
5025 if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { in handle_stripe()
5027 set_bit(STRIPE_BIOFILL_RUN, &sh->state); in handle_stripe()
5043 sh->check_state = 0; in handle_stripe()
5044 sh->reconstruct_state = 0; in handle_stripe()
5045 break_stripe_batch_list(sh, 0); in handle_stripe()
5047 handle_failed_stripe(conf, sh, &s, disks); in handle_stripe()
5049 handle_failed_sync(conf, sh, &s); in handle_stripe()
5056 if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) in handle_stripe()
5058 if (sh->reconstruct_state == reconstruct_state_drain_result || in handle_stripe()
5059 sh->reconstruct_state == reconstruct_state_prexor_drain_result) { in handle_stripe()
5060 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
5065 BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && in handle_stripe()
5066 !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); in handle_stripe()
5067 BUG_ON(sh->qd_idx >= 0 && in handle_stripe()
5068 !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && in handle_stripe()
5069 !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); in handle_stripe()
5071 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
5073 (i == sh->pd_idx || i == sh->qd_idx || in handle_stripe()
5083 ((i == sh->pd_idx || i == sh->qd_idx) && in handle_stripe()
5085 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5088 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in handle_stripe()
5096 pdev = &sh->dev[sh->pd_idx]; in handle_stripe()
5097 s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) in handle_stripe()
5098 || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); in handle_stripe()
5099 qdev = &sh->dev[sh->qd_idx]; in handle_stripe()
5100 s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) in handle_stripe()
5101 || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) in handle_stripe()
5113 handle_stripe_clean_event(conf, sh, disks); in handle_stripe()
5116 r5c_handle_cached_data_endio(conf, sh, disks); in handle_stripe()
5117 log_stripe_write_finished(sh); in handle_stripe()
5128 handle_stripe_fill(sh, &s, disks); in handle_stripe()
5135 r5c_finish_stripe_write_out(conf, sh, &s); in handle_stripe()
5146 if (!sh->reconstruct_state && !sh->check_state && !sh->log_io) { in handle_stripe()
5149 handle_stripe_dirtying(conf, sh, &s, disks); in handle_stripe()
5155 ret = r5c_try_caching_write(conf, sh, &s, in handle_stripe()
5166 (!test_bit(STRIPE_R5C_CACHING, &sh->state) && in handle_stripe()
5168 ret = handle_stripe_dirtying(conf, sh, &s, in handle_stripe()
5181 if (sh->check_state || in handle_stripe()
5183 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5184 !test_bit(STRIPE_INSYNC, &sh->state))) { in handle_stripe()
5186 handle_parity_checks6(conf, sh, &s, disks); in handle_stripe()
5188 handle_parity_checks5(conf, sh, &s, disks); in handle_stripe()
5192 && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) in handle_stripe()
5193 && !test_bit(STRIPE_REPLACED, &sh->state)) { in handle_stripe()
5196 if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { in handle_stripe()
5197 WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); in handle_stripe()
5198 set_bit(R5_WantReplace, &sh->dev[i].flags); in handle_stripe()
5199 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5203 set_bit(STRIPE_INSYNC, &sh->state); in handle_stripe()
5204 set_bit(STRIPE_REPLACED, &sh->state); in handle_stripe()
5207 !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && in handle_stripe()
5208 test_bit(STRIPE_INSYNC, &sh->state)) { in handle_stripe()
5210 clear_bit(STRIPE_SYNCING, &sh->state); in handle_stripe()
5211 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) in handle_stripe()
5220 struct r5dev *dev = &sh->dev[s.failed_num[i]]; in handle_stripe()
5237 if (sh->reconstruct_state == reconstruct_state_result) { in handle_stripe()
5239 = raid5_get_active_stripe(conf, NULL, sh->sector, in handle_stripe()
5243 /* sh cannot be written until sh_src has been read. in handle_stripe()
5244 * so arrange for sh to be delayed a little in handle_stripe()
5246 set_bit(STRIPE_DELAYED, &sh->state); in handle_stripe()
5247 set_bit(STRIPE_HANDLE, &sh->state); in handle_stripe()
5257 sh->reconstruct_state = reconstruct_state_idle; in handle_stripe()
5258 clear_bit(STRIPE_EXPANDING, &sh->state); in handle_stripe()
5260 set_bit(R5_Wantwrite, &sh->dev[i].flags); in handle_stripe()
5261 set_bit(R5_LOCKED, &sh->dev[i].flags); in handle_stripe()
5266 if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && in handle_stripe()
5267 !sh->reconstruct_state) { in handle_stripe()
5269 sh->disks = conf->raid_disks; in handle_stripe()
5270 stripe_set_idx(sh->sector, conf, 0, sh); in handle_stripe()
5271 schedule_reconstruction(sh, &s, 1, 1); in handle_stripe()
5272 } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { in handle_stripe()
5273 clear_bit(STRIPE_EXPAND_READY, &sh->state); in handle_stripe()
5280 !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) in handle_stripe()
5281 handle_stripe_expansion(conf, sh); in handle_stripe()
5301 struct r5dev *dev = &sh->dev[i]; in handle_stripe()
5305 if (!rdev_set_badblocks(rdev, sh->sector, in handle_stripe()
5312 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5321 rdev_clear_badblocks(rdev, sh->sector, in handle_stripe()
5328 raid_run_ops(sh, s.ops_request); in handle_stripe()
5330 ops_run_io(sh, &s); in handle_stripe()
5343 clear_bit_unlock(STRIPE_ACTIVE, &sh->state); in handle_stripe()
5352 struct stripe_head *sh; in raid5_activate_delayed() local
5353 sh = list_entry(l, struct stripe_head, lru); in raid5_activate_delayed()
5355 clear_bit(STRIPE_DELAYED, &sh->state); in raid5_activate_delayed()
5356 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in raid5_activate_delayed()
5358 list_add_tail(&sh->lru, &conf->hold_list); in raid5_activate_delayed()
5359 raid5_wakeup_stripe_thread(sh); in raid5_activate_delayed()
5372 struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); in activate_bit_delay() local
5374 list_del_init(&sh->lru); in activate_bit_delay()
5375 atomic_inc(&sh->count); in activate_bit_delay()
5376 hash = sh->hash_lock_index; in activate_bit_delay()
5377 __release_stripe(conf, sh, &temp_inactive_list[hash]); in activate_bit_delay()
5574 struct stripe_head *sh, *tmp; in __get_priority_stripe() local
5584 sh = NULL; in __get_priority_stripe()
5610 sh = list_entry(handle_list->next, typeof(*sh), lru); in __get_priority_stripe()
5614 else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { in __get_priority_stripe()
5634 sh = tmp; in __get_priority_stripe()
5639 if (sh) { in __get_priority_stripe()
5647 if (!sh) { in __get_priority_stripe()
5657 sh->group = NULL; in __get_priority_stripe()
5659 list_del_init(&sh->lru); in __get_priority_stripe()
5660 BUG_ON(atomic_inc_return(&sh->count) != 1); in __get_priority_stripe()
5661 return sh; in __get_priority_stripe()
5674 struct stripe_head *sh; in raid5_unplug() local
5683 sh = list_first_entry(&cb->list, struct stripe_head, lru); in raid5_unplug()
5684 list_del_init(&sh->lru); in raid5_unplug()
5691 clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); in raid5_unplug()
5696 hash = sh->hash_lock_index; in raid5_unplug()
5697 __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); in raid5_unplug()
5710 struct stripe_head *sh) in release_stripe_plug() argument
5718 raid5_release_stripe(sh); in release_stripe_plug()
5731 if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) in release_stripe_plug()
5732 list_add_tail(&sh->lru, &cb->list); in release_stripe_plug()
5734 raid5_release_stripe(sh); in release_stripe_plug()
5741 struct stripe_head *sh; in make_discard_request() local
5771 sh = raid5_get_active_stripe(conf, NULL, logical_sector, 0); in make_discard_request()
5774 set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5775 if (test_bit(STRIPE_SYNCING, &sh->state)) { in make_discard_request()
5776 raid5_release_stripe(sh); in make_discard_request()
5780 clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); in make_discard_request()
5781 spin_lock_irq(&sh->stripe_lock); in make_discard_request()
5783 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5785 if (sh->dev[d].towrite || sh->dev[d].toread) { in make_discard_request()
5786 set_bit(R5_Overlap, &sh->dev[d].flags); in make_discard_request()
5787 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5788 raid5_release_stripe(sh); in make_discard_request()
5793 set_bit(STRIPE_DISCARD, &sh->state); in make_discard_request()
5795 sh->overwrite_disks = 0; in make_discard_request()
5797 if (d == sh->pd_idx || d == sh->qd_idx) in make_discard_request()
5799 sh->dev[d].towrite = bi; in make_discard_request()
5800 set_bit(R5_OVERWRITE, &sh->dev[d].flags); in make_discard_request()
5803 sh->overwrite_disks++; in make_discard_request()
5805 spin_unlock_irq(&sh->stripe_lock); in make_discard_request()
5811 sh->sector, in make_discard_request()
5814 sh->bm_seq = conf->seq_flush + 1; in make_discard_request()
5815 set_bit(STRIPE_BIT_DELAY, &sh->state); in make_discard_request()
5818 set_bit(STRIPE_HANDLE, &sh->state); in make_discard_request()
5819 clear_bit(STRIPE_DELAYED, &sh->state); in make_discard_request()
5820 if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in make_discard_request()
5822 release_stripe_plug(mddev, sh); in make_discard_request()
5843 struct stripe_head *sh) in stripe_ahead_of_reshape() argument
5849 for (dd_idx = 0; dd_idx < sh->disks; dd_idx++) { in stripe_ahead_of_reshape()
5850 if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) in stripe_ahead_of_reshape()
5853 min_sector = min(min_sector, sh->dev[dd_idx].sector); in stripe_ahead_of_reshape()
5854 max_sector = max(max_sector, sh->dev[dd_idx].sector); in stripe_ahead_of_reshape()
5870 struct stripe_request_ctx *ctx, struct stripe_head *sh, in add_all_stripe_bios() argument
5876 spin_lock_irq(&sh->stripe_lock); in add_all_stripe_bios()
5878 for (dd_idx = 0; dd_idx < sh->disks; dd_idx++) { in add_all_stripe_bios()
5879 struct r5dev *dev = &sh->dev[dd_idx]; in add_all_stripe_bios()
5881 if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) in add_all_stripe_bios()
5888 if (stripe_bio_overlaps(sh, bi, dd_idx, forwrite)) { in add_all_stripe_bios()
5898 for (dd_idx = 0; dd_idx < sh->disks; dd_idx++) { in add_all_stripe_bios()
5899 struct r5dev *dev = &sh->dev[dd_idx]; in add_all_stripe_bios()
5901 if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) in add_all_stripe_bios()
5908 __add_stripe_bio(sh, bi, dd_idx, forwrite, previous); in add_all_stripe_bios()
5914 spin_unlock_irq(&sh->stripe_lock); in add_all_stripe_bios()
5924 struct stripe_head *sh; in make_stripe_request() local
5964 sh = raid5_get_active_stripe(conf, ctx, new_sector, flags); in make_stripe_request()
5965 if (unlikely(!sh)) { in make_stripe_request()
5972 stripe_ahead_of_reshape(mddev, conf, sh)) { in make_stripe_request()
5977 * 'sh', we know that if that happens, in make_stripe_request()
5991 if (test_bit(STRIPE_EXPANDING, &sh->state) || in make_stripe_request()
5992 !add_all_stripe_bios(conf, ctx, sh, bi, rw, previous)) { in make_stripe_request()
6002 if (stripe_can_batch(sh)) { in make_stripe_request()
6003 stripe_add_to_batch_list(conf, sh, ctx->batch_last); in make_stripe_request()
6006 atomic_inc(&sh->count); in make_stripe_request()
6007 ctx->batch_last = sh; in make_stripe_request()
6011 set_bit(STRIPE_R5C_PREFLUSH, &sh->state); in make_stripe_request()
6016 set_bit(STRIPE_HANDLE, &sh->state); in make_stripe_request()
6017 clear_bit(STRIPE_DELAYED, &sh->state); in make_stripe_request()
6018 if ((!sh->batch_head || sh == sh->batch_head) && in make_stripe_request()
6020 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) in make_stripe_request()
6023 release_stripe_plug(mddev, sh); in make_stripe_request()
6027 raid5_release_stripe(sh); in make_stripe_request()
6041 struct stripe_head sh; in raid5_bio_lowest_chunk_sector() local
6047 sector = raid5_compute_sector(conf, r_sector, 0, &dd_idx, &sh); in raid5_bio_lowest_chunk_sector()
6056 while (dd_idx == sh.pd_idx || dd_idx == sh.qd_idx) in raid5_bio_lowest_chunk_sector()
6205 struct stripe_head *sh; in reshape_request() local
6356 sh = raid5_get_active_stripe(conf, NULL, stripe_addr+i, in reshape_request()
6358 set_bit(STRIPE_EXPANDING, &sh->state); in reshape_request()
6363 for (j=sh->disks; j--;) { in reshape_request()
6365 if (j == sh->pd_idx) in reshape_request()
6368 j == sh->qd_idx) in reshape_request()
6370 s = raid5_compute_blocknr(sh, j, 0); in reshape_request()
6375 memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); in reshape_request()
6376 set_bit(R5_Expanded, &sh->dev[j].flags); in reshape_request()
6377 set_bit(R5_UPTODATE, &sh->dev[j].flags); in reshape_request()
6380 set_bit(STRIPE_EXPAND_READY, &sh->state); in reshape_request()
6381 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6383 list_add(&sh->lru, &stripes); in reshape_request()
6406 sh = raid5_get_active_stripe(conf, NULL, first_sector, in reshape_request()
6408 set_bit(STRIPE_EXPAND_SOURCE, &sh->state); in reshape_request()
6409 set_bit(STRIPE_HANDLE, &sh->state); in reshape_request()
6410 raid5_release_stripe(sh); in reshape_request()
6417 sh = list_entry(stripes.next, struct stripe_head, lru); in reshape_request()
6418 list_del_init(&sh->lru); in reshape_request()
6419 raid5_release_stripe(sh); in reshape_request()
6468 struct stripe_head *sh; in raid5_sync_request() local
6527 sh = raid5_get_active_stripe(conf, NULL, sector_nr, in raid5_sync_request()
6529 if (sh == NULL) { in raid5_sync_request()
6530 sh = raid5_get_active_stripe(conf, NULL, sector_nr, 0); in raid5_sync_request()
6549 set_bit(STRIPE_SYNC_REQUESTED, &sh->state); in raid5_sync_request()
6550 set_bit(STRIPE_HANDLE, &sh->state); in raid5_sync_request()
6552 raid5_release_stripe(sh); in raid5_sync_request()
6570 struct stripe_head *sh; in retry_aligned_read() local
6591 sh = raid5_get_active_stripe(conf, NULL, sector, in retry_aligned_read()
6593 if (!sh) { in retry_aligned_read()
6600 if (!add_stripe_bio(sh, raid_bio, dd_idx, 0, 0)) { in retry_aligned_read()
6601 raid5_release_stripe(sh); in retry_aligned_read()
6607 set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); in retry_aligned_read()
6608 handle_stripe(sh); in retry_aligned_read()
6609 raid5_release_stripe(sh); in retry_aligned_read()
6625 struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; in handle_active_stripes() local
6630 (sh = __get_priority_stripe(conf, group)) != NULL) in handle_active_stripes()
6631 batch[batch_size++] = sh; in handle_active_stripes()