aboutsummaryrefslogtreecommitdiffstats
path: root/fs/libfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/libfs.c')
-rw-r--r--fs/libfs.c70
1 files changed, 14 insertions, 56 deletions
diff --git a/fs/libfs.c b/fs/libfs.c
index dcaf972cbf1b..0a9da95317f7 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -327,77 +327,35 @@ 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 330 * simple_setattr - setattr for simple filesystem
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 */
355int 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}
370EXPORT_SYMBOL(simple_setsize);
371
372/**
373 * simple_setattr - setattr for simple in-memory filesystem
374 * @dentry: dentry 331 * @dentry: dentry
375 * @iattr: iattr structure 332 * @iattr: iattr structure
376 * 333 *
377 * Returns 0 on success, -error on failure. 334 * Returns 0 on success, -error on failure.
378 * 335 *
379 * simple_setattr implements setattr for an in-memory filesystem which 336 * simple_setattr is a simple ->setattr implementation without a proper
380 * does not store its own file data or metadata (eg. uses the page cache 337 * implementation of size changes.
381 * and inode cache as its data store). 338 *
339 * It can either be used for in-memory filesystems or special files
340 * on simple regular filesystems. Anything that needs to change on-disk
341 * or wire state on size changes needs its own setattr method.
382 */ 342 */
383int simple_setattr(struct dentry *dentry, struct iattr *iattr) 343int simple_setattr(struct dentry *dentry, struct iattr *iattr)
384{ 344{
385 struct inode *inode = dentry->d_inode; 345 struct inode *inode = dentry->d_inode;
386 int error; 346 int error;
387 347
348 WARN_ON_ONCE(inode->i_op->truncate);
349
388 error = inode_change_ok(inode, iattr); 350 error = inode_change_ok(inode, iattr);
389 if (error) 351 if (error)
390 return error; 352 return error;
391 353
392 if (iattr->ia_valid & ATTR_SIZE) { 354 if (iattr->ia_valid & ATTR_SIZE)
393 error = simple_setsize(inode, iattr->ia_size); 355 truncate_setsize(inode, iattr->ia_size);
394 if (error) 356 setattr_copy(inode, iattr);
395 return error; 357 mark_inode_dirty(inode);
396 } 358 return 0;
397
398 generic_setattr(inode, iattr);
399
400 return error;
401} 359}
402EXPORT_SYMBOL(simple_setattr); 360EXPORT_SYMBOL(simple_setattr);
403 361