btrfs-progs: convert: use on-stack path buffer in create_image
We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
aca69c9d39
commit
c0807cbfc4
|
@ -968,7 +968,7 @@ static int create_image(struct btrfs_root *root,
|
||||||
{
|
{
|
||||||
struct btrfs_inode_item buf;
|
struct btrfs_inode_item buf;
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
struct btrfs_path *path = NULL;
|
struct btrfs_path path;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct cache_extent *cache;
|
struct cache_extent *cache;
|
||||||
struct cache_tree used_tmp;
|
struct cache_tree used_tmp;
|
||||||
|
@ -985,6 +985,7 @@ static int create_image(struct btrfs_root *root,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
cache_tree_init(&used_tmp);
|
cache_tree_init(&used_tmp);
|
||||||
|
btrfs_init_path(&path);
|
||||||
|
|
||||||
ret = btrfs_find_free_objectid(trans, root, BTRFS_FIRST_FREE_OBJECTID,
|
ret = btrfs_find_free_objectid(trans, root, BTRFS_FIRST_FREE_OBJECTID,
|
||||||
&ino);
|
&ino);
|
||||||
|
@ -1001,24 +1002,19 @@ static int create_image(struct btrfs_root *root,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
|
||||||
if (!path) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
key.objectid = ino;
|
key.objectid = ino;
|
||||||
key.type = BTRFS_INODE_ITEM_KEY;
|
key.type = BTRFS_INODE_ITEM_KEY;
|
||||||
key.offset = 0;
|
key.offset = 0;
|
||||||
|
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
ret = btrfs_search_slot(trans, root, &key, &path, 0, 1);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = (ret > 0 ? -ENOENT : ret);
|
ret = (ret > 0 ? -ENOENT : ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
read_extent_buffer(path->nodes[0], &buf,
|
read_extent_buffer(path.nodes[0], &buf,
|
||||||
btrfs_item_ptr_offset(path->nodes[0], path->slots[0]),
|
btrfs_item_ptr_offset(path.nodes[0], path.slots[0]),
|
||||||
sizeof(buf));
|
sizeof(buf));
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(&path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new used space cache, which doesn't contain the reserved
|
* Create a new used space cache, which doesn't contain the reserved
|
||||||
|
@ -1056,18 +1052,18 @@ static int create_image(struct btrfs_root *root,
|
||||||
key.objectid = ino;
|
key.objectid = ino;
|
||||||
key.type = BTRFS_INODE_ITEM_KEY;
|
key.type = BTRFS_INODE_ITEM_KEY;
|
||||||
key.offset = 0;
|
key.offset = 0;
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
ret = btrfs_search_slot(trans, root, &key, &path, 0, 1);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = (ret > 0 ? -ENOENT : ret);
|
ret = (ret > 0 ? -ENOENT : ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
btrfs_set_stack_inode_size(&buf, cfg->num_bytes);
|
btrfs_set_stack_inode_size(&buf, cfg->num_bytes);
|
||||||
write_extent_buffer(path->nodes[0], &buf,
|
write_extent_buffer(path.nodes[0], &buf,
|
||||||
btrfs_item_ptr_offset(path->nodes[0], path->slots[0]),
|
btrfs_item_ptr_offset(path.nodes[0], path.slots[0]),
|
||||||
sizeof(buf));
|
sizeof(buf));
|
||||||
out:
|
out:
|
||||||
free_extent_cache_tree(&used_tmp);
|
free_extent_cache_tree(&used_tmp);
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
btrfs_commit_transaction(trans, root);
|
btrfs_commit_transaction(trans, root);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue