btrfs: remaining BTRFS_PATH_AUTO_FREE conversions
David Sterba
maintainerPATCH 1/1 btrfs: remaining BTRFS_PATH_AUTO_FREE conversions
Do the remaining btrfs_path conversion to the auto cleaning, this seems to be the last one. Most of the conversions are trivial, only adding the declaration and removing the freeing, or changing the goto patterns to return.
There are some functions with many changes, like __btrfs_free_extent(), btrfs_remove_from_free_space_tree() or btrfs_add_to_free_space_tree() but it still follows the same pattern.
Signed-off-by David Sterba <[email protected]>
--- fs/btrfs/block-group.c | 3 +- fs/btrfs/dir-item.c | 3 +- fs/btrfs/extent-tree.c | 41 +++++------ fs/btrfs/free-space-tree.c | 29 ++++---- fs/btrfs/inode-item.c | 3 +- fs/btrfs/inode.c | 3 +- fs/btrfs/ioctl.c | 37 ++++------ fs/btrfs/qgroup.c | 142 ++++++++++++++----------------------- fs/btrfs/super.c | 10 +-- fs/btrfs/tree-log.c | 4 +- fs/btrfs/volumes.c | 3 +- fs/btrfs/xattr.c | 3 +- 12 files changed, 105 insertions(+), 176 deletions(-)
fs/btrfs/block-group.c +1 -2
@@ -1065,7 +1065,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, struct btrfs_chunk_map *map) {struct btrfs_fs_info *fs_info = trans->fs_info; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_block_group *block_group;struct btrfs_free_cluster *cluster;struct inode *inode;
@@ -1305,7 +1305,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,btrfs_put_block_group (block_group);if (remove_rsv)btrfs_dec_delayed_refs_rsv_bg_updates (fs_info); -btrfs_free_path (path);return ret; }
fs/btrfs/dir-item.c +1 -2
@@ -112,7 +112,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,int ret =0 ;int ret2 =0 ;struct btrfs_root *root = dir->root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_dir_item *dir_item;struct extent_buffer *leaf;unsigned long name_ptr;
@@ -164,7 +164,6 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, ret2 =btrfs_insert_delayed_dir_index (trans, name->name, name->len, dir, &disk_key, type, index); out_free: -btrfs_free_path (path);if (ret)return ret;if (ret2)
fs/btrfs/extent-tree.c +16 -25
139 lines not on this page · raw message
fs/btrfs/free-space-tree.c +13 -16
@@ -833,7 +833,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans, u64 start, u64 size) {struct btrfs_block_group *block_group; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);int ret;if (!btrfs_fs_compat_ro (trans->fs_info,FREE_SPACE_TREE ))
@@ -843,7 +843,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,if (unlikely (!path)) { ret = -ENOMEM ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } block_group =btrfs_lookup_block_group (trans->fs_info, start);
@@ -851,7 +851,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,DEBUG_WARN ("no block group found for start=%llu" , start); ret = -ENOENT ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; }mutex_lock (&block_group->free_space_lock);
@@ -861,8 +861,7 @@ int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,btrfs_abort_transaction (trans, ret);btrfs_put_block_group (block_group); -out: -btrfs_free_path (path); +return ret; }
@@ -1015,7 +1014,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans, u64 start, u64 size) {struct btrfs_block_group *block_group; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);int ret;if (!btrfs_fs_compat_ro (trans->fs_info,FREE_SPACE_TREE ))
@@ -1025,7 +1024,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,if (unlikely (!path)) { ret = -ENOMEM ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } block_group =btrfs_lookup_block_group (trans->fs_info, start);
@@ -1033,7 +1032,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,DEBUG_WARN ("no block group found for start=%llu" , start); ret = -ENOENT ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; }mutex_lock (&block_group->free_space_lock);
@@ -1043,8 +1042,7 @@ int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,btrfs_abort_transaction (trans, ret);btrfs_put_block_group (block_group); -out: -btrfs_free_path (path); +return ret; }
@@ -1458,7 +1456,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group) {struct btrfs_root *root =btrfs_free_space_root (block_group); -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key, found_key;struct extent_buffer *leaf;u64 start, end;
@@ -1477,7 +1475,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,if (unlikely (!path)) { ret = -ENOMEM ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } start = block_group->start;
@@ -1491,7 +1489,7 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans, ret =btrfs_search_prev_slot (trans, root, &key, path,-1 ,1 );if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } leaf = path->nodes[0 ];
@@ -1522,14 +1520,13 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans, ret =btrfs_del_items (trans, root, path, path->slots[0 ], nr);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; }btrfs_release_path (path); } ret =0 ; -out: -btrfs_free_path (path); +return ret; }
fs/btrfs/inode-item.c +1 -2
@@ -444,7 +444,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_truncate_control *control) {struct btrfs_fs_info *fs_info = root->fs_info; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *leaf;struct btrfs_file_extent_item *fi;struct btrfs_key key;
@@ -730,6 +730,5 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,if (!ret && control->last_size > new_size) control->last_size = new_size; -btrfs_free_path (path);return ret; }
fs/btrfs/inode.c +1 -2
@@ -4458,7 +4458,7 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, {struct btrfs_root *root = dir->root;struct btrfs_inode *inode =BTRFS_I (d_inode (dentry)); -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *leaf;struct btrfs_dir_item *di;struct btrfs_key key;
@@ -4551,7 +4551,6 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,if (ret)btrfs_abort_transaction (trans, ret); out: -btrfs_free_path (path);fscrypt_free_filename (&fname);return ret; }
fs/btrfs/ioctl.c +13 -24
@@ -1603,7 +1603,7 @@ static noinline int search_ioctl(struct btrfs_root *root, {struct btrfs_fs_info *info = root->fs_info;struct btrfs_key key; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);int ret;int num_found =0 ;unsigned long sk_offset =0 ;
@@ -1623,10 +1623,8 @@ static noinline int search_ioctl(struct btrfs_root *root, }else {/* Look up the root from the arguments. */ root =btrfs_get_fs_root (info, sk->tree_id, true); -if (IS_ERR (root)) { -btrfs_free_path (path); +if (IS_ERR (root))return PTR_ERR (root); - } } key.objectid = sk->min_objectid;
@@ -1660,7 +1658,6 @@ static noinline int search_ioctl(struct btrfs_root *root, sk->nr_items = num_found;btrfs_put_root (root); -btrfs_free_path (path);return ret; }
@@ -1743,7 +1740,7 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,int total_len =0 ;struct btrfs_inode_ref *iref;struct extent_buffer *l; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);if (dirid ==BTRFS_FIRST_FREE_OBJECTID ) { name[0 ]='\0' ;
@@ -1804,7 +1801,6 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, ret =0 ; out:btrfs_put_root (root); -btrfs_free_path (path);return ret; }
@@ -1821,7 +1817,7 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,struct btrfs_inode_ref *iref;struct btrfs_root_ref *rref;struct btrfs_root *root =NULL ; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key, key2;struct extent_buffer *leaf;char *ptr;
@@ -1842,10 +1838,8 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap, ptr = &args->path[BTRFS_INO_LOOKUP_USER_PATH_MAX -1 ]; root =btrfs_get_fs_root (fs_info, treeid, true); -if (IS_ERR (root)) { - ret =PTR_ERR (root); - goto out; - } +if (IS_ERR (root)) +return PTR_ERR (root); key.objectid = dirid; key.type =BTRFS_INODE_REF_KEY ;
@@ -1939,12 +1933,10 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap, key.type =BTRFS_ROOT_REF_KEY ; key.offset = args->treeid; ret =btrfs_search_slot (NULL , fs_info->tree_root, &key, path,0 ,0 ); -if (ret <0 ) { - goto out; - }else if (ret >0 ) { - ret = -ENOENT ; - goto out; - } +if (ret <0 ) +return ret; +else if (ret >0 ) +return -ENOENT ; leaf = path->nodes[0 ]; slot = path->slots[0 ];
@@ -1954,10 +1946,8 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap, item_len =btrfs_item_size (leaf, slot);/* Check if dirid in ROOT_REF corresponds to passed dirid */ rref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref); -if (args->dirid !=btrfs_root_ref_dirid (leaf, rref)) { - ret = -EINVAL ; - goto out; - } +if (args->dirid !=btrfs_root_ref_dirid (leaf, rref)) +return -EINVAL ;/* Copy subvolume's name */ item_off +=sizeof (struct btrfs_root_ref );
@@ -1967,8 +1957,7 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap, out_put:btrfs_put_root (root); -out: -btrfs_free_path (path); +return ret; }
fs/btrfs/qgroup.c +53 -89
389 lines not on this page · raw message
fs/btrfs/super.c +3 -7
@@ -807,17 +807,15 @@ char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,struct btrfs_root_ref *root_ref;struct btrfs_inode_ref *inode_ref;struct btrfs_key key; -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);char *name =NULL , *ptr;u64 dirid;int len;int ret; path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; - goto err; - } +if (!path) +return ERR_PTR (-ENOMEM ); name =kmalloc (PATH_MAX ,GFP_KERNEL );if (!name) {
@@ -905,7 +903,6 @@ char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, fs_root =NULL ; } -btrfs_free_path (path);if (ptr == name +PATH_MAX -1 ) { name[0 ] ='/' ; name[1 ] ='\0' ;
@@ -916,7 +913,6 @@ char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, err:btrfs_put_root (fs_root); -btrfs_free_path (path);kfree (name);return ERR_PTR (ret); }
fs/btrfs/tree-log.c +1 -3
@@ -2648,7 +2648,7 @@ static noinline int replay_dir_deletes(struct walk_control *wc,int ret =0 ;struct btrfs_key dir_key;struct btrfs_key found_key; -struct btrfs_path *log_path; +BTRFS_PATH_AUTO_FREE (log_path);struct btrfs_inode *dir; dir_key.objectid = dirid;
@@ -2665,7 +2665,6 @@ static noinline int replay_dir_deletes(struct walk_control *wc,* we replay the deletes before we copy in the inode item from the log. */ if (IS_ERR (dir)) { -btrfs_free_path (log_path); ret =PTR_ERR (dir);if (ret == -ENOENT ) ret =0 ;
@@ -2745,7 +2744,6 @@ static noinline int replay_dir_deletes(struct walk_control *wc, ret =0 ; out:btrfs_release_path (wc->subvol_path); -btrfs_free_path (log_path);iput (&dir->vfs_inode);return ret; }
fs/btrfs/volumes.c +1 -2
@@ -4054,7 +4054,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)struct btrfs_root *chunk_root = fs_info->chunk_root;u64 chunk_type;struct btrfs_chunk *chunk; -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;struct btrfs_key found_key;struct extent_buffer *leaf;
@@ -4225,7 +4225,6 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) goto again; } error: -btrfs_free_path (path);if (enospc_errors) {btrfs_info (fs_info,"%d enospc errors during balance" , enospc_errors);
fs/btrfs/xattr.c +1 -2
@@ -73,7 +73,7 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode, {struct btrfs_dir_item *di =NULL ;struct btrfs_root *root =BTRFS_I (inode)->root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);size_t name_len =strlen (name);int ret =0 ;
@@ -200,7 +200,6 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,*/ } out: -btrfs_free_path (path);if (!ret) {set_bit (BTRFS_INODE_COPY_EVERYTHING , &BTRFS_I (inode)->runtime_flags);
Signature · 1 line
2.51.1