Lines Matching refs:fs_info

69 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
73 int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace() argument
77 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_init_dev_replace()
78 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_init_dev_replace()
106 if (btrfs_find_device(fs_info->fs_devices, &args)) { in btrfs_init_dev_replace()
107 btrfs_err(fs_info, in btrfs_init_dev_replace()
137 btrfs_warn(fs_info, in btrfs_init_dev_replace()
168 if (btrfs_find_device(fs_info->fs_devices, &args)) { in btrfs_init_dev_replace()
169 btrfs_err(fs_info, 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()
188 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
190 btrfs_warn(fs_info, in btrfs_init_dev_replace()
192 btrfs_warn(fs_info, in btrfs_init_dev_replace()
197 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
199 btrfs_warn(fs_info, in btrfs_init_dev_replace()
201 btrfs_warn(fs_info, in btrfs_init_dev_replace()
221 WARN_ON(fs_info->fs_devices->rw_devices == 0); 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()
243 static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, in btrfs_init_dev_replace_tgtdev() argument
248 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_init_dev_replace_tgtdev()
256 btrfs_err(fs_info, "the filesystem is a seed filesystem!"); in btrfs_init_dev_replace_tgtdev()
261 fs_info->bdev_holder); in btrfs_init_dev_replace_tgtdev()
263 btrfs_err(fs_info, "target device %s is invalid!", device_path); in btrfs_init_dev_replace_tgtdev()
267 if (!btrfs_check_device_zone_type(fs_info, bdev)) { in btrfs_init_dev_replace_tgtdev()
268 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
278 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
287 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
306 device->io_width = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
307 device->io_align = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
308 device->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
314 device->fs_info = fs_info; in btrfs_init_dev_replace_tgtdev()
347 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_run_dev_replace() local
349 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_run_dev_replace()
354 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace()
375 btrfs_warn(fs_info, in btrfs_run_dev_replace()
396 btrfs_warn(fs_info, in btrfs_run_dev_replace()
410 btrfs_warn(fs_info, in btrfs_run_dev_replace()
453 static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info, in mark_block_group_to_copy() argument
459 struct btrfs_root *root = fs_info->dev_root; in mark_block_group_to_copy()
468 if (!btrfs_is_zoned(fs_info)) in mark_block_group_to_copy()
471 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
474 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
475 while (fs_info->running_transaction && in mark_block_group_to_copy()
476 !list_empty(&fs_info->running_transaction->dev_update_list)) { in mark_block_group_to_copy()
477 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
478 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
482 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
484 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
492 mutex_lock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
496 spin_lock(&fs_info->trans_lock); in mark_block_group_to_copy()
498 spin_unlock(&fs_info->trans_lock); in mark_block_group_to_copy()
530 cache = btrfs_lookup_block_group(fs_info, chunk_offset); in mark_block_group_to_copy()
542 mutex_unlock(&fs_info->chunk_mutex); in mark_block_group_to_copy()
551 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_finish_block_group_to_copy() local
559 if (!btrfs_is_zoned(fs_info)) in btrfs_finish_block_group_to_copy()
569 em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); in btrfs_finish_block_group_to_copy()
601 static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_start() argument
605 struct btrfs_root *root = fs_info->dev_root; in btrfs_dev_replace_start()
607 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start()
612 src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, in btrfs_dev_replace_start()
617 if (btrfs_pinned_by_swapfile(fs_info, src_device)) { in btrfs_dev_replace_start()
618 btrfs_warn_in_rcu(fs_info, in btrfs_dev_replace_start()
637 ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name, in btrfs_dev_replace_start()
642 ret = mark_block_group_to_copy(fs_info, src_device); in btrfs_dev_replace_start()
664 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_start()
688 btrfs_err(fs_info, "kobj add dev failed %d", ret); in btrfs_dev_replace_start()
690 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_start()
714 ret = btrfs_scrub_dev(fs_info, src_device->devid, 0, in btrfs_dev_replace_start()
718 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_start()
729 int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_by_ioctl() argument
746 ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name, in btrfs_dev_replace_by_ioctl()
762 static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_blocked() argument
764 set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_blocked()
765 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
766 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
772 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_unblocked() argument
774 clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_unblocked()
775 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
793 lockdep_assert_held(&srcdev->fs_info->chunk_mutex); in btrfs_set_target_alloc_state()
810 struct btrfs_fs_info *fs_info, in btrfs_dev_replace_update_device_in_mapping_tree() argument
814 struct extent_map_tree *em_tree = &fs_info->mapping_tree; in btrfs_dev_replace_update_device_in_mapping_tree()
835 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_finishing() argument
838 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing()
839 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in btrfs_dev_replace_finishing()
842 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_finishing()
867 ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false); in btrfs_dev_replace_finishing()
872 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_finishing()
891 mutex_lock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
895 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
918 btrfs_dev_replace_update_device_in_mapping_tree(fs_info, in btrfs_dev_replace_finishing()
923 btrfs_err_in_rcu(fs_info, in btrfs_dev_replace_finishing()
930 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
932 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
935 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
941 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_finishing()
964 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
968 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
983 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
990 btrfs_scratch_superblocks(fs_info, src_device->bdev, in btrfs_dev_replace_finishing()
1010 static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_progress() argument
1012 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress()
1034 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_status() argument
1037 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status()
1050 args->status.progress_1000 = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_status()
1054 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_cancel() argument
1056 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel()
1060 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_cancel()
1064 if (sb_rdonly(fs_info->sb)) in btrfs_dev_replace_cancel()
1080 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1089 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1113 btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
1123 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
1140 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_suspend_for_unmount() argument
1142 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount()
1158 btrfs_info(fs_info, "suspending dev_replace for unmount"); in btrfs_dev_replace_suspend_for_unmount()
1167 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info) in btrfs_resume_dev_replace_async() argument
1170 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async()
1188 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1190 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1204 if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_REPLACE)) { in btrfs_resume_dev_replace_async()
1209 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
1214 task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl"); in btrfs_resume_dev_replace_async()
1220 struct btrfs_fs_info *fs_info = data; in btrfs_dev_replace_kthread() local
1221 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread()
1225 progress = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_kthread()
1227 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_kthread()
1234 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
1238 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_kthread()
1241 btrfs_exclop_finish(fs_info); in btrfs_dev_replace_kthread()
1272 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount) in btrfs_bio_counter_sub() argument
1274 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1275 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1278 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_blocked() argument
1281 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1283 &fs_info->fs_state))) in btrfs_bio_counter_inc_blocked()
1286 btrfs_bio_counter_dec(fs_info); in btrfs_bio_counter_inc_blocked()
1287 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()
1289 &fs_info->fs_state)); in btrfs_bio_counter_inc_blocked()