diff options
author | Christoph Hellwig <hch@lst.de> | 2010-06-04 05:30:04 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-08-09 16:47:39 -0400 |
commit | 2c27c65ed0696f0b5df2dad2cf6462d72164d547 (patch) | |
tree | 7d9036e3dea98938f7fd7074366ee73929e9b2e5 /fs/libfs.c | |
parent | db78b877f7744bec4a9d9f9e7d10da3931d7cd39 (diff) |
check ATTR_SIZE contraints in inode_change_ok
Make sure we check the truncate constraints early on in ->setattr by adding
those checks to inode_change_ok. Also clean up and document inode_change_ok
to make this obvious.
As a fallout we don't have to call inode_newsize_ok from simple_setsize and
simplify it down to a truncate_setsize which doesn't return an error. This
simplifies a lot of setattr implementations and means we use truncate_setsize
almost everywhere. Get rid of fat_setsize now that it's trivial and mark
ext2_setsize static to make the calling convention obvious.
Keep the inode_newsize_ok in vmtruncate for now as all callers need an
audit for its removal anyway.
Note: setattr code in ecryptfs doesn't call inode_change_ok at all and
needs a deeper audit, but that is left for later.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index 40562224b718..0a9da95317f7 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -327,49 +327,6 @@ int simple_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
327 | } | 327 | } |
328 | 328 | ||
329 | /** | 329 | /** |
330 | * simple_setsize - handle core mm and vfs requirements for file size change | ||
331 | * @inode: inode | ||
332 | * @newsize: new file size | ||
333 | * | ||
334 | * Returns 0 on success, -error on failure. | ||
335 | * | ||
336 | * simple_setsize must be called with inode_mutex held. | ||
337 | * | ||
338 | * simple_setsize will check that the requested new size is OK (see | ||
339 | * inode_newsize_ok), and then will perform the necessary i_size update | ||
340 | * and pagecache truncation (if necessary). It will be typically be called | ||
341 | * from the filesystem's setattr function when ATTR_SIZE is passed in. | ||
342 | * | ||
343 | * The inode itself must have correct permissions and attributes to allow | ||
344 | * i_size to be changed, this function then just checks that the new size | ||
345 | * requested is valid. | ||
346 | * | ||
347 | * In the case of simple in-memory filesystems with inodes stored solely | ||
348 | * in the inode cache, and file data in the pagecache, nothing more needs | ||
349 | * to be done to satisfy a truncate request. Filesystems with on-disk | ||
350 | * blocks for example will need to free them in the case of truncate, in | ||
351 | * that case it may be easier not to use simple_setsize (but each of its | ||
352 | * components will likely be required at some point to update pagecache | ||
353 | * and inode etc). | ||
354 | */ | ||
355 | int simple_setsize(struct inode *inode, loff_t newsize) | ||
356 | { | ||
357 | loff_t oldsize; | ||
358 | int error; | ||
359 | |||
360 | error = inode_newsize_ok(inode, newsize); | ||
361 | if (error) | ||
362 | return error; | ||
363 | |||
364 | oldsize = inode->i_size; | ||
365 | i_size_write(inode, newsize); | ||
366 | truncate_pagecache(inode, oldsize, newsize); | ||
367 | |||
368 | return error; | ||
369 | } | ||
370 | EXPORT_SYMBOL(simple_setsize); | ||
371 | |||
372 | /** | ||
373 | * simple_setattr - setattr for simple filesystem | 330 | * simple_setattr - setattr for simple filesystem |
374 | * @dentry: dentry | 331 | * @dentry: dentry |
375 | * @iattr: iattr structure | 332 | * @iattr: iattr structure |
@@ -394,12 +351,8 @@ int simple_setattr(struct dentry *dentry, struct iattr *iattr) | |||
394 | if (error) | 351 | if (error) |
395 | return error; | 352 | return error; |
396 | 353 | ||
397 | if (iattr->ia_valid & ATTR_SIZE) { | 354 | if (iattr->ia_valid & ATTR_SIZE) |
398 | error = simple_setsize(inode, iattr->ia_size); | 355 | truncate_setsize(inode, iattr->ia_size); |
399 | if (error) | ||
400 | return error; | ||
401 | } | ||
402 | |||
403 | setattr_copy(inode, iattr); | 356 | setattr_copy(inode, iattr); |
404 | mark_inode_dirty(inode); | 357 | mark_inode_dirty(inode); |
405 | return 0; | 358 | return 0; |