Skip to content

Commit

Permalink
btrfs: Make btrfs_ino take a struct btrfs_inode
Browse files Browse the repository at this point in the history
Currently btrfs_ino takes a struct inode and this causes a lot of
internal btrfs functions which consume this ino to take a VFS inode,
rather than btrfs' own struct btrfs_inode. In order to fix this "leak"
of VFS structs into the internals of btrfs first it's necessary to
eliminate all uses of struct inode for the purpose of inode. This patch
does that by using BTRFS_I to convert an inode to btrfs_inode. With
this problem eliminated subsequent patches will start eliminating the
passing of struct inode altogether, eventually resulting in a lot cleaner
code.

Signed-off-by: Nikolay Borisov <[email protected]>
[ fix btrfs_get_extent tracepoint prototype ]
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
Nikolay Borisov authored and kdave committed Feb 14, 2017
1 parent 823bb20 commit 4a0cc7c
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 151 deletions.
10 changes: 5 additions & 5 deletions fs/btrfs/btrfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ static inline void btrfs_insert_inode_hash(struct inode *inode)
__insert_inode_hash(inode, h);
}

static inline u64 btrfs_ino(struct inode *inode)
static inline u64 btrfs_ino(struct btrfs_inode *inode)
{
u64 ino = BTRFS_I(inode)->location.objectid;
u64 ino = inode->location.objectid;

/*
* !ino: btree_inode
* type == BTRFS_ROOT_ITEM_KEY: subvol dir
*/
if (!ino || BTRFS_I(inode)->location.type == BTRFS_ROOT_ITEM_KEY)
ino = inode->i_ino;
if (!ino || inode->location.type == BTRFS_ROOT_ITEM_KEY)
ino = inode->vfs_inode.i_ino;
return ino;
}

Expand All @@ -248,7 +248,7 @@ static inline bool btrfs_is_free_space_inode(struct inode *inode)
struct btrfs_root *root = BTRFS_I(inode)->root;

if (root == root->fs_info->tree_root &&
btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID)
btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID)
return true;
if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID)
return true;
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static int check_compressed_csum(struct inode *inode,
if (csum != *cb_sum) {
btrfs_info(BTRFS_I(inode)->root->fs_info,
"csum failed ino %llu extent %llu csum %u wanted %u mirror %d",
btrfs_ino(inode), disk_start, csum, *cb_sum,
btrfs_ino(BTRFS_I(inode)), disk_start, csum, *cb_sum,
cb->mirror_num);
ret = -EIO;
goto fail;
Expand Down
14 changes: 7 additions & 7 deletions fs/btrfs/delayed-inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode)
{
struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
struct btrfs_root *root = btrfs_inode->root;
u64 ino = btrfs_ino(inode);
u64 ino = btrfs_ino(btrfs_inode);
struct btrfs_delayed_node *node;

node = READ_ONCE(btrfs_inode->delayed_node);
Expand Down Expand Up @@ -112,7 +112,7 @@ static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node(
struct btrfs_delayed_node *node;
struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
struct btrfs_root *root = btrfs_inode->root;
u64 ino = btrfs_ino(inode);
u64 ino = btrfs_ino(btrfs_inode);
int ret;

again:
Expand Down Expand Up @@ -637,7 +637,7 @@ static int btrfs_delayed_inode_reserve_metadata(
node->bytes_reserved = num_bytes;
trace_btrfs_space_reservation(fs_info,
"delayed_inode",
btrfs_ino(inode),
btrfs_ino(BTRFS_I(inode)),
num_bytes, 1);
}
return ret;
Expand All @@ -660,13 +660,13 @@ static int btrfs_delayed_inode_reserve_metadata(
*/
if (!ret) {
trace_btrfs_space_reservation(fs_info, "delayed_inode",
btrfs_ino(inode), num_bytes, 1);
btrfs_ino(BTRFS_I(inode)), num_bytes, 1);
node->bytes_reserved = num_bytes;
}

if (release) {
trace_btrfs_space_reservation(fs_info, "delalloc",
btrfs_ino(inode), num_bytes, 0);
btrfs_ino(BTRFS_I(inode)), num_bytes, 0);
btrfs_block_rsv_release(fs_info, src_rsv, num_bytes);
}

Expand Down Expand Up @@ -1453,7 +1453,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
goto release_node;
}

delayed_item->key.objectid = btrfs_ino(dir);
delayed_item->key.objectid = btrfs_ino(BTRFS_I(dir));
delayed_item->key.type = BTRFS_DIR_INDEX_KEY;
delayed_item->key.offset = index;

Expand Down Expand Up @@ -1521,7 +1521,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
if (IS_ERR(node))
return PTR_ERR(node);

item_key.objectid = btrfs_ino(dir);
item_key.objectid = btrfs_ino(BTRFS_I(dir));
item_key.type = BTRFS_DIR_INDEX_KEY;
item_key.offset = index;

Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/dir-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
struct btrfs_disk_key disk_key;
u32 data_size;

key.objectid = btrfs_ino(dir);
key.objectid = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_DIR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len);

Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
len = BTRFS_FID_SIZE_NON_CONNECTABLE;
type = FILEID_BTRFS_WITHOUT_PARENT;

