aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorJames Morris <jmorris@namei.org>2009-03-23 19:52:46 -0400
committerJames Morris <jmorris@namei.org>2009-03-23 19:52:46 -0400
commit703a3cd72817e99201cef84a8a7aecc60b2b3581 (patch)
tree3e943755178ff410694722bb031f523136fbc432 /fs/btrfs/inode.c
parentdf7f54c012b92ec93d56b68547351dcdf8a163d3 (diff)
parent8e0ee43bc2c3e19db56a4adaa9a9b04ce885cd84 (diff)
Merge branch 'master' into next
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c142
1 files changed, 83 insertions, 59 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 8adfe059ab41..7d4f948bc22a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -34,7 +34,6 @@
34#include <linux/statfs.h> 34#include <linux/statfs.h>
35#include <linux/compat.h> 35#include <linux/compat.h>
36#include <linux/bit_spinlock.h> 36#include <linux/bit_spinlock.h>
37#include <linux/version.h>
38#include <linux/xattr.h> 37#include <linux/xattr.h>
39#include <linux/posix_acl.h> 38#include <linux/posix_acl.h>
40#include <linux/falloc.h> 39#include <linux/falloc.h>
@@ -51,6 +50,7 @@
51#include "tree-log.h" 50#include "tree-log.h"
52#include "ref-cache.h" 51#include "ref-cache.h"
53#include "compression.h" 52#include "compression.h"
53#include "locking.h"
54 54
55struct btrfs_iget_args { 55struct btrfs_iget_args {
56 u64 ino; 56 u64 ino;
@@ -91,32 +91,14 @@ static noinline int cow_file_range(struct inode *inode,
91 u64 start, u64 end, int *page_started, 91 u64 start, u64 end, int *page_started,
92 unsigned long *nr_written, int unlock); 92 unsigned long *nr_written, int unlock);
93 93
94/* 94static int btrfs_init_inode_security(struct inode *inode, struct inode *dir)
95 * a very lame attempt at stopping writes when the FS is 85% full. There
96 * are countless ways this is incorrect, but it is better than nothing.
97 */
98int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
99 int for_del)
100{ 95{
101 u64 total; 96 int err;
102 u64 used;
103 u64 thresh;
104 int ret = 0;
105
106 spin_lock(&root->fs_info->delalloc_lock);
107 total = btrfs_super_total_bytes(&root->fs_info->super_copy);
108 used = btrfs_super_bytes_used(&root->fs_info->super_copy);
109 if (for_del)
110 thresh = total * 90;
111 else
112 thresh = total * 85;
113
114 do_div(thresh, 100);
115 97
116 if (used + root->fs_info->delalloc_bytes + num_required > thresh) 98 err = btrfs_init_acl(inode, dir);
117 ret = -ENOSPC; 99 if (!err)
118 spin_unlock(&root->fs_info->delalloc_lock); 100 err = btrfs_xattr_security_init(inode, dir);
119 return ret; 101 return err;
120} 102}
121 103
122/* 104/*
@@ -350,6 +332,19 @@ again:
350 nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1; 332 nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1;
351 nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE); 333 nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE);
352 334
335 /*
336 * we don't want to send crud past the end of i_size through
337 * compression, that's just a waste of CPU time. So, if the
338 * end of the file is before the start of our current
339 * requested range of bytes, we bail out to the uncompressed
340 * cleanup code that can deal with all of this.
341 *
342 * It isn't really the fastest way to fix things, but this is a
343 * very uncommon corner.
344 */
345 if (actual_end <= start)
346 goto cleanup_and_bail_uncompressed;
347
353 total_compressed = actual_end - start; 348 total_compressed = actual_end - start;
354 349
355 /* we want to make sure that amount of ram required to uncompress 350 /* we want to make sure that amount of ram required to uncompress
@@ -494,6 +489,7 @@ again:
494 goto again; 489 goto again;
495 } 490 }
496 } else { 491 } else {
492cleanup_and_bail_uncompressed:
497 /* 493 /*
498 * No compression, but we still need to write the pages in 494 * No compression, but we still need to write the pages in
499 * the file we've been given so far. redirty the locked 495 * the file we've been given so far. redirty the locked
@@ -1166,6 +1162,7 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end,
1166 */ 1162 */
1167 if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { 1163 if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) {
1168 struct btrfs_root *root = BTRFS_I(inode)->root; 1164 struct btrfs_root *root = BTRFS_I(inode)->root;
1165 btrfs_delalloc_reserve_space(root, inode, end - start + 1);
1169 spin_lock(&root->fs_info->delalloc_lock); 1166 spin_lock(&root->fs_info->delalloc_lock);
1170 BTRFS_I(inode)->delalloc_bytes += end - start + 1; 1167 BTRFS_I(inode)->delalloc_bytes += end - start + 1;
1171 root->fs_info->delalloc_bytes += end - start + 1; 1168 root->fs_info->delalloc_bytes += end - start + 1;
@@ -1199,9 +1196,12 @@ static int btrfs_clear_bit_hook(struct inode *inode, u64 start, u64 end,
1199 (unsigned long long)end - start + 1, 1196 (unsigned long long)end - start + 1,
1200 (unsigned long long) 1197 (unsigned long long)
1201 root->fs_info->delalloc_bytes); 1198 root->fs_info->delalloc_bytes);
1199 btrfs_delalloc_free_space(root, inode, (u64)-1);
1202 root->fs_info->delalloc_bytes = 0; 1200 root->fs_info->delalloc_bytes = 0;
1203 BTRFS_I(inode)->delalloc_bytes = 0; 1201 BTRFS_I(inode)->delalloc_bytes = 0;
1204 } else { 1202 } else {
1203 btrfs_delalloc_free_space(root, inode,
1204 end - start + 1);
1205 root->fs_info->delalloc_bytes -= end - start + 1; 1205 root->fs_info->delalloc_bytes -= end - start + 1;
1206 BTRFS_I(inode)->delalloc_bytes -= end - start + 1; 1206 BTRFS_I(inode)->delalloc_bytes -= end - start + 1;
1207 } 1207 }
@@ -1324,12 +1324,11 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
1324 struct inode *inode, u64 file_offset, 1324 struct inode *inode, u64 file_offset,
1325 struct list_head *list) 1325 struct list_head *list)
1326{ 1326{
1327 struct list_head *cur;
1328 struct btrfs_ordered_sum *sum; 1327 struct btrfs_ordered_sum *sum;
1329 1328
1330 btrfs_set_trans_block_group(trans, inode); 1329 btrfs_set_trans_block_group(trans, inode);
1331 list_for_each(cur, list) { 1330
1332 sum = list_entry(cur, struct btrfs_ordered_sum, list); 1331 list_for_each_entry(sum, list, list) {
1333 btrfs_csum_file_blocks(trans, 1332 btrfs_csum_file_blocks(trans,
1334 BTRFS_I(inode)->root->fs_info->csum_root, sum); 1333 BTRFS_I(inode)->root->fs_info->csum_root, sum);
1335 } 1334 }
@@ -2013,6 +2012,7 @@ void btrfs_read_locked_inode(struct inode *inode)
2013 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item); 2012 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);
2014 2013
2015 alloc_group_block = btrfs_inode_block_group(leaf, inode_item); 2014 alloc_group_block = btrfs_inode_block_group(leaf, inode_item);
2015
2016 BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, 2016 BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0,
2017 alloc_group_block, 0); 2017 alloc_group_block, 0);
2018 btrfs_free_path(path); 2018 btrfs_free_path(path);
@@ -2039,6 +2039,7 @@ void btrfs_read_locked_inode(struct inode *inode)
2039 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 2039 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
2040 break; 2040 break;
2041 default: 2041 default:
2042 inode->i_op = &btrfs_special_inode_operations;
2042 init_special_inode(inode, inode->i_mode, rdev); 2043 init_special_inode(inode, inode->i_mode, rdev);
2043 break; 2044 break;
2044 } 2045 }
@@ -2108,6 +2109,7 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans,
2108 goto failed; 2109 goto failed;
2109 } 2110 }
2110 2111
2112 btrfs_unlock_up_safe(path, 1);
2111 leaf = path->nodes[0]; 2113 leaf = path->nodes[0];
2112 inode_item = btrfs_item_ptr(leaf, path->slots[0], 2114 inode_item = btrfs_item_ptr(leaf, path->slots[0],
2113 struct btrfs_inode_item); 2115 struct btrfs_inode_item);
@@ -2219,10 +2221,6 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
2219 2221
2220 root = BTRFS_I(dir)->root; 2222 root = BTRFS_I(dir)->root;
2221 2223
2222 ret = btrfs_check_free_space(root, 1, 1);
2223 if (ret)
2224 goto fail;
2225
2226 trans = btrfs_start_transaction(root, 1); 2224 trans = btrfs_start_transaction(root, 1);
2227 2225
2228 btrfs_set_trans_block_group(trans, dir); 2226 btrfs_set_trans_block_group(trans, dir);
@@ -2235,7 +2233,6 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
2235 nr = trans->blocks_used; 2233 nr = trans->blocks_used;
2236 2234
2237 btrfs_end_transaction_throttle(trans, root); 2235 btrfs_end_transaction_throttle(trans, root);
2238fail:
2239 btrfs_btree_balance_dirty(root, nr); 2236 btrfs_btree_balance_dirty(root, nr);
2240 return ret; 2237 return ret;
2241} 2238}
@@ -2258,10 +2255,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
2258 return -ENOTEMPTY; 2255 return -ENOTEMPTY;
2259 } 2256 }
2260 2257
2261 ret = btrfs_check_free_space(root, 1, 1);
2262 if (ret)
2263 goto fail;
2264
2265 trans = btrfs_start_transaction(root, 1); 2258 trans = btrfs_start_transaction(root, 1);
2266 btrfs_set_trans_block_group(trans, dir); 2259 btrfs_set_trans_block_group(trans, dir);
2267 2260
@@ -2278,7 +2271,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
2278fail_trans: 2271fail_trans:
2279 nr = trans->blocks_used; 2272 nr = trans->blocks_used;
2280 ret = btrfs_end_transaction_throttle(trans, root); 2273 ret = btrfs_end_transaction_throttle(trans, root);
2281fail:
2282 btrfs_btree_balance_dirty(root, nr); 2274 btrfs_btree_balance_dirty(root, nr);
2283 2275
2284 if (ret && !err) 2276 if (ret && !err)
@@ -2429,6 +2421,8 @@ next_node:
2429 ref->generation = leaf_gen; 2421 ref->generation = leaf_gen;
2430 ref->nritems = 0; 2422 ref->nritems = 0;
2431 2423
2424 btrfs_sort_leaf_ref(ref);
2425
2432 ret = btrfs_add_leaf_ref(root, ref, 0); 2426 ret = btrfs_add_leaf_ref(root, ref, 0);
2433 WARN_ON(ret); 2427 WARN_ON(ret);
2434 btrfs_free_leaf_ref(root, ref); 2428 btrfs_free_leaf_ref(root, ref);
@@ -2476,7 +2470,7 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
2476 struct btrfs_path *path; 2470 struct btrfs_path *path;
2477 struct btrfs_key key; 2471 struct btrfs_key key;
2478 struct btrfs_key found_key; 2472 struct btrfs_key found_key;
2479 u32 found_type; 2473 u32 found_type = (u8)-1;
2480 struct extent_buffer *leaf; 2474 struct extent_buffer *leaf;
2481 struct btrfs_file_extent_item *fi; 2475 struct btrfs_file_extent_item *fi;
2482 u64 extent_start = 0; 2476 u64 extent_start = 0;
@@ -2503,8 +2497,6 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
2503 key.offset = (u64)-1; 2497 key.offset = (u64)-1;
2504 key.type = (u8)-1; 2498 key.type = (u8)-1;
2505 2499
2506 btrfs_init_path(path);
2507
2508search_again: 2500search_again:
2509 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 2501 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
2510 if (ret < 0) 2502 if (ret < 0)
@@ -2663,6 +2655,8 @@ next:
2663 if (pending_del_nr) 2655 if (pending_del_nr)
2664 goto del_pending; 2656 goto del_pending;
2665 btrfs_release_path(root, path); 2657 btrfs_release_path(root, path);
2658 if (found_type == BTRFS_INODE_ITEM_KEY)
2659 break;
2666 goto search_again; 2660 goto search_again;
2667 } 2661 }
2668 2662
@@ -2679,6 +2673,8 @@ del_pending:
2679 BUG_ON(ret); 2673 BUG_ON(ret);
2680 pending_del_nr = 0; 2674 pending_del_nr = 0;
2681 btrfs_release_path(root, path); 2675 btrfs_release_path(root, path);
2676 if (found_type == BTRFS_INODE_ITEM_KEY)
2677 break;
2682 goto search_again; 2678 goto search_again;
2683 } 2679 }
2684 } 2680 }
@@ -2788,7 +2784,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t size)
2788 if (size <= hole_start) 2784 if (size <= hole_start)
2789 return 0; 2785 return 0;
2790 2786
2791 err = btrfs_check_free_space(root, 1, 0); 2787 err = btrfs_check_metadata_free_space(root);
2792 if (err) 2788 if (err)
2793 return err; 2789 return err;
2794 2790
@@ -2984,6 +2980,7 @@ static noinline void init_btrfs_i(struct inode *inode)
2984 bi->last_trans = 0; 2980 bi->last_trans = 0;
2985 bi->logged_trans = 0; 2981 bi->logged_trans = 0;
2986 bi->delalloc_bytes = 0; 2982 bi->delalloc_bytes = 0;
2983 bi->reserved_bytes = 0;
2987 bi->disk_i_size = 0; 2984 bi->disk_i_size = 0;
2988 bi->flags = 0; 2985 bi->flags = 0;
2989 bi->index_cnt = (u64)-1; 2986 bi->index_cnt = (u64)-1;
@@ -3005,6 +3002,7 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p)
3005 inode->i_ino = args->ino; 3002 inode->i_ino = args->ino;
3006 init_btrfs_i(inode); 3003 init_btrfs_i(inode);
3007 BTRFS_I(inode)->root = args->root; 3004 BTRFS_I(inode)->root = args->root;
3005 btrfs_set_inode_space_info(args->root, inode);
3008 return 0; 3006 return 0;
3009} 3007}
3010 3008
@@ -3265,7 +3263,7 @@ skip:
3265 3263
3266 /* Reached end of directory/root. Bump pos past the last item. */ 3264 /* Reached end of directory/root. Bump pos past the last item. */
3267 if (key_type == BTRFS_DIR_INDEX_KEY) 3265 if (key_type == BTRFS_DIR_INDEX_KEY)
3268 filp->f_pos = INT_LIMIT(typeof(filp->f_pos)); 3266 filp->f_pos = INT_LIMIT(off_t);
3269 else 3267 else
3270 filp->f_pos++; 3268 filp->f_pos++;
3271nopos: 3269nopos:
@@ -3425,6 +3423,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3425 BTRFS_I(inode)->index_cnt = 2; 3423 BTRFS_I(inode)->index_cnt = 2;
3426 BTRFS_I(inode)->root = root; 3424 BTRFS_I(inode)->root = root;
3427 BTRFS_I(inode)->generation = trans->transid; 3425 BTRFS_I(inode)->generation = trans->transid;
3426 btrfs_set_inode_space_info(root, inode);
3428 3427
3429 if (mode & S_IFDIR) 3428 if (mode & S_IFDIR)
3430 owner = 0; 3429 owner = 0;
@@ -3458,7 +3457,14 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3458 root->highest_inode = objectid; 3457 root->highest_inode = objectid;
3459 3458
3460 inode->i_uid = current_fsuid(); 3459 inode->i_uid = current_fsuid();
3461 inode->i_gid = current_fsgid(); 3460
3461 if (dir && (dir->i_mode & S_ISGID)) {
3462 inode->i_gid = dir->i_gid;
3463 if (S_ISDIR(mode))
3464 mode |= S_ISGID;
3465 } else
3466 inode->i_gid = current_fsgid();
3467
3462 inode->i_mode = mode; 3468 inode->i_mode = mode;
3463 inode->i_ino = objectid; 3469 inode->i_ino = objectid;
3464 inode_set_bytes(inode, 0); 3470 inode_set_bytes(inode, 0);
@@ -3565,7 +3571,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
3565 if (!new_valid_dev(rdev)) 3571 if (!new_valid_dev(rdev))
3566 return -EINVAL; 3572 return -EINVAL;
3567 3573
3568 err = btrfs_check_free_space(root, 1, 0); 3574 err = btrfs_check_metadata_free_space(root);
3569 if (err) 3575 if (err)
3570 goto fail; 3576 goto fail;
3571 3577
@@ -3586,7 +3592,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
3586 if (IS_ERR(inode)) 3592 if (IS_ERR(inode))
3587 goto out_unlock; 3593 goto out_unlock;
3588 3594
3589 err = btrfs_init_acl(inode, dir); 3595 err = btrfs_init_inode_security(inode, dir);
3590 if (err) { 3596 if (err) {
3591 drop_inode = 1; 3597 drop_inode = 1;
3592 goto out_unlock; 3598 goto out_unlock;
@@ -3628,7 +3634,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
3628 u64 objectid; 3634 u64 objectid;
3629 u64 index = 0; 3635 u64 index = 0;
3630 3636
3631 err = btrfs_check_free_space(root, 1, 0); 3637 err = btrfs_check_metadata_free_space(root);
3632 if (err) 3638 if (err)
3633 goto fail; 3639 goto fail;
3634 trans = btrfs_start_transaction(root, 1); 3640 trans = btrfs_start_transaction(root, 1);
@@ -3649,7 +3655,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
3649 if (IS_ERR(inode)) 3655 if (IS_ERR(inode))
3650 goto out_unlock; 3656 goto out_unlock;
3651 3657
3652 err = btrfs_init_acl(inode, dir); 3658 err = btrfs_init_inode_security(inode, dir);
3653 if (err) { 3659 if (err) {
3654 drop_inode = 1; 3660 drop_inode = 1;
3655 goto out_unlock; 3661 goto out_unlock;
@@ -3696,7 +3702,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
3696 return -ENOENT; 3702 return -ENOENT;
3697 3703
3698 btrfs_inc_nlink(inode); 3704 btrfs_inc_nlink(inode);
3699 err = btrfs_check_free_space(root, 1, 0); 3705 err = btrfs_check_metadata_free_space(root);
3700 if (err) 3706 if (err)
3701 goto fail; 3707 goto fail;
3702 err = btrfs_set_inode_index(dir, &index); 3708 err = btrfs_set_inode_index(dir, &index);
@@ -3742,7 +3748,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
3742 u64 index = 0; 3748 u64 index = 0;
3743 unsigned long nr = 1; 3749 unsigned long nr = 1;
3744 3750
3745 err = btrfs_check_free_space(root, 1, 0); 3751 err = btrfs_check_metadata_free_space(root);
3746 if (err) 3752 if (err)
3747 goto out_unlock; 3753 goto out_unlock;
3748 3754
@@ -3772,7 +3778,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
3772 3778
3773 drop_on_err = 1; 3779 drop_on_err = 1;
3774 3780
3775 err = btrfs_init_acl(inode, dir); 3781 err = btrfs_init_inode_security(inode, dir);
3776 if (err) 3782 if (err)
3777 goto out_fail; 3783 goto out_fail;
3778 3784
@@ -4158,9 +4164,10 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
4158 return -EINVAL; 4164 return -EINVAL;
4159} 4165}
4160 4166
4161static sector_t btrfs_bmap(struct address_space *mapping, sector_t iblock) 4167static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4168 __u64 start, __u64 len)
4162{ 4169{
4163 return extent_bmap(mapping, iblock, btrfs_get_extent); 4170 return extent_fiemap(inode, fieinfo, start, len, btrfs_get_extent);
4164} 4171}
4165 4172
4166int btrfs_readpage(struct file *file, struct page *page) 4173int btrfs_readpage(struct file *file, struct page *page)
@@ -4223,7 +4230,7 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags)
4223{ 4230{
4224 if (PageWriteback(page) || PageDirty(page)) 4231 if (PageWriteback(page) || PageDirty(page))
4225 return 0; 4232 return 0;
4226 return __btrfs_releasepage(page, gfp_flags); 4233 return __btrfs_releasepage(page, gfp_flags & GFP_NOFS);
4227} 4234}
4228 4235
4229static void btrfs_invalidatepage(struct page *page, unsigned long offset) 4236static void btrfs_invalidatepage(struct page *page, unsigned long offset)
@@ -4298,7 +4305,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page)
4298 u64 page_start; 4305 u64 page_start;
4299 u64 page_end; 4306 u64 page_end;
4300 4307
4301 ret = btrfs_check_free_space(root, PAGE_CACHE_SIZE, 0); 4308 ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE);
4302 if (ret) 4309 if (ret)
4303 goto out; 4310 goto out;
4304 4311
@@ -4311,6 +4318,7 @@ again:
4311 4318
4312 if ((page->mapping != inode->i_mapping) || 4319 if ((page->mapping != inode->i_mapping) ||
4313 (page_start >= size)) { 4320 (page_start >= size)) {
4321 btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE);
4314 /* page got truncated out from underneath us */ 4322 /* page got truncated out from underneath us */
4315 goto out_unlock; 4323 goto out_unlock;
4316 } 4324 }
@@ -4593,7 +4601,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
4593 if (old_inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) 4601 if (old_inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
4594 return -EXDEV; 4602 return -EXDEV;
4595 4603
4596 ret = btrfs_check_free_space(root, 1, 0); 4604 ret = btrfs_check_metadata_free_space(root);
4597 if (ret) 4605 if (ret)
4598 goto out_unlock; 4606 goto out_unlock;
4599 4607
@@ -4711,7 +4719,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
4711 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) 4719 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
4712 return -ENAMETOOLONG; 4720 return -ENAMETOOLONG;
4713 4721
4714 err = btrfs_check_free_space(root, 1, 0); 4722 err = btrfs_check_metadata_free_space(root);
4715 if (err) 4723 if (err)
4716 goto out_fail; 4724 goto out_fail;
4717 4725
@@ -4733,7 +4741,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
4733 if (IS_ERR(inode)) 4741 if (IS_ERR(inode))
4734 goto out_unlock; 4742 goto out_unlock;
4735 4743
4736 err = btrfs_init_acl(inode, dir); 4744 err = btrfs_init_inode_security(inode, dir);
4737 if (err) { 4745 if (err) {
4738 drop_inode = 1; 4746 drop_inode = 1;
4739 goto out_unlock; 4747 goto out_unlock;
@@ -4987,13 +4995,24 @@ static struct extent_io_ops btrfs_extent_io_ops = {
4987 .clear_bit_hook = btrfs_clear_bit_hook, 4995 .clear_bit_hook = btrfs_clear_bit_hook,
4988}; 4996};
4989 4997
4998/*
4999 * btrfs doesn't support the bmap operation because swapfiles
5000 * use bmap to make a mapping of extents in the file. They assume
5001 * these extents won't change over the life of the file and they
5002 * use the bmap result to do IO directly to the drive.
5003 *
5004 * the btrfs bmap call would return logical addresses that aren't
5005 * suitable for IO and they also will change frequently as COW
5006 * operations happen. So, swapfile + btrfs == corruption.
5007 *
5008 * For now we're avoiding this by dropping bmap.
5009 */
4990static struct address_space_operations btrfs_aops = { 5010static struct address_space_operations btrfs_aops = {
4991 .readpage = btrfs_readpage, 5011 .readpage = btrfs_readpage,
4992 .writepage = btrfs_writepage, 5012 .writepage = btrfs_writepage,
4993 .writepages = btrfs_writepages, 5013 .writepages = btrfs_writepages,
4994 .readpages = btrfs_readpages, 5014 .readpages = btrfs_readpages,
4995 .sync_page = block_sync_page, 5015 .sync_page = block_sync_page,
4996 .bmap = btrfs_bmap,
4997 .direct_IO = btrfs_direct_IO, 5016 .direct_IO = btrfs_direct_IO,
4998 .invalidatepage = btrfs_invalidatepage, 5017 .invalidatepage = btrfs_invalidatepage,
4999 .releasepage = btrfs_releasepage, 5018 .releasepage = btrfs_releasepage,
@@ -5017,6 +5036,7 @@ static struct inode_operations btrfs_file_inode_operations = {
5017 .removexattr = btrfs_removexattr, 5036 .removexattr = btrfs_removexattr,
5018 .permission = btrfs_permission, 5037 .permission = btrfs_permission,
5019 .fallocate = btrfs_fallocate, 5038 .fallocate = btrfs_fallocate,
5039 .fiemap = btrfs_fiemap,
5020}; 5040};
5021static struct inode_operations btrfs_special_inode_operations = { 5041static struct inode_operations btrfs_special_inode_operations = {
5022 .getattr = btrfs_getattr, 5042 .getattr = btrfs_getattr,
@@ -5032,4 +5052,8 @@ static struct inode_operations btrfs_symlink_inode_operations = {
5032 .follow_link = page_follow_link_light, 5052 .follow_link = page_follow_link_light,
5033 .put_link = page_put_link, 5053 .put_link = page_put_link,
5034 .permission = btrfs_permission, 5054 .permission = btrfs_permission,
5055 .setxattr = btrfs_setxattr,
5056 .getxattr = btrfs_getxattr,
5057 .listxattr = btrfs_listxattr,
5058 .removexattr = btrfs_removexattr,
5035}; 5059};