diff options
| author | Filipe Manana <fdmanana@suse.com> | 2025-11-19 17:59:52 +0000 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2025-11-25 01:53:33 +0100 |
| commit | 5c9cac55b7a2c203cc135560fce053beea173c0f (patch) | |
| tree | 7d1f743d02c28d8dc812a034678f02ae24d6bb17 /fs/btrfs | |
| parent | 7c3acdb998dd723ac791cd4a47f13599d76a1f58 (diff) | |
btrfs: send: do not allocate memory for xattr data when checking it exists
When checking if xattrs were deleted we don't care about their data, but
we are allocating memory for the data and copying it, which only wastes
time and can result in an unnecessary error in case the allocation fails.
So stop allocating memory and copying data by making find_xattr() and
__find_xattr() skip those steps if the given data buffer is NULL.
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
| -rw-r--r-- | fs/btrfs/send.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 9da559f79f7f..130aabced207 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4943,6 +4943,7 @@ struct find_xattr_ctx { int found_idx; char *found_data; int found_data_len; + bool copy_data; }; static int __find_xattr(int num, struct btrfs_key *di_key, const char *name, @@ -4954,9 +4955,11 @@ static int __find_xattr(int num, struct btrfs_key *di_key, const char *name, strncmp(name, ctx->name, name_len) == 0) { ctx->found_idx = num; ctx->found_data_len = data_len; - ctx->found_data = kmemdup(data, data_len, GFP_KERNEL); - if (!ctx->found_data) - return -ENOMEM; + if (ctx->copy_data) { + ctx->found_data = kmemdup(data, data_len, GFP_KERNEL); + if (!ctx->found_data) + return -ENOMEM; + } return 1; } return 0; @@ -4976,6 +4979,7 @@ static int find_xattr(struct btrfs_root *root, ctx.found_idx = -1; ctx.found_data = NULL; ctx.found_data_len = 0; + ctx.copy_data = (data != NULL); ret = iterate_dir_item(root, path, __find_xattr, &ctx); if (ret < 0) @@ -4987,7 +4991,7 @@ static int find_xattr(struct btrfs_root *root, *data = ctx.found_data; *data_len = ctx.found_data_len; } else { - kfree(ctx.found_data); + ASSERT(ctx.found_data == NULL); } return ctx.found_idx; } |