fid->objectid = btrfs_ino(inode);
fid->objectid = btrfs_ino(BTRFS_I(inode));
fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation;

Expand Down Expand Up @@ -166,13 +166,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
if (!path)
return ERR_PTR(-ENOMEM);

if (btrfs_ino(dir) == BTRFS_FIRST_FREE_OBJECTID) {
if (btrfs_ino(BTRFS_I(dir)) == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1;
root = fs_info->tree_root;
} else {
key.objectid = btrfs_ino(dir);
key.objectid = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
if (!S_ISDIR(dir->i_mode))
return -EINVAL;

ino = btrfs_ino(inode);
ino = btrfs_ino(BTRFS_I(inode));

path = btrfs_alloc_path();
if (!path)
Expand All @@ -252,7 +252,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
root = fs_info->tree_root;
} else {
key.objectid = ino;
key.offset = btrfs_ino(dir);
key.offset = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY;
}

Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5756,7 +5756,7 @@ int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
u64 num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1);

trace_btrfs_space_reservation(fs_info, "orphan",
btrfs_ino(inode), num_bytes, 1);
btrfs_ino(BTRFS_I(inode)), num_bytes, 1);
return btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes, 1);
}

Expand All @@ -5767,7 +5767,7 @@ void btrfs_orphan_release_metadata(struct inode *inode)
u64 num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1);

trace_btrfs_space_reservation(fs_info, "orphan",
btrfs_ino(inode), num_bytes, 0);
btrfs_ino(BTRFS_I(inode)), num_bytes, 0);
btrfs_block_rsv_release(fs_info, root->orphan_block_rsv, num_bytes);
}

Expand Down Expand Up @@ -6001,7 +6001,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)

if (to_reserve)
trace_btrfs_space_reservation(fs_info, "delalloc",
btrfs_ino(inode), to_reserve, 1);
btrfs_ino(BTRFS_I(inode)), to_reserve, 1);
if (release_extra)
btrfs_block_rsv_release(fs_info, block_rsv,
btrfs_calc_trans_metadata_size(fs_info, 1));
Expand Down Expand Up @@ -6064,7 +6064,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
if (to_free) {
btrfs_block_rsv_release(fs_info, block_rsv, to_free);
trace_btrfs_space_reservation(fs_info, "delalloc",
btrfs_ino(inode), to_free, 0);
btrfs_ino(BTRFS_I(inode)), to_free, 0);
}
if (delalloc_lock)
mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
Expand Down Expand Up @@ -6100,7 +6100,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
return;

trace_btrfs_space_reservation(fs_info, "delalloc",
btrfs_ino(inode), to_free, 0);
btrfs_ino(BTRFS_I(inode)), to_free, 0);

