Skip to content

Commit cedabed

Browse files
OGAWAHirofumitorvalds
authored andcommitted
vfs: Fix vmtruncate() regression
If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size. But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore. So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change. Acked-by: Nick Piggin <npiggin@suse.de> Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e80c14e commit cedabed

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

‎mm/truncate.c‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages2);
522522
*/
523523
void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
524524
{
525-
if (new < old) {
526-
struct address_space *mapping = inode->i_mapping;
527-
528-
/*
529-
* unmap_mapping_range is called twice, first simply for
530-
* efficiency so that truncate_inode_pages does fewer
531-
* single-page unmaps. However after this first call, and
532-
* before truncate_inode_pages finishes, it is possible for
533-
* private pages to be COWed, which remain after
534-
* truncate_inode_pages finishes, hence the second
535-
* unmap_mapping_range call must be made for correctness.
536-
*/
537-
unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
538-
truncate_inode_pages(mapping, new);
539-
unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
540-
}
525+
struct address_space *mapping = inode->i_mapping;
526+
527+
/*
528+
* unmap_mapping_range is called twice, first simply for
529+
* efficiency so that truncate_inode_pages does fewer
530+
* single-page unmaps. However after this first call, and
531+
* before truncate_inode_pages finishes, it is possible for
532+
* private pages to be COWed, which remain after
533+
* truncate_inode_pages finishes, hence the second
534+
* unmap_mapping_range call must be made for correctness.
535+
*/
536+
unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
537+
truncate_inode_pages(mapping, new);
538+
unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
541539
}
542540
EXPORT_SYMBOL(truncate_pagecache);
543541

0 commit comments

Comments
 (0)