Skip to content

Commit 8546b57

Browse files
committed
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: David Sterba <[email protected]>
1 parent b0c0ea6 commit 8546b57

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

fs/btrfs/ioctl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
661661

662662
pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item),
663663
GFP_NOFS);
664-
if (!pending_snapshot->root_item) {
664+
pending_snapshot->path = btrfs_alloc_path();
665+
if (!pending_snapshot->root_item || !pending_snapshot->path) {
665666
ret = -ENOMEM;
666667
goto free_pending;
667668
}
@@ -747,6 +748,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
747748
wake_up_atomic_t(&root->will_be_snapshoted);
748749
free_pending:
749750
kfree(pending_snapshot->root_item);
751+
btrfs_free_path(pending_snapshot->path);
750752
kfree(pending_snapshot);
751753

752754
return ret;

fs/btrfs/transaction.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,11 +1319,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
13191319
u64 root_flags;
13201320
uuid_le new_uuid;
13211321

1322-
path = btrfs_alloc_path();
1323-
if (!path) {
1324-
pending->error = -ENOMEM;
1325-
return 0;
1326-
}
1322+
ASSERT(pending->path);
1323+
path = pending->path;
13271324

13281325
ASSERT(pending->root_item);
13291326
new_root_item = pending->root_item;
@@ -1561,6 +1558,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
15611558
kfree(new_root_item);
15621559
pending->root_item = NULL;
15631560
btrfs_free_path(path);
1561+
pending->path = NULL;
1562+
15641563
return ret;
15651564
}
15661565

fs/btrfs/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct btrfs_pending_snapshot {
140140
struct btrfs_root_item *root_item;
141141
struct btrfs_root *snap;
142142
struct btrfs_qgroup_inherit *inherit;
143+
struct btrfs_path *path;
143144
/* block reservation for the operation */
144145
struct btrfs_block_rsv block_rsv;
145146
u64 qgroup_reserved;

0 commit comments

Comments
 (0)