kill spurious reference to vmtruncate

Lots of filesystems calls vmtruncate despite not implementing the old
->truncate method.  Switch them to use simple_setsize and add some
comments about the truncate code where it seems fitting.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
npiggin@suse.de 2010-05-27 01:05:34 +10:00 committed by Al Viro
parent 7bb46a6734
commit 15c6fd9786
10 changed files with 37 additions and 22 deletions

View File

@ -322,8 +322,9 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr)
if (error) if (error)
goto out; goto out;
/* XXX: this is missing some actual on-disk truncation.. */
if (ia_valid & ATTR_SIZE) if (ia_valid & ATTR_SIZE)
error = vmtruncate(inode, attr->ia_size); error = simple_setsize(inode, attr->ia_size);
if (error) if (error)
goto out; goto out;

View File

@ -805,7 +805,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
- (ia->ia_size & ~PAGE_CACHE_MASK)); - (ia->ia_size & ~PAGE_CACHE_MASK));
if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
rc = vmtruncate(inode, ia->ia_size); rc = simple_setsize(inode, ia->ia_size);
if (rc) if (rc)
goto out; goto out;
lower_ia->ia_size = ia->ia_size; lower_ia->ia_size = ia->ia_size;
@ -830,7 +830,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
goto out; goto out;
} }
} }
vmtruncate(inode, ia->ia_size); simple_setsize(inode, ia->ia_size);
rc = ecryptfs_write_inode_size_to_metadata(inode); rc = ecryptfs_write_inode_size_to_metadata(inode);
if (rc) { if (rc) {
printk(KERN_ERR "Problem with " printk(KERN_ERR "Problem with "

View File

@ -700,8 +700,14 @@ out:
return 0; return 0;
page_cache_release(page); page_cache_release(page);
/*
* XXX(hch): the call below should probably be replaced with
* a call to the gfs2-specific truncate blocks helper to actually
* release disk blocks..
*/
if (pos + len > ip->i_inode.i_size) if (pos + len > ip->i_inode.i_size)
vmtruncate(&ip->i_inode, ip->i_inode.i_size); simple_setsize(&ip->i_inode, ip->i_inode.i_size);
out_endtrans: out_endtrans:
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
out_trans_fail: out_trans_fail:

View File

@ -1071,6 +1071,9 @@ int gfs2_permission(struct inode *inode, int mask)
return error; return error;
} }
/*
* XXX: should be changed to have proper ordering by opencoding simple_setsize
*/
static int setattr_size(struct inode *inode, struct iattr *attr) static int setattr_size(struct inode *inode, struct iattr *attr)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
@ -1081,7 +1084,7 @@ static int setattr_size(struct inode *inode, struct iattr *attr)
error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
if (error) if (error)
return error; return error;
error = vmtruncate(inode, attr->ia_size); error = simple_setsize(inode, attr->ia_size);
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
if (error) if (error)
return error; return error;

View File

@ -169,13 +169,13 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
mutex_unlock(&f->sem); mutex_unlock(&f->sem);
jffs2_complete_reservation(c); jffs2_complete_reservation(c);
/* We have to do the vmtruncate() without f->sem held, since /* We have to do the simple_setsize() without f->sem held, since
some pages may be locked and waiting for it in readpage(). some pages may be locked and waiting for it in readpage().
We are protected from a simultaneous write() extending i_size We are protected from a simultaneous write() extending i_size
back past iattr->ia_size, because do_truncate() holds the back past iattr->ia_size, because do_truncate() holds the
generic inode semaphore. */ generic inode semaphore. */
if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) { if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
vmtruncate(inode, iattr->ia_size); simple_setsize(inode, iattr->ia_size);
inode->i_blocks = (inode->i_size + 511) >> 9; inode->i_blocks = (inode->i_size + 511) >> 9;
} }

View File

@ -1052,7 +1052,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
} }
/* /*
* This will intentionally not wind up calling vmtruncate(), * This will intentionally not wind up calling simple_setsize(),
* since all the work for a size change has been done above. * since all the work for a size change has been done above.
* Otherwise, we could get into problems with truncate as * Otherwise, we could get into problems with truncate as
* ip_alloc_sem is used there to protect against i_size * ip_alloc_sem is used there to protect against i_size
@ -2118,9 +2118,13 @@ relock:
* direct write may have instantiated a few * direct write may have instantiated a few
* blocks outside i_size. Trim these off again. * blocks outside i_size. Trim these off again.
* Don't need i_size_read because we hold i_mutex. * Don't need i_size_read because we hold i_mutex.
*
* XXX(hch): this looks buggy because ocfs2 did not
* actually implement ->truncate. Take a look at
* the new truncate sequence and update this accordingly
*/ */
if (*ppos + count > inode->i_size) if (*ppos + count > inode->i_size)
vmtruncate(inode, inode->i_size); simple_setsize(inode, inode->i_size);
ret = written; ret = written;
goto out_dio; goto out_dio;
} }

