Commit b204e5c7 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba
Browse files

btrfs: make btrfs_iget() return a btrfs inode instead



It's an internal function and most of the time the callers are doing a lot
of BTRFS_I() calls on the returned VFS inode to get the btrfs inode, so
change the return type to struct btrfs_inode instead.

Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 14d063ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ int __init btrfs_init_cachep(void);
void __cold btrfs_destroy_cachep(void);
struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
			      struct btrfs_path *path);
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root);
struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root);
struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
				    struct folio *folio, u64 start, u64 len);
int btrfs_update_inode(struct btrfs_trans_handle *trans,
+7 −7
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ static int btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info,
				  struct file_ra_state *ra)
{
	struct btrfs_root *inode_root;
	struct inode *inode;
	struct btrfs_inode *inode;
	struct btrfs_ioctl_defrag_range_args range;
	int ret = 0;
	u64 cur = 0;
@@ -250,24 +250,24 @@ static int btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info,
		goto cleanup;
	}

	if (cur >= i_size_read(inode)) {
		iput(inode);
	if (cur >= i_size_read(&inode->vfs_inode)) {
		iput(&inode->vfs_inode);
		goto cleanup;
	}

	/* Do a chunk of defrag */
	clear_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags);
	clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
	memset(&range, 0, sizeof(range));
	range.len = (u64)-1;
	range.start = cur;
	range.extent_thresh = defrag->extent_thresh;
	file_ra_state_init(ra, inode->i_mapping);
	file_ra_state_init(ra, inode->vfs_inode.i_mapping);

	sb_start_write(fs_info->sb);
	ret = btrfs_defrag_file(BTRFS_I(inode), ra, &range, defrag->transid,
	ret = btrfs_defrag_file(inode, ra, &range, defrag->transid,
				BTRFS_DEFRAG_BATCH);
	sb_end_write(fs_info->sb);
	iput(inode);
	iput(&inode->vfs_inode);

	if (ret < 0)
		goto cleanup;
+10 −5
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
{
	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
	struct btrfs_root *root;
	struct inode *inode;
	struct btrfs_inode *inode;

	if (objectid < BTRFS_FIRST_FREE_OBJECTID)
		return ERR_PTR(-ESTALE);
@@ -89,12 +89,12 @@ struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
	if (IS_ERR(inode))
		return ERR_CAST(inode);

	if (generation != 0 && generation != inode->i_generation) {
		iput(inode);
	if (generation != 0 && generation != inode->vfs_inode.i_generation) {
		iput(&inode->vfs_inode);
		return ERR_PTR(-ESTALE);
	}

	return d_obtain_alias(inode);
	return d_obtain_alias(&inode->vfs_inode);
}

static struct dentry *btrfs_fh_to_parent(struct super_block *sb, struct fid *fh,
@@ -146,6 +146,7 @@ static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
struct dentry *btrfs_get_parent(struct dentry *child)
{
	struct btrfs_inode *dir = BTRFS_I(d_inode(child));
	struct btrfs_inode *inode;
	struct btrfs_root *root = dir->root;
	struct btrfs_fs_info *fs_info = root->fs_info;
	struct btrfs_path *path;
@@ -210,7 +211,11 @@ struct dentry *btrfs_get_parent(struct dentry *child)
					found_key.offset, 0);
	}

	return d_obtain_alias(btrfs_iget(key.objectid, root));
	inode = btrfs_iget(key.objectid, root);
	if (IS_ERR(inode))
		return ERR_CAST(inode);

	return d_obtain_alias(&inode->vfs_inode);
fail:
	btrfs_free_path(path);
	return ERR_PTR(ret);
+28 −28
Original line number Diff line number Diff line
@@ -3547,7 +3547,6 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
	struct extent_buffer *leaf;
	struct btrfs_key key, found_key;
	struct btrfs_trans_handle *trans;
	struct inode *inode;
	u64 last_objectid = 0;
	int ret = 0, nr_unlink = 0;

@@ -3566,6 +3565,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
	key.offset = (u64)-1;

	while (1) {
		struct btrfs_inode *inode;

		ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
		if (ret < 0)
			goto out;
@@ -3689,10 +3690,10 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
		 * deleted but wasn't. The inode number may have been reused,
		 * but either way, we can delete the orphan item.
		 */
		if (!inode || inode->i_nlink) {
		if (!inode || inode->vfs_inode.i_nlink) {
			if (inode) {
				ret = btrfs_drop_verity_items(BTRFS_I(inode));
				iput(inode);
				ret = btrfs_drop_verity_items(inode);
				iput(&inode->vfs_inode);
				inode = NULL;
				if (ret)
					goto out;
@@ -3715,7 +3716,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
		nr_unlink++;

		/* this will do delete_inode and everything for us */
		iput(inode);
		iput(&inode->vfs_inode);
	}
	/* release the path since we're done with it */
	btrfs_release_path(path);
@@ -5665,7 +5666,7 @@ struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
/*
 * Get an inode object given its inode number and corresponding root.
 */
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root)
{
	struct btrfs_inode *inode;
	struct btrfs_path *path;
@@ -5676,7 +5677,7 @@ struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
		return ERR_PTR(-ENOMEM);

	if (!(inode->vfs_inode.i_state & I_NEW))
		return &inode->vfs_inode;
		return inode;

	path = btrfs_alloc_path();
	if (!path)
@@ -5688,7 +5689,7 @@ struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
		return ERR_PTR(ret);

	unlock_new_inode(&inode->vfs_inode);
	return &inode->vfs_inode;
	return inode;
}

static struct btrfs_inode *new_simple_dir(struct inode *dir,
@@ -5748,7 +5749,7 @@ static inline u8 btrfs_inode_type(const struct btrfs_inode *inode)
struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
{
	struct btrfs_fs_info *fs_info = inode_to_fs_info(dir);
	struct inode *inode;
	struct btrfs_inode *inode;
	struct btrfs_root *root = BTRFS_I(dir)->root;
	struct btrfs_root *sub_root = root;
	struct btrfs_key location = { 0 };
@@ -5765,49 +5766,48 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
	if (location.type == BTRFS_INODE_ITEM_KEY) {
		inode = btrfs_iget(location.objectid, root);
		if (IS_ERR(inode))
			return inode;
			return ERR_CAST(inode);

		/* Do extra check against inode mode with di_type */
		if (btrfs_inode_type(BTRFS_I(inode)) != di_type) {
		if (btrfs_inode_type(inode) != di_type) {
			btrfs_crit(fs_info,
"inode mode mismatch with dir: inode mode=0%o btrfs type=%u dir type=%u",
				  inode->i_mode, btrfs_inode_type(BTRFS_I(inode)),
				  inode->vfs_inode.i_mode, btrfs_inode_type(inode),
				  di_type);
			iput(inode);
			iput(&inode->vfs_inode);
			return ERR_PTR(-EUCLEAN);
		}
		return inode;
		return &inode->vfs_inode;
	}

	ret = fixup_tree_root_location(fs_info, BTRFS_I(dir), dentry,
				       &location, &sub_root);
	if (ret < 0) {
		if (ret != -ENOENT) {
		if (ret != -ENOENT)
			inode = ERR_PTR(ret);
		} else {
			struct btrfs_inode *b_inode;

			b_inode = new_simple_dir(dir, &location, root);
			inode = &b_inode->vfs_inode;
		}
		else
			inode = new_simple_dir(dir, &location, root);
	} else {
		inode = btrfs_iget(location.objectid, sub_root);
		btrfs_put_root(sub_root);

		if (IS_ERR(inode))
			return inode;
			return ERR_CAST(inode);

		down_read(&fs_info->cleanup_work_sem);
		if (!sb_rdonly(inode->i_sb))
		if (!sb_rdonly(inode->vfs_inode.i_sb))
			ret = btrfs_orphan_cleanup(sub_root);
		up_read(&fs_info->cleanup_work_sem);
		if (ret) {
			iput(inode);
			iput(&inode->vfs_inode);
			inode = ERR_PTR(ret);
		}
	}

	return inode;
	if (IS_ERR(inode))
		return ERR_CAST(inode);

	return &inode->vfs_inode;
}

static int btrfs_dentry_delete(const struct dentry *dentry)
@@ -6460,7 +6460,7 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
	path = NULL;

	if (args->subvol) {
		struct inode *parent;
		struct btrfs_inode *parent;

		/*
		 * Subvolumes inherit properties from their parent subvolume,
@@ -6471,8 +6471,8 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
			ret = PTR_ERR(parent);
		} else {
			ret = btrfs_inode_inherit_props(trans, BTRFS_I(inode),
							BTRFS_I(parent));
			iput(parent);
							parent);
			iput(&parent->vfs_inode);
		}
	} else {
		ret = btrfs_inode_inherit_props(trans, BTRFS_I(inode),
+4 −3
Original line number Diff line number Diff line
@@ -1832,7 +1832,6 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
	struct btrfs_path *path;
	struct btrfs_key key, key2;
	struct extent_buffer *leaf;
	struct inode *temp_inode;
	char *ptr;
	int slot;
	int len;
@@ -1860,6 +1859,8 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
		key.type = BTRFS_INODE_REF_KEY;
		key.offset = (u64)-1;
		while (1) {
			struct btrfs_inode *temp_inode;

			ret = btrfs_search_backwards(root, &key, path);
			if (ret < 0)
				goto out_put;
@@ -1914,9 +1915,9 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
				ret = PTR_ERR(temp_inode);
				goto out_put;
			}
			ret = inode_permission(idmap, temp_inode,
			ret = inode_permission(idmap, &temp_inode->vfs_inode,
					       MAY_READ | MAY_EXEC);
			iput(temp_inode);
			iput(&temp_inode->vfs_inode);
			if (ret) {
				ret = -EACCES;
				goto out_put;
Loading