Lines Matching refs:ms

51 	struct mirror_set *ms;  member
99 struct mirror_set *ms = context; in wakeup_mirrord() local
101 queue_work(ms->kmirrord_wq, &ms->kmirrord_work); in wakeup_mirrord()
106 struct mirror_set *ms = from_timer(ms, t, timer); in delayed_wake_fn() local
108 clear_bit(0, &ms->timer_pending); in delayed_wake_fn()
109 wakeup_mirrord(ms); in delayed_wake_fn()
112 static void delayed_wake(struct mirror_set *ms) in delayed_wake() argument
114 if (test_and_set_bit(0, &ms->timer_pending)) in delayed_wake()
117 ms->timer.expires = jiffies + HZ / 5; in delayed_wake()
118 add_timer(&ms->timer); in delayed_wake()
126 static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw) in queue_bio() argument
132 bl = (rw == WRITE) ? &ms->writes : &ms->reads; in queue_bio()
133 spin_lock_irqsave(&ms->lock, flags); in queue_bio()
136 spin_unlock_irqrestore(&ms->lock, flags); in queue_bio()
139 wakeup_mirrord(ms); in queue_bio()
144 struct mirror_set *ms = context; in dispatch_bios() local
148 queue_bio(ms, bio, WRITE); in dispatch_bios()
178 static struct mirror *get_default_mirror(struct mirror_set *ms) in get_default_mirror() argument
180 return &ms->mirror[atomic_read(&ms->default_mirror)]; in get_default_mirror()
185 struct mirror_set *ms = m->ms; in set_default_mirror() local
186 struct mirror *m0 = &(ms->mirror[0]); in set_default_mirror()
188 atomic_set(&ms->default_mirror, m - m0); in set_default_mirror()
191 static struct mirror *get_valid_mirror(struct mirror_set *ms) in get_valid_mirror() argument
195 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++) in get_valid_mirror()
218 struct mirror_set *ms = m->ms; in fail_mirror() local
221 ms->leg_failure = 1; in fail_mirror()
233 if (!errors_handled(ms)) in fail_mirror()
236 if (m != get_default_mirror(ms)) in fail_mirror()
239 if (!ms->in_sync && !keep_log(ms)) { in fail_mirror()
249 new = get_valid_mirror(ms); in fail_mirror()
256 queue_work(dm_raid1_wq, &ms->trigger_event); in fail_mirror()
261 struct mirror_set *ms = ti->private; in mirror_flush() local
271 .client = ms->io_client, in mirror_flush()
274 for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) { in mirror_flush()
281 dm_io(&io_req, ms->nr_mirrors, io, &error_bits); in mirror_flush()
283 for (i = 0; i < ms->nr_mirrors; i++) in mirror_flush()
285 fail_mirror(ms->mirror + i, in mirror_flush()
306 struct mirror_set *ms = dm_rh_region_context(reg); in recovery_complete() local
312 fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR); in recovery_complete()
322 for (m = 0; m < ms->nr_mirrors; m++) { in recovery_complete()
323 if (&ms->mirror[m] == get_default_mirror(ms)) in recovery_complete()
326 fail_mirror(ms->mirror + m, in recovery_complete()
335 static void recover(struct mirror_set *ms, struct dm_region *reg) in recover() argument
342 sector_t region_size = dm_rh_get_region_size(ms->rh); in recover()
345 m = get_default_mirror(ms); in recover()
347 from.sector = m->offset + dm_rh_region_to_sector(ms->rh, key); in recover()
348 if (key == (ms->nr_regions - 1)) { in recover()
353 from.count = ms->ti->len & (region_size - 1); in recover()
360 for (i = 0, dest = to; i < ms->nr_mirrors; i++) { in recover()
361 if (&ms->mirror[i] == get_default_mirror(ms)) in recover()
364 m = ms->mirror + i; in recover()
366 dest->sector = m->offset + dm_rh_region_to_sector(ms->rh, key); in recover()
372 if (!errors_handled(ms)) in recover()
375 dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, in recover()
379 static void reset_ms_flags(struct mirror_set *ms) in reset_ms_flags() argument
383 ms->leg_failure = 0; in reset_ms_flags()
384 for (m = 0; m < ms->nr_mirrors; m++) { in reset_ms_flags()
385 atomic_set(&(ms->mirror[m].error_count), 0); in reset_ms_flags()
386 ms->mirror[m].error_type = 0; in reset_ms_flags()
390 static void do_recovery(struct mirror_set *ms) in do_recovery() argument
393 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in do_recovery()
398 dm_rh_recovery_prepare(ms->rh); in do_recovery()
403 while ((reg = dm_rh_recovery_start(ms->rh))) in do_recovery()
404 recover(ms, reg); in do_recovery()
409 if (!ms->in_sync && in do_recovery()
410 (log->type->get_sync_count(log) == ms->nr_regions)) { in do_recovery()
412 dm_table_event(ms->ti->table); in do_recovery()
413 ms->in_sync = 1; in do_recovery()
414 reset_ms_flags(ms); in do_recovery()
423 static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector) in choose_mirror() argument
425 struct mirror *m = get_default_mirror(ms); in choose_mirror()
431 if (m-- == ms->mirror) in choose_mirror()
432 m += ms->nr_mirrors; in choose_mirror()
433 } while (m != get_default_mirror(ms)); in choose_mirror()
440 struct mirror *default_mirror = get_default_mirror(m->ms); in default_ok()
445 static int mirror_available(struct mirror_set *ms, struct bio *bio) in mirror_available() argument
447 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_available()
448 region_t region = dm_rh_bio_to_region(ms->rh, bio); in mirror_available()
451 return choose_mirror(ms, bio->bi_iter.bi_sector) ? 1 : 0; in mirror_available()
463 return m->offset + dm_target_offset(m->ms->ti, bio->bi_iter.bi_sector); in map_sector()
480 static void hold_bio(struct mirror_set *ms, struct bio *bio) in hold_bio() argument
486 spin_lock_irq(&ms->lock); in hold_bio()
488 if (atomic_read(&ms->suspend)) { in hold_bio()
489 spin_unlock_irq(&ms->lock); in hold_bio()
494 if (dm_noflush_suspending(ms->ti)) in hold_bio()
506 bio_list_add(&ms->holds, bio); in hold_bio()
507 spin_unlock_irq(&ms->lock); in hold_bio()
530 if (likely(default_ok(m)) || mirror_available(m->ms, bio)) { in read_callback()
533 queue_bio(m->ms, bio, bio_data_dir(bio)); in read_callback()
552 .client = m->ms->io_client, in read_async_bio()
560 static inline int region_in_sync(struct mirror_set *ms, region_t region, in region_in_sync() argument
563 int state = dm_rh_get_state(ms->rh, region, may_block); in region_in_sync()
567 static void do_reads(struct mirror_set *ms, struct bio_list *reads) in do_reads() argument
574 region = dm_rh_bio_to_region(ms->rh, bio); in do_reads()
575 m = get_default_mirror(ms); in do_reads()
580 if (likely(region_in_sync(ms, region, 1))) in do_reads()
581 m = choose_mirror(ms, bio->bi_iter.bi_sector); in do_reads()
608 struct mirror_set *ms; in write_callback() local
612 ms = bio_get_m(bio)->ms; in write_callback()
636 for (i = 0; i < ms->nr_mirrors; i++) in write_callback()
638 fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR); in write_callback()
645 spin_lock_irqsave(&ms->lock, flags); in write_callback()
646 if (!ms->failures.head) in write_callback()
648 bio_list_add(&ms->failures, bio); in write_callback()
649 spin_unlock_irqrestore(&ms->lock, flags); in write_callback()
651 wakeup_mirrord(ms); in write_callback()
654 static void do_write(struct mirror_set *ms, struct bio *bio) in do_write() argument
666 .client = ms->io_client, in do_write()
675 for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) in do_write()
682 bio_set_m(bio, get_default_mirror(ms)); in do_write()
684 BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL)); in do_write()
687 static void do_writes(struct mirror_set *ms, struct bio_list *writes) in do_writes() argument
693 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in do_writes()
714 region = dm_rh_bio_to_region(ms->rh, bio); in do_writes()
722 state = dm_rh_get_state(ms->rh, region, 1); in do_writes()
746 spin_lock_irq(&ms->lock); in do_writes()
747 bio_list_merge(&ms->writes, &requeue); in do_writes()
748 spin_unlock_irq(&ms->lock); in do_writes()
749 delayed_wake(ms); in do_writes()
757 dm_rh_inc_pending(ms->rh, &sync); in do_writes()
758 dm_rh_inc_pending(ms->rh, &nosync); in do_writes()
765 ms->log_failure = dm_rh_flush(ms->rh) ? 1 : ms->log_failure; in do_writes()
770 if (unlikely(ms->log_failure) && errors_handled(ms)) { in do_writes()
771 spin_lock_irq(&ms->lock); in do_writes()
772 bio_list_merge(&ms->failures, &sync); in do_writes()
773 spin_unlock_irq(&ms->lock); in do_writes()
774 wakeup_mirrord(ms); in do_writes()
777 do_write(ms, bio); in do_writes()
780 dm_rh_delay(ms->rh, bio); in do_writes()
783 if (unlikely(ms->leg_failure) && errors_handled(ms) && !keep_log(ms)) { in do_writes()
784 spin_lock_irq(&ms->lock); in do_writes()
785 bio_list_add(&ms->failures, bio); in do_writes()
786 spin_unlock_irq(&ms->lock); in do_writes()
787 wakeup_mirrord(ms); in do_writes()
789 map_bio(get_default_mirror(ms), bio); in do_writes()
795 static void do_failures(struct mirror_set *ms, struct bio_list *failures) in do_failures() argument
820 if (!ms->log_failure) { in do_failures()
821 ms->in_sync = 0; in do_failures()
822 dm_rh_mark_nosync(ms->rh, bio); in do_failures()
838 if (unlikely(!get_valid_mirror(ms) || (keep_log(ms) && ms->log_failure))) in do_failures()
840 else if (errors_handled(ms) && !keep_log(ms)) in do_failures()
841 hold_bio(ms, bio); in do_failures()
849 struct mirror_set *ms = in trigger_event() local
852 dm_table_event(ms->ti->table); in trigger_event()
862 struct mirror_set *ms = container_of(work, struct mirror_set, in do_mirror() local
867 spin_lock_irqsave(&ms->lock, flags); in do_mirror()
868 reads = ms->reads; in do_mirror()
869 writes = ms->writes; in do_mirror()
870 failures = ms->failures; in do_mirror()
871 bio_list_init(&ms->reads); in do_mirror()
872 bio_list_init(&ms->writes); in do_mirror()
873 bio_list_init(&ms->failures); in do_mirror()
874 spin_unlock_irqrestore(&ms->lock, flags); in do_mirror()
876 dm_rh_update_states(ms->rh, errors_handled(ms)); in do_mirror()
877 do_recovery(ms); in do_mirror()
878 do_reads(ms, &reads); in do_mirror()
879 do_writes(ms, &writes); in do_mirror()
880 do_failures(ms, &failures); in do_mirror()
893 struct mirror_set *ms = in alloc_context() local
894 kzalloc(struct_size(ms, mirror, nr_mirrors), GFP_KERNEL); in alloc_context()
896 if (!ms) { in alloc_context()
901 spin_lock_init(&ms->lock); in alloc_context()
902 bio_list_init(&ms->reads); in alloc_context()
903 bio_list_init(&ms->writes); in alloc_context()
904 bio_list_init(&ms->failures); in alloc_context()
905 bio_list_init(&ms->holds); in alloc_context()
907 ms->ti = ti; in alloc_context()
908 ms->nr_mirrors = nr_mirrors; in alloc_context()
909 ms->nr_regions = dm_sector_div_up(ti->len, region_size); in alloc_context()
910 ms->in_sync = 0; in alloc_context()
911 ms->log_failure = 0; in alloc_context()
912 ms->leg_failure = 0; in alloc_context()
913 atomic_set(&ms->suspend, 0); in alloc_context()
914 atomic_set(&ms->default_mirror, DEFAULT_MIRROR); in alloc_context()
916 ms->io_client = dm_io_client_create(); in alloc_context()
917 if (IS_ERR(ms->io_client)) { in alloc_context()
919 kfree(ms); in alloc_context()
923 ms->rh = dm_region_hash_create(ms, dispatch_bios, wakeup_mirrord, in alloc_context()
925 ms->ti->begin, MAX_RECOVERY, in alloc_context()
926 dl, region_size, ms->nr_regions); in alloc_context()
927 if (IS_ERR(ms->rh)) { in alloc_context()
929 dm_io_client_destroy(ms->io_client); in alloc_context()
930 kfree(ms); in alloc_context()
934 return ms; in alloc_context()
937 static void free_context(struct mirror_set *ms, struct dm_target *ti, in free_context() argument
941 dm_put_device(ti, ms->mirror[m].dev); in free_context()
943 dm_io_client_destroy(ms->io_client); in free_context()
944 dm_region_hash_destroy(ms->rh); in free_context()
945 kfree(ms); in free_context()
948 static int get_mirror(struct mirror_set *ms, struct dm_target *ti, in get_mirror() argument
962 &ms->mirror[mirror].dev); in get_mirror()
968 ms->mirror[mirror].ms = ms; in get_mirror()
969 atomic_set(&(ms->mirror[mirror].error_count), 0); in get_mirror()
970 ms->mirror[mirror].error_type = 0; in get_mirror()
971 ms->mirror[mirror].offset = offset; in get_mirror()
1014 static int parse_features(struct mirror_set *ms, unsigned int argc, char **argv, in parse_features() argument
1018 struct dm_target *ti = ms->ti; in parse_features()
1043 ms->features |= DM_RAID1_HANDLE_ERRORS; in parse_features()
1045 ms->features |= DM_RAID1_KEEP_LOG; in parse_features()
1055 if (!errors_handled(ms) && keep_log(ms)) { in parse_features()
1079 struct mirror_set *ms; in mirror_ctr() local
1105 ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl); in mirror_ctr()
1106 if (!ms) { in mirror_ctr()
1113 r = get_mirror(ms, ti, m, argv); in mirror_ctr()
1115 free_context(ms, ti, m); in mirror_ctr()
1122 ti->private = ms; in mirror_ctr()
1124 r = dm_set_target_max_io_len(ti, dm_rh_get_region_size(ms->rh)); in mirror_ctr()
1132 ms->kmirrord_wq = alloc_workqueue("kmirrord", WQ_MEM_RECLAIM, 0); in mirror_ctr()
1133 if (!ms->kmirrord_wq) { in mirror_ctr()
1138 INIT_WORK(&ms->kmirrord_work, do_mirror); in mirror_ctr()
1139 timer_setup(&ms->timer, delayed_wake_fn, 0); in mirror_ctr()
1140 ms->timer_pending = 0; in mirror_ctr()
1141 INIT_WORK(&ms->trigger_event, trigger_event); in mirror_ctr()
1143 r = parse_features(ms, argc, argv, &args_used); in mirror_ctr()
1165 ms->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle); in mirror_ctr()
1166 if (IS_ERR(ms->kcopyd_client)) { in mirror_ctr()
1167 r = PTR_ERR(ms->kcopyd_client); in mirror_ctr()
1171 wakeup_mirrord(ms); in mirror_ctr()
1175 destroy_workqueue(ms->kmirrord_wq); in mirror_ctr()
1177 free_context(ms, ti, ms->nr_mirrors); in mirror_ctr()
1183 struct mirror_set *ms = ti->private; in mirror_dtr() local
1185 del_timer_sync(&ms->timer); in mirror_dtr()
1186 flush_workqueue(ms->kmirrord_wq); in mirror_dtr()
1187 flush_work(&ms->trigger_event); in mirror_dtr()
1188 dm_kcopyd_client_destroy(ms->kcopyd_client); in mirror_dtr()
1189 destroy_workqueue(ms->kmirrord_wq); in mirror_dtr()
1190 free_context(ms, ti, ms->nr_mirrors); in mirror_dtr()
1200 struct mirror_set *ms = ti->private; in mirror_map() local
1201 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_map()
1209 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio); in mirror_map()
1210 queue_bio(ms, bio, rw); in mirror_map()
1214 r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0); in mirror_map()
1225 queue_bio(ms, bio, rw); in mirror_map()
1233 m = choose_mirror(ms, bio->bi_iter.bi_sector); in mirror_map()
1249 struct mirror_set *ms = ti->private; in mirror_end_io() local
1261 dm_rh_dec(ms->rh, bio_record->write_region); in mirror_end_io()
1293 if (default_ok(m) || mirror_available(ms, bio)) { in mirror_end_io()
1300 queue_bio(ms, bio, rw); in mirror_end_io()
1314 struct mirror_set *ms = ti->private; in mirror_presuspend() local
1315 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_presuspend()
1320 atomic_set(&ms->suspend, 1); in mirror_presuspend()
1328 spin_lock_irq(&ms->lock); in mirror_presuspend()
1329 holds = ms->holds; in mirror_presuspend()
1330 bio_list_init(&ms->holds); in mirror_presuspend()
1331 spin_unlock_irq(&ms->lock); in mirror_presuspend()
1334 hold_bio(ms, bio); in mirror_presuspend()
1340 dm_rh_stop_recovery(ms->rh); in mirror_presuspend()
1343 !dm_rh_recovery_in_flight(ms->rh)); in mirror_presuspend()
1355 flush_workqueue(ms->kmirrord_wq); in mirror_presuspend()
1360 struct mirror_set *ms = ti->private; in mirror_postsuspend() local
1361 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_postsuspend()
1370 struct mirror_set *ms = ti->private; in mirror_resume() local
1371 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_resume()
1373 atomic_set(&ms->suspend, 0); in mirror_resume()
1377 dm_rh_start_recovery(ms->rh); in mirror_resume()
1410 struct mirror_set *ms = ti->private; in mirror_status() local
1411 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_status()
1416 DMEMIT("%d ", ms->nr_mirrors); in mirror_status()
1417 for (m = 0; m < ms->nr_mirrors; m++) { in mirror_status()
1418 DMEMIT("%s ", ms->mirror[m].dev->name); in mirror_status()
1419 buffer[m] = device_status_char(&(ms->mirror[m])); in mirror_status()
1425 (unsigned long long)ms->nr_regions, buffer); in mirror_status()
1434 DMEMIT("%d", ms->nr_mirrors); in mirror_status()
1435 for (m = 0; m < ms->nr_mirrors; m++) in mirror_status()
1436 DMEMIT(" %s %llu", ms->mirror[m].dev->name, in mirror_status()
1437 (unsigned long long)ms->mirror[m].offset); in mirror_status()
1439 num_feature_args += !!errors_handled(ms); in mirror_status()
1440 num_feature_args += !!keep_log(ms); in mirror_status()
1443 if (errors_handled(ms)) in mirror_status()
1445 if (keep_log(ms)) in mirror_status()
1453 DMEMIT(",nr_mirrors=%d", ms->nr_mirrors); in mirror_status()
1454 for (m = 0; m < ms->nr_mirrors; m++) { in mirror_status()
1455 DMEMIT(",mirror_device_%d=%s", m, ms->mirror[m].dev->name); in mirror_status()
1457 m, device_status_char(&(ms->mirror[m]))); in mirror_status()
1460 DMEMIT(",handle_errors=%c", errors_handled(ms) ? 'y' : 'n'); in mirror_status()
1461 DMEMIT(",keep_log=%c", keep_log(ms) ? 'y' : 'n'); in mirror_status()
1473 struct mirror_set *ms = ti->private; in mirror_iterate_devices() local
1477 for (i = 0; !ret && i < ms->nr_mirrors; i++) in mirror_iterate_devices()
1478 ret = fn(ti, ms->mirror[i].dev, in mirror_iterate_devices()
1479 ms->mirror[i].offset, ti->len, data); in mirror_iterate_devices()