View File

@ -714,7 +714,7 @@ smb_notify_change(struct dentry *dentry, struct iattr *attr)
error = server->ops->truncate(inode, attr->ia_size); error = server->ops->truncate(inode, attr->ia_size);
if (error) if (error)
goto out; goto out;
error = vmtruncate(inode, attr->ia_size); error = simple_setsize(inode, attr->ia_size);
if (error) if (error)
goto out; goto out;
refresh = 1; refresh = 1;

View File

@ -967,12 +967,15 @@ static int do_writepage(struct page *page, int len)
* the page locked, and it locks @ui_mutex. However, write-back does take inode * the page locked, and it locks @ui_mutex. However, write-back does take inode
* @i_mutex, which means other VFS operations may be run on this inode at the * @i_mutex, which means other VFS operations may be run on this inode at the
* same time. And the problematic one is truncation to smaller size, from where * same time. And the problematic one is truncation to smaller size, from where
* we have to call 'vmtruncate()', which first changes @inode->i_size, then * we have to call 'simple_setsize()', which first changes @inode->i_size, then
* drops the truncated pages. And while dropping the pages, it takes the page * drops the truncated pages. And while dropping the pages, it takes the page
* lock. This means that 'do_truncation()' cannot call 'vmtruncate()' with * lock. This means that 'do_truncation()' cannot call 'simple_setsize()' with
* @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This * @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This
* means that @inode->i_size is changed while @ui_mutex is unlocked. * means that @inode->i_size is changed while @ui_mutex is unlocked.
* *
* XXX: with the new truncate the above is not true anymore, the simple_setsize
* calls can be replaced with the individual components.
*
* But in 'ubifs_writepage()' we have to guarantee that we do not write beyond * But in 'ubifs_writepage()' we have to guarantee that we do not write beyond
* inode size. How do we do this if @inode->i_size may became smaller while we * inode size. How do we do this if @inode->i_size may became smaller while we
* are in the middle of 'ubifs_writepage()'? The UBIFS solution is the * are in the middle of 'ubifs_writepage()'? The UBIFS solution is the
@ -1125,7 +1128,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
budgeted = 0; budgeted = 0;
} }
err = vmtruncate(inode, new_size); err = simple_setsize(inode, new_size);
if (err) if (err)
goto out_budg; goto out_budg;
@ -1214,7 +1217,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
if (attr->ia_valid & ATTR_SIZE) { if (attr->ia_valid & ATTR_SIZE) {
dbg_gen("size %lld -> %lld", inode->i_size, new_size); dbg_gen("size %lld -> %lld", inode->i_size, new_size);
err = vmtruncate(inode, new_size); err = simple_setsize(inode, new_size);
if (err) if (err)
goto out; goto out;
} }
@ -1223,7 +1226,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
if (attr->ia_valid & ATTR_SIZE) { if (attr->ia_valid & ATTR_SIZE) {
/* Truncation changes inode [mc]time */ /* Truncation changes inode [mc]time */
inode->i_mtime = inode->i_ctime = ubifs_current_time(inode); inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
/* 'vmtruncate()' changed @i_size, update @ui_size */ /* 'simple_setsize()' changed @i_size, update @ui_size */
ui->ui_size = inode->i_size; ui->ui_size = inode->i_size;
} }

View File

@ -379,7 +379,7 @@ struct ubifs_gced_idx_leb {
* The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
* @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
* make sure @inode->i_size is always changed under @ui_mutex, because it * make sure @inode->i_size is always changed under @ui_mutex, because it
* cannot call 'vmtruncate()' with @ui_mutex locked, because it would deadlock * cannot call 'simple_setsize()' with @ui_mutex locked, because it would deadlock
* with 'ubifs_writepage()' (see file.c). All the other inode fields are * with 'ubifs_writepage()' (see file.c). All the other inode fields are
* changed under @ui_mutex, so they do not need "shadow" fields. Note, one * changed under @ui_mutex, so they do not need "shadow" fields. Note, one
* could consider to rework locking and base it on "shadow" fields. * could consider to rework locking and base it on "shadow" fields.

View File

@ -501,12 +501,10 @@ out:
return err; return err;
} }
/* /*
* We don't define our `inode->i_op->truncate', and call it here, * TODO:
* because of: * - truncate case should use proper ordering instead of using
* - there is no way to know old size * simple_setsize
* - there is no way inform user about error, if it happens in `truncate'
*/ */
int ufs_setattr(struct dentry *dentry, struct iattr *attr) int ufs_setattr(struct dentry *dentry, struct iattr *attr)
{ {
@ -530,7 +528,7 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) { if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
loff_t old_i_size = inode->i_size; loff_t old_i_size = inode->i_size;
error = vmtruncate(inode, attr->ia_size); error = simple_setsize(inode, attr->ia_size);
if (error) if (error)
return error; return error;
error = ufs_truncate(inode, old_i_size); error = ufs_truncate(inode, old_i_size);