Commit f1ace244 authored by Aneesh's avatar Aneesh Committed by David Woodhouse

btrfs: Code cleanup

Attaching below is some of the code cleanups that i came across while
reading the code.

a) alloc_path already calls init_path.
b) Mention that btrfs_inode is the in memory copy.Ext4 have ext4_inode_info as
the in memory copy ext4_inode as the disk copy
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent b79ab950
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef __BTRFS_I__ #ifndef __BTRFS_I__
#define __BTRFS_I__ #define __BTRFS_I__
/* in memory btrfs inode */
struct btrfs_inode { struct btrfs_inode {
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_block_group_cache *block_group; struct btrfs_block_group_cache *block_group;
......
...@@ -1647,7 +1647,6 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -1647,7 +1647,6 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_insert_empty_item(trans, root, path, cpu_key, data_size); ret = btrfs_insert_empty_item(trans, root, path, cpu_key, data_size);
if (!ret) { if (!ret) {
ptr = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), ptr = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
......
...@@ -74,7 +74,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -74,7 +74,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
ret = btrfs_name_hash(name, name_len, &key.offset); ret = btrfs_name_hash(name, name_len, &key.offset);
BUG_ON(ret); BUG_ON(ret);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
btrfs_init_path(path);
data_size = sizeof(*dir_item) + name_len; data_size = sizeof(*dir_item) + name_len;
dir_item = insert_with_overflow(trans, root, path, &key, data_size, dir_item = insert_with_overflow(trans, root, path, &key, data_size,
name, name_len); name, name_len);
......
...@@ -402,7 +402,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, ...@@ -402,7 +402,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
&ins, 0); &ins, 0);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
key.objectid = blocknr; key.objectid = blocknr;
key.flags = 0; key.flags = 0;
btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
...@@ -437,7 +436,6 @@ static int lookup_extent_ref(struct btrfs_trans_handle *trans, ...@@ -437,7 +436,6 @@ static int lookup_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_extent_item *item; struct btrfs_extent_item *item;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
btrfs_init_path(path);
key.objectid = blocknr; key.objectid = blocknr;
key.offset = num_blocks; key.offset = num_blocks;
key.flags = 0; key.flags = 0;
...@@ -807,7 +805,6 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -807,7 +805,6 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
find_free_extent(trans, root, 0, 0, (u64)-1, 0, &ins, 0); find_free_extent(trans, root, 0, 0, (u64)-1, 0, &ins, 0);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_search_slot(trans, extent_root, &key, path, -1, 1); ret = btrfs_search_slot(trans, extent_root, &key, path, -1, 1);
if (ret) { if (ret) {
...@@ -1463,7 +1460,6 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -1463,7 +1460,6 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
level = btrfs_header_level(btrfs_buffer_header(snap)); level = btrfs_header_level(btrfs_buffer_header(snap));
orig_level = level; orig_level = level;
......
...@@ -38,7 +38,6 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, ...@@ -38,7 +38,6 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
file_key.objectid = objectid; file_key.objectid = objectid;
file_key.offset = pos; file_key.offset = pos;
file_key.flags = 0; file_key.flags = 0;
...@@ -274,7 +273,6 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root, ...@@ -274,7 +273,6 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
file_key.objectid = objectid; file_key.objectid = objectid;
file_key.offset = offset; file_key.offset = offset;
file_key.flags = 0; file_key.flags = 0;
......
...@@ -35,7 +35,6 @@ int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -35,7 +35,6 @@ int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_insert_item(trans, root, &key, inode_item, ret = btrfs_insert_item(trans, root, &key, inode_item,
sizeof(*inode_item)); sizeof(*inode_item));
btrfs_release_path(root, path); btrfs_release_path(root, path);
......
...@@ -79,7 +79,6 @@ void btrfs_read_locked_inode(struct inode *inode) ...@@ -79,7 +79,6 @@ void btrfs_read_locked_inode(struct inode *inode)
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
...@@ -177,7 +176,6 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans, ...@@ -177,7 +176,6 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_lookup_inode(trans, root, path, ret = btrfs_lookup_inode(trans, root, path,
&BTRFS_I(inode)->location, 1); &BTRFS_I(inode)->location, 1);
if (ret) { if (ret) {
...@@ -214,7 +212,6 @@ static int btrfs_unlink_trans(struct btrfs_trans_handle *trans, ...@@ -214,7 +212,6 @@ static int btrfs_unlink_trans(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino, di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino,
name, name_len, -1); name, name_len, -1);
if (IS_ERR(di)) { if (IS_ERR(di)) {
...@@ -289,7 +286,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -289,7 +286,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
btrfs_set_trans_block_group(trans, dir); btrfs_set_trans_block_group(trans, dir);
...@@ -360,7 +356,6 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans, ...@@ -360,7 +356,6 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_lookup_inode(trans, root, path, ret = btrfs_lookup_inode(trans, root, path,
&BTRFS_I(inode)->location, -1); &BTRFS_I(inode)->location, -1);
BUG_ON(ret); BUG_ON(ret);
...@@ -687,7 +682,6 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, ...@@ -687,7 +682,6 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name, di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
namelen, 0); namelen, 0);
if (!di || IS_ERR(di)) { if (!di || IS_ERR(di)) {
...@@ -874,7 +868,6 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -874,7 +868,6 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
btrfs_set_key_type(&key, key_type); btrfs_set_key_type(&key, key_type);
key.offset = filp->f_pos; key.offset = filp->f_pos;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
btrfs_init_path(path);
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto err; goto err;
...@@ -1263,7 +1256,6 @@ static int btrfs_get_block_lock(struct inode *inode, sector_t iblock, ...@@ -1263,7 +1256,6 @@ static int btrfs_get_block_lock(struct inode *inode, sector_t iblock,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
if (create & BTRFS_GET_BLOCK_CREATE) { if (create & BTRFS_GET_BLOCK_CREATE) {
WARN_ON(1); WARN_ON(1);
/* this almost but not quite works */ /* this almost but not quite works */
...@@ -1280,7 +1272,7 @@ static int btrfs_get_block_lock(struct inode *inode, sector_t iblock, ...@@ -1280,7 +1272,7 @@ static int btrfs_get_block_lock(struct inode *inode, sector_t iblock,
} }
ret = btrfs_lookup_file_extent(NULL, root, path, ret = btrfs_lookup_file_extent(NULL, root, path,
inode->i_ino, objectid,
iblock << inode->i_blkbits, 0); iblock << inode->i_blkbits, 0);
if (ret < 0) { if (ret < 0) {
err = ret; err = ret;
......
...@@ -36,7 +36,6 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, ...@@ -36,7 +36,6 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -70,7 +69,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -70,7 +69,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_search_slot(trans, root, key, path, 0, 1); ret = btrfs_search_slot(trans, root, key, path, 0, 1);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -106,7 +104,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -106,7 +104,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_search_slot(trans, root, key, path, -1, 1); ret = btrfs_search_slot(trans, root, key, path, -1, 1);
if (ret < 0) if (ret < 0)
goto out; goto out;
......
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