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)
77 struct btrfs_root *dev_root = fs_info->dev_root;
78 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
106 if (btrfs_find_device(fs_info->fs_devices, &args)) {
107 btrfs_err(fs_info,
137 btrfs_warn(fs_info,
168 if (btrfs_find_device(fs_info->fs_devices, &args)) {
169 btrfs_err(fs_info,
179 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, &args);
181 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, &args);
188 !btrfs_test_opt(fs_info, DEGRADED)) {
190 btrfs_warn(fs_info,
192 btrfs_warn(fs_info,
197 !btrfs_test_opt(fs_info, DEGRADED)) {
199 btrfs_warn(fs_info,
201 btrfs_warn(fs_info,
221 WARN_ON(fs_info->fs_devices->rw_devices == 0);
222 dev_replace->tgtdev->io_width = fs_info->sectorsize;
223 dev_replace->tgtdev->io_align = fs_info->sectorsize;
224 dev_replace->tgtdev->sector_size = fs_info->sectorsize;
225 dev_replace->tgtdev->fs_info = fs_info;
243 static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
248 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
256 btrfs_err(fs_info, "the filesystem is a seed filesystem!");
261 fs_info->bdev_holder, NULL);
263 btrfs_err(fs_info, "target device %s is invalid!", device_path);
267 if (!btrfs_check_device_zone_type(fs_info, bdev)) {
268 btrfs_err(fs_info,
278 btrfs_err(fs_info,
287 btrfs_err(fs_info,
306 device->io_width = fs_info->sectorsize;
307 device->io_align = fs_info->sectorsize;
308 device->sector_size = fs_info->sectorsize;
314 device->fs_info = fs_info;
318 device->holder = fs_info->bdev_holder;
337 blkdev_put(bdev, fs_info->bdev_holder);
347 struct btrfs_fs_info *fs_info = trans->fs_info;
349 struct btrfs_root *dev_root = fs_info->dev_root;
354 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
375 btrfs_warn(fs_info,
396 btrfs_warn(fs_info,
410 btrfs_warn(fs_info,
453 static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
459 struct btrfs_root *root = fs_info->dev_root;
468 if (!btrfs_is_zoned(fs_info))
471 mutex_lock(&fs_info->chunk_mutex);
474 spin_lock(&fs_info->trans_lock);
475 while (fs_info->running_transaction &&
476 !list_empty(&fs_info->running_transaction->dev_update_list)) {
477 spin_unlock(&fs_info->trans_lock);
478 mutex_unlock(&fs_info->chunk_mutex);
482 mutex_lock(&fs_info->chunk_mutex);
484 spin_lock(&fs_info->trans_lock);
492 mutex_lock(&fs_info->chunk_mutex);
496 spin_lock(&fs_info->trans_lock);
498 spin_unlock(&fs_info->trans_lock);
530 cache = btrfs_lookup_block_group(fs_info, chunk_offset);
542 mutex_unlock(&fs_info->chunk_mutex);
551 struct btrfs_fs_info *fs_info = cache->fs_info;
559 if (!btrfs_is_zoned(fs_info))
569 em = btrfs_get_chunk_map(fs_info, chunk_offset, 1);
601 static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
605 struct btrfs_root *root = fs_info->dev_root;
607 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
612 src_device = btrfs_find_device_by_devspec(fs_info, srcdevid,
617 if (btrfs_pinned_by_swapfile(fs_info, src_device)) {
618 btrfs_warn_in_rcu(fs_info,
637 ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name,
642 ret = mark_block_group_to_copy(fs_info, src_device);
664 btrfs_info_in_rcu(fs_info,
688 btrfs_err(fs_info, "kobj add dev failed %d", ret);
690 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
714 ret = btrfs_scrub_dev(fs_info, src_device->devid, 0,
718 ret = btrfs_dev_replace_finishing(fs_info, ret);
746 int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
762 ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name,
778 static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info)
780 set_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
781 wait_event(fs_info->dev_replace.replace_wait, !percpu_counter_sum(
782 &fs_info->dev_replace.bio_counter));
788 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info)
790 clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
791 wake_up(&fs_info->dev_replace.replace_wait);
809 lockdep_assert_held(&srcdev->fs_info->chunk_mutex);
826 struct btrfs_fs_info *fs_info,
830 struct extent_map_tree *em_tree = &fs_info->mapping_tree;
851 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
854 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
855 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
858 struct btrfs_root *root = fs_info->tree_root;
883 ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false);
888 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
907 mutex_lock(&fs_info->chunk_mutex);
911 mutex_unlock(&fs_info->chunk_mutex);
934 btrfs_dev_replace_update_device_in_mapping_tree(fs_info,
939 btrfs_err_in_rcu(fs_info,
946 mutex_unlock(&fs_info->chunk_mutex);
948 btrfs_rm_dev_replace_blocked(fs_info);
951 btrfs_rm_dev_replace_unblocked(fs_info);
957 btrfs_info_in_rcu(fs_info,
980 btrfs_rm_dev_replace_blocked(fs_info);
984 btrfs_rm_dev_replace_unblocked(fs_info);
999 mutex_unlock(&fs_info->chunk_mutex);
1006 btrfs_scratch_superblocks(fs_info, src_device->bdev,
1026 static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info)
1028 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1050 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,
1053 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1066 args->status.progress_1000 = btrfs_dev_replace_progress(fs_info);
1070 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
1072 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1076 struct btrfs_root *root = fs_info->tree_root;
1080 if (sb_rdonly(fs_info->sb))
1096 ret = btrfs_scrub_cancel(fs_info);
1105 btrfs_info_in_rcu(fs_info,
1129 btrfs_scrub_cancel(fs_info);
1139 btrfs_info_in_rcu(fs_info,
1156 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info)
1158 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1174 btrfs_info(fs_info, "suspending dev_replace for unmount");
1183 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info)
1186 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1204 btrfs_info(fs_info,
1206 btrfs_info(fs_info,
1220 if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_REPLACE)) {
1225 btrfs_info(fs_info,
1230 task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl");
1236 struct btrfs_fs_info *fs_info = data;
1237 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
1241 progress = btrfs_dev_replace_progress(fs_info);
1243 btrfs_info_in_rcu(fs_info,
1250 ret = btrfs_scrub_dev(fs_info, dev_replace->srcdev->devid,
1254 ret = btrfs_dev_replace_finishing(fs_info, ret);
1257 btrfs_exclop_finish(fs_info);
1288 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount)
1290 percpu_counter_sub(&fs_info->dev_replace.bio_counter, amount);
1291 cond_wake_up_nomb(&fs_info->dev_replace.replace_wait);
1294 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info)
1297 percpu_counter_inc(&fs_info->dev_replace.bio_counter);
1299 &fs_info->fs_state)))
1302 btrfs_bio_counter_dec(fs_info);
1303 wait_event(fs_info->dev_replace.replace_wait,
1305 &fs_info->fs_state));