aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-06-12 06:35:45 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-06-12 06:35:45 -0400
commit39279cc3d2704cfbf9c35dcb5bdd392159ae4625 (patch)
tree8c6c16a886bdd88ee447871e049c0d56466c2271 /fs/btrfs/disk-io.c
parent5276aedab0baacfb3c5483208b8be85a8416bd5f (diff)
Btrfs: split up super.c
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8a88404525e8..96bf3ef3a798 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -22,7 +22,7 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
22 if (bh_blocknr(buf) != btrfs_header_blocknr(&node->header)) { 22 if (bh_blocknr(buf) != btrfs_header_blocknr(&node->header)) {
23 printk(KERN_CRIT "bh_blocknr(buf) is %Lu, header is %Lu\n", 23 printk(KERN_CRIT "bh_blocknr(buf) is %Lu, header is %Lu\n",
24 bh_blocknr(buf), btrfs_header_blocknr(&node->header)); 24 bh_blocknr(buf), btrfs_header_blocknr(&node->header));
25 BUG(); 25 return 1;
26 } 26 }
27 return 0; 27 return 0;
28} 28}
@@ -253,7 +253,7 @@ uptodate:
253 set_buffer_checked(bh); 253 set_buffer_checked(bh);
254 } 254 }
255 if (check_tree_block(root, bh)) 255 if (check_tree_block(root, bh))
256 BUG(); 256 goto fail;
257 return bh; 257 return bh;
258fail: 258fail:
259 brelse(bh); 259 brelse(bh);
@@ -398,8 +398,13 @@ struct btrfs_root *open_ctree(struct super_block *sb)
398 struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info), 398 struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
399 GFP_NOFS); 399 GFP_NOFS);
400 int ret; 400 int ret;
401 int err = -EIO;
401 struct btrfs_super_block *disk_super; 402 struct btrfs_super_block *disk_super;
402 403
404 if (!extent_root || !tree_root || !fs_info) {
405 err = -ENOMEM;
406 goto fail;
407 }
403 init_bit_radix(&fs_info->pinned_radix); 408 init_bit_radix(&fs_info->pinned_radix);
404 init_bit_radix(&fs_info->pending_del_radix); 409 init_bit_radix(&fs_info->pending_del_radix);
405 init_bit_radix(&fs_info->extent_map_radix); 410 init_bit_radix(&fs_info->extent_map_radix);
@@ -431,9 +436,11 @@ struct btrfs_root *open_ctree(struct super_block *sb)
431 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); 436 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
432 fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC); 437 fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC);
433 spin_lock_init(&fs_info->hash_lock); 438 spin_lock_init(&fs_info->hash_lock);
439
434 if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) { 440 if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
435 printk("failed to allocate digest hash\n"); 441 printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
436 return NULL; 442 err = -ENOMEM;
443 goto fail_iput;
437 } 444 }
438 mutex_init(&fs_info->trans_mutex); 445 mutex_init(&fs_info->trans_mutex);
439 mutex_init(&fs_info->fs_mutex); 446 mutex_init(&fs_info->fs_mutex);
@@ -446,30 +453,53 @@ struct btrfs_root *open_ctree(struct super_block *sb)
446 sb->s_blocksize); 453 sb->s_blocksize);
447 454
448 if (!fs_info->sb_buffer) 455 if (!fs_info->sb_buffer)
449 return NULL; 456 goto fail_iput;
450 disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data; 457 disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data;
458
451 if (!btrfs_super_root(disk_super)) 459 if (!btrfs_super_root(disk_super))
452 return NULL; 460 goto fail_sb_buffer;
453 461
454 i_size_write(fs_info->btree_inode, 462 i_size_write(fs_info->btree_inode,
455 btrfs_super_total_blocks(disk_super) << 463 btrfs_super_total_blocks(disk_super) <<
456 fs_info->btree_inode->i_blkbits); 464 fs_info->btree_inode->i_blkbits);
457 465
458 fs_info->disk_super = disk_super; 466 fs_info->disk_super = disk_super;
467
468 if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
469 sizeof(disk_super->magic))) {
470 printk("btrfs: valid FS not found on %s\n", sb->s_id);
471 goto fail_sb_buffer;
472 }
459 tree_root->node = read_tree_block(tree_root, 473 tree_root->node = read_tree_block(tree_root,
460 btrfs_super_root(disk_super)); 474 btrfs_super_root(disk_super));
461 BUG_ON(!tree_root->node); 475 if (!tree_root->node)
476 goto fail_sb_buffer;
462 477
463 mutex_lock(&fs_info->fs_mutex); 478 mutex_lock(&fs_info->fs_mutex);
464 ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info, 479 ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
465 BTRFS_EXTENT_TREE_OBJECTID, extent_root); 480 BTRFS_EXTENT_TREE_OBJECTID, extent_root);
466 BUG_ON(ret); 481 if (ret) {
482 mutex_unlock(&fs_info->fs_mutex);
483 goto fail_tree_root;
484 }
467 485
468 btrfs_read_block_groups(extent_root); 486 btrfs_read_block_groups(extent_root);
469 487
470 fs_info->generation = btrfs_super_generation(disk_super) + 1; 488 fs_info->generation = btrfs_super_generation(disk_super) + 1;
471 mutex_unlock(&fs_info->fs_mutex); 489 mutex_unlock(&fs_info->fs_mutex);
472 return tree_root; 490 return tree_root;
491
492fail_tree_root:
493 btrfs_block_release(tree_root, tree_root->node);
494fail_sb_buffer:
495 btrfs_block_release(tree_root, fs_info->sb_buffer);
496fail_iput:
497 iput(fs_info->btree_inode);
498fail:
499 kfree(extent_root);
500 kfree(tree_root);
501 kfree(fs_info);
502 return ERR_PTR(err);
473} 503}
474 504
475int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root 505int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root