diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d8bb0dbc4941..a7d1921ac76b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -3754,7 +3754,7 @@ void btrfs_evict_inode(struct inode *inode) | |||
3754 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | 3754 | btrfs_wait_ordered_range(inode, 0, (u64)-1); |
3755 | 3755 | ||
3756 | if (root->fs_info->log_root_recovering) { | 3756 | if (root->fs_info->log_root_recovering) { |
3757 | BUG_ON(!test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, | 3757 | BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
3758 | &BTRFS_I(inode)->runtime_flags)); | 3758 | &BTRFS_I(inode)->runtime_flags)); |
3759 | goto no_delete; | 3759 | goto no_delete; |
3760 | } | 3760 | } |
@@ -5876,8 +5876,17 @@ map: | |||
5876 | bh_result->b_size = len; | 5876 | bh_result->b_size = len; |
5877 | bh_result->b_bdev = em->bdev; | 5877 | bh_result->b_bdev = em->bdev; |
5878 | set_buffer_mapped(bh_result); | 5878 | set_buffer_mapped(bh_result); |
5879 | if (create && !test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) | 5879 | if (create) { |
5880 | set_buffer_new(bh_result); | 5880 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) |
5881 | set_buffer_new(bh_result); | ||
5882 | |||
5883 | /* | ||
5884 | * Need to update the i_size under the extent lock so buffered | ||
5885 | * readers will get the updated i_size when we unlock. | ||
5886 | */ | ||
5887 | if (start + len > i_size_read(inode)) | ||
5888 | i_size_write(inode, start + len); | ||
5889 | } | ||
5881 | 5890 | ||
5882 | free_extent_map(em); | 5891 | free_extent_map(em); |
5883 | 5892 | ||
@@ -6360,12 +6369,48 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
6360 | */ | 6369 | */ |
6361 | ordered = btrfs_lookup_ordered_range(inode, lockstart, | 6370 | ordered = btrfs_lookup_ordered_range(inode, lockstart, |
6362 | lockend - lockstart + 1); | 6371 | lockend - lockstart + 1); |
6363 | if (!ordered) | 6372 | |
6373 | /* | ||
6374 | * We need to make sure there are no buffered pages in this | ||
6375 | * range either, we could have raced between the invalidate in | ||
6376 | * generic_file_direct_write and locking the extent. The | ||
6377 | * invalidate needs to happen so that reads after a write do not | ||
6378 | * get stale data. | ||
6379 | */ | ||
6380 | if (!ordered && (!writing || | ||
6381 | !test_range_bit(&BTRFS_I(inode)->io_tree, | ||
6382 | lockstart, lockend, EXTENT_UPTODATE, 0, | ||
6383 | cached_state))) | ||
6364 | break; | 6384 | break; |
6385 | |||
6365 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, | 6386 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, |
6366 | &cached_state, GFP_NOFS); | 6387 | &cached_state, GFP_NOFS); |
6367 | btrfs_start_ordered_extent(inode, ordered, 1); | 6388 | |
6368 | btrfs_put_ordered_extent(ordered); | 6389 | if (ordered) { |
6390 | btrfs_start_ordered_extent(inode, ordered, 1); | ||
6391 | btrfs_put_ordered_extent(ordered); | ||
6392 | } else { | ||
6393 | /* Screw you mmap */ | ||
6394 | ret = filemap_write_and_wait_range(file->f_mapping, | ||
6395 | lockstart, | ||
6396 | lockend); | ||
6397 | if (ret) | ||
6398 | goto out; | ||
6399 | |||
6400 | /* | ||
6401 | * If we found a page that couldn't be invalidated just | ||
6402 | * fall back to buffered. | ||
6403 | */ | ||
6404 | ret = invalidate_inode_pages2_range(file->f_mapping, | ||
6405 | lockstart >> PAGE_CACHE_SHIFT, | ||
6406 | lockend >> PAGE_CACHE_SHIFT); | ||
6407 | if (ret) { | ||
6408 | if (ret == -EBUSY) | ||
6409 | ret = 0; | ||
6410 | goto out; | ||
6411 | } | ||
6412 | } | ||
6413 | |||
6369 | cond_resched(); | 6414 | cond_resched(); |
6370 | } | 6415 | } |
6371 | 6416 | ||