Lines Matching refs:dev_replace
37 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_init_dev_replace() local
59 dev_replace->replace_state = in btrfs_init_dev_replace()
61 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
63 dev_replace->time_started = 0; in btrfs_init_dev_replace()
64 dev_replace->time_stopped = 0; in btrfs_init_dev_replace()
65 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_init_dev_replace()
66 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_init_dev_replace()
67 dev_replace->cursor_left = 0; in btrfs_init_dev_replace()
68 dev_replace->committed_cursor_left = 0; in btrfs_init_dev_replace()
69 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_init_dev_replace()
70 dev_replace->cursor_right = 0; in btrfs_init_dev_replace()
71 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
72 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
73 dev_replace->is_valid = 0; in btrfs_init_dev_replace()
74 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
89 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
91 dev_replace->replace_state = btrfs_dev_replace_replace_state(eb, ptr); in btrfs_init_dev_replace()
92 dev_replace->time_started = btrfs_dev_replace_time_started(eb, ptr); in btrfs_init_dev_replace()
93 dev_replace->time_stopped = in btrfs_init_dev_replace()
95 atomic64_set(&dev_replace->num_write_errors, in btrfs_init_dev_replace()
97 atomic64_set(&dev_replace->num_uncorrectable_read_errors, in btrfs_init_dev_replace()
99 dev_replace->cursor_left = btrfs_dev_replace_cursor_left(eb, ptr); in btrfs_init_dev_replace()
100 dev_replace->committed_cursor_left = dev_replace->cursor_left; in btrfs_init_dev_replace()
101 dev_replace->cursor_left_last_write_of_item = dev_replace->cursor_left; in btrfs_init_dev_replace()
102 dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr); in btrfs_init_dev_replace()
103 dev_replace->is_valid = 1; in btrfs_init_dev_replace()
105 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
106 switch (dev_replace->replace_state) { in btrfs_init_dev_replace()
110 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
111 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
115 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, in btrfs_init_dev_replace()
117 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, in btrfs_init_dev_replace()
124 if (!dev_replace->srcdev && in btrfs_init_dev_replace()
133 if (!dev_replace->tgtdev && in btrfs_init_dev_replace()
142 if (dev_replace->tgtdev) { in btrfs_init_dev_replace()
143 if (dev_replace->srcdev) { in btrfs_init_dev_replace()
144 dev_replace->tgtdev->total_bytes = in btrfs_init_dev_replace()
145 dev_replace->srcdev->total_bytes; in btrfs_init_dev_replace()
146 dev_replace->tgtdev->disk_total_bytes = in btrfs_init_dev_replace()
147 dev_replace->srcdev->disk_total_bytes; in btrfs_init_dev_replace()
148 dev_replace->tgtdev->commit_total_bytes = in btrfs_init_dev_replace()
149 dev_replace->srcdev->commit_total_bytes; in btrfs_init_dev_replace()
150 dev_replace->tgtdev->bytes_used = in btrfs_init_dev_replace()
151 dev_replace->srcdev->bytes_used; in btrfs_init_dev_replace()
152 dev_replace->tgtdev->commit_bytes_used = in btrfs_init_dev_replace()
153 dev_replace->srcdev->commit_bytes_used; in btrfs_init_dev_replace()
156 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
159 dev_replace->tgtdev->io_width = fs_info->sectorsize; in btrfs_init_dev_replace()
160 dev_replace->tgtdev->io_align = fs_info->sectorsize; in btrfs_init_dev_replace()
161 dev_replace->tgtdev->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace()
162 dev_replace->tgtdev->fs_info = fs_info; in btrfs_init_dev_replace()
164 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
287 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace() local
289 down_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
290 if (!dev_replace->is_valid || in btrfs_run_dev_replace()
291 !dev_replace->item_needs_writeback) { in btrfs_run_dev_replace()
292 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
295 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
353 down_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
354 if (dev_replace->srcdev) in btrfs_run_dev_replace()
356 dev_replace->srcdev->devid); in btrfs_run_dev_replace()
360 dev_replace->cont_reading_from_srcdev_mode); in btrfs_run_dev_replace()
362 dev_replace->replace_state); in btrfs_run_dev_replace()
363 btrfs_set_dev_replace_time_started(eb, ptr, dev_replace->time_started); in btrfs_run_dev_replace()
364 btrfs_set_dev_replace_time_stopped(eb, ptr, dev_replace->time_stopped); in btrfs_run_dev_replace()
366 atomic64_read(&dev_replace->num_write_errors)); in btrfs_run_dev_replace()
368 atomic64_read(&dev_replace->num_uncorrectable_read_errors)); in btrfs_run_dev_replace()
369 dev_replace->cursor_left_last_write_of_item = in btrfs_run_dev_replace()
370 dev_replace->cursor_left; in btrfs_run_dev_replace()
372 dev_replace->cursor_left_last_write_of_item); in btrfs_run_dev_replace()
374 dev_replace->cursor_right); in btrfs_run_dev_replace()
375 dev_replace->item_needs_writeback = 0; in btrfs_run_dev_replace()
376 up_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
400 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start() local
435 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
436 switch (dev_replace->replace_state) { in btrfs_dev_replace_start()
445 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
449 dev_replace->cont_reading_from_srcdev_mode = read_src; in btrfs_dev_replace_start()
450 dev_replace->srcdev = src_device; in btrfs_dev_replace_start()
451 dev_replace->tgtdev = tgt_device; in btrfs_dev_replace_start()
463 dev_replace->replace_state = BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED; in btrfs_dev_replace_start()
464 dev_replace->time_started = ktime_get_real_seconds(); in btrfs_dev_replace_start()
465 dev_replace->cursor_left = 0; in btrfs_dev_replace_start()
466 dev_replace->committed_cursor_left = 0; in btrfs_dev_replace_start()
467 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_dev_replace_start()
468 dev_replace->cursor_right = 0; in btrfs_dev_replace_start()
469 dev_replace->is_valid = 1; in btrfs_dev_replace_start()
470 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_start()
471 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_dev_replace_start()
472 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_dev_replace_start()
473 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
485 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
486 dev_replace->replace_state = in btrfs_dev_replace_start()
488 dev_replace->srcdev = NULL; in btrfs_dev_replace_start()
489 dev_replace->tgtdev = NULL; in btrfs_dev_replace_start()
490 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
500 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_start()
552 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
553 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
562 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
568 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing() local
577 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
579 down_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
581 if (dev_replace->replace_state != in btrfs_dev_replace_finishing()
583 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
584 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
588 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_finishing()
589 src_device = dev_replace->srcdev; in btrfs_dev_replace_finishing()
590 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
598 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
611 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
630 down_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
631 dev_replace->replace_state = in btrfs_dev_replace_finishing()
634 dev_replace->tgtdev = NULL; in btrfs_dev_replace_finishing()
635 dev_replace->srcdev = NULL; in btrfs_dev_replace_finishing()
636 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_finishing()
637 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_finishing()
651 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
658 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
685 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
717 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
755 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress() local
758 switch (dev_replace->replace_state) { in btrfs_dev_replace_progress()
768 ret = div64_u64(dev_replace->cursor_left, in btrfs_dev_replace_progress()
770 dev_replace->srcdev), 1000)); in btrfs_dev_replace_progress()
780 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status() local
782 down_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
786 args->status.replace_state = dev_replace->replace_state; in btrfs_dev_replace_status()
787 args->status.time_started = dev_replace->time_started; in btrfs_dev_replace_status()
788 args->status.time_stopped = dev_replace->time_stopped; in btrfs_dev_replace_status()
790 atomic64_read(&dev_replace->num_write_errors); in btrfs_dev_replace_status()
792 atomic64_read(&dev_replace->num_uncorrectable_read_errors); in btrfs_dev_replace_status()
794 up_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
799 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel() local
810 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
811 down_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
812 switch (dev_replace->replace_state) { in btrfs_dev_replace_cancel()
817 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
820 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
821 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
822 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
844 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
845 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
846 dev_replace->tgtdev = NULL; in btrfs_dev_replace_cancel()
847 dev_replace->srcdev = NULL; in btrfs_dev_replace_cancel()
848 dev_replace->replace_state = in btrfs_dev_replace_cancel()
850 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_cancel()
851 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_cancel()
853 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
861 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
876 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
880 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
886 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount() local
888 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
889 down_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
891 switch (dev_replace->replace_state) { in btrfs_dev_replace_suspend_for_unmount()
898 dev_replace->replace_state = in btrfs_dev_replace_suspend_for_unmount()
900 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_suspend_for_unmount()
901 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_suspend_for_unmount()
906 up_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
907 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
914 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async() local
916 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
918 switch (dev_replace->replace_state) { in btrfs_resume_dev_replace_async()
922 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
927 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
931 if (!dev_replace->tgtdev || !dev_replace->tgtdev->bdev) { in btrfs_resume_dev_replace_async()
936 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
938 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
941 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
949 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
950 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
952 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
965 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread() local
973 btrfs_dev_name(dev_replace->srcdev), in btrfs_dev_replace_kthread()
974 dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
975 btrfs_dev_name(dev_replace->tgtdev), in btrfs_dev_replace_kthread()
978 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
979 dev_replace->committed_cursor_left, in btrfs_dev_replace_kthread()
980 btrfs_device_get_total_bytes(dev_replace->srcdev), in btrfs_dev_replace_kthread()
981 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_kthread()
989 int btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace) in btrfs_dev_replace_is_ongoing() argument
991 if (!dev_replace->is_valid) in btrfs_dev_replace_is_ongoing()
994 switch (dev_replace->replace_state) { in btrfs_dev_replace_is_ongoing()
1018 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_noblocked()
1023 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1024 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1030 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1036 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()