]> git.hungrycats.org Git - linux/commitdiff
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)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Tue, 19 Jan 2016 05:30:56 +0000 (00:30 -0500)
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>
(cherry picked from commit 8546b570511f428838129c00e701eda481cd7c13)
(cherry picked from commit aa8aee6b6eaf4757f1b31fb0d82e23fcd92c3286)

fs/btrfs/ioctl.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 8f3f0f7b5b7f7c68ff57e2e7fdc7e919637cbf91..34f11fccb0ed43debf4edb23fd8dcf164c80bcdf 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 ff10082096e20696f37eefe798c88afa37e07058..6a4d57aa8fec69e81899be3bcf4d09e2705417e4 100644 (file)
@@ -1360,11 +1360,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;
@@ -1602,6 +1599,8 @@ no_free_objectid:
        kfree(new_root_item);
        pending->root_item = NULL;
        btrfs_free_path(path);
+       pending->path = NULL;
+
        return ret;
 }
 
index 93487babed77140ce64c15ea84eded1ff1c3c5ae..f400c70ce47c4309162284ae63fb6055f39872ae 100644 (file)
@@ -141,6 +141,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;