Lines Matching refs:dev_replace

76 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;  in btrfs_init_dev_replace()  local
111 dev_replace->replace_state = in btrfs_init_dev_replace()
113 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
115 dev_replace->time_started = 0; in btrfs_init_dev_replace()
116 dev_replace->time_stopped = 0; in btrfs_init_dev_replace()
117 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_init_dev_replace()
118 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_init_dev_replace()
119 dev_replace->cursor_left = 0; in btrfs_init_dev_replace()
120 dev_replace->committed_cursor_left = 0; in btrfs_init_dev_replace()
121 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_init_dev_replace()
122 dev_replace->cursor_right = 0; in btrfs_init_dev_replace()
123 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
124 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
125 dev_replace->is_valid = 0; in btrfs_init_dev_replace()
126 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
141 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
143 dev_replace->replace_state = btrfs_dev_replace_replace_state(eb, ptr); in btrfs_init_dev_replace()
144 dev_replace->time_started = btrfs_dev_replace_time_started(eb, ptr); in btrfs_init_dev_replace()
145 dev_replace->time_stopped = in btrfs_init_dev_replace()
147 atomic64_set(&dev_replace->num_write_errors, in btrfs_init_dev_replace()
149 atomic64_set(&dev_replace->num_uncorrectable_read_errors, in btrfs_init_dev_replace()
151 dev_replace->cursor_left = btrfs_dev_replace_cursor_left(eb, ptr); in btrfs_init_dev_replace()
152 dev_replace->committed_cursor_left = dev_replace->cursor_left; in btrfs_init_dev_replace()
153 dev_replace->cursor_left_last_write_of_item = dev_replace->cursor_left; in btrfs_init_dev_replace()
154 dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr); in btrfs_init_dev_replace()
155 dev_replace->is_valid = 1; in btrfs_init_dev_replace()
157 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
158 switch (dev_replace->replace_state) { in btrfs_init_dev_replace()
171 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
172 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
177 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_init_dev_replace()
179 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_init_dev_replace()
185 if (!dev_replace->srcdev && in btrfs_init_dev_replace()
194 if (!dev_replace->tgtdev && in btrfs_init_dev_replace()
203 if (dev_replace->tgtdev) { in btrfs_init_dev_replace()
204 if (dev_replace->srcdev) { in btrfs_init_dev_replace()
205 dev_replace->tgtdev->total_bytes = in btrfs_init_dev_replace()
206 dev_replace->srcdev->total_bytes; in btrfs_init_dev_replace()
207 dev_replace->tgtdev->disk_total_bytes = in btrfs_init_dev_replace()
208 dev_replace->srcdev->disk_total_bytes; in btrfs_init_dev_replace()
209 dev_replace->tgtdev->commit_total_bytes = in btrfs_init_dev_replace()
210 dev_replace->srcdev->commit_total_bytes; in btrfs_init_dev_replace()
211 dev_replace->tgtdev->bytes_used = in btrfs_init_dev_replace()
212 dev_replace->srcdev->bytes_used; in btrfs_init_dev_replace()
213 dev_replace->tgtdev->commit_bytes_used = in btrfs_init_dev_replace()
214 dev_replace->srcdev->commit_bytes_used; in btrfs_init_dev_replace()
217 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
220 dev_replace->tgtdev->io_width = fs_info->sectorsize; in btrfs_init_dev_replace()
221 dev_replace->tgtdev->io_align = fs_info->sectorsize; in btrfs_init_dev_replace()
222 dev_replace->tgtdev->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace()
223 dev_replace->tgtdev->fs_info = fs_info; in btrfs_init_dev_replace()
225 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
360 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace() local
362 down_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
363 if (!dev_replace->is_valid || in btrfs_run_dev_replace()
364 !dev_replace->item_needs_writeback) { in btrfs_run_dev_replace()
365 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
368 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
426 down_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
427 if (dev_replace->srcdev) in btrfs_run_dev_replace()
429 dev_replace->srcdev->devid); in btrfs_run_dev_replace()
433 dev_replace->cont_reading_from_srcdev_mode); in btrfs_run_dev_replace()
435 dev_replace->replace_state); in btrfs_run_dev_replace()
436 btrfs_set_dev_replace_time_started(eb, ptr, dev_replace->time_started); in btrfs_run_dev_replace()
437 btrfs_set_dev_replace_time_stopped(eb, ptr, dev_replace->time_stopped); in btrfs_run_dev_replace()
439 atomic64_read(&dev_replace->num_write_errors)); in btrfs_run_dev_replace()
441 atomic64_read(&dev_replace->num_uncorrectable_read_errors)); in btrfs_run_dev_replace()
442 dev_replace->cursor_left_last_write_of_item = in btrfs_run_dev_replace()
443 dev_replace->cursor_left; in btrfs_run_dev_replace()
445 dev_replace->cursor_left_last_write_of_item); in btrfs_run_dev_replace()
447 dev_replace->cursor_right); in btrfs_run_dev_replace()
448 dev_replace->item_needs_writeback = 0; in btrfs_run_dev_replace()
449 up_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
621 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start() local
660 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
661 switch (dev_replace->replace_state) { in btrfs_dev_replace_start()
670 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
674 dev_replace->cont_reading_from_srcdev_mode = read_src; in btrfs_dev_replace_start()
675 dev_replace->srcdev = src_device; in btrfs_dev_replace_start()
676 dev_replace->tgtdev = tgt_device; in btrfs_dev_replace_start()
688 dev_replace->replace_state = BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED; in btrfs_dev_replace_start()
689 dev_replace->time_started = ktime_get_real_seconds(); in btrfs_dev_replace_start()
690 dev_replace->cursor_left = 0; in btrfs_dev_replace_start()
691 dev_replace->committed_cursor_left = 0; in btrfs_dev_replace_start()
692 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_dev_replace_start()
693 dev_replace->cursor_right = 0; in btrfs_dev_replace_start()
694 dev_replace->is_valid = 1; in btrfs_dev_replace_start()
695 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_start()
696 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_dev_replace_start()
697 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_dev_replace_start()
698 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
715 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
716 dev_replace->replace_state = in btrfs_dev_replace_start()
718 dev_replace->srcdev = NULL; in btrfs_dev_replace_start()
719 dev_replace->tgtdev = NULL; in btrfs_dev_replace_start()
720 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
730 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_start()
779 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
780 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
789 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
852 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing() local
862 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
864 down_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
866 if (dev_replace->replace_state != in btrfs_dev_replace_finishing()
868 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
869 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
873 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_finishing()
874 src_device = dev_replace->srcdev; in btrfs_dev_replace_finishing()
875 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
883 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
896 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
915 down_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
916 dev_replace->replace_state = in btrfs_dev_replace_finishing()
919 dev_replace->tgtdev = NULL; in btrfs_dev_replace_finishing()
920 dev_replace->srcdev = NULL; in btrfs_dev_replace_finishing()
921 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_finishing()
922 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_finishing()
943 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
950 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
977 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
1012 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
1026 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress() local
1029 switch (dev_replace->replace_state) { in btrfs_dev_replace_progress()
1039 ret = div64_u64(dev_replace->cursor_left, in btrfs_dev_replace_progress()
1041 dev_replace->srcdev), 1000)); in btrfs_dev_replace_progress()
1051 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status() local
1053 down_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
1057 args->status.replace_state = dev_replace->replace_state; in btrfs_dev_replace_status()
1058 args->status.time_started = dev_replace->time_started; in btrfs_dev_replace_status()
1059 args->status.time_stopped = dev_replace->time_stopped; in btrfs_dev_replace_status()
1061 atomic64_read(&dev_replace->num_write_errors); in btrfs_dev_replace_status()
1063 atomic64_read(&dev_replace->num_uncorrectable_read_errors); in btrfs_dev_replace_status()
1065 up_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
1070 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel() local
1081 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1082 down_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1083 switch (dev_replace->replace_state) { in btrfs_dev_replace_cancel()
1088 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1091 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
1092 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
1093 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1115 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
1116 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
1117 dev_replace->tgtdev = NULL; in btrfs_dev_replace_cancel()
1118 dev_replace->srcdev = NULL; in btrfs_dev_replace_cancel()
1119 dev_replace->replace_state = in btrfs_dev_replace_cancel()
1121 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_cancel()
1122 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_cancel()
1124 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1131 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1146 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1150 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1156 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount() local
1158 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
1159 down_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
1161 switch (dev_replace->replace_state) { in btrfs_dev_replace_suspend_for_unmount()
1168 dev_replace->replace_state = in btrfs_dev_replace_suspend_for_unmount()
1170 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_suspend_for_unmount()
1171 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_suspend_for_unmount()
1176 up_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
1177 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
1184 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async() local
1186 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1188 switch (dev_replace->replace_state) { in btrfs_resume_dev_replace_async()
1192 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1197 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1201 if (!dev_replace->tgtdev || !dev_replace->tgtdev->bdev) { in btrfs_resume_dev_replace_async()
1206 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1208 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1211 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1219 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1220 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1222 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1235 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread() local
1243 btrfs_dev_name(dev_replace->srcdev), in btrfs_dev_replace_kthread()
1244 dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1245 btrfs_dev_name(dev_replace->tgtdev), in btrfs_dev_replace_kthread()
1248 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1249 dev_replace->committed_cursor_left, in btrfs_dev_replace_kthread()
1250 btrfs_device_get_total_bytes(dev_replace->srcdev), in btrfs_dev_replace_kthread()
1251 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_kthread()
1259 int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace) in btrfs_dev_replace_is_ongoing() argument
1261 if (!dev_replace->is_valid) in btrfs_dev_replace_is_ongoing()
1264 switch (dev_replace->replace_state) { in btrfs_dev_replace_is_ongoing()
1288 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1289 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1295 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1301 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()