Commit dce28150 authored by Goldwyn Rodrigues's avatar Goldwyn Rodrigues Committed by David Sterba

btrfs: allocate backref_ctx on stack in find_extent_clone

Instead of using kmalloc() to allocate backref_ctx, allocate backref_ctx
on stack. The size is reasonably small.

sizeof(backref_ctx) = 48
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent c853a578
...@@ -1307,7 +1307,7 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1307,7 +1307,7 @@ static int find_extent_clone(struct send_ctx *sctx,
u64 flags = 0; u64 flags = 0;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct extent_buffer *eb = path->nodes[0]; struct extent_buffer *eb = path->nodes[0];
struct backref_ctx *backref_ctx = NULL; struct backref_ctx backref_ctx = {0};
struct clone_root *cur_clone_root; struct clone_root *cur_clone_root;
struct btrfs_key found_key; struct btrfs_key found_key;
struct btrfs_path *tmp_path; struct btrfs_path *tmp_path;
...@@ -1322,12 +1322,6 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1322,12 +1322,6 @@ static int find_extent_clone(struct send_ctx *sctx,
/* We only use this path under the commit sem */ /* We only use this path under the commit sem */
tmp_path->need_commit_sem = 0; tmp_path->need_commit_sem = 0;
backref_ctx = kmalloc(sizeof(*backref_ctx), GFP_KERNEL);
if (!backref_ctx) {
ret = -ENOMEM;
goto out;
}
if (data_offset >= ino_size) { if (data_offset >= ino_size) {
/* /*
* There may be extents that lie behind the file's size. * There may be extents that lie behind the file's size.
...@@ -1392,12 +1386,12 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1392,12 +1386,12 @@ static int find_extent_clone(struct send_ctx *sctx,
cur_clone_root->found_refs = 0; cur_clone_root->found_refs = 0;
} }
backref_ctx->sctx = sctx; backref_ctx.sctx = sctx;
backref_ctx->found = 0; backref_ctx.found = 0;
backref_ctx->cur_objectid = ino; backref_ctx.cur_objectid = ino;
backref_ctx->cur_offset = data_offset; backref_ctx.cur_offset = data_offset;
backref_ctx->found_itself = 0; backref_ctx.found_itself = 0;
backref_ctx->extent_len = num_bytes; backref_ctx.extent_len = num_bytes;
/* /*
* The last extent of a file may be too large due to page alignment. * The last extent of a file may be too large due to page alignment.
...@@ -1405,7 +1399,7 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1405,7 +1399,7 @@ static int find_extent_clone(struct send_ctx *sctx,
* __iterate_backrefs work. * __iterate_backrefs work.
*/ */
if (data_offset + num_bytes >= ino_size) if (data_offset + num_bytes >= ino_size)
backref_ctx->extent_len = ino_size - data_offset; backref_ctx.extent_len = ino_size - data_offset;
/* /*
* Now collect all backrefs. * Now collect all backrefs.
...@@ -1416,12 +1410,12 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1416,12 +1410,12 @@ static int find_extent_clone(struct send_ctx *sctx,
extent_item_pos = 0; extent_item_pos = 0;
ret = iterate_extent_inodes(fs_info, found_key.objectid, ret = iterate_extent_inodes(fs_info, found_key.objectid,
extent_item_pos, 1, __iterate_backrefs, extent_item_pos, 1, __iterate_backrefs,
backref_ctx, false); &backref_ctx, false);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (!backref_ctx->found_itself) { if (!backref_ctx.found_itself) {
/* found a bug in backref code? */ /* found a bug in backref code? */
ret = -EIO; ret = -EIO;
btrfs_err(fs_info, btrfs_err(fs_info,
...@@ -1434,7 +1428,7 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1434,7 +1428,7 @@ static int find_extent_clone(struct send_ctx *sctx,
"find_extent_clone: data_offset=%llu, ino=%llu, num_bytes=%llu, logical=%llu", "find_extent_clone: data_offset=%llu, ino=%llu, num_bytes=%llu, logical=%llu",
data_offset, ino, num_bytes, logical); data_offset, ino, num_bytes, logical);
if (!backref_ctx->found) if (!backref_ctx.found)
btrfs_debug(fs_info, "no clones found"); btrfs_debug(fs_info, "no clones found");
cur_clone_root = NULL; cur_clone_root = NULL;
...@@ -1458,7 +1452,6 @@ static int find_extent_clone(struct send_ctx *sctx, ...@@ -1458,7 +1452,6 @@ static int find_extent_clone(struct send_ctx *sctx,
out: out:
btrfs_free_path(tmp_path); btrfs_free_path(tmp_path);
kfree(backref_ctx);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment