aboutsummaryrefslogtreecommitdiffstats
path: root/mm/truncate.c
diff options
context:
space:
mode:
authorHugh Dickins <hughd@google.com>2011-07-25 20:12:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:57:10 -0400
commit8a549bea51138be2126a2cc6aabe8f17ef66b79b (patch)
treedc6e0afdf59808238dd44c685d897da98852fca5 /mm/truncate.c
parent85821aab39b3403a8b5731812a930b78684d1642 (diff)
mm: tidy vmtruncate_range and related functions
Use consistent variable names in truncate_pagecache(), truncate_setsize(), vmtruncate() and vmtruncate_range(). unmap_mapping_range() and vmtruncate_range() have mismatched interfaces: don't change either, but make the vmtruncates more precise about what they expect unmap_mapping_range() to do. vmtruncate_range() is currently called only with page-aligned start and end+1: can handle unaligned start, but unaligned end+1 would hit BUG_ON in truncate_inode_pages_range() (lacks partial clearing of the end page). Signed-off-by: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/truncate.c')
-rw-r--r--mm/truncate.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/mm/truncate.c b/mm/truncate.c
index 003c6c685fc8..c924764e2ce5 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -531,8 +531,8 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages2);
531/** 531/**
532 * truncate_pagecache - unmap and remove pagecache that has been truncated 532 * truncate_pagecache - unmap and remove pagecache that has been truncated
533 * @inode: inode 533 * @inode: inode
534 * @old: old file offset 534 * @oldsize: old file size
535 * @new: new file offset 535 * @newsize: new file size
536 * 536 *
537 * inode's new i_size must already be written before truncate_pagecache 537 * inode's new i_size must already be written before truncate_pagecache
538 * is called. 538 * is called.
@@ -544,9 +544,10 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages2);
544 * situations such as writepage being called for a page that has already 544 * situations such as writepage being called for a page that has already
545 * had its underlying blocks deallocated. 545 * had its underlying blocks deallocated.
546 */ 546 */
547void truncate_pagecache(struct inode *inode, loff_t old, loff_t new) 547void truncate_pagecache(struct inode *inode, loff_t oldsize, loff_t newsize)
548{ 548{
549 struct address_space *mapping = inode->i_mapping; 549 struct address_space *mapping = inode->i_mapping;
550 loff_t holebegin = round_up(newsize, PAGE_SIZE);
550 551
551 /* 552 /*
552 * unmap_mapping_range is called twice, first simply for 553 * unmap_mapping_range is called twice, first simply for
@@ -557,9 +558,9 @@ void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
557 * truncate_inode_pages finishes, hence the second 558 * truncate_inode_pages finishes, hence the second
558 * unmap_mapping_range call must be made for correctness. 559 * unmap_mapping_range call must be made for correctness.
559 */ 560 */
560 unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1); 561 unmap_mapping_range(mapping, holebegin, 0, 1);
561 truncate_inode_pages(mapping, new); 562 truncate_inode_pages(mapping, newsize);
562 unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1); 563 unmap_mapping_range(mapping, holebegin, 0, 1);
563} 564}
564EXPORT_SYMBOL(truncate_pagecache); 565EXPORT_SYMBOL(truncate_pagecache);
565 566
@@ -589,29 +590,31 @@ EXPORT_SYMBOL(truncate_setsize);
589/** 590/**
590 * vmtruncate - unmap mappings "freed" by truncate() syscall 591 * vmtruncate - unmap mappings "freed" by truncate() syscall
591 * @inode: inode of the file used 592 * @inode: inode of the file used
592 * @offset: file offset to start truncating 593 * @newsize: file offset to start truncating
593 * 594 *
594 * This function is deprecated and truncate_setsize or truncate_pagecache 595 * This function is deprecated and truncate_setsize or truncate_pagecache
595 * should be used instead, together with filesystem specific block truncation. 596 * should be used instead, together with filesystem specific block truncation.
596 */ 597 */
597int vmtruncate(struct inode *inode, loff_t offset) 598int vmtruncate(struct inode *inode, loff_t newsize)
598{ 599{
599 int error; 600 int error;
600 601
601 error = inode_newsize_ok(inode, offset); 602 error = inode_newsize_ok(inode, newsize);
602 if (error) 603 if (error)
603 return error; 604 return error;
604 605
605 truncate_setsize(inode, offset); 606 truncate_setsize(inode, newsize);
606 if (inode->i_op->truncate) 607 if (inode->i_op->truncate)
607 inode->i_op->truncate(inode); 608 inode->i_op->truncate(inode);
608 return 0; 609 return 0;
609} 610}
610EXPORT_SYMBOL(vmtruncate); 611EXPORT_SYMBOL(vmtruncate);
611 612
612int vmtruncate_range(struct inode *inode, loff_t offset, loff_t end) 613int vmtruncate_range(struct inode *inode, loff_t lstart, loff_t lend)
613{ 614{
614 struct address_space *mapping = inode->i_mapping; 615 struct address_space *mapping = inode->i_mapping;
616 loff_t holebegin = round_up(lstart, PAGE_SIZE);
617 loff_t holelen = 1 + lend - holebegin;
615 618
616 /* 619 /*
617 * If the underlying filesystem is not going to provide 620 * If the underlying filesystem is not going to provide
@@ -623,10 +626,10 @@ int vmtruncate_range(struct inode *inode, loff_t offset, loff_t end)
623 626
624 mutex_lock(&inode->i_mutex); 627 mutex_lock(&inode->i_mutex);
625 inode_dio_wait(inode); 628 inode_dio_wait(inode);
626 unmap_mapping_range(mapping, offset, (end - offset), 1); 629 unmap_mapping_range(mapping, holebegin, holelen, 1);
627 inode->i_op->truncate_range(inode, offset, end); 630 inode->i_op->truncate_range(inode, lstart, lend);
628 /* unmap again to remove racily COWed private pages */ 631 /* unmap again to remove racily COWed private pages */
629 unmap_mapping_range(mapping, offset, (end - offset), 1); 632 unmap_mapping_range(mapping, holebegin, holelen, 1);
630 mutex_unlock(&inode->i_mutex); 633 mutex_unlock(&inode->i_mutex);
631 634
632 return 0; 635 return 0;