diff options
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 111 |
1 files changed, 100 insertions, 11 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index 232bea425b09..dcaf972cbf1b 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
9 | #include <linux/mount.h> | 9 | #include <linux/mount.h> |
10 | #include <linux/vfs.h> | 10 | #include <linux/vfs.h> |
11 | #include <linux/quotaops.h> | ||
11 | #include <linux/mutex.h> | 12 | #include <linux/mutex.h> |
12 | #include <linux/exportfs.h> | 13 | #include <linux/exportfs.h> |
13 | #include <linux/writeback.h> | 14 | #include <linux/writeback.h> |
@@ -58,11 +59,6 @@ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct na | |||
58 | return NULL; | 59 | return NULL; |
59 | } | 60 | } |
60 | 61 | ||
61 | int simple_sync_file(struct file * file, struct dentry *dentry, int datasync) | ||
62 | { | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | int dcache_dir_open(struct inode *inode, struct file *file) | 62 | int dcache_dir_open(struct inode *inode, struct file *file) |
67 | { | 63 | { |
68 | static struct qstr cursor_name = {.len = 1, .name = "."}; | 64 | static struct qstr cursor_name = {.len = 1, .name = "."}; |
@@ -190,7 +186,7 @@ const struct file_operations simple_dir_operations = { | |||
190 | .llseek = dcache_dir_lseek, | 186 | .llseek = dcache_dir_lseek, |
191 | .read = generic_read_dir, | 187 | .read = generic_read_dir, |
192 | .readdir = dcache_readdir, | 188 | .readdir = dcache_readdir, |
193 | .fsync = simple_sync_file, | 189 | .fsync = noop_fsync, |
194 | }; | 190 | }; |
195 | 191 | ||
196 | const struct inode_operations simple_dir_inode_operations = { | 192 | const struct inode_operations simple_dir_inode_operations = { |
@@ -330,6 +326,81 @@ int simple_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
330 | return 0; | 326 | return 0; |
331 | } | 327 | } |
332 | 328 | ||
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 in-memory filesystem | ||
374 | * @dentry: dentry | ||
375 | * @iattr: iattr structure | ||
376 | * | ||
377 | * Returns 0 on success, -error on failure. | ||
378 | * | ||
379 | * simple_setattr implements setattr for an in-memory filesystem which | ||
380 | * does not store its own file data or metadata (eg. uses the page cache | ||
381 | * and inode cache as its data store). | ||
382 | */ | ||
383 | int simple_setattr(struct dentry *dentry, struct iattr *iattr) | ||
384 | { | ||
385 | struct inode *inode = dentry->d_inode; | ||
386 | int error; | ||
387 | |||
388 | error = inode_change_ok(inode, iattr); | ||
389 | if (error) | ||
390 | return error; | ||
391 | |||
392 | if (iattr->ia_valid & ATTR_SIZE) { | ||
393 | error = simple_setsize(inode, iattr->ia_size); | ||
394 | if (error) | ||
395 | return error; | ||
396 | } | ||
397 | |||
398 | generic_setattr(inode, iattr); | ||
399 | |||
400 | return error; | ||
401 | } | ||
402 | EXPORT_SYMBOL(simple_setattr); | ||
403 | |||
333 | int simple_readpage(struct file *file, struct page *page) | 404 | int simple_readpage(struct file *file, struct page *page) |
334 | { | 405 | { |
335 | clear_highpage(page); | 406 | clear_highpage(page); |
@@ -418,7 +489,8 @@ int simple_write_end(struct file *file, struct address_space *mapping, | |||
418 | * unique inode values later for this filesystem, then you must take care | 489 | * unique inode values later for this filesystem, then you must take care |
419 | * to pass it an appropriate max_reserved value to avoid collisions. | 490 | * to pass it an appropriate max_reserved value to avoid collisions. |
420 | */ | 491 | */ |
421 | int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files) | 492 | int simple_fill_super(struct super_block *s, unsigned long magic, |
493 | struct tree_descr *files) | ||
422 | { | 494 | { |
423 | struct inode *inode; | 495 | struct inode *inode; |
424 | struct dentry *root; | 496 | struct dentry *root; |
@@ -851,13 +923,22 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid, | |||
851 | } | 923 | } |
852 | EXPORT_SYMBOL_GPL(generic_fh_to_parent); | 924 | EXPORT_SYMBOL_GPL(generic_fh_to_parent); |
853 | 925 | ||
854 | int simple_fsync(struct file *file, struct dentry *dentry, int datasync) | 926 | /** |
927 | * generic_file_fsync - generic fsync implementation for simple filesystems | ||
928 | * @file: file to synchronize | ||
929 | * @datasync: only synchronize essential metadata if true | ||
930 | * | ||
931 | * This is a generic implementation of the fsync method for simple | ||
932 | * filesystems which track all non-inode metadata in the buffers list | ||
933 | * hanging off the address_space structure. | ||
934 | */ | ||
935 | int generic_file_fsync(struct file *file, int datasync) | ||
855 | { | 936 | { |
856 | struct writeback_control wbc = { | 937 | struct writeback_control wbc = { |
857 | .sync_mode = WB_SYNC_ALL, | 938 | .sync_mode = WB_SYNC_ALL, |
858 | .nr_to_write = 0, /* metadata-only; caller takes care of data */ | 939 | .nr_to_write = 0, /* metadata-only; caller takes care of data */ |
859 | }; | 940 | }; |
860 | struct inode *inode = dentry->d_inode; | 941 | struct inode *inode = file->f_mapping->host; |
861 | int err; | 942 | int err; |
862 | int ret; | 943 | int ret; |
863 | 944 | ||
@@ -872,7 +953,15 @@ int simple_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
872 | ret = err; | 953 | ret = err; |
873 | return ret; | 954 | return ret; |
874 | } | 955 | } |
875 | EXPORT_SYMBOL(simple_fsync); | 956 | EXPORT_SYMBOL(generic_file_fsync); |
957 | |||
958 | /* | ||
959 | * No-op implementation of ->fsync for in-memory filesystems. | ||
960 | */ | ||
961 | int noop_fsync(struct file *file, int datasync) | ||
962 | { | ||
963 | return 0; | ||
964 | } | ||
876 | 965 | ||
877 | EXPORT_SYMBOL(dcache_dir_close); | 966 | EXPORT_SYMBOL(dcache_dir_close); |
878 | EXPORT_SYMBOL(dcache_dir_lseek); | 967 | EXPORT_SYMBOL(dcache_dir_lseek); |
@@ -895,7 +984,7 @@ EXPORT_SYMBOL(simple_release_fs); | |||
895 | EXPORT_SYMBOL(simple_rename); | 984 | EXPORT_SYMBOL(simple_rename); |
896 | EXPORT_SYMBOL(simple_rmdir); | 985 | EXPORT_SYMBOL(simple_rmdir); |
897 | EXPORT_SYMBOL(simple_statfs); | 986 | EXPORT_SYMBOL(simple_statfs); |
898 | EXPORT_SYMBOL(simple_sync_file); | 987 | EXPORT_SYMBOL(noop_fsync); |
899 | EXPORT_SYMBOL(simple_unlink); | 988 | EXPORT_SYMBOL(simple_unlink); |
900 | EXPORT_SYMBOL(simple_read_from_buffer); | 989 | EXPORT_SYMBOL(simple_read_from_buffer); |
901 | EXPORT_SYMBOL(simple_write_to_buffer); | 990 | EXPORT_SYMBOL(simple_write_to_buffer); |