Skip to content

Commit 3889e6e

Browse files
npiggin@suse.deAl Viro
authored andcommitted
tmpfs: convert to use the new truncate convention
Cc: Christoph Hellwig <[email protected]> Acked-by: Hugh Dickins <[email protected]> Signed-off-by: Nick Piggin <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 3322e79 commit 3889e6e

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

mm/shmem.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,11 @@ static void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end)
727727
if (inode->i_mapping->nrpages && (info->flags & SHMEM_PAGEIN)) {
728728
/*
729729
* Call truncate_inode_pages again: racing shmem_unuse_inode
730-
* may have swizzled a page in from swap since vmtruncate or
731-
* generic_delete_inode did it, before we lowered next_index.
732-
* Also, though shmem_getpage checks i_size before adding to
733-
* cache, no recheck after: so fix the narrow window there too.
730+
* may have swizzled a page in from swap since
731+
* truncate_pagecache or generic_delete_inode did it, before we
732+
* lowered next_index. Also, though shmem_getpage checks
733+
* i_size before adding to cache, no recheck after: so fix the
734+
* narrow window there too.
734735
*
735736
* Recalling truncate_inode_pages_range and unmap_mapping_range
736737
* every time for punch_hole (which never got a chance to clear
@@ -760,29 +761,26 @@ static void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end)
760761
}
761762
}
762763

763-
static void shmem_truncate(struct inode *inode)
764-
{
765-
shmem_truncate_range(inode, inode->i_size, (loff_t)-1);
766-
}
767-
768764
static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
769765
{
770766
struct inode *inode = dentry->d_inode;
771-
struct page *page = NULL;
772767
int error;
773768

774769
if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) {
775-
if (attr->ia_size < inode->i_size) {
770+
loff_t newsize = attr->ia_size;
771+
struct page *page = NULL;
772+
773+
if (newsize < inode->i_size) {
776774
/*
777775
* If truncating down to a partial page, then
778776
* if that page is already allocated, hold it
779777
* in memory until the truncation is over, so
780778
* truncate_partial_page cannnot miss it were
781779
* it assigned to swap.
782780
*/
783-
if (attr->ia_size & (PAGE_CACHE_SIZE-1)) {
781+
if (newsize & (PAGE_CACHE_SIZE-1)) {
784782
(void) shmem_getpage(inode,
785-
attr->ia_size>>PAGE_CACHE_SHIFT,
783+
newsize >> PAGE_CACHE_SHIFT,
786784
&page, SGP_READ, NULL);
787785
if (page)
788786
unlock_page(page);
@@ -794,36 +792,41 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
794792
* if it's being fully truncated to zero-length: the
795793
* nrpages check is efficient enough in that case.
796794
*/
797-
if (attr->ia_size) {
795+
if (newsize) {
798796
struct shmem_inode_info *info = SHMEM_I(inode);
799797
spin_lock(&info->lock);
800798
info->flags &= ~SHMEM_PAGEIN;
801799
spin_unlock(&info->lock);
802800
}
803801
}
802+
803+
error = simple_setsize(inode, newsize);
804+
if (page)
805+
page_cache_release(page);
806+
if (error)
807+
return error;
808+
shmem_truncate_range(inode, newsize, (loff_t)-1);
804809
}
805810

806811
error = inode_change_ok(inode, attr);
807812
if (!error)
808-
error = inode_setattr(inode, attr);
813+
generic_setattr(inode, attr);
809814
#ifdef CONFIG_TMPFS_POSIX_ACL
810815
if (!error && (attr->ia_valid & ATTR_MODE))
811816
error = generic_acl_chmod(inode);
812817
#endif
813-
if (page)
814-
page_cache_release(page);
815818
return error;
816819
}
817820

818821
static void shmem_delete_inode(struct inode *inode)
819822
{
820823
struct shmem_inode_info *info = SHMEM_I(inode);
821824

822-
if (inode->i_op->truncate == shmem_truncate) {
825+
if (inode->i_mapping->a_ops == &shmem_aops) {
823826
truncate_inode_pages(inode->i_mapping, 0);
824827
shmem_unacct_size(info->flags, inode->i_size);
825828
inode->i_size = 0;
826-
shmem_truncate(inode);
829+
shmem_truncate_range(inode, 0, (loff_t)-1);
827830
if (!list_empty(&info->swaplist)) {
828831
mutex_lock(&shmem_swaplist_mutex);
829832
list_del_init(&info->swaplist);
@@ -2022,7 +2025,6 @@ static const struct inode_operations shmem_symlink_inline_operations = {
20222025
};
20232026

20242027
static const struct inode_operations shmem_symlink_inode_operations = {
2025-
.truncate = shmem_truncate,
20262028
.readlink = generic_readlink,
20272029
.follow_link = shmem_follow_link,
20282030
.put_link = shmem_put_link,
@@ -2440,7 +2442,6 @@ static const struct file_operations shmem_file_operations = {
24402442
};
24412443

24422444
static const struct inode_operations shmem_inode_operations = {
2443-
.truncate = shmem_truncate,
24442445
.setattr = shmem_notify_change,
24452446
.truncate_range = shmem_truncate_range,
24462447
#ifdef CONFIG_TMPFS_POSIX_ACL

0 commit comments

Comments
 (0)