Lines Matching refs:fs_info

67 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
71 int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace() argument
75 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_init_dev_replace()
76 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_init_dev_replace()
104 if (btrfs_find_device(fs_info->fs_devices, &args)) { in btrfs_init_dev_replace()
105 btrfs_err(fs_info, in btrfs_init_dev_replace()
135 btrfs_warn(fs_info, in btrfs_init_dev_replace()
166 if (btrfs_find_device(fs_info->fs_devices, &args)) { in btrfs_init_dev_replace()
167 btrfs_err(fs_info, 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()
186 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
188 btrfs_warn(fs_info, in btrfs_init_dev_replace()
190 btrfs_warn(fs_info, in btrfs_init_dev_replace()
195 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
197 btrfs_warn(fs_info, in btrfs_init_dev_replace()
199 btrfs_warn(fs_info, in btrfs_init_dev_replace()
219 WARN_ON(fs_info->fs_devices->rw_devices == 0); 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()
241 static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, in btrfs_init_dev_replace_tgtdev() argument
246 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_init_dev_replace_tgtdev()
255 btrfs_err(fs_info, "the filesystem is a seed filesystem!"); in btrfs_init_dev_replace_tgtdev()
260 fs_info->bdev_holder); in btrfs_init_dev_replace_tgtdev()
262 btrfs_err(fs_info, "target device %s is invalid!", device_path); in btrfs_init_dev_replace_tgtdev()
266 if (!btrfs_check_device_zone_type(fs_info, bdev)) { in btrfs_init_dev_replace_tgtdev()
267 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
277 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
286 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
312 device->io_width = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
313 device->io_align = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
314 device->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
320 device->fs_info = fs_info; in btrfs_init_dev_replace_tgtdev()
353 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_run_dev_replace() local
355 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_run_dev_replace()
360 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace()
381 btrfs_warn(fs_info, in btrfs_run_dev_replace()
402 btrfs_warn(fs_info, in btrfs_run_dev_replace()
416 btrfs_warn(fs_info, in btrfs_run_dev_replace()
467 static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info, in mark_block_group_to_copy() argument
473 struct btrfs_root *root = fs_info->dev_root; in mark_block_group_to_copy()
482 if (!btrfs_is_zoned(fs_info)) in mark_block_group_to_copy()
485 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
488 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
489 while (fs_info->running_transaction && in mark_block_group_to_copy()
490 !list_empty(&fs_info->running_transaction->dev_update_list)) { in mark_block_group_to_copy()
491 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
492 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
496 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
498 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
506 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
510 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
512 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
544 cache = btrfs_lookup_block_group(fs_info, chunk_offset); in mark_block_group_to_copy()
556 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
565 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_finish_block_group_to_copy() local
573 if (!btrfs_is_zoned(fs_info)) in btrfs_finish_block_group_to_copy()
583 em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); in btrfs_finish_block_group_to_copy()
615 static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_start() argument
619 struct btrfs_root *root = fs_info->dev_root; in btrfs_dev_replace_start()
621 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start()
626 src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, in btrfs_dev_replace_start()
631 if (btrfs_pinned_by_swapfile(fs_info, src_device)) { in btrfs_dev_replace_start()
632 btrfs_warn_in_rcu(fs_info, in btrfs_dev_replace_start()
651 ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name, in btrfs_dev_replace_start()
656 ret = mark_block_group_to_copy(fs_info, src_device); in btrfs_dev_replace_start()
678 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_start()
702 btrfs_err(fs_info, "kobj add dev failed %d", ret); in btrfs_dev_replace_start()
704 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_start()
728 ret = btrfs_scrub_dev(fs_info, src_device->devid, 0, in btrfs_dev_replace_start()
732 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_start()
743 int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_by_ioctl() argument
760 ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name, in btrfs_dev_replace_by_ioctl()
776 static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_blocked() argument
778 set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_blocked()
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()
786 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_unblocked() argument
788 clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_unblocked()
789 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
807 lockdep_assert_held(&srcdev->fs_info->chunk_mutex); in btrfs_set_target_alloc_state()
824 struct btrfs_fs_info *fs_info, in btrfs_dev_replace_update_device_in_mapping_tree() argument
828 struct extent_map_tree *em_tree = &fs_info->mapping_tree; in btrfs_dev_replace_update_device_in_mapping_tree()
849 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_finishing() argument
852 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing()
853 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_dev_replace_finishing()
856 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_finishing()
881 ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false); in btrfs_dev_replace_finishing()
886 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_finishing()
905 mutex_lock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
909 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
932 btrfs_dev_replace_update_device_in_mapping_tree(fs_info, in btrfs_dev_replace_finishing()
937 btrfs_err_in_rcu(fs_info, in btrfs_dev_replace_finishing()
944 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
946 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
949 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
955 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_finishing()
978 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
982 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
997 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
1004 btrfs_scratch_superblocks(fs_info, src_device->bdev, in btrfs_dev_replace_finishing()
1024 static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_progress() argument
1026 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress()
1048 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_status() argument
1051 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status()
1064 args->status.progress_1000 = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_status()
1068 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_cancel() argument
1070 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel()
1074 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_cancel()
1078 if (sb_rdonly(fs_info->sb)) in btrfs_dev_replace_cancel()
1094 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1103 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1127 btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1137 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1154 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_suspend_for_unmount() argument
1156 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount()
1172 btrfs_info(fs_info, "suspending dev_replace for unmount"); in btrfs_dev_replace_suspend_for_unmount()
1181 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info) in btrfs_resume_dev_replace_async() argument
1184 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async()
1202 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1204 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1218 if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_REPLACE)) { in btrfs_resume_dev_replace_async()
1223 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1228 task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl"); in btrfs_resume_dev_replace_async()
1234 struct btrfs_fs_info *fs_info = data; in btrfs_dev_replace_kthread() local
1235 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread()
1239 progress = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_kthread()
1241 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_kthread()
1248 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1252 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_kthread()
1255 btrfs_exclop_finish(fs_info); in btrfs_dev_replace_kthread()
1286 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount) in btrfs_bio_counter_sub() argument
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()
1292 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_blocked() argument
1295 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1297 &fs_info->fs_state))) in btrfs_bio_counter_inc_blocked()
1300 btrfs_bio_counter_dec(fs_info); in btrfs_bio_counter_inc_blocked()
1301 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()
1303 &fs_info->fs_state)); in btrfs_bio_counter_inc_blocked()