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
254 btrfs_err(fs_info, "the filesystem is a seed filesystem!"); in btrfs_init_dev_replace_tgtdev()
259 fs_info->bdev_holder); in btrfs_init_dev_replace_tgtdev()
261 btrfs_err(fs_info, "target device %s is invalid!", device_path); in btrfs_init_dev_replace_tgtdev()
265 if (!btrfs_check_device_zone_type(fs_info, bdev)) { in btrfs_init_dev_replace_tgtdev()
266 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
274 list_for_each_entry(device, &fs_info->fs_devices->devices, dev_list) { in btrfs_init_dev_replace_tgtdev()
276 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
285 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
308 device->io_width = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
309 device->io_align = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
310 device->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
316 device->fs_info = fs_info; in btrfs_init_dev_replace_tgtdev()
323 device->fs_devices = fs_info->fs_devices; in btrfs_init_dev_replace_tgtdev()
329 mutex_lock(&fs_info->fs_devices->device_list_mutex); in btrfs_init_dev_replace_tgtdev()
330 list_add(&device->dev_list, &fs_info->fs_devices->devices); in btrfs_init_dev_replace_tgtdev()
331 fs_info->fs_devices->num_devices++; in btrfs_init_dev_replace_tgtdev()
332 fs_info->fs_devices->open_devices++; in btrfs_init_dev_replace_tgtdev()
333 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_init_dev_replace_tgtdev()
349 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_run_dev_replace() local
351 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_run_dev_replace()
356 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace()
377 btrfs_warn(fs_info, in btrfs_run_dev_replace()
398 btrfs_warn(fs_info, in btrfs_run_dev_replace()
412 btrfs_warn(fs_info, in btrfs_run_dev_replace()
463 static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info, in mark_block_group_to_copy() argument
469 struct btrfs_root *root = fs_info->dev_root; in mark_block_group_to_copy()
477 if (!btrfs_is_zoned(fs_info)) in mark_block_group_to_copy()
480 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
483 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
484 while (fs_info->running_transaction && in mark_block_group_to_copy()
485 !list_empty(&fs_info->running_transaction->dev_update_list)) { in mark_block_group_to_copy()
486 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
487 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
491 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
493 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
501 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
505 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
507 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
560 cache = btrfs_lookup_block_group(fs_info, chunk_offset); in mark_block_group_to_copy()
582 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
591 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_finish_block_group_to_copy() local
599 if (!btrfs_is_zoned(fs_info)) in btrfs_finish_block_group_to_copy()
609 em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); in btrfs_finish_block_group_to_copy()
642 static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_start() argument
646 struct btrfs_root *root = fs_info->dev_root; in btrfs_dev_replace_start()
648 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start()
653 src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, in btrfs_dev_replace_start()
658 if (btrfs_pinned_by_swapfile(fs_info, src_device)) { in btrfs_dev_replace_start()
659 btrfs_warn_in_rcu(fs_info, in btrfs_dev_replace_start()
678 ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name, in btrfs_dev_replace_start()
683 ret = mark_block_group_to_copy(fs_info, src_device); in btrfs_dev_replace_start()
705 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_start()
729 btrfs_err(fs_info, "kobj add dev failed %d", ret); in btrfs_dev_replace_start()
731 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_start()
750 ret = btrfs_scrub_dev(fs_info, src_device->devid, 0, in btrfs_dev_replace_start()
754 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_start()
765 int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_by_ioctl() argument
782 ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name, in btrfs_dev_replace_by_ioctl()
798 static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_blocked() argument
800 set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_blocked()
801 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
802 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
808 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_unblocked() argument
810 clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_unblocked()
811 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
829 lockdep_assert_held(&srcdev->fs_info->chunk_mutex); in btrfs_set_target_alloc_state()
846 struct btrfs_fs_info *fs_info, in btrfs_dev_replace_update_device_in_mapping_tree() argument
850 struct extent_map_tree *em_tree = &fs_info->mapping_tree; in btrfs_dev_replace_update_device_in_mapping_tree()
871 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_finishing() argument
874 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing()
877 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_finishing()
902 ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false); in btrfs_dev_replace_finishing()
907 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_finishing()
928 mutex_lock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
930 mutex_lock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
933 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
934 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
957 btrfs_dev_replace_update_device_in_mapping_tree(fs_info, in btrfs_dev_replace_finishing()
962 btrfs_err_in_rcu(fs_info, in btrfs_dev_replace_finishing()
969 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
970 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
972 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
975 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
981 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_finishing()
1000 list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list); in btrfs_dev_replace_finishing()
1001 fs_info->fs_devices->rw_devices++; in btrfs_dev_replace_finishing()
1004 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
1008 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
1023 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
1024 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
1030 btrfs_scratch_superblocks(fs_info, src_device->bdev, in btrfs_dev_replace_finishing()
1050 static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_progress() argument
1052 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress()
1074 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_status() argument
1077 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status()
1090 args->status.progress_1000 = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_status()
1094 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_cancel() argument
1096 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel()
1100 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_cancel()
1104 if (sb_rdonly(fs_info->sb)) in btrfs_dev_replace_cancel()
1120 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1129 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1153 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1164 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1181 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_suspend_for_unmount() argument
1183 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount()
1199 btrfs_info(fs_info, "suspending dev_replace for unmount"); in btrfs_dev_replace_suspend_for_unmount()
1208 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info) in btrfs_resume_dev_replace_async() argument
1211 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async()
1229 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1231 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1245 if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_REPLACE)) { in btrfs_resume_dev_replace_async()
1250 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1255 task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl"); in btrfs_resume_dev_replace_async()
1261 struct btrfs_fs_info *fs_info = data; in btrfs_dev_replace_kthread() local
1262 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread()
1266 progress = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_kthread()
1268 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_kthread()
1275 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1279 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_kthread()
1282 btrfs_exclop_finish(fs_info); in btrfs_dev_replace_kthread()
1313 void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_noblocked() argument
1315 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_noblocked()
1318 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount) in btrfs_bio_counter_sub() argument
1320 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1321 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1324 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_blocked() argument
1327 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1329 &fs_info->fs_state))) in btrfs_bio_counter_inc_blocked()
1332 btrfs_bio_counter_dec(fs_info); in btrfs_bio_counter_inc_blocked()
1333 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()
1335 &fs_info->fs_state)); in btrfs_bio_counter_inc_blocked()