diff options
| author | David Sterba <dsterba@suse.com> | 2015-11-10 12:54:03 -0500 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2016-01-07 09:20:55 -0500 |
| commit | 8546b570511f428838129c00e701eda481cd7c13 (patch) | |
| tree | bf8087d889e778e484afb12af3ee82edd5220e28 /fs/btrfs | |
| parent | b0c0ea6338d5018e02d27c5315084fb1a5d099f6 (diff) | |
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 <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
| -rw-r--r-- | fs/btrfs/ioctl.c | 4 | ||||
| -rw-r--r-- | fs/btrfs/transaction.c | 9 | ||||
| -rw-r--r-- | fs/btrfs/transaction.h | 1 |
3 files changed, 8 insertions, 6 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 27fc660b0ff3..3d9b27d2176e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
| @@ -661,7 +661,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
| 661 | 661 | ||
| 662 | pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), | 662 | pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), |
| 663 | GFP_NOFS); | 663 | GFP_NOFS); |
| 664 | if (!pending_snapshot->root_item) { | 664 | pending_snapshot->path = btrfs_alloc_path(); |
| 665 | if (!pending_snapshot->root_item || !pending_snapshot->path) { | ||
| 665 | ret = -ENOMEM; | 666 | ret = -ENOMEM; |
| 666 | goto free_pending; | 667 | goto free_pending; |
| 667 | } | 668 | } |
| @@ -747,6 +748,7 @@ dec_and_free: | |||
| 747 | wake_up_atomic_t(&root->will_be_snapshoted); | 748 | wake_up_atomic_t(&root->will_be_snapshoted); |
| 748 | free_pending: | 749 | free_pending: |
| 749 | kfree(pending_snapshot->root_item); | 750 | kfree(pending_snapshot->root_item); |
| 751 | btrfs_free_path(pending_snapshot->path); | ||
| 750 | kfree(pending_snapshot); | 752 | kfree(pending_snapshot); |
| 751 | 753 | ||
| 752 | return ret; | 754 | return ret; |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 2074106122d9..be463b7f1f30 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
| @@ -1319,11 +1319,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
| 1319 | u64 root_flags; | 1319 | u64 root_flags; |
| 1320 | uuid_le new_uuid; | 1320 | uuid_le new_uuid; |
| 1321 | 1321 | ||
| 1322 | path = btrfs_alloc_path(); | 1322 | ASSERT(pending->path); |
| 1323 | if (!path) { | 1323 | path = pending->path; |
| 1324 | pending->error = -ENOMEM; | ||
| 1325 | return 0; | ||
| 1326 | } | ||
| 1327 | 1324 | ||
| 1328 | ASSERT(pending->root_item); | 1325 | ASSERT(pending->root_item); |
| 1329 | new_root_item = pending->root_item; | 1326 | new_root_item = pending->root_item; |
| @@ -1561,6 +1558,8 @@ no_free_objectid: | |||
| 1561 | kfree(new_root_item); | 1558 | kfree(new_root_item); |
| 1562 | pending->root_item = NULL; | 1559 | pending->root_item = NULL; |
| 1563 | btrfs_free_path(path); | 1560 | btrfs_free_path(path); |
| 1561 | pending->path = NULL; | ||
| 1562 | |||
| 1564 | return ret; | 1563 | return ret; |
| 1565 | } | 1564 | } |
| 1566 | 1565 | ||
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index b6f9a3c94468..72be51f7ca2f 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
| @@ -140,6 +140,7 @@ struct btrfs_pending_snapshot { | |||
| 140 | struct btrfs_root_item *root_item; | 140 | struct btrfs_root_item *root_item; |
| 141 | struct btrfs_root *snap; | 141 | struct btrfs_root *snap; |
| 142 | struct btrfs_qgroup_inherit *inherit; | 142 | struct btrfs_qgroup_inherit *inherit; |
| 143 | struct btrfs_path *path; | ||
| 143 | /* block reservation for the operation */ | 144 | /* block reservation for the operation */ |
| 144 | struct btrfs_block_rsv block_rsv; | 145 | struct btrfs_block_rsv block_rsv; |
| 145 | u64 qgroup_reserved; | 146 | u64 qgroup_reserved; |
