diff options
author | Robbie Ko <robbieko@synology.com> | 2018-05-08 18:11:37 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-05-28 18:07:32 +0200 |
commit | 35c8eda12fc69e8a3f67c4615050ca4e76adec32 (patch) | |
tree | d0c820fdc66b62d5ecabd1e48cb246880a8d66ab | |
parent | 2335efafa63f0c675ebb4f8908fff9e972fb8a58 (diff) |
btrfs: incremental send, move allocation until it's needed in orphan_dir_info
Move the allocation after the search when it's clear that the new entry
will be added.
Signed-off-by: Robbie Ko <robbieko@synology.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/send.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 6e8184f239e0..29cfc0df1f27 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2844,12 +2844,6 @@ add_orphan_dir_info(struct send_ctx *sctx, u64 dir_ino) struct rb_node *parent = NULL; struct orphan_dir_info *entry, *odi; - odi = kmalloc(sizeof(*odi), GFP_KERNEL); - if (!odi) - return ERR_PTR(-ENOMEM); - odi->ino = dir_ino; - odi->gen = 0; - while (*p) { parent = *p; entry = rb_entry(parent, struct orphan_dir_info, node); @@ -2858,11 +2852,16 @@ add_orphan_dir_info(struct send_ctx *sctx, u64 dir_ino) } else if (dir_ino > entry->ino) { p = &(*p)->rb_right; } else { - kfree(odi); return entry; } } + odi = kmalloc(sizeof(*odi), GFP_KERNEL); + if (!odi) + return ERR_PTR(-ENOMEM); + odi->ino = dir_ino; + odi->gen = 0; + rb_link_node(&odi->node, parent, p); rb_insert_color(&odi->node, &sctx->orphan_dirs); return odi; |