Lines Matching refs:conf
69 static void allow_barrier(struct r10conf *conf);
70 static void lower_barrier(struct r10conf *conf);
71 static int _enough(struct r10conf *conf, int previous, int ignore);
72 static int enough(struct r10conf *conf, int ignore);
77 static void end_reshape(struct r10conf *conf);
82 #define cmd_before(conf, cmd) \ argument
84 write_sequnlock_irq(&(conf)->resync_lock); \
87 #define cmd_after(conf) write_seqlock_irq(&(conf)->resync_lock) argument
89 #define wait_event_barrier_cmd(conf, cond, cmd) \ argument
90 wait_event_cmd((conf)->wait_barrier, cond, cmd_before(conf, cmd), \
91 cmd_after(conf))
93 #define wait_event_barrier(conf, cond) \ argument
94 wait_event_barrier_cmd(conf, cond, NULL_CMD)
107 struct r10conf *conf = data; in r10bio_pool_alloc() local
108 int size = offsetof(struct r10bio, devs[conf->geo.raid_disks]); in r10bio_pool_alloc()
132 struct r10conf *conf = data; in r10buf_pool_alloc() local
139 r10_bio = r10bio_pool_alloc(gfp_flags, conf); in r10buf_pool_alloc()
143 if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery) || in r10buf_pool_alloc()
144 test_bit(MD_RECOVERY_RESHAPE, &conf->mddev->recovery)) in r10buf_pool_alloc()
145 nalloc = conf->copies; /* resync */ in r10buf_pool_alloc()
150 if (!conf->have_replacement) in r10buf_pool_alloc()
167 if (!conf->have_replacement) in r10buf_pool_alloc()
190 &conf->mddev->recovery)) { in r10buf_pool_alloc()
224 rbio_pool_free(r10_bio, conf); in r10buf_pool_alloc()
230 struct r10conf *conf = data; in r10buf_pool_free() local
235 for (j = conf->copies; j--; ) { in r10buf_pool_free()
255 rbio_pool_free(r10bio, conf); in r10buf_pool_free()
258 static void put_all_bios(struct r10conf *conf, struct r10bio *r10_bio) in put_all_bios() argument
262 for (i = 0; i < conf->geo.raid_disks; i++) { in put_all_bios()
276 struct r10conf *conf = r10_bio->mddev->private; in free_r10bio() local
278 put_all_bios(conf, r10_bio); in free_r10bio()
279 mempool_free(r10_bio, &conf->r10bio_pool); in free_r10bio()
284 struct r10conf *conf = r10_bio->mddev->private; in put_buf() local
286 mempool_free(r10_bio, &conf->r10buf_pool); in put_buf()
288 lower_barrier(conf); in put_buf()
291 static void wake_up_barrier(struct r10conf *conf) in wake_up_barrier() argument
293 if (wq_has_sleeper(&conf->wait_barrier)) in wake_up_barrier()
294 wake_up(&conf->wait_barrier); in wake_up_barrier()
301 struct r10conf *conf = mddev->private; in reschedule_retry() local
303 spin_lock_irqsave(&conf->device_lock, flags); in reschedule_retry()
304 list_add(&r10_bio->retry_list, &conf->retry_list); in reschedule_retry()
305 conf->nr_queued ++; in reschedule_retry()
306 spin_unlock_irqrestore(&conf->device_lock, flags); in reschedule_retry()
309 wake_up(&conf->wait_barrier); in reschedule_retry()
322 struct r10conf *conf = r10_bio->mddev->private; in raid_end_bio_io() local
332 allow_barrier(conf); in raid_end_bio_io()
342 struct r10conf *conf = r10_bio->mddev->private; in update_head_pos() local
344 conf->mirrors[r10_bio->devs[slot].devnum].head_position = in update_head_pos()
351 static int find_bio_disk(struct r10conf *conf, struct r10bio *r10_bio, in find_bio_disk() argument
357 for (slot = 0; slot < conf->geo.raid_disks; slot++) { in find_bio_disk()
381 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_read_request() local
407 if (!_enough(conf, test_bit(R10BIO_Previous, &r10_bio->state), in raid10_end_read_request()
413 rdev_dec_pending(rdev, conf->mddev); in raid10_end_read_request()
419 mdname(conf->mddev), in raid10_end_read_request()
458 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_write_request() local
466 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in raid10_end_write_request()
469 rdev = conf->mirrors[dev].replacement; in raid10_end_write_request()
473 rdev = conf->mirrors[dev].rdev; in raid10_end_write_request()
552 rdev_dec_pending(rdev, conf->mddev); in raid10_end_write_request()
645 static void raid10_find_phys(struct r10conf *conf, struct r10bio *r10bio) in raid10_find_phys() argument
647 struct geom *geo = &conf->geo; in raid10_find_phys()
649 if (conf->reshape_progress != MaxSector && in raid10_find_phys()
650 ((r10bio->sector >= conf->reshape_progress) != in raid10_find_phys()
651 conf->mddev->reshape_backwards)) { in raid10_find_phys()
653 geo = &conf->prev; in raid10_find_phys()
660 static sector_t raid10_find_virt(struct r10conf *conf, sector_t sector, int dev) in raid10_find_virt() argument
666 struct geom *geo = &conf->geo; in raid10_find_virt()
724 static struct md_rdev *read_balance(struct r10conf *conf, in read_balance() argument
738 struct geom *geo = &conf->geo; in read_balance()
740 raid10_find_phys(conf, r10_bio); in read_balance()
750 if (raid1_should_read_first(conf->mddev, this_sector, sectors)) in read_balance()
753 for (slot = 0; slot < conf->copies ; slot++) { in read_balance()
763 rdev = conf->mirrors[disk].replacement; in read_balance()
767 rdev = conf->mirrors[disk].rdev; in read_balance()
834 conf->mirrors[disk].head_position); in read_balance()
842 if (slot >= conf->copies) { in read_balance()
862 static void flush_pending_writes(struct r10conf *conf) in flush_pending_writes() argument
867 spin_lock_irq(&conf->device_lock); in flush_pending_writes()
869 if (conf->pending_bio_list.head) { in flush_pending_writes()
873 bio = bio_list_get(&conf->pending_bio_list); in flush_pending_writes()
874 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
888 raid1_prepare_flush_writes(conf->mddev); in flush_pending_writes()
889 wake_up(&conf->wait_barrier); in flush_pending_writes()
900 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
925 static void raise_barrier(struct r10conf *conf, int force) in raise_barrier() argument
927 write_seqlock_irq(&conf->resync_lock); in raise_barrier()
929 if (WARN_ON_ONCE(force && !conf->barrier)) in raise_barrier()
933 wait_event_barrier(conf, force || !conf->nr_waiting); in raise_barrier()
936 WRITE_ONCE(conf->barrier, conf->barrier + 1); in raise_barrier()
939 wait_event_barrier(conf, !atomic_read(&conf->nr_pending) && in raise_barrier()
940 conf->barrier < RESYNC_DEPTH); in raise_barrier()
942 write_sequnlock_irq(&conf->resync_lock); in raise_barrier()
945 static void lower_barrier(struct r10conf *conf) in lower_barrier() argument
949 write_seqlock_irqsave(&conf->resync_lock, flags); in lower_barrier()
950 WRITE_ONCE(conf->barrier, conf->barrier - 1); in lower_barrier()
951 write_sequnlock_irqrestore(&conf->resync_lock, flags); in lower_barrier()
952 wake_up(&conf->wait_barrier); in lower_barrier()
955 static bool stop_waiting_barrier(struct r10conf *conf) in stop_waiting_barrier() argument
961 if (!conf->barrier) in stop_waiting_barrier()
970 if (atomic_read(&conf->nr_pending) && bio_list && in stop_waiting_barrier()
975 thread = rcu_dereference_protected(conf->mddev->thread, true); in stop_waiting_barrier()
982 WARN_ON_ONCE(atomic_read(&conf->nr_pending) == 0); in stop_waiting_barrier()
989 static bool wait_barrier_nolock(struct r10conf *conf) in wait_barrier_nolock() argument
991 unsigned int seq = read_seqbegin(&conf->resync_lock); in wait_barrier_nolock()
993 if (READ_ONCE(conf->barrier)) in wait_barrier_nolock()
996 atomic_inc(&conf->nr_pending); in wait_barrier_nolock()
997 if (!read_seqretry(&conf->resync_lock, seq)) in wait_barrier_nolock()
1000 if (atomic_dec_and_test(&conf->nr_pending)) in wait_barrier_nolock()
1001 wake_up_barrier(conf); in wait_barrier_nolock()
1006 static bool wait_barrier(struct r10conf *conf, bool nowait) in wait_barrier() argument
1010 if (wait_barrier_nolock(conf)) in wait_barrier()
1013 write_seqlock_irq(&conf->resync_lock); in wait_barrier()
1014 if (conf->barrier) { in wait_barrier()
1019 conf->nr_waiting++; in wait_barrier()
1020 mddev_add_trace_msg(conf->mddev, "raid10 wait barrier"); in wait_barrier()
1021 wait_event_barrier(conf, stop_waiting_barrier(conf)); in wait_barrier()
1022 conf->nr_waiting--; in wait_barrier()
1024 if (!conf->nr_waiting) in wait_barrier()
1025 wake_up(&conf->wait_barrier); in wait_barrier()
1029 atomic_inc(&conf->nr_pending); in wait_barrier()
1030 write_sequnlock_irq(&conf->resync_lock); in wait_barrier()
1034 static void allow_barrier(struct r10conf *conf) in allow_barrier() argument
1036 if ((atomic_dec_and_test(&conf->nr_pending)) || in allow_barrier()
1037 (conf->array_freeze_pending)) in allow_barrier()
1038 wake_up_barrier(conf); in allow_barrier()
1041 static void freeze_array(struct r10conf *conf, int extra) in freeze_array() argument
1055 write_seqlock_irq(&conf->resync_lock); in freeze_array()
1056 conf->array_freeze_pending++; in freeze_array()
1057 WRITE_ONCE(conf->barrier, conf->barrier + 1); in freeze_array()
1058 conf->nr_waiting++; in freeze_array()
1059 wait_event_barrier_cmd(conf, atomic_read(&conf->nr_pending) == in freeze_array()
1060 conf->nr_queued + extra, flush_pending_writes(conf)); in freeze_array()
1061 conf->array_freeze_pending--; in freeze_array()
1062 write_sequnlock_irq(&conf->resync_lock); in freeze_array()
1065 static void unfreeze_array(struct r10conf *conf) in unfreeze_array() argument
1068 write_seqlock_irq(&conf->resync_lock); in unfreeze_array()
1069 WRITE_ONCE(conf->barrier, conf->barrier - 1); in unfreeze_array()
1070 conf->nr_waiting--; in unfreeze_array()
1071 wake_up(&conf->wait_barrier); in unfreeze_array()
1072 write_sequnlock_irq(&conf->resync_lock); in unfreeze_array()
1089 struct r10conf *conf = mddev->private; in raid10_unplug() local
1093 spin_lock_irq(&conf->device_lock); in raid10_unplug()
1094 bio_list_merge(&conf->pending_bio_list, &plug->pending); in raid10_unplug()
1095 spin_unlock_irq(&conf->device_lock); in raid10_unplug()
1096 wake_up_barrier(conf); in raid10_unplug()
1105 wake_up_barrier(conf); in raid10_unplug()
1123 static bool regular_request_wait(struct mddev *mddev, struct r10conf *conf, in regular_request_wait() argument
1127 if (!wait_barrier(conf, bio->bi_opf & REQ_NOWAIT)) { in regular_request_wait()
1132 bio->bi_iter.bi_sector < conf->reshape_progress && in regular_request_wait()
1133 bio->bi_iter.bi_sector + sectors > conf->reshape_progress) { in regular_request_wait()
1134 allow_barrier(conf); in regular_request_wait()
1139 mddev_add_trace_msg(conf->mddev, "raid10 wait reshape"); in regular_request_wait()
1140 wait_event(conf->wait_barrier, in regular_request_wait()
1141 conf->reshape_progress <= bio->bi_iter.bi_sector || in regular_request_wait()
1142 conf->reshape_progress >= bio->bi_iter.bi_sector + in regular_request_wait()
1144 wait_barrier(conf, false); in regular_request_wait()
1152 struct r10conf *conf = mddev->private; in raid10_read_request() local
1180 err_rdev = conf->mirrors[disk].rdev; in raid10_read_request()
1190 if (!regular_request_wait(mddev, conf, bio, r10_bio->sectors)) in raid10_read_request()
1192 rdev = read_balance(conf, r10_bio, &max_sectors); in raid10_read_request()
1209 gfp, &conf->bio_split); in raid10_read_request()
1215 allow_barrier(conf); in raid10_read_request()
1217 wait_barrier(conf, false); in raid10_read_request()
1260 struct r10conf *conf = mddev->private; in raid10_write_one_disk() local
1265 rdev = replacement ? conf->mirrors[devnum].replacement : in raid10_write_one_disk()
1266 conf->mirrors[devnum].rdev; in raid10_write_one_disk()
1279 &conf->mirrors[devnum].rdev->flags) in raid10_write_one_disk()
1280 && enough(conf, devnum)) in raid10_write_one_disk()
1289 if (!raid1_add_bio_to_plug(mddev, mbio, raid10_unplug, conf->copies)) { in raid10_write_one_disk()
1290 spin_lock_irqsave(&conf->device_lock, flags); in raid10_write_one_disk()
1291 bio_list_add(&conf->pending_bio_list, mbio); in raid10_write_one_disk()
1292 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_write_one_disk()
1299 struct r10conf *conf = mddev->private; in wait_blocked_dev() local
1305 for (i = 0; i < conf->copies; i++) { in wait_blocked_dev()
1308 rdev = conf->mirrors[i].rdev; in wait_blocked_dev()
1333 rrdev = conf->mirrors[i].replacement; in wait_blocked_dev()
1343 allow_barrier(conf); in wait_blocked_dev()
1344 mddev_add_trace_msg(conf->mddev, in wait_blocked_dev()
1348 wait_barrier(conf, false); in wait_blocked_dev()
1356 struct r10conf *conf = mddev->private; in raid10_write_request() local
1373 prepare_to_wait(&conf->wait_barrier, in raid10_write_request()
1380 finish_wait(&conf->wait_barrier, &w); in raid10_write_request()
1384 if (!regular_request_wait(mddev, conf, bio, sectors)) in raid10_write_request()
1388 ? (bio->bi_iter.bi_sector < conf->reshape_safe && in raid10_write_request()
1389 bio->bi_iter.bi_sector + sectors > conf->reshape_progress) in raid10_write_request()
1390 : (bio->bi_iter.bi_sector + sectors > conf->reshape_safe && in raid10_write_request()
1391 bio->bi_iter.bi_sector < conf->reshape_progress))) { in raid10_write_request()
1393 mddev->reshape_position = conf->reshape_progress; in raid10_write_request()
1398 allow_barrier(conf); in raid10_write_request()
1402 mddev_add_trace_msg(conf->mddev, in raid10_write_request()
1407 conf->reshape_safe = mddev->reshape_position; in raid10_write_request()
1421 raid10_find_phys(conf, r10_bio); in raid10_write_request()
1427 for (i = 0; i < conf->copies; i++) { in raid10_write_request()
1431 rdev = conf->mirrors[d].rdev; in raid10_write_request()
1432 rrdev = conf->mirrors[d].replacement; in raid10_write_request()
1506 GFP_NOIO, &conf->bio_split); in raid10_write_request()
1512 allow_barrier(conf); in raid10_write_request()
1514 wait_barrier(conf, false); in raid10_write_request()
1525 for (i = 0; i < conf->copies; i++) { in raid10_write_request()
1536 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid10_write_request()
1537 struct md_rdev *rrdev = conf->mirrors[d].replacement; in raid10_write_request()
1556 struct r10conf *conf = mddev->private; in __make_request() local
1559 r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO); in __make_request()
1569 conf->geo.raid_disks); in __make_request()
1579 struct r10conf *conf = r10bio->mddev->private; in raid_end_discard_bio() local
1584 allow_barrier(conf); in raid_end_discard_bio()
1602 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_discard_request() local
1613 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in raid10_end_discard_request()
1614 rdev = repl ? conf->mirrors[dev].replacement : in raid10_end_discard_request()
1615 conf->mirrors[dev].rdev; in raid10_end_discard_request()
1618 rdev_dec_pending(rdev, conf->mddev); in raid10_end_discard_request()
1629 struct r10conf *conf = mddev->private; in raid10_handle_discard() local
1630 struct geom *geo = &conf->geo; in raid10_handle_discard()
1655 wait_barrier(conf, false); in raid10_handle_discard()
1692 split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split); in raid10_handle_discard()
1699 allow_barrier(conf); in raid10_handle_discard()
1702 wait_barrier(conf, false); in raid10_handle_discard()
1707 split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split); in raid10_handle_discard()
1714 allow_barrier(conf); in raid10_handle_discard()
1718 wait_barrier(conf, false); in raid10_handle_discard()
1748 r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO); in raid10_handle_discard()
1778 rdev = conf->mirrors[disk].rdev; in raid10_handle_discard()
1779 rrdev = conf->mirrors[disk].replacement; in raid10_handle_discard()
1838 struct md_rdev *rdev = conf->mirrors[disk].rdev; in raid10_handle_discard()
1852 struct md_rdev *rrdev = conf->mirrors[disk].replacement; in raid10_handle_discard()
1874 wait_barrier(conf, false); in raid10_handle_discard()
1882 allow_barrier(conf); in raid10_handle_discard()
1888 struct r10conf *conf = mddev->private; in raid10_make_request() local
1889 sector_t chunk_mask = (conf->geo.chunk_mask & conf->prev.chunk_mask); in raid10_make_request()
1909 && (conf->geo.near_copies < conf->geo.raid_disks in raid10_make_request()
1910 || conf->prev.near_copies < in raid10_make_request()
1911 conf->prev.raid_disks))) in raid10_make_request()
1918 wake_up_barrier(conf); in raid10_make_request()
1924 struct r10conf *conf = mddev->private; in raid10_status() local
1929 if (conf->geo.near_copies < conf->geo.raid_disks) in raid10_status()
1931 if (conf->geo.near_copies > 1) in raid10_status()
1932 seq_printf(seq, " %d near-copies", conf->geo.near_copies); in raid10_status()
1933 if (conf->geo.far_copies > 1) { in raid10_status()
1934 if (conf->geo.far_offset) in raid10_status()
1935 seq_printf(seq, " %d offset-copies", conf->geo.far_copies); in raid10_status()
1937 seq_printf(seq, " %d far-copies", conf->geo.far_copies); in raid10_status()
1938 if (conf->geo.far_set_size != conf->geo.raid_disks) in raid10_status()
1939 seq_printf(seq, " %d devices per set", conf->geo.far_set_size); in raid10_status()
1941 seq_printf(seq, " [%d/%d] [", conf->geo.raid_disks, in raid10_status()
1942 conf->geo.raid_disks - mddev->degraded); in raid10_status()
1943 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_status()
1944 struct md_rdev *rdev = READ_ONCE(conf->mirrors[i].rdev); in raid10_status()
1956 static int _enough(struct r10conf *conf, int previous, int ignore) in _enough() argument
1962 disks = conf->prev.raid_disks; in _enough()
1963 ncopies = conf->prev.near_copies; in _enough()
1965 disks = conf->geo.raid_disks; in _enough()
1966 ncopies = conf->geo.near_copies; in _enough()
1970 int n = conf->copies; in _enough()
1976 (rdev = conf->mirrors[this].rdev) && in _enough()
1990 static int enough(struct r10conf *conf, int ignore) in enough() argument
1997 return _enough(conf, 0, ignore) && in enough()
1998 _enough(conf, 1, ignore); in enough()
2018 struct r10conf *conf = mddev->private; in raid10_error() local
2021 spin_lock_irqsave(&conf->device_lock, flags); in raid10_error()
2023 if (test_bit(In_sync, &rdev->flags) && !enough(conf, rdev->raid_disk)) { in raid10_error()
2027 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_error()
2039 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_error()
2043 mdname(mddev), conf->geo.raid_disks - mddev->degraded); in raid10_error()
2046 static void print_conf(struct r10conf *conf) in print_conf() argument
2052 if (!conf) { in print_conf()
2056 pr_debug(" --- wd:%d rd:%d\n", conf->geo.raid_disks - conf->mddev->degraded, in print_conf()
2057 conf->geo.raid_disks); in print_conf()
2059 lockdep_assert_held(&conf->mddev->reconfig_mutex); in print_conf()
2060 for (i = 0; i < conf->geo.raid_disks; i++) { in print_conf()
2061 rdev = conf->mirrors[i].rdev; in print_conf()
2070 static void close_sync(struct r10conf *conf) in close_sync() argument
2072 wait_barrier(conf, false); in close_sync()
2073 allow_barrier(conf); in close_sync()
2075 mempool_exit(&conf->r10buf_pool); in close_sync()
2081 struct r10conf *conf = mddev->private; in raid10_spare_active() local
2090 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_spare_active()
2091 tmp = conf->mirrors + i; in raid10_spare_active()
2118 spin_lock_irqsave(&conf->device_lock, flags); in raid10_spare_active()
2120 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_spare_active()
2122 print_conf(conf); in raid10_spare_active()
2128 struct r10conf *conf = mddev->private; in raid10_add_disk() local
2132 int last = conf->geo.raid_disks - 1; in raid10_add_disk()
2140 if (rdev->saved_raid_disk < 0 && !_enough(conf, 1, -1)) in raid10_add_disk()
2147 rdev->saved_raid_disk < conf->geo.raid_disks && in raid10_add_disk()
2148 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) in raid10_add_disk()
2153 p = &conf->mirrors[mirror]; in raid10_add_disk()
2171 conf->fullsync = 1; in raid10_add_disk()
2177 p = &conf->mirrors[repl_slot]; in raid10_add_disk()
2184 conf->fullsync = 1; in raid10_add_disk()
2188 print_conf(conf); in raid10_add_disk()
2194 struct r10conf *conf = mddev->private; in raid10_remove_disk() local
2200 print_conf(conf); in raid10_remove_disk()
2203 p = conf->mirrors + number; in raid10_remove_disk()
2222 number < conf->geo.raid_disks && in raid10_remove_disk()
2223 enough(conf, -1)) { in raid10_remove_disk()
2240 print_conf(conf); in raid10_remove_disk()
2246 struct r10conf *conf = r10_bio->mddev->private; in __end_sync_read() local
2255 &conf->mirrors[d].rdev->corrected_errors); in __end_sync_read()
2260 rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev); in __end_sync_read()
2273 struct r10conf *conf = r10_bio->mddev->private; in end_sync_read() local
2274 int d = find_bio_disk(conf, r10_bio, bio, NULL, NULL); in end_sync_read()
2318 struct r10conf *conf = mddev->private; in end_sync_write() local
2324 d = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in end_sync_write()
2326 rdev = conf->mirrors[d].replacement; in end_sync_write()
2328 rdev = conf->mirrors[d].rdev; in end_sync_write()
2368 struct r10conf *conf = mddev->private; in sync_request_write() local
2377 for (i=0; i<conf->copies; i++) in sync_request_write()
2381 if (i == conf->copies) in sync_request_write()
2392 for (i=0 ; i < conf->copies ; i++) { in sync_request_write()
2406 rdev = conf->mirrors[d].rdev; in sync_request_write()
2440 bio_reset(tbio, conf->mirrors[d].rdev->bdev, REQ_OP_WRITE); in sync_request_write()
2451 atomic_inc(&conf->mirrors[d].rdev->nr_pending); in sync_request_write()
2453 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(tbio)); in sync_request_write()
2455 if (test_bit(FailFast, &conf->mirrors[d].rdev->flags)) in sync_request_write()
2457 tbio->bi_iter.bi_sector += conf->mirrors[d].rdev->data_offset; in sync_request_write()
2464 for (i = 0; i < conf->copies; i++) { in sync_request_write()
2475 md_sync_acct(conf->mirrors[d].replacement->bdev, in sync_request_write()
2507 struct r10conf *conf = mddev->private; in fix_recovery_read_error() local
2525 rdev = conf->mirrors[dr].rdev; in fix_recovery_read_error()
2533 rdev = conf->mirrors[dw].rdev; in fix_recovery_read_error()
2555 if (rdev != conf->mirrors[dw].rdev) { in fix_recovery_read_error()
2557 struct md_rdev *rdev2 = conf->mirrors[dw].rdev; in fix_recovery_read_error()
2565 conf->mirrors[dw].recovery_disabled in fix_recovery_read_error()
2582 struct r10conf *conf = mddev->private; in recovery_request_write() local
2609 atomic_inc(&conf->mirrors[d].rdev->nr_pending); in recovery_request_write()
2610 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio)); in recovery_request_write()
2614 atomic_inc(&conf->mirrors[d].replacement->nr_pending); in recovery_request_write()
2615 md_sync_acct(conf->mirrors[d].replacement->bdev, in recovery_request_write()
2650 static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10bio *r10_bio) in fix_read_error() argument
2660 rdev = conf->mirrors[d].rdev; in fix_read_error()
2683 rdev = conf->mirrors[d].rdev; in fix_read_error()
2695 conf->tmppage, in fix_read_error()
2702 if (sl == conf->copies) in fix_read_error()
2712 rdev = conf->mirrors[dn].rdev; in fix_read_error()
2730 sl = conf->copies; in fix_read_error()
2733 rdev = conf->mirrors[d].rdev; in fix_read_error()
2743 s, conf->tmppage, REQ_OP_WRITE) in fix_read_error()
2762 sl = conf->copies; in fix_read_error()
2765 rdev = conf->mirrors[d].rdev; in fix_read_error()
2775 s, conf->tmppage, REQ_OP_READ)) { in fix_read_error()
2810 struct r10conf *conf = mddev->private; in narrow_write_error() local
2811 struct md_rdev *rdev = conf->mirrors[r10_bio->devs[i].devnum].rdev; in narrow_write_error()
2871 struct r10conf *conf = mddev->private; in handle_read_error() local
2889 freeze_array(conf, 1); in handle_read_error()
2890 fix_read_error(conf, mddev, r10_bio); in handle_read_error()
2891 unfreeze_array(conf); in handle_read_error()
2902 allow_barrier(conf); in handle_read_error()
2905 static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) in handle_write_completed() argument
2918 for (m = 0; m < conf->copies; m++) { in handle_write_completed()
2920 rdev = conf->mirrors[dev].rdev; in handle_write_completed()
2934 md_error(conf->mddev, rdev); in handle_write_completed()
2936 rdev = conf->mirrors[dev].replacement; in handle_write_completed()
2951 md_error(conf->mddev, rdev); in handle_write_completed()
2957 for (m = 0; m < conf->copies; m++) { in handle_write_completed()
2960 rdev = conf->mirrors[dev].rdev; in handle_write_completed()
2966 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
2970 md_error(conf->mddev, rdev); in handle_write_completed()
2974 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
2977 rdev = conf->mirrors[dev].replacement; in handle_write_completed()
2983 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
2987 spin_lock_irq(&conf->device_lock); in handle_write_completed()
2988 list_add(&r10_bio->retry_list, &conf->bio_end_io_list); in handle_write_completed()
2989 conf->nr_queued++; in handle_write_completed()
2990 spin_unlock_irq(&conf->device_lock); in handle_write_completed()
2995 wake_up(&conf->wait_barrier); in handle_write_completed()
2996 md_wakeup_thread(conf->mddev->thread); in handle_write_completed()
3011 struct r10conf *conf = mddev->private; in raid10d() local
3012 struct list_head *head = &conf->retry_list; in raid10d()
3017 if (!list_empty_careful(&conf->bio_end_io_list) && in raid10d()
3020 spin_lock_irqsave(&conf->device_lock, flags); in raid10d()
3022 while (!list_empty(&conf->bio_end_io_list)) { in raid10d()
3023 list_move(conf->bio_end_io_list.prev, &tmp); in raid10d()
3024 conf->nr_queued--; in raid10d()
3027 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3045 flush_pending_writes(conf); in raid10d()
3047 spin_lock_irqsave(&conf->device_lock, flags); in raid10d()
3049 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3054 conf->nr_queued--; in raid10d()
3055 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3058 conf = mddev->private; in raid10d()
3061 handle_write_completed(conf, r10_bio); in raid10d()
3080 static int init_resync(struct r10conf *conf) in init_resync() argument
3085 BUG_ON(mempool_initialized(&conf->r10buf_pool)); in init_resync()
3086 conf->have_replacement = 0; in init_resync()
3087 for (i = 0; i < conf->geo.raid_disks; i++) in init_resync()
3088 if (conf->mirrors[i].replacement) in init_resync()
3089 conf->have_replacement = 1; in init_resync()
3090 ret = mempool_init(&conf->r10buf_pool, buffs, in init_resync()
3091 r10buf_pool_alloc, r10buf_pool_free, conf); in init_resync()
3094 conf->next_resync = 0; in init_resync()
3098 static struct r10bio *raid10_alloc_init_r10buf(struct r10conf *conf) in raid10_alloc_init_r10buf() argument
3100 struct r10bio *r10bio = mempool_alloc(&conf->r10buf_pool, GFP_NOIO); in raid10_alloc_init_r10buf()
3106 if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery) || in raid10_alloc_init_r10buf()
3107 test_bit(MD_RECOVERY_RESHAPE, &conf->mddev->recovery)) in raid10_alloc_init_r10buf()
3108 nalloc = conf->copies; /* resync */ in raid10_alloc_init_r10buf()
3131 static void raid10_set_cluster_sync_high(struct r10conf *conf) in raid10_set_cluster_sync_high() argument
3148 chunks = conf->geo.raid_disks / conf->geo.near_copies; in raid10_set_cluster_sync_high()
3149 if (conf->geo.raid_disks % conf->geo.near_copies == 0) in raid10_set_cluster_sync_high()
3153 window_size = (chunks + extra_chunk) * conf->mddev->chunk_sectors; in raid10_set_cluster_sync_high()
3161 conf->cluster_sync_high = conf->cluster_sync_low + window_size; in raid10_set_cluster_sync_high()
3199 struct r10conf *conf = mddev->private; in raid10_sync_request() local
3208 sector_t chunk_mask = conf->geo.chunk_mask; in raid10_sync_request()
3222 conf->fullsync == 0) { in raid10_sync_request()
3227 if (!mempool_initialized(&conf->r10buf_pool)) in raid10_sync_request()
3228 if (init_resync(conf)) in raid10_sync_request()
3233 conf->cluster_sync_low = 0; in raid10_sync_request()
3234 conf->cluster_sync_high = 0; in raid10_sync_request()
3246 end_reshape(conf); in raid10_sync_request()
3247 close_sync(conf); in raid10_sync_request()
3256 else for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3258 raid10_find_virt(conf, mddev->curr_resync, i); in raid10_sync_request()
3265 if ((!mddev->bitmap || conf->fullsync) in raid10_sync_request()
3266 && conf->have_replacement in raid10_sync_request()
3271 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3273 conf->mirrors[i].replacement; in raid10_sync_request()
3279 conf->fullsync = 0; in raid10_sync_request()
3282 close_sync(conf); in raid10_sync_request()
3290 if (chunks_skipped >= conf->geo.raid_disks) { in raid10_sync_request()
3299 conf->mirrors[error_disk].recovery_disabled = in raid10_sync_request()
3317 if (conf->geo.near_copies < conf->geo.raid_disks && in raid10_sync_request()
3325 if (conf->nr_waiting) in raid10_sync_request()
3349 for (i = 0 ; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3355 struct raid10_info *mirror = &conf->mirrors[i]; in raid10_sync_request()
3373 sect = raid10_find_virt(conf, sector_nr, i); in raid10_sync_request()
3390 !conf->fullsync) { in raid10_sync_request()
3402 r10_bio = raid10_alloc_init_r10buf(conf); in raid10_sync_request()
3404 raise_barrier(conf, rb2 != NULL); in raid10_sync_request()
3414 raid10_find_phys(conf, r10_bio); in raid10_sync_request()
3419 for (j = 0; j < conf->geo.raid_disks; j++) { in raid10_sync_request()
3420 struct md_rdev *rdev = conf->mirrors[j].rdev; in raid10_sync_request()
3432 for (j=0; j<conf->copies;j++) { in raid10_sync_request()
3436 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid10_sync_request()
3472 for (k=0; k<conf->copies; k++) in raid10_sync_request()
3475 BUG_ON(k == conf->copies); in raid10_sync_request()
3515 if (j == conf->copies) { in raid10_sync_request()
3523 for (k = 0; k < conf->copies; k++) in raid10_sync_request()
3570 for (; j < conf->copies; j++) { in raid10_sync_request()
3572 if (conf->mirrors[d].rdev && in raid10_sync_request()
3574 &conf->mirrors[d].rdev->flags)) in raid10_sync_request()
3604 (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high)); in raid10_sync_request()
3609 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, in raid10_sync_request()
3617 r10_bio = raid10_alloc_init_r10buf(conf); in raid10_sync_request()
3622 raise_barrier(conf, 0); in raid10_sync_request()
3623 conf->next_resync = sector_nr; in raid10_sync_request()
3628 raid10_find_phys(conf, r10_bio); in raid10_sync_request()
3631 for (i = 0; i < conf->copies; i++) { in raid10_sync_request()
3642 rdev = conf->mirrors[d].rdev; in raid10_sync_request()
3670 rdev = conf->mirrors[d].replacement; in raid10_sync_request()
3693 for (i=0; i<conf->copies; i++) { in raid10_sync_request()
3696 rdev_dec_pending(conf->mirrors[d].rdev, in raid10_sync_request()
3701 conf->mirrors[d].replacement, in raid10_sync_request()
3737 if (conf->cluster_sync_high < sector_nr + nr_sectors) { in raid10_sync_request()
3738 conf->cluster_sync_low = mddev->curr_resync_completed; in raid10_sync_request()
3739 raid10_set_cluster_sync_high(conf); in raid10_sync_request()
3742 conf->cluster_sync_low, in raid10_sync_request()
3743 conf->cluster_sync_high); in raid10_sync_request()
3750 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3756 sect_va1 = raid10_find_virt(conf, sector_nr, i); in raid10_sync_request()
3758 if (conf->cluster_sync_high < sect_va1 + nr_sectors) { in raid10_sync_request()
3764 sect_va2 = raid10_find_virt(conf, in raid10_sync_request()
3767 if (conf->cluster_sync_low == 0 || in raid10_sync_request()
3768 conf->cluster_sync_low > sect_va2) in raid10_sync_request()
3769 conf->cluster_sync_low = sect_va2; in raid10_sync_request()
3773 raid10_set_cluster_sync_high(conf); in raid10_sync_request()
3775 conf->cluster_sync_low, in raid10_sync_request()
3776 conf->cluster_sync_high); in raid10_sync_request()
3820 struct r10conf *conf = mddev->private; in raid10_size() local
3823 raid_disks = min(conf->geo.raid_disks, in raid10_size()
3824 conf->prev.raid_disks); in raid10_size()
3826 sectors = conf->dev_sectors; in raid10_size()
3828 size = sectors >> conf->geo.chunk_shift; in raid10_size()
3829 sector_div(size, conf->geo.far_copies); in raid10_size()
3831 sector_div(size, conf->geo.near_copies); in raid10_size()
3833 return size << conf->geo.chunk_shift; in raid10_size()
3836 static void calc_sectors(struct r10conf *conf, sector_t size) in calc_sectors() argument
3843 size = size >> conf->geo.chunk_shift; in calc_sectors()
3844 sector_div(size, conf->geo.far_copies); in calc_sectors()
3845 size = size * conf->geo.raid_disks; in calc_sectors()
3846 sector_div(size, conf->geo.near_copies); in calc_sectors()
3849 size = size * conf->copies; in calc_sectors()
3854 size = DIV_ROUND_UP_SECTOR_T(size, conf->geo.raid_disks); in calc_sectors()
3856 conf->dev_sectors = size << conf->geo.chunk_shift; in calc_sectors()
3858 if (conf->geo.far_offset) in calc_sectors()
3859 conf->geo.stride = 1 << conf->geo.chunk_shift; in calc_sectors()
3861 sector_div(size, conf->geo.far_copies); in calc_sectors()
3862 conf->geo.stride = size << conf->geo.chunk_shift; in calc_sectors()
3923 static void raid10_free_conf(struct r10conf *conf) in raid10_free_conf() argument
3925 if (!conf) in raid10_free_conf()
3928 mempool_exit(&conf->r10bio_pool); in raid10_free_conf()
3929 kfree(conf->mirrors); in raid10_free_conf()
3930 kfree(conf->mirrors_old); in raid10_free_conf()
3931 kfree(conf->mirrors_new); in raid10_free_conf()
3932 safe_put_page(conf->tmppage); in raid10_free_conf()
3933 bioset_exit(&conf->bio_split); in raid10_free_conf()
3934 kfree(conf); in raid10_free_conf()
3939 struct r10conf *conf = NULL; in setup_conf() local
3959 conf = kzalloc(sizeof(struct r10conf), GFP_KERNEL); in setup_conf()
3960 if (!conf) in setup_conf()
3964 conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks), in setup_conf()
3967 if (!conf->mirrors) in setup_conf()
3970 conf->tmppage = alloc_page(GFP_KERNEL); in setup_conf()
3971 if (!conf->tmppage) in setup_conf()
3974 conf->geo = geo; in setup_conf()
3975 conf->copies = copies; in setup_conf()
3976 err = mempool_init(&conf->r10bio_pool, NR_RAID_BIOS, r10bio_pool_alloc, in setup_conf()
3977 rbio_pool_free, conf); in setup_conf()
3981 err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
3985 calc_sectors(conf, mddev->dev_sectors); in setup_conf()
3987 conf->prev = conf->geo; in setup_conf()
3988 conf->reshape_progress = MaxSector; in setup_conf()
3990 if (setup_geo(&conf->prev, mddev, geo_old) != conf->copies) { in setup_conf()
3994 conf->reshape_progress = mddev->reshape_position; in setup_conf()
3995 if (conf->prev.far_offset) in setup_conf()
3996 conf->prev.stride = 1 << conf->prev.chunk_shift; in setup_conf()
3999 conf->prev.stride = conf->dev_sectors; in setup_conf()
4001 conf->reshape_safe = conf->reshape_progress; in setup_conf()
4002 spin_lock_init(&conf->device_lock); in setup_conf()
4003 INIT_LIST_HEAD(&conf->retry_list); in setup_conf()
4004 INIT_LIST_HEAD(&conf->bio_end_io_list); in setup_conf()
4006 seqlock_init(&conf->resync_lock); in setup_conf()
4007 init_waitqueue_head(&conf->wait_barrier); in setup_conf()
4008 atomic_set(&conf->nr_pending, 0); in setup_conf()
4011 rcu_assign_pointer(conf->thread, in setup_conf()
4013 if (!conf->thread) in setup_conf()
4016 conf->mddev = mddev; in setup_conf()
4017 return conf; in setup_conf()
4020 raid10_free_conf(conf); in setup_conf()
4024 static unsigned int raid10_nr_stripes(struct r10conf *conf) in raid10_nr_stripes() argument
4026 unsigned int raid_disks = conf->geo.raid_disks; in raid10_nr_stripes()
4028 if (conf->geo.raid_disks % conf->geo.near_copies) in raid10_nr_stripes()
4030 return raid_disks / conf->geo.near_copies; in raid10_nr_stripes()
4035 struct r10conf *conf = mddev->private; in raid10_set_queue_limits() local
4042 lim.io_opt = lim.io_min * raid10_nr_stripes(conf); in raid10_set_queue_limits()
4054 struct r10conf *conf; in raid10_run() local
4064 conf = setup_conf(mddev); in raid10_run()
4065 if (IS_ERR(conf)) in raid10_run()
4066 return PTR_ERR(conf); in raid10_run()
4067 mddev->private = conf; in raid10_run()
4069 conf = mddev->private; in raid10_run()
4070 if (!conf) in raid10_run()
4073 rcu_assign_pointer(mddev->thread, conf->thread); in raid10_run()
4074 rcu_assign_pointer(conf->thread, NULL); in raid10_run()
4076 if (mddev_is_clustered(conf->mddev)) { in raid10_run()
4094 if (disk_idx >= conf->geo.raid_disks && in raid10_run()
4095 disk_idx >= conf->prev.raid_disks) in raid10_run()
4097 disk = conf->mirrors + disk_idx; in raid10_run()
4120 if (!mddev_is_dm(conf->mddev)) { in raid10_run()
4130 if (!enough(conf, -1)) { in raid10_run()
4136 if (conf->reshape_progress != MaxSector) { in raid10_run()
4138 if (conf->geo.far_copies != 1 && in raid10_run()
4139 conf->geo.far_offset == 0) in raid10_run()
4141 if (conf->prev.far_copies != 1 && in raid10_run()
4142 conf->prev.far_offset == 0) in raid10_run()
4148 i < conf->geo.raid_disks in raid10_run()
4149 || i < conf->prev.raid_disks; in raid10_run()
4152 disk = conf->mirrors + i; in raid10_run()
4167 conf->fullsync = 1; in raid10_run()
4173 conf->fullsync = 1; in raid10_run()
4183 mdname(mddev), conf->geo.raid_disks - mddev->degraded, in raid10_run()
4184 conf->geo.raid_disks); in raid10_run()
4188 mddev->dev_sectors = conf->dev_sectors; in raid10_run()
4197 if (conf->reshape_progress != MaxSector) { in raid10_run()
4200 before_length = ((1 << conf->prev.chunk_shift) * in raid10_run()
4201 conf->prev.far_copies); in raid10_run()
4202 after_length = ((1 << conf->geo.chunk_shift) * in raid10_run()
4203 conf->geo.far_copies); in raid10_run()
4210 conf->offset_diff = min_offset_diff; in raid10_run()
4222 raid10_free_conf(conf); in raid10_run()
4235 struct r10conf *conf = mddev->private; in raid10_quiesce() local
4238 raise_barrier(conf, 0); in raid10_quiesce()
4240 lower_barrier(conf); in raid10_quiesce()
4257 struct r10conf *conf = mddev->private; in raid10_resize() local
4264 if (conf->geo.far_copies > 1 && !conf->geo.far_offset) in raid10_resize()
4283 calc_sectors(conf, sectors); in raid10_resize()
4284 mddev->dev_sectors = conf->dev_sectors; in raid10_resize()
4292 struct r10conf *conf; in raid10_takeover_raid0() local
4312 conf = setup_conf(mddev); in raid10_takeover_raid0()
4313 if (!IS_ERR(conf)) { in raid10_takeover_raid0()
4321 return conf; in raid10_takeover_raid0()
4362 struct r10conf *conf = mddev->private; in raid10_check_reshape() local
4365 if (conf->geo.far_copies != 1 && !conf->geo.far_offset) in raid10_check_reshape()
4368 if (setup_geo(&geo, mddev, geo_start) != conf->copies) in raid10_check_reshape()
4379 if (!enough(conf, -1)) in raid10_check_reshape()
4382 kfree(conf->mirrors_new); in raid10_check_reshape()
4383 conf->mirrors_new = NULL; in raid10_check_reshape()
4386 conf->mirrors_new = in raid10_check_reshape()
4390 if (!conf->mirrors_new) in raid10_check_reshape()
4409 static int calc_degraded(struct r10conf *conf) in calc_degraded() argument
4416 for (i = 0; i < conf->prev.raid_disks; i++) { in calc_degraded()
4417 struct md_rdev *rdev = conf->mirrors[i].rdev; in calc_degraded()
4428 if (conf->geo.raid_disks == conf->prev.raid_disks) in calc_degraded()
4431 for (i = 0; i < conf->geo.raid_disks; i++) { in calc_degraded()
4432 struct md_rdev *rdev = conf->mirrors[i].rdev; in calc_degraded()
4442 if (conf->geo.raid_disks <= conf->prev.raid_disks) in calc_degraded()
4467 struct r10conf *conf = mddev->private; in raid10_start_reshape() local
4475 if (setup_geo(&new, mddev, geo_start) != conf->copies) in raid10_start_reshape()
4478 before_length = ((1 << conf->prev.chunk_shift) * in raid10_start_reshape()
4479 conf->prev.far_copies); in raid10_start_reshape()
4480 after_length = ((1 << conf->geo.chunk_shift) * in raid10_start_reshape()
4481 conf->geo.far_copies); in raid10_start_reshape()
4506 conf->offset_diff = min_offset_diff; in raid10_start_reshape()
4507 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4508 if (conf->mirrors_new) { in raid10_start_reshape()
4509 memcpy(conf->mirrors_new, conf->mirrors, in raid10_start_reshape()
4510 sizeof(struct raid10_info)*conf->prev.raid_disks); in raid10_start_reshape()
4512 kfree(conf->mirrors_old); in raid10_start_reshape()
4513 conf->mirrors_old = conf->mirrors; in raid10_start_reshape()
4514 conf->mirrors = conf->mirrors_new; in raid10_start_reshape()
4515 conf->mirrors_new = NULL; in raid10_start_reshape()
4517 setup_geo(&conf->geo, mddev, geo_start); in raid10_start_reshape()
4522 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4528 conf->reshape_progress = size; in raid10_start_reshape()
4530 conf->reshape_progress = 0; in raid10_start_reshape()
4531 conf->reshape_safe = conf->reshape_progress; in raid10_start_reshape()
4532 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4539 newsize = raid10_size(mddev, 0, conf->geo.raid_disks); in raid10_start_reshape()
4581 conf->prev.raid_disks) in raid10_start_reshape()
4589 } else if (rdev->raid_disk >= conf->prev.raid_disks in raid10_start_reshape()
4599 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4600 mddev->degraded = calc_degraded(conf); in raid10_start_reshape()
4601 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4602 mddev->raid_disks = conf->geo.raid_disks; in raid10_start_reshape()
4603 mddev->reshape_position = conf->reshape_progress; in raid10_start_reshape()
4611 conf->reshape_checkpoint = jiffies; in raid10_start_reshape()
4617 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4618 conf->geo = conf->prev; in raid10_start_reshape()
4619 mddev->raid_disks = conf->geo.raid_disks; in raid10_start_reshape()
4623 conf->reshape_progress = MaxSector; in raid10_start_reshape()
4624 conf->reshape_safe = MaxSector; in raid10_start_reshape()
4626 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4701 struct r10conf *conf = mddev->private; in reshape_request() local
4717 conf->reshape_progress < raid10_size(mddev, 0, 0)) { in reshape_request()
4719 - conf->reshape_progress); in reshape_request()
4721 conf->reshape_progress > 0) in reshape_request()
4722 sector_nr = conf->reshape_progress; in reshape_request()
4739 next = first_dev_address(conf->reshape_progress - 1, in reshape_request()
4740 &conf->geo); in reshape_request()
4745 safe = last_dev_address(conf->reshape_safe - 1, in reshape_request()
4746 &conf->prev); in reshape_request()
4748 if (next + conf->offset_diff < safe) in reshape_request()
4751 last = conf->reshape_progress - 1; in reshape_request()
4752 sector_nr = last & ~(sector_t)(conf->geo.chunk_mask in reshape_request()
4753 & conf->prev.chunk_mask); in reshape_request()
4760 next = last_dev_address(conf->reshape_progress, &conf->geo); in reshape_request()
4765 safe = first_dev_address(conf->reshape_safe, &conf->prev); in reshape_request()
4770 if (next > safe + conf->offset_diff) in reshape_request()
4773 sector_nr = conf->reshape_progress; in reshape_request()
4774 last = sector_nr | (conf->geo.chunk_mask in reshape_request()
4775 & conf->prev.chunk_mask); in reshape_request()
4782 time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { in reshape_request()
4784 wait_barrier(conf, false); in reshape_request()
4785 mddev->reshape_position = conf->reshape_progress; in reshape_request()
4788 - conf->reshape_progress; in reshape_request()
4790 mddev->curr_resync_completed = conf->reshape_progress; in reshape_request()
4791 conf->reshape_checkpoint = jiffies; in reshape_request()
4797 allow_barrier(conf); in reshape_request()
4800 conf->reshape_safe = mddev->reshape_position; in reshape_request()
4801 allow_barrier(conf); in reshape_request()
4804 raise_barrier(conf, 0); in reshape_request()
4807 r10_bio = raid10_alloc_init_r10buf(conf); in reshape_request()
4809 raise_barrier(conf, 1); in reshape_request()
4815 rdev = read_balance(conf, r10_bio, &max_sectors); in reshape_request()
4823 mempool_free(r10_bio, &conf->r10buf_pool); in reshape_request()
4841 if (mddev_is_clustered(mddev) && conf->cluster_sync_high <= sector_nr) { in reshape_request()
4845 conf->cluster_sync_low = sector_nr; in reshape_request()
4846 conf->cluster_sync_high = sector_nr + CLUSTER_RESYNC_WINDOW_SECTORS; in reshape_request()
4855 if (sb_reshape_pos < conf->cluster_sync_low) in reshape_request()
4856 conf->cluster_sync_low = sb_reshape_pos; in reshape_request()
4859 md_cluster_ops->resync_info_update(mddev, conf->cluster_sync_low, in reshape_request()
4860 conf->cluster_sync_high); in reshape_request()
4864 __raid10_find_phys(&conf->geo, r10_bio); in reshape_request()
4869 for (s = 0; s < conf->copies*2; s++) { in reshape_request()
4874 rdev2 = conf->mirrors[d].replacement; in reshape_request()
4877 rdev2 = conf->mirrors[d].rdev; in reshape_request()
4922 lower_barrier(conf); in reshape_request()
4928 conf->reshape_progress -= sectors_done; in reshape_request()
4930 conf->reshape_progress += sectors_done; in reshape_request()
4945 struct r10conf *conf = mddev->private; in reshape_request_write() local
4959 for (s = 0; s < conf->copies*2; s++) { in reshape_request_write()
4964 rdev = conf->mirrors[d].replacement; in reshape_request_write()
4967 rdev = conf->mirrors[d].rdev; in reshape_request_write()
4982 static void end_reshape(struct r10conf *conf) in end_reshape() argument
4984 if (test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) in end_reshape()
4987 spin_lock_irq(&conf->device_lock); in end_reshape()
4988 conf->prev = conf->geo; in end_reshape()
4989 md_finish_reshape(conf->mddev); in end_reshape()
4991 conf->reshape_progress = MaxSector; in end_reshape()
4992 conf->reshape_safe = MaxSector; in end_reshape()
4993 spin_unlock_irq(&conf->device_lock); in end_reshape()
4995 mddev_update_io_opt(conf->mddev, raid10_nr_stripes(conf)); in end_reshape()
4996 conf->fullsync = 0; in end_reshape()
5001 struct r10conf *conf = mddev->private; in raid10_update_reshape_pos() local
5007 conf->reshape_progress = mddev->reshape_position; in raid10_update_reshape_pos()
5017 struct r10conf *conf = mddev->private; in handle_reshape_read_error() local
5023 r10b = kmalloc(struct_size(r10b, devs, conf->copies), GFP_NOIO); in handle_reshape_read_error()
5033 __raid10_find_phys(&conf->prev, r10b); in handle_reshape_read_error()
5045 struct md_rdev *rdev = conf->mirrors[d].rdev; in handle_reshape_read_error()
5064 if (slot >= conf->copies) in handle_reshape_read_error()
5087 struct r10conf *conf = mddev->private; in end_reshape_write() local
5093 d = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in end_reshape_write()
5094 rdev = repl ? conf->mirrors[d].replacement : in end_reshape_write()
5095 conf->mirrors[d].rdev; in end_reshape_write()
5117 struct r10conf *conf = mddev->private; in raid10_finish_reshape() local
5130 for (d = conf->geo.raid_disks ; in raid10_finish_reshape()
5131 d < conf->geo.raid_disks - mddev->delta_disks; in raid10_finish_reshape()
5133 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid10_finish_reshape()
5136 rdev = conf->mirrors[d].replacement; in raid10_finish_reshape()
5142 mddev->chunk_sectors = 1 << conf->geo.chunk_shift; in raid10_finish_reshape()