Lines Matching refs:fs_info

25 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
28 struct btrfs_fs_info *fs_info,
33 int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace() argument
36 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_init_dev_replace()
37 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_init_dev_replace()
83 btrfs_warn(fs_info, in btrfs_init_dev_replace()
115 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, in btrfs_init_dev_replace()
117 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, in btrfs_init_dev_replace()
125 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
127 btrfs_warn(fs_info, in btrfs_init_dev_replace()
129 btrfs_warn(fs_info, in btrfs_init_dev_replace()
134 !btrfs_test_opt(fs_info, DEGRADED)) { in btrfs_init_dev_replace()
136 btrfs_warn(fs_info, in btrfs_init_dev_replace()
138 btrfs_warn(fs_info, in btrfs_init_dev_replace()
158 WARN_ON(fs_info->fs_devices->rw_devices == 0); in btrfs_init_dev_replace()
159 dev_replace->tgtdev->io_width = fs_info->sectorsize; in btrfs_init_dev_replace()
160 dev_replace->tgtdev->io_align = fs_info->sectorsize; in btrfs_init_dev_replace()
161 dev_replace->tgtdev->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace()
162 dev_replace->tgtdev->fs_info = fs_info; in btrfs_init_dev_replace()
180 static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, in btrfs_init_dev_replace_tgtdev() argument
193 if (fs_info->fs_devices->seeding) { in btrfs_init_dev_replace_tgtdev()
194 btrfs_err(fs_info, "the filesystem is a seed filesystem!"); in btrfs_init_dev_replace_tgtdev()
199 fs_info->bdev_holder); in btrfs_init_dev_replace_tgtdev()
201 btrfs_err(fs_info, "target device %s is invalid!", device_path); in btrfs_init_dev_replace_tgtdev()
207 devices = &fs_info->fs_devices->devices; in btrfs_init_dev_replace_tgtdev()
210 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
220 btrfs_err(fs_info, in btrfs_init_dev_replace_tgtdev()
243 device->io_width = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
244 device->io_align = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
245 device->sector_size = fs_info->sectorsize; in btrfs_init_dev_replace_tgtdev()
251 device->fs_info = fs_info; in btrfs_init_dev_replace_tgtdev()
258 device->fs_devices = fs_info->fs_devices; in btrfs_init_dev_replace_tgtdev()
260 mutex_lock(&fs_info->fs_devices->device_list_mutex); in btrfs_init_dev_replace_tgtdev()
261 list_add(&device->dev_list, &fs_info->fs_devices->devices); in btrfs_init_dev_replace_tgtdev()
262 fs_info->fs_devices->num_devices++; in btrfs_init_dev_replace_tgtdev()
263 fs_info->fs_devices->open_devices++; in btrfs_init_dev_replace_tgtdev()
264 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_init_dev_replace_tgtdev()
280 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_run_dev_replace() local
282 struct btrfs_root *dev_root = fs_info->dev_root; in btrfs_run_dev_replace()
287 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_run_dev_replace()
308 btrfs_warn(fs_info, in btrfs_run_dev_replace()
329 btrfs_warn(fs_info, in btrfs_run_dev_replace()
343 btrfs_warn(fs_info, in btrfs_run_dev_replace()
394 static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_start() argument
398 struct btrfs_root *root = fs_info->dev_root; in btrfs_dev_replace_start()
400 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_start()
405 src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, in btrfs_dev_replace_start()
410 if (btrfs_pinned_by_swapfile(fs_info, src_device)) { in btrfs_dev_replace_start()
411 btrfs_warn_in_rcu(fs_info, in btrfs_dev_replace_start()
430 ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name, in btrfs_dev_replace_start()
453 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_start()
477 btrfs_err(fs_info, "kobj add dev failed %d", ret); in btrfs_dev_replace_start()
479 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_start()
498 ret = btrfs_scrub_dev(fs_info, src_device->devid, 0, in btrfs_dev_replace_start()
502 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_start()
516 int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_by_ioctl() argument
533 ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name, in btrfs_dev_replace_by_ioctl()
549 static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_blocked() argument
551 set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_blocked()
552 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum( in btrfs_rm_dev_replace_blocked()
553 &fs_info->dev_replace.bio_counter)); in btrfs_rm_dev_replace_blocked()
559 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info) in btrfs_rm_dev_replace_unblocked() argument
561 clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state); in btrfs_rm_dev_replace_unblocked()
562 wake_up(&fs_info->dev_replace.replace_wait); in btrfs_rm_dev_replace_unblocked()
565 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_finishing() argument
568 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_finishing()
571 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_finishing()
596 ret = btrfs_start_delalloc_roots(fs_info, -1); in btrfs_dev_replace_finishing()
601 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_dev_replace_finishing()
618 mutex_lock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
620 mutex_lock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
623 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
624 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
641 btrfs_dev_replace_update_device_in_mapping_tree(fs_info, in btrfs_dev_replace_finishing()
646 btrfs_err_in_rcu(fs_info, in btrfs_dev_replace_finishing()
652 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
653 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
654 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
657 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
663 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_finishing()
682 list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list); in btrfs_dev_replace_finishing()
683 fs_info->fs_devices->rw_devices++; in btrfs_dev_replace_finishing()
686 btrfs_rm_dev_replace_blocked(fs_info); in btrfs_dev_replace_finishing()
690 btrfs_rm_dev_replace_unblocked(fs_info); in btrfs_dev_replace_finishing()
705 mutex_unlock(&fs_info->chunk_mutex); in btrfs_dev_replace_finishing()
706 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in btrfs_dev_replace_finishing()
709 btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device); in btrfs_dev_replace_finishing()
723 struct btrfs_fs_info *fs_info, in btrfs_dev_replace_update_device_in_mapping_tree() argument
727 struct extent_map_tree *em_tree = &fs_info->mapping_tree; in btrfs_dev_replace_update_device_in_mapping_tree()
753 static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_progress() argument
755 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_progress()
777 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info, in btrfs_dev_replace_status() argument
780 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_status()
793 args->status.progress_1000 = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_status()
797 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_cancel() argument
799 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_cancel()
803 struct btrfs_root *root = fs_info->tree_root; in btrfs_dev_replace_cancel()
807 if (sb_rdonly(fs_info->sb)) in btrfs_dev_replace_cancel()
823 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
832 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
856 ret = btrfs_scrub_cancel(fs_info); in btrfs_dev_replace_cancel()
867 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_cancel()
884 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info) in btrfs_dev_replace_suspend_for_unmount() argument
886 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_suspend_for_unmount()
902 btrfs_info(fs_info, "suspending dev_replace for unmount"); in btrfs_dev_replace_suspend_for_unmount()
911 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info) in btrfs_resume_dev_replace_async() argument
914 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_resume_dev_replace_async()
932 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
934 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
948 if (test_and_set_bit(BTRFS_FS_EXCL_OP, &fs_info->flags)) { in btrfs_resume_dev_replace_async()
953 btrfs_info(fs_info, in btrfs_resume_dev_replace_async()
958 task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl"); in btrfs_resume_dev_replace_async()
964 struct btrfs_fs_info *fs_info = data; in btrfs_dev_replace_kthread() local
965 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; in btrfs_dev_replace_kthread()
969 progress = btrfs_dev_replace_progress(fs_info); in btrfs_dev_replace_kthread()
971 btrfs_info_in_rcu(fs_info, in btrfs_dev_replace_kthread()
978 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid, in btrfs_dev_replace_kthread()
982 ret = btrfs_dev_replace_finishing(fs_info, ret); in btrfs_dev_replace_kthread()
985 clear_bit(BTRFS_FS_EXCL_OP, &fs_info->flags); in btrfs_dev_replace_kthread()
1016 void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_noblocked() argument
1018 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_noblocked()
1021 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount) in btrfs_bio_counter_sub() argument
1023 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount); in btrfs_bio_counter_sub()
1024 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait); in btrfs_bio_counter_sub()
1027 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info) in btrfs_bio_counter_inc_blocked() argument
1030 percpu_counter_inc(&fs_info->dev_replace.bio_counter); in btrfs_bio_counter_inc_blocked()
1032 &fs_info->fs_state))) in btrfs_bio_counter_inc_blocked()
1035 btrfs_bio_counter_dec(fs_info); in btrfs_bio_counter_inc_blocked()
1036 wait_event(fs_info->dev_replace.replace_wait, in btrfs_bio_counter_inc_blocked()
1038 &fs_info->fs_state)); in btrfs_bio_counter_inc_blocked()