diff options
author | David Sterba <dsterba@suse.com> | 2015-11-10 18:54:00 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-01-07 15:20:54 +0100 |
commit | b0c0ea6338d5018e02d27c5315084fb1a5d099f6 (patch) | |
tree | bf2aa288dd2d98143b12ea1753739491c7eda54d /fs/btrfs/ioctl.c | |
parent | a1ee736268448d74af25737568e383acb84c3c18 (diff) | |
download | op-kernel-dev-b0c0ea6338d5018e02d27c5315084fb1a5d099f6.zip op-kernel-dev-b0c0ea6338d5018e02d27c5315084fb1a5d099f6.tar.gz |
btrfs: allocate root item at snapshot ioctl time
The actual snapshot creation is delayed until transaction commit. If we
cannot get enough memory for the root item there, we have to fail the
whole transaction commit which is bad. So we'll allocate the memory at
the ioctl call and pass it along with the pending_snapshot struct. The
potential ENOMEM will be returned to the caller of snapshot ioctl.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r-- | fs/btrfs/ioctl.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fa25091..27fc660 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -659,6 +659,13 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, if (!pending_snapshot) return -ENOMEM; + pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), + GFP_NOFS); + if (!pending_snapshot->root_item) { + ret = -ENOMEM; + goto free_pending; + } + atomic_inc(&root->will_be_snapshoted); smp_mb__after_atomic(); btrfs_wait_for_no_snapshoting_writes(root); @@ -738,6 +745,8 @@ fail: dec_and_free: if (atomic_dec_and_test(&root->will_be_snapshoted)) wake_up_atomic_t(&root->will_be_snapshoted); +free_pending: + kfree(pending_snapshot->root_item); kfree(pending_snapshot); return ret; |