diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 88 |
1 files changed, 71 insertions, 17 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8adfe059ab41..3cee77ae03c8 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 | ||
55 | struct btrfs_iget_args { | 55 | struct btrfs_iget_args { |
56 | u64 ino; | 56 | u64 ino; |
@@ -91,6 +91,16 @@ 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 | static int btrfs_init_inode_security(struct inode *inode, struct inode *dir) | ||
95 | { | ||
96 | int err; | ||
97 | |||
98 | err = btrfs_init_acl(inode, dir); | ||
99 | if (!err) | ||
100 | err = btrfs_xattr_security_init(inode, dir); | ||
101 | return err; | ||
102 | } | ||
103 | |||
94 | /* | 104 | /* |
95 | * a very lame attempt at stopping writes when the FS is 85% full. There | 105 | * 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. | 106 | * are countless ways this is incorrect, but it is better than nothing. |
@@ -350,6 +360,19 @@ again: | |||
350 | nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1; | 360 | nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1; |
351 | nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE); | 361 | nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE); |
352 | 362 | ||
363 | /* | ||
364 | * we don't want to send crud past the end of i_size through | ||
365 | * compression, that's just a waste of CPU time. So, if the | ||
366 | * end of the file is before the start of our current | ||
367 | * requested range of bytes, we bail out to the uncompressed | ||
368 | * cleanup code that can deal with all of this. | ||
369 | * | ||
370 | * It isn't really the fastest way to fix things, but this is a | ||
371 | * very uncommon corner. | ||
372 | */ | ||
373 | if (actual_end <= start) | ||
374 | goto cleanup_and_bail_uncompressed; | ||
375 | |||
353 | total_compressed = actual_end - start; | 376 | total_compressed = actual_end - start; |
354 | 377 | ||
355 | /* we want to make sure that amount of ram required to uncompress | 378 | /* we want to make sure that amount of ram required to uncompress |
@@ -494,6 +517,7 @@ again: | |||
494 | goto again; | 517 | goto again; |
495 | } | 518 | } |
496 | } else { | 519 | } else { |
520 | cleanup_and_bail_uncompressed: | ||
497 | /* | 521 | /* |
498 | * No compression, but we still need to write the pages in | 522 | * No compression, but we still need to write the pages in |
499 | * the file we've been given so far. redirty the locked | 523 | * the file we've been given so far. redirty the locked |
@@ -1324,12 +1348,11 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, | |||
1324 | struct inode *inode, u64 file_offset, | 1348 | struct inode *inode, u64 file_offset, |
1325 | struct list_head *list) | 1349 | struct list_head *list) |
1326 | { | 1350 | { |
1327 | struct list_head *cur; | ||
1328 | struct btrfs_ordered_sum *sum; | 1351 | struct btrfs_ordered_sum *sum; |
1329 | 1352 | ||
1330 | btrfs_set_trans_block_group(trans, inode); | 1353 | btrfs_set_trans_block_group(trans, inode); |
1331 | list_for_each(cur, list) { | 1354 | |
1332 | sum = list_entry(cur, struct btrfs_ordered_sum, list); | 1355 | list_for_each_entry(sum, list, list) { |
1333 | btrfs_csum_file_blocks(trans, | 1356 | btrfs_csum_file_blocks(trans, |
1334 | BTRFS_I(inode)->root->fs_info->csum_root, sum); | 1357 | BTRFS_I(inode)->root->fs_info->csum_root, sum); |
1335 | } | 1358 | } |
@@ -2013,6 +2036,7 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
2013 | BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item); | 2036 | BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item); |
2014 | 2037 | ||
2015 | alloc_group_block = btrfs_inode_block_group(leaf, inode_item); | 2038 | alloc_group_block = btrfs_inode_block_group(leaf, inode_item); |
2039 | |||
2016 | BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, | 2040 | BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, |
2017 | alloc_group_block, 0); | 2041 | alloc_group_block, 0); |
2018 | btrfs_free_path(path); | 2042 | btrfs_free_path(path); |
@@ -2039,6 +2063,7 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
2039 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | 2063 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; |
2040 | break; | 2064 | break; |
2041 | default: | 2065 | default: |
2066 | inode->i_op = &btrfs_special_inode_operations; | ||
2042 | init_special_inode(inode, inode->i_mode, rdev); | 2067 | init_special_inode(inode, inode->i_mode, rdev); |
2043 | break; | 2068 | break; |
2044 | } | 2069 | } |
@@ -2108,6 +2133,7 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, | |||
2108 | goto failed; | 2133 | goto failed; |
2109 | } | 2134 | } |
2110 | 2135 | ||
2136 | btrfs_unlock_up_safe(path, 1); | ||
2111 | leaf = path->nodes[0]; | 2137 | leaf = path->nodes[0]; |
2112 | inode_item = btrfs_item_ptr(leaf, path->slots[0], | 2138 | inode_item = btrfs_item_ptr(leaf, path->slots[0], |
2113 | struct btrfs_inode_item); | 2139 | struct btrfs_inode_item); |
@@ -2429,6 +2455,8 @@ next_node: | |||
2429 | ref->generation = leaf_gen; | 2455 | ref->generation = leaf_gen; |
2430 | ref->nritems = 0; | 2456 | ref->nritems = 0; |
2431 | 2457 | ||
2458 | btrfs_sort_leaf_ref(ref); | ||
2459 | |||
2432 | ret = btrfs_add_leaf_ref(root, ref, 0); | 2460 | ret = btrfs_add_leaf_ref(root, ref, 0); |
2433 | WARN_ON(ret); | 2461 | WARN_ON(ret); |
2434 | btrfs_free_leaf_ref(root, ref); | 2462 | btrfs_free_leaf_ref(root, ref); |
@@ -2476,7 +2504,7 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2476 | struct btrfs_path *path; | 2504 | struct btrfs_path *path; |
2477 | struct btrfs_key key; | 2505 | struct btrfs_key key; |
2478 | struct btrfs_key found_key; | 2506 | struct btrfs_key found_key; |
2479 | u32 found_type; | 2507 | u32 found_type = (u8)-1; |
2480 | struct extent_buffer *leaf; | 2508 | struct extent_buffer *leaf; |
2481 | struct btrfs_file_extent_item *fi; | 2509 | struct btrfs_file_extent_item *fi; |
2482 | u64 extent_start = 0; | 2510 | u64 extent_start = 0; |
@@ -2503,8 +2531,6 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2503 | key.offset = (u64)-1; | 2531 | key.offset = (u64)-1; |
2504 | key.type = (u8)-1; | 2532 | key.type = (u8)-1; |
2505 | 2533 | ||
2506 | btrfs_init_path(path); | ||
2507 | |||
2508 | search_again: | 2534 | search_again: |
2509 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | 2535 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); |
2510 | if (ret < 0) | 2536 | if (ret < 0) |
@@ -2663,6 +2689,8 @@ next: | |||
2663 | if (pending_del_nr) | 2689 | if (pending_del_nr) |
2664 | goto del_pending; | 2690 | goto del_pending; |
2665 | btrfs_release_path(root, path); | 2691 | btrfs_release_path(root, path); |
2692 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
2693 | break; | ||
2666 | goto search_again; | 2694 | goto search_again; |
2667 | } | 2695 | } |
2668 | 2696 | ||
@@ -2679,6 +2707,8 @@ del_pending: | |||
2679 | BUG_ON(ret); | 2707 | BUG_ON(ret); |
2680 | pending_del_nr = 0; | 2708 | pending_del_nr = 0; |
2681 | btrfs_release_path(root, path); | 2709 | btrfs_release_path(root, path); |
2710 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
2711 | break; | ||
2682 | goto search_again; | 2712 | goto search_again; |
2683 | } | 2713 | } |
2684 | } | 2714 | } |
@@ -3265,7 +3295,7 @@ skip: | |||
3265 | 3295 | ||
3266 | /* Reached end of directory/root. Bump pos past the last item. */ | 3296 | /* Reached end of directory/root. Bump pos past the last item. */ |
3267 | if (key_type == BTRFS_DIR_INDEX_KEY) | 3297 | if (key_type == BTRFS_DIR_INDEX_KEY) |
3268 | filp->f_pos = INT_LIMIT(typeof(filp->f_pos)); | 3298 | filp->f_pos = INT_LIMIT(off_t); |
3269 | else | 3299 | else |
3270 | filp->f_pos++; | 3300 | filp->f_pos++; |
3271 | nopos: | 3301 | nopos: |
@@ -3458,7 +3488,14 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
3458 | root->highest_inode = objectid; | 3488 | root->highest_inode = objectid; |
3459 | 3489 | ||
3460 | inode->i_uid = current_fsuid(); | 3490 | inode->i_uid = current_fsuid(); |
3461 | inode->i_gid = current_fsgid(); | 3491 | |
3492 | if (dir && (dir->i_mode & S_ISGID)) { | ||
3493 | inode->i_gid = dir->i_gid; | ||
3494 | if (S_ISDIR(mode)) | ||
3495 | mode |= S_ISGID; | ||
3496 | } else | ||
3497 | inode->i_gid = current_fsgid(); | ||
3498 | |||
3462 | inode->i_mode = mode; | 3499 | inode->i_mode = mode; |
3463 | inode->i_ino = objectid; | 3500 | inode->i_ino = objectid; |
3464 | inode_set_bytes(inode, 0); | 3501 | inode_set_bytes(inode, 0); |
@@ -3586,7 +3623,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
3586 | if (IS_ERR(inode)) | 3623 | if (IS_ERR(inode)) |
3587 | goto out_unlock; | 3624 | goto out_unlock; |
3588 | 3625 | ||
3589 | err = btrfs_init_acl(inode, dir); | 3626 | err = btrfs_init_inode_security(inode, dir); |
3590 | if (err) { | 3627 | if (err) { |
3591 | drop_inode = 1; | 3628 | drop_inode = 1; |
3592 | goto out_unlock; | 3629 | goto out_unlock; |
@@ -3649,7 +3686,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
3649 | if (IS_ERR(inode)) | 3686 | if (IS_ERR(inode)) |
3650 | goto out_unlock; | 3687 | goto out_unlock; |
3651 | 3688 | ||
3652 | err = btrfs_init_acl(inode, dir); | 3689 | err = btrfs_init_inode_security(inode, dir); |
3653 | if (err) { | 3690 | if (err) { |
3654 | drop_inode = 1; | 3691 | drop_inode = 1; |
3655 | goto out_unlock; | 3692 | goto out_unlock; |
@@ -3772,7 +3809,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
3772 | 3809 | ||
3773 | drop_on_err = 1; | 3810 | drop_on_err = 1; |
3774 | 3811 | ||
3775 | err = btrfs_init_acl(inode, dir); | 3812 | err = btrfs_init_inode_security(inode, dir); |
3776 | if (err) | 3813 | if (err) |
3777 | goto out_fail; | 3814 | goto out_fail; |
3778 | 3815 | ||
@@ -4158,9 +4195,10 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
4158 | return -EINVAL; | 4195 | return -EINVAL; |
4159 | } | 4196 | } |
4160 | 4197 | ||
4161 | static sector_t btrfs_bmap(struct address_space *mapping, sector_t iblock) | 4198 | static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
4199 | __u64 start, __u64 len) | ||
4162 | { | 4200 | { |
4163 | return extent_bmap(mapping, iblock, btrfs_get_extent); | 4201 | return extent_fiemap(inode, fieinfo, start, len, btrfs_get_extent); |
4164 | } | 4202 | } |
4165 | 4203 | ||
4166 | int btrfs_readpage(struct file *file, struct page *page) | 4204 | int btrfs_readpage(struct file *file, struct page *page) |
@@ -4223,7 +4261,7 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) | |||
4223 | { | 4261 | { |
4224 | if (PageWriteback(page) || PageDirty(page)) | 4262 | if (PageWriteback(page) || PageDirty(page)) |
4225 | return 0; | 4263 | return 0; |
4226 | return __btrfs_releasepage(page, gfp_flags); | 4264 | return __btrfs_releasepage(page, gfp_flags & GFP_NOFS); |
4227 | } | 4265 | } |
4228 | 4266 | ||
4229 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) | 4267 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) |
@@ -4733,7 +4771,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
4733 | if (IS_ERR(inode)) | 4771 | if (IS_ERR(inode)) |
4734 | goto out_unlock; | 4772 | goto out_unlock; |
4735 | 4773 | ||
4736 | err = btrfs_init_acl(inode, dir); | 4774 | err = btrfs_init_inode_security(inode, dir); |
4737 | if (err) { | 4775 | if (err) { |
4738 | drop_inode = 1; | 4776 | drop_inode = 1; |
4739 | goto out_unlock; | 4777 | goto out_unlock; |
@@ -4987,13 +5025,24 @@ static struct extent_io_ops btrfs_extent_io_ops = { | |||
4987 | .clear_bit_hook = btrfs_clear_bit_hook, | 5025 | .clear_bit_hook = btrfs_clear_bit_hook, |
4988 | }; | 5026 | }; |
4989 | 5027 | ||
5028 | /* | ||
5029 | * btrfs doesn't support the bmap operation because swapfiles | ||
5030 | * use bmap to make a mapping of extents in the file. They assume | ||
5031 | * these extents won't change over the life of the file and they | ||
5032 | * use the bmap result to do IO directly to the drive. | ||
5033 | * | ||
5034 | * the btrfs bmap call would return logical addresses that aren't | ||
5035 | * suitable for IO and they also will change frequently as COW | ||
5036 | * operations happen. So, swapfile + btrfs == corruption. | ||
5037 | * | ||
5038 | * For now we're avoiding this by dropping bmap. | ||
5039 | */ | ||
4990 | static struct address_space_operations btrfs_aops = { | 5040 | static struct address_space_operations btrfs_aops = { |
4991 | .readpage = btrfs_readpage, | 5041 | .readpage = btrfs_readpage, |
4992 | .writepage = btrfs_writepage, | 5042 | .writepage = btrfs_writepage, |
4993 | .writepages = btrfs_writepages, | 5043 | .writepages = btrfs_writepages, |
4994 | .readpages = btrfs_readpages, | 5044 | .readpages = btrfs_readpages, |
4995 | .sync_page = block_sync_page, | 5045 | .sync_page = block_sync_page, |
4996 | .bmap = btrfs_bmap, | ||
4997 | .direct_IO = btrfs_direct_IO, | 5046 | .direct_IO = btrfs_direct_IO, |
4998 | .invalidatepage = btrfs_invalidatepage, | 5047 | .invalidatepage = btrfs_invalidatepage, |
4999 | .releasepage = btrfs_releasepage, | 5048 | .releasepage = btrfs_releasepage, |
@@ -5017,6 +5066,7 @@ static struct inode_operations btrfs_file_inode_operations = { | |||
5017 | .removexattr = btrfs_removexattr, | 5066 | .removexattr = btrfs_removexattr, |
5018 | .permission = btrfs_permission, | 5067 | .permission = btrfs_permission, |
5019 | .fallocate = btrfs_fallocate, | 5068 | .fallocate = btrfs_fallocate, |
5069 | .fiemap = btrfs_fiemap, | ||
5020 | }; | 5070 | }; |
5021 | static struct inode_operations btrfs_special_inode_operations = { | 5071 | static struct inode_operations btrfs_special_inode_operations = { |
5022 | .getattr = btrfs_getattr, | 5072 | .getattr = btrfs_getattr, |
@@ -5032,4 +5082,8 @@ static struct inode_operations btrfs_symlink_inode_operations = { | |||
5032 | .follow_link = page_follow_link_light, | 5082 | .follow_link = page_follow_link_light, |
5033 | .put_link = page_put_link, | 5083 | .put_link = page_put_link, |
5034 | .permission = btrfs_permission, | 5084 | .permission = btrfs_permission, |
5085 | .setxattr = btrfs_setxattr, | ||
5086 | .getxattr = btrfs_getxattr, | ||
5087 | .listxattr = btrfs_listxattr, | ||
5088 | .removexattr = btrfs_removexattr, | ||
5035 | }; | 5089 | }; |