btrfs_block_rsv_release(fs_info, &fs_info->delalloc_block_rsv, to_free);
}
Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static inline void __btrfs_debug_check_extent_io_range(const char *caller,
if (end >= PAGE_SIZE && (end % 2) == 0 && end != isize - 1) {
btrfs_debug_rl(BTRFS_I(inode)->root->fs_info,
"%s: ino %llu isize %llu odd range [%llu,%llu]",
caller, btrfs_ino(inode), isize, start, end);
caller, btrfs_ino(BTRFS_I(inode)), isize, start, end);
}
}
#else
Expand Down Expand Up @@ -2065,7 +2065,7 @@ int repair_io_failure(struct inode *inode, u64 start, u64 length, u64 logical,

btrfs_info_rl_in_rcu(fs_info,
"read error corrected: ino %llu off %llu (dev %s sector %llu)",
btrfs_ino(inode), start,
btrfs_ino(BTRFS_I(inode)), start,
rcu_str_deref(dev->name), sector);
btrfs_bio_counter_dec(fs_info);
bio_put(bio);
Expand Down Expand Up @@ -4413,7 +4413,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
* lookup the last file extent. We're not using i_size here
* because there might be preallocation past i_size
*/
ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode), -1,
ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(BTRFS_I(inode)), -1,
0);
if (ret < 0) {
btrfs_free_path(path);
Expand All @@ -4429,7 +4429,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
found_type = found_key.type;

/* No extents, but there might be delalloc bits */
if (found_key.objectid != btrfs_ino(inode) ||
if (found_key.objectid != btrfs_ino(BTRFS_I(inode)) ||
found_type != BTRFS_EXTENT_DATA_KEY) {
/* have to trust i_size as the end */
last = (u64)-1;
Expand Down Expand Up @@ -4539,7 +4539,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
*/
ret = btrfs_check_shared(trans, root->fs_info,
root->objectid,
btrfs_ino(inode), bytenr);
btrfs_ino(BTRFS_I(inode)), bytenr);
if (trans)
btrfs_end_transaction(trans);
if (ret < 0)
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
} else {
btrfs_info_rl(fs_info,
"no csum found for inode %llu start %llu",
btrfs_ino(inode), offset);
btrfs_ino(BTRFS_I(inode)), offset);
}
item = NULL;
btrfs_release_path(path);
Expand Down Expand Up @@ -977,7 +977,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode,
} else {
btrfs_err(fs_info,
"unknown file extent item type %d, inode %llu, offset %llu, root %llu",
type, btrfs_ino(inode), extent_start,
type, btrfs_ino(BTRFS_I(inode)), extent_start,
root->root_key.objectid);
}
}
12 changes: 6 additions & 6 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
if (!defrag)
return -ENOMEM;

defrag->ino = btrfs_ino(inode);
defrag->ino = btrfs_ino(BTRFS_I(inode));
defrag->transid = transid;
defrag->root = root->root_key.objectid;

Expand Down Expand Up @@ -702,7 +702,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
struct btrfs_file_extent_item *fi;
struct btrfs_key key;
struct btrfs_key new_key;
u64 ino = btrfs_ino(inode);
u64 ino = btrfs_ino(BTRFS_I(inode));
u64 search_start = start;
u64 disk_bytenr = 0;
u64 num_bytes = 0;
Expand Down Expand Up @@ -1102,7 +1102,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
int del_slot = 0;
int recow;
int ret;
u64 ino = btrfs_ino(inode);
u64 ino = btrfs_ino(BTRFS_I(inode));

path = btrfs_alloc_path();
if (!path)
Expand Down Expand Up @@ -2203,7 +2203,7 @@ static int hole_mergeable(struct inode *inode, struct extent_buffer *leaf,
return 0;

btrfs_item_key_to_cpu(leaf, &key, slot);
if (key.objectid != btrfs_ino(inode) ||
if (key.objectid != btrfs_ino(BTRFS_I(inode)) ||
key.type != BTRFS_EXTENT_DATA_KEY)
return 0;

Expand Down Expand Up @@ -2237,7 +2237,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
if (btrfs_fs_incompat(fs_info, NO_HOLES))
goto out;

key.objectid = btrfs_ino(inode);
key.objectid = btrfs_ino(BTRFS_I(inode));
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = offset;

Expand Down Expand Up @@ -2285,7 +2285,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
}
btrfs_release_path(path);

ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset,
ret = btrfs_insert_file_extent(trans, root, btrfs_ino(BTRFS_I(inode)), offset,
0, 0, end - offset, 0, end - offset,
0, 0, 0);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,

num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);

if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID)
if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FREE_INO_OBJECTID)
check_crcs = 1;

/* Make sure we can fit our crcs into the first page */
Expand Down
Loading

0 comments on commit 4a0cc7c

Please sign in to comment.