clean up vmtruncate
vmtruncate is a twisted maze of gotos, this patch cleans it up to have a proper if else for the two major cases of extending and truncating truncate and thus makes it a lot more readable while keeping exactly the same functinality. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
1b1b32f2c6
commit
61d5048f14
55
mm/memory.c
55
mm/memory.c
@@ -1909,50 +1909,49 @@ EXPORT_SYMBOL(unmap_mapping_range);
|
|||||||
*/
|
*/
|
||||||
int vmtruncate(struct inode * inode, loff_t offset)
|
int vmtruncate(struct inode * inode, loff_t offset)
|
||||||
{
|
{
|
||||||
struct address_space *mapping = inode->i_mapping;
|
if (inode->i_size < offset) {
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
|
|
||||||
if (inode->i_size < offset)
|
|
||||||
goto do_expand;
|
|
||||||
/*
|
|
||||||
* truncation of in-use swapfiles is disallowed - it would cause
|
|
||||||
* subsequent swapout to scribble on the now-freed blocks.
|
|
||||||
*/
|
|
||||||
if (IS_SWAPFILE(inode))
|
|
||||||
goto out_busy;
|
|
||||||
i_size_write(inode, offset);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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, offset + PAGE_SIZE - 1, 0, 1);
|
|
||||||
truncate_inode_pages(mapping, offset);
|
|
||||||
unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
|
|
||||||
goto out_truncate;
|
|
||||||
|
|
||||||
do_expand:
|
|
||||||
limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
|
limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
|
||||||
if (limit != RLIM_INFINITY && offset > limit)
|
if (limit != RLIM_INFINITY && offset > limit)
|
||||||
goto out_sig;
|
goto out_sig;
|
||||||
if (offset > inode->i_sb->s_maxbytes)
|
if (offset > inode->i_sb->s_maxbytes)
|
||||||
goto out_big;
|
goto out_big;
|
||||||
i_size_write(inode, offset);
|
i_size_write(inode, offset);
|
||||||
|
} else {
|
||||||
|
struct address_space *mapping = inode->i_mapping;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* truncation of in-use swapfiles is disallowed - it would
|
||||||
|
* cause subsequent swapout to scribble on the now-freed
|
||||||
|
* blocks.
|
||||||
|
*/
|
||||||
|
if (IS_SWAPFILE(inode))
|
||||||
|
return -ETXTBSY;
|
||||||
|
i_size_write(inode, offset);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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, offset + PAGE_SIZE - 1, 0, 1);
|
||||||
|
truncate_inode_pages(mapping, offset);
|
||||||
|
unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
out_truncate:
|
|
||||||
if (inode->i_op && inode->i_op->truncate)
|
if (inode->i_op && inode->i_op->truncate)
|
||||||
inode->i_op->truncate(inode);
|
inode->i_op->truncate(inode);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_sig:
|
out_sig:
|
||||||
send_sig(SIGXFSZ, current, 0);
|
send_sig(SIGXFSZ, current, 0);
|
||||||
out_big:
|
out_big:
|
||||||
return -EFBIG;
|
return -EFBIG;
|
||||||
out_busy:
|
|
||||||
return -ETXTBSY;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(vmtruncate);
|
EXPORT_SYMBOL(vmtruncate);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user