Commit 10934c13 authored by David Sterba's avatar David Sterba
Browse files

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: default avatarDavid Sterba <dsterba@suse.com>
parent 5c9cac55
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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;
}

+1 −2
Original line number Diff line number Diff line
@@ -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)
+16 −25
Original line number Diff line number Diff line
@@ -3085,7 +3085,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
{
	struct btrfs_fs_info *info = trans->fs_info;
	struct btrfs_key key;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct btrfs_root *extent_root;
	struct extent_buffer *leaf;
	struct btrfs_extent_item *ei;
@@ -3120,7 +3120,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
			   node->bytenr, refs_to_drop);
		ret = -EINVAL;
		btrfs_abort_transaction(trans, ret);
		goto out;
		return ret;
	}

	if (is_data)
@@ -3165,15 +3165,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
				abort_and_dump(trans, path,
"invalid iref slot %u, no EXTENT/METADATA_ITEM found but has inline extent ref",
					   path->slots[0]);
				ret = -EUCLEAN;
				goto out;
				return -EUCLEAN;
			}
			/* Must be SHARED_* item, remove the backref first */
			ret = remove_extent_backref(trans, extent_root, path,
						    NULL, refs_to_drop, is_data);
			if (unlikely(ret)) {
				btrfs_abort_transaction(trans, ret);
				goto out;
				return ret;
			}
			btrfs_release_path(path);

@@ -3222,7 +3221,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
			}
			if (unlikely(ret < 0)) {
				btrfs_abort_transaction(trans, ret);
				goto out;
				return ret;
			}
			extent_slot = path->slots[0];
		}
@@ -3231,10 +3230,10 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
"unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu slot %d",
			       bytenr, node->parent, node->ref_root, owner_objectid,
			       owner_offset, path->slots[0]);
		goto out;
		return ret;
	} else {
		btrfs_abort_transaction(trans, ret);
		goto out;
		return ret;
	}

	leaf = path->nodes[0];
@@ -3245,7 +3244,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
			  "unexpected extent item size, has %u expect >= %zu",
			  item_size, sizeof(*ei));
		btrfs_abort_transaction(trans, ret);
		goto out;
		return ret;
	}
	ei = btrfs_item_ptr(leaf, extent_slot,
			    struct btrfs_extent_item);
@@ -3259,8 +3258,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
				       key.objectid, key.type, key.offset,
				       path->slots[0], owner_objectid, item_size,
				       sizeof(*ei) + sizeof(*bi));
			ret = -EUCLEAN;
			goto out;
			return -EUCLEAN;
		}
		bi = (struct btrfs_tree_block_info *)(ei + 1);
		WARN_ON(owner_objectid != btrfs_tree_block_level(leaf, bi));
@@ -3271,8 +3269,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
		abort_and_dump(trans, path,
		"trying to drop %d refs but we only have %llu for bytenr %llu slot %u",
			       refs_to_drop, refs, bytenr, path->slots[0]);
		ret = -EUCLEAN;
		goto out;
		return -EUCLEAN;
	}
	refs -= refs_to_drop;

@@ -3288,8 +3285,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
				abort_and_dump(trans, path,
"invalid iref, got inlined extent ref but no EXTENT/METADATA_ITEM found, slot %u",
					       path->slots[0]);
				ret = -EUCLEAN;
				goto out;
				return -EUCLEAN;
			}
		} else {
			btrfs_set_extent_refs(leaf, ei, refs);
@@ -3299,7 +3295,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
						    iref, refs_to_drop, is_data);
			if (unlikely(ret)) {
				btrfs_abort_transaction(trans, ret);
				goto out;
				return ret;
			}
		}
	} else {
@@ -3319,8 +3315,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
		"invalid refs_to_drop, current refs %u refs_to_drop %u slot %u",
					       extent_data_ref_count(path, iref),
					       refs_to_drop, path->slots[0]);
				ret = -EUCLEAN;
				goto out;
				return -EUCLEAN;
			}
			if (iref) {
				if (unlikely(path->slots[0] != extent_slot)) {
@@ -3328,8 +3323,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
"invalid iref, extent item key " BTRFS_KEY_FMT " slot %u doesn't have wanted iref",
						       BTRFS_KEY_FMT_VALUE(&key),
						       path->slots[0]);
					ret = -EUCLEAN;
					goto out;
					return -EUCLEAN;
				}
			} else {
				/*
@@ -3342,8 +3336,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
					abort_and_dump(trans, path,
	"invalid SHARED_* item slot %u, previous item is not EXTENT/METADATA_ITEM",
						       path->slots[0]);
					ret = -EUCLEAN;
					goto out;
					return -EUCLEAN;
				}
				path->slots[0] = extent_slot;
				num_to_del = 2;
@@ -3364,7 +3357,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
				      num_to_del);
		if (unlikely(ret)) {
			btrfs_abort_transaction(trans, ret);
			goto out;
			return ret;
		}
		btrfs_release_path(path);

@@ -3372,8 +3365,6 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
	}
	btrfs_release_path(path);

out:
	btrfs_free_path(path);
	return ret;
}

+13 −16
Original line number Diff line number Diff line
@@ -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;
}

+1 −2
Original line number Diff line number Diff line
@@ -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;
}
Loading