aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dbe1aabf96cd..791eab19e330 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -26,7 +26,6 @@
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/string.h> 28#include <linux/string.h>
29#include <linux/smp_lock.h>
30#include <linux/backing-dev.h> 29#include <linux/backing-dev.h>
31#include <linux/mpage.h> 30#include <linux/mpage.h>
32#include <linux/swap.h> 31#include <linux/swap.h>
@@ -3580,12 +3579,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3580 owner = 1; 3579 owner = 1;
3581 BTRFS_I(inode)->block_group = 3580 BTRFS_I(inode)->block_group =
3582 btrfs_find_block_group(root, 0, alloc_hint, owner); 3581 btrfs_find_block_group(root, 0, alloc_hint, owner);
3583 if ((mode & S_IFREG)) {
3584 if (btrfs_test_opt(root, NODATASUM))
3585 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
3586 if (btrfs_test_opt(root, NODATACOW))
3587 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
3588 }
3589 3582
3590 key[0].objectid = objectid; 3583 key[0].objectid = objectid;
3591 btrfs_set_key_type(&key[0], BTRFS_INODE_ITEM_KEY); 3584 btrfs_set_key_type(&key[0], BTRFS_INODE_ITEM_KEY);
@@ -3640,6 +3633,13 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3640 3633
3641 btrfs_inherit_iflags(inode, dir); 3634 btrfs_inherit_iflags(inode, dir);
3642 3635
3636 if ((mode & S_IFREG)) {
3637 if (btrfs_test_opt(root, NODATASUM))
3638 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
3639 if (btrfs_test_opt(root, NODATACOW))
3640 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
3641 }
3642
3643 insert_inode_hash(inode); 3643 insert_inode_hash(inode);
3644 inode_tree_add(inode); 3644 inode_tree_add(inode);
3645 return inode; 3645 return inode;
@@ -5082,6 +5082,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5082 u64 mask = BTRFS_I(inode)->root->sectorsize - 1; 5082 u64 mask = BTRFS_I(inode)->root->sectorsize - 1;
5083 struct extent_map *em; 5083 struct extent_map *em;
5084 struct btrfs_trans_handle *trans; 5084 struct btrfs_trans_handle *trans;
5085 struct btrfs_root *root;
5085 int ret; 5086 int ret;
5086 5087
5087 alloc_start = offset & ~mask; 5088 alloc_start = offset & ~mask;
@@ -5100,6 +5101,13 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5100 goto out; 5101 goto out;
5101 } 5102 }
5102 5103
5104 root = BTRFS_I(inode)->root;
5105
5106 ret = btrfs_check_data_free_space(root, inode,
5107 alloc_end - alloc_start);
5108 if (ret)
5109 goto out;
5110
5103 locked_end = alloc_end - 1; 5111 locked_end = alloc_end - 1;
5104 while (1) { 5112 while (1) {
5105 struct btrfs_ordered_extent *ordered; 5113 struct btrfs_ordered_extent *ordered;
@@ -5107,7 +5115,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5107 trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1); 5115 trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1);
5108 if (!trans) { 5116 if (!trans) {
5109 ret = -EIO; 5117 ret = -EIO;
5110 goto out; 5118 goto out_free;
5111 } 5119 }
5112 5120
5113 /* the extent lock is ordered inside the running 5121 /* the extent lock is ordered inside the running
@@ -5168,6 +5176,8 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5168 GFP_NOFS); 5176 GFP_NOFS);
5169 5177
5170 btrfs_end_transaction(trans, BTRFS_I(inode)->root); 5178 btrfs_end_transaction(trans, BTRFS_I(inode)->root);
5179out_free:
5180 btrfs_free_reserved_data_space(root, inode, alloc_end - alloc_start);
5171out: 5181out:
5172 mutex_unlock(&inode->i_mutex); 5182 mutex_unlock(&inode->i_mutex);
5173 return ret; 5183 return ret;