Commit 39279cc3 authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: split up super.c

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 5276aeda
...@@ -4,7 +4,7 @@ ifneq ($(KERNELRELEASE),) ...@@ -4,7 +4,7 @@ ifneq ($(KERNELRELEASE),)
obj-m := btrfs.o obj-m := btrfs.o
btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
hash.o file-item.o inode-item.o inode-map.o disk-io.o \ hash.o file-item.o inode-item.o inode-map.o disk-io.o \
transaction.o bit-radix.o transaction.o bit-radix.o inode.o file.o
#btrfs-y := ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ #btrfs-y := ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
# root-tree.o dir-item.o hash.o file-item.o inode-item.o \ # root-tree.o dir-item.o hash.o file-item.o inode-item.o \
...@@ -16,7 +16,7 @@ else ...@@ -16,7 +16,7 @@ else
KERNELDIR := /lib/modules/`uname -r`/build KERNELDIR := /lib/modules/`uname -r`/build
all:: all::
$(MAKE) C=1 -C $(KERNELDIR) M=`pwd` modules $(MAKE) -C $(KERNELDIR) M=`pwd` modules
clean:: clean::
rm *.o btrfs.ko rm *.o btrfs.ko
endif endif
* fix printk warnings
* cleanup, add more error checking, get rid of BUG_ONs * cleanup, add more error checking, get rid of BUG_ONs
* Fix ENOSPC handling * Fix ENOSPC handling
* Make allocator smarter * Make allocator smarter
......
...@@ -1123,5 +1123,28 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, ...@@ -1123,5 +1123,28 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
int btrfs_csum_truncate(struct btrfs_trans_handle *trans, int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_path *path, struct btrfs_root *root, struct btrfs_path *path,
u64 isize); u64 isize);
/* super.c */ /* inode.c */
void btrfs_delete_inode(struct inode *inode);
void btrfs_read_locked_inode(struct inode *inode);
int btrfs_write_inode(struct inode *inode, int wait);
void btrfs_dirty_inode(struct inode *inode);
struct inode *btrfs_alloc_inode(struct super_block *sb);
void btrfs_destroy_inode(struct inode *inode);
int btrfs_init_cachep(void);
void btrfs_destroy_cachep(void);
int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
unsigned long arg);
long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg);
struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
struct btrfs_root *root);
int btrfs_commit_write(struct file *file, struct page *page,
unsigned from, unsigned to);
int btrfs_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *result, int create);
/* file.c */
extern struct file_operations btrfs_file_operations;
int btrfs_drop_extents(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct inode *inode,
u64 start, u64 end, u64 *hint_block);
#endif #endif
...@@ -22,7 +22,7 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf) ...@@ -22,7 +22,7 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
if (bh_blocknr(buf) != btrfs_header_blocknr(&node->header)) { if (bh_blocknr(buf) != btrfs_header_blocknr(&node->header)) {
printk(KERN_CRIT "bh_blocknr(buf) is %Lu, header is %Lu\n", printk(KERN_CRIT "bh_blocknr(buf) is %Lu, header is %Lu\n",
bh_blocknr(buf), btrfs_header_blocknr(&node->header)); bh_blocknr(buf), btrfs_header_blocknr(&node->header));
BUG(); return 1;
} }
return 0; return 0;
} }
...@@ -253,7 +253,7 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr) ...@@ -253,7 +253,7 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
set_buffer_checked(bh); set_buffer_checked(bh);
} }
if (check_tree_block(root, bh)) if (check_tree_block(root, bh))
BUG(); goto fail;
return bh; return bh;
fail: fail:
brelse(bh); brelse(bh);
...@@ -398,8 +398,13 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -398,8 +398,13 @@ struct btrfs_root *open_ctree(struct super_block *sb)
struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info), struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
GFP_NOFS); GFP_NOFS);
int ret; int ret;
int err = -EIO;
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
if (!extent_root || !tree_root || !fs_info) {
err = -ENOMEM;
goto fail;
}
init_bit_radix(&fs_info->pinned_radix); init_bit_radix(&fs_info->pinned_radix);
init_bit_radix(&fs_info->pending_del_radix); init_bit_radix(&fs_info->pending_del_radix);
init_bit_radix(&fs_info->extent_map_radix); init_bit_radix(&fs_info->extent_map_radix);
...@@ -431,9 +436,11 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -431,9 +436,11 @@ struct btrfs_root *open_ctree(struct super_block *sb)
mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC); fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC);
spin_lock_init(&fs_info->hash_lock); spin_lock_init(&fs_info->hash_lock);
if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) { if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
printk("failed to allocate digest hash\n"); printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
return NULL; err = -ENOMEM;
goto fail_iput;
} }
mutex_init(&fs_info->trans_mutex); mutex_init(&fs_info->trans_mutex);
mutex_init(&fs_info->fs_mutex); mutex_init(&fs_info->fs_mutex);
...@@ -446,30 +453,53 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -446,30 +453,53 @@ struct btrfs_root *open_ctree(struct super_block *sb)
sb->s_blocksize); sb->s_blocksize);
if (!fs_info->sb_buffer) if (!fs_info->sb_buffer)
return NULL; goto fail_iput;
disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data; disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data;
if (!btrfs_super_root(disk_super)) if (!btrfs_super_root(disk_super))
return NULL; goto fail_sb_buffer;
i_size_write(fs_info->btree_inode, i_size_write(fs_info->btree_inode,
btrfs_super_total_blocks(disk_super) << btrfs_super_total_blocks(disk_super) <<
fs_info->btree_inode->i_blkbits); fs_info->btree_inode->i_blkbits);
fs_info->disk_super = disk_super; fs_info->disk_super = disk_super;
if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
sizeof(disk_super->magic))) {
printk("btrfs: valid FS not found on %s\n", sb->s_id);
goto fail_sb_buffer;
}
tree_root->node = read_tree_block(tree_root, tree_root->node = read_tree_block(tree_root,
btrfs_super_root(disk_super)); btrfs_super_root(disk_super));
BUG_ON(!tree_root->node); if (!tree_root->node)
goto fail_sb_buffer;
mutex_lock(&fs_info->fs_mutex); mutex_lock(&fs_info->fs_mutex);
ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info, ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
BTRFS_EXTENT_TREE_OBJECTID, extent_root); BTRFS_EXTENT_TREE_OBJECTID, extent_root);
BUG_ON(ret); if (ret) {
mutex_unlock(&fs_info->fs_mutex);
goto fail_tree_root;
}
btrfs_read_block_groups(extent_root); btrfs_read_block_groups(extent_root);
fs_info->generation = btrfs_super_generation(disk_super) + 1; fs_info->generation = btrfs_super_generation(disk_super) + 1;
mutex_unlock(&fs_info->fs_mutex); mutex_unlock(&fs_info->fs_mutex);
return tree_root; return tree_root;
fail_tree_root:
btrfs_block_release(tree_root, tree_root->node);
fail_sb_buffer:
btrfs_block_release(tree_root, fs_info->sb_buffer);
fail_iput:
iput(fs_info->btree_inode);
fail:
kfree(extent_root);
kfree(tree_root);
kfree(fs_info);
return ERR_PTR(err);
} }
int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment