diff options
Diffstat (limited to 'fs/btrfs/inode.c')
| -rw-r--r-- | fs/btrfs/inode.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a7d1921ac76b..6e8f416773d4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
| @@ -324,7 +324,8 @@ static noinline int add_async_extent(struct async_cow *cow, | |||
| 324 | * If this code finds it can't get good compression, it puts an | 324 | * If this code finds it can't get good compression, it puts an |
| 325 | * entry onto the work queue to write the uncompressed bytes. This | 325 | * entry onto the work queue to write the uncompressed bytes. This |
| 326 | * makes sure that both compressed inodes and uncompressed inodes | 326 | * makes sure that both compressed inodes and uncompressed inodes |
| 327 | * are written in the same order that pdflush sent them down. | 327 | * are written in the same order that the flusher thread sent them |
| 328 | * down. | ||
| 328 | */ | 329 | */ |
| 329 | static noinline int compress_file_range(struct inode *inode, | 330 | static noinline int compress_file_range(struct inode *inode, |
| 330 | struct page *locked_page, | 331 | struct page *locked_page, |
| @@ -825,7 +826,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
| 825 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | 826 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; |
| 826 | int ret = 0; | 827 | int ret = 0; |
| 827 | 828 | ||
| 828 | BUG_ON(btrfs_is_free_space_inode(root, inode)); | 829 | BUG_ON(btrfs_is_free_space_inode(inode)); |
| 829 | trans = btrfs_join_transaction(root); | 830 | trans = btrfs_join_transaction(root); |
| 830 | if (IS_ERR(trans)) { | 831 | if (IS_ERR(trans)) { |
| 831 | extent_clear_unlock_delalloc(inode, | 832 | extent_clear_unlock_delalloc(inode, |
| @@ -1010,7 +1011,7 @@ static noinline void async_cow_submit(struct btrfs_work *work) | |||
| 1010 | atomic_sub(nr_pages, &root->fs_info->async_delalloc_pages); | 1011 | atomic_sub(nr_pages, &root->fs_info->async_delalloc_pages); |
| 1011 | 1012 | ||
| 1012 | if (atomic_read(&root->fs_info->async_delalloc_pages) < | 1013 | if (atomic_read(&root->fs_info->async_delalloc_pages) < |
| 1013 | 5 * 1042 * 1024 && | 1014 | 5 * 1024 * 1024 && |
| 1014 | waitqueue_active(&root->fs_info->async_submit_wait)) | 1015 | waitqueue_active(&root->fs_info->async_submit_wait)) |
| 1015 | wake_up(&root->fs_info->async_submit_wait); | 1016 | wake_up(&root->fs_info->async_submit_wait); |
| 1016 | 1017 | ||
| @@ -1035,7 +1036,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, | |||
| 1035 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1036 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 1036 | unsigned long nr_pages; | 1037 | unsigned long nr_pages; |
| 1037 | u64 cur_end; | 1038 | u64 cur_end; |
| 1038 | int limit = 10 * 1024 * 1042; | 1039 | int limit = 10 * 1024 * 1024; |
| 1039 | 1040 | ||
| 1040 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, | 1041 | clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, |
| 1041 | 1, 0, NULL, GFP_NOFS); | 1042 | 1, 0, NULL, GFP_NOFS); |
| @@ -1153,7 +1154,7 @@ static noinline int run_delalloc_nocow(struct inode *inode, | |||
| 1153 | return -ENOMEM; | 1154 | return -ENOMEM; |
| 1154 | } | 1155 | } |
| 1155 | 1156 | ||
| 1156 | nolock = btrfs_is_free_space_inode(root, inode); | 1157 | nolock = btrfs_is_free_space_inode(inode); |
| 1157 | 1158 | ||
| 1158 | if (nolock) | 1159 | if (nolock) |
| 1159 | trans = btrfs_join_transaction_nolock(root); | 1160 | trans = btrfs_join_transaction_nolock(root); |
| @@ -1466,7 +1467,7 @@ static void btrfs_set_bit_hook(struct inode *inode, | |||
| 1466 | if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { | 1467 | if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { |
| 1467 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1468 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 1468 | u64 len = state->end + 1 - state->start; | 1469 | u64 len = state->end + 1 - state->start; |
| 1469 | bool do_list = !btrfs_is_free_space_inode(root, inode); | 1470 | bool do_list = !btrfs_is_free_space_inode(inode); |
| 1470 | 1471 | ||
| 1471 | if (*bits & EXTENT_FIRST_DELALLOC) { | 1472 | if (*bits & EXTENT_FIRST_DELALLOC) { |
| 1472 | *bits &= ~EXTENT_FIRST_DELALLOC; | 1473 | *bits &= ~EXTENT_FIRST_DELALLOC; |
| @@ -1501,7 +1502,7 @@ static void btrfs_clear_bit_hook(struct inode *inode, | |||
| 1501 | if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { | 1502 | if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { |
| 1502 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1503 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 1503 | u64 len = state->end + 1 - state->start; | 1504 | u64 len = state->end + 1 - state->start; |
| 1504 | bool do_list = !btrfs_is_free_space_inode(root, inode); | 1505 | bool do_list = !btrfs_is_free_space_inode(inode); |
| 1505 | 1506 | ||
| 1506 | if (*bits & EXTENT_FIRST_DELALLOC) { | 1507 | if (*bits & EXTENT_FIRST_DELALLOC) { |
| 1507 | *bits &= ~EXTENT_FIRST_DELALLOC; | 1508 | *bits &= ~EXTENT_FIRST_DELALLOC; |
| @@ -1612,7 +1613,7 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, | |||
| 1612 | 1613 | ||
| 1613 | skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; | 1614 | skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; |
| 1614 | 1615 | ||
| 1615 | if (btrfs_is_free_space_inode(root, inode)) | 1616 | if (btrfs_is_free_space_inode(inode)) |
| 1616 | metadata = 2; | 1617 | metadata = 2; |
| 1617 | 1618 | ||
| 1618 | if (!(rw & REQ_WRITE)) { | 1619 | if (!(rw & REQ_WRITE)) { |
| @@ -1869,7 +1870,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) | |||
| 1869 | int ret; | 1870 | int ret; |
| 1870 | bool nolock; | 1871 | bool nolock; |
| 1871 | 1872 | ||
| 1872 | nolock = btrfs_is_free_space_inode(root, inode); | 1873 | nolock = btrfs_is_free_space_inode(inode); |
| 1873 | 1874 | ||
| 1874 | if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { | 1875 | if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { |
| 1875 | ret = -EIO; | 1876 | ret = -EIO; |
| @@ -2007,7 +2008,7 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, | |||
| 2007 | ordered_extent->work.func = finish_ordered_fn; | 2008 | ordered_extent->work.func = finish_ordered_fn; |
| 2008 | ordered_extent->work.flags = 0; | 2009 | ordered_extent->work.flags = 0; |
| 2009 | 2010 | ||
| 2010 | if (btrfs_is_free_space_inode(root, inode)) | 2011 | if (btrfs_is_free_space_inode(inode)) |
| 2011 | workers = &root->fs_info->endio_freespace_worker; | 2012 | workers = &root->fs_info->endio_freespace_worker; |
| 2012 | else | 2013 | else |
| 2013 | workers = &root->fs_info->endio_write_workers; | 2014 | workers = &root->fs_info->endio_write_workers; |
| @@ -2732,8 +2733,10 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, | |||
| 2732 | * The data relocation inode should also be directly updated | 2733 | * The data relocation inode should also be directly updated |
| 2733 | * without delay | 2734 | * without delay |
| 2734 | */ | 2735 | */ |
| 2735 | if (!btrfs_is_free_space_inode(root, inode) | 2736 | if (!btrfs_is_free_space_inode(inode) |
| 2736 | && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { | 2737 | && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { |
| 2738 | btrfs_update_root_times(trans, root); | ||
| 2739 | |||
| 2737 | ret = btrfs_delayed_update_inode(trans, root, inode); | 2740 | ret = btrfs_delayed_update_inode(trans, root, inode); |
| 2738 | if (!ret) | 2741 | if (!ret) |
| 2739 | btrfs_set_inode_last_trans(trans, inode); | 2742 | btrfs_set_inode_last_trans(trans, inode); |
| @@ -2833,7 +2836,7 @@ err: | |||
| 2833 | inode_inc_iversion(inode); | 2836 | inode_inc_iversion(inode); |
| 2834 | inode_inc_iversion(dir); | 2837 | inode_inc_iversion(dir); |
| 2835 | inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; | 2838 | inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; |
| 2836 | btrfs_update_inode(trans, root, dir); | 2839 | ret = btrfs_update_inode(trans, root, dir); |
| 2837 | out: | 2840 | out: |
| 2838 | return ret; | 2841 | return ret; |
| 2839 | } | 2842 | } |
| @@ -3743,7 +3746,7 @@ void btrfs_evict_inode(struct inode *inode) | |||
| 3743 | 3746 | ||
| 3744 | truncate_inode_pages(&inode->i_data, 0); | 3747 | truncate_inode_pages(&inode->i_data, 0); |
| 3745 | if (inode->i_nlink && (btrfs_root_refs(&root->root_item) != 0 || | 3748 | if (inode->i_nlink && (btrfs_root_refs(&root->root_item) != 0 || |
| 3746 | btrfs_is_free_space_inode(root, inode))) | 3749 | btrfs_is_free_space_inode(inode))) |
| 3747 | goto no_delete; | 3750 | goto no_delete; |
| 3748 | 3751 | ||
| 3749 | if (is_bad_inode(inode)) { | 3752 | if (is_bad_inode(inode)) { |
| @@ -4082,7 +4085,6 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p) | |||
| 4082 | struct btrfs_iget_args *args = p; | 4085 | struct btrfs_iget_args *args = p; |
| 4083 | inode->i_ino = args->ino; | 4086 | inode->i_ino = args->ino; |
| 4084 | BTRFS_I(inode)->root = args->root; | 4087 | BTRFS_I(inode)->root = args->root; |
| 4085 | btrfs_set_inode_space_info(args->root, inode); | ||
| 4086 | return 0; | 4088 | return 0; |
| 4087 | } | 4089 | } |
| 4088 | 4090 | ||
| @@ -4247,7 +4249,7 @@ static void btrfs_dentry_release(struct dentry *dentry) | |||
| 4247 | } | 4249 | } |
| 4248 | 4250 | ||
| 4249 | static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, | 4251 | static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, |
| 4250 | struct nameidata *nd) | 4252 | unsigned int flags) |
| 4251 | { | 4253 | { |
| 4252 | struct dentry *ret; | 4254 | struct dentry *ret; |
| 4253 | 4255 | ||
| @@ -4457,7 +4459,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) | |||
| 4457 | if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) | 4459 | if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) |
| 4458 | return 0; | 4460 | return 0; |
| 4459 | 4461 | ||
| 4460 | if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) | 4462 | if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(inode)) |
| 4461 | nolock = true; | 4463 | nolock = true; |
| 4462 | 4464 | ||
| 4463 | if (wbc->sync_mode == WB_SYNC_ALL) { | 4465 | if (wbc->sync_mode == WB_SYNC_ALL) { |
| @@ -4518,6 +4520,11 @@ int btrfs_dirty_inode(struct inode *inode) | |||
| 4518 | static int btrfs_update_time(struct inode *inode, struct timespec *now, | 4520 | static int btrfs_update_time(struct inode *inode, struct timespec *now, |
| 4519 | int flags) | 4521 | int flags) |
| 4520 | { | 4522 | { |
| 4523 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
| 4524 | |||
| 4525 | if (btrfs_root_readonly(root)) | ||
| 4526 | return -EROFS; | ||
| 4527 | |||
| 4521 | if (flags & S_VERSION) | 4528 | if (flags & S_VERSION) |
| 4522 | inode_inc_iversion(inode); | 4529 | inode_inc_iversion(inode); |
| 4523 | if (flags & S_CTIME) | 4530 | if (flags & S_CTIME) |
| @@ -4662,7 +4669,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
| 4662 | BTRFS_I(inode)->root = root; | 4669 | BTRFS_I(inode)->root = root; |
| 4663 | BTRFS_I(inode)->generation = trans->transid; | 4670 | BTRFS_I(inode)->generation = trans->transid; |
| 4664 | inode->i_generation = BTRFS_I(inode)->generation; | 4671 | inode->i_generation = BTRFS_I(inode)->generation; |
| 4665 | btrfs_set_inode_space_info(root, inode); | ||
| 4666 | 4672 | ||
| 4667 | if (S_ISDIR(mode)) | 4673 | if (S_ISDIR(mode)) |
| 4668 | owner = 0; | 4674 | owner = 0; |
| @@ -4690,6 +4696,8 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
| 4690 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 4696 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 4691 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], | 4697 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], |
| 4692 | struct btrfs_inode_item); | 4698 | struct btrfs_inode_item); |
| 4699 | memset_extent_buffer(path->nodes[0], 0, (unsigned long)inode_item, | ||
| 4700 | sizeof(*inode_item)); | ||
| 4693 | fill_inode_item(trans, path->nodes[0], inode_item, inode); | 4701 | fill_inode_item(trans, path->nodes[0], inode_item, inode); |
| 4694 | 4702 | ||
| 4695 | ref = btrfs_item_ptr(path->nodes[0], path->slots[0] + 1, | 4703 | ref = btrfs_item_ptr(path->nodes[0], path->slots[0] + 1, |
| @@ -4723,6 +4731,8 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
| 4723 | trace_btrfs_inode_new(inode); | 4731 | trace_btrfs_inode_new(inode); |
| 4724 | btrfs_set_inode_last_trans(trans, inode); | 4732 | btrfs_set_inode_last_trans(trans, inode); |
| 4725 | 4733 | ||
| 4734 | btrfs_update_root_times(trans, root); | ||
| 4735 | |||
| 4726 | return inode; | 4736 | return inode; |
| 4727 | fail: | 4737 | fail: |
| 4728 | if (dir) | 4738 | if (dir) |
| @@ -4893,7 +4903,7 @@ out_unlock: | |||
| 4893 | } | 4903 | } |
| 4894 | 4904 | ||
| 4895 | static int btrfs_create(struct inode *dir, struct dentry *dentry, | 4905 | static int btrfs_create(struct inode *dir, struct dentry *dentry, |
| 4896 | umode_t mode, struct nameidata *nd) | 4906 | umode_t mode, bool excl) |
| 4897 | { | 4907 | { |
| 4898 | struct btrfs_trans_handle *trans; | 4908 | struct btrfs_trans_handle *trans; |
| 4899 | struct btrfs_root *root = BTRFS_I(dir)->root; | 4909 | struct btrfs_root *root = BTRFS_I(dir)->root; |
| @@ -6620,6 +6630,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
| 6620 | u64 page_start; | 6630 | u64 page_start; |
| 6621 | u64 page_end; | 6631 | u64 page_end; |
| 6622 | 6632 | ||
| 6633 | sb_start_pagefault(inode->i_sb); | ||
| 6623 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); | 6634 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
| 6624 | if (!ret) { | 6635 | if (!ret) { |
| 6625 | ret = file_update_time(vma->vm_file); | 6636 | ret = file_update_time(vma->vm_file); |
| @@ -6709,12 +6720,15 @@ again: | |||
| 6709 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); | 6720 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); |
| 6710 | 6721 | ||
| 6711 | out_unlock: | 6722 | out_unlock: |
| 6712 | if (!ret) | 6723 | if (!ret) { |
| 6724 | sb_end_pagefault(inode->i_sb); | ||
| 6713 | return VM_FAULT_LOCKED; | 6725 | return VM_FAULT_LOCKED; |
| 6726 | } | ||
| 6714 | unlock_page(page); | 6727 | unlock_page(page); |
| 6715 | out: | 6728 | out: |
| 6716 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); | 6729 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); |
| 6717 | out_noreserve: | 6730 | out_noreserve: |
| 6731 | sb_end_pagefault(inode->i_sb); | ||
| 6718 | return ret; | 6732 | return ret; |
| 6719 | } | 6733 | } |
| 6720 | 6734 | ||
| @@ -6939,7 +6953,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
| 6939 | return NULL; | 6953 | return NULL; |
| 6940 | 6954 | ||
| 6941 | ei->root = NULL; | 6955 | ei->root = NULL; |
| 6942 | ei->space_info = NULL; | ||
| 6943 | ei->generation = 0; | 6956 | ei->generation = 0; |
| 6944 | ei->last_trans = 0; | 6957 | ei->last_trans = 0; |
| 6945 | ei->last_sub_trans = 0; | 6958 | ei->last_sub_trans = 0; |
| @@ -6987,7 +7000,7 @@ void btrfs_destroy_inode(struct inode *inode) | |||
| 6987 | struct btrfs_ordered_extent *ordered; | 7000 | struct btrfs_ordered_extent *ordered; |
| 6988 | struct btrfs_root *root = BTRFS_I(inode)->root; | 7001 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 6989 | 7002 | ||
| 6990 | WARN_ON(!list_empty(&inode->i_dentry)); | 7003 | WARN_ON(!hlist_empty(&inode->i_dentry)); |
| 6991 | WARN_ON(inode->i_data.nrpages); | 7004 | WARN_ON(inode->i_data.nrpages); |
| 6992 | WARN_ON(BTRFS_I(inode)->outstanding_extents); | 7005 | WARN_ON(BTRFS_I(inode)->outstanding_extents); |
| 6993 | WARN_ON(BTRFS_I(inode)->reserved_extents); | 7006 | WARN_ON(BTRFS_I(inode)->reserved_extents); |
| @@ -7046,7 +7059,7 @@ int btrfs_drop_inode(struct inode *inode) | |||
| 7046 | struct btrfs_root *root = BTRFS_I(inode)->root; | 7059 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 7047 | 7060 | ||
| 7048 | if (btrfs_root_refs(&root->root_item) == 0 && | 7061 | if (btrfs_root_refs(&root->root_item) == 0 && |
| 7049 | !btrfs_is_free_space_inode(root, inode)) | 7062 | !btrfs_is_free_space_inode(inode)) |
| 7050 | return 1; | 7063 | return 1; |
| 7051 | else | 7064 | else |
| 7052 | return generic_drop_inode(inode); | 7065 | return generic_drop_inode(inode); |
