Lines Matching refs:mddev

199 		md_wakeup_thread(conf->mddev->thread);  in raid5_wakeup_stripe_thread()
271 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
277 md_wakeup_thread(conf->mddev->thread); in do_release_stripe()
358 md_wakeup_thread(conf->mddev->thread); in release_inactive_stripe_list()
404 if (unlikely(!conf->mddev->thread) || in raid5_release_stripe()
409 md_wakeup_thread(conf->mddev->thread); in raid5_release_stripe()
625 if (conf->mddev->reshape_position == MaxSector) in has_failed()
626 return conf->mddev->degraded > conf->max_degraded; in has_failed()
837 md_wakeup_thread(conf->mddev->thread); in stripe_add_to_batch_list()
1072 if (!conf->mddev->external && in ops_run_io()
1073 conf->mddev->sb_flags) { in ops_run_io()
1078 md_check_recovery(conf->mddev); in ops_run_io()
1086 md_wait_for_blocked_rdev(rdev, conf->mddev); in ops_run_io()
1089 rdev_dec_pending(rdev, conf->mddev); in ops_run_io()
1152 if (conf->mddev->gendisk) in ops_run_io()
1154 bi, disk_devt(conf->mddev->gendisk), in ops_run_io()
1202 if (conf->mddev->gendisk) in ops_run_io()
1204 rbi, disk_devt(conf->mddev->gendisk), in ops_run_io()
2205 if (conf->mddev->gendisk) in grow_stripes()
2207 "raid%d-%s", conf->level, mdname(conf->mddev)); in grow_stripes()
2210 "raid%d-%p", conf->level, conf->mddev); in grow_stripes()
2271 mddev_suspend(conf->mddev); in resize_chunks()
2291 mddev_resume(conf->mddev); in resize_chunks()
2332 md_allow_write(conf->mddev); in resize_stripes()
2519 mdname(conf->mddev), STRIPE_SECTORS, in raid5_end_read_request()
2547 mdname(conf->mddev), in raid5_end_read_request()
2550 else if (conf->mddev->degraded >= conf->max_degraded) { in raid5_end_read_request()
2554 mdname(conf->mddev), in raid5_end_read_request()
2562 mdname(conf->mddev), in raid5_end_read_request()
2568 mdname(conf->mddev), bdn); in raid5_end_read_request()
2587 md_error(conf->mddev, rdev); in raid5_end_read_request()
2590 rdev_dec_pending(rdev, conf->mddev); in raid5_end_read_request()
2636 md_error(conf->mddev, rdev); in raid5_end_write_request()
2648 &rdev->mddev->recovery); in raid5_end_write_request()
2661 rdev_dec_pending(rdev, conf->mddev); in raid5_end_write_request()
2676 static void raid5_error(struct mddev *mddev, struct md_rdev *rdev) in raid5_error() argument
2679 struct r5conf *conf = mddev->private; in raid5_error()
2686 mddev->degraded = raid5_calc_degraded(conf); in raid5_error()
2688 set_bit(MD_RECOVERY_INTR, &mddev->recovery); in raid5_error()
2691 set_mask_bits(&mddev->sb_flags, 0, in raid5_error()
2695 mdname(mddev), in raid5_error()
2697 mdname(mddev), in raid5_error()
2698 conf->raid_disks - mddev->degraded); in raid5_error()
2699 r5c_update_on_rdev_error(mddev, rdev); in raid5_error()
3022 mdname(conf->mddev)); in raid5_compute_blocknr()
3266 md_write_inc(conf->mddev, bi); in add_stripe_bio()
3287 if (conf->mddev->bitmap && firstwrite) { in add_stripe_bio()
3302 md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, in add_stripe_bio()
3366 md_error(conf->mddev, rdev); in handle_failed_stripe()
3367 rdev_dec_pending(rdev, conf->mddev); in handle_failed_stripe()
3388 md_write_end(conf->mddev); in handle_failed_stripe()
3393 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3409 md_write_end(conf->mddev); in handle_failed_stripe()
3439 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_failed_stripe()
3451 md_wakeup_thread(conf->mddev->thread); in handle_failed_stripe()
3474 if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { in handle_failed_sync()
3498 conf->mddev->recovery_disabled; in handle_failed_sync()
3500 md_done_sync(conf->mddev, STRIPE_SECTORS, !abort); in handle_failed_sync()
3514 || rdev->mddev->recovery_cp <= sh->sector)) in want_replace()
3596 sh->sector < sh->raid_conf->mddev->recovery_cp) in need_this_block()
3776 md_write_end(conf->mddev); in handle_stripe_clean_event()
3780 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, in handle_stripe_clean_event()
3837 md_wakeup_thread(conf->mddev->thread); in handle_stripe_clean_event()
3864 sector_t recovery_cp = conf->mddev->recovery_cp; in handle_stripe_dirtying()
3915 if (conf->mddev->queue) in handle_stripe_dirtying()
3916 blk_add_trace_msg(conf->mddev->queue, in handle_stripe_dirtying()
3999 if (rcw && conf->mddev->queue) in handle_stripe_dirtying()
4000 blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", in handle_stripe_dirtying()
4088 atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); in handle_parity_checks5()
4089 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks5()
4093 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks5()
4245 atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); in handle_parity_checks6()
4246 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { in handle_parity_checks6()
4250 "%llu-%llu\n", mdname(conf->mddev), in handle_parity_checks6()
4545 sh->sector >= conf->mddev->recovery_cp || in analyse_stripe()
4546 test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) in analyse_stripe()
4709 test_bit(MD_SB_CHANGE_PENDING, &conf->mddev->sb_flags)) { in handle_stripe()
4721 rdev_dec_pending(s.blocked_rdev, conf->mddev); in handle_stripe()
4909 md_done_sync(conf->mddev, STRIPE_SECTORS, 1); in handle_stripe()
4918 if (s.failed <= conf->max_degraded && !conf->mddev->ro) in handle_stripe()
4977 md_done_sync(conf->mddev, STRIPE_SECTORS, 1); in handle_stripe()
4987 if (conf->mddev->external) in handle_stripe()
4989 conf->mddev); in handle_stripe()
4996 conf->mddev); in handle_stripe()
5008 md_error(conf->mddev, rdev); in handle_stripe()
5009 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5015 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5024 rdev_dec_pending(rdev, conf->mddev); in handle_stripe()
5041 md_wakeup_thread(conf->mddev->thread); in handle_stripe()
5081 static int raid5_congested(struct mddev *mddev, int bits) in raid5_congested() argument
5083 struct r5conf *conf = mddev->private; in raid5_congested()
5103 static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) in in_chunk_boundary() argument
5105 struct r5conf *conf = mddev->private; in in_chunk_boundary()
5131 md_wakeup_thread(conf->mddev->thread); in add_bio_to_retry()
5164 struct mddev *mddev; in raid5_align_endio() local
5173 mddev = rdev->mddev; in raid5_align_endio()
5174 conf = mddev->private; in raid5_align_endio()
5176 rdev_dec_pending(rdev, conf->mddev); in raid5_align_endio()
5190 static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio) in raid5_read_one_chunk() argument
5192 struct r5conf *conf = mddev->private; in raid5_read_one_chunk()
5198 if (!in_chunk_boundary(mddev, raid_bio)) { in raid5_read_one_chunk()
5205 align_bi = bio_clone_fast(raid_bio, GFP_NOIO, &mddev->bio_set); in raid5_read_one_chunk()
5254 rdev_dec_pending(rdev, mddev); in raid5_read_one_chunk()
5268 if (mddev->gendisk) in raid5_read_one_chunk()
5270 align_bi, disk_devt(mddev->gendisk), in raid5_read_one_chunk()
5281 static struct bio *chunk_aligned_read(struct mddev *mddev, struct bio *raid_bio) in chunk_aligned_read() argument
5285 unsigned chunk_sects = mddev->chunk_sectors; in chunk_aligned_read()
5289 struct r5conf *conf = mddev->private; in chunk_aligned_read()
5296 if (!raid5_read_one_chunk(mddev, raid_bio)) in chunk_aligned_read()
5415 struct mddev *mddev = cb->cb.data; in raid5_unplug() local
5416 struct r5conf *conf = mddev->private; in raid5_unplug()
5444 if (mddev->queue) in raid5_unplug()
5445 trace_block_unplug(mddev->queue, cnt, !from_schedule); in raid5_unplug()
5449 static void release_stripe_plug(struct mddev *mddev, in release_stripe_plug() argument
5453 raid5_unplug, mddev, in release_stripe_plug()
5477 static void make_discard_request(struct mddev *mddev, struct bio *bi) in make_discard_request() argument
5479 struct r5conf *conf = mddev->private; in make_discard_request()
5484 if (mddev->reshape_position != MaxSector) in make_discard_request()
5538 md_write_inc(mddev, bi); in make_discard_request()
5542 if (conf->mddev->bitmap) { in make_discard_request()
5546 md_bitmap_startwrite(mddev->bitmap, in make_discard_request()
5558 release_stripe_plug(mddev, sh); in make_discard_request()
5564 static bool raid5_make_request(struct mddev *mddev, struct bio * bi) in raid5_make_request() argument
5566 struct r5conf *conf = mddev->private; in raid5_make_request()
5582 md_flush_request(mddev, bi); in raid5_make_request()
5593 if (!md_write_start(mddev, bi)) in raid5_make_request()
5600 if (rw == READ && mddev->degraded == 0 && in raid5_make_request()
5601 mddev->reshape_position == MaxSector) { in raid5_make_request()
5602 bi = chunk_aligned_read(mddev, bi); in raid5_make_request()
5608 make_discard_request(mddev, bi); in raid5_make_request()
5609 md_write_end(mddev); in raid5_make_request()
5639 if (mddev->reshape_backwards in raid5_make_request()
5644 if (mddev->reshape_backwards in raid5_make_request()
5677 if (mddev->reshape_backwards in raid5_make_request()
5704 md_wakeup_thread(mddev->thread); in raid5_make_request()
5722 release_stripe_plug(mddev, sh); in raid5_make_request()
5732 md_write_end(mddev); in raid5_make_request()
5737 static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks);
5739 static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *skipped) in reshape_request() argument
5750 struct r5conf *conf = mddev->private; in reshape_request()
5767 if (mddev->reshape_backwards && in reshape_request()
5768 conf->reshape_progress < raid5_size(mddev, 0, 0)) { in reshape_request()
5769 sector_nr = raid5_size(mddev, 0, 0) in reshape_request()
5771 } else if (mddev->reshape_backwards && in reshape_request()
5775 } else if (!mddev->reshape_backwards && in reshape_request()
5780 mddev->curr_resync_completed = sector_nr; in reshape_request()
5781 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); in reshape_request()
5807 if (mddev->reshape_backwards) { in reshape_request()
5825 if (mddev->reshape_backwards) { in reshape_request()
5828 BUG_ON((mddev->dev_sectors & in reshape_request()
5863 if ((mddev->reshape_backwards in reshape_request()
5870 || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); in reshape_request()
5873 mddev->reshape_position = conf->reshape_progress; in reshape_request()
5874 mddev->curr_resync_completed = sector_nr; in reshape_request()
5875 if (!mddev->reshape_backwards) in reshape_request()
5877 rdev_for_each(rdev, mddev) in reshape_request()
5885 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in reshape_request()
5886 md_wakeup_thread(mddev->thread); in reshape_request()
5887 wait_event(mddev->sb_wait, mddev->sb_flags == 0 || in reshape_request()
5888 test_bit(MD_RECOVERY_INTR, &mddev->recovery)); in reshape_request()
5889 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) in reshape_request()
5892 conf->reshape_safe = mddev->reshape_position; in reshape_request()
5895 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); in reshape_request()
5916 if (s < raid5_size(mddev, 0, 0)) { in reshape_request()
5931 if (mddev->reshape_backwards) in reshape_request()
5948 if (last_sector >= mddev->dev_sectors) in reshape_request()
5949 last_sector = mddev->dev_sectors - 1; in reshape_request()
5971 if (mddev->curr_resync_completed > mddev->resync_max || in reshape_request()
5972 (sector_nr - mddev->curr_resync_completed) * 2 in reshape_request()
5973 >= mddev->resync_max - mddev->curr_resync_completed) { in reshape_request()
5977 || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); in reshape_request()
5980 mddev->reshape_position = conf->reshape_progress; in reshape_request()
5981 mddev->curr_resync_completed = sector_nr; in reshape_request()
5982 if (!mddev->reshape_backwards) in reshape_request()
5984 rdev_for_each(rdev, mddev) in reshape_request()
5991 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in reshape_request()
5992 md_wakeup_thread(mddev->thread); in reshape_request()
5993 wait_event(mddev->sb_wait, in reshape_request()
5994 !test_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags) in reshape_request()
5995 || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); in reshape_request()
5996 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) in reshape_request()
5999 conf->reshape_safe = mddev->reshape_position; in reshape_request()
6002 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); in reshape_request()
6008 static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_nr, in raid5_sync_request() argument
6011 struct r5conf *conf = mddev->private; in raid5_sync_request()
6013 sector_t max_sector = mddev->dev_sectors; in raid5_sync_request()
6021 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { in raid5_sync_request()
6026 if (mddev->curr_resync < max_sector) /* aborted */ in raid5_sync_request()
6027 md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync, in raid5_sync_request()
6031 md_bitmap_close_sync(mddev->bitmap); in raid5_sync_request()
6039 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) in raid5_sync_request()
6040 return reshape_request(mddev, sector_nr, skipped); in raid5_sync_request()
6052 if (mddev->degraded >= conf->max_degraded && in raid5_sync_request()
6053 test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { in raid5_sync_request()
6054 sector_t rv = mddev->dev_sectors - sector_nr; in raid5_sync_request()
6058 if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && in raid5_sync_request()
6060 !md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && in raid5_sync_request()
6068 md_bitmap_cond_end_sync(mddev->bitmap, sector_nr, false); in raid5_sync_request()
6091 md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); in raid5_sync_request()
6218 struct mddev *mddev = conf->mddev; in raid5_do_work() local
6239 wait_event_lock_irq(mddev->sb_wait, in raid5_do_work()
6240 !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags), in raid5_do_work()
6266 struct mddev *mddev = thread->mddev; in raid5d() local
6267 struct r5conf *conf = mddev->private; in raid5d()
6273 md_check_recovery(mddev); in raid5d()
6292 md_bitmap_unplug(mddev->bitmap); in raid5d()
6315 if (mddev->sb_flags & ~(1 << MD_SB_CHANGE_PENDING)) { in raid5d()
6317 md_check_recovery(mddev); in raid5d()
6345 raid5_show_stripe_cache_size(struct mddev *mddev, char *page) in raid5_show_stripe_cache_size() argument
6349 spin_lock(&mddev->lock); in raid5_show_stripe_cache_size()
6350 conf = mddev->private; in raid5_show_stripe_cache_size()
6353 spin_unlock(&mddev->lock); in raid5_show_stripe_cache_size()
6358 raid5_set_cache_size(struct mddev *mddev, int size) in raid5_set_cache_size() argument
6360 struct r5conf *conf = mddev->private; in raid5_set_cache_size()
6372 md_allow_write(mddev); in raid5_set_cache_size()
6385 raid5_store_stripe_cache_size(struct mddev *mddev, const char *page, size_t len) in raid5_store_stripe_cache_size() argument
6395 err = mddev_lock(mddev); in raid5_store_stripe_cache_size()
6398 conf = mddev->private; in raid5_store_stripe_cache_size()
6402 err = raid5_set_cache_size(mddev, new); in raid5_store_stripe_cache_size()
6403 mddev_unlock(mddev); in raid5_store_stripe_cache_size()
6414 raid5_show_rmw_level(struct mddev *mddev, char *page) in raid5_show_rmw_level() argument
6416 struct r5conf *conf = mddev->private; in raid5_show_rmw_level()
6424 raid5_store_rmw_level(struct mddev *mddev, const char *page, size_t len) in raid5_store_rmw_level() argument
6426 struct r5conf *conf = mddev->private; in raid5_store_rmw_level()
6457 raid5_show_preread_threshold(struct mddev *mddev, char *page) in raid5_show_preread_threshold() argument
6461 spin_lock(&mddev->lock); in raid5_show_preread_threshold()
6462 conf = mddev->private; in raid5_show_preread_threshold()
6465 spin_unlock(&mddev->lock); in raid5_show_preread_threshold()
6470 raid5_store_preread_threshold(struct mddev *mddev, const char *page, size_t len) in raid5_store_preread_threshold() argument
6481 err = mddev_lock(mddev); in raid5_store_preread_threshold()
6484 conf = mddev->private; in raid5_store_preread_threshold()
6491 mddev_unlock(mddev); in raid5_store_preread_threshold()
6502 raid5_show_skip_copy(struct mddev *mddev, char *page) in raid5_show_skip_copy() argument
6506 spin_lock(&mddev->lock); in raid5_show_skip_copy()
6507 conf = mddev->private; in raid5_show_skip_copy()
6510 spin_unlock(&mddev->lock); in raid5_show_skip_copy()
6515 raid5_store_skip_copy(struct mddev *mddev, const char *page, size_t len) in raid5_store_skip_copy() argument
6527 err = mddev_lock(mddev); in raid5_store_skip_copy()
6530 conf = mddev->private; in raid5_store_skip_copy()
6534 mddev_suspend(mddev); in raid5_store_skip_copy()
6537 mddev->queue->backing_dev_info->capabilities |= in raid5_store_skip_copy()
6540 mddev->queue->backing_dev_info->capabilities &= in raid5_store_skip_copy()
6542 mddev_resume(mddev); in raid5_store_skip_copy()
6544 mddev_unlock(mddev); in raid5_store_skip_copy()
6554 stripe_cache_active_show(struct mddev *mddev, char *page) in stripe_cache_active_show() argument
6556 struct r5conf *conf = mddev->private; in stripe_cache_active_show()
6567 raid5_show_group_thread_cnt(struct mddev *mddev, char *page) in raid5_show_group_thread_cnt() argument
6571 spin_lock(&mddev->lock); in raid5_show_group_thread_cnt()
6572 conf = mddev->private; in raid5_show_group_thread_cnt()
6575 spin_unlock(&mddev->lock); in raid5_show_group_thread_cnt()
6584 raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) in raid5_store_group_thread_cnt() argument
6600 err = mddev_lock(mddev); in raid5_store_group_thread_cnt()
6603 conf = mddev->private; in raid5_store_group_thread_cnt()
6607 mddev_suspend(mddev); in raid5_store_group_thread_cnt()
6627 mddev_resume(mddev); in raid5_store_group_thread_cnt()
6629 mddev_unlock(mddev); in raid5_store_group_thread_cnt()
6711 raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) in raid5_size() argument
6713 struct r5conf *conf = mddev->private; in raid5_size()
6716 sectors = mddev->dev_sectors; in raid5_size()
6855 static struct r5conf *setup_conf(struct mddev *mddev) in setup_conf() argument
6867 if (mddev->new_level != 5 in setup_conf()
6868 && mddev->new_level != 4 in setup_conf()
6869 && mddev->new_level != 6) { in setup_conf()
6871 mdname(mddev), mddev->new_level); in setup_conf()
6874 if ((mddev->new_level == 5 in setup_conf()
6875 && !algorithm_valid_raid5(mddev->new_layout)) || in setup_conf()
6876 (mddev->new_level == 6 in setup_conf()
6877 && !algorithm_valid_raid6(mddev->new_layout))) { in setup_conf()
6879 mdname(mddev), mddev->new_layout); in setup_conf()
6882 if (mddev->new_level == 6 && mddev->raid_disks < 4) { in setup_conf()
6884 mdname(mddev), mddev->raid_disks); in setup_conf()
6888 if (!mddev->new_chunk_sectors || in setup_conf()
6889 (mddev->new_chunk_sectors << 9) % PAGE_SIZE || in setup_conf()
6890 !is_power_of_2(mddev->new_chunk_sectors)) { in setup_conf()
6892 mdname(mddev), mddev->new_chunk_sectors << 9); in setup_conf()
6933 rdev_for_each(rdev, mddev) { in setup_conf()
6943 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
6945 conf->raid_disks = mddev->raid_disks; in setup_conf()
6946 if (mddev->reshape_position == MaxSector) in setup_conf()
6947 conf->previous_raid_disks = mddev->raid_disks; in setup_conf()
6949 conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; in setup_conf()
6967 conf->mddev = mddev; in setup_conf()
6994 conf->level = mddev->new_level; in setup_conf()
6995 conf->chunk_sectors = mddev->new_chunk_sectors; in setup_conf()
6999 pr_debug("raid456: run(%s) called.\n", mdname(mddev)); in setup_conf()
7001 rdev_for_each(rdev, mddev) { in setup_conf()
7021 mdname(mddev), bdevname(rdev->bdev, b), raid_disk); in setup_conf()
7027 conf->level = mddev->new_level; in setup_conf()
7038 conf->algorithm = mddev->new_layout; in setup_conf()
7039 conf->reshape_progress = mddev->reshape_position; in setup_conf()
7041 conf->prev_chunk_sectors = mddev->chunk_sectors; in setup_conf()
7042 conf->prev_algo = mddev->layout; in setup_conf()
7049 if (mddev->reshape_position != MaxSector) { in setup_conf()
7051 ((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4, in setup_conf()
7052 ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4); in setup_conf()
7056 mdname(mddev), conf->min_nr_stripes); in setup_conf()
7063 mdname(mddev), memory); in setup_conf()
7066 pr_debug("md/raid:%s: allocated %dkB\n", mdname(mddev), memory); in setup_conf()
7079 mdname(mddev)); in setup_conf()
7083 sprintf(pers_name, "raid%d", mddev->new_level); in setup_conf()
7084 conf->thread = md_register_thread(raid5d, mddev, pers_name); in setup_conf()
7087 mdname(mddev)); in setup_conf()
7127 static int raid5_run(struct mddev *mddev) in raid5_run() argument
7139 if (mddev_init_writes_pending(mddev) < 0) in raid5_run()
7142 if (mddev->recovery_cp != MaxSector) in raid5_run()
7144 mdname(mddev)); in raid5_run()
7146 rdev_for_each(rdev, mddev) { in raid5_run()
7159 } else if (mddev->reshape_backwards && in raid5_run()
7162 else if (!mddev->reshape_backwards && in raid5_run()
7167 if ((test_bit(MD_HAS_JOURNAL, &mddev->flags) || journal_dev) && in raid5_run()
7168 (mddev->bitmap_info.offset || mddev->bitmap_info.file)) { in raid5_run()
7170 mdname(mddev)); in raid5_run()
7174 if (mddev->reshape_position != MaxSector) { in raid5_run()
7189 int max_degraded = (mddev->level == 6 ? 2 : 1); in raid5_run()
7195 mdname(mddev)); in raid5_run()
7199 if (mddev->new_level != mddev->level) { in raid5_run()
7201 mdname(mddev)); in raid5_run()
7204 old_disks = mddev->raid_disks - mddev->delta_disks; in raid5_run()
7212 here_new = mddev->reshape_position; in raid5_run()
7213 chunk_sectors = max(mddev->chunk_sectors, mddev->new_chunk_sectors); in raid5_run()
7214 new_data_disks = mddev->raid_disks - max_degraded; in raid5_run()
7217 mdname(mddev)); in raid5_run()
7222 here_old = mddev->reshape_position; in raid5_run()
7226 if (mddev->delta_disks == 0) { in raid5_run()
7234 if (abs(min_offset_diff) >= mddev->chunk_sectors && in raid5_run()
7235 abs(min_offset_diff) >= mddev->new_chunk_sectors) in raid5_run()
7237 else if (mddev->ro == 0) { in raid5_run()
7239 mdname(mddev)); in raid5_run()
7242 } else if (mddev->reshape_backwards in raid5_run()
7249 mdname(mddev)); in raid5_run()
7252 pr_debug("md/raid:%s: reshape will continue\n", mdname(mddev)); in raid5_run()
7255 BUG_ON(mddev->level != mddev->new_level); in raid5_run()
7256 BUG_ON(mddev->layout != mddev->new_layout); in raid5_run()
7257 BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); in raid5_run()
7258 BUG_ON(mddev->delta_disks != 0); in raid5_run()
7261 if (test_bit(MD_HAS_JOURNAL, &mddev->flags) && in raid5_run()
7262 test_bit(MD_HAS_PPL, &mddev->flags)) { in raid5_run()
7264 mdname(mddev)); in raid5_run()
7265 clear_bit(MD_HAS_PPL, &mddev->flags); in raid5_run()
7266 clear_bit(MD_HAS_MULTIPLE_PPLS, &mddev->flags); in raid5_run()
7269 if (mddev->private == NULL) in raid5_run()
7270 conf = setup_conf(mddev); in raid5_run()
7272 conf = mddev->private; in raid5_run()
7277 if (test_bit(MD_HAS_JOURNAL, &mddev->flags)) { in raid5_run()
7280 mdname(mddev)); in raid5_run()
7281 mddev->ro = 1; in raid5_run()
7282 set_disk_ro(mddev->gendisk, 1); in raid5_run()
7283 } else if (mddev->recovery_cp == MaxSector) in raid5_run()
7284 set_bit(MD_JOURNAL_CLEAN, &mddev->flags); in raid5_run()
7288 mddev->thread = conf->thread; in raid5_run()
7290 mddev->private = conf; in raid5_run()
7323 if (mddev->major_version == 0 && in raid5_run()
7324 mddev->minor_version > 90) in raid5_run()
7346 mddev->degraded = raid5_calc_degraded(conf); in raid5_run()
7350 mdname(mddev), mddev->degraded, conf->raid_disks); in raid5_run()
7355 mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); in raid5_run()
7356 mddev->resync_max_sectors = mddev->dev_sectors; in raid5_run()
7358 if (mddev->degraded > dirty_parity_disks && in raid5_run()
7359 mddev->recovery_cp != MaxSector) { in raid5_run()
7360 if (test_bit(MD_HAS_PPL, &mddev->flags)) in raid5_run()
7362 mdname(mddev)); in raid5_run()
7363 else if (mddev->ok_start_degraded) in raid5_run()
7365 mdname(mddev)); in raid5_run()
7368 mdname(mddev)); in raid5_run()
7374 mdname(mddev), conf->level, in raid5_run()
7375 mddev->raid_disks-mddev->degraded, mddev->raid_disks, in raid5_run()
7376 mddev->new_layout); in raid5_run()
7383 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid5_run()
7384 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); in raid5_run()
7385 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); in raid5_run()
7386 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); in raid5_run()
7387 mddev->sync_thread = md_register_thread(md_do_sync, mddev, in raid5_run()
7392 if (mddev->to_remove == &raid5_attrs_group) in raid5_run()
7393 mddev->to_remove = NULL; in raid5_run()
7394 else if (mddev->kobj.sd && in raid5_run()
7395 sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) in raid5_run()
7397 mdname(mddev)); in raid5_run()
7398 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); in raid5_run()
7400 if (mddev->queue) { in raid5_run()
7408 ((mddev->chunk_sectors << 9) / PAGE_SIZE); in raid5_run()
7409 if (mddev->queue->backing_dev_info->ra_pages < 2 * stripe) in raid5_run()
7410 mddev->queue->backing_dev_info->ra_pages = 2 * stripe; in raid5_run()
7412 chunk_size = mddev->chunk_sectors << 9; in raid5_run()
7413 blk_queue_io_min(mddev->queue, chunk_size); in raid5_run()
7414 blk_queue_io_opt(mddev->queue, chunk_size * in raid5_run()
7416 mddev->queue->limits.raid_partial_stripes_expensive = 1; in raid5_run()
7426 mddev->queue->limits.discard_alignment = stripe; in raid5_run()
7427 mddev->queue->limits.discard_granularity = stripe; in raid5_run()
7429 blk_queue_max_write_same_sectors(mddev->queue, 0); in raid5_run()
7430 blk_queue_max_write_zeroes_sectors(mddev->queue, 0); in raid5_run()
7432 rdev_for_each(rdev, mddev) { in raid5_run()
7433 disk_stack_limits(mddev->gendisk, rdev->bdev, in raid5_run()
7435 disk_stack_limits(mddev->gendisk, rdev->bdev, in raid5_run()
7455 mddev->queue->limits.max_discard_sectors >= (stripe >> 9) && in raid5_run()
7456 mddev->queue->limits.discard_granularity >= stripe) in raid5_run()
7458 mddev->queue); in raid5_run()
7461 mddev->queue); in raid5_run()
7463 blk_queue_max_hw_sectors(mddev->queue, UINT_MAX); in raid5_run()
7471 md_unregister_thread(&mddev->thread); in raid5_run()
7474 mddev->private = NULL; in raid5_run()
7475 pr_warn("md/raid:%s: failed to run raid set.\n", mdname(mddev)); in raid5_run()
7479 static void raid5_free(struct mddev *mddev, void *priv) in raid5_free() argument
7484 mddev->to_remove = &raid5_attrs_group; in raid5_free()
7487 static void raid5_status(struct seq_file *seq, struct mddev *mddev) in raid5_status() argument
7489 struct r5conf *conf = mddev->private; in raid5_status()
7492 seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, in raid5_status()
7493 conf->chunk_sectors / 2, mddev->layout); in raid5_status()
7494 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); in raid5_status()
7516 conf->raid_disks - conf->mddev->degraded); in print_raid5_conf()
7528 static int raid5_spare_active(struct mddev *mddev) in raid5_spare_active() argument
7531 struct r5conf *conf = mddev->private; in raid5_spare_active()
7565 mddev->degraded = raid5_calc_degraded(conf); in raid5_spare_active()
7571 static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) in raid5_remove_disk() argument
7573 struct r5conf *conf = mddev->private; in raid5_remove_disk()
7615 mddev->recovery_disabled != conf->recovery_disabled && in raid5_remove_disk()
7656 static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) in raid5_add_disk() argument
7658 struct r5conf *conf = mddev->private; in raid5_add_disk()
7677 if (mddev->recovery_disabled == conf->recovery_disabled) in raid5_add_disk()
7728 static int raid5_resize(struct mddev *mddev, sector_t sectors) in raid5_resize() argument
7738 struct r5conf *conf = mddev->private; in raid5_resize()
7743 newsize = raid5_size(mddev, sectors, mddev->raid_disks); in raid5_resize()
7744 if (mddev->external_size && in raid5_resize()
7745 mddev->array_sectors > newsize) in raid5_resize()
7747 if (mddev->bitmap) { in raid5_resize()
7748 int ret = md_bitmap_resize(mddev->bitmap, sectors, 0, 0); in raid5_resize()
7752 md_set_array_sectors(mddev, newsize); in raid5_resize()
7753 if (sectors > mddev->dev_sectors && in raid5_resize()
7754 mddev->recovery_cp > mddev->dev_sectors) { in raid5_resize()
7755 mddev->recovery_cp = mddev->dev_sectors; in raid5_resize()
7756 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in raid5_resize()
7758 mddev->dev_sectors = sectors; in raid5_resize()
7759 mddev->resync_max_sectors = sectors; in raid5_resize()
7763 static int check_stripe_cache(struct mddev *mddev) in check_stripe_cache() argument
7773 struct r5conf *conf = mddev->private; in check_stripe_cache()
7774 if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 in check_stripe_cache()
7776 ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 in check_stripe_cache()
7779 mdname(mddev), in check_stripe_cache()
7780 ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) in check_stripe_cache()
7787 static int check_reshape(struct mddev *mddev) in check_reshape() argument
7789 struct r5conf *conf = mddev->private; in check_reshape()
7793 if (mddev->delta_disks == 0 && in check_reshape()
7794 mddev->new_layout == mddev->layout && in check_reshape()
7795 mddev->new_chunk_sectors == mddev->chunk_sectors) in check_reshape()
7799 if (mddev->delta_disks < 0 && mddev->reshape_position == MaxSector) { in check_reshape()
7806 if (mddev->level == 6) in check_reshape()
7808 if (mddev->raid_disks + mddev->delta_disks < min) in check_reshape()
7812 if (!check_stripe_cache(mddev)) in check_reshape()
7815 if (mddev->new_chunk_sectors > mddev->chunk_sectors || in check_reshape()
7816 mddev->delta_disks > 0) in check_reshape()
7819 + max(0, mddev->delta_disks), in check_reshape()
7820 max(mddev->new_chunk_sectors, in check_reshape()
7821 mddev->chunk_sectors) in check_reshape()
7825 if (conf->previous_raid_disks + mddev->delta_disks <= conf->pool_size) in check_reshape()
7828 + mddev->delta_disks)); in check_reshape()
7831 static int raid5_start_reshape(struct mddev *mddev) in raid5_start_reshape() argument
7833 struct r5conf *conf = mddev->private; in raid5_start_reshape()
7838 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) in raid5_start_reshape()
7841 if (!check_stripe_cache(mddev)) in raid5_start_reshape()
7847 rdev_for_each(rdev, mddev) { in raid5_start_reshape()
7853 if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) in raid5_start_reshape()
7863 if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) in raid5_start_reshape()
7864 < mddev->array_sectors) { in raid5_start_reshape()
7866 mdname(mddev)); in raid5_start_reshape()
7874 conf->raid_disks += mddev->delta_disks; in raid5_start_reshape()
7876 conf->chunk_sectors = mddev->new_chunk_sectors; in raid5_start_reshape()
7878 conf->algorithm = mddev->new_layout; in raid5_start_reshape()
7884 if (mddev->reshape_backwards) in raid5_start_reshape()
7885 conf->reshape_progress = raid5_size(mddev, 0, 0); in raid5_start_reshape()
7896 mddev_suspend(mddev); in raid5_start_reshape()
7897 mddev_resume(mddev); in raid5_start_reshape()
7906 if (mddev->delta_disks >= 0) { in raid5_start_reshape()
7907 rdev_for_each(rdev, mddev) in raid5_start_reshape()
7910 if (raid5_add_disk(mddev, rdev) == 0) { in raid5_start_reshape()
7917 if (sysfs_link_rdev(mddev, rdev)) in raid5_start_reshape()
7931 mddev->degraded = raid5_calc_degraded(conf); in raid5_start_reshape()
7934 mddev->raid_disks = conf->raid_disks; in raid5_start_reshape()
7935 mddev->reshape_position = conf->reshape_progress; in raid5_start_reshape()
7936 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in raid5_start_reshape()
7938 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid5_start_reshape()
7939 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); in raid5_start_reshape()
7940 clear_bit(MD_RECOVERY_DONE, &mddev->recovery); in raid5_start_reshape()
7941 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); in raid5_start_reshape()
7942 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); in raid5_start_reshape()
7943 mddev->sync_thread = md_register_thread(md_do_sync, mddev, in raid5_start_reshape()
7945 if (!mddev->sync_thread) { in raid5_start_reshape()
7946 mddev->recovery = 0; in raid5_start_reshape()
7949 mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; in raid5_start_reshape()
7950 mddev->new_chunk_sectors = in raid5_start_reshape()
7952 mddev->new_layout = conf->algorithm = conf->prev_algo; in raid5_start_reshape()
7953 rdev_for_each(rdev, mddev) in raid5_start_reshape()
7958 mddev->reshape_position = MaxSector; in raid5_start_reshape()
7964 md_wakeup_thread(mddev->sync_thread); in raid5_start_reshape()
7965 md_new_event(mddev); in raid5_start_reshape()
7975 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in end_reshape()
7980 md_finish_reshape(conf->mddev); in end_reshape()
7983 conf->mddev->reshape_position = MaxSector; in end_reshape()
7984 rdev_for_each(rdev, conf->mddev) in end_reshape()
7995 if (conf->mddev->queue) { in end_reshape()
7999 if (conf->mddev->queue->backing_dev_info->ra_pages < 2 * stripe) in end_reshape()
8000 conf->mddev->queue->backing_dev_info->ra_pages = 2 * stripe; in end_reshape()
8008 static void raid5_finish_reshape(struct mddev *mddev) in raid5_finish_reshape() argument
8010 struct r5conf *conf = mddev->private; in raid5_finish_reshape()
8012 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { in raid5_finish_reshape()
8014 if (mddev->delta_disks <= 0) { in raid5_finish_reshape()
8017 mddev->degraded = raid5_calc_degraded(conf); in raid5_finish_reshape()
8020 d < conf->raid_disks - mddev->delta_disks; in raid5_finish_reshape()
8030 mddev->layout = conf->algorithm; in raid5_finish_reshape()
8031 mddev->chunk_sectors = conf->chunk_sectors; in raid5_finish_reshape()
8032 mddev->reshape_position = MaxSector; in raid5_finish_reshape()
8033 mddev->delta_disks = 0; in raid5_finish_reshape()
8034 mddev->reshape_backwards = 0; in raid5_finish_reshape()
8038 static void raid5_quiesce(struct mddev *mddev, int quiesce) in raid5_quiesce() argument
8040 struct r5conf *conf = mddev->private; in raid5_quiesce()
8070 static void *raid45_takeover_raid0(struct mddev *mddev, int level) in raid45_takeover_raid0() argument
8072 struct r0conf *raid0_conf = mddev->private; in raid45_takeover_raid0()
8078 mdname(mddev)); in raid45_takeover_raid0()
8084 mddev->dev_sectors = sectors; in raid45_takeover_raid0()
8085 mddev->new_level = level; in raid45_takeover_raid0()
8086 mddev->new_layout = ALGORITHM_PARITY_N; in raid45_takeover_raid0()
8087 mddev->new_chunk_sectors = mddev->chunk_sectors; in raid45_takeover_raid0()
8088 mddev->raid_disks += 1; in raid45_takeover_raid0()
8089 mddev->delta_disks = 1; in raid45_takeover_raid0()
8091 mddev->recovery_cp = MaxSector; in raid45_takeover_raid0()
8093 return setup_conf(mddev); in raid45_takeover_raid0()
8096 static void *raid5_takeover_raid1(struct mddev *mddev) in raid5_takeover_raid1() argument
8101 if (mddev->raid_disks != 2 || in raid5_takeover_raid1()
8102 mddev->degraded > 1) in raid5_takeover_raid1()
8110 while (chunksect && (mddev->array_sectors & (chunksect-1))) in raid5_takeover_raid1()
8117 mddev->new_level = 5; in raid5_takeover_raid1()
8118 mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; in raid5_takeover_raid1()
8119 mddev->new_chunk_sectors = chunksect; in raid5_takeover_raid1()
8121 ret = setup_conf(mddev); in raid5_takeover_raid1()
8123 mddev_clear_unsupported_flags(mddev, in raid5_takeover_raid1()
8128 static void *raid5_takeover_raid6(struct mddev *mddev) in raid5_takeover_raid6() argument
8132 switch (mddev->layout) { in raid5_takeover_raid6()
8154 mddev->new_level = 5; in raid5_takeover_raid6()
8155 mddev->new_layout = new_layout; in raid5_takeover_raid6()
8156 mddev->delta_disks = -1; in raid5_takeover_raid6()
8157 mddev->raid_disks -= 1; in raid5_takeover_raid6()
8158 return setup_conf(mddev); in raid5_takeover_raid6()
8161 static int raid5_check_reshape(struct mddev *mddev) in raid5_check_reshape() argument
8168 struct r5conf *conf = mddev->private; in raid5_check_reshape()
8169 int new_chunk = mddev->new_chunk_sectors; in raid5_check_reshape()
8171 if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) in raid5_check_reshape()
8178 if (mddev->array_sectors & (new_chunk-1)) in raid5_check_reshape()
8185 if (mddev->raid_disks == 2) { in raid5_check_reshape()
8187 if (mddev->new_layout >= 0) { in raid5_check_reshape()
8188 conf->algorithm = mddev->new_layout; in raid5_check_reshape()
8189 mddev->layout = mddev->new_layout; in raid5_check_reshape()
8193 mddev->chunk_sectors = new_chunk; in raid5_check_reshape()
8195 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in raid5_check_reshape()
8196 md_wakeup_thread(mddev->thread); in raid5_check_reshape()
8198 return check_reshape(mddev); in raid5_check_reshape()
8201 static int raid6_check_reshape(struct mddev *mddev) in raid6_check_reshape() argument
8203 int new_chunk = mddev->new_chunk_sectors; in raid6_check_reshape()
8205 if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) in raid6_check_reshape()
8212 if (mddev->array_sectors & (new_chunk-1)) in raid6_check_reshape()
8218 return check_reshape(mddev); in raid6_check_reshape()
8221 static void *raid5_takeover(struct mddev *mddev) in raid5_takeover() argument
8229 if (mddev->level == 0) in raid5_takeover()
8230 return raid45_takeover_raid0(mddev, 5); in raid5_takeover()
8231 if (mddev->level == 1) in raid5_takeover()
8232 return raid5_takeover_raid1(mddev); in raid5_takeover()
8233 if (mddev->level == 4) { in raid5_takeover()
8234 mddev->new_layout = ALGORITHM_PARITY_N; in raid5_takeover()
8235 mddev->new_level = 5; in raid5_takeover()
8236 return setup_conf(mddev); in raid5_takeover()
8238 if (mddev->level == 6) in raid5_takeover()
8239 return raid5_takeover_raid6(mddev); in raid5_takeover()
8244 static void *raid4_takeover(struct mddev *mddev) in raid4_takeover() argument
8250 if (mddev->level == 0) in raid4_takeover()
8251 return raid45_takeover_raid0(mddev, 4); in raid4_takeover()
8252 if (mddev->level == 5 && in raid4_takeover()
8253 mddev->layout == ALGORITHM_PARITY_N) { in raid4_takeover()
8254 mddev->new_layout = 0; in raid4_takeover()
8255 mddev->new_level = 4; in raid4_takeover()
8256 return setup_conf(mddev); in raid4_takeover()
8263 static void *raid6_takeover(struct mddev *mddev) in raid6_takeover() argument
8271 if (mddev->pers != &raid5_personality) in raid6_takeover()
8273 if (mddev->degraded > 1) in raid6_takeover()
8275 if (mddev->raid_disks > 253) in raid6_takeover()
8277 if (mddev->raid_disks < 3) in raid6_takeover()
8280 switch (mddev->layout) { in raid6_takeover()
8302 mddev->new_level = 6; in raid6_takeover()
8303 mddev->new_layout = new_layout; in raid6_takeover()
8304 mddev->delta_disks = 1; in raid6_takeover()
8305 mddev->raid_disks += 1; in raid6_takeover()
8306 return setup_conf(mddev); in raid6_takeover()
8309 static int raid5_change_consistency_policy(struct mddev *mddev, const char *buf) in raid5_change_consistency_policy() argument
8314 err = mddev_lock(mddev); in raid5_change_consistency_policy()
8317 conf = mddev->private; in raid5_change_consistency_policy()
8319 mddev_unlock(mddev); in raid5_change_consistency_policy()
8336 mddev_suspend(mddev); in raid5_change_consistency_policy()
8338 mddev_resume(mddev); in raid5_change_consistency_policy()
8340 } else if (test_bit(MD_HAS_JOURNAL, &conf->mddev->flags) && in raid5_change_consistency_policy()
8345 rdev_for_each(rdev, mddev) in raid5_change_consistency_policy()
8352 mddev_suspend(mddev); in raid5_change_consistency_policy()
8353 clear_bit(MD_HAS_JOURNAL, &mddev->flags); in raid5_change_consistency_policy()
8354 mddev_resume(mddev); in raid5_change_consistency_policy()
8364 md_update_sb(mddev, 1); in raid5_change_consistency_policy()
8366 mddev_unlock(mddev); in raid5_change_consistency_policy()
8371 static int raid5_start(struct mddev *mddev) in raid5_start() argument
8373 struct r5conf *conf = mddev->private; in raid5_start()