diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 84 |
1 files changed, 70 insertions, 14 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8adfe059ab41..8f0706210a47 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; |
@@ -2663,6 +2691,8 @@ next: | |||
2663 | if (pending_del_nr) | 2691 | if (pending_del_nr) |
2664 | goto del_pending; | 2692 | goto del_pending; |
2665 | btrfs_release_path(root, path); | 2693 | btrfs_release_path(root, path); |
2694 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
2695 | break; | ||
2666 | goto search_again; | 2696 | goto search_again; |
2667 | } | 2697 | } |
2668 | 2698 | ||
@@ -2679,6 +2709,8 @@ del_pending: | |||
2679 | BUG_ON(ret); | 2709 | BUG_ON(ret); |
2680 | pending_del_nr = 0; | 2710 | pending_del_nr = 0; |
2681 | btrfs_release_path(root, path); | 2711 | btrfs_release_path(root, path); |
2712 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
2713 | break; | ||
2682 | goto search_again; | 2714 | goto search_again; |
2683 | } | 2715 | } |
2684 | } | 2716 | } |
@@ -3265,7 +3297,7 @@ skip: | |||
3265 | 3297 | ||
3266 | /* Reached end of directory/root. Bump pos past the last item. */ | 3298 | /* Reached end of directory/root. Bump pos past the last item. */ |
3267 | if (key_type == BTRFS_DIR_INDEX_KEY) | 3299 | if (key_type == BTRFS_DIR_INDEX_KEY) |
3268 | filp->f_pos = INT_LIMIT(typeof(filp->f_pos)); | 3300 | filp->f_pos = INT_LIMIT(off_t); |
3269 | else | 3301 | else |
3270 | filp->f_pos++; | 3302 | filp->f_pos++; |
3271 | nopos: | 3303 | nopos: |
@@ -3458,7 +3490,14 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
3458 | root->highest_inode = objectid; | 3490 | root->highest_inode = objectid; |
3459 | 3491 | ||
3460 | inode->i_uid = current_fsuid(); | 3492 | inode->i_uid = current_fsuid(); |
3461 | inode->i_gid = current_fsgid(); | 3493 | |
3494 | if (dir && (dir->i_mode & S_ISGID)) { | ||
3495 | inode->i_gid = dir->i_gid; | ||
3496 | if (S_ISDIR(mode)) | ||
3497 | mode |= S_ISGID; | ||
3498 | } else | ||
3499 | inode->i_gid = current_fsgid(); | ||
3500 | |||
3462 | inode->i_mode = mode; | 3501 | inode->i_mode = mode; |
3463 | inode->i_ino = objectid; | 3502 | inode->i_ino = objectid; |
3464 | inode_set_bytes(inode, 0); | 3503 | inode_set_bytes(inode, 0); |
@@ -3586,7 +3625,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
3586 | if (IS_ERR(inode)) | 3625 | if (IS_ERR(inode)) |
3587 | goto out_unlock; | 3626 | goto out_unlock; |
3588 | 3627 | ||
3589 | err = btrfs_init_acl(inode, dir); | 3628 | err = btrfs_init_inode_security(inode, dir); |
3590 | if (err) { | 3629 | if (err) { |
3591 | drop_inode = 1; | 3630 | drop_inode = 1; |
3592 | goto out_unlock; | 3631 | goto out_unlock; |
@@ -3649,7 +3688,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
3649 | if (IS_ERR(inode)) | 3688 | if (IS_ERR(inode)) |
3650 | goto out_unlock; | 3689 | goto out_unlock; |
3651 | 3690 | ||
3652 | err = btrfs_init_acl(inode, dir); | 3691 | err = btrfs_init_inode_security(inode, dir); |
3653 | if (err) { | 3692 | if (err) { |
3654 | drop_inode = 1; | 3693 | drop_inode = 1; |
3655 | goto out_unlock; | 3694 | goto out_unlock; |
@@ -3772,7 +3811,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
3772 | 3811 | ||
3773 | drop_on_err = 1; | 3812 | drop_on_err = 1; |
3774 | 3813 | ||
3775 | err = btrfs_init_acl(inode, dir); | 3814 | err = btrfs_init_inode_security(inode, dir); |
3776 | if (err) | 3815 | if (err) |
3777 | goto out_fail; | 3816 | goto out_fail; |
3778 | 3817 | ||
@@ -4158,9 +4197,10 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
4158 | return -EINVAL; | 4197 | return -EINVAL; |
4159 | } | 4198 | } |
4160 | 4199 | ||
4161 | static sector_t btrfs_bmap(struct address_space *mapping, sector_t iblock) | 4200 | static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
4201 | __u64 start, __u64 len) | ||
4162 | { | 4202 | { |
4163 | return extent_bmap(mapping, iblock, btrfs_get_extent); | 4203 | return extent_fiemap(inode, fieinfo, start, len, btrfs_get_extent); |
4164 | } | 4204 | } |
4165 | 4205 | ||
4166 | int btrfs_readpage(struct file *file, struct page *page) | 4206 | int btrfs_readpage(struct file *file, struct page *page) |
@@ -4733,7 +4773,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
4733 | if (IS_ERR(inode)) | 4773 | if (IS_ERR(inode)) |
4734 | goto out_unlock; | 4774 | goto out_unlock; |
4735 | 4775 | ||
4736 | err = btrfs_init_acl(inode, dir); | 4776 | err = btrfs_init_inode_security(inode, dir); |
4737 | if (err) { | 4777 | if (err) { |
4738 | drop_inode = 1; | 4778 | drop_inode = 1; |
4739 | goto out_unlock; | 4779 | goto out_unlock; |
@@ -4987,13 +5027,24 @@ static struct extent_io_ops btrfs_extent_io_ops = { | |||
4987 | .clear_bit_hook = btrfs_clear_bit_hook, | 5027 | .clear_bit_hook = btrfs_clear_bit_hook, |
4988 | }; | 5028 | }; |
4989 | 5029 | ||
5030 | /* | ||
5031 | * btrfs doesn't support the bmap operation because swapfiles | ||
5032 | * use bmap to make a mapping of extents in the file. They assume | ||
5033 | * these extents won't change over the life of the file and they | ||
5034 | * use the bmap result to do IO directly to the drive. | ||
5035 | * | ||
5036 | * the btrfs bmap call would return logical addresses that aren't | ||
5037 | * suitable for IO and they also will change frequently as COW | ||
5038 | * operations happen. So, swapfile + btrfs == corruption. | ||
5039 | * | ||
5040 | * For now we're avoiding this by dropping bmap. | ||
5041 | */ | ||
4990 | static struct address_space_operations btrfs_aops = { | 5042 | static struct address_space_operations btrfs_aops = { |
4991 | .readpage = btrfs_readpage, | 5043 | .readpage = btrfs_readpage, |
4992 | .writepage = btrfs_writepage, | 5044 | .writepage = btrfs_writepage, |
4993 | .writepages = btrfs_writepages, | 5045 | .writepages = btrfs_writepages, |
4994 | .readpages = btrfs_readpages, | 5046 | .readpages = btrfs_readpages, |
4995 | .sync_page = block_sync_page, | 5047 | .sync_page = block_sync_page, |
4996 | .bmap = btrfs_bmap, | ||
4997 | .direct_IO = btrfs_direct_IO, | 5048 | .direct_IO = btrfs_direct_IO, |
4998 | .invalidatepage = btrfs_invalidatepage, | 5049 | .invalidatepage = btrfs_invalidatepage, |
4999 | .releasepage = btrfs_releasepage, | 5050 | .releasepage = btrfs_releasepage, |
@@ -5017,6 +5068,7 @@ static struct inode_operations btrfs_file_inode_operations = { | |||
5017 | .removexattr = btrfs_removexattr, | 5068 | .removexattr = btrfs_removexattr, |
5018 | .permission = btrfs_permission, | 5069 | .permission = btrfs_permission, |
5019 | .fallocate = btrfs_fallocate, | 5070 | .fallocate = btrfs_fallocate, |
5071 | .fiemap = btrfs_fiemap, | ||
5020 | }; | 5072 | }; |
5021 | static struct inode_operations btrfs_special_inode_operations = { | 5073 | static struct inode_operations btrfs_special_inode_operations = { |
5022 | .getattr = btrfs_getattr, | 5074 | .getattr = btrfs_getattr, |
@@ -5032,4 +5084,8 @@ static struct inode_operations btrfs_symlink_inode_operations = { | |||
5032 | .follow_link = page_follow_link_light, | 5084 | .follow_link = page_follow_link_light, |
5033 | .put_link = page_put_link, | 5085 | .put_link = page_put_link, |
5034 | .permission = btrfs_permission, | 5086 | .permission = btrfs_permission, |
5087 | .setxattr = btrfs_setxattr, | ||
5088 | .getxattr = btrfs_getxattr, | ||
5089 | .listxattr = btrfs_listxattr, | ||
5090 | .removexattr = btrfs_removexattr, | ||
5035 | }; | 5091 | }; |