Skip to content

Commit 15c6fd9

Browse files
npiggin@suse.deAl Viro
authored andcommitted
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 <[email protected]> Signed-off-by: Nick Piggin <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 7bb46a6 commit 15c6fd9

File tree

10 files changed

+37
-22
lines changed

10 files changed

+37
-22
lines changed

fs/adfs/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr)
322322
if (error)
323323
goto out;
324324

325+
/* XXX: this is missing some actual on-disk truncation.. */
325326
if (ia_valid & ATTR_SIZE)
326-
error = vmtruncate(inode, attr->ia_size);
327+
error = simple_setsize(inode, attr->ia_size);
327328

328329
if (error)
329330
goto out;

fs/ecryptfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
805805
- (ia->ia_size & ~PAGE_CACHE_MASK));
806806

807807
if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
808-
rc = vmtruncate(inode, ia->ia_size);
808+
rc = simple_setsize(inode, ia->ia_size);
809809
if (rc)
810810
goto out;
811811
lower_ia->ia_size = ia->ia_size;
@@ -830,7 +830,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
830830
goto out;
831831
}
832832
}
833-
vmtruncate(inode, ia->ia_size);
833+
simple_setsize(inode, ia->ia_size);
834834
rc = ecryptfs_write_inode_size_to_metadata(inode);
835835
if (rc) {
836836
printk(KERN_ERR "Problem with "

fs/gfs2/aops.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,14 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
700700
return 0;
701701

702702
page_cache_release(page);
703+
704+
/*
705+
* XXX(hch): the call below should probably be replaced with
706+
* a call to the gfs2-specific truncate blocks helper to actually
707+
* release disk blocks..
708+
*/
703709
if (pos + len > ip->i_inode.i_size)
704-
vmtruncate(&ip->i_inode, ip->i_inode.i_size);
710+
simple_setsize(&ip->i_inode, ip->i_inode.i_size);
705711
out_endtrans:
706712
gfs2_trans_end(sdp);
707713
out_trans_fail:

fs/gfs2/ops_inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ int gfs2_permission(struct inode *inode, int mask)
10711071
return error;
10721072
}
10731073

1074+
/*
1075+
* XXX: should be changed to have proper ordering by opencoding simple_setsize
1076+
*/
10741077
static int setattr_size(struct inode *inode, struct iattr *attr)
10751078
{
10761079
struct gfs2_inode *ip = GFS2_I(inode);
@@ -1081,7 +1084,7 @@ static int setattr_size(struct inode *inode, struct iattr *attr)
10811084
error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
10821085
if (error)
10831086
return error;
1084-
error = vmtruncate(inode, attr->ia_size);
1087+
error = simple_setsize(inode, attr->ia_size);
10851088
gfs2_trans_end(sdp);
10861089
if (error)
10871090
return error;

fs/jffs2/fs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
169169
mutex_unlock(&f->sem);
170170
jffs2_complete_reservation(c);
171171

172-
/* We have to do the vmtruncate() without f->sem held, since
172+
/* We have to do the simple_setsize() without f->sem held, since
173173
some pages may be locked and waiting for it in readpage().
174174
We are protected from a simultaneous write() extending i_size
175175
back past iattr->ia_size, because do_truncate() holds the
176176
generic inode semaphore. */
177177
if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
178-
vmtruncate(inode, iattr->ia_size);
178+
simple_setsize(inode, iattr->ia_size);
179179
inode->i_blocks = (inode->i_size + 511) >> 9;
180180
}
181181

fs/ocfs2/file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
10521052
}
10531053

