Commit 8546b570 authored by David Sterba's avatar David Sterba

btrfs: preallocate path for snapshot creation at ioctl time

We can also preallocate btrfs_path that's used during pending snapshot
creation and avoid another late ENOMEM failure.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent b0c0ea63
...@@ -661,7 +661,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, ...@@ -661,7 +661,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item),
GFP_NOFS); GFP_NOFS);
if (!pending_snapshot->root_item) { pending_snapshot->path = btrfs_alloc_path();
if (!pending_snapshot->root_item || !pending_snapshot->path) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_pending; goto free_pending;
} }
...@@ -747,6 +748,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, ...@@ -747,6 +748,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
wake_up_atomic_t(&root->will_be_snapshoted); wake_up_atomic_t(&root->will_be_snapshoted);
free_pending: free_pending:
kfree(pending_snapshot->root_item); kfree(pending_snapshot->root_item);
btrfs_free_path(pending_snapshot->path);
kfree(pending_snapshot); kfree(pending_snapshot);
return ret; return ret;
......
...@@ -1319,11 +1319,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1319,11 +1319,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
u64 root_flags; u64 root_flags;
uuid_le new_uuid; uuid_le new_uuid;
path = btrfs_alloc_path(); ASSERT(pending->path);
if (!path) { path = pending->path;
pending->error = -ENOMEM;
return 0;
}
ASSERT(pending->root_item); ASSERT(pending->root_item);
new_root_item = pending->root_item; new_root_item = pending->root_item;
...@@ -1561,6 +1558,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1561,6 +1558,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
kfree(new_root_item); kfree(new_root_item);
pending->root_item = NULL; pending->root_item = NULL;
btrfs_free_path(path); btrfs_free_path(path);
pending->path = NULL;
return ret; return ret;
} }
......
...@@ -140,6 +140,7 @@ struct btrfs_pending_snapshot { ...@@ -140,6 +140,7 @@ struct btrfs_pending_snapshot {
struct btrfs_root_item *root_item; struct btrfs_root_item *root_item;
struct btrfs_root *snap; struct btrfs_root *snap;
struct btrfs_qgroup_inherit *inherit; struct btrfs_qgroup_inherit *inherit;
struct btrfs_path *path;
/* block reservation for the operation */ /* block reservation for the operation */
struct btrfs_block_rsv block_rsv; struct btrfs_block_rsv block_rsv;
u64 qgroup_reserved; u64 qgroup_reserved;
......
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