Lines Matching refs:dev_replace
78 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_init_dev_replace() local
113 dev_replace->replace_state = in btrfs_init_dev_replace()
115 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
117 dev_replace->time_started = 0; in btrfs_init_dev_replace()
118 dev_replace->time_stopped = 0; in btrfs_init_dev_replace()
119 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_init_dev_replace()
120 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_init_dev_replace()
121 dev_replace->cursor_left = 0; in btrfs_init_dev_replace()
122 dev_replace->committed_cursor_left = 0; in btrfs_init_dev_replace()
123 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_init_dev_replace()
124 dev_replace->cursor_right = 0; in btrfs_init_dev_replace()
125 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
126 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
127 dev_replace->is_valid = 0; in btrfs_init_dev_replace()
128 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
143 dev_replace->cont_reading_from_srcdev_mode = in btrfs_init_dev_replace()
145 dev_replace->replace_state = btrfs_dev_replace_replace_state(eb, ptr); in btrfs_init_dev_replace()
146 dev_replace->time_started = btrfs_dev_replace_time_started(eb, ptr); in btrfs_init_dev_replace()
147 dev_replace->time_stopped = in btrfs_init_dev_replace()
149 atomic64_set(&dev_replace->num_write_errors, in btrfs_init_dev_replace()
151 atomic64_set(&dev_replace->num_uncorrectable_read_errors, in btrfs_init_dev_replace()
153 dev_replace->cursor_left = btrfs_dev_replace_cursor_left(eb, ptr); in btrfs_init_dev_replace()
154 dev_replace->committed_cursor_left = dev_replace->cursor_left; in btrfs_init_dev_replace()
155 dev_replace->cursor_left_last_write_of_item = dev_replace->cursor_left; in btrfs_init_dev_replace()
156 dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr); in btrfs_init_dev_replace()
157 dev_replace->is_valid = 1; in btrfs_init_dev_replace()
159 dev_replace->item_needs_writeback = 0; in btrfs_init_dev_replace()
160 switch (dev_replace->replace_state) { in btrfs_init_dev_replace()
173 dev_replace->srcdev = NULL; in btrfs_init_dev_replace()
174 dev_replace->tgtdev = NULL; in btrfs_init_dev_replace()
179 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_init_dev_replace()
181 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, &args); in btrfs_init_dev_replace()
187 if (!dev_replace->srcdev && in btrfs_init_dev_replace()
196 if (!dev_replace->tgtdev && in btrfs_init_dev_replace()
205 if (dev_replace->tgtdev) { in btrfs_init_dev_replace()
206 if (dev_replace->srcdev) { in btrfs_init_dev_replace()
207 dev_replace->tgtdev->total_bytes = in btrfs_init_dev_replace()
208 dev_replace->srcdev->total_bytes; in btrfs_init_dev_replace()
209 dev_replace->tgtdev->disk_total_bytes = in btrfs_init_dev_replace()
210 dev_replace->srcdev->disk_total_bytes; in btrfs_init_dev_replace()
211 dev_replace->tgtdev->commit_total_bytes = in btrfs_init_dev_replace()
212 dev_replace->srcdev->commit_total_bytes; in btrfs_init_dev_replace()
213 dev_replace->tgtdev->bytes_used = in btrfs_init_dev_replace()
214 dev_replace->srcdev->bytes_used; in btrfs_init_dev_replace()
215 dev_replace->tgtdev->commit_bytes_used = in btrfs_init_dev_replace()
216 dev_replace->srcdev->commit_bytes_used; in btrfs_init_dev_replace()
219 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
222 dev_replace->tgtdev->io_width = fs_info->sectorsize; in btrfs_init_dev_replace()
223 dev_replace->tgtdev->io_align = fs_info->sectorsize; in btrfs_init_dev_replace()
224 dev_replace->tgtdev->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace()
225 dev_replace->tgtdev->fs_info = fs_info; in btrfs_init_dev_replace()
227 &dev_replace->tgtdev->dev_state); in btrfs_init_dev_replace()
354 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace() local
356 down_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
357 if (!dev_replace->is_valid || in btrfs_run_dev_replace()
358 !dev_replace->item_needs_writeback) { in btrfs_run_dev_replace()
359 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
362 up_read(&dev_replace->rwsem); in btrfs_run_dev_replace()
420 down_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
421 if (dev_replace->srcdev) in btrfs_run_dev_replace()
423 dev_replace->srcdev->devid); in btrfs_run_dev_replace()
427 dev_replace->cont_reading_from_srcdev_mode); in btrfs_run_dev_replace()
429 dev_replace->replace_state); in btrfs_run_dev_replace()
430 btrfs_set_dev_replace_time_started(eb, ptr, dev_replace->time_started); in btrfs_run_dev_replace()
431 btrfs_set_dev_replace_time_stopped(eb, ptr, dev_replace->time_stopped); in btrfs_run_dev_replace()
433 atomic64_read(&dev_replace->num_write_errors)); in btrfs_run_dev_replace()
435 atomic64_read(&dev_replace->num_uncorrectable_read_errors)); in btrfs_run_dev_replace()
436 dev_replace->cursor_left_last_write_of_item = in btrfs_run_dev_replace()
437 dev_replace->cursor_left; in btrfs_run_dev_replace()
439 dev_replace->cursor_left_last_write_of_item); in btrfs_run_dev_replace()
441 dev_replace->cursor_right); in btrfs_run_dev_replace()
442 dev_replace->item_needs_writeback = 0; in btrfs_run_dev_replace()
443 up_write(&dev_replace->rwsem); in btrfs_run_dev_replace()
607 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start() local
646 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
647 switch (dev_replace->replace_state) { in btrfs_dev_replace_start()
656 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
660 dev_replace->cont_reading_from_srcdev_mode = read_src; in btrfs_dev_replace_start()
661 dev_replace->srcdev = src_device; in btrfs_dev_replace_start()
662 dev_replace->tgtdev = tgt_device; in btrfs_dev_replace_start()
674 dev_replace->replace_state = BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED; in btrfs_dev_replace_start()
675 dev_replace->time_started = ktime_get_real_seconds(); in btrfs_dev_replace_start()
676 dev_replace->cursor_left = 0; in btrfs_dev_replace_start()
677 dev_replace->committed_cursor_left = 0; in btrfs_dev_replace_start()
678 dev_replace->cursor_left_last_write_of_item = 0; in btrfs_dev_replace_start()
679 dev_replace->cursor_right = 0; in btrfs_dev_replace_start()
680 dev_replace->is_valid = 1; in btrfs_dev_replace_start()
681 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_start()
682 atomic64_set(&dev_replace->num_write_errors, 0); in btrfs_dev_replace_start()
683 atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); in btrfs_dev_replace_start()
684 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
701 down_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
702 dev_replace->replace_state = in btrfs_dev_replace_start()
704 dev_replace->srcdev = NULL; in btrfs_dev_replace_start()
705 dev_replace->tgtdev = NULL; in btrfs_dev_replace_start()
706 up_write(&dev_replace->rwsem); in btrfs_dev_replace_start()
716 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_start()
781 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
782 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
791 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
854 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing() local
864 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
866 down_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
868 if (dev_replace->replace_state != in btrfs_dev_replace_finishing()
870 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
871 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
875 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_finishing()
876 src_device = dev_replace->srcdev; in btrfs_dev_replace_finishing()
877 up_read(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
885 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
898 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
917 down_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
918 dev_replace->replace_state = in btrfs_dev_replace_finishing()
921 dev_replace->tgtdev = NULL; in btrfs_dev_replace_finishing()
922 dev_replace->srcdev = NULL; in btrfs_dev_replace_finishing()
923 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_finishing()
924 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_finishing()
945 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
952 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
979 up_write(&dev_replace->rwsem); in btrfs_dev_replace_finishing()
1014 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_finishing()
1028 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress() local
1031 switch (dev_replace->replace_state) { in btrfs_dev_replace_progress()
1041 ret = div64_u64(dev_replace->cursor_left, in btrfs_dev_replace_progress()
1043 dev_replace->srcdev), 1000)); in btrfs_dev_replace_progress()
1053 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status() local
1055 down_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
1059 args->status.replace_state = dev_replace->replace_state; in btrfs_dev_replace_status()
1060 args->status.time_started = dev_replace->time_started; in btrfs_dev_replace_status()
1061 args->status.time_stopped = dev_replace->time_stopped; in btrfs_dev_replace_status()
1063 atomic64_read(&dev_replace->num_write_errors); in btrfs_dev_replace_status()
1065 atomic64_read(&dev_replace->num_uncorrectable_read_errors); in btrfs_dev_replace_status()
1067 up_read(&dev_replace->rwsem); in btrfs_dev_replace_status()
1072 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel() local
1083 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1084 down_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1085 switch (dev_replace->replace_state) { in btrfs_dev_replace_cancel()
1090 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1093 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
1094 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
1095 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1117 tgt_device = dev_replace->tgtdev; in btrfs_dev_replace_cancel()
1118 src_device = dev_replace->srcdev; in btrfs_dev_replace_cancel()
1119 dev_replace->tgtdev = NULL; in btrfs_dev_replace_cancel()
1120 dev_replace->srcdev = NULL; in btrfs_dev_replace_cancel()
1121 dev_replace->replace_state = in btrfs_dev_replace_cancel()
1123 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_cancel()
1124 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_cancel()
1126 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1133 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1148 up_write(&dev_replace->rwsem); in btrfs_dev_replace_cancel()
1152 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_cancel()
1158 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount() local
1160 mutex_lock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
1161 down_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
1163 switch (dev_replace->replace_state) { in btrfs_dev_replace_suspend_for_unmount()
1170 dev_replace->replace_state = in btrfs_dev_replace_suspend_for_unmount()
1172 dev_replace->time_stopped = ktime_get_real_seconds(); in btrfs_dev_replace_suspend_for_unmount()
1173 dev_replace->item_needs_writeback = 1; in btrfs_dev_replace_suspend_for_unmount()
1178 up_write(&dev_replace->rwsem); in btrfs_dev_replace_suspend_for_unmount()
1179 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); in btrfs_dev_replace_suspend_for_unmount()
1186 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async() local
1188 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1190 switch (dev_replace->replace_state) { in btrfs_resume_dev_replace_async()
1194 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1199 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1203 if (!dev_replace->tgtdev || !dev_replace->tgtdev->bdev) { in btrfs_resume_dev_replace_async()
1208 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1210 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1213 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1221 down_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1222 dev_replace->replace_state = in btrfs_resume_dev_replace_async()
1224 up_write(&dev_replace->rwsem); in btrfs_resume_dev_replace_async()
1237 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread() local
1245 btrfs_dev_name(dev_replace->srcdev), in btrfs_dev_replace_kthread()
1246 dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1247 btrfs_dev_name(dev_replace->tgtdev), in btrfs_dev_replace_kthread()
1250 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1251 dev_replace->committed_cursor_left, in btrfs_dev_replace_kthread()
1252 btrfs_device_get_total_bytes(dev_replace->srcdev), in btrfs_dev_replace_kthread()
1253 &dev_replace->scrub_progress, 0, 1); in btrfs_dev_replace_kthread()
1261 int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace) in btrfs_dev_replace_is_ongoing() argument
1263 if (!dev_replace->is_valid) in btrfs_dev_replace_is_ongoing()
1266 switch (dev_replace->replace_state) { in btrfs_dev_replace_is_ongoing()
1290 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1291 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1297 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1303 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()