diff options
author | David Sterba <dsterba@suse.com> | 2015-11-10 12:53:56 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-01-07 09:20:54 -0500 |
commit | a1ee736268448d74af25737568e383acb84c3c18 (patch) | |
tree | 2216e2f064209ade5011543d89da9f3dfbb075c8 | |
parent | 4fb72bf2e913ca3798afd9e226e2416918936e49 (diff) |
btrfs: do an allocation earlier during snapshot creation
We can allocate pending_snapshot earlier and do not have to do cleanup
in case of failure.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/ioctl.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6e896415a734..fa25091e10ab 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -655,22 +655,20 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
655 | if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) | 655 | if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) |
656 | return -EINVAL; | 656 | return -EINVAL; |
657 | 657 | ||
658 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | ||
659 | if (!pending_snapshot) | ||
660 | return -ENOMEM; | ||
661 | |||
658 | atomic_inc(&root->will_be_snapshoted); | 662 | atomic_inc(&root->will_be_snapshoted); |
659 | smp_mb__after_atomic(); | 663 | smp_mb__after_atomic(); |
660 | btrfs_wait_for_no_snapshoting_writes(root); | 664 | btrfs_wait_for_no_snapshoting_writes(root); |
661 | 665 | ||
662 | ret = btrfs_start_delalloc_inodes(root, 0); | 666 | ret = btrfs_start_delalloc_inodes(root, 0); |
663 | if (ret) | 667 | if (ret) |
664 | goto out; | 668 | goto dec_and_free; |
665 | 669 | ||
666 | btrfs_wait_ordered_extents(root, -1); | 670 | btrfs_wait_ordered_extents(root, -1); |
667 | 671 | ||
668 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | ||
669 | if (!pending_snapshot) { | ||
670 | ret = -ENOMEM; | ||
671 | goto out; | ||
672 | } | ||
673 | |||
674 | btrfs_init_block_rsv(&pending_snapshot->block_rsv, | 672 | btrfs_init_block_rsv(&pending_snapshot->block_rsv, |
675 | BTRFS_BLOCK_RSV_TEMP); | 673 | BTRFS_BLOCK_RSV_TEMP); |
676 | /* | 674 | /* |
@@ -686,7 +684,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, | |||
686 | &pending_snapshot->qgroup_reserved, | 684 | &pending_snapshot->qgroup_reserved, |
687 | false); | 685 | false); |
688 | if (ret) | 686 | if (ret) |
689 | goto free; | 687 | goto dec_and_free; |
690 | 688 | ||
691 | pending_snapshot->dentry = dentry; | 689 | pending_snapshot->dentry = dentry; |
692 | pending_snapshot->root = root; | 690 | pending_snapshot->root = root; |
@@ -737,11 +735,11 @@ fail: | |||
737 | btrfs_subvolume_release_metadata(BTRFS_I(dir)->root, | 735 | btrfs_subvolume_release_metadata(BTRFS_I(dir)->root, |
738 | &pending_snapshot->block_rsv, | 736 | &pending_snapshot->block_rsv, |
739 | pending_snapshot->qgroup_reserved); | 737 | pending_snapshot->qgroup_reserved); |
740 | free: | 738 | dec_and_free: |
741 | kfree(pending_snapshot); | ||
742 | out: | ||
743 | if (atomic_dec_and_test(&root->will_be_snapshoted)) | 739 | if (atomic_dec_and_test(&root->will_be_snapshoted)) |
744 | wake_up_atomic_t(&root->will_be_snapshoted); | 740 | wake_up_atomic_t(&root->will_be_snapshoted); |
741 | kfree(pending_snapshot); | ||
742 | |||
745 | return ret; | 743 | return ret; |
746 | } | 744 | } |
747 | 745 | ||