Lines Matching full:conf

22  * conf->seq_write is the number of the last batch successfully written.
23 * conf->seq_flush is the number of the last batch that was closed to
74 static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) in stripe_hash() argument
76 int hash = (sect >> RAID5_STRIPE_SHIFT(conf)) & HASH_MASK; in stripe_hash()
77 return &conf->stripe_hashtbl[hash]; in stripe_hash()
80 static inline int stripe_hash_locks_hash(struct r5conf *conf, sector_t sect) in stripe_hash_locks_hash() argument
82 return (sect >> RAID5_STRIPE_SHIFT(conf)) & STRIPE_HASH_LOCKS_MASK; in stripe_hash_locks_hash()
85 static inline void lock_device_hash_lock(struct r5conf *conf, int hash) in lock_device_hash_lock() argument
86 __acquires(&conf->device_lock) in lock_device_hash_lock()
88 spin_lock_irq(conf->hash_locks + hash); in lock_device_hash_lock()
89 spin_lock(&conf->device_lock); in lock_device_hash_lock()
92 static inline void unlock_device_hash_lock(struct r5conf *conf, int hash) in unlock_device_hash_lock() argument
93 __releases(&conf->device_lock) in unlock_device_hash_lock()
95 spin_unlock(&conf->device_lock); in unlock_device_hash_lock()
96 spin_unlock_irq(conf->hash_locks + hash); in unlock_device_hash_lock()
99 static inline void lock_all_device_hash_locks_irq(struct r5conf *conf) in lock_all_device_hash_locks_irq() argument
100 __acquires(&conf->device_lock) in lock_all_device_hash_locks_irq()
103 spin_lock_irq(conf->hash_locks); in lock_all_device_hash_locks_irq()
105 spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks); in lock_all_device_hash_locks_irq()
106 spin_lock(&conf->device_lock); in lock_all_device_hash_locks_irq()
109 static inline void unlock_all_device_hash_locks_irq(struct r5conf *conf) in unlock_all_device_hash_locks_irq() argument
110 __releases(&conf->device_lock) in unlock_all_device_hash_locks_irq()
113 spin_unlock(&conf->device_lock); in unlock_all_device_hash_locks_irq()
115 spin_unlock(conf->hash_locks + i); in unlock_all_device_hash_locks_irq()
116 spin_unlock_irq(conf->hash_locks); in unlock_all_device_hash_locks_irq()
158 static void print_raid5_conf(struct r5conf *conf);
177 struct r5conf *conf = sh->raid_conf; in raid5_wakeup_stripe_thread() local
189 group = conf->worker_groups + cpu_to_group(cpu); in raid5_wakeup_stripe_thread()
198 if (conf->worker_cnt_per_group == 0) { in raid5_wakeup_stripe_thread()
199 md_wakeup_thread(conf->mddev->thread); in raid5_wakeup_stripe_thread()
203 group = conf->worker_groups + cpu_to_group(sh->cpu); in raid5_wakeup_stripe_thread()
211 for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { in raid5_wakeup_stripe_thread()
221 static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, in do_release_stripe() argument
223 __must_hold(&conf->device_lock) in do_release_stripe()
229 BUG_ON(atomic_read(&conf->active_stripes)==0); in do_release_stripe()
231 if (r5c_is_writeback(conf->log)) in do_release_stripe()
243 (conf->quiesce && r5c_is_writeback(conf->log) && in do_release_stripe()
253 list_add_tail(&sh->lru, &conf->delayed_list); 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()
260 if (conf->worker_cnt_per_group == 0) { in do_release_stripe()
263 &conf->loprio_list); in do_release_stripe()
266 &conf->handle_list); in do_release_stripe()
272 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
276 if (atomic_dec_return(&conf->preread_active_stripes) in do_release_stripe()
278 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
279 atomic_dec(&conf->active_stripes); in do_release_stripe()
281 if (!r5c_is_writeback(conf->log)) in do_release_stripe()
287 else if (injournal == conf->raid_disks - conf->max_degraded) { in do_release_stripe()
290 atomic_inc(&conf->r5c_cached_full_stripes); in do_release_stripe()
292 atomic_dec(&conf->r5c_cached_partial_stripes); in do_release_stripe()
293 list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); in do_release_stripe()
294 r5c_check_cached_full_stripe(conf); 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
309 __must_hold(&conf->device_lock) in __release_stripe()
312 do_release_stripe(conf, sh, temp_inactive_list); in __release_stripe()
322 static void release_inactive_stripe_list(struct r5conf *conf, in release_inactive_stripe_list() argument
343 spin_lock_irqsave(conf->hash_locks + hash, flags); in release_inactive_stripe_list()
344 if (list_empty(conf->inactive_list + hash) && in release_inactive_stripe_list()
346 atomic_dec(&conf->empty_inactive_list_nr); in release_inactive_stripe_list()
347 list_splice_tail_init(list, conf->inactive_list + hash); in release_inactive_stripe_list()
349 spin_unlock_irqrestore(conf->hash_locks + hash, flags); in release_inactive_stripe_list()
356 wake_up(&conf->wait_for_stripe); in release_inactive_stripe_list()
357 if (atomic_read(&conf->active_stripes) == 0) in release_inactive_stripe_list()
358 wake_up(&conf->wait_for_quiescent); in release_inactive_stripe_list()
359 if (conf->retry_read_aligned) in release_inactive_stripe_list()
360 md_wakeup_thread(conf->mddev->thread); in release_inactive_stripe_list()
364 static int release_stripe_list(struct r5conf *conf, in release_stripe_list() argument
366 __must_hold(&conf->device_lock) in release_stripe_list()
372 head = llist_del_all(&conf->released_stripes); in release_stripe_list()
386 __release_stripe(conf, sh, &temp_inactive_list[hash]); in release_stripe_list()
395 struct r5conf *conf = sh->raid_conf; in raid5_release_stripe() local
406 if (unlikely(!conf->mddev->thread) || in raid5_release_stripe()
409 wakeup = llist_add(&sh->release_list, &conf->released_stripes); in raid5_release_stripe()
411 md_wakeup_thread(conf->mddev->thread); in raid5_release_stripe()
415 if (atomic_dec_and_lock_irqsave(&sh->count, &conf->device_lock, flags)) { in raid5_release_stripe()
418 do_release_stripe(conf, sh, &list); in raid5_release_stripe()
419 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_release_stripe()
420 release_inactive_stripe_list(conf, &list, hash); in raid5_release_stripe()
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()
443 static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) in get_free_stripe() argument
448 if (list_empty(conf->inactive_list + hash)) in get_free_stripe()
450 first = (conf->inactive_list + hash)->next; in get_free_stripe()
454 atomic_inc(&conf->active_stripes); in get_free_stripe()
456 if (list_empty(conf->inactive_list + hash)) in get_free_stripe()
457 atomic_inc(&conf->empty_inactive_list_nr); in get_free_stripe()
501 init_stripe_shared_pages(struct stripe_head *sh, struct r5conf *conf, int disks) in init_stripe_shared_pages() argument
508 /* Each of the sh->dev[i] need one conf->stripe_size */ in init_stripe_shared_pages()
509 cnt = PAGE_SIZE / conf->stripe_size; in init_stripe_shared_pages()
573 static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous,
578 struct r5conf *conf = sh->raid_conf; in init_stripe() local
589 seq = read_seqcount_begin(&conf->gen_lock); 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()
593 stripe_set_idx(sector, conf, previous, sh); in init_stripe()
610 if (read_seqcount_retry(&conf->gen_lock, seq)) in init_stripe()
613 insert_hash(conf, sh); in init_stripe()
618 static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, in __find_stripe() argument
624 hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) in __find_stripe()
631 static struct stripe_head *find_get_stripe(struct r5conf *conf, in find_get_stripe() argument
637 sh = __find_stripe(conf, sector, generation); in find_get_stripe()
650 spin_lock(&conf->device_lock); in find_get_stripe()
653 atomic_inc(&conf->active_stripes); in find_get_stripe()
657 if (!list_empty(conf->inactive_list + hash)) in find_get_stripe()
660 if (list_empty(conf->inactive_list + hash) && in find_get_stripe()
662 atomic_inc(&conf->empty_inactive_list_nr); in find_get_stripe()
669 spin_unlock(&conf->device_lock); in find_get_stripe()
687 * Most calls to this function hold &conf->device_lock. Calls
691 int raid5_calc_degraded(struct r5conf *conf) in raid5_calc_degraded() argument
697 for (i = 0; i < conf->previous_raid_disks; i++) { in raid5_calc_degraded()
698 struct md_rdev *rdev = READ_ONCE(conf->disks[i].rdev); in raid5_calc_degraded()
701 rdev = READ_ONCE(conf->disks[i].replacement); in raid5_calc_degraded()
716 if (conf->raid_disks >= conf->previous_raid_disks) in raid5_calc_degraded()
719 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 = READ_ONCE(conf->disks[i].rdev); in raid5_calc_degraded()
726 rdev = READ_ONCE(conf->disks[i].replacement); in raid5_calc_degraded()
737 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()
791 static bool is_inactive_blocked(struct r5conf *conf, int hash) in is_inactive_blocked() argument
793 if (list_empty(conf->inactive_list + hash)) in is_inactive_blocked()
796 if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) in is_inactive_blocked()
799 return (atomic_read(&conf->active_stripes) < in is_inactive_blocked()
800 (conf->max_nr_stripes * 3 / 4)); in is_inactive_blocked()
803 struct stripe_head *raid5_get_active_stripe(struct r5conf *conf, in raid5_get_active_stripe() argument
808 int hash = stripe_hash_locks_hash(conf, sector); in raid5_get_active_stripe()
813 spin_lock_irq(conf->hash_locks + hash); in raid5_get_active_stripe()
816 if (!(flags & R5_GAS_NOQUIESCE) && conf->quiesce) { in raid5_get_active_stripe()
829 wait_event_lock_irq(conf->wait_for_quiescent, in raid5_get_active_stripe()
830 !conf->quiesce, in raid5_get_active_stripe()
831 *(conf->hash_locks + hash)); in raid5_get_active_stripe()
834 sh = find_get_stripe(conf, sector, conf->generation - previous, in raid5_get_active_stripe()
839 if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { in raid5_get_active_stripe()
840 sh = get_free_stripe(conf, hash); in raid5_get_active_stripe()
842 r5c_check_stripe_cache_usage(conf); in raid5_get_active_stripe()
848 if (!test_bit(R5_DID_ALLOC, &conf->cache_state)) in raid5_get_active_stripe()
849 set_bit(R5_ALLOC_MORE, &conf->cache_state); in raid5_get_active_stripe()
855 set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); in raid5_get_active_stripe()
856 r5l_wake_reclaim(conf->log, 0); in raid5_get_active_stripe()
864 wait_event_lock_irq(conf->wait_for_stripe, in raid5_get_active_stripe()
865 is_inactive_blocked(conf, hash), in raid5_get_active_stripe()
866 *(conf->hash_locks + hash)); in raid5_get_active_stripe()
867 clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); in raid5_get_active_stripe()
870 spin_unlock_irq(conf->hash_locks + hash); in raid5_get_active_stripe()
904 struct r5conf *conf = sh->raid_conf; in stripe_can_batch() local
906 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in stripe_can_batch()
914 static void stripe_add_to_batch_list(struct r5conf *conf, in stripe_add_to_batch_list() argument
924 if (!sector_div(tmp_sec, conf->chunk_sectors)) in stripe_add_to_batch_list()
926 head_sector = sh->sector - RAID5_STRIPE_SECTORS(conf); in stripe_add_to_batch_list()
932 hash = stripe_hash_locks_hash(conf, head_sector); in stripe_add_to_batch_list()
933 spin_lock_irq(conf->hash_locks + hash); in stripe_add_to_batch_list()
934 head = find_get_stripe(conf, head_sector, conf->generation, in stripe_add_to_batch_list()
936 spin_unlock_irq(conf->hash_locks + hash); in stripe_add_to_batch_list()
989 if (atomic_dec_return(&conf->preread_active_stripes) in stripe_add_to_batch_list()
991 md_wakeup_thread(conf->mddev->thread); in stripe_add_to_batch_list()
1012 static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) in use_new_offset() argument
1014 sector_t progress = conf->reshape_progress; in use_new_offset()
1016 * of conf->generation, or ->data_offset that was set before in use_new_offset()
1022 if (sh->generation == conf->generation - 1) in use_new_offset()
1052 static void dispatch_defer_bios(struct r5conf *conf, int target, in dispatch_defer_bios() argument
1059 if (conf->pending_data_cnt == 0) in dispatch_defer_bios()
1062 list_sort(NULL, &conf->pending_list, cmp_stripe); in dispatch_defer_bios()
1064 first = conf->pending_list.next; in dispatch_defer_bios()
1067 if (conf->next_pending_data) in dispatch_defer_bios()
1068 list_move_tail(&conf->pending_list, in dispatch_defer_bios()
1069 &conf->next_pending_data->sibling); in dispatch_defer_bios()
1071 while (!list_empty(&conf->pending_list)) { in dispatch_defer_bios()
1072 data = list_first_entry(&conf->pending_list, in dispatch_defer_bios()
1079 list_move(&data->sibling, &conf->free_list); in dispatch_defer_bios()
1084 conf->pending_data_cnt -= cnt; in dispatch_defer_bios()
1085 BUG_ON(conf->pending_data_cnt < 0 || cnt < target); in dispatch_defer_bios()
1087 if (next != &conf->pending_list) in dispatch_defer_bios()
1088 conf->next_pending_data = list_entry(next, in dispatch_defer_bios()
1091 conf->next_pending_data = NULL; in dispatch_defer_bios()
1093 if (first != &conf->pending_list) in dispatch_defer_bios()
1094 list_move_tail(&conf->pending_list, first); in dispatch_defer_bios()
1097 static void flush_deferred_bios(struct r5conf *conf) in flush_deferred_bios() argument
1101 if (conf->pending_data_cnt == 0) in flush_deferred_bios()
1104 spin_lock(&conf->pending_bios_lock); in flush_deferred_bios()
1105 dispatch_defer_bios(conf, conf->pending_data_cnt, &tmp); in flush_deferred_bios()
1106 BUG_ON(conf->pending_data_cnt != 0); in flush_deferred_bios()
1107 spin_unlock(&conf->pending_bios_lock); in flush_deferred_bios()
1112 static void defer_issue_bios(struct r5conf *conf, sector_t sector, in defer_issue_bios() argument
1118 spin_lock(&conf->pending_bios_lock); in defer_issue_bios()
1119 ent = list_first_entry(&conf->free_list, struct r5pending_data, in defer_issue_bios()
1121 list_move_tail(&ent->sibling, &conf->pending_list); in defer_issue_bios()
1125 conf->pending_data_cnt++; in defer_issue_bios()
1126 if (conf->pending_data_cnt >= PENDING_IO_MAX) in defer_issue_bios()
1127 dispatch_defer_bios(conf, PENDING_IO_ONE_FLUSH, &tmp); in defer_issue_bios()
1129 spin_unlock(&conf->pending_bios_lock); in defer_issue_bios()
1141 struct r5conf *conf = sh->raid_conf; in ops_run_io() local
1153 should_defer = conf->batch_bio_dispatch && conf->group_cnt; in ops_run_io()
1185 rdev = conf->disks[i].rdev; in ops_run_io()
1186 rrdev = conf->disks[i].replacement; in ops_run_io()
1215 RAID5_STRIPE_SECTORS(conf)); in ops_run_io()
1221 if (!conf->mddev->external && in ops_run_io()
1222 conf->mddev->sb_flags) { in ops_run_io()
1227 md_check_recovery(conf->mddev); in ops_run_io()
1235 md_wait_for_blocked_rdev(rdev, conf->mddev); in ops_run_io()
1238 rdev_dec_pending(rdev, conf->mddev); in ops_run_io()
1246 md_sync_acct(rdev->bdev, RAID5_STRIPE_SECTORS(conf)); in ops_run_io()
1262 if (use_new_offset(conf, sh)) in ops_run_io()
1285 bi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1287 bi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1297 mddev_trace_remap(conf->mddev, bi, sh->dev[i].sector); in ops_run_io()
1306 md_sync_acct(rrdev->bdev, RAID5_STRIPE_SECTORS(conf)); in ops_run_io()
1322 if (use_new_offset(conf, sh)) in ops_run_io()
1332 rbi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1334 rbi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); in ops_run_io()
1341 mddev_trace_remap(conf->mddev, rbi, sh->dev[i].sector); in ops_run_io()
1365 defer_issue_bios(conf, head_sh->sector, &pending_bios); in ops_run_io()
1379 struct r5conf *conf = sh->raid_conf; in async_copy_data() local
1401 if (len > 0 && page_offset + len > RAID5_STRIPE_SIZE(conf)) in async_copy_data()
1402 clen = RAID5_STRIPE_SIZE(conf) - page_offset; in async_copy_data()
1410 if (conf->skip_copy && in async_copy_data()
1412 clen == RAID5_STRIPE_SIZE(conf) && in async_copy_data()
1437 struct r5conf *conf = sh->raid_conf; in ops_complete_biofill() local
1458 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_complete_biofill()
1459 rbi2 = r5_next_bio(conf, rbi, dev->sector); in ops_complete_biofill()
1476 struct r5conf *conf = sh->raid_conf; in ops_run_biofill() local
1491 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_run_biofill()
1495 rbi = r5_next_bio(conf, rbi, dev->sector); in ops_run_biofill()
1921 struct r5conf *conf = sh->raid_conf; in ops_run_biodrain() local
1954 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in ops_run_biodrain()
1965 r5c_is_writeback(conf->log)); in ops_run_biodrain()
1967 !r5c_is_writeback(conf->log)) { in ops_run_biodrain()
1973 wbi = r5_next_bio(conf, wbi, dev->sector); in ops_run_biodrain()
2278 struct r5conf *conf = sh->raid_conf; in raid_run_ops() local
2279 int level = conf->level; in raid_run_ops()
2282 local_lock(&conf->percpu->lock); in raid_run_ops()
2283 percpu = this_cpu_ptr(conf->percpu); in raid_run_ops()
2343 local_unlock(&conf->percpu->lock); in raid_run_ops()
2357 int disks, struct r5conf *conf) in alloc_stripe() argument
2370 sh->raid_conf = conf; in alloc_stripe()
2373 if (raid5_has_ppl(conf)) { in alloc_stripe()
2381 if (init_stripe_shared_pages(sh, conf, disks)) { in alloc_stripe()
2389 static int grow_one_stripe(struct r5conf *conf, gfp_t gfp) in grow_one_stripe() argument
2393 sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size, conf); in grow_one_stripe()
2399 free_stripe(conf->slab_cache, sh); in grow_one_stripe()
2403 conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS; in grow_one_stripe()
2405 atomic_inc(&conf->active_stripes); in grow_one_stripe()
2408 WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes + 1); in grow_one_stripe()
2412 static int grow_stripes(struct r5conf *conf, int num) in grow_stripes() argument
2415 size_t namelen = sizeof(conf->cache_name[0]); in grow_stripes()
2416 int devs = max(conf->raid_disks, conf->previous_raid_disks); in grow_stripes()
2418 if (mddev_is_dm(conf->mddev)) in grow_stripes()
2419 snprintf(conf->cache_name[0], namelen, in grow_stripes()
2420 "raid%d-%p", conf->level, conf->mddev); in grow_stripes()
2422 snprintf(conf->cache_name[0], namelen, in grow_stripes()
2423 "raid%d-%s", conf->level, mdname(conf->mddev)); in grow_stripes()
2424 snprintf(conf->cache_name[1], namelen, "%.27s-alt", conf->cache_name[0]); in grow_stripes()
2426 conf->active_name = 0; in grow_stripes()
2427 sc = kmem_cache_create(conf->cache_name[conf->active_name], in grow_stripes()
2432 conf->slab_cache = sc; in grow_stripes()
2433 conf->pool_size = devs; in grow_stripes()
2435 if (!grow_one_stripe(conf, GFP_KERNEL)) in grow_stripes()
2482 static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors) in resize_chunks() argument
2488 if (conf->scribble_disks >= new_disks && in resize_chunks()
2489 conf->scribble_sectors >= new_sectors) in resize_chunks()
2492 raid5_quiesce(conf->mddev, true); in resize_chunks()
2498 percpu = per_cpu_ptr(conf->percpu, cpu); in resize_chunks()
2500 new_sectors / RAID5_STRIPE_SECTORS(conf)); in resize_chunks()
2506 raid5_quiesce(conf->mddev, false); in resize_chunks()
2509 conf->scribble_disks = new_disks; in resize_chunks()
2510 conf->scribble_sectors = new_sectors; in resize_chunks()
2515 static int resize_stripes(struct r5conf *conf, int newsize) in resize_stripes() argument
2529 * 3/ reallocate conf->disks to be suitable bigger. If this fails, in resize_stripes()
2548 md_allow_write(conf->mddev); in resize_stripes()
2551 sc = kmem_cache_create(conf->cache_name[1-conf->active_name], in resize_stripes()
2558 mutex_lock(&conf->cache_size_mutex); in resize_stripes()
2560 for (i = conf->max_nr_stripes; i; i--) { in resize_stripes()
2561 nsh = alloc_stripe(sc, GFP_KERNEL, newsize, conf); in resize_stripes()
2575 mutex_unlock(&conf->cache_size_mutex); in resize_stripes()
2585 lock_device_hash_lock(conf, hash); in resize_stripes()
2586 wait_event_cmd(conf->wait_for_stripe, in resize_stripes()
2587 !list_empty(conf->inactive_list + hash), in resize_stripes()
2588 unlock_device_hash_lock(conf, hash), in resize_stripes()
2589 lock_device_hash_lock(conf, hash)); in resize_stripes()
2590 osh = get_free_stripe(conf, hash); in resize_stripes()
2591 unlock_device_hash_lock(conf, hash); in resize_stripes()
2599 for(i=0; i<conf->pool_size; i++) { in resize_stripes()
2605 free_stripe(conf->slab_cache, osh); in resize_stripes()
2607 if (cnt >= conf->max_nr_stripes / NR_STRIPE_HASH_LOCKS + in resize_stripes()
2608 !!((conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS) > hash)) { in resize_stripes()
2613 kmem_cache_destroy(conf->slab_cache); in resize_stripes()
2618 * conf->disks and the scribble region in resize_stripes()
2622 for (i = 0; i < conf->pool_size; i++) in resize_stripes()
2623 ndisks[i] = conf->disks[i]; in resize_stripes()
2625 for (i = conf->pool_size; i < newsize; i++) { in resize_stripes()
2632 for (i = conf->pool_size; i < newsize; i++) in resize_stripes()
2637 kfree(conf->disks); in resize_stripes()
2638 conf->disks = ndisks; in resize_stripes()
2643 conf->slab_cache = sc; in resize_stripes()
2644 conf->active_name = 1-conf->active_name; in resize_stripes()
2660 for (i = conf->raid_disks; i < newsize; i++) { in resize_stripes()
2668 for (i=conf->raid_disks; i < newsize; i++) in resize_stripes()
2683 conf->pool_size = newsize; in resize_stripes()
2684 mutex_unlock(&conf->cache_size_mutex); in resize_stripes()
2689 static int drop_one_stripe(struct r5conf *conf) in drop_one_stripe() argument
2692 int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK; in drop_one_stripe()
2694 spin_lock_irq(conf->hash_locks + hash); in drop_one_stripe()
2695 sh = get_free_stripe(conf, hash); in drop_one_stripe()
2696 spin_unlock_irq(conf->hash_locks + hash); in drop_one_stripe()
2701 free_stripe(conf->slab_cache, sh); in drop_one_stripe()
2702 atomic_dec(&conf->active_stripes); in drop_one_stripe()
2703 WRITE_ONCE(conf->max_nr_stripes, conf->max_nr_stripes - 1); in drop_one_stripe()
2707 static void shrink_stripes(struct r5conf *conf) in shrink_stripes() argument
2709 while (conf->max_nr_stripes && in shrink_stripes()
2710 drop_one_stripe(conf)) in shrink_stripes()
2713 kmem_cache_destroy(conf->slab_cache); in shrink_stripes()
2714 conf->slab_cache = NULL; in shrink_stripes()
2720 struct r5conf *conf = sh->raid_conf; in raid5_end_read_request() local
2742 rdev = conf->disks[i].replacement; in raid5_end_read_request()
2744 rdev = conf->disks[i].rdev; in raid5_end_read_request()
2746 if (use_new_offset(conf, sh)) in raid5_end_read_request()
2759 mdname(conf->mddev), RAID5_STRIPE_SECTORS(conf), in raid5_end_read_request()
2762 atomic_add(RAID5_STRIPE_SECTORS(conf), &rdev->corrected_errors); in raid5_end_read_request()
2787 mdname(conf->mddev), in raid5_end_read_request()
2790 else if (conf->mddev->degraded >= conf->max_degraded) { in raid5_end_read_request()
2794 mdname(conf->mddev), in raid5_end_read_request()
2802 mdname(conf->mddev), in raid5_end_read_request()
2806 > conf->max_nr_stripes) { in raid5_end_read_request()
2809 mdname(conf->mddev), in raid5_end_read_request()
2811 conf->max_nr_stripes); in raid5_end_read_request()
2813 mdname(conf->mddev), rdev->bdev); in raid5_end_read_request()
2834 rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0))) in raid5_end_read_request()
2835 md_error(conf->mddev, rdev); in raid5_end_read_request()
2838 rdev_dec_pending(rdev, conf->mddev); in raid5_end_read_request()
2848 struct r5conf *conf = sh->raid_conf; in raid5_end_write_request() local
2855 rdev = conf->disks[i].rdev; in raid5_end_write_request()
2859 rdev = conf->disks[i].replacement; in raid5_end_write_request()
2867 rdev = conf->disks[i].rdev; in raid5_end_write_request()
2881 md_error(conf->mddev, rdev); in raid5_end_write_request()
2883 RAID5_STRIPE_SECTORS(conf))) in raid5_end_write_request()
2894 RAID5_STRIPE_SECTORS(conf))) { in raid5_end_write_request()
2904 rdev_dec_pending(rdev, conf->mddev); in raid5_end_write_request()
2921 struct r5conf *conf = mddev->private; in raid5_error() local
2928 spin_lock_irqsave(&conf->device_lock, flags); in raid5_error()
2931 mddev->degraded = raid5_calc_degraded(conf); in raid5_error()
2933 if (has_failed(conf)) { in raid5_error()
2934 set_bit(MD_BROKEN, &conf->mddev->flags); in raid5_error()
2935 conf->recovery_disabled = mddev->recovery_disabled; in raid5_error()
2938 mdname(mddev), mddev->degraded, conf->raid_disks); in raid5_error()
2941 mdname(mddev), conf->raid_disks - mddev->degraded); in raid5_error()
2944 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_error()
2957 sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, in raid5_compute_sector() argument
2967 int algorithm = previous ? conf->prev_algo in raid5_compute_sector()
2968 : conf->algorithm; in raid5_compute_sector()
2969 int sectors_per_chunk = previous ? conf->prev_chunk_sectors in raid5_compute_sector()
2970 : conf->chunk_sectors; in raid5_compute_sector()
2971 int raid_disks = previous ? conf->previous_raid_disks in raid5_compute_sector()
2972 : conf->raid_disks; in raid5_compute_sector()
2973 int data_disks = raid_disks - conf->max_degraded; in raid5_compute_sector()
2993 switch(conf->level) { in raid5_compute_sector()
3161 struct r5conf *conf = sh->raid_conf; in raid5_compute_blocknr() local
3163 int data_disks = raid_disks - conf->max_degraded; in raid5_compute_blocknr()
3165 int sectors_per_chunk = previous ? conf->prev_chunk_sectors in raid5_compute_blocknr()
3166 : conf->chunk_sectors; in raid5_compute_blocknr()
3167 int algorithm = previous ? conf->prev_algo in raid5_compute_blocknr()
3168 : conf->algorithm; in raid5_compute_blocknr()
3181 switch(conf->level) { in raid5_compute_blocknr()
3268 check = raid5_compute_sector(conf, r_sector, in raid5_compute_blocknr()
3273 mdname(conf->mddev)); in raid5_compute_blocknr()
3300 * stripe, we need to reserve (conf->raid_disk + 1) pages per stripe
3302 * operation, we only need (conf->max_degraded + 1) pages per stripe.
3317 static inline bool delay_towrite(struct r5conf *conf, in delay_towrite() argument
3326 if (test_bit(R5C_LOG_CRITICAL, &conf->cache_state) && in delay_towrite()
3340 struct r5conf *conf = sh->raid_conf; in schedule_reconstruction() local
3341 int level = conf->level; in schedule_reconstruction()
3355 if (dev->towrite && !delay_towrite(conf, dev, s)) { in schedule_reconstruction()
3381 if (s->locked + conf->max_degraded == disks) in schedule_reconstruction()
3383 atomic_inc(&conf->pending_full_writes); in schedule_reconstruction()
3447 struct r5conf *conf = sh->raid_conf; in stripe_bio_overlaps() local
3471 if (forwrite && raid5_has_ppl(conf)) { in stripe_bio_overlaps()
3497 if (first + conf->chunk_sectors * (count - 1) != last) in stripe_bio_overlaps()
3507 struct r5conf *conf = sh->raid_conf; in __add_stripe_bio() local
3530 md_write_inc(conf->mddev, bi); in __add_stripe_bio()
3536 sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && in __add_stripe_bio()
3538 bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { in __add_stripe_bio()
3542 if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) in __add_stripe_bio()
3551 if (conf->mddev->bitmap && firstwrite) { in __add_stripe_bio()
3566 conf->mddev->bitmap_ops->startwrite(conf->mddev, sh->sector, in __add_stripe_bio()
3567 RAID5_STRIPE_SECTORS(conf), false); in __add_stripe_bio()
3571 sh->bm_seq = conf->seq_flush+1; in __add_stripe_bio()
3598 static void end_reshape(struct r5conf *conf);
3600 static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, in stripe_set_idx() argument
3604 previous ? conf->prev_chunk_sectors : conf->chunk_sectors; in stripe_set_idx()
3607 int disks = previous ? conf->previous_raid_disks : conf->raid_disks; in stripe_set_idx()
3609 raid5_compute_sector(conf, in stripe_set_idx()
3610 stripe * (disks - conf->max_degraded) in stripe_set_idx()
3617 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, in handle_failed_stripe() argument
3627 struct md_rdev *rdev = conf->disks[i].rdev; in handle_failed_stripe()
3638 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_stripe()
3639 md_error(conf->mddev, rdev); in handle_failed_stripe()
3640 rdev_dec_pending(rdev, conf->mddev); in handle_failed_stripe()
3658 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3659 struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3661 md_write_end(conf->mddev); in handle_failed_stripe()
3666 conf->mddev->bitmap_ops->endwrite(conf->mddev, in handle_failed_stripe()
3667 sh->sector, RAID5_STRIPE_SECTORS(conf), in handle_failed_stripe()
3680 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3681 struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3683 md_write_end(conf->mddev); in handle_failed_stripe()
3692 s->failed > conf->max_degraded && in handle_failed_stripe()
3704 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { in handle_failed_stripe()
3706 r5_next_bio(conf, bi, sh->dev[i].sector); in handle_failed_stripe()
3713 conf->mddev->bitmap_ops->endwrite(conf->mddev, in handle_failed_stripe()
3714 sh->sector, RAID5_STRIPE_SECTORS(conf), in handle_failed_stripe()
3725 if (atomic_dec_and_test(&conf->pending_full_writes)) in handle_failed_stripe()
3726 md_wakeup_thread(conf->mddev->thread); in handle_failed_stripe()
3730 handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, in handle_failed_sync() argument
3749 if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { in handle_failed_sync()
3753 for (i = 0; i < conf->raid_disks; i++) { in handle_failed_sync()
3754 struct md_rdev *rdev = conf->disks[i].rdev; in handle_failed_sync()
3760 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_sync()
3762 rdev = conf->disks[i].replacement; in handle_failed_sync()
3768 RAID5_STRIPE_SECTORS(conf), 0)) in handle_failed_sync()
3772 conf->recovery_disabled = in handle_failed_sync()
3773 conf->mddev->recovery_disabled; in handle_failed_sync()
3775 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), !abort); in handle_failed_sync()
4027 static void handle_stripe_clean_event(struct r5conf *conf, in handle_stripe_clean_event() argument
4058 dev->sector + RAID5_STRIPE_SECTORS(conf)) { in handle_stripe_clean_event()
4059 wbi2 = r5_next_bio(conf, wbi, dev->sector); in handle_stripe_clean_event()
4060 md_write_end(conf->mddev); in handle_stripe_clean_event()
4064 conf->mddev->bitmap_ops->endwrite(conf->mddev, in handle_stripe_clean_event()
4065 sh->sector, RAID5_STRIPE_SECTORS(conf), in handle_stripe_clean_event()
4103 spin_lock_irq(conf->hash_locks + hash); in handle_stripe_clean_event()
4105 spin_unlock_irq(conf->hash_locks + hash); in handle_stripe_clean_event()
4120 if (atomic_dec_and_test(&conf->pending_full_writes)) in handle_stripe_clean_event()
4121 md_wakeup_thread(conf->mddev->thread); in handle_stripe_clean_event()
4142 static int handle_stripe_dirtying(struct r5conf *conf, in handle_stripe_dirtying() argument
4148 sector_t recovery_cp = conf->mddev->recovery_cp; in handle_stripe_dirtying()
4157 if (conf->rmw_level == PARITY_DISABLE_RMW || in handle_stripe_dirtying()
4165 conf->rmw_level, (unsigned long long)recovery_cp, in handle_stripe_dirtying()
4170 if (((dev->towrite && !delay_towrite(conf, dev, s)) || in handle_stripe_dirtying()
4197 if ((rmw < rcw || (rmw == rcw && conf->rmw_level == PARITY_PREFER_RMW)) && rmw > 0) { in handle_stripe_dirtying()
4199 mddev_add_trace_msg(conf->mddev, "raid5 rmw %llu %d", in handle_stripe_dirtying()
4220 &conf->cache_state)) { in handle_stripe_dirtying()
4234 if (((dev->towrite && !delay_towrite(conf, dev, s)) || in handle_stripe_dirtying()
4253 if ((rcw < rmw || (rcw == rmw && conf->rmw_level != PARITY_PREFER_RMW)) && rcw > 0) { in handle_stripe_dirtying()
4278 if (rcw && !mddev_is_dm(conf->mddev)) in handle_stripe_dirtying()
4279 blk_add_trace_msg(conf->mddev->gendisk->queue, in handle_stripe_dirtying()
4306 static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks5() argument
4368 atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); in handle_parity_checks5()
4369 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks5()
4373 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks5()
4376 RAID5_STRIPE_SECTORS(conf)); in handle_parity_checks5()
4399 static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, in handle_parity_checks6() argument
4495 mdname(conf->mddev), in handle_parity_checks6()
4533 atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); in handle_parity_checks6()
4534 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks6()
4538 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks6()
4541 RAID5_STRIPE_SECTORS(conf)); in handle_parity_checks6()
4576 static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) in handle_stripe_expansion() argument
4593 sector_t s = raid5_compute_sector(conf, bn, 0, in handle_stripe_expansion()
4595 sh2 = raid5_get_active_stripe(conf, NULL, s, in handle_stripe_expansion()
4614 sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), in handle_stripe_expansion()
4619 for (j = 0; j < conf->raid_disks; j++) in handle_stripe_expansion()
4624 if (j == conf->raid_disks) { in handle_stripe_expansion()
4651 struct r5conf *conf = sh->raid_conf; in analyse_stripe() local
4663 s->log_failed = r5l_log_disk_error(conf); in analyse_stripe()
4708 rdev = conf->disks[i].replacement; in analyse_stripe()
4710 rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && in analyse_stripe()
4712 RAID5_STRIPE_SECTORS(conf))) in analyse_stripe()
4719 rdev = conf->disks[i].rdev; in analyse_stripe()
4726 RAID5_STRIPE_SECTORS(conf)); in analyse_stripe()
4752 else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) in analyse_stripe()
4766 struct md_rdev *rdev2 = conf->disks[i].rdev; in analyse_stripe()
4779 struct md_rdev *rdev2 = conf->disks[i].rdev; in analyse_stripe()
4788 struct md_rdev *rdev2 = conf->disks[i].replacement; in analyse_stripe()
4810 rdev = conf->disks[i].replacement; in analyse_stripe()
4831 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4832 test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) in analyse_stripe()
4937 struct r5conf *conf = sh->raid_conf; in handle_stripe() local
4994 test_bit(MD_SB_CHANGE_PENDING, &conf->mddev->sb_flags)) { in handle_stripe()
5006 rdev_dec_pending(s.blocked_rdev, conf->mddev); in handle_stripe()
5026 if (s.failed > conf->max_degraded || in handle_stripe()
5032 handle_failed_stripe(conf, sh, &s, disks); in handle_stripe()
5034 handle_failed_sync(conf, sh, &s); in handle_stripe()
5087 || conf->level < 6; in handle_stripe()
5098 handle_stripe_clean_event(conf, sh, disks); in handle_stripe()
5101 r5c_handle_cached_data_endio(conf, sh, disks); in handle_stripe()
5120 r5c_finish_stripe_write_out(conf, sh, &s); in handle_stripe()
5132 if (!r5c_is_writeback(conf->log)) { in handle_stripe()
5134 handle_stripe_dirtying(conf, sh, &s, disks); in handle_stripe()
5140 ret = r5c_try_caching_write(conf, sh, &s, in handle_stripe()
5153 ret = handle_stripe_dirtying(conf, sh, &s, in handle_stripe()
5170 if (conf->level == 6) in handle_stripe()
5171 handle_parity_checks6(conf, sh, &s, disks); in handle_stripe()
5173 handle_parity_checks5(conf, sh, &s, disks); in handle_stripe()
5180 for (i = 0; i < conf->raid_disks; i++) in handle_stripe()
5194 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); in handle_stripe()
5203 if (s.failed <= conf->max_degraded && !conf->mddev->ro) in handle_stripe()
5224 = raid5_get_active_stripe(conf, NULL, sh->sector, in handle_stripe()
5235 atomic_inc(&conf->preread_active_stripes); in handle_stripe()
5244 for (i = conf->raid_disks; i--; ) { in handle_stripe()
5254 sh->disks = conf->raid_disks; in handle_stripe()
5255 stripe_set_idx(sh->sector, conf, 0, sh); in handle_stripe()
5259 atomic_dec(&conf->reshape_stripes); in handle_stripe()
5260 wake_up(&conf->wait_for_reshape); in handle_stripe()
5261 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); in handle_stripe()
5266 handle_stripe_expansion(conf, sh); in handle_stripe()
5271 if (conf->mddev->external) in handle_stripe()
5273 conf->mddev); in handle_stripe()
5280 conf->mddev); in handle_stripe()
5289 rdev = conf->disks[i].rdev; in handle_stripe()
5291 RAID5_STRIPE_SECTORS(conf), 0)) in handle_stripe()
5292 md_error(conf->mddev, rdev); in handle_stripe()
5293 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5296 rdev = conf->disks[i].rdev; in handle_stripe()
5298 RAID5_STRIPE_SECTORS(conf), 0); in handle_stripe()
5299 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5302 rdev = conf->disks[i].replacement; in handle_stripe()
5305 rdev = conf->disks[i].rdev; in handle_stripe()
5307 RAID5_STRIPE_SECTORS(conf), 0); in handle_stripe()
5308 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5322 atomic_dec(&conf->preread_active_stripes); in handle_stripe()
5323 if (atomic_read(&conf->preread_active_stripes) < in handle_stripe()
5325 md_wakeup_thread(conf->mddev->thread); in handle_stripe()
5331 static void raid5_activate_delayed(struct r5conf *conf) in raid5_activate_delayed() argument
5332 __must_hold(&conf->device_lock) in raid5_activate_delayed()
5334 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { in raid5_activate_delayed()
5335 while (!list_empty(&conf->delayed_list)) { in raid5_activate_delayed()
5336 struct list_head *l = conf->delayed_list.next; in raid5_activate_delayed()
5342 atomic_inc(&conf->preread_active_stripes); in raid5_activate_delayed()
5343 list_add_tail(&sh->lru, &conf->hold_list); in raid5_activate_delayed()
5349 static void activate_bit_delay(struct r5conf *conf, in activate_bit_delay() argument
5351 __must_hold(&conf->device_lock) in activate_bit_delay()
5354 list_add(&head, &conf->bitmap_list); in activate_bit_delay()
5355 list_del_init(&conf->bitmap_list); in activate_bit_delay()
5362 __release_stripe(conf, sh, &temp_inactive_list[hash]); in activate_bit_delay()
5368 struct r5conf *conf = mddev->private; in in_chunk_boundary() local
5373 chunk_sectors = min(conf->chunk_sectors, conf->prev_chunk_sectors); in in_chunk_boundary()
5382 static void add_bio_to_retry(struct bio *bi,struct r5conf *conf) in add_bio_to_retry() argument
5386 spin_lock_irqsave(&conf->device_lock, flags); in add_bio_to_retry()
5388 bi->bi_next = conf->retry_read_aligned_list; in add_bio_to_retry()
5389 conf->retry_read_aligned_list = bi; in add_bio_to_retry()
5391 spin_unlock_irqrestore(&conf->device_lock, flags); in add_bio_to_retry()
5392 md_wakeup_thread(conf->mddev->thread); in add_bio_to_retry()
5395 static struct bio *remove_bio_from_retry(struct r5conf *conf, in remove_bio_from_retry() argument
5400 bi = conf->retry_read_aligned; in remove_bio_from_retry()
5402 *offset = conf->retry_read_offset; in remove_bio_from_retry()
5403 conf->retry_read_aligned = NULL; in remove_bio_from_retry()
5406 bi = conf->retry_read_aligned_list; in remove_bio_from_retry()
5408 conf->retry_read_aligned_list = bi->bi_next; in remove_bio_from_retry()
5427 struct r5conf *conf = mddev->private; in raid5_align_endio() local
5432 rdev_dec_pending(rdev, conf->mddev); in raid5_align_endio()
5436 if (atomic_dec_and_test(&conf->active_aligned_reads)) in raid5_align_endio()
5437 wake_up(&conf->wait_for_quiescent); in raid5_align_endio()
5443 add_bio_to_retry(raid_bi, conf); in raid5_align_endio()
5448 struct r5conf *conf = mddev->private; in raid5_read_one_chunk() local
5460 sector = raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, 0, in raid5_read_one_chunk()
5464 if (r5c_big_stripe_cached(conf, sector)) in raid5_read_one_chunk()
5467 rdev = conf->disks[dd_idx].replacement; in raid5_read_one_chunk()
5470 rdev = conf->disks[dd_idx].rdev; in raid5_read_one_chunk()
5499 if (conf->quiesce == 0) { in raid5_read_one_chunk()
5500 atomic_inc(&conf->active_aligned_reads); in raid5_read_one_chunk()
5504 if (!did_inc || smp_load_acquire(&conf->quiesce) != 0) { in raid5_read_one_chunk()
5508 if (did_inc && atomic_dec_and_test(&conf->active_aligned_reads)) in raid5_read_one_chunk()
5509 wake_up(&conf->wait_for_quiescent); in raid5_read_one_chunk()
5510 spin_lock_irq(&conf->device_lock); in raid5_read_one_chunk()
5511 wait_event_lock_irq(conf->wait_for_quiescent, conf->quiesce == 0, in raid5_read_one_chunk()
5512 conf->device_lock); in raid5_read_one_chunk()
5513 atomic_inc(&conf->active_aligned_reads); in raid5_read_one_chunk()
5514 spin_unlock_irq(&conf->device_lock); in raid5_read_one_chunk()
5530 struct r5conf *conf = mddev->private; in chunk_aligned_read() local
5531 split = bio_split(raid_bio, sectors, GFP_NOIO, &conf->bio_split); in chunk_aligned_read()
5553 static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group) in __get_priority_stripe() argument
5554 __must_hold(&conf->device_lock) in __get_priority_stripe()
5559 bool second_try = !r5c_is_writeback(conf->log) && in __get_priority_stripe()
5560 !r5l_log_disk_error(conf); in __get_priority_stripe()
5561 bool try_loprio = test_bit(R5C_LOG_TIGHT, &conf->cache_state) || in __get_priority_stripe()
5562 r5l_log_disk_error(conf); in __get_priority_stripe()
5567 if (conf->worker_cnt_per_group == 0) { in __get_priority_stripe()
5568 handle_list = try_loprio ? &conf->loprio_list : in __get_priority_stripe()
5569 &conf->handle_list; in __get_priority_stripe()
5571 handle_list = try_loprio ? &conf->worker_groups[group].loprio_list : in __get_priority_stripe()
5572 &conf->worker_groups[group].handle_list; in __get_priority_stripe()
5573 wg = &conf->worker_groups[group]; in __get_priority_stripe()
5576 for (i = 0; i < conf->group_cnt; i++) { in __get_priority_stripe()
5577 handle_list = try_loprio ? &conf->worker_groups[i].loprio_list : in __get_priority_stripe()
5578 &conf->worker_groups[i].handle_list; in __get_priority_stripe()
5579 wg = &conf->worker_groups[i]; in __get_priority_stripe()
5588 list_empty(&conf->hold_list) ? "empty" : "busy", in __get_priority_stripe()
5589 atomic_read(&conf->pending_full_writes), conf->bypass_count); in __get_priority_stripe()
5594 if (list_empty(&conf->hold_list)) in __get_priority_stripe()
5595 conf->bypass_count = 0; in __get_priority_stripe()
5597 if (conf->hold_list.next == conf->last_hold) in __get_priority_stripe()
5598 conf->bypass_count++; in __get_priority_stripe()
5600 conf->last_hold = conf->hold_list.next; in __get_priority_stripe()
5601 conf->bypass_count -= conf->bypass_threshold; in __get_priority_stripe()
5602 if (conf->bypass_count < 0) in __get_priority_stripe()
5603 conf->bypass_count = 0; in __get_priority_stripe()
5606 } else if (!list_empty(&conf->hold_list) && in __get_priority_stripe()
5607 ((conf->bypass_threshold && in __get_priority_stripe()
5608 conf->bypass_count > conf->bypass_threshold) || in __get_priority_stripe()
5609 atomic_read(&conf->pending_full_writes) == 0)) { in __get_priority_stripe()
5611 list_for_each_entry(tmp, &conf->hold_list, lru) { in __get_priority_stripe()
5612 if (conf->worker_cnt_per_group == 0 || in __get_priority_stripe()
5622 conf->bypass_count -= conf->bypass_threshold; in __get_priority_stripe()
5623 if (conf->bypass_count < 0) in __get_priority_stripe()
5624 conf->bypass_count = 0; in __get_priority_stripe()
5658 struct r5conf *conf = mddev->private; in raid5_unplug() local
5663 spin_lock_irq(&conf->device_lock); in raid5_unplug()
5679 __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); in raid5_unplug()
5682 spin_unlock_irq(&conf->device_lock); in raid5_unplug()
5684 release_inactive_stripe_list(conf, cb->temp_inactive_list, in raid5_unplug()
5721 struct r5conf *conf = mddev->private; in make_discard_request() local
5734 logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in make_discard_request()
5739 stripe_sectors = conf->chunk_sectors * in make_discard_request()
5740 (conf->raid_disks - conf->max_degraded); in make_discard_request()
5745 logical_sector *= conf->chunk_sectors; in make_discard_request()
5746 last_sector *= conf->chunk_sectors; in make_discard_request()
5749 logical_sector += RAID5_STRIPE_SECTORS(conf)) { in make_discard_request()
5753 sh = raid5_get_active_stripe(conf, NULL, logical_sector, 0); in make_discard_request()
5763 for (d = 0; d < conf->raid_disks; d++) { in make_discard_request()
5777 for (d = 0; d < conf->raid_disks; d++) { in make_discard_request()
5787 if (conf->mddev->bitmap) { in make_discard_request()
5788 for (d = 0; d < conf->raid_disks - conf->max_degraded; in make_discard_request()
5791 RAID5_STRIPE_SECTORS(conf), false); in make_discard_request()
5792 sh->bm_seq = conf->seq_flush + 1; in make_discard_request()
5799 atomic_inc(&conf->preread_active_stripes); in make_discard_request()
5820 static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, in stripe_ahead_of_reshape() argument
5835 spin_lock_irq(&conf->device_lock); in stripe_ahead_of_reshape()
5838 conf->reshape_progress)) in stripe_ahead_of_reshape()
5842 spin_unlock_irq(&conf->device_lock); in stripe_ahead_of_reshape()
5847 static int add_all_stripe_bios(struct r5conf *conf, in add_all_stripe_bios() argument
5874 md_wakeup_thread(conf->mddev->thread); in add_all_stripe_bios()
5892 RAID5_STRIPE_SHIFT(conf), ctx->sectors_to_do); in add_all_stripe_bios()
5907 struct r5conf *conf, sector_t logical_sector) in get_reshape_loc() argument
5919 spin_lock_irq(&conf->device_lock); in get_reshape_loc()
5920 reshape_progress = conf->reshape_progress; in get_reshape_loc()
5921 reshape_safe = conf->reshape_safe; in get_reshape_loc()
5922 spin_unlock_irq(&conf->device_lock); in get_reshape_loc()
5933 struct r5conf *conf, struct stripe_request_ctx *ctx, in make_stripe_request() argument
5943 seq = read_seqcount_begin(&conf->gen_lock); in make_stripe_request()
5945 if (unlikely(conf->reshape_progress != MaxSector)) { in make_stripe_request()
5946 enum reshape_loc loc = get_reshape_loc(mddev, conf, in make_stripe_request()
5956 new_sector = raid5_compute_sector(conf, logical_sector, previous, in make_stripe_request()
5965 sh = raid5_get_active_stripe(conf, ctx, new_sector, flags); in make_stripe_request()
5973 stripe_ahead_of_reshape(mddev, conf, sh)) { in make_stripe_request()
5986 if (read_seqcount_retry(&conf->gen_lock, seq)) { in make_stripe_request()
5998 if (!add_all_stripe_bios(conf, ctx, sh, bi, rw, previous)) { in make_stripe_request()
6004 stripe_add_to_batch_list(conf, sh, ctx->batch_last); in make_stripe_request()
6022 atomic_inc(&conf->preread_active_stripes); in make_stripe_request()
6042 static sector_t raid5_bio_lowest_chunk_sector(struct r5conf *conf, in raid5_bio_lowest_chunk_sector() argument
6045 int sectors_per_chunk = conf->chunk_sectors; in raid5_bio_lowest_chunk_sector()
6046 int raid_disks = conf->raid_disks; in raid5_bio_lowest_chunk_sector()
6050 sector_t r_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in raid5_bio_lowest_chunk_sector()
6054 sector = raid5_compute_sector(conf, r_sector, 0, &dd_idx, &sh); in raid5_bio_lowest_chunk_sector()
6074 struct r5conf *conf = mddev->private; in raid5_make_request() local
6082 int ret = log_handle_flush_request(conf, bi); in raid5_make_request()
6117 logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in raid5_make_request()
6123 RAID5_STRIPE_SECTORS(conf)); in raid5_make_request()
6131 (conf->reshape_progress != MaxSector) && in raid5_make_request()
6132 get_reshape_loc(mddev, conf, logical_sector) == LOC_INSIDE_RESHAPE) { in raid5_make_request()
6147 if (likely(conf->reshape_progress == MaxSector)) { in raid5_make_request()
6148 logical_sector = raid5_bio_lowest_chunk_sector(conf, bi); in raid5_make_request()
6151 add_wait_queue(&conf->wait_for_reshape, &wait); in raid5_make_request()
6154 s = (logical_sector - ctx.first_sector) >> RAID5_STRIPE_SHIFT(conf); in raid5_make_request()
6157 res = make_stripe_request(mddev, conf, &ctx, logical_sector, in raid5_make_request()
6189 (s << RAID5_STRIPE_SHIFT(conf)); in raid5_make_request()
6192 remove_wait_queue(&conf->wait_for_reshape, &wait); in raid5_make_request()
6221 struct r5conf *conf = mddev->private; in reshape_request() local
6225 int raid_disks = conf->previous_raid_disks; in reshape_request()
6226 int data_disks = raid_disks - conf->max_degraded; in reshape_request()
6227 int new_data_disks = conf->raid_disks - conf->max_degraded; in reshape_request()
6239 conf->reshape_progress < raid5_size(mddev, 0, 0)) { in reshape_request()
6241 - conf->reshape_progress; in reshape_request()
6243 conf->reshape_progress == MaxSector) { in reshape_request()
6247 conf->reshape_progress > 0) in reshape_request()
6248 sector_nr = conf->reshape_progress; in reshape_request()
6264 reshape_sectors = max(conf->chunk_sectors, conf->prev_chunk_sectors); in reshape_request()
6272 writepos = conf->reshape_progress; in reshape_request()
6274 readpos = conf->reshape_progress; in reshape_request()
6276 safepos = conf->reshape_safe; in reshape_request()
6299 if (WARN_ON(conf->reshape_progress == 0)) in reshape_request()
6334 if (conf->min_offset_diff < 0) { in reshape_request()
6335 safepos += -conf->min_offset_diff; in reshape_request()
6336 readpos += -conf->min_offset_diff; in reshape_request()
6338 writepos += conf->min_offset_diff; in reshape_request()
6343 time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { in reshape_request()
6345 wait_event(conf->wait_for_reshape, in reshape_request()
6346 atomic_read(&conf->reshape_stripes)==0 in reshape_request()
6348 if (atomic_read(&conf->reshape_stripes) != 0) in reshape_request()
6350 mddev->reshape_position = conf->reshape_progress; in reshape_request()
6361 conf->reshape_checkpoint = jiffies; in reshape_request()
6368 spin_lock_irq(&conf->device_lock); in reshape_request()
6369 conf->reshape_safe = mddev->reshape_position; in reshape_request()
6370 spin_unlock_irq(&conf->device_lock); in reshape_request()
6371 wake_up(&conf->wait_for_reshape); in reshape_request()
6376 for (i = 0; i < reshape_sectors; i += RAID5_STRIPE_SECTORS(conf)) { in reshape_request()
6379 sh = raid5_get_active_stripe(conf, NULL, stripe_addr+i, in reshape_request()
6382 atomic_inc(&conf->reshape_stripes); in reshape_request()
6390 if (conf->level == 6 && in reshape_request()
6398 memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); in reshape_request()
6408 spin_lock_irq(&conf->device_lock); in reshape_request()
6410 conf->reshape_progress -= reshape_sectors * new_data_disks; in reshape_request()
6412 conf->reshape_progress += reshape_sectors * new_data_disks; in reshape_request()
6413 spin_unlock_irq(&conf->device_lock); in reshape_request()
6420 raid5_compute_sector(conf, stripe_addr*(new_data_disks), in reshape_request()
6423 raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) in reshape_request()
6429 sh = raid5_get_active_stripe(conf, NULL, first_sector, in reshape_request()
6434 first_sector += RAID5_STRIPE_SECTORS(conf); in reshape_request()
6454 wait_event(conf->wait_for_reshape, in reshape_request()
6455 atomic_read(&conf->reshape_stripes) == 0 in reshape_request()
6457 if (atomic_read(&conf->reshape_stripes) != 0) in reshape_request()
6459 mddev->reshape_position = conf->reshape_progress; in reshape_request()
6469 conf->reshape_checkpoint = jiffies; in reshape_request()
6477 spin_lock_irq(&conf->device_lock); in reshape_request()
6478 conf->reshape_safe = mddev->reshape_position; in reshape_request()
6479 spin_unlock_irq(&conf->device_lock); in reshape_request()
6480 wake_up(&conf->wait_for_reshape); in reshape_request()
6490 struct r5conf *conf = mddev->private; in raid5_sync_request() local
6500 end_reshape(conf); in raid5_sync_request()
6508 conf->fullsync = 0; in raid5_sync_request()
6515 wait_event(conf->wait_for_reshape, conf->quiesce != 2); in raid5_sync_request()
6530 if (mddev->degraded >= conf->max_degraded && in raid5_sync_request()
6537 !conf->fullsync && in raid5_sync_request()
6540 sync_blocks >= RAID5_STRIPE_SECTORS(conf)) { in raid5_sync_request()
6542 do_div(sync_blocks, RAID5_STRIPE_SECTORS(conf)); in raid5_sync_request()
6545 return sync_blocks * RAID5_STRIPE_SECTORS(conf); in raid5_sync_request()
6550 sh = raid5_get_active_stripe(conf, NULL, sector_nr, in raid5_sync_request()
6553 sh = raid5_get_active_stripe(conf, NULL, sector_nr, 0); in raid5_sync_request()
6563 for (i = 0; i < conf->raid_disks; i++) { in raid5_sync_request()
6564 struct md_rdev *rdev = conf->disks[i].rdev; in raid5_sync_request()
6578 return RAID5_STRIPE_SECTORS(conf); in raid5_sync_request()
6581 static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio, in retry_aligned_read() argument
6601 ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); in retry_aligned_read()
6602 sector = raid5_compute_sector(conf, logical_sector, in retry_aligned_read()
6607 logical_sector += RAID5_STRIPE_SECTORS(conf), in retry_aligned_read()
6608 sector += RAID5_STRIPE_SECTORS(conf), in retry_aligned_read()
6615 sh = raid5_get_active_stripe(conf, NULL, sector, in retry_aligned_read()
6619 conf->retry_read_aligned = raid_bio; in retry_aligned_read()
6620 conf->retry_read_offset = scnt; in retry_aligned_read()
6626 conf->retry_read_aligned = raid_bio; in retry_aligned_read()
6627 conf->retry_read_offset = scnt; in retry_aligned_read()
6639 if (atomic_dec_and_test(&conf->active_aligned_reads)) in retry_aligned_read()
6640 wake_up(&conf->wait_for_quiescent); in retry_aligned_read()
6644 static int handle_active_stripes(struct r5conf *conf, int group, in handle_active_stripes() argument
6647 __must_hold(&conf->device_lock) in handle_active_stripes()
6654 (sh = __get_priority_stripe(conf, group)) != NULL) in handle_active_stripes()
6662 spin_unlock_irq(&conf->device_lock); in handle_active_stripes()
6663 log_flush_stripe_to_raid(conf); in handle_active_stripes()
6664 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6669 spin_unlock_irq(&conf->device_lock); in handle_active_stripes()
6671 release_inactive_stripe_list(conf, temp_inactive_list, in handle_active_stripes()
6674 r5l_flush_stripe_to_raid(conf->log); in handle_active_stripes()
6676 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6682 log_write_stripe_run(conf); in handle_active_stripes()
6686 spin_lock_irq(&conf->device_lock); in handle_active_stripes()
6689 __release_stripe(conf, batch[i], &temp_inactive_list[hash]); in handle_active_stripes()
6698 struct r5conf *conf = group->conf; in raid5_do_work() local
6699 struct mddev *mddev = conf->mddev; in raid5_do_work()
6700 int group_id = group - conf->worker_groups; in raid5_do_work()
6708 spin_lock_irq(&conf->device_lock); in raid5_do_work()
6712 released = release_stripe_list(conf, worker->temp_inactive_list); in raid5_do_work()
6714 batch_size = handle_active_stripes(conf, group_id, worker, in raid5_do_work()
6722 conf->device_lock); in raid5_do_work()
6726 spin_unlock_irq(&conf->device_lock); in raid5_do_work()
6728 flush_deferred_bios(conf); in raid5_do_work()
6730 r5l_flush_stripe_to_raid(conf->log); in raid5_do_work()
6748 struct r5conf *conf = mddev->private; in raid5d() local
6758 spin_lock_irq(&conf->device_lock); in raid5d()
6767 released = release_stripe_list(conf, conf->temp_inactive_list); in raid5d()
6769 clear_bit(R5_DID_ALLOC, &conf->cache_state); in raid5d()
6772 !list_empty(&conf->bitmap_list)) { in raid5d()
6774 conf->seq_flush++; in raid5d()
6775 spin_unlock_irq(&conf->device_lock); in raid5d()
6777 spin_lock_irq(&conf->device_lock); in raid5d()
6778 conf->seq_write = conf->seq_flush; in raid5d()
6779 activate_bit_delay(conf, conf->temp_inactive_list); in raid5d()
6781 raid5_activate_delayed(conf); in raid5d()
6783 while ((bio = remove_bio_from_retry(conf, &offset))) { in raid5d()
6785 spin_unlock_irq(&conf->device_lock); in raid5d()
6786 ok = retry_aligned_read(conf, bio, offset); in raid5d()
6787 spin_lock_irq(&conf->device_lock); in raid5d()
6793 batch_size = handle_active_stripes(conf, ANY_GROUP, NULL, in raid5d()
6794 conf->temp_inactive_list); in raid5d()
6800 spin_unlock_irq(&conf->device_lock); in raid5d()
6802 spin_lock_irq(&conf->device_lock); in raid5d()
6807 spin_unlock_irq(&conf->device_lock); in raid5d()
6808 if (test_and_clear_bit(R5_ALLOC_MORE, &conf->cache_state) && in raid5d()
6809 mutex_trylock(&conf->cache_size_mutex)) { in raid5d()
6810 grow_one_stripe(conf, __GFP_NOWARN); in raid5d()
6814 set_bit(R5_DID_ALLOC, &conf->cache_state); in raid5d()
6815 mutex_unlock(&conf->cache_size_mutex); in raid5d()
6818 flush_deferred_bios(conf); in raid5d()
6820 r5l_flush_stripe_to_raid(conf->log); in raid5d()
6831 struct r5conf *conf; in raid5_show_stripe_cache_size() local
6834 conf = mddev->private; in raid5_show_stripe_cache_size()
6835 if (conf) in raid5_show_stripe_cache_size()
6836 ret = sprintf(page, "%d\n", conf->min_nr_stripes); in raid5_show_stripe_cache_size()
6845 struct r5conf *conf = mddev->private; in raid5_set_cache_size() local
6850 WRITE_ONCE(conf->min_nr_stripes, size); in raid5_set_cache_size()
6851 mutex_lock(&conf->cache_size_mutex); in raid5_set_cache_size()
6852 while (size < conf->max_nr_stripes && in raid5_set_cache_size()
6853 drop_one_stripe(conf)) in raid5_set_cache_size()
6855 mutex_unlock(&conf->cache_size_mutex); in raid5_set_cache_size()
6859 mutex_lock(&conf->cache_size_mutex); in raid5_set_cache_size()
6860 while (size > conf->max_nr_stripes) in raid5_set_cache_size()
6861 if (!grow_one_stripe(conf, GFP_KERNEL)) { in raid5_set_cache_size()
6862 WRITE_ONCE(conf->min_nr_stripes, conf->max_nr_stripes); in raid5_set_cache_size()
6866 mutex_unlock(&conf->cache_size_mutex); in raid5_set_cache_size()
6875 struct r5conf *conf; in raid5_store_stripe_cache_size() local
6886 conf = mddev->private; in raid5_store_stripe_cache_size()
6887 if (!conf) in raid5_store_stripe_cache_size()
6904 struct r5conf *conf = mddev->private; in raid5_show_rmw_level() local
6905 if (conf) in raid5_show_rmw_level()
6906 return sprintf(page, "%d\n", conf->rmw_level); in raid5_show_rmw_level()
6914 struct r5conf *conf = mddev->private; in raid5_store_rmw_level() local
6917 if (!conf) in raid5_store_rmw_level()
6934 conf->rmw_level = new; in raid5_store_rmw_level()
6946 struct r5conf *conf; in raid5_show_stripe_size() local
6950 conf = mddev->private; in raid5_show_stripe_size()
6951 if (conf) in raid5_show_stripe_size()
6952 ret = sprintf(page, "%lu\n", RAID5_STRIPE_SIZE(conf)); in raid5_show_stripe_size()
6961 struct r5conf *conf; in raid5_store_stripe_size() local
6985 conf = mddev->private; in raid5_store_stripe_size()
6986 if (!conf) { in raid5_store_stripe_size()
6991 if (new == conf->stripe_size) in raid5_store_stripe_size()
6995 conf->stripe_size, new); in raid5_store_stripe_size()
7003 mutex_lock(&conf->cache_size_mutex); in raid5_store_stripe_size()
7004 size = conf->max_nr_stripes; in raid5_store_stripe_size()
7006 shrink_stripes(conf); in raid5_store_stripe_size()
7008 conf->stripe_size = new; in raid5_store_stripe_size()
7009 conf->stripe_shift = ilog2(new) - 9; in raid5_store_stripe_size()
7010 conf->stripe_sectors = new >> 9; in raid5_store_stripe_size()
7011 if (grow_stripes(conf, size)) { in raid5_store_stripe_size()
7016 mutex_unlock(&conf->cache_size_mutex); in raid5_store_stripe_size()
7037 struct r5conf *conf; in raid5_show_preread_threshold() local
7040 conf = mddev->private; in raid5_show_preread_threshold()
7041 if (conf) in raid5_show_preread_threshold()
7042 ret = sprintf(page, "%d\n", conf->bypass_threshold); in raid5_show_preread_threshold()
7050 struct r5conf *conf; in raid5_store_preread_threshold() local
7062 conf = mddev->private; in raid5_store_preread_threshold()
7063 if (!conf) in raid5_store_preread_threshold()
7065 else if (new > conf->min_nr_stripes) in raid5_store_preread_threshold()
7068 conf->bypass_threshold = new; in raid5_store_preread_threshold()
7082 struct r5conf *conf; in raid5_show_skip_copy() local
7085 conf = mddev->private; in raid5_show_skip_copy()
7086 if (conf) in raid5_show_skip_copy()
7087 ret = sprintf(page, "%d\n", conf->skip_copy); in raid5_show_skip_copy()
7095 struct r5conf *conf; in raid5_store_skip_copy() local
7108 conf = mddev->private; in raid5_store_skip_copy()
7109 if (!conf) in raid5_store_skip_copy()
7111 else if (new != conf->skip_copy) { in raid5_store_skip_copy()
7115 conf->skip_copy = new; in raid5_store_skip_copy()
7134 struct r5conf *conf = mddev->private; in stripe_cache_active_show() local
7135 if (conf) in stripe_cache_active_show()
7136 return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); in stripe_cache_active_show()
7147 struct r5conf *conf; in raid5_show_group_thread_cnt() local
7150 conf = mddev->private; in raid5_show_group_thread_cnt()
7151 if (conf) in raid5_show_group_thread_cnt()
7152 ret = sprintf(page, "%d\n", conf->worker_cnt_per_group); in raid5_show_group_thread_cnt()
7157 static int alloc_thread_groups(struct r5conf *conf, int cnt,
7163 struct r5conf *conf; in raid5_store_group_thread_cnt() local
7180 conf = mddev->private; in raid5_store_group_thread_cnt()
7181 if (!conf) in raid5_store_group_thread_cnt()
7183 else if (new != conf->worker_cnt_per_group) { in raid5_store_group_thread_cnt()
7184 old_groups = conf->worker_groups; in raid5_store_group_thread_cnt()
7188 err = alloc_thread_groups(conf, new, &group_cnt, &new_groups); in raid5_store_group_thread_cnt()
7190 spin_lock_irq(&conf->device_lock); in raid5_store_group_thread_cnt()
7191 conf->group_cnt = group_cnt; in raid5_store_group_thread_cnt()
7192 conf->worker_cnt_per_group = new; in raid5_store_group_thread_cnt()
7193 conf->worker_groups = new_groups; in raid5_store_group_thread_cnt()
7194 spin_unlock_irq(&conf->device_lock); in raid5_store_group_thread_cnt()
7228 static int alloc_thread_groups(struct r5conf *conf, int cnt, int *group_cnt, in alloc_thread_groups() argument
7257 group->conf = conf; in alloc_thread_groups()
7273 static void free_thread_groups(struct r5conf *conf) in free_thread_groups() argument
7275 if (conf->worker_groups) in free_thread_groups()
7276 kfree(conf->worker_groups[0].workers); in free_thread_groups()
7277 kfree(conf->worker_groups); in free_thread_groups()
7278 conf->worker_groups = NULL; in free_thread_groups()
7284 struct r5conf *conf = mddev->private; in raid5_size() local
7290 raid_disks = min(conf->raid_disks, conf->previous_raid_disks); in raid5_size()
7292 sectors &= ~((sector_t)conf->chunk_sectors - 1); in raid5_size()
7293 sectors &= ~((sector_t)conf->prev_chunk_sectors - 1); in raid5_size()
7294 return sectors * (raid_disks - conf->max_degraded); in raid5_size()
7297 static void free_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) in free_scratch_buffer() argument
7305 static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) in alloc_scratch_buffer() argument
7307 if (conf->level == 6 && !percpu->spare_page) { in alloc_scratch_buffer()
7314 max(conf->raid_disks, in alloc_scratch_buffer()
7315 conf->previous_raid_disks), in alloc_scratch_buffer()
7316 max(conf->chunk_sectors, in alloc_scratch_buffer()
7317 conf->prev_chunk_sectors) in alloc_scratch_buffer()
7318 / RAID5_STRIPE_SECTORS(conf))) { in alloc_scratch_buffer()
7319 free_scratch_buffer(conf, percpu); in alloc_scratch_buffer()
7329 struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); in raid456_cpu_dead() local
7331 free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); in raid456_cpu_dead()
7335 static void raid5_free_percpu(struct r5conf *conf) in raid5_free_percpu() argument
7337 if (!conf->percpu) in raid5_free_percpu()
7340 cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); in raid5_free_percpu()
7341 free_percpu(conf->percpu); in raid5_free_percpu()
7344 static void free_conf(struct r5conf *conf) in free_conf() argument
7348 log_exit(conf); in free_conf()
7350 shrinker_free(conf->shrinker); in free_conf()
7351 free_thread_groups(conf); in free_conf()
7352 shrink_stripes(conf); in free_conf()
7353 raid5_free_percpu(conf); in free_conf()
7354 for (i = 0; i < conf->pool_size; i++) in free_conf()
7355 if (conf->disks[i].extra_page) in free_conf()
7356 put_page(conf->disks[i].extra_page); in free_conf()
7357 kfree(conf->disks); in free_conf()
7358 bioset_exit(&conf->bio_split); in free_conf()
7359 kfree(conf->stripe_hashtbl); in free_conf()
7360 kfree(conf->pending_data); in free_conf()
7361 kfree(conf); in free_conf()
7366 struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); in raid456_cpu_up_prepare() local
7367 struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); in raid456_cpu_up_prepare()
7369 if (alloc_scratch_buffer(conf, percpu)) { in raid456_cpu_up_prepare()
7377 static int raid5_alloc_percpu(struct r5conf *conf) in raid5_alloc_percpu() argument
7381 conf->percpu = alloc_percpu(struct raid5_percpu); in raid5_alloc_percpu()
7382 if (!conf->percpu) in raid5_alloc_percpu()
7385 err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); in raid5_alloc_percpu()
7387 conf->scribble_disks = max(conf->raid_disks, in raid5_alloc_percpu()
7388 conf->previous_raid_disks); in raid5_alloc_percpu()
7389 conf->scribble_sectors = max(conf->chunk_sectors, in raid5_alloc_percpu()
7390 conf->prev_chunk_sectors); in raid5_alloc_percpu()
7398 struct r5conf *conf = shrink->private_data; in raid5_cache_scan() local
7401 if (mutex_trylock(&conf->cache_size_mutex)) { in raid5_cache_scan()
7404 conf->max_nr_stripes > conf->min_nr_stripes) { in raid5_cache_scan()
7405 if (drop_one_stripe(conf) == 0) { in raid5_cache_scan()
7411 mutex_unlock(&conf->cache_size_mutex); in raid5_cache_scan()
7419 struct r5conf *conf = shrink->private_data; in raid5_cache_count() local
7420 int max_stripes = READ_ONCE(conf->max_nr_stripes); in raid5_cache_count()
7421 int min_stripes = READ_ONCE(conf->min_nr_stripes); in raid5_cache_count()
7431 struct r5conf *conf; in setup_conf() local
7470 conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); in setup_conf()
7471 if (conf == NULL) in setup_conf()
7475 conf->stripe_size = DEFAULT_STRIPE_SIZE; in setup_conf()
7476 conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9; in setup_conf()
7477 conf->stripe_sectors = DEFAULT_STRIPE_SIZE >> 9; in setup_conf()
7479 INIT_LIST_HEAD(&conf->free_list); in setup_conf()
7480 INIT_LIST_HEAD(&conf->pending_list); in setup_conf()
7481 conf->pending_data = kcalloc(PENDING_IO_MAX, in setup_conf()
7484 if (!conf->pending_data) in setup_conf()
7487 list_add(&conf->pending_data[i].sibling, &conf->free_list); in setup_conf()
7489 if (!alloc_thread_groups(conf, 0, &group_cnt, &new_group)) { in setup_conf()
7490 conf->group_cnt = group_cnt; in setup_conf()
7491 conf->worker_cnt_per_group = 0; in setup_conf()
7492 conf->worker_groups = new_group; in setup_conf()
7495 spin_lock_init(&conf->device_lock); in setup_conf()
7496 seqcount_spinlock_init(&conf->gen_lock, &conf->device_lock); in setup_conf()
7497 mutex_init(&conf->cache_size_mutex); in setup_conf()
7499 init_waitqueue_head(&conf->wait_for_quiescent); in setup_conf()
7500 init_waitqueue_head(&conf->wait_for_stripe); in setup_conf()
7501 init_waitqueue_head(&conf->wait_for_reshape); in setup_conf()
7502 INIT_LIST_HEAD(&conf->handle_list); in setup_conf()
7503 INIT_LIST_HEAD(&conf->loprio_list); in setup_conf()
7504 INIT_LIST_HEAD(&conf->hold_list); in setup_conf()
7505 INIT_LIST_HEAD(&conf->delayed_list); in setup_conf()
7506 INIT_LIST_HEAD(&conf->bitmap_list); in setup_conf()
7507 init_llist_head(&conf->released_stripes); in setup_conf()
7508 atomic_set(&conf->active_stripes, 0); in setup_conf()
7509 atomic_set(&conf->preread_active_stripes, 0); in setup_conf()
7510 atomic_set(&conf->active_aligned_reads, 0); in setup_conf()
7511 spin_lock_init(&conf->pending_bios_lock); in setup_conf()
7512 conf->batch_bio_dispatch = true; in setup_conf()
7517 conf->batch_bio_dispatch = false; in setup_conf()
7522 conf->bypass_threshold = BYPASS_THRESHOLD; in setup_conf()
7523 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
7525 conf->raid_disks = mddev->raid_disks; in setup_conf()
7527 conf->previous_raid_disks = mddev->raid_disks; in setup_conf()
7529 conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; in setup_conf()
7530 max_disks = max(conf->raid_disks, conf->previous_raid_disks); in setup_conf()
7532 conf->disks = kcalloc(max_disks, sizeof(struct disk_info), in setup_conf()
7535 if (!conf->disks) in setup_conf()
7539 conf->disks[i].extra_page = alloc_page(GFP_KERNEL); in setup_conf()
7540 if (!conf->disks[i].extra_page) in setup_conf()
7544 ret = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
7547 conf->mddev = mddev; in setup_conf()
7550 conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL); in setup_conf()
7551 if (!conf->stripe_hashtbl) in setup_conf()
7559 spin_lock_init(conf->hash_locks); in setup_conf()
7561 spin_lock_init(conf->hash_locks + i); in setup_conf()
7564 INIT_LIST_HEAD(conf->inactive_list + i); in setup_conf()
7567 INIT_LIST_HEAD(conf->temp_inactive_list + i); in setup_conf()
7569 atomic_set(&conf->r5c_cached_full_stripes, 0); in setup_conf()
7570 INIT_LIST_HEAD(&conf->r5c_full_stripe_list); in setup_conf()
7571 atomic_set(&conf->r5c_cached_partial_stripes, 0); in setup_conf()
7572 INIT_LIST_HEAD(&conf->r5c_partial_stripe_list); in setup_conf()
7573 atomic_set(&conf->r5c_flushing_full_stripes, 0); in setup_conf()
7574 atomic_set(&conf->r5c_flushing_partial_stripes, 0); in setup_conf()
7576 conf->level = mddev->new_level; in setup_conf()
7577 conf->chunk_sectors = mddev->new_chunk_sectors; in setup_conf()
7578 ret = raid5_alloc_percpu(conf); in setup_conf()
7590 disk = conf->disks + raid_disk; in setup_conf()
7607 conf->fullsync = 1; in setup_conf()
7610 conf->level = mddev->new_level; in setup_conf()
7611 if (conf->level == 6) { in setup_conf()
7612 conf->max_degraded = 2; in setup_conf()
7614 conf->rmw_level = PARITY_ENABLE_RMW; in setup_conf()
7616 conf->rmw_level = PARITY_DISABLE_RMW; in setup_conf()
7618 conf->max_degraded = 1; in setup_conf()
7619 conf->rmw_level = PARITY_ENABLE_RMW; in setup_conf()
7621 conf->algorithm = mddev->new_layout; in setup_conf()
7622 conf->reshape_progress = mddev->reshape_position; in setup_conf()
7623 if (conf->reshape_progress != MaxSector) { in setup_conf()
7624 conf->prev_chunk_sectors = mddev->chunk_sectors; in setup_conf()
7625 conf->prev_algo = mddev->layout; in setup_conf()
7627 conf->prev_chunk_sectors = conf->chunk_sectors; in setup_conf()
7628 conf->prev_algo = conf->algorithm; in setup_conf()
7631 conf->min_nr_stripes = NR_STRIPES; in setup_conf()
7634 ((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4, in setup_conf()
7635 ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4); in setup_conf()
7636 conf->min_nr_stripes = max(NR_STRIPES, stripes); in setup_conf()
7637 if (conf->min_nr_stripes != NR_STRIPES) in setup_conf()
7639 mdname(mddev), conf->min_nr_stripes); in setup_conf()
7641 memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + in setup_conf()
7643 atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS); in setup_conf()
7644 if (grow_stripes(conf, conf->min_nr_stripes)) { in setup_conf()
7656 conf->shrinker = shrinker_alloc(0, "md-raid5:%s", mdname(mddev)); in setup_conf()
7657 if (!conf->shrinker) { in setup_conf()
7664 conf->shrinker->seeks = DEFAULT_SEEKS * conf->raid_disks * 4; in setup_conf()
7665 conf->shrinker->scan_objects = raid5_cache_scan; in setup_conf()
7666 conf->shrinker->count_objects = raid5_cache_count; in setup_conf()
7667 conf->shrinker->batch = 128; in setup_conf()
7668 conf->shrinker->private_data = conf; in setup_conf()
7670 shrinker_register(conf->shrinker); in setup_conf()
7673 rcu_assign_pointer(conf->thread, in setup_conf()
7675 if (!conf->thread) { in setup_conf()
7682 return conf; in setup_conf()
7685 if (conf) in setup_conf()
7686 free_conf(conf); in setup_conf()
7718 struct r5conf *conf = mddev->private; in raid5_set_limits() local
7727 data_disks = conf->previous_raid_disks - conf->max_degraded; in raid5_set_limits()
7737 lim.io_opt = lim.io_min * (conf->raid_disks - conf->max_degraded); in raid5_set_limits()
7769 lim.max_hw_sectors = RAID5_MAX_REQ_STRIPES << RAID5_STRIPE_SHIFT(conf); in raid5_set_limits()
7779 struct r5conf *conf; in raid5_run() local
7917 conf = setup_conf(mddev); in raid5_run()
7919 conf = mddev->private; in raid5_run()
7921 if (IS_ERR(conf)) in raid5_run()
7922 return PTR_ERR(conf); in raid5_run()
7934 conf->min_offset_diff = min_offset_diff; in raid5_run()
7935 rcu_assign_pointer(mddev->thread, conf->thread); in raid5_run()
7936 rcu_assign_pointer(conf->thread, NULL); in raid5_run()
7937 mddev->private = conf; in raid5_run()
7939 for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; in raid5_run()
7941 rdev = conf->disks[i].rdev; in raid5_run()
7944 if (conf->disks[i].replacement && in raid5_run()
7945 conf->reshape_progress != MaxSector) { in raid5_run()
7968 conf->algorithm, in raid5_run()
7969 conf->raid_disks, in raid5_run()
7970 conf->max_degraded)) in raid5_run()
7974 conf->prev_algo, in raid5_run()
7975 conf->previous_raid_disks, in raid5_run()
7976 conf->max_degraded)) in raid5_run()
7984 mddev->degraded = raid5_calc_degraded(conf); in raid5_run()
7986 if (has_failed(conf)) { in raid5_run()
7988 mdname(mddev), mddev->degraded, conf->raid_disks); in raid5_run()
8012 mdname(mddev), conf->level, in raid5_run()
8016 print_raid5_conf(conf); in raid5_run()
8018 if (conf->reshape_progress != MaxSector) { in raid5_run()
8019 conf->reshape_safe = conf->reshape_progress; in raid5_run()
8020 atomic_set(&conf->reshape_stripes, 0); in raid5_run()
8042 if (log_init(conf, journal_dev, raid5_has_ppl(conf))) in raid5_run()
8048 print_raid5_conf(conf); in raid5_run()
8049 free_conf(conf); in raid5_run()
8057 struct r5conf *conf = priv; in raid5_free() local
8059 free_conf(conf); in raid5_free()
8065 struct r5conf *conf = mddev->private; in raid5_status() local
8071 conf->chunk_sectors / 2, mddev->layout); in raid5_status()
8072 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); in raid5_status()
8073 for (i = 0; i < conf->raid_disks; i++) { in raid5_status()
8074 struct md_rdev *rdev = READ_ONCE(conf->disks[i].rdev); in raid5_status()
8081 static void print_raid5_conf(struct r5conf *conf) in print_raid5_conf() argument
8086 pr_debug("RAID conf printout:\n"); in print_raid5_conf()
8087 if (!conf) { in print_raid5_conf()
8088 pr_debug("(conf==NULL)\n"); in print_raid5_conf()
8091 pr_debug(" --- level:%d rd:%d wd:%d\n", conf->level, in print_raid5_conf()
8092 conf->raid_disks, in print_raid5_conf()
8093 conf->raid_disks - conf->mddev->degraded); in print_raid5_conf()
8095 for (i = 0; i < conf->raid_disks; i++) { in print_raid5_conf()
8096 rdev = conf->disks[i].rdev; in print_raid5_conf()
8107 struct r5conf *conf = mddev->private; in raid5_spare_active() local
8112 for (i = 0; i < conf->raid_disks; i++) { in raid5_spare_active()
8113 rdev = conf->disks[i].rdev; in raid5_spare_active()
8114 replacement = conf->disks[i].replacement; in raid5_spare_active()
8141 spin_lock_irqsave(&conf->device_lock, flags); in raid5_spare_active()
8142 mddev->degraded = raid5_calc_degraded(conf); in raid5_spare_active()
8143 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_spare_active()
8144 print_raid5_conf(conf); in raid5_spare_active()
8150 struct r5conf *conf = mddev->private; in raid5_remove_disk() local
8157 print_raid5_conf(conf); in raid5_remove_disk()
8158 if (test_bit(Journal, &rdev->flags) && conf->log) { in raid5_remove_disk()
8165 if (atomic_read(&conf->active_stripes) || in raid5_remove_disk()
8166 atomic_read(&conf->r5c_cached_full_stripes) || in raid5_remove_disk()
8167 atomic_read(&conf->r5c_cached_partial_stripes)) { in raid5_remove_disk()
8170 log_exit(conf); in raid5_remove_disk()
8173 if (unlikely(number >= conf->pool_size)) in raid5_remove_disk()
8175 p = conf->disks + number; in raid5_remove_disk()
8183 if (number >= conf->raid_disks && in raid5_remove_disk()
8184 conf->reshape_progress == MaxSector) in raid5_remove_disk()
8196 mddev->recovery_disabled != conf->recovery_disabled && in raid5_remove_disk()
8197 !has_failed(conf) && in raid5_remove_disk()
8199 number < conf->raid_disks) { in raid5_remove_disk()
8205 err = log_modify(conf, rdev, false); in raid5_remove_disk()
8218 err = log_modify(conf, tmp, true); in raid5_remove_disk()
8224 print_raid5_conf(conf); in raid5_remove_disk()
8230 struct r5conf *conf = mddev->private; in raid5_add_disk() local
8236 int last = conf->raid_disks - 1; in raid5_add_disk()
8239 if (conf->log) in raid5_add_disk()
8247 ret = log_init(conf, rdev, false); in raid5_add_disk()
8251 ret = r5l_start(conf->log); in raid5_add_disk()
8257 if (mddev->recovery_disabled == conf->recovery_disabled) in raid5_add_disk()
8260 if (rdev->saved_raid_disk < 0 && has_failed(conf)) in raid5_add_disk()
8273 conf->disks[rdev->saved_raid_disk].rdev == NULL) in raid5_add_disk()
8277 p = conf->disks + disk; in raid5_add_disk()
8282 conf->fullsync = 1; in raid5_add_disk()
8285 err = log_modify(conf, rdev, true); in raid5_add_disk()
8291 p = conf->disks + disk; in raid5_add_disk()
8300 conf->fullsync = 1; in raid5_add_disk()
8306 print_raid5_conf(conf); in raid5_add_disk()
8320 struct r5conf *conf = mddev->private; in raid5_resize() local
8323 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in raid5_resize()
8325 sectors &= ~((sector_t)conf->chunk_sectors - 1); in raid5_resize()
8356 struct r5conf *conf = mddev->private; in check_stripe_cache() local
8357 if (((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 in check_stripe_cache()
8358 > conf->min_nr_stripes || in check_stripe_cache()
8359 ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 in check_stripe_cache()
8360 > conf->min_nr_stripes) { in check_stripe_cache()
8364 / RAID5_STRIPE_SIZE(conf))*4); in check_stripe_cache()
8372 struct r5conf *conf = mddev->private; in check_reshape() local
8374 if (raid5_has_log(conf) || raid5_has_ppl(conf)) in check_reshape()
8380 if (has_failed(conf)) in check_reshape()
8400 if (resize_chunks(conf, in check_reshape()
8401 conf->previous_raid_disks in check_reshape()
8408 if (conf->previous_raid_disks + mddev->delta_disks <= conf->pool_size) in check_reshape()
8410 return resize_stripes(conf, (conf->previous_raid_disks in check_reshape()
8416 struct r5conf *conf = mddev->private; in raid5_start_reshape() local
8428 if (has_failed(conf)) in raid5_start_reshape()
8434 for (i = 0; i < conf->raid_disks; i++) in raid5_start_reshape()
8435 if (conf->disks[i].replacement) in raid5_start_reshape()
8444 if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) in raid5_start_reshape()
8454 if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) in raid5_start_reshape()
8461 atomic_set(&conf->reshape_stripes, 0); in raid5_start_reshape()
8462 spin_lock_irq(&conf->device_lock); in raid5_start_reshape()
8463 write_seqcount_begin(&conf->gen_lock); in raid5_start_reshape()
8464 conf->previous_raid_disks = conf->raid_disks; in raid5_start_reshape()
8465 conf->raid_disks += mddev->delta_disks; in raid5_start_reshape()
8466 conf->prev_chunk_sectors = conf->chunk_sectors; in raid5_start_reshape()
8467 conf->chunk_sectors = mddev->new_chunk_sectors; in raid5_start_reshape()
8468 conf->prev_algo = conf->algorithm; in raid5_start_reshape()
8469 conf->algorithm = mddev->new_layout; in raid5_start_reshape()
8470 conf->generation++; in raid5_start_reshape()
8476 conf->reshape_progress = raid5_size(mddev, 0, 0); in raid5_start_reshape()
8478 conf->reshape_progress = 0; in raid5_start_reshape()
8479 conf->reshape_safe = conf->reshape_progress; in raid5_start_reshape()
8480 write_seqcount_end(&conf->gen_lock); in raid5_start_reshape()
8481 spin_unlock_irq(&conf->device_lock); in raid5_start_reshape()
8503 >= conf->previous_raid_disks) in raid5_start_reshape()
8511 } else if (rdev->raid_disk >= conf->previous_raid_disks in raid5_start_reshape()
8521 spin_lock_irqsave(&conf->device_lock, flags); in raid5_start_reshape()
8522 mddev->degraded = raid5_calc_degraded(conf); in raid5_start_reshape()
8523 spin_unlock_irqrestore(&conf->device_lock, flags); in raid5_start_reshape()
8525 mddev->raid_disks = conf->raid_disks; in raid5_start_reshape()
8526 mddev->reshape_position = conf->reshape_progress; in raid5_start_reshape()
8534 conf->reshape_checkpoint = jiffies; in raid5_start_reshape()
8540 * changes needed in 'conf'
8542 static void end_reshape(struct r5conf *conf) in end_reshape() argument
8545 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in end_reshape()
8548 spin_lock_irq(&conf->device_lock); in end_reshape()
8549 conf->previous_raid_disks = conf->raid_disks; in end_reshape()
8550 md_finish_reshape(conf->mddev); in end_reshape()
8552 conf->reshape_progress = MaxSector; in end_reshape()
8553 conf->mddev->reshape_position = MaxSector; in end_reshape()
8554 rdev_for_each(rdev, conf->mddev) in end_reshape()
8559 spin_unlock_irq(&conf->device_lock); in end_reshape()
8560 wake_up(&conf->wait_for_reshape); in end_reshape()
8562 mddev_update_io_opt(conf->mddev, in end_reshape()
8563 conf->raid_disks - conf->max_degraded); in end_reshape()
8572 struct r5conf *conf = mddev->private; in raid5_finish_reshape() local
8579 spin_lock_irq(&conf->device_lock); in raid5_finish_reshape()
8580 mddev->degraded = raid5_calc_degraded(conf); in raid5_finish_reshape()
8581 spin_unlock_irq(&conf->device_lock); in raid5_finish_reshape()
8582 for (d = conf->raid_disks ; in raid5_finish_reshape()
8583 d < conf->raid_disks - mddev->delta_disks; in raid5_finish_reshape()
8585 rdev = conf->disks[d].rdev; in raid5_finish_reshape()
8588 rdev = conf->disks[d].replacement; in raid5_finish_reshape()
8593 mddev->layout = conf->algorithm; in raid5_finish_reshape()
8594 mddev->chunk_sectors = conf->chunk_sectors; in raid5_finish_reshape()
8603 struct r5conf *conf = mddev->private; in raid5_quiesce() local
8607 lock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8611 r5c_flush_cache(conf, INT_MAX); in raid5_quiesce()
8615 smp_store_release(&conf->quiesce, 2); in raid5_quiesce()
8616 wait_event_cmd(conf->wait_for_quiescent, in raid5_quiesce()
8617 atomic_read(&conf->active_stripes) == 0 && in raid5_quiesce()
8618 atomic_read(&conf->active_aligned_reads) == 0, in raid5_quiesce()
8619 unlock_all_device_hash_locks_irq(conf), in raid5_quiesce()
8620 lock_all_device_hash_locks_irq(conf)); in raid5_quiesce()
8621 conf->quiesce = 1; in raid5_quiesce()
8622 unlock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8624 wake_up(&conf->wait_for_reshape); in raid5_quiesce()
8627 lock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8628 conf->quiesce = 0; in raid5_quiesce()
8629 wake_up(&conf->wait_for_quiescent); in raid5_quiesce()
8630 wake_up(&conf->wait_for_reshape); in raid5_quiesce()
8631 unlock_all_device_hash_locks_irq(conf); in raid5_quiesce()
8633 log_quiesce(conf, quiesce); in raid5_quiesce()
8734 struct r5conf *conf = mddev->private; in raid5_check_reshape() local
8754 conf->algorithm = mddev->new_layout; in raid5_check_reshape()
8758 conf->chunk_sectors = new_chunk ; in raid5_check_reshape()
8877 struct r5conf *conf; in raid5_change_consistency_policy() local
8883 conf = mddev->private; in raid5_change_consistency_policy()
8884 if (!conf) { in raid5_change_consistency_policy()
8891 if (!raid5_has_ppl(conf) && conf->level == 5) { in raid5_change_consistency_policy()
8892 err = log_init(conf, NULL, true); in raid5_change_consistency_policy()
8894 err = resize_stripes(conf, conf->pool_size); in raid5_change_consistency_policy()
8896 log_exit(conf); in raid5_change_consistency_policy()
8901 if (raid5_has_ppl(conf)) { in raid5_change_consistency_policy()
8902 log_exit(conf); in raid5_change_consistency_policy()
8903 err = resize_stripes(conf, conf->pool_size); in raid5_change_consistency_policy()
8904 } else if (test_bit(MD_HAS_JOURNAL, &conf->mddev->flags) && in raid5_change_consistency_policy()
8905 r5l_log_disk_error(conf)) { in raid5_change_consistency_policy()
8935 struct r5conf *conf = mddev->private; in raid5_start() local
8937 return r5l_start(conf->log); in raid5_start()
8947 struct r5conf *conf = mddev->private; in raid5_prepare_suspend() local
8949 wake_up(&conf->wait_for_reshape); in raid5_prepare_suspend()