Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] vfs: Fix vmtruncate() regression

0 views
Skip to first unread message

OGAWA Hirofumi

unread,
Jan 11, 2010, 1:50:02 PM1/11/10
to
Hi,

Could you review this one?

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.

Cc: sta...@kernel.org
Signed-off-by: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>
---

mm/truncate.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c
--- linux-2.6/mm/truncate.c~truncate_pagecache-fix 2010-01-12 02:41:27.000000000 +0900
+++ linux-2.6-hirofumi/mm/truncate.c 2010-01-12 02:42:53.000000000 +0900
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
*/
void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
{
- if (new < old) {
- struct address_space *mapping = inode->i_mapping;
+ struct address_space *mapping = inode->i_mapping;

- /*
- * unmap_mapping_range is called twice, first simply for
- * efficiency so that truncate_inode_pages does fewer
- * single-page unmaps. However after this first call, and
- * before truncate_inode_pages finishes, it is possible for
- * private pages to be COWed, which remain after
- * truncate_inode_pages finishes, hence the second
- * unmap_mapping_range call must be made for correctness.
- */
- unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
- truncate_inode_pages(mapping, new);
- unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
- }
+ /*
+ * unmap_mapping_range is called twice, first simply for
+ * efficiency so that truncate_inode_pages does fewer
+ * single-page unmaps. However after this first call, and
+ * before truncate_inode_pages finishes, it is possible for
+ * private pages to be COWed, which remain after
+ * truncate_inode_pages finishes, hence the second
+ * unmap_mapping_range call must be made for correctness.
+ */
+ unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+ truncate_inode_pages(mapping, new);
+ unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
}
EXPORT_SYMBOL(truncate_pagecache);

_

--
OGAWA Hirofumi <hiro...@mail.parknet.co.jp>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Nick Piggin

unread,
Jan 13, 2010, 1:10:02 AM1/13/10
to
On Tue, Jan 12, 2010 at 03:40:42AM +0900, OGAWA Hirofumi wrote:
> Hi,
>
> Could you review this one?
>
>
>
> 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.
>
> Cc: sta...@kernel.org
> Signed-off-by: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>

Hmm, truncate_pagecache() is for truncating the mm/vm part of the
pagecache. vmtruncate should still call inode->i_op->truncate() to
trim blocks if required.

However I'd say we do still need to ensure do_invalidatepage is
called for the page, for private metadata. So yes I think your patch
looks good.

Acked-by: Nick Piggin <npi...@suse.de>

Please apply to mainline and 2.6.32.

OGAWA Hirofumi

unread,
Jan 13, 2010, 7:10:01 AM1/13/10
to
Nick Piggin <npi...@suse.de> writes:

>> 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.
>>
>> Cc: sta...@kernel.org
>> Signed-off-by: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>
>
> Hmm, truncate_pagecache() is for truncating the mm/vm part of the
> pagecache. vmtruncate should still call inode->i_op->truncate() to
> trim blocks if required.
>
> However I'd say we do still need to ensure do_invalidatepage is
> called for the page, for private metadata. So yes I think your patch
> looks good.

Thanks for reviewing. Yes, and it also needs to be called to ensure that
have the same state on-disk and page/bh state. [BTW, this became the
cause of fatfs corruption.]

Thanks.

OGAWA Hirofumi

unread,
Jan 13, 2010, 7:20:02 AM1/13/10
to

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 <npi...@suse.de>
Signed-off-by: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>
---

mm/truncate.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c
--- linux-2.6/mm/truncate.c~truncate_pagecache-fix 2010-01-12 05:43:06.000000000 +0900
+++ linux-2.6-hirofumi/mm/truncate.c 2010-01-12 05:43:06.000000000 +0900

Andrew Morton

unread,
Jan 14, 2010, 5:40:04 PM1/14/10
to

The fix was applied to 2.6.33-rcX
(cedabed49b39b4319bccc059a63344b6232b619c), appears to be needed in
2.6.32.x but no cc:stable's are present?

OGAWA Hirofumi

unread,
Jan 14, 2010, 7:30:02 PM1/14/10
to
Andrew Morton <ak...@linux-foundation.org> writes:

Ah, yes. I forgot to add "Cc: stable". Please apply this to 2.6.32.x.
--
OGAWA Hirofumi <hiro...@mail.parknet.co.jp>

Nick Piggin

unread,
Jan 17, 2010, 11:00:01 PM1/17/10
to

Thanks guys, it's quite important so please apply to stable 2.6.32 and
consider it as a high priority to release.

Greg KH

unread,
Jan 19, 2010, 7:10:02 PM1/19/10
to

Now queued up for the next .32 -stable release.

greg k-h

0 new messages