btrfs: preallocate path for snapshot creation at ioctl time
authorDavid Sterba <dsterba@suse.com>
Tue, 10 Nov 2015 17:54:03 +0000 (18:54 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 7 Jan 2016 14:20:55 +0000 (15:20 +0100)
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>
fs/btrfs/ioctl.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 27fc660b0ff33e12f1e739af5daa48fa65dcc5da..3d9b27d2176e7d075c0eb1384a772a434592c7e7 100644 (file)
@@ -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),
                        GFP_NOFS);
-       if (!pending_snapshot->root_item) {
+       pending_snapshot->path = btrfs_alloc_path();
+       if (!pending_snapshot->root_item || !pending_snapshot->path) {
                ret = -ENOMEM;
                goto free_pending;
        }
@@ -747,6 +748,7 @@ dec_and_free:
                wake_up_atomic_t(&root->will_be_snapshoted);
 free_pending:
        kfree(pending_snapshot->root_item);
+       btrfs_free_path(pending_snapshot->path);
        kfree(pending_snapshot);
 
        return ret;
index 2074106122d9ab5b2c8d6074eb7f7624000b4cd8..be463b7f1f30150e3baf7992e0df637d9862c0ee 100644 (file)
@@ -1319,11 +1319,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        u64 root_flags;
        uuid_le new_uuid;
 
-       path = btrfs_alloc_path();
-       if (!path) {
-               pending->error = -ENOMEM;
-               return 0;
-       }
+       ASSERT(pending->path);
+       path = pending->path;
 
        ASSERT(pending->root_item);
        new_root_item = pending->root_item;
@@ -1561,6 +1558,8 @@ no_free_objectid:
        kfree(new_root_item);
        pending->root_item = NULL;
        btrfs_free_path(path);
+       pending->path = NULL;
+
        return ret;
 }
 
index b6f9a3c944685136c72f7d8bd0a76e3809f8047a..72be51f7ca2fbf92507f2e2f36344a6b0a45f1a8 100644 (file)
@@ -140,6 +140,7 @@ struct btrfs_pending_snapshot {
        struct btrfs_root_item *root_item;
        struct btrfs_root *snap;
        struct btrfs_qgroup_inherit *inherit;
+       struct btrfs_path *path;
        /* block reservation for the operation */
        struct btrfs_block_rsv block_rsv;
        u64 qgroup_reserved;