aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index d8525662ca7a..89e99eb384db 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -43,6 +43,7 @@
43#include "tree-log.h" 43#include "tree-log.h"
44#include "free-space-cache.h" 44#include "free-space-cache.h"
45#include "inode-map.h" 45#include "inode-map.h"
46#include "check-integrity.h"
46 47
47static struct extent_io_ops btree_extent_io_ops; 48static struct extent_io_ops btree_extent_io_ops;
48static void end_workqueue_fn(struct btrfs_work *work); 49static void end_workqueue_fn(struct btrfs_work *work);
@@ -1244,7 +1245,8 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1244 root->ref_cows = 0; 1245 root->ref_cows = 0;
1245 1246
1246 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 1247 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
1247 BTRFS_TREE_LOG_OBJECTID, NULL, 0, 0, 0); 1248 BTRFS_TREE_LOG_OBJECTID, NULL,
1249 0, 0, 0, 0);
1248 if (IS_ERR(leaf)) { 1250 if (IS_ERR(leaf)) {
1249 kfree(root); 1251 kfree(root);
1250 return ERR_CAST(leaf); 1252 return ERR_CAST(leaf);
@@ -1998,6 +2000,17 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1998 init_waitqueue_head(&fs_info->scrub_pause_wait); 2000 init_waitqueue_head(&fs_info->scrub_pause_wait);
1999 init_rwsem(&fs_info->scrub_super_lock); 2001 init_rwsem(&fs_info->scrub_super_lock);
2000 fs_info->scrub_workers_refcnt = 0; 2002 fs_info->scrub_workers_refcnt = 0;
2003#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2004 fs_info->check_integrity_print_mask = 0;
2005#endif
2006
2007 spin_lock_init(&fs_info->balance_lock);
2008 mutex_init(&fs_info->balance_mutex);
2009 atomic_set(&fs_info->balance_running, 0);
2010 atomic_set(&fs_info->balance_pause_req, 0);
2011 atomic_set(&fs_info->balance_cancel_req, 0);
2012 fs_info->balance_ctl = NULL;
2013 init_waitqueue_head(&fs_info->balance_wait_q);
2001 2014
2002 sb->s_blocksize = 4096; 2015 sb->s_blocksize = 4096;
2003 sb->s_blocksize_bits = blksize_bits(4096); 2016 sb->s_blocksize_bits = blksize_bits(4096);
@@ -2267,9 +2280,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
2267 (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node), 2280 (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node),
2268 BTRFS_UUID_SIZE); 2281 BTRFS_UUID_SIZE);
2269 2282
2270 mutex_lock(&fs_info->chunk_mutex);
2271 ret = btrfs_read_chunk_tree(chunk_root); 2283 ret = btrfs_read_chunk_tree(chunk_root);
2272 mutex_unlock(&fs_info->chunk_mutex);
2273 if (ret) { 2284 if (ret) {
2274 printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n", 2285 printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n",
2275 sb->s_id); 2286 sb->s_id);
@@ -2318,9 +2329,6 @@ retry_root_backup:
2318 2329
2319 fs_info->generation = generation; 2330 fs_info->generation = generation;
2320 fs_info->last_trans_committed = generation; 2331 fs_info->last_trans_committed = generation;
2321 fs_info->data_alloc_profile = (u64)-1;
2322 fs_info->metadata_alloc_profile = (u64)-1;
2323 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
2324 2332
2325 ret = btrfs_init_space_info(fs_info); 2333 ret = btrfs_init_space_info(fs_info);
2326 if (ret) { 2334 if (ret) {
@@ -2353,6 +2361,19 @@ retry_root_backup:
2353 btrfs_set_opt(fs_info->mount_opt, SSD); 2361 btrfs_set_opt(fs_info->mount_opt, SSD);
2354 } 2362 }
2355 2363
2364#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2365 if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
2366 ret = btrfsic_mount(tree_root, fs_devices,
2367 btrfs_test_opt(tree_root,
2368 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
2369 1 : 0,
2370 fs_info->check_integrity_print_mask);
2371 if (ret)
2372 printk(KERN_WARNING "btrfs: failed to initialize"
2373 " integrity check module %s\n", sb->s_id);
2374 }
2375#endif
2376
2356 /* do not make disk changes in broken FS */ 2377 /* do not make disk changes in broken FS */
2357 if (btrfs_super_log_root(disk_super) != 0 && 2378 if (btrfs_super_log_root(disk_super) != 0 &&
2358 !(fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)) { 2379 !(fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)) {
@@ -2423,6 +2444,10 @@ retry_root_backup:
2423 if (!err) 2444 if (!err)
2424 err = btrfs_orphan_cleanup(fs_info->tree_root); 2445 err = btrfs_orphan_cleanup(fs_info->tree_root);
2425 up_read(&fs_info->cleanup_work_sem); 2446 up_read(&fs_info->cleanup_work_sem);
2447
2448 if (!err)
2449 err = btrfs_recover_balance(fs_info->tree_root);
2450
2426 if (err) { 2451 if (err) {
2427 close_ctree(tree_root); 2452 close_ctree(tree_root);
2428 return ERR_PTR(err); 2453 return ERR_PTR(err);
@@ -2631,7 +2656,7 @@ static int write_dev_supers(struct btrfs_device *device,
2631 * we fua the first super. The others we allow 2656 * we fua the first super. The others we allow
2632 * to go down lazy. 2657 * to go down lazy.
2633 */ 2658 */
2634 ret = submit_bh(WRITE_FUA, bh); 2659 ret = btrfsic_submit_bh(WRITE_FUA, bh);
2635 if (ret) 2660 if (ret)
2636 errors++; 2661 errors++;
2637 } 2662 }
@@ -2708,7 +2733,7 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
2708 device->flush_bio = bio; 2733 device->flush_bio = bio;
2709 2734
2710 bio_get(bio); 2735 bio_get(bio);
2711 submit_bio(WRITE_FLUSH, bio); 2736 btrfsic_submit_bio(WRITE_FLUSH, bio);
2712 2737
2713 return 0; 2738 return 0;
2714} 2739}
@@ -2972,6 +2997,9 @@ int close_ctree(struct btrfs_root *root)
2972 fs_info->closing = 1; 2997 fs_info->closing = 1;
2973 smp_mb(); 2998 smp_mb();
2974 2999
3000 /* pause restriper - we want to resume on mount */
3001 btrfs_pause_balance(root->fs_info);
3002
2975 btrfs_scrub_cancel(root); 3003 btrfs_scrub_cancel(root);
2976 3004
2977 /* wait for any defraggers to finish */ 3005 /* wait for any defraggers to finish */
@@ -3054,6 +3082,11 @@ int close_ctree(struct btrfs_root *root)
3054 btrfs_stop_workers(&fs_info->caching_workers); 3082 btrfs_stop_workers(&fs_info->caching_workers);
3055 btrfs_stop_workers(&fs_info->readahead_workers); 3083 btrfs_stop_workers(&fs_info->readahead_workers);
3056 3084
3085#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3086 if (btrfs_test_opt(root, CHECK_INTEGRITY))
3087 btrfsic_unmount(root, fs_info->fs_devices);
3088#endif
3089
3057 btrfs_close_devices(fs_info->fs_devices); 3090 btrfs_close_devices(fs_info->fs_devices);
3058 btrfs_mapping_tree_free(&fs_info->mapping_tree); 3091 btrfs_mapping_tree_free(&fs_info->mapping_tree);
3059 3092