10541054
/*
1055-
* This will intentionally not wind up calling vmtruncate(),
1055+
* This will intentionally not wind up calling simple_setsize(),
10561056
* since all the work for a size change has been done above.
10571057
* Otherwise, we could get into problems with truncate as
10581058
* ip_alloc_sem is used there to protect against i_size
@@ -2118,9 +2118,13 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
21182118
* direct write may have instantiated a few
21192119
* blocks outside i_size. Trim these off again.
21202120
* Don't need i_size_read because we hold i_mutex.
2121+
*
2122+
* XXX(hch): this looks buggy because ocfs2 did not
2123+
* actually implement ->truncate. Take a look at
2124+
* the new truncate sequence and update this accordingly
21212125
*/
21222126
if (*ppos + count > inode->i_size)
2123-
vmtruncate(inode, inode->i_size);
2127+
simple_setsize(inode, inode->i_size);
21242128
ret = written;
21252129
goto out_dio;
21262130
}

fs/smbfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ smb_notify_change(struct dentry *dentry, struct iattr *attr)
714714
error = server->ops->truncate(inode, attr->ia_size);
715715
if (error)
716716
goto out;
717-
error = vmtruncate(inode, attr->ia_size);
717+
error = simple_setsize(inode, attr->ia_size);
718718
if (error)
719719
goto out;
720720
refresh = 1;

fs/ubifs/file.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,15 @@ static int do_writepage(struct page *page, int len)
967967
* the page locked, and it locks @ui_mutex. However, write-back does take inode
968968
* @i_mutex, which means other VFS operations may be run on this inode at the
969969
* same time. And the problematic one is truncation to smaller size, from where
970-
* we have to call 'vmtruncate()', which first changes @inode->i_size, then
970+
* we have to call 'simple_setsize()', which first changes @inode->i_size, then
971971
* drops the truncated pages. And while dropping the pages, it takes the page
972-
* lock. This means that 'do_truncation()' cannot call 'vmtruncate()' with
972+
* lock. This means that 'do_truncation()' cannot call 'simple_setsize()' with
973973
* @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This
974974
* means that @inode->i_size is changed while @ui_mutex is unlocked.
975975
*
976+
* XXX: with the new truncate the above is not true anymore, the simple_setsize
977+
* calls can be replaced with the individual components.
978+
*
976979
* But in 'ubifs_writepage()' we have to guarantee that we do not write beyond
977980
* inode size. How do we do this if @inode->i_size may became smaller while we
978981
* 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,
11251128
budgeted = 0;
11261129
}
11271130

1128-
err = vmtruncate(inode, new_size);
1131+
err = simple_setsize(inode, new_size);
11291132
if (err)
11301133
goto out_budg;
11311134

@@ -1214,7 +1217,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
12141217

12151218
if (attr->ia_valid & ATTR_SIZE) {
12161219
dbg_gen("size %lld -> %lld", inode->i_size, new_size);
1217-
err = vmtruncate(inode, new_size);
1220+
err = simple_setsize(inode, new_size);
12181221
if (err)
12191222
goto out;
12201223
}
@@ -1223,7 +1226,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
12231226
if (attr->ia_valid & ATTR_SIZE) {
12241227
/* Truncation changes inode [mc]time */
12251228
inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
1226-
/* 'vmtruncate()' changed @i_size, update @ui_size */
1229+
/* 'simple_setsize()' changed @i_size, update @ui_size */
12271230
ui->ui_size = inode->i_size;
12281231
}
12291232

fs/ubifs/ubifs.h

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

fs/ufs/truncate.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,10 @@ int ufs_truncate(struct inode *inode, loff_t old_i_size)
501501
return err;
502502
}
503503

504-
505504
/*
506-
* We don't define our `inode->i_op->truncate', and call it here,
507-
* because of:
508-
* - there is no way to know old size
509-
* - there is no way inform user about error, if it happens in `truncate'
505+
* TODO:
506+
* - truncate case should use proper ordering instead of using
507+
* simple_setsize
510508
*/
511509
int ufs_setattr(struct dentry *dentry, struct iattr *attr)
512510
{
@@ -530,7 +528,7 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
530528
if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
531529
loff_t old_i_size = inode->i_size;
532530

533-
error = vmtruncate(inode, attr->ia_size);
531+
error = simple_setsize(inode, attr->ia_size);
534532
if (error)
535533
return error;
536534
error = ufs_truncate(inode, old_i_size);

0 commit comments

Comments
 (0)