diff options
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 107 |
1 files changed, 45 insertions, 62 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index dcaf972cbf1b..304a5132ca27 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -255,7 +255,7 @@ int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *den | |||
255 | 255 | ||
256 | inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; | 256 | inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; |
257 | inc_nlink(inode); | 257 | inc_nlink(inode); |
258 | atomic_inc(&inode->i_count); | 258 | ihold(inode); |
259 | dget(dentry); | 259 | dget(dentry); |
260 | d_instantiate(dentry, inode); | 260 | d_instantiate(dentry, inode); |
261 | return 0; | 261 | return 0; |
@@ -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 | */ | ||
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 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 | */ |
383 | int simple_setattr(struct dentry *dentry, struct iattr *iattr) | 343 | int 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 | } |
402 | EXPORT_SYMBOL(simple_setattr); | 360 | EXPORT_SYMBOL(simple_setattr); |
403 | 361 | ||
@@ -934,10 +892,6 @@ EXPORT_SYMBOL_GPL(generic_fh_to_parent); | |||
934 | */ | 892 | */ |
935 | int generic_file_fsync(struct file *file, int datasync) | 893 | int generic_file_fsync(struct file *file, int datasync) |
936 | { | 894 | { |
937 | struct writeback_control wbc = { | ||
938 | .sync_mode = WB_SYNC_ALL, | ||
939 | .nr_to_write = 0, /* metadata-only; caller takes care of data */ | ||
940 | }; | ||
941 | struct inode *inode = file->f_mapping->host; | 895 | struct inode *inode = file->f_mapping->host; |
942 | int err; | 896 | int err; |
943 | int ret; | 897 | int ret; |
@@ -948,13 +902,42 @@ int generic_file_fsync(struct file *file, int datasync) | |||
948 | if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) | 902 | if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) |
949 | return ret; | 903 | return ret; |
950 | 904 | ||
951 | err = sync_inode(inode, &wbc); | 905 | err = sync_inode_metadata(inode, 1); |
952 | if (ret == 0) | 906 | if (ret == 0) |
953 | ret = err; | 907 | ret = err; |
954 | return ret; | 908 | return ret; |
955 | } | 909 | } |
956 | EXPORT_SYMBOL(generic_file_fsync); | 910 | EXPORT_SYMBOL(generic_file_fsync); |
957 | 911 | ||
912 | /** | ||
913 | * generic_check_addressable - Check addressability of file system | ||
914 | * @blocksize_bits: log of file system block size | ||
915 | * @num_blocks: number of blocks in file system | ||
916 | * | ||
917 | * Determine whether a file system with @num_blocks blocks (and a | ||
918 | * block size of 2**@blocksize_bits) is addressable by the sector_t | ||
919 | * and page cache of the system. Return 0 if so and -EFBIG otherwise. | ||
920 | */ | ||
921 | int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks) | ||
922 | { | ||
923 | u64 last_fs_block = num_blocks - 1; | ||
924 | u64 last_fs_page = | ||
925 | last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits); | ||
926 | |||
927 | if (unlikely(num_blocks == 0)) | ||
928 | return 0; | ||
929 | |||
930 | if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT)) | ||
931 | return -EINVAL; | ||
932 | |||
933 | if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) || | ||
934 | (last_fs_page > (pgoff_t)(~0ULL))) { | ||
935 | return -EFBIG; | ||
936 | } | ||
937 | return 0; | ||
938 | } | ||
939 | EXPORT_SYMBOL(generic_check_addressable); | ||
940 | |||
958 | /* | 941 | /* |
959 | * No-op implementation of ->fsync for in-memory filesystems. | 942 | * No-op implementation of ->fsync for in-memory filesystems. |
960 | */ | 943 | */ |