diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 99 |
1 files changed, 84 insertions, 15 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index cb1c1ab2720b..cbfe13bf5b2a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -2880,8 +2880,6 @@ static void ext4_invalidatepage_free_endio(struct page *page, unsigned long offs | |||
2880 | 2880 | ||
2881 | static void ext4_invalidatepage(struct page *page, unsigned long offset) | 2881 | static void ext4_invalidatepage(struct page *page, unsigned long offset) |
2882 | { | 2882 | { |
2883 | journal_t *journal = EXT4_JOURNAL(page->mapping->host); | ||
2884 | |||
2885 | trace_ext4_invalidatepage(page, offset); | 2883 | trace_ext4_invalidatepage(page, offset); |
2886 | 2884 | ||
2887 | /* | 2885 | /* |
@@ -2889,16 +2887,34 @@ static void ext4_invalidatepage(struct page *page, unsigned long offset) | |||
2889 | */ | 2887 | */ |
2890 | if (ext4_should_dioread_nolock(page->mapping->host)) | 2888 | if (ext4_should_dioread_nolock(page->mapping->host)) |
2891 | ext4_invalidatepage_free_endio(page, offset); | 2889 | ext4_invalidatepage_free_endio(page, offset); |
2890 | |||
2891 | /* No journalling happens on data buffers when this function is used */ | ||
2892 | WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page))); | ||
2893 | |||
2894 | block_invalidatepage(page, offset); | ||
2895 | } | ||
2896 | |||
2897 | static int __ext4_journalled_invalidatepage(struct page *page, | ||
2898 | unsigned long offset) | ||
2899 | { | ||
2900 | journal_t *journal = EXT4_JOURNAL(page->mapping->host); | ||
2901 | |||
2902 | trace_ext4_journalled_invalidatepage(page, offset); | ||
2903 | |||
2892 | /* | 2904 | /* |
2893 | * If it's a full truncate we just forget about the pending dirtying | 2905 | * If it's a full truncate we just forget about the pending dirtying |
2894 | */ | 2906 | */ |
2895 | if (offset == 0) | 2907 | if (offset == 0) |
2896 | ClearPageChecked(page); | 2908 | ClearPageChecked(page); |
2897 | 2909 | ||
2898 | if (journal) | 2910 | return jbd2_journal_invalidatepage(journal, page, offset); |
2899 | jbd2_journal_invalidatepage(journal, page, offset); | 2911 | } |
2900 | else | 2912 | |
2901 | block_invalidatepage(page, offset); | 2913 | /* Wrapper for aops... */ |
2914 | static void ext4_journalled_invalidatepage(struct page *page, | ||
2915 | unsigned long offset) | ||
2916 | { | ||
2917 | WARN_ON(__ext4_journalled_invalidatepage(page, offset) < 0); | ||
2902 | } | 2918 | } |
2903 | 2919 | ||
2904 | static int ext4_releasepage(struct page *page, gfp_t wait) | 2920 | static int ext4_releasepage(struct page *page, gfp_t wait) |
@@ -3264,7 +3280,7 @@ static const struct address_space_operations ext4_journalled_aops = { | |||
3264 | .write_end = ext4_journalled_write_end, | 3280 | .write_end = ext4_journalled_write_end, |
3265 | .set_page_dirty = ext4_journalled_set_page_dirty, | 3281 | .set_page_dirty = ext4_journalled_set_page_dirty, |
3266 | .bmap = ext4_bmap, | 3282 | .bmap = ext4_bmap, |
3267 | .invalidatepage = ext4_invalidatepage, | 3283 | .invalidatepage = ext4_journalled_invalidatepage, |
3268 | .releasepage = ext4_releasepage, | 3284 | .releasepage = ext4_releasepage, |
3269 | .direct_IO = ext4_direct_IO, | 3285 | .direct_IO = ext4_direct_IO, |
3270 | .is_partially_uptodate = block_is_partially_uptodate, | 3286 | .is_partially_uptodate = block_is_partially_uptodate, |
@@ -4305,6 +4321,47 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) | |||
4305 | } | 4321 | } |
4306 | 4322 | ||
4307 | /* | 4323 | /* |
4324 | * In data=journal mode ext4_journalled_invalidatepage() may fail to invalidate | ||
4325 | * buffers that are attached to a page stradding i_size and are undergoing | ||
4326 | * commit. In that case we have to wait for commit to finish and try again. | ||
4327 | */ | ||
4328 | static void ext4_wait_for_tail_page_commit(struct inode *inode) | ||
4329 | { | ||
4330 | struct page *page; | ||
4331 | unsigned offset; | ||
4332 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; | ||
4333 | tid_t commit_tid = 0; | ||
4334 | int ret; | ||
4335 | |||
4336 | offset = inode->i_size & (PAGE_CACHE_SIZE - 1); | ||
4337 | /* | ||
4338 | * All buffers in the last page remain valid? Then there's nothing to | ||
4339 | * do. We do the check mainly to optimize the common PAGE_CACHE_SIZE == | ||
4340 | * blocksize case | ||
4341 | */ | ||
4342 | if (offset > PAGE_CACHE_SIZE - (1 << inode->i_blkbits)) | ||
4343 | return; | ||
4344 | while (1) { | ||
4345 | page = find_lock_page(inode->i_mapping, | ||
4346 | inode->i_size >> PAGE_CACHE_SHIFT); | ||
4347 | if (!page) | ||
4348 | return; | ||
4349 | ret = __ext4_journalled_invalidatepage(page, offset); | ||
4350 | unlock_page(page); | ||
4351 | page_cache_release(page); | ||
4352 | if (ret != -EBUSY) | ||
4353 | return; | ||
4354 | commit_tid = 0; | ||
4355 | read_lock(&journal->j_state_lock); | ||
4356 | if (journal->j_committing_transaction) | ||
4357 | commit_tid = journal->j_committing_transaction->t_tid; | ||
4358 | read_unlock(&journal->j_state_lock); | ||
4359 | if (commit_tid) | ||
4360 | jbd2_log_wait_commit(journal, commit_tid); | ||
4361 | } | ||
4362 | } | ||
4363 | |||
4364 | /* | ||
4308 | * ext4_setattr() | 4365 | * ext4_setattr() |
4309 | * | 4366 | * |
4310 | * Called from notify_change. | 4367 | * Called from notify_change. |
@@ -4417,16 +4474,28 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
4417 | } | 4474 | } |
4418 | 4475 | ||
4419 | if (attr->ia_valid & ATTR_SIZE) { | 4476 | if (attr->ia_valid & ATTR_SIZE) { |
4420 | if (attr->ia_size != i_size_read(inode)) { | 4477 | if (attr->ia_size != inode->i_size) { |
4421 | truncate_setsize(inode, attr->ia_size); | 4478 | loff_t oldsize = inode->i_size; |
4422 | /* Inode size will be reduced, wait for dio in flight. | 4479 | |
4423 | * Temporarily disable dioread_nolock to prevent | 4480 | i_size_write(inode, attr->ia_size); |
4424 | * livelock. */ | 4481 | /* |
4482 | * Blocks are going to be removed from the inode. Wait | ||
4483 | * for dio in flight. Temporarily disable | ||
4484 | * dioread_nolock to prevent livelock. | ||
4485 | */ | ||
4425 | if (orphan) { | 4486 | if (orphan) { |
4426 | ext4_inode_block_unlocked_dio(inode); | 4487 | if (!ext4_should_journal_data(inode)) { |
4427 | inode_dio_wait(inode); | 4488 | ext4_inode_block_unlocked_dio(inode); |
4428 | ext4_inode_resume_unlocked_dio(inode); | 4489 | inode_dio_wait(inode); |
4490 | ext4_inode_resume_unlocked_dio(inode); | ||
4491 | } else | ||
4492 | ext4_wait_for_tail_page_commit(inode); | ||
4429 | } | 4493 | } |
4494 | /* | ||
4495 | * Truncate pagecache after we've waited for commit | ||
4496 | * in data=journal mode to make pages freeable. | ||
4497 | */ | ||
4498 | truncate_pagecache(inode, oldsize, inode->i_size); | ||
4430 | } | 4499 | } |
4431 | ext4_truncate(inode); | 4500 | ext4_truncate(inode); |
4432 | } | 4501 | } |