Lines Matching refs:conf

72 static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect)  in stripe_hash()  argument
74 int hash = (sect >> RAID5_STRIPE_SHIFT(conf)) & HASH_MASK; in stripe_hash()
75 return &conf->stripe_hashtbl[hash]; in stripe_hash()
78 static inline int stripe_hash_locks_hash(struct r5conf *conf, sector_t sect) in stripe_hash_locks_hash() argument
80 return (sect >> RAID5_STRIPE_SHIFT(conf)) & STRIPE_HASH_LOCKS_MASK; in stripe_hash_locks_hash()
83 static inline void lock_device_hash_lock(struct r5conf *conf, int hash) in lock_device_hash_lock() argument
84 __acquires(&conf->device_lock) in lock_device_hash_lock()
86 spin_lock_irq(conf->hash_locks + hash); in lock_device_hash_lock()
87 spin_lock(&conf->device_lock); in lock_device_hash_lock()
90 static inline void unlock_device_hash_lock(struct r5conf *conf, int hash) in unlock_device_hash_lock() argument
91 __releases(&conf->device_lock) in unlock_device_hash_lock()
93 spin_unlock(&conf->device_lock); in unlock_device_hash_lock()
94 spin_unlock_irq(conf->hash_locks + hash); in unlock_device_hash_lock()
97 static inline void lock_all_device_hash_locks_irq(struct r5conf *conf) in lock_all_device_hash_locks_irq() argument
98 __acquires(&conf->device_lock) in lock_all_device_hash_locks_irq()
101 spin_lock_irq(conf->hash_locks); in lock_all_device_hash_locks_irq()
103 spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks); in lock_all_device_hash_locks_irq()
104 spin_lock(&conf->device_lock); in lock_all_device_hash_locks_irq()
107 static inline void unlock_all_device_hash_locks_irq(struct r5conf *conf) in unlock_all_device_hash_locks_irq() argument
108 __releases(&conf->device_lock) in unlock_all_device_hash_locks_irq()
111 spin_unlock(&conf->device_lock); in unlock_all_device_hash_locks_irq()
113 spin_unlock(conf->hash_locks + i); in unlock_all_device_hash_locks_irq()
114 spin_unlock_irq(conf->hash_locks); in unlock_all_device_hash_locks_irq()
156 static void print_raid5_conf (struct r5conf *conf);
175 struct r5conf *conf = sh->raid_conf; in raid5_wakeup_stripe_thread() local
187 group = conf->worker_groups + cpu_to_group(cpu); in raid5_wakeup_stripe_thread()
196 if (conf->worker_cnt_per_group == 0) { in raid5_wakeup_stripe_thread()
197 md_wakeup_thread(conf->mddev->thread); in raid5_wakeup_stripe_thread()
201 group = conf->worker_groups + cpu_to_group(sh->cpu); in raid5_wakeup_stripe_thread()
209 for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { in raid5_wakeup_stripe_thread()
219 static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, in do_release_stripe() argument
221 __must_hold(&conf->device_lock) in do_release_stripe()
227 BUG_ON(atomic_read(&conf->active_stripes)==0); in do_release_stripe()
229 if (r5c_is_writeback(conf->log)) in do_release_stripe()
241 (conf->quiesce && r5c_is_writeback(conf->log) && in do_release_stripe()
251 list_add_tail(&sh->lru, &conf->delayed_list); in do_release_stripe()
253 sh->bm_seq - conf->seq_write > 0) in do_release_stripe()
254 list_add_tail(&sh->lru, &conf->bitmap_list); in do_release_stripe()
258 if (conf->worker_cnt_per_group == 0) { in do_release_stripe()
261 &conf->loprio_list); in do_release_stripe()
264 &conf->handle_list); in do_release_stripe()
270 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
274 if (atomic_dec_return(&conf->preread_active_stripes) in do_release_stripe()
276 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
277 atomic_dec(&conf->active_stripes); in do_release_stripe()
279 if (!r5c_is_writeback(conf->log)) in do_release_stripe()
285 else if (injournal == conf->raid_disks - conf->max_degraded) { in do_release_stripe()
288 atomic_inc(&conf->r5c_cached_full_stripes); in do_release_stripe()
290 atomic_dec(&conf->r5c_cached_partial_stripes); in do_release_stripe()
291 list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); in do_release_stripe()
292 r5c_check_cached_full_stripe(conf); in do_release_stripe()
299 list_add_tail(&sh->lru, &conf->r5c_partial_stripe_list); in do_release_stripe()
305 static void __release_stripe(struct r5conf *conf, struct stripe_head *sh, in __release_stripe() argument
307 __must_hold(&conf->device_lock) in __release_stripe()
310 do_release_stripe(conf, sh, temp_inactive_list); in __release_stripe()
320 static void release_inactive_stripe_list(struct r5conf *conf, in release_inactive_stripe_list() argument
341 spin_lock_irqsave(conf->hash_locks + hash, flags); in release_inactive_stripe_list()
342 if (list_empty(conf->inactive_list + hash) && in release_inactive_stripe_list()
344 atomic_dec(&conf->empty_inactive_list_nr); in release_inactive_stripe_list()
345 list_splice_tail_init(list, conf->inactive_list + hash); in release_inactive_stripe_list()
347 spin_unlock_irqrestore(conf->hash_locks + hash, flags); in release_inactive_stripe_list()
354 wake_up(&conf->wait_for_stripe); in release_inactive_stripe_list()
355 if (atomic_read(&conf->active_stripes) == 0) in release_inactive_stripe_list()
356 wake_up(&conf->wait_for_quiescent); in release_inactive_stripe_list()
357 if (conf->retry_read_aligned) in release_inactive_stripe_list()
358 md_wakeup_thread(conf->mddev->thread); in release_inactive_stripe_list()
362 static int release_stripe_list(struct r5conf *conf, in release_stripe_list() argument
364 __must_hold(&conf->device_lock) in release_stripe_list()
370 head = llist_del_all(&conf->released_stripes); in release_stripe_list()
384 __release_stripe(conf, sh, &temp_inactive_list[hash]); in release_stripe_list()
393 struct r5conf *conf = sh->raid_conf; in raid5_release_stripe() local
404 if (unlikely(!conf->mddev->thread) || in raid5_release_stripe()
407 wakeup = llist_add(&sh->release_list, &conf->released_stripes); in raid5_release_stripe()
409 md_wakeup_thread(conf->mddev->thread); in raid5_release_stripe()
413 if (atomic_dec_and_lock_irqsave(&sh->count, &conf->device_lock, flags)) { in raid5_release_stripe()
416 do_release_stripe(conf, sh, &list); in raid5_release_stripe()
417 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_release_stripe()
418 release_inactive_stripe_list(conf, &list, hash); in raid5_release_stripe()
430 static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) in insert_hash() argument
432 struct hlist_head *hp = stripe_hash(conf, sh->sector); in insert_hash()
441 static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) in get_free_stripe() argument
446 if (list_empty(conf->inactive_list + hash)) in get_free_stripe()
448 first = (conf->inactive_list + hash)->next; in get_free_stripe()
452 atomic_inc(&conf->active_stripes); in get_free_stripe()
454 if (list_empty(conf->inactive_list + hash)) in get_free_stripe()
455 atomic_inc(&conf->empty_inactive_list_nr); in get_free_stripe()
499 init_stripe_shared_pages(struct stripe_head *sh, struct r5conf *conf, int disks) in init_stripe_shared_pages() argument
507 cnt = PAGE_SIZE / conf->stripe_size; in init_stripe_shared_pages()
571 static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous,
576 struct r5conf *conf = sh->raid_conf; in init_stripe() local
587 seq = read_seqcount_begin(&conf->gen_lock); in init_stripe()
588 sh->generation = conf->generation - previous; in init_stripe()
589 sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; in init_stripe()
591 stripe_set_idx(sector, conf, previous, sh); in init_stripe()
608 if (read_seqcount_retry(&conf->gen_lock, seq)) in init_stripe()
611 insert_hash(conf, sh); in init_stripe()
616 static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, in __find_stripe() argument
622 hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) in __find_stripe()
629 static struct stripe_head *find_get_stripe(struct r5conf *conf, in find_get_stripe() argument
635 sh = __find_stripe(conf, sector, generation); in find_get_stripe()
648 spin_lock(&conf->device_lock); in find_get_stripe()
651 atomic_inc(&conf->active_stripes); in find_get_stripe()
655 if (!list_empty(conf->inactive_list + hash)) in find_get_stripe()
658 if (list_empty(conf->inactive_list + hash) && in find_get_stripe()
660 atomic_inc(&conf->empty_inactive_list_nr); in find_get_stripe()
667 spin_unlock(&conf->device_lock); in find_get_stripe()
689 int raid5_calc_degraded(struct r5conf *conf) in raid5_calc_degraded() argument
696 for (i = 0; i < conf->previous_raid_disks; i++) { in raid5_calc_degraded()
697 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); in raid5_calc_degraded()
699 rdev = rcu_dereference(conf->disks[i].replacement); in raid5_calc_degraded()
714 if (conf->raid_disks >= conf->previous_raid_disks) in raid5_calc_degraded()
718 if (conf->raid_disks == conf->previous_raid_disks) in raid5_calc_degraded()
722 for (i = 0; i < conf->raid_disks; i++) { in raid5_calc_degraded()
723 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); in raid5_calc_degraded()
725 rdev = rcu_dereference(conf->disks[i].replacement); in raid5_calc_degraded()
736 if (conf->raid_disks <= conf->previous_raid_disks) in raid5_calc_degraded()
745 static bool has_failed(struct r5conf *conf) in has_failed() argument
747 int degraded = conf->mddev->degraded; in has_failed()
749 if (test_bit(MD_BROKEN, &conf->mddev->flags)) in has_failed()
752 if (conf->mddev->reshape_position != MaxSector) in has_failed()
753 degraded = raid5_calc_degraded(conf); in has_failed()
755 return degraded > conf->max_degraded; in has_failed()
790 static bool is_inactive_blocked(struct r5conf *conf, int hash) in is_inactive_blocked() argument
792 if (list_empty(conf->inactive_list + hash)) in is_inactive_blocked()
795 if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) in is_inactive_blocked()
798 return (atomic_read(&conf->active_stripes) < in is_inactive_blocked()
799 (conf->max_nr_stripes * 3 / 4)); in is_inactive_blocked()
802 struct stripe_head *raid5_get_active_stripe(struct r5conf *conf, in raid5_get_active_stripe() argument
807 int hash = stripe_hash_locks_hash(conf, sector); in raid5_get_active_stripe()
812 spin_lock_irq(conf->hash_locks + hash); in raid5_get_active_stripe()
815 if (!(flags & R5_GAS_NOQUIESCE) && conf->quiesce) { in raid5_get_active_stripe()
828 wait_event_lock_irq(conf->wait_for_quiescent, in raid5_get_active_stripe()
829 !conf->quiesce, in raid5_get_active_stripe()
830 *(conf->hash_locks + hash)); in raid5_get_active_stripe()
833 sh = find_get_stripe(conf, sector, conf->generation - previous, in raid5_get_active_stripe()
838 if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { in raid5_get_active_stripe()
839 sh = get_free_stripe(conf, hash); in raid5_get_active_stripe()
841 r5c_check_stripe_cache_usage(conf); in raid5_get_active_stripe()
847 if (!test_bit(R5_DID_ALLOC, &conf->cache_state)) in raid5_get_active_stripe()
848 set_bit(R5_ALLOC_MORE, &conf->cache_state); in raid5_get_active_stripe()
854 set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); in raid5_get_active_stripe()
855 r5l_wake_reclaim(conf->log, 0); in raid5_get_active_stripe()
863 wait_event_lock_irq(conf->wait_for_stripe, in raid5_get_active_stripe()
864 is_inactive_blocked(conf, hash), in raid5_get_active_stripe()
865 *(conf->hash_locks + hash)); in raid5_get_active_stripe()
866 clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); in raid5_get_active_stripe()
869 spin_unlock_irq(conf->hash_locks + hash); in raid5_get_active_stripe()
903 struct r5conf *conf = sh->raid_conf; in stripe_can_batch() local
905 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in stripe_can_batch()
913 static void stripe_add_to_batch_list(struct r5conf *conf, in stripe_add_to_batch_list() argument
923 if (!sector_div(tmp_sec, conf->chunk_sectors)) in stripe_add_to_batch_list()
925 head_sector = sh->sector - RAID5_STRIPE_SECTORS(conf); in stripe_add_to_batch_list()
931 hash = stripe_hash_locks_hash(conf, head_sector); in stripe_add_to_batch_list()
932 spin_lock_irq(conf->hash_locks + hash); in stripe_add_to_batch_list()
933 head = find_get_stripe(conf, head_sector, conf->generation, in stripe_add_to_batch_list()
935 spin_unlock_irq(conf->hash_locks + hash); in stripe_add_to_batch_list()
988 if (atomic_dec_return(&conf->preread_active_stripes) in stripe_add_to_batch_list()
990 md_wakeup_thread(conf->mddev->thread); in stripe_add_to_batch_list()
1011 static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) in use_new_offset() argument
1013 sector_t progress = conf->reshape_progress; in use_new_offset()
1021 if (sh->generation == conf->generation - 1) in use_new_offset()
1051 static void dispatch_defer_bios(struct r5conf *conf, int target, in dispatch_defer_bios() argument
1058 if (conf->pending_data_cnt == 0) in dispatch_defer_bios()
1061 list_sort(NULL, &conf->pending_list, cmp_stripe); in dispatch_defer_bios()
1063 first = conf->pending_list.next; in dispatch_defer_bios()
1066 if (conf->next_pending_data) in dispatch_defer_bios()
1067 list_move_tail(&conf->pending_list, in dispatch_defer_bios()
1068 &conf->next_pending_data->sibling); in dispatch_defer_bios()
1070 while (!list_empty(&conf->pending_list)) { in dispatch_defer_bios()
1071 data = list_first_entry(&conf->pending_list, in dispatch_defer_bios()
1078 list_move(&data->sibling, &conf->free_list); in dispatch_defer_bios()
1083 conf->pending_data_cnt -= cnt; in dispatch_defer_bios()
1084 BUG_ON(conf->pending_data_cnt < 0 || cnt < target); in dispatch_defer_bios()
1086 if (next != &conf->pending_list) in dispatch_defer_bios()
1087 conf->next_pending_data = list_entry(next, in dispatch_defer_bios()
1090 conf->next_pending_data = NULL; in dispatch_defer_bios()
1092 if (first != &conf->pending_list) in dispatch_defer_bios()
1093 list_move_tail(&conf->pending_list, first); in dispatch_defer_bios()
1096 static void flush_deferred_bios(struct r5conf *conf) in flush_deferred_bios() argument
1100 if (conf->pending_data_cnt == 0) in flush_deferred_bios()
1103 spin_lock(&conf->pending_bios_lock); in flush_deferred_bios()
1104 dispatch_defer_bios(conf, conf->pending_data_cnt, &tmp); in flush_deferred_bios()
1105 BUG_ON(conf->pending_data_cnt != 0); in flush_deferred_bios()
1106 spin_unlock(&conf->pending_bios_lock); in flush_deferred_bios()
1111 static void defer_issue_bios(struct r5conf *conf, sector_t sector, in defer_issue_bios() argument
1117 spin_lock(&conf->pending_bios_lock); in defer_issue_bios()
1118 ent = list_first_entry(&conf->free_list, struct r5pending_data, in defer_issue_bios()
1120 list_move_tail(&ent->sibling, &conf->pending_list); in defer_issue_bios()
1124 conf->pending_data_cnt++; in defer_issue_bios()
1125 if (conf->pending_data_cnt >= PENDING_IO_MAX) in defer_issue_bios()
1126 dispatch_defer_bios(conf, PENDING_IO_ONE_FLUSH, &tmp); in defer_issue_bios()
1128 spin_unlock(&conf->pending_bios_lock); in defer_issue_bios()
1140 struct r5conf *conf = sh->raid_conf; in ops_run_io() local
1152 should_defer = conf->batch_bio_dispatch && conf->group_cnt; in ops_run_io()
1185 rrdev = rcu_dereference(conf->disks[i].replacement); in ops_run_io()
1187 rdev = rcu_dereference(conf->disks[i].rdev); in ops_run_io()
1222 int bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in ops_run_io()
1229 if (!conf->mddev->external && in ops_run_io()
1230 conf->mddev->sb_flags) { in ops_run_io()
1235 md_check_recovery(conf->mddev); in ops_run_io()
1243 md_wait_for_blocked_rdev(rdev, conf->mddev); in ops_run_io()
1246 rdev_dec_pending(rdev, conf->mddev); in ops_run_io()
1254 md_sync_acct(rdev->bdev, RAID5_STRIPE_SECTORS(conf)); in ops_run_io()
1270 if (use_new_offset(conf, sh)) in ops_run_io()
1293 bi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1295 bi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1305 if (conf->mddev->gendisk) in ops_run_io()
1307 disk_devt(conf->mddev->gendisk), in ops_run_io()
1317 md_sync_acct(rrdev->bdev, RAID5_STRIPE_SECTORS(conf)); in ops_run_io()
1333 if (use_new_offset(conf, sh)) in ops_run_io()
1343 rbi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1345 rbi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1352 if (conf->mddev->gendisk) in ops_run_io()
1354 disk_devt(conf->mddev->gendisk), in ops_run_io()
1379 defer_issue_bios(conf, head_sh->sector, &pending_bios); in ops_run_io()
1393 struct r5conf *conf = sh->raid_conf; in async_copy_data() local
1415 if (len > 0 && page_offset + len > RAID5_STRIPE_SIZE(conf)) in async_copy_data()
1416 clen = RAID5_STRIPE_SIZE(conf) - page_offset; in async_copy_data()
1424 if (conf->skip_copy && in async_copy_data()
1426 clen == RAID5_STRIPE_SIZE(conf) && in async_copy_data()
1451 struct r5conf *conf = sh->raid_conf; in ops_complete_biofill() local
1472 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_complete_biofill()
1473 rbi2 = r5_next_bio(conf, rbi, dev->sector); in ops_complete_biofill()
1490 struct r5conf *conf = sh->raid_conf; in ops_run_biofill() local
1505 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_run_biofill()
1509 rbi = r5_next_bio(conf, rbi, dev->sector); in ops_run_biofill()
1935 struct r5conf *conf = sh->raid_conf; in ops_run_biodrain() local
1968 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_run_biodrain()
1979 r5c_is_writeback(conf->log)); in ops_run_biodrain()
1981 !r5c_is_writeback(conf->log)) { in ops_run_biodrain()
1987 wbi = r5_next_bio(conf, wbi, dev->sector); in ops_run_biodrain()
2292 struct r5conf *conf = sh->raid_conf; in raid_run_ops() local
2293 int level = conf->level; in raid_run_ops()
2296 local_lock(&conf->percpu->lock); in raid_run_ops()
2297 percpu = this_cpu_ptr(conf->percpu); in raid_run_ops()
2357 local_unlock(&conf->percpu->lock); in raid_run_ops()
2371 int disks, struct r5conf *conf) in alloc_stripe() argument
2384 sh->raid_conf = conf; in alloc_stripe()
2387 if (raid5_has_ppl(conf)) { in alloc_stripe()
2395 if (init_stripe_shared_pages(sh, conf, disks)) { in alloc_stripe()
2403 static int grow_one_stripe(struct r5conf *conf, gfp_t gfp) in grow_one_stripe() argument
2407 sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size, conf); in grow_one_stripe()
2413 free_stripe(conf->slab_cache, sh); in grow_one_stripe()
2417 conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS; in grow_one_stripe()
2419 atomic_inc(&conf->active_stripes); in grow_one_stripe()
2422 WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes + 1); in grow_one_stripe()
2426 static int grow_stripes(struct r5conf *conf, int num) in grow_stripes() argument
2429 size_t namelen = sizeof(conf->cache_name[0]); in grow_stripes()
2430 int devs = max(conf->raid_disks, conf->previous_raid_disks); in grow_stripes()
2432 if (conf->mddev->gendisk) in grow_stripes()
2433 snprintf(conf->cache_name[0], namelen, in grow_stripes()
2434 "raid%d-%s", conf->level, mdname(conf->mddev)); in grow_stripes()
2436 snprintf(conf->cache_name[0], namelen, in grow_stripes()
2437 "raid%d-%p", conf->level, conf->mddev); in grow_stripes()
2438 snprintf(conf->cache_name[1], namelen, "%.27s-alt", conf->cache_name[0]); in grow_stripes()
2440 conf->active_name = 0; in grow_stripes()
2441 sc = kmem_cache_create(conf->cache_name[conf->active_name], in grow_stripes()
2446 conf->slab_cache = sc; in grow_stripes()
2447 conf->pool_size = devs; in grow_stripes()
2449 if (!grow_one_stripe(conf, GFP_KERNEL)) in grow_stripes()
2496 static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors) in resize_chunks() argument
2506 if (conf->scribble_disks >= new_disks && in resize_chunks()
2507 conf->scribble_sectors >= new_sectors) in resize_chunks()
2509 mddev_suspend(conf->mddev); in resize_chunks()
2515 percpu = per_cpu_ptr(conf->percpu, cpu); in resize_chunks()
2517 new_sectors / RAID5_STRIPE_SECTORS(conf)); in resize_chunks()
2523 mddev_resume(conf->mddev); in resize_chunks()
2525 conf->scribble_disks = new_disks; in resize_chunks()
2526 conf->scribble_sectors = new_sectors; in resize_chunks()
2531 static int resize_stripes(struct r5conf *conf, int newsize) in resize_stripes() argument
2564 md_allow_write(conf->mddev); in resize_stripes()
2567 sc = kmem_cache_create(conf->cache_name[1-conf->active_name], in resize_stripes()
2574 mutex_lock(&conf->cache_size_mutex); in resize_stripes()
2576 for (i = conf->max_nr_stripes; i; i--) { in resize_stripes()
2577 nsh = alloc_stripe(sc, GFP_KERNEL, newsize, conf); in resize_stripes()
2591 mutex_unlock(&conf->cache_size_mutex); in resize_stripes()
2601 lock_device_hash_lock(conf, hash); in resize_stripes()
2602 wait_event_cmd(conf->wait_for_stripe, in resize_stripes()
2603 !list_empty(conf->inactive_list + hash), in resize_stripes()
2604 unlock_device_hash_lock(conf, hash), in resize_stripes()
2605 lock_device_hash_lock(conf, hash)); in resize_stripes()
2606 osh = get_free_stripe(conf, hash); in resize_stripes()
2607 unlock_device_hash_lock(conf, hash); in resize_stripes()
2615 for(i=0; i<conf->pool_size; i++) { in resize_stripes()
2621 free_stripe(conf->slab_cache, osh); in resize_stripes()
2623 if (cnt >= conf->max_nr_stripes / NR_STRIPE_HASH_LOCKS + in resize_stripes()
2624 !!((conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS) > hash)) { in resize_stripes()
2629 kmem_cache_destroy(conf->slab_cache); in resize_stripes()
2638 for (i = 0; i < conf->pool_size; i++) in resize_stripes()
2639 ndisks[i] = conf->disks[i]; in resize_stripes()
2641 for (i = conf->pool_size; i < newsize; i++) { in resize_stripes()
2648 for (i = conf->pool_size; i < newsize; i++) in resize_stripes()
2653 kfree(conf->disks); in resize_stripes()
2654 conf->disks = ndisks; in resize_stripes()
2659 conf->slab_cache = sc; in resize_stripes()
2660 conf->active_name = 1-conf->active_name; in resize_stripes()
2676 for (i = conf->raid_disks; i < newsize; i++) { in resize_stripes()
2684 for (i=conf->raid_disks; i < newsize; i++) in resize_stripes()
2699 conf->pool_size = newsize; in resize_stripes()
2700 mutex_unlock(&conf->cache_size_mutex); in resize_stripes()
2705 static int drop_one_stripe(struct r5conf *conf) in drop_one_stripe() argument
2708 int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK; in drop_one_stripe()
2710 spin_lock_irq(conf->hash_locks + hash); in drop_one_stripe()
2711 sh = get_free_stripe(conf, hash); in drop_one_stripe()
2712 spin_unlock_irq(conf->hash_locks + hash); in drop_one_stripe()
2717 free_stripe(conf->slab_cache, sh); in drop_one_stripe()
2718 atomic_dec(&conf->active_stripes); in drop_one_stripe()
2719 WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes - 1); in drop_one_stripe()
2723 static void shrink_stripes(struct r5conf *conf) in shrink_stripes() argument
2725 while (conf->max_nr_stripes && in shrink_stripes()
2726 drop_one_stripe(conf)) in shrink_stripes()
2729 kmem_cache_destroy(conf->slab_cache); in shrink_stripes()
2730 conf->slab_cache = NULL; in shrink_stripes()
2758 struct r5conf *conf = sh->raid_conf; in raid5_end_read_request() local
2780 rdev = rdev_pend_deref(conf->disks[i].replacement); in raid5_end_read_request()
2782 rdev = rdev_pend_deref(conf->disks[i].rdev); in raid5_end_read_request()
2784 if (use_new_offset(conf, sh)) in raid5_end_read_request()
2797 mdname(conf->mddev), RAID5_STRIPE_SECTORS(conf), in raid5_end_read_request()
2800 atomic_add(RAID5_STRIPE_SECTORS(conf), &rdev->corrected_errors); in raid5_end_read_request()
2825 mdname(conf->mddev), in raid5_end_read_request()
2828 else if (conf->mddev->degraded >= conf->max_degraded) { in raid5_end_read_request()
2832 mdname(conf->mddev), in raid5_end_read_request()
2840 mdname(conf->mddev), in raid5_end_read_request()
2844 > conf->max_nr_stripes) { in raid5_end_read_request()
2847 mdname(conf->mddev), in raid5_end_read_request()
2849 conf->max_nr_stripes); in raid5_end_read_request()
2851 mdname(conf->mddev), rdev->bdev); in raid5_end_read_request()
2872 rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0))) in raid5_end_read_request()
2873 md_error(conf->mddev, rdev); in raid5_end_read_request()
2876 rdev_dec_pending(rdev, conf->mddev); in raid5_end_read_request()
2886 struct r5conf *conf = sh->raid_conf; in raid5_end_write_request() local
2895 rdev = rdev_pend_deref(conf->disks[i].rdev); in raid5_end_write_request()
2899 rdev = rdev_pend_deref(conf->disks[i].replacement); in raid5_end_write_request()
2907 rdev = rdev_pend_deref(conf->disks[i].rdev); in raid5_end_write_request()
2921 md_error(conf->mddev, rdev); in raid5_end_write_request()
2923 RAID5_STRIPE_SECTORS(conf), in raid5_end_write_request()
2935 RAID5_STRIPE_SECTORS(conf), in raid5_end_write_request()
2946 rdev_dec_pending(rdev, conf->mddev); in raid5_end_write_request()
2963 struct r5conf *conf = mddev->private; in raid5_error() local
2970 spin_lock_irqsave(&conf->device_lock, flags); in raid5_error()
2973 mddev->degraded = raid5_calc_degraded(conf); in raid5_error()
2975 if (has_failed(conf)) { in raid5_error()
2976 set_bit(MD_BROKEN, &conf->mddev->flags); in raid5_error()
2977 conf->recovery_disabled = mddev->recovery_disabled; in raid5_error()
2980 mdname(mddev), mddev->degraded, conf->raid_disks); in raid5_error()
2983 mdname(mddev), conf->raid_disks - mddev->degraded); in raid5_error()
2986 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_error()
2999 sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, in raid5_compute_sector() argument
3009 int algorithm = previous ? conf->prev_algo in raid5_compute_sector()
3010 : conf->algorithm; in raid5_compute_sector()
3011 int sectors_per_chunk = previous ? conf->prev_chunk_sectors in raid5_compute_sector()
3012 : conf->chunk_sectors; in raid5_compute_sector()
3013 int raid_disks = previous ? conf->previous_raid_disks in raid5_compute_sector()
3014 : conf->raid_disks; in raid5_compute_sector()
3015 int data_disks = raid_disks - conf->max_degraded; in raid5_compute_sector()
3035 switch(conf->level) { in raid5_compute_sector()
3203 struct r5conf *conf = sh->raid_conf; in raid5_compute_blocknr() local
3205 int data_disks = raid_disks - conf->max_degraded; in raid5_compute_blocknr()
3207 int sectors_per_chunk = previous ? conf->prev_chunk_sectors in raid5_compute_blocknr()
3208 : conf->chunk_sectors; in raid5_compute_blocknr()
3209 int algorithm = previous ? conf->prev_algo in raid5_compute_blocknr()
3210 : conf->algorithm; in raid5_compute_blocknr()
3223 switch(conf->level) { in raid5_compute_blocknr()
3310 check = raid5_compute_sector(conf, r_sector, in raid5_compute_blocknr()
3315 mdname(conf->mddev)); in raid5_compute_blocknr()
3359 static inline bool delay_towrite(struct r5conf *conf, in delay_towrite() argument
3368 if (test_bit(R5C_LOG_CRITICAL, &conf->cache_state) && in delay_towrite()
3382 struct r5conf *conf = sh->raid_conf; in schedule_reconstruction() local
3383 int level = conf->level; in schedule_reconstruction()
3397 if (dev->towrite && !delay_towrite(conf, dev, s)) { in schedule_reconstruction()
3423 if (s->locked + conf->max_degraded == disks) in schedule_reconstruction()
3425 atomic_inc(&conf->pending_full_writes); in schedule_reconstruction()
3489 struct r5conf *conf = sh->raid_conf; in stripe_bio_overlaps() local
3513 if (forwrite && raid5_has_ppl(conf)) { in stripe_bio_overlaps()
3539 if (first + conf->chunk_sectors * (count - 1) != last) in stripe_bio_overlaps()
3549 struct r5conf *conf = sh->raid_conf; in __add_stripe_bio() local
3572 md_write_inc(conf->mddev, bi); in __add_stripe_bio()
3578 sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && in __add_stripe_bio()
3580 bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { in __add_stripe_bio()
3584 if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) in __add_stripe_bio()
3593 if (conf->mddev->bitmap && firstwrite) { in __add_stripe_bio()
3608 md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, in __add_stripe_bio()
3609 RAID5_STRIPE_SECTORS(conf), 0); in __add_stripe_bio()
3613 sh->bm_seq = conf->seq_flush+1; in __add_stripe_bio()
3640 static void end_reshape(struct r5conf *conf);
3642 static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, in stripe_set_idx() argument
3646 previous ? conf->prev_chunk_sectors : conf->chunk_sectors; in stripe_set_idx()
3649 int disks = previous ? conf->previous_raid_disks : conf->raid_disks; in stripe_set_idx()
3651 raid5_compute_sector(conf, in stripe_set_idx()
3652 stripe * (disks - conf->max_degraded) in stripe_set_idx()
3659 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, in handle_failed_stripe() argument
3671 rdev = rcu_dereference(conf->disks[i].rdev); in handle_failed_stripe()
3682 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_stripe()
3683 md_error(conf->mddev, rdev); in handle_failed_stripe()
3684 rdev_dec_pending(rdev, conf->mddev); in handle_failed_stripe()
3699 wake_up(&conf->wait_for_overlap); in handle_failed_stripe()
3702 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3703 struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3705 md_write_end(conf->mddev); in handle_failed_stripe()
3710 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3711 RAID5_STRIPE_SECTORS(conf), 0, 0); in handle_failed_stripe()
3723 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3724 struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3726 md_write_end(conf->mddev); in handle_failed_stripe()
3735 s->failed > conf->max_degraded && in handle_failed_stripe()
3743 wake_up(&conf->wait_for_overlap); in handle_failed_stripe()
3747 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3749 r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3756 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3757 RAID5_STRIPE_SECTORS(conf), 0, 0); in handle_failed_stripe()
3767 if (atomic_dec_and_test(&conf->pending_full_writes)) in handle_failed_stripe()
3768 md_wakeup_thread(conf->mddev->thread); in handle_failed_stripe()
3772 handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, in handle_failed_sync() argument
3781 wake_up(&conf->wait_for_overlap); in handle_failed_sync()
3791 if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { in handle_failed_sync()
3796 for (i = 0; i < conf->raid_disks; i++) { in handle_failed_sync()
3797 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); in handle_failed_sync()
3802 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_sync()
3804 rdev = rcu_dereference(conf->disks[i].replacement); in handle_failed_sync()
3809 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_sync()
3814 conf->recovery_disabled = in handle_failed_sync()
3815 conf->mddev->recovery_disabled; in handle_failed_sync()
3817 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), !abort); in handle_failed_sync()
4071 static void handle_stripe_clean_event(struct r5conf *conf, in handle_stripe_clean_event() argument
4102 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in handle_stripe_clean_event()
4103 wbi2 = r5_next_bio(conf, wbi, dev->sector); in handle_stripe_clean_event()
4104 md_write_end(conf->mddev); in handle_stripe_clean_event()
4108 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_stripe_clean_event()
4109 RAID5_STRIPE_SECTORS(conf), in handle_stripe_clean_event()
4147 spin_lock_irq(conf->hash_locks + hash); in handle_stripe_clean_event()
4149 spin_unlock_irq(conf->hash_locks + hash); in handle_stripe_clean_event()
4164 if (atomic_dec_and_test(&conf->pending_full_writes)) in handle_stripe_clean_event()
4165 md_wakeup_thread(conf->mddev->thread); in handle_stripe_clean_event()
4186 static int handle_stripe_dirtying(struct r5conf *conf, in handle_stripe_dirtying() argument
4192 sector_t recovery_cp = conf->mddev->recovery_cp; in handle_stripe_dirtying()
4201 if (conf->rmw_level == PARITY_DISABLE_RMW || in handle_stripe_dirtying()
4209 conf->rmw_level, (unsigned long long)recovery_cp, in handle_stripe_dirtying()
4214 if (((dev->towrite && !delay_towrite(conf, dev, s)) || in handle_stripe_dirtying()
4241 if ((rmw < rcw || (rmw == rcw && conf->rmw_level == PARITY_PREFER_RMW)) && rmw > 0) { in handle_stripe_dirtying()
4243 if (conf->mddev->queue) in handle_stripe_dirtying()
4244 blk_add_trace_msg(conf->mddev->queue, in handle_stripe_dirtying()
4265 &conf->cache_state)) { in handle_stripe_dirtying()
4279 if (((dev->towrite && !delay_towrite(conf, dev, s)) || in handle_stripe_dirtying()
4298 if ((rcw < rmw || (rcw == rmw && conf->rmw_level != PARITY_PREFER_RMW)) && rcw > 0) { in handle_stripe_dirtying()
4323 if (rcw && conf->mddev->queue) in handle_stripe_dirtying()
4324 blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", in handle_stripe_dirtying()
4350 static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks5() argument
4412 atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); in handle_parity_checks5()
4413 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks5()
4417 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks5()
4420 RAID5_STRIPE_SECTORS(conf)); in handle_parity_checks5()
4443 static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks6() argument
4539 mdname(conf->mddev), in handle_parity_checks6()
4577 atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); in handle_parity_checks6()
4578 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks6()
4582 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks6()
4585 RAID5_STRIPE_SECTORS(conf)); in handle_parity_checks6()
4620 static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) in handle_stripe_expansion() argument
4637 sector_t s = raid5_compute_sector(conf, bn, 0, in handle_stripe_expansion()
4639 sh2 = raid5_get_active_stripe(conf, NULL, s, in handle_stripe_expansion()
4658 sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), in handle_stripe_expansion()
4663 for (j = 0; j < conf->raid_disks; j++) in handle_stripe_expansion()
4668 if (j == conf->raid_disks) { in handle_stripe_expansion()
4695 struct r5conf *conf = sh->raid_conf; in analyse_stripe() local
4707 s->log_failed = r5l_log_disk_error(conf); in analyse_stripe()
4755 rdev = rcu_dereference(conf->disks[i].replacement); in analyse_stripe()
4757 rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && in analyse_stripe()
4758 !is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4766 rdev = rcu_dereference(conf->disks[i].rdev); in analyse_stripe()
4772 is_bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), in analyse_stripe()
4799 else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) in analyse_stripe()
4814 conf->disks[i].rdev); in analyse_stripe()
4827 conf->disks[i].rdev); in analyse_stripe()
4836 conf->disks[i].replacement); in analyse_stripe()
4858 conf->disks[i].replacement); in analyse_stripe()
4879 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4880 test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) in analyse_stripe()
4990 struct r5conf *conf = sh->raid_conf; in handle_stripe() local
5047 test_bit(MD_SB_CHANGE_PENDING, &conf->mddev->sb_flags)) { in handle_stripe()
5059 rdev_dec_pending(s.blocked_rdev, conf->mddev); in handle_stripe()
5079 if (s.failed > conf->max_degraded || in handle_stripe()
5085 handle_failed_stripe(conf, sh, &s, disks); in handle_stripe()
5087 handle_failed_sync(conf, sh, &s); in handle_stripe()
5140 || conf->level < 6; in handle_stripe()
5151 handle_stripe_clean_event(conf, sh, disks); in handle_stripe()
5154 r5c_handle_cached_data_endio(conf, sh, disks); in handle_stripe()
5173 r5c_finish_stripe_write_out(conf, sh, &s); in handle_stripe()
5185 if (!r5c_is_writeback(conf->log)) { in handle_stripe()
5187 handle_stripe_dirtying(conf, sh, &s, disks); in handle_stripe()
5193 ret = r5c_try_caching_write(conf, sh, &s, in handle_stripe()
5206 ret = handle_stripe_dirtying(conf, sh, &s, in handle_stripe()
5223 if (conf->level == 6) in handle_stripe()
5224 handle_parity_checks6(conf, sh, &s, disks); in handle_stripe()
5226 handle_parity_checks5(conf, sh, &s, disks); in handle_stripe()
5233 for (i = 0; i < conf->raid_disks; i++) in handle_stripe()
5247 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); in handle_stripe()
5250 wake_up(&conf->wait_for_overlap); in handle_stripe()
5256 if (s.failed <= conf->max_degraded && !conf->mddev->ro) in handle_stripe()
5277 = raid5_get_active_stripe(conf, NULL, sh->sector, in handle_stripe()
5288 atomic_inc(&conf->preread_active_stripes); in handle_stripe()
5297 for (i = conf->raid_disks; i--; ) { in handle_stripe()
5307 sh->disks = conf->raid_disks; in handle_stripe()
5308 stripe_set_idx(sh->sector, conf, 0, sh); in handle_stripe()
5312 atomic_dec(&conf->reshape_stripes); in handle_stripe()
5313 wake_up(&conf->wait_for_overlap); in handle_stripe()
5314 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); in handle_stripe()
5319 handle_stripe_expansion(conf, sh); in handle_stripe()
5324 if (conf->mddev->external) in handle_stripe()
5326 conf->mddev); in handle_stripe()
5333 conf->mddev); in handle_stripe()
5342 rdev = rdev_pend_deref(conf->disks[i].rdev); in handle_stripe()
5344 RAID5_STRIPE_SECTORS(conf), 0)) in handle_stripe()
5345 md_error(conf->mddev, rdev); in handle_stripe()
5346 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5349 rdev = rdev_pend_deref(conf->disks[i].rdev); in handle_stripe()
5351 RAID5_STRIPE_SECTORS(conf), 0); in handle_stripe()
5352 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5355 rdev = rdev_pend_deref(conf->disks[i].replacement); in handle_stripe()
5358 rdev = rdev_pend_deref(conf->disks[i].rdev); in handle_stripe()
5360 RAID5_STRIPE_SECTORS(conf), 0); in handle_stripe()
5361 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5375 atomic_dec(&conf->preread_active_stripes); in handle_stripe()
5376 if (atomic_read(&conf->preread_active_stripes) < in handle_stripe()
5378 md_wakeup_thread(conf->mddev->thread); in handle_stripe()
5384 static void raid5_activate_delayed(struct r5conf *conf) in raid5_activate_delayed() argument
5385 __must_hold(&conf->device_lock) in raid5_activate_delayed()
5387 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { in raid5_activate_delayed()
5388 while (!list_empty(&conf->delayed_list)) { in raid5_activate_delayed()
5389 struct list_head *l = conf->delayed_list.next; in raid5_activate_delayed()
5395 atomic_inc(&conf->preread_active_stripes); in raid5_activate_delayed()
5396 list_add_tail(&sh->lru, &conf->hold_list); in raid5_activate_delayed()
5402 static void activate_bit_delay(struct r5conf *conf, in activate_bit_delay() argument
5404 __must_hold(&conf->device_lock) in activate_bit_delay()
5407 list_add(&head, &conf->bitmap_list); in activate_bit_delay()
5408 list_del_init(&conf->bitmap_list); in activate_bit_delay()
5415 __release_stripe(conf, sh, &temp_inactive_list[hash]); in activate_bit_delay()
5421 struct r5conf *conf = mddev->private; in in_chunk_boundary() local
5426 chunk_sectors = min(conf->chunk_sectors, conf->prev_chunk_sectors); in in_chunk_boundary()
5435 static void add_bio_to_retry(struct bio *bi,struct r5conf *conf) in add_bio_to_retry() argument
5439 spin_lock_irqsave(&conf->device_lock, flags); in add_bio_to_retry()
5441 bi->bi_next = conf->retry_read_aligned_list; in add_bio_to_retry()
5442 conf->retry_read_aligned_list = bi; in add_bio_to_retry()
5444 spin_unlock_irqrestore(&conf->device_lock, flags); in add_bio_to_retry()
5445 md_wakeup_thread(conf->mddev->thread); in add_bio_to_retry()
5448 static struct bio *remove_bio_from_retry(struct r5conf *conf, in remove_bio_from_retry() argument
5453 bi = conf->retry_read_aligned; in remove_bio_from_retry()
5455 *offset = conf->retry_read_offset; in remove_bio_from_retry()
5456 conf->retry_read_aligned = NULL; in remove_bio_from_retry()
5459 bi = conf->retry_read_aligned_list; in remove_bio_from_retry()
5461 conf->retry_read_aligned_list = bi->bi_next; in remove_bio_from_retry()
5480 struct r5conf *conf = mddev->private; in raid5_align_endio() local
5485 rdev_dec_pending(rdev, conf->mddev); in raid5_align_endio()
5489 if (atomic_dec_and_test(&conf->active_aligned_reads)) in raid5_align_endio()
5490 wake_up(&conf->wait_for_quiescent); in raid5_align_endio()
5496 add_bio_to_retry(raid_bi, conf); in raid5_align_endio()
5501 struct r5conf *conf = mddev->private; in raid5_read_one_chunk() local
5513 sector = raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, 0, in raid5_read_one_chunk()
5518 if (r5c_big_stripe_cached(conf, sector)) in raid5_read_one_chunk()
5521 rdev = rcu_dereference(conf->disks[dd_idx].replacement); in raid5_read_one_chunk()
5524 rdev = rcu_dereference(conf->disks[dd_idx].rdev); in raid5_read_one_chunk()
5555 if (conf->quiesce == 0) { in raid5_read_one_chunk()
5556 atomic_inc(&conf->active_aligned_reads); in raid5_read_one_chunk()
5560 if (!did_inc || smp_load_acquire(&conf->quiesce) != 0) { in raid5_read_one_chunk()
5564 if (did_inc && atomic_dec_and_test(&conf->active_aligned_reads)) in raid5_read_one_chunk()
5565 wake_up(&conf->wait_for_quiescent); in raid5_read_one_chunk()
5566 spin_lock_irq(&conf->device_lock); in raid5_read_one_chunk()
5567 wait_event_lock_irq(conf->wait_for_quiescent, conf->quiesce == 0, in raid5_read_one_chunk()
5568 conf->device_lock); in raid5_read_one_chunk()
5569 atomic_inc(&conf->active_aligned_reads); in raid5_read_one_chunk()
5570 spin_unlock_irq(&conf->device_lock); in raid5_read_one_chunk()
5592 struct r5conf *conf = mddev->private; in chunk_aligned_read() local
5593 split = bio_split(raid_bio, sectors, GFP_NOIO, &conf->bio_split); in chunk_aligned_read()
5615 static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group) in __get_priority_stripe() argument
5616 __must_hold(&conf->device_lock) in __get_priority_stripe()
5621 bool second_try = !r5c_is_writeback(conf->log) && in __get_priority_stripe()
5622 !r5l_log_disk_error(conf); in __get_priority_stripe()
5623 bool try_loprio = test_bit(R5C_LOG_TIGHT, &conf->cache_state) || in __get_priority_stripe()
5624 r5l_log_disk_error(conf); in __get_priority_stripe()
5629 if (conf->worker_cnt_per_group == 0) { in __get_priority_stripe()
5630 handle_list = try_loprio ? &conf->loprio_list : in __get_priority_stripe()
5631 &conf->handle_list; in __get_priority_stripe()
5633 handle_list = try_loprio ? &conf->worker_groups[group].loprio_list : in __get_priority_stripe()
5634 &conf->worker_groups[group].handle_list; in __get_priority_stripe()
5635 wg = &conf->worker_groups[group]; in __get_priority_stripe()
5638 for (i = 0; i < conf->group_cnt; i++) { in __get_priority_stripe()
5639 handle_list = try_loprio ? &conf->worker_groups[i].loprio_list : in __get_priority_stripe()
5640 &conf->worker_groups[i].handle_list; in __get_priority_stripe()
5641 wg = &conf->worker_groups[i]; in __get_priority_stripe()
5650 list_empty(&conf->hold_list) ? "empty" : "busy", in __get_priority_stripe()
5651 atomic_read(&conf->pending_full_writes), conf->bypass_count); in __get_priority_stripe()
5656 if (list_empty(&conf->hold_list)) in __get_priority_stripe()
5657 conf->bypass_count = 0; in __get_priority_stripe()
5659 if (conf->hold_list.next == conf->last_hold) in __get_priority_stripe()
5660 conf->bypass_count++; in __get_priority_stripe()
5662 conf->last_hold = conf->hold_list.next; in __get_priority_stripe()
5663 conf->bypass_count -= conf->bypass_threshold; in __get_priority_stripe()
5664 if (conf->bypass_count < 0) in __get_priority_stripe()
5665 conf->bypass_count = 0; in __get_priority_stripe()
5668 } else if (!list_empty(&conf->hold_list) && in __get_priority_stripe()
5669 ((conf->bypass_threshold && in __get_priority_stripe()
5670 conf->bypass_count > conf->bypass_threshold) || in __get_priority_stripe()
5671 atomic_read(&conf->pending_full_writes) == 0)) { in __get_priority_stripe()
5673 list_for_each_entry(tmp, &conf->hold_list, lru) { in __get_priority_stripe()
5674 if (conf->worker_cnt_per_group == 0 || in __get_priority_stripe()
5684 conf->bypass_count -= conf->bypass_threshold; in __get_priority_stripe()
5685 if (conf->bypass_count < 0) in __get_priority_stripe()
5686 conf->bypass_count = 0; in __get_priority_stripe()
5720 struct r5conf *conf = mddev->private; in raid5_unplug() local
5725 spin_lock_irq(&conf->device_lock); in raid5_unplug()
5741 __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); in raid5_unplug()
5744 spin_unlock_irq(&conf->device_lock); in raid5_unplug()
5746 release_inactive_stripe_list(conf, cb->temp_inactive_list, in raid5_unplug()
5783 struct r5conf *conf = mddev->private; in make_discard_request() local
5796 logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in make_discard_request()
5801 stripe_sectors = conf->chunk_sectors * in make_discard_request()
5802 (conf->raid_disks - conf->max_degraded); in make_discard_request()
5807 logical_sector *= conf->chunk_sectors; in make_discard_request()
5808 last_sector *= conf->chunk_sectors; in make_discard_request()
5811 logical_sector += RAID5_STRIPE_SECTORS(conf)) { in make_discard_request()
5815 sh = raid5_get_active_stripe(conf, NULL, logical_sector, 0); in make_discard_request()
5816 prepare_to_wait(&conf->wait_for_overlap, &w, in make_discard_request()
5826 for (d = 0; d < conf->raid_disks; d++) { in make_discard_request()
5838 finish_wait(&conf->wait_for_overlap, &w); in make_discard_request()
5840 for (d = 0; d < conf->raid_disks; d++) { in make_discard_request()
5850 if (conf->mddev->bitmap) { in make_discard_request()
5852 d < conf->raid_disks - conf->max_degraded; in make_discard_request()
5856 RAID5_STRIPE_SECTORS(conf), in make_discard_request()
5858 sh->bm_seq = conf->seq_flush + 1; in make_discard_request()
5865 atomic_inc(&conf->preread_active_stripes); in make_discard_request()
5886 static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, in stripe_ahead_of_reshape() argument
5901 spin_lock_irq(&conf->device_lock); in stripe_ahead_of_reshape()
5904 conf->reshape_progress)) in stripe_ahead_of_reshape()
5908 spin_unlock_irq(&conf->device_lock); in stripe_ahead_of_reshape()
5913 static int add_all_stripe_bios(struct r5conf *conf, in add_all_stripe_bios() argument
5954 RAID5_STRIPE_SHIFT(conf), ctx->sectors_to_do); in add_all_stripe_bios()
5976 struct r5conf *conf, struct stripe_request_ctx *ctx, in make_stripe_request() argument
5986 seq = read_seqcount_begin(&conf->gen_lock); in make_stripe_request()
5988 if (unlikely(conf->reshape_progress != MaxSector)) { in make_stripe_request()
5998 spin_lock_irq(&conf->device_lock); in make_stripe_request()
6000 conf->reshape_progress)) { in make_stripe_request()
6004 conf->reshape_safe)) { in make_stripe_request()
6005 spin_unlock_irq(&conf->device_lock); in make_stripe_request()
6010 spin_unlock_irq(&conf->device_lock); in make_stripe_request()
6013 new_sector = raid5_compute_sector(conf, logical_sector, previous, in make_stripe_request()
6022 sh = raid5_get_active_stripe(conf, ctx, new_sector, flags); in make_stripe_request()
6030 stripe_ahead_of_reshape(mddev, conf, sh)) { in make_stripe_request()
6043 if (read_seqcount_retry(&conf->gen_lock, seq)) { in make_stripe_request()
6050 !add_all_stripe_bios(conf, ctx, sh, bi, rw, previous)) { in make_stripe_request()
6061 stripe_add_to_batch_list(conf, sh, ctx->batch_last); in make_stripe_request()
6079 atomic_inc(&conf->preread_active_stripes); in make_stripe_request()
6102 static sector_t raid5_bio_lowest_chunk_sector(struct r5conf *conf, in raid5_bio_lowest_chunk_sector() argument
6105 int sectors_per_chunk = conf->chunk_sectors; in raid5_bio_lowest_chunk_sector()
6106 int raid_disks = conf->raid_disks; in raid5_bio_lowest_chunk_sector()
6110 sector_t r_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in raid5_bio_lowest_chunk_sector()
6114 sector = raid5_compute_sector(conf, r_sector, 0, &dd_idx, &sh); in raid5_bio_lowest_chunk_sector()
6133 struct r5conf *conf = mddev->private; in raid5_make_request() local
6141 int ret = log_handle_flush_request(conf, bi); in raid5_make_request()
6177 logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in raid5_make_request()
6183 RAID5_STRIPE_SECTORS(conf)); in raid5_make_request()
6191 (conf->reshape_progress != MaxSector) && in raid5_make_request()
6192 !ahead_of_reshape(mddev, logical_sector, conf->reshape_progress) && in raid5_make_request()
6193 ahead_of_reshape(mddev, logical_sector, conf->reshape_safe)) { in raid5_make_request()
6208 if (likely(conf->reshape_progress == MaxSector)) in raid5_make_request()
6209 logical_sector = raid5_bio_lowest_chunk_sector(conf, bi); in raid5_make_request()
6210 s = (logical_sector - ctx.first_sector) >> RAID5_STRIPE_SHIFT(conf); in raid5_make_request()
6212 add_wait_queue(&conf->wait_for_overlap, &wait); in raid5_make_request()
6214 res = make_stripe_request(mddev, conf, &ctx, logical_sector, in raid5_make_request()
6245 (s << RAID5_STRIPE_SHIFT(conf)); in raid5_make_request()
6247 remove_wait_queue(&conf->wait_for_overlap, &wait); in raid5_make_request()
6271 struct r5conf *conf = mddev->private; in reshape_request() local
6275 int raid_disks = conf->previous_raid_disks; in reshape_request()
6276 int data_disks = raid_disks - conf->max_degraded; in reshape_request()
6277 int new_data_disks = conf->raid_disks - conf->max_degraded; in reshape_request()
6289 conf->reshape_progress < raid5_size(mddev, 0, 0)) { in reshape_request()
6291 - conf->reshape_progress; in reshape_request()
6293 conf->reshape_progress == MaxSector) { in reshape_request()
6297 conf->reshape_progress > 0) in reshape_request()
6298 sector_nr = conf->reshape_progress; in reshape_request()
6314 reshape_sectors = max(conf->chunk_sectors, conf->prev_chunk_sectors); in reshape_request()
6322 writepos = conf->reshape_progress; in reshape_request()
6324 readpos = conf->reshape_progress; in reshape_request()
6326 safepos = conf->reshape_safe; in reshape_request()
6349 if (WARN_ON(conf->reshape_progress == 0)) in reshape_request()
6384 if (conf->min_offset_diff < 0) { in reshape_request()
6385 safepos += -conf->min_offset_diff; in reshape_request()
6386 readpos += -conf->min_offset_diff; in reshape_request()
6388 writepos += conf->min_offset_diff; in reshape_request()
6393 time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { in reshape_request()
6395 wait_event(conf->wait_for_overlap, in reshape_request()
6396 atomic_read(&conf->reshape_stripes)==0 in reshape_request()
6398 if (atomic_read(&conf->reshape_stripes) != 0) in reshape_request()
6400 mddev->reshape_position = conf->reshape_progress; in reshape_request()
6411 conf->reshape_checkpoint = jiffies; in reshape_request()
6418 spin_lock_irq(&conf->device_lock); in reshape_request()
6419 conf->reshape_safe = mddev->reshape_position; in reshape_request()
6420 spin_unlock_irq(&conf->device_lock); in reshape_request()
6421 wake_up(&conf->wait_for_overlap); in reshape_request()
6426 for (i = 0; i < reshape_sectors; i += RAID5_STRIPE_SECTORS(conf)) { in reshape_request()
6429 sh = raid5_get_active_stripe(conf, NULL, stripe_addr+i, in reshape_request()
6432 atomic_inc(&conf->reshape_stripes); in reshape_request()
6440 if (conf->level == 6 && in reshape_request()
6448 memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); in reshape_request()
6458 spin_lock_irq(&conf->device_lock); in reshape_request()
6460 conf->reshape_progress -= reshape_sectors * new_data_disks; in reshape_request()
6462 conf->reshape_progress += reshape_sectors * new_data_disks; in reshape_request()
6463 spin_unlock_irq(&conf->device_lock); in reshape_request()
6470 raid5_compute_sector(conf, stripe_addr*(new_data_disks), in reshape_request()
6473 raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) in reshape_request()
6479 sh = raid5_get_active_stripe(conf, NULL, first_sector, in reshape_request()
6484 first_sector += RAID5_STRIPE_SECTORS(conf); in reshape_request()
6504 wait_event(conf->wait_for_overlap, in reshape_request()
6505 atomic_read(&conf->reshape_stripes) == 0 in reshape_request()
6507 if (atomic_read(&conf->reshape_stripes) != 0) in reshape_request()
6509 mddev->reshape_position = conf->reshape_progress; in reshape_request()
6519 conf->reshape_checkpoint = jiffies; in reshape_request()
6527 spin_lock_irq(&conf->device_lock); in reshape_request()
6528 conf->reshape_safe = mddev->reshape_position; in reshape_request()
6529 spin_unlock_irq(&conf->device_lock); in reshape_request()
6530 wake_up(&conf->wait_for_overlap); in reshape_request()
6540 struct r5conf *conf = mddev->private; in raid5_sync_request() local
6551 end_reshape(conf); in raid5_sync_request()
6559 conf->fullsync = 0; in raid5_sync_request()
6566 wait_event(conf->wait_for_overlap, conf->quiesce != 2); in raid5_sync_request()
6581 if (mddev->degraded >= conf->max_degraded && in raid5_sync_request()
6588 !conf->fullsync && in raid5_sync_request()
6590 sync_blocks >= RAID5_STRIPE_SECTORS(conf)) { in raid5_sync_request()
6592 do_div(sync_blocks, RAID5_STRIPE_SECTORS(conf)); in raid5_sync_request()
6595 return sync_blocks * RAID5_STRIPE_SECTORS(conf); in raid5_sync_request()
6600 sh = raid5_get_active_stripe(conf, NULL, sector_nr, in raid5_sync_request()
6603 sh = raid5_get_active_stripe(conf, NULL, sector_nr, 0); in raid5_sync_request()
6614 for (i = 0; i < conf->raid_disks; i++) { in raid5_sync_request()
6615 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); in raid5_sync_request()
6629 return RAID5_STRIPE_SECTORS(conf); in raid5_sync_request()
6632 static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio, in retry_aligned_read() argument
6652 ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in retry_aligned_read()
6653 sector = raid5_compute_sector(conf, logical_sector, in retry_aligned_read()
6658 logical_sector += RAID5_STRIPE_SECTORS(conf), in retry_aligned_read()
6659 sector += RAID5_STRIPE_SECTORS(conf), in retry_aligned_read()
6666 sh = raid5_get_active_stripe(conf, NULL, sector, in retry_aligned_read()
6670 conf->retry_read_aligned = raid_bio; in retry_aligned_read()
6671 conf->retry_read_offset = scnt; in retry_aligned_read()
6677 conf->retry_read_aligned = raid_bio; in retry_aligned_read()
6678 conf->retry_read_offset = scnt; in retry_aligned_read()
6690 if (atomic_dec_and_test(&conf->active_aligned_reads)) in retry_aligned_read()
6691 wake_up(&conf->wait_for_quiescent); in retry_aligned_read()
6695 static int handle_active_stripes(struct r5conf *conf, int group, in handle_active_stripes() argument
6698 __must_hold(&conf->device_lock) in handle_active_stripes()
6705 (sh = __get_priority_stripe(conf, group)) != NULL) in handle_active_stripes()
6713 spin_unlock_irq(&conf->device_lock); in handle_active_stripes()
6714 log_flush_stripe_to_raid(conf); in handle_active_stripes()
6715 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6720 spin_unlock_irq(&conf->device_lock); in handle_active_stripes()
6722 release_inactive_stripe_list(conf, temp_inactive_list, in handle_active_stripes()
6725 r5l_flush_stripe_to_raid(conf->log); in handle_active_stripes()
6727 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6733 log_write_stripe_run(conf); in handle_active_stripes()
6737 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6740 __release_stripe(conf, batch[i], &temp_inactive_list[hash]); in handle_active_stripes()
6749 struct r5conf *conf = group->conf; in raid5_do_work() local
6750 struct mddev *mddev = conf->mddev; in raid5_do_work()
6751 int group_id = group - conf->worker_groups; in raid5_do_work()
6759 spin_lock_irq(&conf->device_lock); in raid5_do_work()
6763 released = release_stripe_list(conf, worker->temp_inactive_list); in raid5_do_work()
6765 batch_size = handle_active_stripes(conf, group_id, worker, in raid5_do_work()
6773 conf->device_lock); in raid5_do_work()
6777 spin_unlock_irq(&conf->device_lock); in raid5_do_work()
6779 flush_deferred_bios(conf); in raid5_do_work()
6781 r5l_flush_stripe_to_raid(conf->log); in raid5_do_work()
6799 struct r5conf *conf = mddev->private; in raid5d() local
6809 spin_lock_irq(&conf->device_lock); in raid5d()
6818 released = release_stripe_list(conf, conf->temp_inactive_list); in raid5d()
6820 clear_bit(R5_DID_ALLOC, &conf->cache_state); in raid5d()
6823 !list_empty(&conf->bitmap_list)) { in raid5d()
6825 conf->seq_flush++; in raid5d()
6826 spin_unlock_irq(&conf->device_lock); in raid5d()
6828 spin_lock_irq(&conf->device_lock); in raid5d()
6829 conf->seq_write = conf->seq_flush; in raid5d()
6830 activate_bit_delay(conf, conf->temp_inactive_list); in raid5d()
6832 raid5_activate_delayed(conf); in raid5d()
6834 while ((bio = remove_bio_from_retry(conf, &offset))) { in raid5d()
6836 spin_unlock_irq(&conf->device_lock); in raid5d()
6837 ok = retry_aligned_read(conf, bio, offset); in raid5d()
6838 spin_lock_irq(&conf->device_lock); in raid5d()
6844 batch_size = handle_active_stripes(conf, ANY_GROUP, NULL, in raid5d()
6845 conf->temp_inactive_list); in raid5d()
6851 spin_unlock_irq(&conf->device_lock); in raid5d()
6853 spin_lock_irq(&conf->device_lock); in raid5d()
6858 spin_unlock_irq(&conf->device_lock); in raid5d()
6859 if (test_and_clear_bit(R5_ALLOC_MORE, &conf->cache_state) && in raid5d()
6860 mutex_trylock(&conf->cache_size_mutex)) { in raid5d()
6861 grow_one_stripe(conf, __GFP_NOWARN); in raid5d()
6865 set_bit(R5_DID_ALLOC, &conf->cache_state); in raid5d()
6866 mutex_unlock(&conf->cache_size_mutex); in raid5d()
6869 flush_deferred_bios(conf); in raid5d()
6871 r5l_flush_stripe_to_raid(conf->log); in raid5d()
6882 struct r5conf *conf; in raid5_show_stripe_cache_size() local
6885 conf = mddev->private; in raid5_show_stripe_cache_size()
6886 if (conf) in raid5_show_stripe_cache_size()
6887 ret = sprintf(page, "%d\n", conf->min_nr_stripes); in raid5_show_stripe_cache_size()
6896 struct r5conf *conf = mddev->private; in raid5_set_cache_size() local
6901 WRITE_ONCE(conf->min_nr_stripes, size); in raid5_set_cache_size()
6902 mutex_lock(&conf->cache_size_mutex); in raid5_set_cache_size()
6903 while (size < conf->max_nr_stripes && in raid5_set_cache_size()
6904 drop_one_stripe(conf)) in raid5_set_cache_size()
6906 mutex_unlock(&conf->cache_size_mutex); in raid5_set_cache_size()
6910 mutex_lock(&conf->cache_size_mutex); in raid5_set_cache_size()
6911 while (size > conf->max_nr_stripes) in raid5_set_cache_size()
6912 if (!grow_one_stripe(conf, GFP_KERNEL)) { in raid5_set_cache_size()
6913 WRITE_ONCE(conf->min_nr_stripes, conf->max_nr_stripes); in raid5_set_cache_size()
6917 mutex_unlock(&conf->cache_size_mutex); in raid5_set_cache_size()
6926 struct r5conf *conf; in raid5_store_stripe_cache_size() local
6937 conf = mddev->private; in raid5_store_stripe_cache_size()
6938 if (!conf) in raid5_store_stripe_cache_size()
6955 struct r5conf *conf = mddev->private; in raid5_show_rmw_level() local
6956 if (conf) in raid5_show_rmw_level()
6957 return sprintf(page, "%d\n", conf->rmw_level); in raid5_show_rmw_level()
6965 struct r5conf *conf = mddev->private; in raid5_store_rmw_level() local
6968 if (!conf) in raid5_store_rmw_level()
6985 conf->rmw_level = new; in raid5_store_rmw_level()
6997 struct r5conf *conf; in raid5_show_stripe_size() local
7001 conf = mddev->private; in raid5_show_stripe_size()
7002 if (conf) in raid5_show_stripe_size()
7003 ret = sprintf(page, "%lu\n", RAID5_STRIPE_SIZE(conf)); in raid5_show_stripe_size()
7012 struct r5conf *conf; in raid5_store_stripe_size() local
7036 conf = mddev->private; in raid5_store_stripe_size()
7037 if (!conf) { in raid5_store_stripe_size()
7042 if (new == conf->stripe_size) in raid5_store_stripe_size()
7046 conf->stripe_size, new); in raid5_store_stripe_size()
7057 mutex_lock(&conf->cache_size_mutex); in raid5_store_stripe_size()
7058 size = conf->max_nr_stripes; in raid5_store_stripe_size()
7060 shrink_stripes(conf); in raid5_store_stripe_size()
7062 conf->stripe_size = new; in raid5_store_stripe_size()
7063 conf->stripe_shift = ilog2(new) - 9; in raid5_store_stripe_size()
7064 conf->stripe_sectors = new >> 9; in raid5_store_stripe_size()
7065 if (grow_stripes(conf, size)) { in raid5_store_stripe_size()
7070 mutex_unlock(&conf->cache_size_mutex); in raid5_store_stripe_size()
7092 struct r5conf *conf; in raid5_show_preread_threshold() local
7095 conf = mddev->private; in raid5_show_preread_threshold()
7096 if (conf) in raid5_show_preread_threshold()
7097 ret = sprintf(page, "%d\n", conf->bypass_threshold); in raid5_show_preread_threshold()
7105 struct r5conf *conf; in raid5_store_preread_threshold() local
7117 conf = mddev->private; in raid5_store_preread_threshold()
7118 if (!conf) in raid5_store_preread_threshold()
7120 else if (new > conf->min_nr_stripes) in raid5_store_preread_threshold()
7123 conf->bypass_threshold = new; in raid5_store_preread_threshold()
7137 struct r5conf *conf; in raid5_show_skip_copy() local
7140 conf = mddev->private; in raid5_show_skip_copy()
7141 if (conf) in raid5_show_skip_copy()
7142 ret = sprintf(page, "%d\n", conf->skip_copy); in raid5_show_skip_copy()
7150 struct r5conf *conf; in raid5_store_skip_copy() local
7163 conf = mddev->private; in raid5_store_skip_copy()
7164 if (!conf) in raid5_store_skip_copy()
7166 else if (new != conf->skip_copy) { in raid5_store_skip_copy()
7170 conf->skip_copy = new; in raid5_store_skip_copy()
7189 struct r5conf *conf = mddev->private; in stripe_cache_active_show() local
7190 if (conf) in stripe_cache_active_show()
7191 return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); in stripe_cache_active_show()
7202 struct r5conf *conf; in raid5_show_group_thread_cnt() local
7205 conf = mddev->private; in raid5_show_group_thread_cnt()
7206 if (conf) in raid5_show_group_thread_cnt()
7207 ret = sprintf(page, "%d\n", conf->worker_cnt_per_group); in raid5_show_group_thread_cnt()
7212 static int alloc_thread_groups(struct r5conf *conf, int cnt,
7218 struct r5conf *conf; in raid5_store_group_thread_cnt() local
7235 conf = mddev->private; in raid5_store_group_thread_cnt()
7236 if (!conf) in raid5_store_group_thread_cnt()
7238 else if (new != conf->worker_cnt_per_group) { in raid5_store_group_thread_cnt()
7241 old_groups = conf->worker_groups; in raid5_store_group_thread_cnt()
7245 err = alloc_thread_groups(conf, new, &group_cnt, &new_groups); in raid5_store_group_thread_cnt()
7247 spin_lock_irq(&conf->device_lock); in raid5_store_group_thread_cnt()
7248 conf->group_cnt = group_cnt; in raid5_store_group_thread_cnt()
7249 conf->worker_cnt_per_group = new; in raid5_store_group_thread_cnt()
7250 conf->worker_groups = new_groups; in raid5_store_group_thread_cnt()
7251 spin_unlock_irq(&conf->device_lock); in raid5_store_group_thread_cnt()
7286 static int alloc_thread_groups(struct r5conf *conf, int cnt, int *group_cnt, in alloc_thread_groups() argument
7315 group->conf = conf; in alloc_thread_groups()
7331 static void free_thread_groups(struct r5conf *conf) in free_thread_groups() argument
7333 if (conf->worker_groups) in free_thread_groups()
7334 kfree(conf->worker_groups[0].workers); in free_thread_groups()
7335 kfree(conf->worker_groups); in free_thread_groups()
7336 conf->worker_groups = NULL; in free_thread_groups()
7342 struct r5conf *conf = mddev->private; in raid5_size() local
7348 raid_disks = min(conf->raid_disks, conf->previous_raid_disks); in raid5_size()
7350 sectors &= ~((sector_t)conf->chunk_sectors - 1); in raid5_size()
7351 sectors &= ~((sector_t)conf->prev_chunk_sectors - 1); in raid5_size()
7352 return sectors * (raid_disks - conf->max_degraded); in raid5_size()
7355 static void free_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) in free_scratch_buffer() argument
7363 static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) in alloc_scratch_buffer() argument
7365 if (conf->level == 6 && !percpu->spare_page) { in alloc_scratch_buffer()
7372 max(conf->raid_disks, in alloc_scratch_buffer()
7373 conf->previous_raid_disks), in alloc_scratch_buffer()
7374 max(conf->chunk_sectors, in alloc_scratch_buffer()
7375 conf->prev_chunk_sectors) in alloc_scratch_buffer()
7376 / RAID5_STRIPE_SECTORS(conf))) { in alloc_scratch_buffer()
7377 free_scratch_buffer(conf, percpu); in alloc_scratch_buffer()
7387 struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); in raid456_cpu_dead() local
7389 free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); in raid456_cpu_dead()
7393 static void raid5_free_percpu(struct r5conf *conf) in raid5_free_percpu() argument
7395 if (!conf->percpu) in raid5_free_percpu()
7398 cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); in raid5_free_percpu()
7399 free_percpu(conf->percpu); in raid5_free_percpu()
7402 static void free_conf(struct r5conf *conf) in free_conf() argument
7406 log_exit(conf); in free_conf()
7408 unregister_shrinker(&conf->shrinker); in free_conf()
7409 free_thread_groups(conf); in free_conf()
7410 shrink_stripes(conf); in free_conf()
7411 raid5_free_percpu(conf); in free_conf()
7412 for (i = 0; i < conf->pool_size; i++) in free_conf()
7413 if (conf->disks[i].extra_page) in free_conf()
7414 put_page(conf->disks[i].extra_page); in free_conf()
7415 kfree(conf->disks); in free_conf()
7416 bioset_exit(&conf->bio_split); in free_conf()
7417 kfree(conf->stripe_hashtbl); in free_conf()
7418 kfree(conf->pending_data); in free_conf()
7419 kfree(conf); in free_conf()
7424 struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); in raid456_cpu_up_prepare() local
7425 struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); in raid456_cpu_up_prepare()
7427 if (alloc_scratch_buffer(conf, percpu)) { in raid456_cpu_up_prepare()
7435 static int raid5_alloc_percpu(struct r5conf *conf) in raid5_alloc_percpu() argument
7439 conf->percpu = alloc_percpu(struct raid5_percpu); in raid5_alloc_percpu()
7440 if (!conf->percpu) in raid5_alloc_percpu()
7443 err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); in raid5_alloc_percpu()
7445 conf->scribble_disks = max(conf->raid_disks, in raid5_alloc_percpu()
7446 conf->previous_raid_disks); in raid5_alloc_percpu()
7447 conf->scribble_sectors = max(conf->chunk_sectors, in raid5_alloc_percpu()
7448 conf->prev_chunk_sectors); in raid5_alloc_percpu()
7456 struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); in raid5_cache_scan() local
7459 if (mutex_trylock(&conf->cache_size_mutex)) { in raid5_cache_scan()
7462 conf->max_nr_stripes > conf->min_nr_stripes) { in raid5_cache_scan()
7463 if (drop_one_stripe(conf) == 0) { in raid5_cache_scan()
7469 mutex_unlock(&conf->cache_size_mutex); in raid5_cache_scan()
7477 struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); in raid5_cache_count() local
7478 int max_stripes = READ_ONCE(conf->max_nr_stripes); in raid5_cache_count()
7479 int min_stripes = READ_ONCE(conf->min_nr_stripes); in raid5_cache_count()
7489 struct r5conf *conf; in setup_conf() local
7528 conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); in setup_conf()
7529 if (conf == NULL) in setup_conf()
7533 conf->stripe_size = DEFAULT_STRIPE_SIZE; in setup_conf()
7534 conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9; in setup_conf()
7535 conf->stripe_sectors = DEFAULT_STRIPE_SIZE >> 9; in setup_conf()
7537 INIT_LIST_HEAD(&conf->free_list); in setup_conf()
7538 INIT_LIST_HEAD(&conf->pending_list); in setup_conf()
7539 conf->pending_data = kcalloc(PENDING_IO_MAX, in setup_conf()
7542 if (!conf->pending_data) in setup_conf()
7545 list_add(&conf->pending_data[i].sibling, &conf->free_list); in setup_conf()
7547 if (!alloc_thread_groups(conf, 0, &group_cnt, &new_group)) { in setup_conf()
7548 conf->group_cnt = group_cnt; in setup_conf()
7549 conf->worker_cnt_per_group = 0; in setup_conf()
7550 conf->worker_groups = new_group; in setup_conf()
7553 spin_lock_init(&conf->device_lock); in setup_conf()
7554 seqcount_spinlock_init(&conf->gen_lock, &conf->device_lock); in setup_conf()
7555 mutex_init(&conf->cache_size_mutex); in setup_conf()
7557 init_waitqueue_head(&conf->wait_for_quiescent); in setup_conf()
7558 init_waitqueue_head(&conf->wait_for_stripe); in setup_conf()
7559 init_waitqueue_head(&conf->wait_for_overlap); in setup_conf()
7560 INIT_LIST_HEAD(&conf->handle_list); in setup_conf()
7561 INIT_LIST_HEAD(&conf->loprio_list); in setup_conf()
7562 INIT_LIST_HEAD(&conf->hold_list); in setup_conf()
7563 INIT_LIST_HEAD(&conf->delayed_list); in setup_conf()
7564 INIT_LIST_HEAD(&conf->bitmap_list); in setup_conf()
7565 init_llist_head(&conf->released_stripes); in setup_conf()
7566 atomic_set(&conf->active_stripes, 0); in setup_conf()
7567 atomic_set(&conf->preread_active_stripes, 0); in setup_conf()
7568 atomic_set(&conf->active_aligned_reads, 0); in setup_conf()
7569 spin_lock_init(&conf->pending_bios_lock); in setup_conf()
7570 conf->batch_bio_dispatch = true; in setup_conf()
7575 conf->batch_bio_dispatch = false; in setup_conf()
7580 conf->bypass_threshold = BYPASS_THRESHOLD; in setup_conf()
7581 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
7583 conf->raid_disks = mddev->raid_disks; in setup_conf()
7585 conf->previous_raid_disks = mddev->raid_disks; in setup_conf()
7587 conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; in setup_conf()
7588 max_disks = max(conf->raid_disks, conf->previous_raid_disks); in setup_conf()
7590 conf->disks = kcalloc(max_disks, sizeof(struct disk_info), in setup_conf()
7593 if (!conf->disks) in setup_conf()
7597 conf->disks[i].extra_page = alloc_page(GFP_KERNEL); in setup_conf()
7598 if (!conf->disks[i].extra_page) in setup_conf()
7602 ret = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
7605 conf->mddev = mddev; in setup_conf()
7608 conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL); in setup_conf()
7609 if (!conf->stripe_hashtbl) in setup_conf()
7617 spin_lock_init(conf->hash_locks); in setup_conf()
7619 spin_lock_init(conf->hash_locks + i); in setup_conf()
7622 INIT_LIST_HEAD(conf->inactive_list + i); in setup_conf()
7625 INIT_LIST_HEAD(conf->temp_inactive_list + i); in setup_conf()
7627 atomic_set(&conf->r5c_cached_full_stripes, 0); in setup_conf()
7628 INIT_LIST_HEAD(&conf->r5c_full_stripe_list); in setup_conf()
7629 atomic_set(&conf->r5c_cached_partial_stripes, 0); in setup_conf()
7630 INIT_LIST_HEAD(&conf->r5c_partial_stripe_list); in setup_conf()
7631 atomic_set(&conf->r5c_flushing_full_stripes, 0); in setup_conf()
7632 atomic_set(&conf->r5c_flushing_partial_stripes, 0); in setup_conf()
7634 conf->level = mddev->new_level; in setup_conf()
7635 conf->chunk_sectors = mddev->new_chunk_sectors; in setup_conf()
7636 ret = raid5_alloc_percpu(conf); in setup_conf()
7648 disk = conf->disks + raid_disk; in setup_conf()
7665 conf->fullsync = 1; in setup_conf()
7668 conf->level = mddev->new_level; in setup_conf()
7669 if (conf->level == 6) { in setup_conf()
7670 conf->max_degraded = 2; in setup_conf()
7672 conf->rmw_level = PARITY_ENABLE_RMW; in setup_conf()
7674 conf->rmw_level = PARITY_DISABLE_RMW; in setup_conf()
7676 conf->max_degraded = 1; in setup_conf()
7677 conf->rmw_level = PARITY_ENABLE_RMW; in setup_conf()
7679 conf->algorithm = mddev->new_layout; in setup_conf()
7680 conf->reshape_progress = mddev->reshape_position; in setup_conf()
7681 if (conf->reshape_progress != MaxSector) { in setup_conf()
7682 conf->prev_chunk_sectors = mddev->chunk_sectors; in setup_conf()
7683 conf->prev_algo = mddev->layout; in setup_conf()
7685 conf->prev_chunk_sectors = conf->chunk_sectors; in setup_conf()
7686 conf->prev_algo = conf->algorithm; in setup_conf()
7689 conf->min_nr_stripes = NR_STRIPES; in setup_conf()
7692 ((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4, in setup_conf()
7693 ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4); in setup_conf()
7694 conf->min_nr_stripes = max(NR_STRIPES, stripes); in setup_conf()
7695 if (conf->min_nr_stripes != NR_STRIPES) in setup_conf()
7697 mdname(mddev), conf->min_nr_stripes); in setup_conf()
7699 memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + in setup_conf()
7701 atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS); in setup_conf()
7702 if (grow_stripes(conf, conf->min_nr_stripes)) { in setup_conf()
7714 conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; in setup_conf()
7715 conf->shrinker.scan_objects = raid5_cache_scan; in setup_conf()
7716 conf->shrinker.count_objects = raid5_cache_count; in setup_conf()
7717 conf->shrinker.batch = 128; in setup_conf()
7718 conf->shrinker.flags = 0; in setup_conf()
7719 ret = register_shrinker(&conf->shrinker, "md-raid5:%s", mdname(mddev)); in setup_conf()
7727 rcu_assign_pointer(conf->thread, in setup_conf()
7729 if (!conf->thread) { in setup_conf()
7736 return conf; in setup_conf()
7739 if (conf) in setup_conf()
7740 free_conf(conf); in setup_conf()
7770 static void raid5_set_io_opt(struct r5conf *conf) in raid5_set_io_opt() argument
7772 blk_queue_io_opt(conf->mddev->queue, (conf->chunk_sectors << 9) * in raid5_set_io_opt()
7773 (conf->raid_disks - conf->max_degraded)); in raid5_set_io_opt()
7778 struct r5conf *conf; in raid5_run() local
7918 conf = setup_conf(mddev); in raid5_run()
7920 conf = mddev->private; in raid5_run()
7922 if (IS_ERR(conf)) in raid5_run()
7923 return PTR_ERR(conf); in raid5_run()
7935 conf->min_offset_diff = min_offset_diff; in raid5_run()
7936 rcu_assign_pointer(mddev->thread, conf->thread); in raid5_run()
7937 rcu_assign_pointer(conf->thread, NULL); in raid5_run()
7938 mddev->private = conf; in raid5_run()
7940 for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; in raid5_run()
7942 rdev = rdev_mdlock_deref(mddev, conf->disks[i].rdev); in raid5_run()
7943 if (!rdev && conf->disks[i].replacement) { in raid5_run()
7946 conf->disks[i].replacement); in raid5_run()
7947 conf->disks[i].replacement = NULL; in raid5_run()
7949 rcu_assign_pointer(conf->disks[i].rdev, rdev); in raid5_run()
7953 if (rcu_access_pointer(conf->disks[i].replacement) && in raid5_run()
7954 conf->reshape_progress != MaxSector) { in raid5_run()
7977 conf->algorithm, in raid5_run()
7978 conf->raid_disks, in raid5_run()
7979 conf->max_degraded)) in raid5_run()
7983 conf->prev_algo, in raid5_run()
7984 conf->previous_raid_disks, in raid5_run()
7985 conf->max_degraded)) in raid5_run()
7993 mddev->degraded = raid5_calc_degraded(conf); in raid5_run()
7995 if (has_failed(conf)) { in raid5_run()
7997 mdname(mddev), mddev->degraded, conf->raid_disks); in raid5_run()
8021 mdname(mddev), conf->level, in raid5_run()
8025 print_raid5_conf(conf); in raid5_run()
8027 if (conf->reshape_progress != MaxSector) { in raid5_run()
8028 conf->reshape_safe = conf->reshape_progress; in raid5_run()
8029 atomic_set(&conf->reshape_stripes, 0); in raid5_run()
8055 int data_disks = conf->previous_raid_disks - conf->max_degraded; in raid5_run()
8061 raid5_set_io_opt(conf); in raid5_run()
8105 RAID5_MAX_REQ_STRIPES << RAID5_STRIPE_SHIFT(conf)); in raid5_run()
8111 if (log_init(conf, journal_dev, raid5_has_ppl(conf))) in raid5_run()
8117 print_raid5_conf(conf); in raid5_run()
8118 free_conf(conf); in raid5_run()
8126 struct r5conf *conf = priv; in raid5_free() local
8128 free_conf(conf); in raid5_free()
8134 struct r5conf *conf = mddev->private; in raid5_status() local
8138 conf->chunk_sectors / 2, mddev->layout); in raid5_status()
8139 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); in raid5_status()
8141 for (i = 0; i < conf->raid_disks; i++) { in raid5_status()
8142 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); in raid5_status()
8149 static void print_raid5_conf (struct r5conf *conf) in print_raid5_conf() argument
8155 if (!conf) { in print_raid5_conf()
8159 pr_debug(" --- level:%d rd:%d wd:%d\n", conf->level, in print_raid5_conf()
8160 conf->raid_disks, in print_raid5_conf()
8161 conf->raid_disks - conf->mddev->degraded); in print_raid5_conf()
8164 for (i = 0; i < conf->raid_disks; i++) { in print_raid5_conf()
8165 rdev = rcu_dereference(conf->disks[i].rdev); in print_raid5_conf()
8177 struct r5conf *conf = mddev->private; in raid5_spare_active() local
8182 for (i = 0; i < conf->raid_disks; i++) { in raid5_spare_active()
8183 rdev = rdev_mdlock_deref(mddev, conf->disks[i].rdev); in raid5_spare_active()
8185 conf->disks[i].replacement); in raid5_spare_active()
8212 spin_lock_irqsave(&conf->device_lock, flags); in raid5_spare_active()
8213 mddev->degraded = raid5_calc_degraded(conf); in raid5_spare_active()
8214 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_spare_active()
8215 print_raid5_conf(conf); in raid5_spare_active()
8221 struct r5conf *conf = mddev->private; in raid5_remove_disk() local
8228 print_raid5_conf(conf); in raid5_remove_disk()
8229 if (test_bit(Journal, &rdev->flags) && conf->log) { in raid5_remove_disk()
8236 if (atomic_read(&conf->active_stripes) || in raid5_remove_disk()
8237 atomic_read(&conf->r5c_cached_full_stripes) || in raid5_remove_disk()
8238 atomic_read(&conf->r5c_cached_partial_stripes)) { in raid5_remove_disk()
8241 log_exit(conf); in raid5_remove_disk()
8244 if (unlikely(number >= conf->pool_size)) in raid5_remove_disk()
8246 p = conf->disks + number; in raid5_remove_disk()
8254 if (number >= conf->raid_disks && in raid5_remove_disk()
8255 conf->reshape_progress == MaxSector) in raid5_remove_disk()
8267 mddev->recovery_disabled != conf->recovery_disabled && in raid5_remove_disk()
8268 !has_failed(conf) && in raid5_remove_disk()
8271 number < conf->raid_disks) { in raid5_remove_disk()
8286 err = log_modify(conf, rdev, false); in raid5_remove_disk()
8302 err = log_modify(conf, tmp, true); in raid5_remove_disk()
8308 print_raid5_conf(conf); in raid5_remove_disk()
8314 struct r5conf *conf = mddev->private; in raid5_add_disk() local
8320 int last = conf->raid_disks - 1; in raid5_add_disk()
8323 if (conf->log) in raid5_add_disk()
8331 ret = log_init(conf, rdev, false); in raid5_add_disk()
8335 ret = r5l_start(conf->log); in raid5_add_disk()
8341 if (mddev->recovery_disabled == conf->recovery_disabled) in raid5_add_disk()
8344 if (rdev->saved_raid_disk < 0 && has_failed(conf)) in raid5_add_disk()
8357 conf->disks[rdev->saved_raid_disk].rdev == NULL) in raid5_add_disk()
8361 p = conf->disks + disk; in raid5_add_disk()
8366 conf->fullsync = 1; in raid5_add_disk()
8369 err = log_modify(conf, rdev, true); in raid5_add_disk()
8375 p = conf->disks + disk; in raid5_add_disk()
8384 conf->fullsync = 1; in raid5_add_disk()
8390 print_raid5_conf(conf); in raid5_add_disk()
8404 struct r5conf *conf = mddev->private; in raid5_resize() local
8406 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in raid5_resize()
8408 sectors &= ~((sector_t)conf->chunk_sectors - 1); in raid5_resize()
8439 struct r5conf *conf = mddev->private; in check_stripe_cache() local
8440 if (((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 in check_stripe_cache()
8441 > conf->min_nr_stripes || in check_stripe_cache()
8442 ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 in check_stripe_cache()
8443 > conf->min_nr_stripes) { in check_stripe_cache()
8447 / RAID5_STRIPE_SIZE(conf))*4); in check_stripe_cache()
8455 struct r5conf *conf = mddev->private; in check_reshape() local
8457 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in check_reshape()
8463 if (has_failed(conf)) in check_reshape()
8483 if (resize_chunks(conf, in check_reshape()
8484 conf->previous_raid_disks in check_reshape()
8491 if (conf->previous_raid_disks + mddev->delta_disks <= conf->pool_size) in check_reshape()
8493 return resize_stripes(conf, (conf->previous_raid_disks in check_reshape()
8499 struct r5conf *conf = mddev->private; in raid5_start_reshape() local
8511 if (has_failed(conf)) in raid5_start_reshape()
8517 for (i = 0; i < conf->raid_disks; i++) in raid5_start_reshape()
8518 if (rdev_mdlock_deref(mddev, conf->disks[i].replacement)) in raid5_start_reshape()
8527 if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) in raid5_start_reshape()
8537 if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) in raid5_start_reshape()
8544 atomic_set(&conf->reshape_stripes, 0); in raid5_start_reshape()
8545 spin_lock_irq(&conf->device_lock); in raid5_start_reshape()
8546 write_seqcount_begin(&conf->gen_lock); in raid5_start_reshape()
8547 conf->previous_raid_disks = conf->raid_disks; in raid5_start_reshape()
8548 conf->raid_disks += mddev->delta_disks; in raid5_start_reshape()
8549 conf->prev_chunk_sectors = conf->chunk_sectors; in raid5_start_reshape()
8550 conf->chunk_sectors = mddev->new_chunk_sectors; in raid5_start_reshape()
8551 conf->prev_algo = conf->algorithm; in raid5_start_reshape()
8552 conf->algorithm = mddev->new_layout; in raid5_start_reshape()
8553 conf->generation++; in raid5_start_reshape()
8559 conf->reshape_progress = raid5_size(mddev, 0, 0); in raid5_start_reshape()
8561 conf->reshape_progress = 0; in raid5_start_reshape()
8562 conf->reshape_safe = conf->reshape_progress; in raid5_start_reshape()
8563 write_seqcount_end(&conf->gen_lock); in raid5_start_reshape()
8564 spin_unlock_irq(&conf->device_lock); in raid5_start_reshape()
8586 >= conf->previous_raid_disks) in raid5_start_reshape()
8594 } else if (rdev->raid_disk >= conf->previous_raid_disks in raid5_start_reshape()
8604 spin_lock_irqsave(&conf->device_lock, flags); in raid5_start_reshape()
8605 mddev->degraded = raid5_calc_degraded(conf); in raid5_start_reshape()
8606 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_start_reshape()
8608 mddev->raid_disks = conf->raid_disks; in raid5_start_reshape()
8609 mddev->reshape_position = conf->reshape_progress; in raid5_start_reshape()
8621 spin_lock_irq(&conf->device_lock); in raid5_start_reshape()
8622 write_seqcount_begin(&conf->gen_lock); in raid5_start_reshape()
8623 mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; in raid5_start_reshape()
8625 conf->chunk_sectors = conf->prev_chunk_sectors; in raid5_start_reshape()
8626 mddev->new_layout = conf->algorithm = conf->prev_algo; in raid5_start_reshape()
8630 conf->generation --; in raid5_start_reshape()
8631 conf->reshape_progress = MaxSector; in raid5_start_reshape()
8633 write_seqcount_end(&conf->gen_lock); in raid5_start_reshape()
8634 spin_unlock_irq(&conf->device_lock); in raid5_start_reshape()
8637 conf->reshape_checkpoint = jiffies; in raid5_start_reshape()
8646 static void end_reshape(struct r5conf *conf) in end_reshape() argument
8649 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in end_reshape()
8652 spin_lock_irq(&conf->device_lock); in end_reshape()
8653 conf->previous_raid_disks = conf->raid_disks; in end_reshape()
8654 md_finish_reshape(conf->mddev); in end_reshape()
8656 conf->reshape_progress = MaxSector; in end_reshape()
8657 conf->mddev->reshape_position = MaxSector; in end_reshape()
8658 rdev_for_each(rdev, conf->mddev) in end_reshape()
8663 spin_unlock_irq(&conf->device_lock); in end_reshape()
8664 wake_up(&conf->wait_for_overlap); in end_reshape()
8666 if (conf->mddev->queue) in end_reshape()
8667 raid5_set_io_opt(conf); in end_reshape()
8676 struct r5conf *conf = mddev->private; in raid5_finish_reshape() local
8683 spin_lock_irq(&conf->device_lock); in raid5_finish_reshape()
8684 mddev->degraded = raid5_calc_degraded(conf); in raid5_finish_reshape()
8685 spin_unlock_irq(&conf->device_lock); in raid5_finish_reshape()
8686 for (d = conf->raid_disks ; in raid5_finish_reshape()
8687 d < conf->raid_disks - mddev->delta_disks; in raid5_finish_reshape()
8690 conf->disks[d].rdev); in raid5_finish_reshape()
8694 conf->disks[d].replacement); in raid5_finish_reshape()
8699 mddev->layout = conf->algorithm; in raid5_finish_reshape()
8700 mddev->chunk_sectors = conf->chunk_sectors; in raid5_finish_reshape()
8709 struct r5conf *conf = mddev->private; in raid5_quiesce() local
8713 lock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8717 r5c_flush_cache(conf, INT_MAX); in raid5_quiesce()
8721 smp_store_release(&conf->quiesce, 2); in raid5_quiesce()
8722 wait_event_cmd(conf->wait_for_quiescent, in raid5_quiesce()
8723 atomic_read(&conf->active_stripes) == 0 && in raid5_quiesce()
8724 atomic_read(&conf->active_aligned_reads) == 0, in raid5_quiesce()
8725 unlock_all_device_hash_locks_irq(conf), in raid5_quiesce()
8726 lock_all_device_hash_locks_irq(conf)); in raid5_quiesce()
8727 conf->quiesce = 1; in raid5_quiesce()
8728 unlock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8730 wake_up(&conf->wait_for_overlap); in raid5_quiesce()
8733 lock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8734 conf->quiesce = 0; in raid5_quiesce()
8735 wake_up(&conf->wait_for_quiescent); in raid5_quiesce()
8736 wake_up(&conf->wait_for_overlap); in raid5_quiesce()
8737 unlock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8739 log_quiesce(conf, quiesce); in raid5_quiesce()
8840 struct r5conf *conf = mddev->private; in raid5_check_reshape() local
8860 conf->algorithm = mddev->new_layout; in raid5_check_reshape()
8864 conf->chunk_sectors = new_chunk ; in raid5_check_reshape()
8983 struct r5conf *conf; in raid5_change_consistency_policy() local
8989 conf = mddev->private; in raid5_change_consistency_policy()
8990 if (!conf) { in raid5_change_consistency_policy()
8997 if (!raid5_has_ppl(conf) && conf->level == 5) { in raid5_change_consistency_policy()
8998 err = log_init(conf, NULL, true); in raid5_change_consistency_policy()
9000 err = resize_stripes(conf, conf->pool_size); in raid5_change_consistency_policy()
9003 log_exit(conf); in raid5_change_consistency_policy()
9010 if (raid5_has_ppl(conf)) { in raid5_change_consistency_policy()
9012 log_exit(conf); in raid5_change_consistency_policy()
9014 err = resize_stripes(conf, conf->pool_size); in raid5_change_consistency_policy()
9015 } else if (test_bit(MD_HAS_JOURNAL, &conf->mddev->flags) && in raid5_change_consistency_policy()
9016 r5l_log_disk_error(conf)) { in raid5_change_consistency_policy()
9048 struct r5conf *conf = mddev->private; in raid5_start() local
9050 return r5l_start(conf->log); in raid5_start()
9055 struct r5conf *conf = mddev->private; in raid5_prepare_suspend() local
9066 wake_up(&conf->wait_for_overlap); in raid5_prepare_suspend()