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.c109
1 files changed, 89 insertions, 20 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 03708ef3deef..9c194bd74d6e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1096,8 +1096,10 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
1096 async_cow->end = cur_end; 1096 async_cow->end = cur_end;
1097 INIT_LIST_HEAD(&async_cow->extents); 1097 INIT_LIST_HEAD(&async_cow->extents);
1098 1098
1099 btrfs_init_work(&async_cow->work, async_cow_start, 1099 btrfs_init_work(&async_cow->work,
1100 async_cow_submit, async_cow_free); 1100 btrfs_delalloc_helper,
1101 async_cow_start, async_cow_submit,
1102 async_cow_free);
1101 1103
1102 nr_pages = (cur_end - start + PAGE_CACHE_SIZE) >> 1104 nr_pages = (cur_end - start + PAGE_CACHE_SIZE) >>
1103 PAGE_CACHE_SHIFT; 1105 PAGE_CACHE_SHIFT;
@@ -1881,7 +1883,8 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end)
1881 1883
1882 SetPageChecked(page); 1884 SetPageChecked(page);
1883 page_cache_get(page); 1885 page_cache_get(page);
1884 btrfs_init_work(&fixup->work, btrfs_writepage_fixup_worker, NULL, NULL); 1886 btrfs_init_work(&fixup->work, btrfs_fixup_helper,
1887 btrfs_writepage_fixup_worker, NULL, NULL);
1885 fixup->page = page; 1888 fixup->page = page;
1886 btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work); 1889 btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work);
1887 return -EBUSY; 1890 return -EBUSY;
@@ -2822,7 +2825,8 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
2822 struct inode *inode = page->mapping->host; 2825 struct inode *inode = page->mapping->host;
2823 struct btrfs_root *root = BTRFS_I(inode)->root; 2826 struct btrfs_root *root = BTRFS_I(inode)->root;
2824 struct btrfs_ordered_extent *ordered_extent = NULL; 2827 struct btrfs_ordered_extent *ordered_extent = NULL;
2825 struct btrfs_workqueue *workers; 2828 struct btrfs_workqueue *wq;
2829 btrfs_work_func_t func;
2826 2830
2827 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); 2831 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate);
2828 2832
@@ -2831,13 +2835,17 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
2831 end - start + 1, uptodate)) 2835 end - start + 1, uptodate))
2832 return 0; 2836 return 0;
2833 2837
2834 btrfs_init_work(&ordered_extent->work, finish_ordered_fn, NULL, NULL); 2838 if (btrfs_is_free_space_inode(inode)) {
2839 wq = root->fs_info->endio_freespace_worker;
2840 func = btrfs_freespace_write_helper;
2841 } else {
2842 wq = root->fs_info->endio_write_workers;
2843 func = btrfs_endio_write_helper;
2844 }
2835 2845
2836 if (btrfs_is_free_space_inode(inode)) 2846 btrfs_init_work(&ordered_extent->work, func, finish_ordered_fn, NULL,
2837 workers = root->fs_info->endio_freespace_worker; 2847 NULL);
2838 else 2848 btrfs_queue_work(wq, &ordered_extent->work);
2839 workers = root->fs_info->endio_write_workers;
2840 btrfs_queue_work(workers, &ordered_extent->work);
2841 2849
2842 return 0; 2850 return 0;
2843} 2851}
@@ -4674,6 +4682,11 @@ static void evict_inode_truncate_pages(struct inode *inode)
4674 clear_bit(EXTENT_FLAG_LOGGING, &em->flags); 4682 clear_bit(EXTENT_FLAG_LOGGING, &em->flags);
4675 remove_extent_mapping(map_tree, em); 4683 remove_extent_mapping(map_tree, em);
4676 free_extent_map(em); 4684 free_extent_map(em);
4685 if (need_resched()) {
4686 write_unlock(&map_tree->lock);
4687 cond_resched();
4688 write_lock(&map_tree->lock);
4689 }
4677 } 4690 }
4678 write_unlock(&map_tree->lock); 4691 write_unlock(&map_tree->lock);
4679 4692
@@ -4696,6 +4709,7 @@ static void evict_inode_truncate_pages(struct inode *inode)
4696 &cached_state, GFP_NOFS); 4709 &cached_state, GFP_NOFS);
4697 free_extent_state(state); 4710 free_extent_state(state);
4698 4711
4712 cond_resched();
4699 spin_lock(&io_tree->lock); 4713 spin_lock(&io_tree->lock);
4700 } 4714 }
4701 spin_unlock(&io_tree->lock); 4715 spin_unlock(&io_tree->lock);
@@ -5181,6 +5195,42 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
5181 iput(inode); 5195 iput(inode);
5182 inode = ERR_PTR(ret); 5196 inode = ERR_PTR(ret);
5183 } 5197 }
5198 /*
5199 * If orphan cleanup did remove any orphans, it means the tree
5200 * was modified and therefore the commit root is not the same as
5201 * the current root anymore. This is a problem, because send
5202 * uses the commit root and therefore can see inode items that
5203 * don't exist in the current root anymore, and for example make
5204 * calls to btrfs_iget, which will do tree lookups based on the
5205 * current root and not on the commit root. Those lookups will
5206 * fail, returning a -ESTALE error, and making send fail with
5207 * that error. So make sure a send does not see any orphans we
5208 * have just removed, and that it will see the same inodes
5209 * regardless of whether a transaction commit happened before
5210 * it started (meaning that the commit root will be the same as
5211 * the current root) or not.
5212 */
5213 if (sub_root->node != sub_root->commit_root) {
5214 u64 sub_flags = btrfs_root_flags(&sub_root->root_item);
5215
5216 if (sub_flags & BTRFS_ROOT_SUBVOL_RDONLY) {
5217 struct extent_buffer *eb;
5218
5219 /*
5220 * Assert we can't have races between dentry
5221 * lookup called through the snapshot creation
5222 * ioctl and the VFS.
5223 */
5224 ASSERT(mutex_is_locked(&dir->i_mutex));
5225
5226 down_write(&root->fs_info->commit_root_sem);
5227 eb = sub_root->commit_root;
5228 sub_root->commit_root =
5229 btrfs_root_node(sub_root);
5230 up_write(&root->fs_info->commit_root_sem);
5231 free_extent_buffer(eb);
5232 }
5233 }
5184 } 5234 }
5185 5235
5186 return inode; 5236 return inode;
@@ -5606,6 +5656,13 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
5606 } 5656 }
5607 5657
5608 /* 5658 /*
5659 * O_TMPFILE, set link count to 0, so that after this point,
5660 * we fill in an inode item with the correct link count.
5661 */
5662 if (!name)
5663 set_nlink(inode, 0);
5664
5665 /*
5609 * we have to initialize this early, so we can reclaim the inode 5666 * we have to initialize this early, so we can reclaim the inode
5610 * number if we fail afterwards in this function. 5667 * number if we fail afterwards in this function.
5611 */ 5668 */
@@ -6097,14 +6154,14 @@ out_fail:
6097static int merge_extent_mapping(struct extent_map_tree *em_tree, 6154static int merge_extent_mapping(struct extent_map_tree *em_tree,
6098 struct extent_map *existing, 6155 struct extent_map *existing,
6099 struct extent_map *em, 6156 struct extent_map *em,
6100 u64 map_start, u64 map_len) 6157 u64 map_start)
6101{ 6158{
6102 u64 start_diff; 6159 u64 start_diff;
6103 6160
6104 BUG_ON(map_start < em->start || map_start >= extent_map_end(em)); 6161 BUG_ON(map_start < em->start || map_start >= extent_map_end(em));
6105 start_diff = map_start - em->start; 6162 start_diff = map_start - em->start;
6106 em->start = map_start; 6163 em->start = map_start;
6107 em->len = map_len; 6164 em->len = existing->start - em->start;
6108 if (em->block_start < EXTENT_MAP_LAST_BYTE && 6165 if (em->block_start < EXTENT_MAP_LAST_BYTE &&
6109 !test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) { 6166 !test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) {
6110 em->block_start += start_diff; 6167 em->block_start += start_diff;
@@ -6275,6 +6332,8 @@ next:
6275 goto not_found; 6332 goto not_found;
6276 if (start + len <= found_key.offset) 6333 if (start + len <= found_key.offset)
6277 goto not_found; 6334 goto not_found;
6335 if (start > found_key.offset)
6336 goto next;
6278 em->start = start; 6337 em->start = start;
6279 em->orig_start = start; 6338 em->orig_start = start;
6280 em->len = found_key.offset - start; 6339 em->len = found_key.offset - start;
@@ -6390,8 +6449,7 @@ insert:
6390 em->len); 6449 em->len);
6391 if (existing) { 6450 if (existing) {
6392 err = merge_extent_mapping(em_tree, existing, 6451 err = merge_extent_mapping(em_tree, existing,
6393 em, start, 6452 em, start);
6394 root->sectorsize);
6395 free_extent_map(existing); 6453 free_extent_map(existing);
6396 if (err) { 6454 if (err) {
6397 free_extent_map(em); 6455 free_extent_map(em);
@@ -7158,7 +7216,8 @@ again:
7158 if (!ret) 7216 if (!ret)
7159 goto out_test; 7217 goto out_test;
7160 7218
7161 btrfs_init_work(&ordered->work, finish_ordered_fn, NULL, NULL); 7219 btrfs_init_work(&ordered->work, btrfs_endio_write_helper,
7220 finish_ordered_fn, NULL, NULL);
7162 btrfs_queue_work(root->fs_info->endio_write_workers, 7221 btrfs_queue_work(root->fs_info->endio_write_workers,
7163 &ordered->work); 7222 &ordered->work);
7164out_test: 7223out_test:
@@ -7306,10 +7365,8 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
7306 map_length = orig_bio->bi_iter.bi_size; 7365 map_length = orig_bio->bi_iter.bi_size;
7307 ret = btrfs_map_block(root->fs_info, rw, start_sector << 9, 7366 ret = btrfs_map_block(root->fs_info, rw, start_sector << 9,
7308 &map_length, NULL, 0); 7367 &map_length, NULL, 0);
7309 if (ret) { 7368 if (ret)
7310 bio_put(orig_bio);
7311 return -EIO; 7369 return -EIO;
7312 }
7313 7370
7314 if (map_length >= orig_bio->bi_iter.bi_size) { 7371 if (map_length >= orig_bio->bi_iter.bi_size) {
7315 bio = orig_bio; 7372 bio = orig_bio;
@@ -7326,6 +7383,7 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
7326 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS); 7383 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS);
7327 if (!bio) 7384 if (!bio)
7328 return -ENOMEM; 7385 return -ENOMEM;
7386
7329 bio->bi_private = dip; 7387 bio->bi_private = dip;
7330 bio->bi_end_io = btrfs_end_dio_bio; 7388 bio->bi_end_io = btrfs_end_dio_bio;
7331 atomic_inc(&dip->pending_bios); 7389 atomic_inc(&dip->pending_bios);
@@ -7534,7 +7592,8 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
7534 count = iov_iter_count(iter); 7592 count = iov_iter_count(iter);
7535 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 7593 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
7536 &BTRFS_I(inode)->runtime_flags)) 7594 &BTRFS_I(inode)->runtime_flags))
7537 filemap_fdatawrite_range(inode->i_mapping, offset, count); 7595 filemap_fdatawrite_range(inode->i_mapping, offset,
7596 offset + count - 1);
7538 7597
7539 if (rw & WRITE) { 7598 if (rw & WRITE) {
7540 /* 7599 /*
@@ -8495,7 +8554,9 @@ struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode,
8495 work->inode = inode; 8554 work->inode = inode;
8496 work->wait = wait; 8555 work->wait = wait;
8497 work->delay_iput = delay_iput; 8556 work->delay_iput = delay_iput;
8498 btrfs_init_work(&work->work, btrfs_run_delalloc_work, NULL, NULL); 8557 WARN_ON_ONCE(!inode);
8558 btrfs_init_work(&work->work, btrfs_flush_delalloc_helper,
8559 btrfs_run_delalloc_work, NULL, NULL);
8499 8560
8500 return work; 8561 return work;
8501} 8562}
@@ -8979,6 +9040,14 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
8979 if (ret) 9040 if (ret)
8980 goto out; 9041 goto out;
8981 9042
9043 /*
9044 * We set number of links to 0 in btrfs_new_inode(), and here we set
9045 * it to 1 because d_tmpfile() will issue a warning if the count is 0,
9046 * through:
9047 *
9048 * d_tmpfile() -> inode_dec_link_count() -> drop_nlink()
9049 */
9050 set_nlink(inode, 1);
8982 d_tmpfile(dentry, inode); 9051 d_tmpfile(dentry, inode);
8983 mark_inode_dirty(inode); 9052 mark_inode_dirty(inode);
8984 9053