diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 60ce1190307b..ff2362dca91a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -101,7 +101,7 @@ int __init btrfs_end_io_wq_init(void) | |||
101 | btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq", | 101 | btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq", |
102 | sizeof(struct btrfs_end_io_wq), | 102 | sizeof(struct btrfs_end_io_wq), |
103 | 0, | 103 | 0, |
104 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, | 104 | SLAB_MEM_SPREAD, |
105 | NULL); | 105 | NULL); |
106 | if (!btrfs_end_io_wq_cache) | 106 | if (!btrfs_end_io_wq_cache) |
107 | return -ENOMEM; | 107 | return -ENOMEM; |
@@ -1146,7 +1146,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, | |||
1146 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | 1146 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, |
1147 | u64 bytenr) | 1147 | u64 bytenr) |
1148 | { | 1148 | { |
1149 | if (btrfs_test_is_dummy_root(root)) | 1149 | if (btrfs_is_testing(root->fs_info)) |
1150 | return alloc_test_extent_buffer(root->fs_info, bytenr, | 1150 | return alloc_test_extent_buffer(root->fs_info, bytenr, |
1151 | root->nodesize); | 1151 | root->nodesize); |
1152 | return alloc_extent_buffer(root->fs_info, bytenr); | 1152 | return alloc_extent_buffer(root->fs_info, bytenr); |
@@ -1233,6 +1233,7 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, | |||
1233 | struct btrfs_root *root, struct btrfs_fs_info *fs_info, | 1233 | struct btrfs_root *root, struct btrfs_fs_info *fs_info, |
1234 | u64 objectid) | 1234 | u64 objectid) |
1235 | { | 1235 | { |
1236 | bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); | ||
1236 | root->node = NULL; | 1237 | root->node = NULL; |
1237 | root->commit_root = NULL; | 1238 | root->commit_root = NULL; |
1238 | root->sectorsize = sectorsize; | 1239 | root->sectorsize = sectorsize; |
@@ -1287,14 +1288,14 @@ static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize, | |||
1287 | root->log_transid = 0; | 1288 | root->log_transid = 0; |
1288 | root->log_transid_committed = -1; | 1289 | root->log_transid_committed = -1; |
1289 | root->last_log_commit = 0; | 1290 | root->last_log_commit = 0; |
1290 | if (fs_info) | 1291 | if (!dummy) |
1291 | extent_io_tree_init(&root->dirty_log_pages, | 1292 | extent_io_tree_init(&root->dirty_log_pages, |
1292 | fs_info->btree_inode->i_mapping); | 1293 | fs_info->btree_inode->i_mapping); |
1293 | 1294 | ||
1294 | memset(&root->root_key, 0, sizeof(root->root_key)); | 1295 | memset(&root->root_key, 0, sizeof(root->root_key)); |
1295 | memset(&root->root_item, 0, sizeof(root->root_item)); | 1296 | memset(&root->root_item, 0, sizeof(root->root_item)); |
1296 | memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); | 1297 | memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); |
1297 | if (fs_info) | 1298 | if (!dummy) |
1298 | root->defrag_trans_start = fs_info->generation; | 1299 | root->defrag_trans_start = fs_info->generation; |
1299 | else | 1300 | else |
1300 | root->defrag_trans_start = 0; | 1301 | root->defrag_trans_start = 0; |
@@ -1315,17 +1316,20 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, | |||
1315 | 1316 | ||
1316 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | 1317 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
1317 | /* Should only be used by the testing infrastructure */ | 1318 | /* Should only be used by the testing infrastructure */ |
1318 | struct btrfs_root *btrfs_alloc_dummy_root(u32 sectorsize, u32 nodesize) | 1319 | struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info, |
1320 | u32 sectorsize, u32 nodesize) | ||
1319 | { | 1321 | { |
1320 | struct btrfs_root *root; | 1322 | struct btrfs_root *root; |
1321 | 1323 | ||
1322 | root = btrfs_alloc_root(NULL, GFP_KERNEL); | 1324 | if (!fs_info) |
1325 | return ERR_PTR(-EINVAL); | ||
1326 | |||
1327 | root = btrfs_alloc_root(fs_info, GFP_KERNEL); | ||
1323 | if (!root) | 1328 | if (!root) |
1324 | return ERR_PTR(-ENOMEM); | 1329 | return ERR_PTR(-ENOMEM); |
1325 | /* We don't use the stripesize in selftest, set it as sectorsize */ | 1330 | /* We don't use the stripesize in selftest, set it as sectorsize */ |
1326 | __setup_root(nodesize, sectorsize, sectorsize, root, NULL, | 1331 | __setup_root(nodesize, sectorsize, sectorsize, root, fs_info, |
1327 | BTRFS_ROOT_TREE_OBJECTID); | 1332 | BTRFS_ROOT_TREE_OBJECTID); |
1328 | set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); | ||
1329 | root->alloc_bytenr = 0; | 1333 | root->alloc_bytenr = 0; |
1330 | 1334 | ||
1331 | return root; | 1335 | return root; |
@@ -1600,14 +1604,14 @@ int btrfs_init_fs_root(struct btrfs_root *root) | |||
1600 | 1604 | ||
1601 | ret = get_anon_bdev(&root->anon_dev); | 1605 | ret = get_anon_bdev(&root->anon_dev); |
1602 | if (ret) | 1606 | if (ret) |
1603 | goto free_writers; | 1607 | goto fail; |
1604 | 1608 | ||
1605 | mutex_lock(&root->objectid_mutex); | 1609 | mutex_lock(&root->objectid_mutex); |
1606 | ret = btrfs_find_highest_objectid(root, | 1610 | ret = btrfs_find_highest_objectid(root, |
1607 | &root->highest_objectid); | 1611 | &root->highest_objectid); |
1608 | if (ret) { | 1612 | if (ret) { |
1609 | mutex_unlock(&root->objectid_mutex); | 1613 | mutex_unlock(&root->objectid_mutex); |
1610 | goto free_root_dev; | 1614 | goto fail; |
1611 | } | 1615 | } |
1612 | 1616 | ||
1613 | ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); | 1617 | ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); |
@@ -1615,14 +1619,8 @@ int btrfs_init_fs_root(struct btrfs_root *root) | |||
1615 | mutex_unlock(&root->objectid_mutex); | 1619 | mutex_unlock(&root->objectid_mutex); |
1616 | 1620 | ||
1617 | return 0; | 1621 | return 0; |
1618 | |||
1619 | free_root_dev: | ||
1620 | free_anon_bdev(root->anon_dev); | ||
1621 | free_writers: | ||
1622 | btrfs_free_subvolume_writers(root->subv_writers); | ||
1623 | fail: | 1622 | fail: |
1624 | kfree(root->free_ino_ctl); | 1623 | /* the caller is responsible to call free_fs_root */ |
1625 | kfree(root->free_ino_pinned); | ||
1626 | return ret; | 1624 | return ret; |
1627 | } | 1625 | } |
1628 | 1626 | ||
@@ -2316,17 +2314,19 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, | |||
2316 | unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND; | 2314 | unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND; |
2317 | 2315 | ||
2318 | fs_info->workers = | 2316 | fs_info->workers = |
2319 | btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI, | 2317 | btrfs_alloc_workqueue(fs_info, "worker", |
2320 | max_active, 16); | 2318 | flags | WQ_HIGHPRI, max_active, 16); |
2321 | 2319 | ||
2322 | fs_info->delalloc_workers = | 2320 | fs_info->delalloc_workers = |
2323 | btrfs_alloc_workqueue("delalloc", flags, max_active, 2); | 2321 | btrfs_alloc_workqueue(fs_info, "delalloc", |
2322 | flags, max_active, 2); | ||
2324 | 2323 | ||
2325 | fs_info->flush_workers = | 2324 | fs_info->flush_workers = |
2326 | btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0); | 2325 | btrfs_alloc_workqueue(fs_info, "flush_delalloc", |
2326 | flags, max_active, 0); | ||
2327 | 2327 | ||
2328 | fs_info->caching_workers = | 2328 | fs_info->caching_workers = |
2329 | btrfs_alloc_workqueue("cache", flags, max_active, 0); | 2329 | btrfs_alloc_workqueue(fs_info, "cache", flags, max_active, 0); |
2330 | 2330 | ||
2331 | /* | 2331 | /* |
2332 | * a higher idle thresh on the submit workers makes it much more | 2332 | * a higher idle thresh on the submit workers makes it much more |
@@ -2334,41 +2334,48 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, | |||
2334 | * devices | 2334 | * devices |
2335 | */ | 2335 | */ |
2336 | fs_info->submit_workers = | 2336 | fs_info->submit_workers = |
2337 | btrfs_alloc_workqueue("submit", flags, | 2337 | btrfs_alloc_workqueue(fs_info, "submit", flags, |
2338 | min_t(u64, fs_devices->num_devices, | 2338 | min_t(u64, fs_devices->num_devices, |
2339 | max_active), 64); | 2339 | max_active), 64); |
2340 | 2340 | ||
2341 | fs_info->fixup_workers = | 2341 | fs_info->fixup_workers = |
2342 | btrfs_alloc_workqueue("fixup", flags, 1, 0); | 2342 | btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0); |
2343 | 2343 | ||
2344 | /* | 2344 | /* |
2345 | * endios are largely parallel and should have a very | 2345 | * endios are largely parallel and should have a very |
2346 | * low idle thresh | 2346 | * low idle thresh |
2347 | */ | 2347 | */ |
2348 | fs_info->endio_workers = | 2348 | fs_info->endio_workers = |
2349 | btrfs_alloc_workqueue("endio", flags, max_active, 4); | 2349 | btrfs_alloc_workqueue(fs_info, "endio", flags, max_active, 4); |
2350 | fs_info->endio_meta_workers = | 2350 | fs_info->endio_meta_workers = |
2351 | btrfs_alloc_workqueue("endio-meta", flags, max_active, 4); | 2351 | btrfs_alloc_workqueue(fs_info, "endio-meta", flags, |
2352 | max_active, 4); | ||
2352 | fs_info->endio_meta_write_workers = | 2353 | fs_info->endio_meta_write_workers = |
2353 | btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2); | 2354 | btrfs_alloc_workqueue(fs_info, "endio-meta-write", flags, |
2355 | max_active, 2); | ||
2354 | fs_info->endio_raid56_workers = | 2356 | fs_info->endio_raid56_workers = |
2355 | btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4); | 2357 | btrfs_alloc_workqueue(fs_info, "endio-raid56", flags, |
2358 | max_active, 4); | ||
2356 | fs_info->endio_repair_workers = | 2359 | fs_info->endio_repair_workers = |
2357 | btrfs_alloc_workqueue("endio-repair", flags, 1, 0); | 2360 | btrfs_alloc_workqueue(fs_info, "endio-repair", flags, 1, 0); |
2358 | fs_info->rmw_workers = | 2361 | fs_info->rmw_workers = |
2359 | btrfs_alloc_workqueue("rmw", flags, max_active, 2); | 2362 | btrfs_alloc_workqueue(fs_info, "rmw", flags, max_active, 2); |
2360 | fs_info->endio_write_workers = | 2363 | fs_info->endio_write_workers = |
2361 | btrfs_alloc_workqueue("endio-write", flags, max_active, 2); | 2364 | btrfs_alloc_workqueue(fs_info, "endio-write", flags, |
2365 | max_active, 2); | ||
2362 | fs_info->endio_freespace_worker = | 2366 | fs_info->endio_freespace_worker = |
2363 | btrfs_alloc_workqueue("freespace-write", flags, max_active, 0); | 2367 | btrfs_alloc_workqueue(fs_info, "freespace-write", flags, |
2368 | max_active, 0); | ||
2364 | fs_info->delayed_workers = | 2369 | fs_info->delayed_workers = |
2365 | btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0); | 2370 | btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, |
2371 | max_active, 0); | ||
2366 | fs_info->readahead_workers = | 2372 | fs_info->readahead_workers = |
2367 | btrfs_alloc_workqueue("readahead", flags, max_active, 2); | 2373 | btrfs_alloc_workqueue(fs_info, "readahead", flags, |
2374 | max_active, 2); | ||
2368 | fs_info->qgroup_rescan_workers = | 2375 | fs_info->qgroup_rescan_workers = |
2369 | btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0); | 2376 | btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); |
2370 | fs_info->extent_workers = | 2377 | fs_info->extent_workers = |
2371 | btrfs_alloc_workqueue("extent-refs", flags, | 2378 | btrfs_alloc_workqueue(fs_info, "extent-refs", flags, |
2372 | min_t(u64, fs_devices->num_devices, | 2379 | min_t(u64, fs_devices->num_devices, |
2373 | max_active), 8); | 2380 | max_active), 8); |
2374 | 2381 | ||
@@ -3016,8 +3023,8 @@ retry_root_backup: | |||
3016 | if (IS_ERR(fs_info->transaction_kthread)) | 3023 | if (IS_ERR(fs_info->transaction_kthread)) |
3017 | goto fail_cleaner; | 3024 | goto fail_cleaner; |
3018 | 3025 | ||
3019 | if (!btrfs_test_opt(tree_root, SSD) && | 3026 | if (!btrfs_test_opt(tree_root->fs_info, SSD) && |
3020 | !btrfs_test_opt(tree_root, NOSSD) && | 3027 | !btrfs_test_opt(tree_root->fs_info, NOSSD) && |
3021 | !fs_info->fs_devices->rotating) { | 3028 | !fs_info->fs_devices->rotating) { |
3022 | btrfs_info(fs_info, "detected SSD devices, enabling SSD mode"); | 3029 | btrfs_info(fs_info, "detected SSD devices, enabling SSD mode"); |
3023 | btrfs_set_opt(fs_info->mount_opt, SSD); | 3030 | btrfs_set_opt(fs_info->mount_opt, SSD); |
@@ -3030,9 +3037,9 @@ retry_root_backup: | |||
3030 | btrfs_apply_pending_changes(fs_info); | 3037 | btrfs_apply_pending_changes(fs_info); |
3031 | 3038 | ||
3032 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 3039 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
3033 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { | 3040 | if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) { |
3034 | ret = btrfsic_mount(tree_root, fs_devices, | 3041 | ret = btrfsic_mount(tree_root, fs_devices, |
3035 | btrfs_test_opt(tree_root, | 3042 | btrfs_test_opt(tree_root->fs_info, |
3036 | CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ? | 3043 | CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ? |
3037 | 1 : 0, | 3044 | 1 : 0, |
3038 | fs_info->check_integrity_print_mask); | 3045 | fs_info->check_integrity_print_mask); |
@@ -3048,7 +3055,7 @@ retry_root_backup: | |||
3048 | 3055 | ||
3049 | /* do not make disk changes in broken FS or nologreplay is given */ | 3056 | /* do not make disk changes in broken FS or nologreplay is given */ |
3050 | if (btrfs_super_log_root(disk_super) != 0 && | 3057 | if (btrfs_super_log_root(disk_super) != 0 && |
3051 | !btrfs_test_opt(tree_root, NOLOGREPLAY)) { | 3058 | !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) { |
3052 | ret = btrfs_replay_log(fs_info, fs_devices); | 3059 | ret = btrfs_replay_log(fs_info, fs_devices); |
3053 | if (ret) { | 3060 | if (ret) { |
3054 | err = ret; | 3061 | err = ret; |
@@ -3089,7 +3096,7 @@ retry_root_backup: | |||
3089 | if (sb->s_flags & MS_RDONLY) | 3096 | if (sb->s_flags & MS_RDONLY) |
3090 | return 0; | 3097 | return 0; |
3091 | 3098 | ||
3092 | if (btrfs_test_opt(tree_root, FREE_SPACE_TREE) && | 3099 | if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) && |
3093 | !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { | 3100 | !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { |
3094 | btrfs_info(fs_info, "creating free space tree"); | 3101 | btrfs_info(fs_info, "creating free space tree"); |
3095 | ret = btrfs_create_free_space_tree(fs_info); | 3102 | ret = btrfs_create_free_space_tree(fs_info); |
@@ -3126,7 +3133,7 @@ retry_root_backup: | |||
3126 | 3133 | ||
3127 | btrfs_qgroup_rescan_resume(fs_info); | 3134 | btrfs_qgroup_rescan_resume(fs_info); |
3128 | 3135 | ||
3129 | if (btrfs_test_opt(tree_root, CLEAR_CACHE) && | 3136 | if (btrfs_test_opt(tree_root->fs_info, CLEAR_CACHE) && |
3130 | btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { | 3137 | btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { |
3131 | btrfs_info(fs_info, "clearing free space tree"); | 3138 | btrfs_info(fs_info, "clearing free space tree"); |
3132 | ret = btrfs_clear_free_space_tree(fs_info); | 3139 | ret = btrfs_clear_free_space_tree(fs_info); |
@@ -3147,7 +3154,7 @@ retry_root_backup: | |||
3147 | close_ctree(tree_root); | 3154 | close_ctree(tree_root); |
3148 | return ret; | 3155 | return ret; |
3149 | } | 3156 | } |
3150 | } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) || | 3157 | } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) || |
3151 | fs_info->generation != | 3158 | fs_info->generation != |
3152 | btrfs_super_uuid_tree_generation(disk_super)) { | 3159 | btrfs_super_uuid_tree_generation(disk_super)) { |
3153 | btrfs_info(fs_info, "checking UUID tree"); | 3160 | btrfs_info(fs_info, "checking UUID tree"); |
@@ -3224,7 +3231,7 @@ fail: | |||
3224 | return err; | 3231 | return err; |
3225 | 3232 | ||
3226 | recovery_tree_root: | 3233 | recovery_tree_root: |
3227 | if (!btrfs_test_opt(tree_root, USEBACKUPROOT)) | 3234 | if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT)) |
3228 | goto fail_tree_roots; | 3235 | goto fail_tree_roots; |
3229 | 3236 | ||
3230 | free_root_pointers(fs_info, 0); | 3237 | free_root_pointers(fs_info, 0); |
@@ -3639,7 +3646,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
3639 | int total_errors = 0; | 3646 | int total_errors = 0; |
3640 | u64 flags; | 3647 | u64 flags; |
3641 | 3648 | ||
3642 | do_barriers = !btrfs_test_opt(root, NOBARRIER); | 3649 | do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER); |
3643 | backup_super_roots(root->fs_info); | 3650 | backup_super_roots(root->fs_info); |
3644 | 3651 | ||
3645 | sb = root->fs_info->super_for_commit; | 3652 | sb = root->fs_info->super_for_commit; |
@@ -3923,7 +3930,7 @@ void close_ctree(struct btrfs_root *root) | |||
3923 | iput(fs_info->btree_inode); | 3930 | iput(fs_info->btree_inode); |
3924 | 3931 | ||
3925 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 3932 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
3926 | if (btrfs_test_opt(root, CHECK_INTEGRITY)) | 3933 | if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY)) |
3927 | btrfsic_unmount(root, fs_info->fs_devices); | 3934 | btrfsic_unmount(root, fs_info->fs_devices); |
3928 | #endif | 3935 | #endif |
3929 | 3936 | ||