diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-28 13:07:48 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-28 13:07:48 -0400 |
commit | 89ad6a6173127e5d31bea7a4a45ec23fa5bf4a17 (patch) | |
tree | 6feb3d663ee48b790a0be2420647e43bc20c31ad | |
parent | aa36c7bf987dfa5597c0f7c46f8fca46b2dd33d2 (diff) | |
parent | 49837a80b38b79a7c06217b2c40842aeb6fa13b9 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
remove detritus left by "mm: make read_cache_page synchronous"
fix fs/sysv s_dirt handling
fat: convert to use the new truncate convention.
ext2: convert to use the new truncate convention.
tmpfs: convert to use the new truncate convention
fs: convert simple fs to new truncate
kill spurious reference to vmtruncate
fs: introduce new truncate sequence
fs/super: fix kernel-doc warning
fs/minix: bugfix, number of indirect block ptrs per block depends on block size
rename the generic fsync implementations
drop unused dentry argument to ->fsync
fs: Add missing mutex_unlock
Fix racy use of anon_inode_getfd() in perf_event.c
get rid of the magic around f_count in aio
VFS: fix recent breakage of FS_REVAL_DOT
Revert "anon_inode: set S_IFREG on the anon_inode"
112 files changed, 782 insertions, 415 deletions
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index 61c98f03baa1..96d4293607ec 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking | |||
@@ -380,7 +380,7 @@ prototypes: | |||
380 | int (*open) (struct inode *, struct file *); | 380 | int (*open) (struct inode *, struct file *); |
381 | int (*flush) (struct file *); | 381 | int (*flush) (struct file *); |
382 | int (*release) (struct inode *, struct file *); | 382 | int (*release) (struct inode *, struct file *); |
383 | int (*fsync) (struct file *, struct dentry *, int datasync); | 383 | int (*fsync) (struct file *, int datasync); |
384 | int (*aio_fsync) (struct kiocb *, int datasync); | 384 | int (*aio_fsync) (struct kiocb *, int datasync); |
385 | int (*fasync) (int, struct file *, int); | 385 | int (*fasync) (int, struct file *, int); |
386 | int (*lock) (struct file *, int, struct file_lock *); | 386 | int (*lock) (struct file *, int, struct file_lock *); |
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index b66858538df5..94677e7dcb13 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt | |||
@@ -401,11 +401,16 @@ otherwise noted. | |||
401 | started might not be in the page cache at the end of the | 401 | started might not be in the page cache at the end of the |
402 | walk). | 402 | walk). |
403 | 403 | ||
404 | truncate: called by the VFS to change the size of a file. The | 404 | truncate: Deprecated. This will not be called if ->setsize is defined. |
405 | Called by the VFS to change the size of a file. The | ||
405 | i_size field of the inode is set to the desired size by the | 406 | i_size field of the inode is set to the desired size by the |
406 | VFS before this method is called. This method is called by | 407 | VFS before this method is called. This method is called by |
407 | the truncate(2) system call and related functionality. | 408 | the truncate(2) system call and related functionality. |
408 | 409 | ||
410 | Note: ->truncate and vmtruncate are deprecated. Do not add new | ||
411 | instances/calls of these. Filesystems should be converted to do their | ||
412 | truncate sequence via ->setattr(). | ||
413 | |||
409 | permission: called by the VFS to check for access rights on a POSIX-like | 414 | permission: called by the VFS to check for access rights on a POSIX-like |
410 | filesystem. | 415 | filesystem. |
411 | 416 | ||
@@ -729,7 +734,7 @@ struct file_operations { | |||
729 | int (*open) (struct inode *, struct file *); | 734 | int (*open) (struct inode *, struct file *); |
730 | int (*flush) (struct file *); | 735 | int (*flush) (struct file *); |
731 | int (*release) (struct inode *, struct file *); | 736 | int (*release) (struct inode *, struct file *); |
732 | int (*fsync) (struct file *, struct dentry *, int datasync); | 737 | int (*fsync) (struct file *, int datasync); |
733 | int (*aio_fsync) (struct kiocb *, int datasync); | 738 | int (*aio_fsync) (struct kiocb *, int datasync); |
734 | int (*fasync) (int, struct file *, int); | 739 | int (*fasync) (int, struct file *, int); |
735 | int (*lock) (struct file *, int, struct file_lock *); | 740 | int (*lock) (struct file *, int, struct file_lock *); |
diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c index 5c2808252516..1a40da92154c 100644 --- a/arch/powerpc/platforms/cell/spufs/file.c +++ b/arch/powerpc/platforms/cell/spufs/file.c | |||
@@ -1849,8 +1849,7 @@ out: | |||
1849 | return ret; | 1849 | return ret; |
1850 | } | 1850 | } |
1851 | 1851 | ||
1852 | static int spufs_mfc_fsync(struct file *file, struct dentry *dentry, | 1852 | static int spufs_mfc_fsync(struct file *file, int datasync) |
1853 | int datasync) | ||
1854 | { | 1853 | { |
1855 | return spufs_mfc_flush(file, NULL); | 1854 | return spufs_mfc_flush(file, NULL); |
1856 | } | 1855 | } |
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c index fc1b1c42b1dc..e5e5f823d687 100644 --- a/arch/powerpc/platforms/cell/spufs/inode.c +++ b/arch/powerpc/platforms/cell/spufs/inode.c | |||
@@ -251,7 +251,7 @@ const struct file_operations spufs_context_fops = { | |||
251 | .llseek = dcache_dir_lseek, | 251 | .llseek = dcache_dir_lseek, |
252 | .read = generic_read_dir, | 252 | .read = generic_read_dir, |
253 | .readdir = dcache_readdir, | 253 | .readdir = dcache_readdir, |
254 | .fsync = simple_sync_file, | 254 | .fsync = noop_fsync, |
255 | }; | 255 | }; |
256 | EXPORT_SYMBOL_GPL(spufs_context_fops); | 256 | EXPORT_SYMBOL_GPL(spufs_context_fops); |
257 | 257 | ||
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c index 606048b72bcf..85c004a518ee 100644 --- a/drivers/char/ps3flash.c +++ b/drivers/char/ps3flash.c | |||
@@ -305,8 +305,7 @@ static int ps3flash_flush(struct file *file, fl_owner_t id) | |||
305 | return ps3flash_writeback(ps3flash_dev); | 305 | return ps3flash_writeback(ps3flash_dev); |
306 | } | 306 | } |
307 | 307 | ||
308 | static int ps3flash_fsync(struct file *file, struct dentry *dentry, | 308 | static int ps3flash_fsync(struct file *file, int datasync) |
309 | int datasync) | ||
310 | { | 309 | { |
311 | return ps3flash_writeback(ps3flash_dev); | 310 | return ps3flash_writeback(ps3flash_dev); |
312 | } | 311 | } |
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 72ebb3f06b86..4dfa6b90c21c 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -189,8 +189,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin) | |||
189 | return new_offset; | 189 | return new_offset; |
190 | } | 190 | } |
191 | 191 | ||
192 | static int vol_cdev_fsync(struct file *file, struct dentry *dentry, | 192 | static int vol_cdev_fsync(struct file *file, int datasync) |
193 | int datasync) | ||
194 | { | 193 | { |
195 | struct ubi_volume_desc *desc = file->private_data; | 194 | struct ubi_volume_desc *desc = file->private_data; |
196 | struct ubi_device *ubi = desc->vol->ubi; | 195 | struct ubi_device *ubi = desc->vol->ubi; |
diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c index 9286e863b0e7..e92595eff1b8 100644 --- a/drivers/staging/pohmelfs/inode.c +++ b/drivers/staging/pohmelfs/inode.c | |||
@@ -880,7 +880,7 @@ static struct inode *pohmelfs_alloc_inode(struct super_block *sb) | |||
880 | /* | 880 | /* |
881 | * We want fsync() to work on POHMELFS. | 881 | * We want fsync() to work on POHMELFS. |
882 | */ | 882 | */ |
883 | static int pohmelfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 883 | static int pohmelfs_fsync(struct file *file, int datasync) |
884 | { | 884 | { |
885 | struct inode *inode = file->f_mapping->host; | 885 | struct inode *inode = file->f_mapping->host; |
886 | struct writeback_control wbc = { | 886 | struct writeback_control wbc = { |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 6b8bf8c781c4..43abf55d8c60 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -794,7 +794,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
794 | } | 794 | } |
795 | 795 | ||
796 | static int | 796 | static int |
797 | printer_fsync(struct file *fd, struct dentry *dentry, int datasync) | 797 | printer_fsync(struct file *fd, int datasync) |
798 | { | 798 | { |
799 | struct printer_dev *dev = fd->private_data; | 799 | struct printer_dev *dev = fd->private_data; |
800 | unsigned long flags; | 800 | unsigned long flags; |
diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c index 1105a591dcc1..073c9b408cf7 100644 --- a/drivers/video/fb_defio.c +++ b/drivers/video/fb_defio.c | |||
@@ -66,7 +66,7 @@ static int fb_deferred_io_fault(struct vm_area_struct *vma, | |||
66 | return 0; | 66 | return 0; |
67 | } | 67 | } |
68 | 68 | ||
69 | int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, int datasync) | 69 | int fb_deferred_io_fsync(struct file *file, int datasync) |
70 | { | 70 | { |
71 | struct fb_info *info = file->private_data; | 71 | struct fb_info *info = file->private_data; |
72 | 72 | ||
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 25b300e1c9d7..2bedc6c94fc2 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
@@ -257,15 +257,13 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
257 | return total; | 257 | return total; |
258 | } | 258 | } |
259 | 259 | ||
260 | static int v9fs_file_fsync(struct file *filp, struct dentry *dentry, | 260 | static int v9fs_file_fsync(struct file *filp, int datasync) |
261 | int datasync) | ||
262 | { | 261 | { |
263 | struct p9_fid *fid; | 262 | struct p9_fid *fid; |
264 | struct p9_wstat wstat; | 263 | struct p9_wstat wstat; |
265 | int retval; | 264 | int retval; |
266 | 265 | ||
267 | P9_DPRINTK(P9_DEBUG_VFS, "filp %p dentry %p datasync %x\n", filp, | 266 | P9_DPRINTK(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync); |
268 | dentry, datasync); | ||
269 | 267 | ||
270 | fid = filp->private_data; | 268 | fid = filp->private_data; |
271 | v9fs_blank_wstat(&wstat); | 269 | v9fs_blank_wstat(&wstat); |
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c index 23aa52f548a0..f4287e4de744 100644 --- a/fs/adfs/dir.c +++ b/fs/adfs/dir.c | |||
@@ -197,7 +197,7 @@ const struct file_operations adfs_dir_operations = { | |||
197 | .read = generic_read_dir, | 197 | .read = generic_read_dir, |
198 | .llseek = generic_file_llseek, | 198 | .llseek = generic_file_llseek, |
199 | .readdir = adfs_readdir, | 199 | .readdir = adfs_readdir, |
200 | .fsync = simple_fsync, | 200 | .fsync = generic_file_fsync, |
201 | }; | 201 | }; |
202 | 202 | ||
203 | static int | 203 | static int |
diff --git a/fs/adfs/file.c b/fs/adfs/file.c index 005ea34d1758..a36da5382b40 100644 --- a/fs/adfs/file.c +++ b/fs/adfs/file.c | |||
@@ -26,7 +26,7 @@ const struct file_operations adfs_file_operations = { | |||
26 | .read = do_sync_read, | 26 | .read = do_sync_read, |
27 | .aio_read = generic_file_aio_read, | 27 | .aio_read = generic_file_aio_read, |
28 | .mmap = generic_file_mmap, | 28 | .mmap = generic_file_mmap, |
29 | .fsync = simple_fsync, | 29 | .fsync = generic_file_fsync, |
30 | .write = do_sync_write, | 30 | .write = do_sync_write, |
31 | .aio_write = generic_file_aio_write, | 31 | .aio_write = generic_file_aio_write, |
32 | .splice_read = generic_file_splice_read, | 32 | .splice_read = generic_file_splice_read, |
diff --git a/fs/adfs/inode.c b/fs/adfs/inode.c index 0f5e30978135..6f850b06ab62 100644 --- a/fs/adfs/inode.c +++ b/fs/adfs/inode.c | |||
@@ -322,8 +322,9 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr) | |||
322 | if (error) | 322 | if (error) |
323 | goto out; | 323 | goto out; |
324 | 324 | ||
325 | /* XXX: this is missing some actual on-disk truncation.. */ | ||
325 | if (ia_valid & ATTR_SIZE) | 326 | if (ia_valid & ATTR_SIZE) |
326 | error = vmtruncate(inode, attr->ia_size); | 327 | error = simple_setsize(inode, attr->ia_size); |
327 | 328 | ||
328 | if (error) | 329 | if (error) |
329 | goto out; | 330 | goto out; |
diff --git a/fs/affs/affs.h b/fs/affs/affs.h index 861dae68ac12..f05b6155ccc8 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h | |||
@@ -183,7 +183,7 @@ extern int affs_add_entry(struct inode *dir, struct inode *inode, struct dent | |||
183 | 183 | ||
184 | void affs_free_prealloc(struct inode *inode); | 184 | void affs_free_prealloc(struct inode *inode); |
185 | extern void affs_truncate(struct inode *); | 185 | extern void affs_truncate(struct inode *); |
186 | int affs_file_fsync(struct file *, struct dentry *, int); | 186 | int affs_file_fsync(struct file *, int); |
187 | 187 | ||
188 | /* dir.c */ | 188 | /* dir.c */ |
189 | 189 | ||
diff --git a/fs/affs/file.c b/fs/affs/file.c index 184e55c1c9ba..322710c3eedf 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c | |||
@@ -916,9 +916,9 @@ affs_truncate(struct inode *inode) | |||
916 | affs_free_prealloc(inode); | 916 | affs_free_prealloc(inode); |
917 | } | 917 | } |
918 | 918 | ||
919 | int affs_file_fsync(struct file *filp, struct dentry *dentry, int datasync) | 919 | int affs_file_fsync(struct file *filp, int datasync) |
920 | { | 920 | { |
921 | struct inode * inode = dentry->d_inode; | 921 | struct inode *inode = filp->f_mapping->host; |
922 | int ret, err; | 922 | int ret, err; |
923 | 923 | ||
924 | ret = write_inode_now(inode, 0); | 924 | ret = write_inode_now(inode, 0); |
diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 807f284cc75e..5f679b77ce24 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h | |||
@@ -740,7 +740,7 @@ extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); | |||
740 | extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, | 740 | extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, |
741 | unsigned long, loff_t); | 741 | unsigned long, loff_t); |
742 | extern int afs_writeback_all(struct afs_vnode *); | 742 | extern int afs_writeback_all(struct afs_vnode *); |
743 | extern int afs_fsync(struct file *, struct dentry *, int); | 743 | extern int afs_fsync(struct file *, int); |
744 | 744 | ||
745 | 745 | ||
746 | /*****************************************************************************/ | 746 | /*****************************************************************************/ |
diff --git a/fs/afs/write.c b/fs/afs/write.c index 3bed54a294d4..3dab9e9948d0 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c | |||
@@ -701,8 +701,9 @@ int afs_writeback_all(struct afs_vnode *vnode) | |||
701 | * - the return status from this call provides a reliable indication of | 701 | * - the return status from this call provides a reliable indication of |
702 | * whether any write errors occurred for this process. | 702 | * whether any write errors occurred for this process. |
703 | */ | 703 | */ |
704 | int afs_fsync(struct file *file, struct dentry *dentry, int datasync) | 704 | int afs_fsync(struct file *file, int datasync) |
705 | { | 705 | { |
706 | struct dentry *dentry = file->f_path.dentry; | ||
706 | struct afs_writeback *wb, *xwb; | 707 | struct afs_writeback *wb, *xwb; |
707 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); | 708 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); |
708 | int ret; | 709 | int ret; |
@@ -527,7 +527,7 @@ static void aio_fput_routine(struct work_struct *data) | |||
527 | 527 | ||
528 | /* Complete the fput(s) */ | 528 | /* Complete the fput(s) */ |
529 | if (req->ki_filp != NULL) | 529 | if (req->ki_filp != NULL) |
530 | __fput(req->ki_filp); | 530 | fput(req->ki_filp); |
531 | 531 | ||
532 | /* Link the iocb into the context's free list */ | 532 | /* Link the iocb into the context's free list */ |
533 | spin_lock_irq(&ctx->ctx_lock); | 533 | spin_lock_irq(&ctx->ctx_lock); |
@@ -560,11 +560,11 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) | |||
560 | 560 | ||
561 | /* | 561 | /* |
562 | * Try to optimize the aio and eventfd file* puts, by avoiding to | 562 | * Try to optimize the aio and eventfd file* puts, by avoiding to |
563 | * schedule work in case it is not __fput() time. In normal cases, | 563 | * schedule work in case it is not final fput() time. In normal cases, |
564 | * we would not be holding the last reference to the file*, so | 564 | * we would not be holding the last reference to the file*, so |
565 | * this function will be executed w/out any aio kthread wakeup. | 565 | * this function will be executed w/out any aio kthread wakeup. |
566 | */ | 566 | */ |
567 | if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count))) { | 567 | if (unlikely(!fput_atomic(req->ki_filp))) { |
568 | get_ioctx(ctx); | 568 | get_ioctx(ctx); |
569 | spin_lock(&fput_lock); | 569 | spin_lock(&fput_lock); |
570 | list_add(&req->ki_list, &fput_head); | 570 | list_add(&req->ki_list, &fput_head); |
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 9bd4b3876c99..e4b75d6eda83 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c | |||
@@ -205,7 +205,7 @@ static struct inode *anon_inode_mkinode(void) | |||
205 | * that it already _is_ on the dirty list. | 205 | * that it already _is_ on the dirty list. |
206 | */ | 206 | */ |
207 | inode->i_state = I_DIRTY; | 207 | inode->i_state = I_DIRTY; |
208 | inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR; | 208 | inode->i_mode = S_IRUSR | S_IWUSR; |
209 | inode->i_uid = current_fsuid(); | 209 | inode->i_uid = current_fsuid(); |
210 | inode->i_gid = current_fsgid(); | 210 | inode->i_gid = current_fsgid(); |
211 | inode->i_flags |= S_PRIVATE; | 211 | inode->i_flags |= S_PRIVATE; |
@@ -67,14 +67,14 @@ EXPORT_SYMBOL(inode_change_ok); | |||
67 | * @offset: the new size to assign to the inode | 67 | * @offset: the new size to assign to the inode |
68 | * @Returns: 0 on success, -ve errno on failure | 68 | * @Returns: 0 on success, -ve errno on failure |
69 | * | 69 | * |
70 | * inode_newsize_ok must be called with i_mutex held. | ||
71 | * | ||
70 | * inode_newsize_ok will check filesystem limits and ulimits to check that the | 72 | * inode_newsize_ok will check filesystem limits and ulimits to check that the |
71 | * new inode size is within limits. inode_newsize_ok will also send SIGXFSZ | 73 | * new inode size is within limits. inode_newsize_ok will also send SIGXFSZ |
72 | * when necessary. Caller must not proceed with inode size change if failure is | 74 | * when necessary. Caller must not proceed with inode size change if failure is |
73 | * returned. @inode must be a file (not directory), with appropriate | 75 | * returned. @inode must be a file (not directory), with appropriate |
74 | * permissions to allow truncate (inode_newsize_ok does NOT check these | 76 | * permissions to allow truncate (inode_newsize_ok does NOT check these |
75 | * conditions). | 77 | * conditions). |
76 | * | ||
77 | * inode_newsize_ok must be called with i_mutex held. | ||
78 | */ | 78 | */ |
79 | int inode_newsize_ok(const struct inode *inode, loff_t offset) | 79 | int inode_newsize_ok(const struct inode *inode, loff_t offset) |
80 | { | 80 | { |
@@ -104,17 +104,25 @@ out_big: | |||
104 | } | 104 | } |
105 | EXPORT_SYMBOL(inode_newsize_ok); | 105 | EXPORT_SYMBOL(inode_newsize_ok); |
106 | 106 | ||
107 | int inode_setattr(struct inode * inode, struct iattr * attr) | 107 | /** |
108 | * generic_setattr - copy simple metadata updates into the generic inode | ||
109 | * @inode: the inode to be updated | ||
110 | * @attr: the new attributes | ||
111 | * | ||
112 | * generic_setattr must be called with i_mutex held. | ||
113 | * | ||
114 | * generic_setattr updates the inode's metadata with that specified | ||
115 | * in attr. Noticably missing is inode size update, which is more complex | ||
116 | * as it requires pagecache updates. See simple_setsize. | ||
117 | * | ||
118 | * The inode is not marked as dirty after this operation. The rationale is | ||
119 | * that for "simple" filesystems, the struct inode is the inode storage. | ||
120 | * The caller is free to mark the inode dirty afterwards if needed. | ||
121 | */ | ||
122 | void generic_setattr(struct inode *inode, const struct iattr *attr) | ||
108 | { | 123 | { |
109 | unsigned int ia_valid = attr->ia_valid; | 124 | unsigned int ia_valid = attr->ia_valid; |
110 | 125 | ||
111 | if (ia_valid & ATTR_SIZE && | ||
112 | attr->ia_size != i_size_read(inode)) { | ||
113 | int error = vmtruncate(inode, attr->ia_size); | ||
114 | if (error) | ||
115 | return error; | ||
116 | } | ||
117 | |||
118 | if (ia_valid & ATTR_UID) | 126 | if (ia_valid & ATTR_UID) |
119 | inode->i_uid = attr->ia_uid; | 127 | inode->i_uid = attr->ia_uid; |
120 | if (ia_valid & ATTR_GID) | 128 | if (ia_valid & ATTR_GID) |
@@ -135,6 +143,28 @@ int inode_setattr(struct inode * inode, struct iattr * attr) | |||
135 | mode &= ~S_ISGID; | 143 | mode &= ~S_ISGID; |
136 | inode->i_mode = mode; | 144 | inode->i_mode = mode; |
137 | } | 145 | } |
146 | } | ||
147 | EXPORT_SYMBOL(generic_setattr); | ||
148 | |||
149 | /* | ||
150 | * note this function is deprecated, the new truncate sequence should be | ||
151 | * used instead -- see eg. simple_setsize, generic_setattr. | ||
152 | */ | ||
153 | int inode_setattr(struct inode *inode, const struct iattr *attr) | ||
154 | { | ||
155 | unsigned int ia_valid = attr->ia_valid; | ||
156 | |||
157 | if (ia_valid & ATTR_SIZE && | ||
158 | attr->ia_size != i_size_read(inode)) { | ||
159 | int error; | ||
160 | |||
161 | error = vmtruncate(inode, attr->ia_size); | ||
162 | if (error) | ||
163 | return error; | ||
164 | } | ||
165 | |||
166 | generic_setattr(inode, attr); | ||
167 | |||
138 | mark_inode_dirty(inode); | 168 | mark_inode_dirty(inode); |
139 | 169 | ||
140 | return 0; | 170 | return 0; |
diff --git a/fs/bad_inode.c b/fs/bad_inode.c index a05287a23f62..52e59bf4aa5f 100644 --- a/fs/bad_inode.c +++ b/fs/bad_inode.c | |||
@@ -93,8 +93,7 @@ static int bad_file_release(struct inode *inode, struct file *filp) | |||
93 | return -EIO; | 93 | return -EIO; |
94 | } | 94 | } |
95 | 95 | ||
96 | static int bad_file_fsync(struct file *file, struct dentry *dentry, | 96 | static int bad_file_fsync(struct file *file, int datasync) |
97 | int datasync) | ||
98 | { | 97 | { |
99 | return -EIO; | 98 | return -EIO; |
100 | } | 99 | } |
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c index 8f73841fc974..d967e052b779 100644 --- a/fs/bfs/dir.c +++ b/fs/bfs/dir.c | |||
@@ -78,7 +78,7 @@ static int bfs_readdir(struct file *f, void *dirent, filldir_t filldir) | |||
78 | const struct file_operations bfs_dir_operations = { | 78 | const struct file_operations bfs_dir_operations = { |
79 | .read = generic_read_dir, | 79 | .read = generic_read_dir, |
80 | .readdir = bfs_readdir, | 80 | .readdir = bfs_readdir, |
81 | .fsync = simple_fsync, | 81 | .fsync = generic_file_fsync, |
82 | .llseek = generic_file_llseek, | 82 | .llseek = generic_file_llseek, |
83 | }; | 83 | }; |
84 | 84 | ||
diff --git a/fs/block_dev.c b/fs/block_dev.c index 26e5f5026620..7346c96308a5 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -172,8 +172,9 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
172 | struct file *file = iocb->ki_filp; | 172 | struct file *file = iocb->ki_filp; |
173 | struct inode *inode = file->f_mapping->host; | 173 | struct inode *inode = file->f_mapping->host; |
174 | 174 | ||
175 | return blockdev_direct_IO_no_locking(rw, iocb, inode, I_BDEV(inode), | 175 | return blockdev_direct_IO_no_locking_newtrunc(rw, iocb, inode, |
176 | iov, offset, nr_segs, blkdev_get_blocks, NULL); | 176 | I_BDEV(inode), iov, offset, nr_segs, |
177 | blkdev_get_blocks, NULL); | ||
177 | } | 178 | } |
178 | 179 | ||
179 | int __sync_blockdev(struct block_device *bdev, int wait) | 180 | int __sync_blockdev(struct block_device *bdev, int wait) |
@@ -309,8 +310,8 @@ static int blkdev_write_begin(struct file *file, struct address_space *mapping, | |||
309 | struct page **pagep, void **fsdata) | 310 | struct page **pagep, void **fsdata) |
310 | { | 311 | { |
311 | *pagep = NULL; | 312 | *pagep = NULL; |
312 | return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 313 | return block_write_begin_newtrunc(file, mapping, pos, len, flags, |
313 | blkdev_get_block); | 314 | pagep, fsdata, blkdev_get_block); |
314 | } | 315 | } |
315 | 316 | ||
316 | static int blkdev_write_end(struct file *file, struct address_space *mapping, | 317 | static int blkdev_write_end(struct file *file, struct address_space *mapping, |
@@ -358,12 +359,7 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin) | |||
358 | return retval; | 359 | return retval; |
359 | } | 360 | } |
360 | 361 | ||
361 | /* | 362 | int blkdev_fsync(struct file *filp, int datasync) |
362 | * Filp is never NULL; the only case when ->fsync() is called with | ||
363 | * NULL first argument is nfsd_sync_dir() and that's not a directory. | ||
364 | */ | ||
365 | |||
366 | int blkdev_fsync(struct file *filp, struct dentry *dentry, int datasync) | ||
367 | { | 363 | { |
368 | struct inode *bd_inode = filp->f_mapping->host; | 364 | struct inode *bd_inode = filp->f_mapping->host; |
369 | struct block_device *bdev = I_BDEV(bd_inode); | 365 | struct block_device *bdev = I_BDEV(bd_inode); |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e9bf86415e86..29c20092847e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -2434,7 +2434,7 @@ void btrfs_update_iflags(struct inode *inode); | |||
2434 | void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); | 2434 | void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); |
2435 | 2435 | ||
2436 | /* file.c */ | 2436 | /* file.c */ |
2437 | int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync); | 2437 | int btrfs_sync_file(struct file *file, int datasync); |
2438 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | 2438 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, |
2439 | int skip_pinned); | 2439 | int skip_pinned); |
2440 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); | 2440 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 79437c5eeb1e..787b50a16a14 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1101,8 +1101,9 @@ int btrfs_release_file(struct inode *inode, struct file *filp) | |||
1101 | * important optimization for directories because holding the mutex prevents | 1101 | * important optimization for directories because holding the mutex prevents |
1102 | * new operations on the dir while we write to disk. | 1102 | * new operations on the dir while we write to disk. |
1103 | */ | 1103 | */ |
1104 | int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | 1104 | int btrfs_sync_file(struct file *file, int datasync) |
1105 | { | 1105 | { |
1106 | struct dentry *dentry = file->f_path.dentry; | ||
1106 | struct inode *inode = dentry->d_inode; | 1107 | struct inode *inode = dentry->d_inode; |
1107 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1108 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1108 | int ret = 0; | 1109 | int ret = 0; |
diff --git a/fs/buffer.c b/fs/buffer.c index e8aa7081d25c..d54812b198e9 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -1949,14 +1949,11 @@ static int __block_commit_write(struct inode *inode, struct page *page, | |||
1949 | } | 1949 | } |
1950 | 1950 | ||
1951 | /* | 1951 | /* |
1952 | * block_write_begin takes care of the basic task of block allocation and | 1952 | * Filesystems implementing the new truncate sequence should use the |
1953 | * bringing partial write blocks uptodate first. | 1953 | * _newtrunc postfix variant which won't incorrectly call vmtruncate. |
1954 | * | 1954 | * The filesystem needs to handle block truncation upon failure. |
1955 | * If *pagep is not NULL, then block_write_begin uses the locked page | ||
1956 | * at *pagep rather than allocating its own. In this case, the page will | ||
1957 | * not be unlocked or deallocated on failure. | ||
1958 | */ | 1955 | */ |
1959 | int block_write_begin(struct file *file, struct address_space *mapping, | 1956 | int block_write_begin_newtrunc(struct file *file, struct address_space *mapping, |
1960 | loff_t pos, unsigned len, unsigned flags, | 1957 | loff_t pos, unsigned len, unsigned flags, |
1961 | struct page **pagep, void **fsdata, | 1958 | struct page **pagep, void **fsdata, |
1962 | get_block_t *get_block) | 1959 | get_block_t *get_block) |
@@ -1992,20 +1989,50 @@ int block_write_begin(struct file *file, struct address_space *mapping, | |||
1992 | unlock_page(page); | 1989 | unlock_page(page); |
1993 | page_cache_release(page); | 1990 | page_cache_release(page); |
1994 | *pagep = NULL; | 1991 | *pagep = NULL; |
1995 | |||
1996 | /* | ||
1997 | * prepare_write() may have instantiated a few blocks | ||
1998 | * outside i_size. Trim these off again. Don't need | ||
1999 | * i_size_read because we hold i_mutex. | ||
2000 | */ | ||
2001 | if (pos + len > inode->i_size) | ||
2002 | vmtruncate(inode, inode->i_size); | ||
2003 | } | 1992 | } |
2004 | } | 1993 | } |
2005 | 1994 | ||
2006 | out: | 1995 | out: |
2007 | return status; | 1996 | return status; |
2008 | } | 1997 | } |
1998 | EXPORT_SYMBOL(block_write_begin_newtrunc); | ||
1999 | |||
2000 | /* | ||
2001 | * block_write_begin takes care of the basic task of block allocation and | ||
2002 | * bringing partial write blocks uptodate first. | ||
2003 | * | ||
2004 | * If *pagep is not NULL, then block_write_begin uses the locked page | ||
2005 | * at *pagep rather than allocating its own. In this case, the page will | ||
2006 | * not be unlocked or deallocated on failure. | ||
2007 | */ | ||
2008 | int block_write_begin(struct file *file, struct address_space *mapping, | ||
2009 | loff_t pos, unsigned len, unsigned flags, | ||
2010 | struct page **pagep, void **fsdata, | ||
2011 | get_block_t *get_block) | ||
2012 | { | ||
2013 | int ret; | ||
2014 | |||
2015 | ret = block_write_begin_newtrunc(file, mapping, pos, len, flags, | ||
2016 | pagep, fsdata, get_block); | ||
2017 | |||
2018 | /* | ||
2019 | * prepare_write() may have instantiated a few blocks | ||
2020 | * outside i_size. Trim these off again. Don't need | ||
2021 | * i_size_read because we hold i_mutex. | ||
2022 | * | ||
2023 | * Filesystems which pass down their own page also cannot | ||
2024 | * call into vmtruncate here because it would lead to lock | ||
2025 | * inversion problems (*pagep is locked). This is a further | ||
2026 | * example of where the old truncate sequence is inadequate. | ||
2027 | */ | ||
2028 | if (unlikely(ret) && *pagep == NULL) { | ||
2029 | loff_t isize = mapping->host->i_size; | ||
2030 | if (pos + len > isize) | ||
2031 | vmtruncate(mapping->host, isize); | ||
2032 | } | ||
2033 | |||
2034 | return ret; | ||
2035 | } | ||
2009 | EXPORT_SYMBOL(block_write_begin); | 2036 | EXPORT_SYMBOL(block_write_begin); |
2010 | 2037 | ||
2011 | int block_write_end(struct file *file, struct address_space *mapping, | 2038 | int block_write_end(struct file *file, struct address_space *mapping, |
@@ -2324,7 +2351,7 @@ out: | |||
2324 | * For moronic filesystems that do not allow holes in file. | 2351 | * For moronic filesystems that do not allow holes in file. |
2325 | * We may have to extend the file. | 2352 | * We may have to extend the file. |
2326 | */ | 2353 | */ |
2327 | int cont_write_begin(struct file *file, struct address_space *mapping, | 2354 | int cont_write_begin_newtrunc(struct file *file, struct address_space *mapping, |
2328 | loff_t pos, unsigned len, unsigned flags, | 2355 | loff_t pos, unsigned len, unsigned flags, |
2329 | struct page **pagep, void **fsdata, | 2356 | struct page **pagep, void **fsdata, |
2330 | get_block_t *get_block, loff_t *bytes) | 2357 | get_block_t *get_block, loff_t *bytes) |
@@ -2345,11 +2372,30 @@ int cont_write_begin(struct file *file, struct address_space *mapping, | |||
2345 | } | 2372 | } |
2346 | 2373 | ||
2347 | *pagep = NULL; | 2374 | *pagep = NULL; |
2348 | err = block_write_begin(file, mapping, pos, len, | 2375 | err = block_write_begin_newtrunc(file, mapping, pos, len, |
2349 | flags, pagep, fsdata, get_block); | 2376 | flags, pagep, fsdata, get_block); |
2350 | out: | 2377 | out: |
2351 | return err; | 2378 | return err; |
2352 | } | 2379 | } |
2380 | EXPORT_SYMBOL(cont_write_begin_newtrunc); | ||
2381 | |||
2382 | int cont_write_begin(struct file *file, struct address_space *mapping, | ||
2383 | loff_t pos, unsigned len, unsigned flags, | ||
2384 | struct page **pagep, void **fsdata, | ||
2385 | get_block_t *get_block, loff_t *bytes) | ||
2386 | { | ||
2387 | int ret; | ||
2388 | |||
2389 | ret = cont_write_begin_newtrunc(file, mapping, pos, len, flags, | ||
2390 | pagep, fsdata, get_block, bytes); | ||
2391 | if (unlikely(ret)) { | ||
2392 | loff_t isize = mapping->host->i_size; | ||
2393 | if (pos + len > isize) | ||
2394 | vmtruncate(mapping->host, isize); | ||
2395 | } | ||
2396 | |||
2397 | return ret; | ||
2398 | } | ||
2353 | EXPORT_SYMBOL(cont_write_begin); | 2399 | EXPORT_SYMBOL(cont_write_begin); |
2354 | 2400 | ||
2355 | int block_prepare_write(struct page *page, unsigned from, unsigned to, | 2401 | int block_prepare_write(struct page *page, unsigned from, unsigned to, |
@@ -2381,7 +2427,7 @@ EXPORT_SYMBOL(block_commit_write); | |||
2381 | * | 2427 | * |
2382 | * We are not allowed to take the i_mutex here so we have to play games to | 2428 | * We are not allowed to take the i_mutex here so we have to play games to |
2383 | * protect against truncate races as the page could now be beyond EOF. Because | 2429 | * protect against truncate races as the page could now be beyond EOF. Because |
2384 | * vmtruncate() writes the inode size before removing pages, once we have the | 2430 | * truncate writes the inode size before removing pages, once we have the |
2385 | * page lock we can determine safely if the page is beyond EOF. If it is not | 2431 | * page lock we can determine safely if the page is beyond EOF. If it is not |
2386 | * beyond EOF, then the page is guaranteed safe against truncation until we | 2432 | * beyond EOF, then the page is guaranteed safe against truncation until we |
2387 | * unlock the page. | 2433 | * unlock the page. |
@@ -2464,10 +2510,11 @@ static void attach_nobh_buffers(struct page *page, struct buffer_head *head) | |||
2464 | } | 2510 | } |
2465 | 2511 | ||
2466 | /* | 2512 | /* |
2467 | * On entry, the page is fully not uptodate. | 2513 | * Filesystems implementing the new truncate sequence should use the |
2468 | * On exit the page is fully uptodate in the areas outside (from,to) | 2514 | * _newtrunc postfix variant which won't incorrectly call vmtruncate. |
2515 | * The filesystem needs to handle block truncation upon failure. | ||
2469 | */ | 2516 | */ |
2470 | int nobh_write_begin(struct file *file, struct address_space *mapping, | 2517 | int nobh_write_begin_newtrunc(struct file *file, struct address_space *mapping, |
2471 | loff_t pos, unsigned len, unsigned flags, | 2518 | loff_t pos, unsigned len, unsigned flags, |
2472 | struct page **pagep, void **fsdata, | 2519 | struct page **pagep, void **fsdata, |
2473 | get_block_t *get_block) | 2520 | get_block_t *get_block) |
@@ -2500,8 +2547,8 @@ int nobh_write_begin(struct file *file, struct address_space *mapping, | |||
2500 | unlock_page(page); | 2547 | unlock_page(page); |
2501 | page_cache_release(page); | 2548 | page_cache_release(page); |
2502 | *pagep = NULL; | 2549 | *pagep = NULL; |
2503 | return block_write_begin(file, mapping, pos, len, flags, pagep, | 2550 | return block_write_begin_newtrunc(file, mapping, pos, len, |
2504 | fsdata, get_block); | 2551 | flags, pagep, fsdata, get_block); |
2505 | } | 2552 | } |
2506 | 2553 | ||
2507 | if (PageMappedToDisk(page)) | 2554 | if (PageMappedToDisk(page)) |
@@ -2605,8 +2652,34 @@ out_release: | |||
2605 | page_cache_release(page); | 2652 | page_cache_release(page); |
2606 | *pagep = NULL; | 2653 | *pagep = NULL; |
2607 | 2654 | ||
2608 | if (pos + len > inode->i_size) | 2655 | return ret; |
2609 | vmtruncate(inode, inode->i_size); | 2656 | } |
2657 | EXPORT_SYMBOL(nobh_write_begin_newtrunc); | ||
2658 | |||
2659 | /* | ||
2660 | * On entry, the page is fully not uptodate. | ||
2661 | * On exit the page is fully uptodate in the areas outside (from,to) | ||
2662 | */ | ||
2663 | int nobh_write_begin(struct file *file, struct address_space *mapping, | ||
2664 | loff_t pos, unsigned len, unsigned flags, | ||
2665 | struct page **pagep, void **fsdata, | ||
2666 | get_block_t *get_block) | ||
2667 | { | ||
2668 | int ret; | ||
2669 | |||
2670 | ret = nobh_write_begin_newtrunc(file, mapping, pos, len, flags, | ||
2671 | pagep, fsdata, get_block); | ||
2672 | |||
2673 | /* | ||
2674 | * prepare_write() may have instantiated a few blocks | ||
2675 | * outside i_size. Trim these off again. Don't need | ||
2676 | * i_size_read because we hold i_mutex. | ||
2677 | */ | ||
2678 | if (unlikely(ret)) { | ||
2679 | loff_t isize = mapping->host->i_size; | ||
2680 | if (pos + len > isize) | ||
2681 | vmtruncate(mapping->host, isize); | ||
2682 | } | ||
2610 | 2683 | ||
2611 | return ret; | 2684 | return ret; |
2612 | } | 2685 | } |
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 0dd0b81e64f7..ae3e3a306445 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c | |||
@@ -1776,9 +1776,9 @@ out: | |||
1776 | spin_unlock(&ci->i_unsafe_lock); | 1776 | spin_unlock(&ci->i_unsafe_lock); |
1777 | } | 1777 | } |
1778 | 1778 | ||
1779 | int ceph_fsync(struct file *file, struct dentry *dentry, int datasync) | 1779 | int ceph_fsync(struct file *file, int datasync) |
1780 | { | 1780 | { |
1781 | struct inode *inode = dentry->d_inode; | 1781 | struct inode *inode = file->f_mapping->host; |
1782 | struct ceph_inode_info *ci = ceph_inode(inode); | 1782 | struct ceph_inode_info *ci = ceph_inode(inode); |
1783 | unsigned flush_tid; | 1783 | unsigned flush_tid; |
1784 | int ret; | 1784 | int ret; |
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 4fd30900eff7..0057f4a07347 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c | |||
@@ -1107,10 +1107,9 @@ static ssize_t ceph_read_dir(struct file *file, char __user *buf, size_t size, | |||
1107 | * an fsync() on a dir will wait for any uncommitted directory | 1107 | * an fsync() on a dir will wait for any uncommitted directory |
1108 | * operations to commit. | 1108 | * operations to commit. |
1109 | */ | 1109 | */ |
1110 | static int ceph_dir_fsync(struct file *file, struct dentry *dentry, | 1110 | static int ceph_dir_fsync(struct file *file, int datasync) |
1111 | int datasync) | ||
1112 | { | 1111 | { |
1113 | struct inode *inode = dentry->d_inode; | 1112 | struct inode *inode = file->f_path.dentry->d_inode; |
1114 | struct ceph_inode_info *ci = ceph_inode(inode); | 1113 | struct ceph_inode_info *ci = ceph_inode(inode); |
1115 | struct list_head *head = &ci->i_unsafe_dirops; | 1114 | struct list_head *head = &ci->i_unsafe_dirops; |
1116 | struct ceph_mds_request *req; | 1115 | struct ceph_mds_request *req; |
diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 3725c9ee9d08..dd1e7add656b 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h | |||
@@ -811,7 +811,7 @@ extern void ceph_put_cap(struct ceph_cap *cap); | |||
811 | 811 | ||
812 | extern void ceph_queue_caps_release(struct inode *inode); | 812 | extern void ceph_queue_caps_release(struct inode *inode); |
813 | extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc); | 813 | extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc); |
814 | extern int ceph_fsync(struct file *file, struct dentry *dentry, int datasync); | 814 | extern int ceph_fsync(struct file *file, int datasync); |
815 | extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc, | 815 | extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc, |
816 | struct ceph_mds_session *session); | 816 | struct ceph_mds_session *session); |
817 | extern int ceph_get_cap_mds(struct inode *inode); | 817 | extern int ceph_get_cap_mds(struct inode *inode); |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 0242ff9cbf41..a7eb65c84b1c 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -84,7 +84,7 @@ extern ssize_t cifs_user_read(struct file *file, char __user *read_data, | |||
84 | extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, | 84 | extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, |
85 | size_t write_size, loff_t *poffset); | 85 | size_t write_size, loff_t *poffset); |
86 | extern int cifs_lock(struct file *, int, struct file_lock *); | 86 | extern int cifs_lock(struct file *, int, struct file_lock *); |
87 | extern int cifs_fsync(struct file *, struct dentry *, int); | 87 | extern int cifs_fsync(struct file *, int); |
88 | extern int cifs_flush(struct file *, fl_owner_t id); | 88 | extern int cifs_flush(struct file *, fl_owner_t id); |
89 | extern int cifs_file_mmap(struct file * , struct vm_area_struct *); | 89 | extern int cifs_file_mmap(struct file * , struct vm_area_struct *); |
90 | extern const struct file_operations cifs_dir_ops; | 90 | extern const struct file_operations cifs_dir_ops; |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index a83541ec9713..f1ff785b2292 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -1676,7 +1676,7 @@ static int cifs_write_end(struct file *file, struct address_space *mapping, | |||
1676 | return rc; | 1676 | return rc; |
1677 | } | 1677 | } |
1678 | 1678 | ||
1679 | int cifs_fsync(struct file *file, struct dentry *dentry, int datasync) | 1679 | int cifs_fsync(struct file *file, int datasync) |
1680 | { | 1680 | { |
1681 | int xid; | 1681 | int xid; |
1682 | int rc = 0; | 1682 | int rc = 0; |
@@ -1688,7 +1688,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
1688 | xid = GetXid(); | 1688 | xid = GetXid(); |
1689 | 1689 | ||
1690 | cFYI(1, "Sync file - name: %s datasync: 0x%x", | 1690 | cFYI(1, "Sync file - name: %s datasync: 0x%x", |
1691 | dentry->d_name.name, datasync); | 1691 | file->f_path.dentry->d_name.name, datasync); |
1692 | 1692 | ||
1693 | rc = filemap_write_and_wait(inode->i_mapping); | 1693 | rc = filemap_write_and_wait(inode->i_mapping); |
1694 | if (rc == 0) { | 1694 | if (rc == 0) { |
diff --git a/fs/coda/coda_int.h b/fs/coda/coda_int.h index d99860a33890..6b443ff43a19 100644 --- a/fs/coda/coda_int.h +++ b/fs/coda/coda_int.h | |||
@@ -11,8 +11,7 @@ extern int coda_fake_statfs; | |||
11 | 11 | ||
12 | void coda_destroy_inodecache(void); | 12 | void coda_destroy_inodecache(void); |
13 | int coda_init_inodecache(void); | 13 | int coda_init_inodecache(void); |
14 | int coda_fsync(struct file *coda_file, struct dentry *coda_dentry, | 14 | int coda_fsync(struct file *coda_file, int datasync); |
15 | int datasync); | ||
16 | void coda_sysctl_init(void); | 15 | void coda_sysctl_init(void); |
17 | void coda_sysctl_clean(void); | 16 | void coda_sysctl_clean(void); |
18 | 17 | ||
diff --git a/fs/coda/file.c b/fs/coda/file.c index 7196077b1688..ad3cd2abeeb4 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c | |||
@@ -202,10 +202,10 @@ int coda_release(struct inode *coda_inode, struct file *coda_file) | |||
202 | return 0; | 202 | return 0; |
203 | } | 203 | } |
204 | 204 | ||
205 | int coda_fsync(struct file *coda_file, struct dentry *coda_dentry, int datasync) | 205 | int coda_fsync(struct file *coda_file, int datasync) |
206 | { | 206 | { |
207 | struct file *host_file; | 207 | struct file *host_file; |
208 | struct inode *coda_inode = coda_dentry->d_inode; | 208 | struct inode *coda_inode = coda_file->f_path.dentry->d_inode; |
209 | struct coda_file_info *cfi; | 209 | struct coda_file_info *cfi; |
210 | int err = 0; | 210 | int err = 0; |
211 | 211 | ||
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c index c8af2d91174b..41645142b88b 100644 --- a/fs/configfs/inode.c +++ b/fs/configfs/inode.c | |||
@@ -72,16 +72,11 @@ int configfs_setattr(struct dentry * dentry, struct iattr * iattr) | |||
72 | if (!sd) | 72 | if (!sd) |
73 | return -EINVAL; | 73 | return -EINVAL; |
74 | 74 | ||
75 | sd_iattr = sd->s_iattr; | 75 | error = simple_setattr(dentry, iattr); |
76 | |||
77 | error = inode_change_ok(inode, iattr); | ||
78 | if (error) | ||
79 | return error; | ||
80 | |||
81 | error = inode_setattr(inode, iattr); | ||
82 | if (error) | 76 | if (error) |
83 | return error; | 77 | return error; |
84 | 78 | ||
79 | sd_iattr = sd->s_iattr; | ||
85 | if (!sd_iattr) { | 80 | if (!sd_iattr) { |
86 | /* setting attributes for the first time, allocate now */ | 81 | /* setting attributes for the first time, allocate now */ |
87 | sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL); | 82 | sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL); |
diff --git a/fs/direct-io.c b/fs/direct-io.c index da111aacb46e..7600aacf531d 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -1134,27 +1134,8 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode, | |||
1134 | return ret; | 1134 | return ret; |
1135 | } | 1135 | } |
1136 | 1136 | ||
1137 | /* | ||
1138 | * This is a library function for use by filesystem drivers. | ||
1139 | * | ||
1140 | * The locking rules are governed by the flags parameter: | ||
1141 | * - if the flags value contains DIO_LOCKING we use a fancy locking | ||
1142 | * scheme for dumb filesystems. | ||
1143 | * For writes this function is called under i_mutex and returns with | ||
1144 | * i_mutex held, for reads, i_mutex is not held on entry, but it is | ||
1145 | * taken and dropped again before returning. | ||
1146 | * For reads and writes i_alloc_sem is taken in shared mode and released | ||
1147 | * on I/O completion (which may happen asynchronously after returning to | ||
1148 | * the caller). | ||
1149 | * | ||
1150 | * - if the flags value does NOT contain DIO_LOCKING we don't use any | ||
1151 | * internal locking but rather rely on the filesystem to synchronize | ||
1152 | * direct I/O reads/writes versus each other and truncate. | ||
1153 | * For reads and writes both i_mutex and i_alloc_sem are not held on | ||
1154 | * entry and are never taken. | ||
1155 | */ | ||
1156 | ssize_t | 1137 | ssize_t |
1157 | __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 1138 | __blockdev_direct_IO_newtrunc(int rw, struct kiocb *iocb, struct inode *inode, |
1158 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 1139 | struct block_device *bdev, const struct iovec *iov, loff_t offset, |
1159 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 1140 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, |
1160 | dio_submit_t submit_io, int flags) | 1141 | dio_submit_t submit_io, int flags) |
@@ -1247,9 +1228,46 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1247 | nr_segs, blkbits, get_block, end_io, | 1228 | nr_segs, blkbits, get_block, end_io, |
1248 | submit_io, dio); | 1229 | submit_io, dio); |
1249 | 1230 | ||
1231 | out: | ||
1232 | return retval; | ||
1233 | } | ||
1234 | EXPORT_SYMBOL(__blockdev_direct_IO_newtrunc); | ||
1235 | |||
1236 | /* | ||
1237 | * This is a library function for use by filesystem drivers. | ||
1238 | * | ||
1239 | * The locking rules are governed by the flags parameter: | ||
1240 | * - if the flags value contains DIO_LOCKING we use a fancy locking | ||
1241 | * scheme for dumb filesystems. | ||
1242 | * For writes this function is called under i_mutex and returns with | ||
1243 | * i_mutex held, for reads, i_mutex is not held on entry, but it is | ||
1244 | * taken and dropped again before returning. | ||
1245 | * For reads and writes i_alloc_sem is taken in shared mode and released | ||
1246 | * on I/O completion (which may happen asynchronously after returning to | ||
1247 | * the caller). | ||
1248 | * | ||
1249 | * - if the flags value does NOT contain DIO_LOCKING we don't use any | ||
1250 | * internal locking but rather rely on the filesystem to synchronize | ||
1251 | * direct I/O reads/writes versus each other and truncate. | ||
1252 | * For reads and writes both i_mutex and i_alloc_sem are not held on | ||
1253 | * entry and are never taken. | ||
1254 | */ | ||
1255 | ssize_t | ||
1256 | __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | ||
1257 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | ||
1258 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | ||
1259 | dio_submit_t submit_io, int flags) | ||
1260 | { | ||
1261 | ssize_t retval; | ||
1262 | |||
1263 | retval = __blockdev_direct_IO_newtrunc(rw, iocb, inode, bdev, iov, | ||
1264 | offset, nr_segs, get_block, end_io, submit_io, flags); | ||
1250 | /* | 1265 | /* |
1251 | * In case of error extending write may have instantiated a few | 1266 | * In case of error extending write may have instantiated a few |
1252 | * blocks outside i_size. Trim these off again for DIO_LOCKING. | 1267 | * blocks outside i_size. Trim these off again for DIO_LOCKING. |
1268 | * NOTE: DIO_NO_LOCK/DIO_OWN_LOCK callers have to handle this in | ||
1269 | * their own manner. This is a further example of where the old | ||
1270 | * truncate sequence is inadequate. | ||
1253 | * | 1271 | * |
1254 | * NOTE: filesystems with their own locking have to handle this | 1272 | * NOTE: filesystems with their own locking have to handle this |
1255 | * on their own. | 1273 | * on their own. |
@@ -1257,12 +1275,13 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1257 | if (flags & DIO_LOCKING) { | 1275 | if (flags & DIO_LOCKING) { |
1258 | if (unlikely((rw & WRITE) && retval < 0)) { | 1276 | if (unlikely((rw & WRITE) && retval < 0)) { |
1259 | loff_t isize = i_size_read(inode); | 1277 | loff_t isize = i_size_read(inode); |
1278 | loff_t end = offset + iov_length(iov, nr_segs); | ||
1279 | |||
1260 | if (end > isize) | 1280 | if (end > isize) |
1261 | vmtruncate(inode, isize); | 1281 | vmtruncate(inode, isize); |
1262 | } | 1282 | } |
1263 | } | 1283 | } |
1264 | 1284 | ||
1265 | out: | ||
1266 | return retval; | 1285 | return retval; |
1267 | } | 1286 | } |
1268 | EXPORT_SYMBOL(__blockdev_direct_IO); | 1287 | EXPORT_SYMBOL(__blockdev_direct_IO); |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 3bdddbcc785f..e8fcf4e2ed7d 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -274,7 +274,7 @@ static int ecryptfs_release(struct inode *inode, struct file *file) | |||
274 | } | 274 | } |
275 | 275 | ||
276 | static int | 276 | static int |
277 | ecryptfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 277 | ecryptfs_fsync(struct file *file, int datasync) |
278 | { | 278 | { |
279 | return vfs_fsync(ecryptfs_file_to_lower(file), datasync); | 279 | return vfs_fsync(ecryptfs_file_to_lower(file), datasync); |
280 | } | 280 | } |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 65dee2f336ae..31ef5252f0fe 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -805,7 +805,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia, | |||
805 | - (ia->ia_size & ~PAGE_CACHE_MASK)); | 805 | - (ia->ia_size & ~PAGE_CACHE_MASK)); |
806 | 806 | ||
807 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { | 807 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { |
808 | rc = vmtruncate(inode, ia->ia_size); | 808 | rc = simple_setsize(inode, ia->ia_size); |
809 | if (rc) | 809 | if (rc) |
810 | goto out; | 810 | goto out; |
811 | lower_ia->ia_size = ia->ia_size; | 811 | lower_ia->ia_size = ia->ia_size; |
@@ -830,7 +830,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia, | |||
830 | goto out; | 830 | goto out; |
831 | } | 831 | } |
832 | } | 832 | } |
833 | vmtruncate(inode, ia->ia_size); | 833 | simple_setsize(inode, ia->ia_size); |
834 | rc = ecryptfs_write_inode_size_to_metadata(inode); | 834 | rc = ecryptfs_write_inode_size_to_metadata(inode); |
835 | if (rc) { | 835 | if (rc) { |
836 | printk(KERN_ERR "Problem with " | 836 | printk(KERN_ERR "Problem with " |
diff --git a/fs/exofs/file.c b/fs/exofs/file.c index 839b9dc1e70f..fef6899be397 100644 --- a/fs/exofs/file.c +++ b/fs/exofs/file.c | |||
@@ -40,12 +40,11 @@ static int exofs_release_file(struct inode *inode, struct file *filp) | |||
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
42 | 42 | ||
43 | static int exofs_file_fsync(struct file *filp, struct dentry *dentry, | 43 | static int exofs_file_fsync(struct file *filp, int datasync) |
44 | int datasync) | ||
45 | { | 44 | { |
46 | int ret; | 45 | int ret; |
47 | struct address_space *mapping = filp->f_mapping; | 46 | struct address_space *mapping = filp->f_mapping; |
48 | struct inode *inode = dentry->d_inode; | 47 | struct inode *inode = mapping->host; |
49 | struct super_block *sb; | 48 | struct super_block *sb; |
50 | 49 | ||
51 | ret = filemap_write_and_wait(mapping); | 50 | ret = filemap_write_and_wait(mapping); |
@@ -66,7 +65,7 @@ static int exofs_file_fsync(struct file *filp, struct dentry *dentry, | |||
66 | 65 | ||
67 | static int exofs_flush(struct file *file, fl_owner_t id) | 66 | static int exofs_flush(struct file *file, fl_owner_t id) |
68 | { | 67 | { |
69 | exofs_file_fsync(file, file->f_path.dentry, 1); | 68 | exofs_file_fsync(file, 1); |
70 | /* TODO: Flush the OSD target */ | 69 | /* TODO: Flush the OSD target */ |
71 | return 0; | 70 | return 0; |
72 | } | 71 | } |
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 0b038e47ad2f..52b34f1d2738 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h | |||
@@ -122,7 +122,6 @@ extern int ext2_write_inode (struct inode *, struct writeback_control *); | |||
122 | extern void ext2_delete_inode (struct inode *); | 122 | extern void ext2_delete_inode (struct inode *); |
123 | extern int ext2_sync_inode (struct inode *); | 123 | extern int ext2_sync_inode (struct inode *); |
124 | extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); | 124 | extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); |
125 | extern void ext2_truncate (struct inode *); | ||
126 | extern int ext2_setattr (struct dentry *, struct iattr *); | 125 | extern int ext2_setattr (struct dentry *, struct iattr *); |
127 | extern void ext2_set_inode_flags(struct inode *inode); | 126 | extern void ext2_set_inode_flags(struct inode *inode); |
128 | extern void ext2_get_inode_flags(struct ext2_inode_info *); | 127 | extern void ext2_get_inode_flags(struct ext2_inode_info *); |
@@ -155,7 +154,7 @@ extern void ext2_write_super (struct super_block *); | |||
155 | extern const struct file_operations ext2_dir_operations; | 154 | extern const struct file_operations ext2_dir_operations; |
156 | 155 | ||
157 | /* file.c */ | 156 | /* file.c */ |
158 | extern int ext2_fsync(struct file *file, struct dentry *dentry, int datasync); | 157 | extern int ext2_fsync(struct file *file, int datasync); |
159 | extern const struct inode_operations ext2_file_inode_operations; | 158 | extern const struct inode_operations ext2_file_inode_operations; |
160 | extern const struct file_operations ext2_file_operations; | 159 | extern const struct file_operations ext2_file_operations; |
161 | extern const struct file_operations ext2_xip_file_operations; | 160 | extern const struct file_operations ext2_xip_file_operations; |
diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 5d198d0697fb..49eec9456c5b 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c | |||
@@ -40,13 +40,13 @@ static int ext2_release_file (struct inode * inode, struct file * filp) | |||
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
42 | 42 | ||
43 | int ext2_fsync(struct file *file, struct dentry *dentry, int datasync) | 43 | int ext2_fsync(struct file *file, int datasync) |
44 | { | 44 | { |
45 | int ret; | 45 | int ret; |
46 | struct super_block *sb = dentry->d_inode->i_sb; | 46 | struct super_block *sb = file->f_mapping->host->i_sb; |
47 | struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; | 47 | struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; |
48 | 48 | ||
49 | ret = simple_fsync(file, dentry, datasync); | 49 | ret = generic_file_fsync(file, datasync); |
50 | if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) { | 50 | if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) { |
51 | /* We don't really know where the IO error happened... */ | 51 | /* We don't really know where the IO error happened... */ |
52 | ext2_error(sb, __func__, | 52 | ext2_error(sb, __func__, |
@@ -95,7 +95,6 @@ const struct file_operations ext2_xip_file_operations = { | |||
95 | #endif | 95 | #endif |
96 | 96 | ||
97 | const struct inode_operations ext2_file_inode_operations = { | 97 | const struct inode_operations ext2_file_inode_operations = { |
98 | .truncate = ext2_truncate, | ||
99 | #ifdef CONFIG_EXT2_FS_XATTR | 98 | #ifdef CONFIG_EXT2_FS_XATTR |
100 | .setxattr = generic_setxattr, | 99 | .setxattr = generic_setxattr, |
101 | .getxattr = generic_getxattr, | 100 | .getxattr = generic_getxattr, |
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 527c46d9bc1f..19214435b752 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c | |||
@@ -54,6 +54,18 @@ static inline int ext2_inode_is_fast_symlink(struct inode *inode) | |||
54 | inode->i_blocks - ea_blocks == 0); | 54 | inode->i_blocks - ea_blocks == 0); |
55 | } | 55 | } |
56 | 56 | ||
57 | static void ext2_truncate_blocks(struct inode *inode, loff_t offset); | ||
58 | |||
59 | static void ext2_write_failed(struct address_space *mapping, loff_t to) | ||
60 | { | ||
61 | struct inode *inode = mapping->host; | ||
62 | |||
63 | if (to > inode->i_size) { | ||
64 | truncate_pagecache(inode, to, inode->i_size); | ||
65 | ext2_truncate_blocks(inode, inode->i_size); | ||
66 | } | ||
67 | } | ||
68 | |||
57 | /* | 69 | /* |
58 | * Called at the last iput() if i_nlink is zero. | 70 | * Called at the last iput() if i_nlink is zero. |
59 | */ | 71 | */ |
@@ -71,7 +83,7 @@ void ext2_delete_inode (struct inode * inode) | |||
71 | 83 | ||
72 | inode->i_size = 0; | 84 | inode->i_size = 0; |
73 | if (inode->i_blocks) | 85 | if (inode->i_blocks) |
74 | ext2_truncate (inode); | 86 | ext2_truncate_blocks(inode, 0); |
75 | ext2_free_inode (inode); | 87 | ext2_free_inode (inode); |
76 | 88 | ||
77 | return; | 89 | return; |
@@ -757,8 +769,8 @@ int __ext2_write_begin(struct file *file, struct address_space *mapping, | |||
757 | loff_t pos, unsigned len, unsigned flags, | 769 | loff_t pos, unsigned len, unsigned flags, |
758 | struct page **pagep, void **fsdata) | 770 | struct page **pagep, void **fsdata) |
759 | { | 771 | { |
760 | return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 772 | return block_write_begin_newtrunc(file, mapping, pos, len, flags, |
761 | ext2_get_block); | 773 | pagep, fsdata, ext2_get_block); |
762 | } | 774 | } |
763 | 775 | ||
764 | static int | 776 | static int |
@@ -766,8 +778,25 @@ ext2_write_begin(struct file *file, struct address_space *mapping, | |||
766 | loff_t pos, unsigned len, unsigned flags, | 778 | loff_t pos, unsigned len, unsigned flags, |
767 | struct page **pagep, void **fsdata) | 779 | struct page **pagep, void **fsdata) |
768 | { | 780 | { |
781 | int ret; | ||
782 | |||
769 | *pagep = NULL; | 783 | *pagep = NULL; |
770 | return __ext2_write_begin(file, mapping, pos, len, flags, pagep,fsdata); | 784 | ret = __ext2_write_begin(file, mapping, pos, len, flags, pagep, fsdata); |
785 | if (ret < 0) | ||
786 | ext2_write_failed(mapping, pos + len); | ||
787 | return ret; | ||
788 | } | ||
789 | |||
790 | static int ext2_write_end(struct file *file, struct address_space *mapping, | ||
791 | loff_t pos, unsigned len, unsigned copied, | ||
792 | struct page *page, void *fsdata) | ||
793 | { | ||
794 | int ret; | ||
795 | |||
796 | ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); | ||
797 | if (ret < len) | ||
798 | ext2_write_failed(mapping, pos + len); | ||
799 | return ret; | ||
771 | } | 800 | } |
772 | 801 | ||
773 | static int | 802 | static int |
@@ -775,13 +804,18 @@ ext2_nobh_write_begin(struct file *file, struct address_space *mapping, | |||
775 | loff_t pos, unsigned len, unsigned flags, | 804 | loff_t pos, unsigned len, unsigned flags, |
776 | struct page **pagep, void **fsdata) | 805 | struct page **pagep, void **fsdata) |
777 | { | 806 | { |
807 | int ret; | ||
808 | |||
778 | /* | 809 | /* |
779 | * Dir-in-pagecache still uses ext2_write_begin. Would have to rework | 810 | * Dir-in-pagecache still uses ext2_write_begin. Would have to rework |
780 | * directory handling code to pass around offsets rather than struct | 811 | * directory handling code to pass around offsets rather than struct |
781 | * pages in order to make this work easily. | 812 | * pages in order to make this work easily. |
782 | */ | 813 | */ |
783 | return nobh_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 814 | ret = nobh_write_begin_newtrunc(file, mapping, pos, len, flags, pagep, |
784 | ext2_get_block); | 815 | fsdata, ext2_get_block); |
816 | if (ret < 0) | ||
817 | ext2_write_failed(mapping, pos + len); | ||
818 | return ret; | ||
785 | } | 819 | } |
786 | 820 | ||
787 | static int ext2_nobh_writepage(struct page *page, | 821 | static int ext2_nobh_writepage(struct page *page, |
@@ -800,10 +834,15 @@ ext2_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
800 | loff_t offset, unsigned long nr_segs) | 834 | loff_t offset, unsigned long nr_segs) |
801 | { | 835 | { |
802 | struct file *file = iocb->ki_filp; | 836 | struct file *file = iocb->ki_filp; |
803 | struct inode *inode = file->f_mapping->host; | 837 | struct address_space *mapping = file->f_mapping; |
804 | 838 | struct inode *inode = mapping->host; | |
805 | return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 839 | ssize_t ret; |
806 | offset, nr_segs, ext2_get_block, NULL); | 840 | |
841 | ret = blockdev_direct_IO_newtrunc(rw, iocb, inode, inode->i_sb->s_bdev, | ||
842 | iov, offset, nr_segs, ext2_get_block, NULL); | ||
843 | if (ret < 0 && (rw & WRITE)) | ||
844 | ext2_write_failed(mapping, offset + iov_length(iov, nr_segs)); | ||
845 | return ret; | ||
807 | } | 846 | } |
808 | 847 | ||
809 | static int | 848 | static int |
@@ -818,7 +857,7 @@ const struct address_space_operations ext2_aops = { | |||
818 | .writepage = ext2_writepage, | 857 | .writepage = ext2_writepage, |
819 | .sync_page = block_sync_page, | 858 | .sync_page = block_sync_page, |
820 | .write_begin = ext2_write_begin, | 859 | .write_begin = ext2_write_begin, |
821 | .write_end = generic_write_end, | 860 | .write_end = ext2_write_end, |
822 | .bmap = ext2_bmap, | 861 | .bmap = ext2_bmap, |
823 | .direct_IO = ext2_direct_IO, | 862 | .direct_IO = ext2_direct_IO, |
824 | .writepages = ext2_writepages, | 863 | .writepages = ext2_writepages, |
@@ -1027,7 +1066,7 @@ static void ext2_free_branches(struct inode *inode, __le32 *p, __le32 *q, int de | |||
1027 | ext2_free_data(inode, p, q); | 1066 | ext2_free_data(inode, p, q); |
1028 | } | 1067 | } |
1029 | 1068 | ||
1030 | void ext2_truncate(struct inode *inode) | 1069 | static void __ext2_truncate_blocks(struct inode *inode, loff_t offset) |
1031 | { | 1070 | { |
1032 | __le32 *i_data = EXT2_I(inode)->i_data; | 1071 | __le32 *i_data = EXT2_I(inode)->i_data; |
1033 | struct ext2_inode_info *ei = EXT2_I(inode); | 1072 | struct ext2_inode_info *ei = EXT2_I(inode); |
@@ -1039,27 +1078,8 @@ void ext2_truncate(struct inode *inode) | |||
1039 | int n; | 1078 | int n; |
1040 | long iblock; | 1079 | long iblock; |
1041 | unsigned blocksize; | 1080 | unsigned blocksize; |
1042 | |||
1043 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | ||
1044 | S_ISLNK(inode->i_mode))) | ||
1045 | return; | ||
1046 | if (ext2_inode_is_fast_symlink(inode)) | ||
1047 | return; | ||
1048 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | ||
1049 | return; | ||
1050 | |||
1051 | blocksize = inode->i_sb->s_blocksize; | 1081 | blocksize = inode->i_sb->s_blocksize; |
1052 | iblock = (inode->i_size + blocksize-1) | 1082 | iblock = (offset + blocksize-1) >> EXT2_BLOCK_SIZE_BITS(inode->i_sb); |
1053 | >> EXT2_BLOCK_SIZE_BITS(inode->i_sb); | ||
1054 | |||
1055 | if (mapping_is_xip(inode->i_mapping)) | ||
1056 | xip_truncate_page(inode->i_mapping, inode->i_size); | ||
1057 | else if (test_opt(inode->i_sb, NOBH)) | ||
1058 | nobh_truncate_page(inode->i_mapping, | ||
1059 | inode->i_size, ext2_get_block); | ||
1060 | else | ||
1061 | block_truncate_page(inode->i_mapping, | ||
1062 | inode->i_size, ext2_get_block); | ||
1063 | 1083 | ||
1064 | n = ext2_block_to_path(inode, iblock, offsets, NULL); | 1084 | n = ext2_block_to_path(inode, iblock, offsets, NULL); |
1065 | if (n == 0) | 1085 | if (n == 0) |
@@ -1127,6 +1147,62 @@ do_indirects: | |||
1127 | ext2_discard_reservation(inode); | 1147 | ext2_discard_reservation(inode); |
1128 | 1148 | ||
1129 | mutex_unlock(&ei->truncate_mutex); | 1149 | mutex_unlock(&ei->truncate_mutex); |
1150 | } | ||
1151 | |||
1152 | static void ext2_truncate_blocks(struct inode *inode, loff_t offset) | ||
1153 | { | ||
1154 | /* | ||
1155 | * XXX: it seems like a bug here that we don't allow | ||
1156 | * IS_APPEND inode to have blocks-past-i_size trimmed off. | ||
1157 | * review and fix this. | ||
1158 | * | ||
1159 | * Also would be nice to be able to handle IO errors and such, | ||
1160 | * but that's probably too much to ask. | ||
1161 | */ | ||
1162 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | ||
1163 | S_ISLNK(inode->i_mode))) | ||
1164 | return; | ||
1165 | if (ext2_inode_is_fast_symlink(inode)) | ||
1166 | return; | ||
1167 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | ||
1168 | return; | ||
1169 | __ext2_truncate_blocks(inode, offset); | ||
1170 | } | ||
1171 | |||
1172 | int ext2_setsize(struct inode *inode, loff_t newsize) | ||
1173 | { | ||
1174 | loff_t oldsize; | ||
1175 | int error; | ||
1176 | |||
1177 | error = inode_newsize_ok(inode, newsize); | ||
1178 | if (error) | ||
1179 | return error; | ||
1180 | |||
1181 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | ||
1182 | S_ISLNK(inode->i_mode))) | ||
1183 | return -EINVAL; | ||
1184 | if (ext2_inode_is_fast_symlink(inode)) | ||
1185 | return -EINVAL; | ||
1186 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | ||
1187 | return -EPERM; | ||
1188 | |||
1189 | if (mapping_is_xip(inode->i_mapping)) | ||
1190 | error = xip_truncate_page(inode->i_mapping, newsize); | ||
1191 | else if (test_opt(inode->i_sb, NOBH)) | ||
1192 | error = nobh_truncate_page(inode->i_mapping, | ||
1193 | newsize, ext2_get_block); | ||
1194 | else | ||
1195 | error = block_truncate_page(inode->i_mapping, | ||
1196 | newsize, ext2_get_block); | ||
1197 | if (error) | ||
1198 | return error; | ||
1199 | |||
1200 | oldsize = inode->i_size; | ||
1201 | i_size_write(inode, newsize); | ||
1202 | truncate_pagecache(inode, oldsize, newsize); | ||
1203 | |||
1204 | __ext2_truncate_blocks(inode, newsize); | ||
1205 | |||
1130 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; | 1206 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; |
1131 | if (inode_needs_sync(inode)) { | 1207 | if (inode_needs_sync(inode)) { |
1132 | sync_mapping_buffers(inode->i_mapping); | 1208 | sync_mapping_buffers(inode->i_mapping); |
@@ -1134,6 +1210,8 @@ do_indirects: | |||
1134 | } else { | 1210 | } else { |
1135 | mark_inode_dirty(inode); | 1211 | mark_inode_dirty(inode); |
1136 | } | 1212 | } |
1213 | |||
1214 | return 0; | ||
1137 | } | 1215 | } |
1138 | 1216 | ||
1139 | static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, | 1217 | static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, |
@@ -1474,8 +1552,15 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr) | |||
1474 | if (error) | 1552 | if (error) |
1475 | return error; | 1553 | return error; |
1476 | } | 1554 | } |
1477 | error = inode_setattr(inode, iattr); | 1555 | if (iattr->ia_valid & ATTR_SIZE) { |
1478 | if (!error && (iattr->ia_valid & ATTR_MODE)) | 1556 | error = ext2_setsize(inode, iattr->ia_size); |
1557 | if (error) | ||
1558 | return error; | ||
1559 | } | ||
1560 | generic_setattr(inode, iattr); | ||
1561 | if (iattr->ia_valid & ATTR_MODE) | ||
1479 | error = ext2_acl_chmod(inode); | 1562 | error = ext2_acl_chmod(inode); |
1563 | mark_inode_dirty(inode); | ||
1564 | |||
1480 | return error; | 1565 | return error; |
1481 | } | 1566 | } |
diff --git a/fs/ext3/fsync.c b/fs/ext3/fsync.c index fcf7487734b6..d7e9f74dc3a6 100644 --- a/fs/ext3/fsync.c +++ b/fs/ext3/fsync.c | |||
@@ -43,9 +43,9 @@ | |||
43 | * inode to disk. | 43 | * inode to disk. |
44 | */ | 44 | */ |
45 | 45 | ||
46 | int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) | 46 | int ext3_sync_file(struct file *file, int datasync) |
47 | { | 47 | { |
48 | struct inode *inode = dentry->d_inode; | 48 | struct inode *inode = file->f_mapping->host; |
49 | struct ext3_inode_info *ei = EXT3_I(inode); | 49 | struct ext3_inode_info *ei = EXT3_I(inode); |
50 | journal_t *journal = EXT3_SB(inode->i_sb)->s_journal; | 50 | journal_t *journal = EXT3_SB(inode->i_sb)->s_journal; |
51 | int ret, needs_barrier = 0; | 51 | int ret, needs_barrier = 0; |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 60bd31026e7c..19a4de57128a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -1519,7 +1519,7 @@ extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, | |||
1519 | extern void ext4_htree_free_dir_info(struct dir_private_info *p); | 1519 | extern void ext4_htree_free_dir_info(struct dir_private_info *p); |
1520 | 1520 | ||
1521 | /* fsync.c */ | 1521 | /* fsync.c */ |
1522 | extern int ext4_sync_file(struct file *, struct dentry *, int); | 1522 | extern int ext4_sync_file(struct file *, int); |
1523 | 1523 | ||
1524 | /* hash.c */ | 1524 | /* hash.c */ |
1525 | extern int ext4fs_dirhash(const char *name, int len, struct | 1525 | extern int ext4fs_dirhash(const char *name, int len, struct |
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index b6a74f991bf4..592adf2e546e 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c | |||
@@ -71,9 +71,9 @@ static void ext4_sync_parent(struct inode *inode) | |||
71 | * i_mutex lock is held when entering and exiting this function | 71 | * i_mutex lock is held when entering and exiting this function |
72 | */ | 72 | */ |
73 | 73 | ||
74 | int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) | 74 | int ext4_sync_file(struct file *file, int datasync) |
75 | { | 75 | { |
76 | struct inode *inode = dentry->d_inode; | 76 | struct inode *inode = file->f_mapping->host; |
77 | struct ext4_inode_info *ei = EXT4_I(inode); | 77 | struct ext4_inode_info *ei = EXT4_I(inode); |
78 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; | 78 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; |
79 | int ret; | 79 | int ret; |
@@ -81,7 +81,7 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
81 | 81 | ||
82 | J_ASSERT(ext4_journal_current_handle() == NULL); | 82 | J_ASSERT(ext4_journal_current_handle() == NULL); |
83 | 83 | ||
84 | trace_ext4_sync_file(file, dentry, datasync); | 84 | trace_ext4_sync_file(file, datasync); |
85 | 85 | ||
86 | if (inode->i_sb->s_flags & MS_RDONLY) | 86 | if (inode->i_sb->s_flags & MS_RDONLY) |
87 | return 0; | 87 | return 0; |
@@ -91,7 +91,7 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
91 | return ret; | 91 | return ret; |
92 | 92 | ||
93 | if (!journal) { | 93 | if (!journal) { |
94 | ret = simple_fsync(file, dentry, datasync); | 94 | ret = generic_file_fsync(file, datasync); |
95 | if (!ret && !list_empty(&inode->i_dentry)) | 95 | if (!ret && !list_empty(&inode->i_dentry)) |
96 | ext4_sync_parent(inode); | 96 | ext4_sync_parent(inode); |
97 | return ret; | 97 | return ret; |
diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 53dba57b49a1..27ac25725954 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h | |||
@@ -306,11 +306,11 @@ extern long fat_generic_ioctl(struct file *filp, unsigned int cmd, | |||
306 | extern const struct file_operations fat_file_operations; | 306 | extern const struct file_operations fat_file_operations; |
307 | extern const struct inode_operations fat_file_inode_operations; | 307 | extern const struct inode_operations fat_file_inode_operations; |
308 | extern int fat_setattr(struct dentry * dentry, struct iattr * attr); | 308 | extern int fat_setattr(struct dentry * dentry, struct iattr * attr); |
309 | extern void fat_truncate(struct inode *inode); | 309 | extern int fat_setsize(struct inode *inode, loff_t offset); |
310 | extern void fat_truncate_blocks(struct inode *inode, loff_t offset); | ||
310 | extern int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, | 311 | extern int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, |
311 | struct kstat *stat); | 312 | struct kstat *stat); |
312 | extern int fat_file_fsync(struct file *file, struct dentry *dentry, | 313 | extern int fat_file_fsync(struct file *file, int datasync); |
313 | int datasync); | ||
314 | 314 | ||
315 | /* fat/inode.c */ | 315 | /* fat/inode.c */ |
316 | extern void fat_attach(struct inode *inode, loff_t i_pos); | 316 | extern void fat_attach(struct inode *inode, loff_t i_pos); |
diff --git a/fs/fat/file.c b/fs/fat/file.c index a14c2f6a489e..990dfae022e5 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c | |||
@@ -149,12 +149,12 @@ static int fat_file_release(struct inode *inode, struct file *filp) | |||
149 | return 0; | 149 | return 0; |
150 | } | 150 | } |
151 | 151 | ||
152 | int fat_file_fsync(struct file *filp, struct dentry *dentry, int datasync) | 152 | int fat_file_fsync(struct file *filp, int datasync) |
153 | { | 153 | { |
154 | struct inode *inode = dentry->d_inode; | 154 | struct inode *inode = filp->f_mapping->host; |
155 | int res, err; | 155 | int res, err; |
156 | 156 | ||
157 | res = simple_fsync(filp, dentry, datasync); | 157 | res = generic_file_fsync(filp, datasync); |
158 | err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping); | 158 | err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping); |
159 | 159 | ||
160 | return res ? res : err; | 160 | return res ? res : err; |
@@ -283,7 +283,7 @@ static int fat_free(struct inode *inode, int skip) | |||
283 | return fat_free_clusters(inode, free_start); | 283 | return fat_free_clusters(inode, free_start); |
284 | } | 284 | } |
285 | 285 | ||
286 | void fat_truncate(struct inode *inode) | 286 | void fat_truncate_blocks(struct inode *inode, loff_t offset) |
287 | { | 287 | { |
288 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); | 288 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); |
289 | const unsigned int cluster_size = sbi->cluster_size; | 289 | const unsigned int cluster_size = sbi->cluster_size; |
@@ -293,10 +293,10 @@ void fat_truncate(struct inode *inode) | |||
293 | * This protects against truncating a file bigger than it was then | 293 | * This protects against truncating a file bigger than it was then |
294 | * trying to write into the hole. | 294 | * trying to write into the hole. |
295 | */ | 295 | */ |
296 | if (MSDOS_I(inode)->mmu_private > inode->i_size) | 296 | if (MSDOS_I(inode)->mmu_private > offset) |
297 | MSDOS_I(inode)->mmu_private = inode->i_size; | 297 | MSDOS_I(inode)->mmu_private = offset; |
298 | 298 | ||
299 | nr_clusters = (inode->i_size + (cluster_size - 1)) >> sbi->cluster_bits; | 299 | nr_clusters = (offset + (cluster_size - 1)) >> sbi->cluster_bits; |
300 | 300 | ||
301 | fat_free(inode, nr_clusters); | 301 | fat_free(inode, nr_clusters); |
302 | fat_flush_inodes(inode->i_sb, inode, NULL); | 302 | fat_flush_inodes(inode->i_sb, inode, NULL); |
@@ -364,6 +364,18 @@ static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode) | |||
364 | return 0; | 364 | return 0; |
365 | } | 365 | } |
366 | 366 | ||
367 | int fat_setsize(struct inode *inode, loff_t offset) | ||
368 | { | ||
369 | int error; | ||
370 | |||
371 | error = simple_setsize(inode, offset); | ||
372 | if (error) | ||
373 | return error; | ||
374 | fat_truncate_blocks(inode, offset); | ||
375 | |||
376 | return error; | ||
377 | } | ||
378 | |||
367 | #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET) | 379 | #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET) |
368 | /* valid file mode bits */ | 380 | /* valid file mode bits */ |
369 | #define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO) | 381 | #define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO) |
@@ -378,7 +390,8 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr) | |||
378 | /* | 390 | /* |
379 | * Expand the file. Since inode_setattr() updates ->i_size | 391 | * Expand the file. Since inode_setattr() updates ->i_size |
380 | * before calling the ->truncate(), but FAT needs to fill the | 392 | * before calling the ->truncate(), but FAT needs to fill the |
381 | * hole before it. | 393 | * hole before it. XXX: this is no longer true with new truncate |
394 | * sequence. | ||
382 | */ | 395 | */ |
383 | if (attr->ia_valid & ATTR_SIZE) { | 396 | if (attr->ia_valid & ATTR_SIZE) { |
384 | if (attr->ia_size > inode->i_size) { | 397 | if (attr->ia_size > inode->i_size) { |
@@ -427,15 +440,20 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr) | |||
427 | attr->ia_valid &= ~ATTR_MODE; | 440 | attr->ia_valid &= ~ATTR_MODE; |
428 | } | 441 | } |
429 | 442 | ||
430 | if (attr->ia_valid) | 443 | if (attr->ia_valid & ATTR_SIZE) { |
431 | error = inode_setattr(inode, attr); | 444 | error = fat_setsize(inode, attr->ia_size); |
445 | if (error) | ||
446 | goto out; | ||
447 | } | ||
448 | |||
449 | generic_setattr(inode, attr); | ||
450 | mark_inode_dirty(inode); | ||
432 | out: | 451 | out: |
433 | return error; | 452 | return error; |
434 | } | 453 | } |
435 | EXPORT_SYMBOL_GPL(fat_setattr); | 454 | EXPORT_SYMBOL_GPL(fat_setattr); |
436 | 455 | ||
437 | const struct inode_operations fat_file_inode_operations = { | 456 | const struct inode_operations fat_file_inode_operations = { |
438 | .truncate = fat_truncate, | ||
439 | .setattr = fat_setattr, | 457 | .setattr = fat_setattr, |
440 | .getattr = fat_getattr, | 458 | .getattr = fat_getattr, |
441 | }; | 459 | }; |
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index ed33904926ee..7bf45aee56d7 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c | |||
@@ -142,14 +142,29 @@ static int fat_readpages(struct file *file, struct address_space *mapping, | |||
142 | return mpage_readpages(mapping, pages, nr_pages, fat_get_block); | 142 | return mpage_readpages(mapping, pages, nr_pages, fat_get_block); |
143 | } | 143 | } |
144 | 144 | ||
145 | static void fat_write_failed(struct address_space *mapping, loff_t to) | ||
146 | { | ||
147 | struct inode *inode = mapping->host; | ||
148 | |||
149 | if (to > inode->i_size) { | ||
150 | truncate_pagecache(inode, to, inode->i_size); | ||
151 | fat_truncate_blocks(inode, inode->i_size); | ||
152 | } | ||
153 | } | ||
154 | |||
145 | static int fat_write_begin(struct file *file, struct address_space *mapping, | 155 | static int fat_write_begin(struct file *file, struct address_space *mapping, |
146 | loff_t pos, unsigned len, unsigned flags, | 156 | loff_t pos, unsigned len, unsigned flags, |
147 | struct page **pagep, void **fsdata) | 157 | struct page **pagep, void **fsdata) |
148 | { | 158 | { |
159 | int err; | ||
160 | |||
149 | *pagep = NULL; | 161 | *pagep = NULL; |
150 | return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 162 | err = cont_write_begin_newtrunc(file, mapping, pos, len, flags, |
151 | fat_get_block, | 163 | pagep, fsdata, fat_get_block, |
152 | &MSDOS_I(mapping->host)->mmu_private); | 164 | &MSDOS_I(mapping->host)->mmu_private); |
165 | if (err < 0) | ||
166 | fat_write_failed(mapping, pos + len); | ||
167 | return err; | ||
153 | } | 168 | } |
154 | 169 | ||
155 | static int fat_write_end(struct file *file, struct address_space *mapping, | 170 | static int fat_write_end(struct file *file, struct address_space *mapping, |
@@ -159,6 +174,8 @@ static int fat_write_end(struct file *file, struct address_space *mapping, | |||
159 | struct inode *inode = mapping->host; | 174 | struct inode *inode = mapping->host; |
160 | int err; | 175 | int err; |
161 | err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata); | 176 | err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata); |
177 | if (err < len) | ||
178 | fat_write_failed(mapping, pos + len); | ||
162 | if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) { | 179 | if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) { |
163 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; | 180 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; |
164 | MSDOS_I(inode)->i_attrs |= ATTR_ARCH; | 181 | MSDOS_I(inode)->i_attrs |= ATTR_ARCH; |
@@ -172,7 +189,9 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | |||
172 | loff_t offset, unsigned long nr_segs) | 189 | loff_t offset, unsigned long nr_segs) |
173 | { | 190 | { |
174 | struct file *file = iocb->ki_filp; | 191 | struct file *file = iocb->ki_filp; |
175 | struct inode *inode = file->f_mapping->host; | 192 | struct address_space *mapping = file->f_mapping; |
193 | struct inode *inode = mapping->host; | ||
194 | ssize_t ret; | ||
176 | 195 | ||
177 | if (rw == WRITE) { | 196 | if (rw == WRITE) { |
178 | /* | 197 | /* |
@@ -193,8 +212,12 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | |||
193 | * FAT need to use the DIO_LOCKING for avoiding the race | 212 | * FAT need to use the DIO_LOCKING for avoiding the race |
194 | * condition of fat_get_block() and ->truncate(). | 213 | * condition of fat_get_block() and ->truncate(). |
195 | */ | 214 | */ |
196 | return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 215 | ret = blockdev_direct_IO_newtrunc(rw, iocb, inode, inode->i_sb->s_bdev, |
197 | offset, nr_segs, fat_get_block, NULL); | 216 | iov, offset, nr_segs, fat_get_block, NULL); |
217 | if (ret < 0 && (rw & WRITE)) | ||
218 | fat_write_failed(mapping, offset + iov_length(iov, nr_segs)); | ||
219 | |||
220 | return ret; | ||
198 | } | 221 | } |
199 | 222 | ||
200 | static sector_t _fat_bmap(struct address_space *mapping, sector_t block) | 223 | static sector_t _fat_bmap(struct address_space *mapping, sector_t block) |
@@ -429,7 +452,7 @@ static void fat_delete_inode(struct inode *inode) | |||
429 | { | 452 | { |
430 | truncate_inode_pages(&inode->i_data, 0); | 453 | truncate_inode_pages(&inode->i_data, 0); |
431 | inode->i_size = 0; | 454 | inode->i_size = 0; |
432 | fat_truncate(inode); | 455 | fat_truncate_blocks(inode, 0); |
433 | clear_inode(inode); | 456 | clear_inode(inode); |
434 | } | 457 | } |
435 | 458 | ||
diff --git a/fs/file_table.c b/fs/file_table.c index 32d12b78bac8..5c7d10ead4ad 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -194,14 +194,6 @@ struct file *alloc_file(struct path *path, fmode_t mode, | |||
194 | } | 194 | } |
195 | EXPORT_SYMBOL(alloc_file); | 195 | EXPORT_SYMBOL(alloc_file); |
196 | 196 | ||
197 | void fput(struct file *file) | ||
198 | { | ||
199 | if (atomic_long_dec_and_test(&file->f_count)) | ||
200 | __fput(file); | ||
201 | } | ||
202 | |||
203 | EXPORT_SYMBOL(fput); | ||
204 | |||
205 | /** | 197 | /** |
206 | * drop_file_write_access - give up ability to write to a file | 198 | * drop_file_write_access - give up ability to write to a file |
207 | * @file: the file to which we will stop writing | 199 | * @file: the file to which we will stop writing |
@@ -227,10 +219,9 @@ void drop_file_write_access(struct file *file) | |||
227 | } | 219 | } |
228 | EXPORT_SYMBOL_GPL(drop_file_write_access); | 220 | EXPORT_SYMBOL_GPL(drop_file_write_access); |
229 | 221 | ||
230 | /* __fput is called from task context when aio completion releases the last | 222 | /* the real guts of fput() - releasing the last reference to file |
231 | * last use of a struct file *. Do not use otherwise. | ||
232 | */ | 223 | */ |
233 | void __fput(struct file *file) | 224 | static void __fput(struct file *file) |
234 | { | 225 | { |
235 | struct dentry *dentry = file->f_path.dentry; | 226 | struct dentry *dentry = file->f_path.dentry; |
236 | struct vfsmount *mnt = file->f_path.mnt; | 227 | struct vfsmount *mnt = file->f_path.mnt; |
@@ -268,6 +259,14 @@ void __fput(struct file *file) | |||
268 | mntput(mnt); | 259 | mntput(mnt); |
269 | } | 260 | } |
270 | 261 | ||
262 | void fput(struct file *file) | ||
263 | { | ||
264 | if (atomic_long_dec_and_test(&file->f_count)) | ||
265 | __fput(file); | ||
266 | } | ||
267 | |||
268 | EXPORT_SYMBOL(fput); | ||
269 | |||
271 | struct file *fget(unsigned int fd) | 270 | struct file *fget(unsigned int fd) |
272 | { | 271 | { |
273 | struct file *file; | 272 | struct file *file; |
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 4787ae6c5c1c..3cdc5f78a406 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -1156,10 +1156,9 @@ static int fuse_dir_release(struct inode *inode, struct file *file) | |||
1156 | return 0; | 1156 | return 0; |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync) | 1159 | static int fuse_dir_fsync(struct file *file, int datasync) |
1160 | { | 1160 | { |
1161 | /* nfsd can call this with no file */ | 1161 | return fuse_fsync_common(file, datasync, 1); |
1162 | return file ? fuse_fsync_common(file, de, datasync, 1) : 0; | ||
1163 | } | 1162 | } |
1164 | 1163 | ||
1165 | static bool update_mtime(unsigned ivalid) | 1164 | static bool update_mtime(unsigned ivalid) |
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index a9f5e137f1d3..b5fd6f9905e4 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -351,10 +351,9 @@ static void fuse_sync_writes(struct inode *inode) | |||
351 | fuse_release_nowrite(inode); | 351 | fuse_release_nowrite(inode); |
352 | } | 352 | } |
353 | 353 | ||
354 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, | 354 | int fuse_fsync_common(struct file *file, int datasync, int isdir) |
355 | int isdir) | ||
356 | { | 355 | { |
357 | struct inode *inode = de->d_inode; | 356 | struct inode *inode = file->f_mapping->host; |
358 | struct fuse_conn *fc = get_fuse_conn(inode); | 357 | struct fuse_conn *fc = get_fuse_conn(inode); |
359 | struct fuse_file *ff = file->private_data; | 358 | struct fuse_file *ff = file->private_data; |
360 | struct fuse_req *req; | 359 | struct fuse_req *req; |
@@ -403,9 +402,9 @@ int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, | |||
403 | return err; | 402 | return err; |
404 | } | 403 | } |
405 | 404 | ||
406 | static int fuse_fsync(struct file *file, struct dentry *de, int datasync) | 405 | static int fuse_fsync(struct file *file, int datasync) |
407 | { | 406 | { |
408 | return fuse_fsync_common(file, de, datasync, 0); | 407 | return fuse_fsync_common(file, datasync, 0); |
409 | } | 408 | } |
410 | 409 | ||
411 | void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos, | 410 | void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos, |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 01cc462ff45d..2c0d14a86779 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -568,8 +568,7 @@ void fuse_release_common(struct file *file, int opcode); | |||
568 | /** | 568 | /** |
569 | * Send FSYNC or FSYNCDIR request | 569 | * Send FSYNC or FSYNCDIR request |
570 | */ | 570 | */ |
571 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, | 571 | int fuse_fsync_common(struct file *file, int datasync, int isdir); |
572 | int isdir); | ||
573 | 572 | ||
574 | /** | 573 | /** |
575 | * Notify poll wakeup | 574 | * Notify poll wakeup |
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index a739a0a48067..9f8b52500d63 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c | |||
@@ -700,8 +700,14 @@ out: | |||
700 | return 0; | 700 | return 0; |
701 | 701 | ||
702 | page_cache_release(page); | 702 | 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 | */ | ||
703 | if (pos + len > ip->i_inode.i_size) | 709 | 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); |
705 | out_endtrans: | 711 | out_endtrans: |
706 | gfs2_trans_end(sdp); | 712 | gfs2_trans_end(sdp); |
707 | out_trans_fail: | 713 | out_trans_fail: |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index b20bfcc9fa2d..ed9a94f0ef15 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -554,9 +554,9 @@ static int gfs2_close(struct inode *inode, struct file *file) | |||
554 | * Returns: errno | 554 | * Returns: errno |
555 | */ | 555 | */ |
556 | 556 | ||
557 | static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) | 557 | static int gfs2_fsync(struct file *file, int datasync) |
558 | { | 558 | { |
559 | struct inode *inode = dentry->d_inode; | 559 | struct inode *inode = file->f_mapping->host; |
560 | int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); | 560 | int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); |
561 | int ret = 0; | 561 | int ret = 0; |
562 | 562 | ||
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 4e64352d49de..98cdd05f3316 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c | |||
@@ -1071,6 +1071,9 @@ int gfs2_permission(struct inode *inode, int mask) | |||
1071 | return error; | 1071 | return error; |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | /* | ||
1075 | * XXX: should be changed to have proper ordering by opencoding simple_setsize | ||
1076 | */ | ||
1074 | static int setattr_size(struct inode *inode, struct iattr *attr) | 1077 | static int setattr_size(struct inode *inode, struct iattr *attr) |
1075 | { | 1078 | { |
1076 | struct gfs2_inode *ip = GFS2_I(inode); | 1079 | struct gfs2_inode *ip = GFS2_I(inode); |
@@ -1081,7 +1084,7 @@ static int setattr_size(struct inode *inode, struct iattr *attr) | |||
1081 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); | 1084 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
1082 | if (error) | 1085 | if (error) |
1083 | return error; | 1086 | return error; |
1084 | error = vmtruncate(inode, attr->ia_size); | 1087 | error = simple_setsize(inode, attr->ia_size); |
1085 | gfs2_trans_end(sdp); | 1088 | gfs2_trans_end(sdp); |
1086 | if (error) | 1089 | if (error) |
1087 | return error; | 1090 | return error; |
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 3a029d8f4cf1..87ac1891a185 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c | |||
@@ -411,9 +411,9 @@ int hostfs_file_open(struct inode *ino, struct file *file) | |||
411 | return 0; | 411 | return 0; |
412 | } | 412 | } |
413 | 413 | ||
414 | int hostfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 414 | int hostfs_fsync(struct file *file, int datasync) |
415 | { | 415 | { |
416 | return fsync_file(HOSTFS_I(dentry->d_inode)->fd, datasync); | 416 | return fsync_file(HOSTFS_I(file->f_mapping->host)->fd, datasync); |
417 | } | 417 | } |
418 | 418 | ||
419 | static const struct file_operations hostfs_file_fops = { | 419 | static const struct file_operations hostfs_file_fops = { |
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 3efabff00367..a9ae9bfa752f 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c | |||
@@ -19,9 +19,9 @@ static int hpfs_file_release(struct inode *inode, struct file *file) | |||
19 | return 0; | 19 | return 0; |
20 | } | 20 | } |
21 | 21 | ||
22 | int hpfs_file_fsync(struct file *file, struct dentry *dentry, int datasync) | 22 | int hpfs_file_fsync(struct file *file, int datasync) |
23 | { | 23 | { |
24 | /*return file_fsync(file, dentry);*/ | 24 | /*return file_fsync(file, datasync);*/ |
25 | return 0; /* Don't fsync :-) */ | 25 | return 0; /* Don't fsync :-) */ |
26 | } | 26 | } |
27 | 27 | ||
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h index 97bf738cd5d6..75f9d4324851 100644 --- a/fs/hpfs/hpfs_fn.h +++ b/fs/hpfs/hpfs_fn.h | |||
@@ -268,7 +268,7 @@ void hpfs_set_ea(struct inode *, struct fnode *, const char *, | |||
268 | 268 | ||
269 | /* file.c */ | 269 | /* file.c */ |
270 | 270 | ||
271 | int hpfs_file_fsync(struct file *, struct dentry *, int); | 271 | int hpfs_file_fsync(struct file *, int); |
272 | extern const struct file_operations hpfs_file_ops; | 272 | extern const struct file_operations hpfs_file_ops; |
273 | extern const struct inode_operations hpfs_file_iops; | 273 | extern const struct inode_operations hpfs_file_iops; |
274 | extern const struct address_space_operations hpfs_aops; | 274 | extern const struct address_space_operations hpfs_aops; |
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c index 2e4dfa8593da..826c3f9d29ac 100644 --- a/fs/hppfs/hppfs.c +++ b/fs/hppfs/hppfs.c | |||
@@ -587,7 +587,7 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) | |||
587 | return err; | 587 | return err; |
588 | } | 588 | } |
589 | 589 | ||
590 | static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 590 | static int hppfs_fsync(struct file *file, int datasync) |
591 | { | 591 | { |
592 | return 0; | 592 | return 0; |
593 | } | 593 | } |
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a0bbd3d1b41a..a4e9a7ec3691 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c | |||
@@ -688,7 +688,7 @@ static void init_once(void *foo) | |||
688 | const struct file_operations hugetlbfs_file_operations = { | 688 | const struct file_operations hugetlbfs_file_operations = { |
689 | .read = hugetlbfs_read, | 689 | .read = hugetlbfs_read, |
690 | .mmap = hugetlbfs_file_mmap, | 690 | .mmap = hugetlbfs_file_mmap, |
691 | .fsync = simple_sync_file, | 691 | .fsync = noop_fsync, |
692 | .get_unmapped_area = hugetlb_get_unmapped_area, | 692 | .get_unmapped_area = hugetlb_get_unmapped_area, |
693 | }; | 693 | }; |
694 | 694 | ||
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index e7291c161a19..813497024437 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c | |||
@@ -26,9 +26,9 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping, | |||
26 | struct page **pagep, void **fsdata); | 26 | struct page **pagep, void **fsdata); |
27 | static int jffs2_readpage (struct file *filp, struct page *pg); | 27 | static int jffs2_readpage (struct file *filp, struct page *pg); |
28 | 28 | ||
29 | int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync) | 29 | int jffs2_fsync(struct file *filp, int datasync) |
30 | { | 30 | { |
31 | struct inode *inode = dentry->d_inode; | 31 | struct inode *inode = filp->f_mapping->host; |
32 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); | 32 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); |
33 | 33 | ||
34 | /* Trigger GC to flush any pending writes for this inode */ | 34 | /* Trigger GC to flush any pending writes for this inode */ |
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 86e0821fc989..8bc2c80ab159 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c | |||
@@ -169,13 +169,13 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) | |||
169 | mutex_unlock(&f->sem); | 169 | mutex_unlock(&f->sem); |
170 | jffs2_complete_reservation(c); | 170 | jffs2_complete_reservation(c); |
171 | 171 | ||
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 |
173 | some pages may be locked and waiting for it in readpage(). | 173 | some pages may be locked and waiting for it in readpage(). |
174 | We are protected from a simultaneous write() extending i_size | 174 | We are protected from a simultaneous write() extending i_size |
175 | back past iattr->ia_size, because do_truncate() holds the | 175 | back past iattr->ia_size, because do_truncate() holds the |
176 | generic inode semaphore. */ | 176 | generic inode semaphore. */ |
177 | if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) { | 177 | if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) { |
178 | vmtruncate(inode, iattr->ia_size); | 178 | simple_setsize(inode, iattr->ia_size); |
179 | inode->i_blocks = (inode->i_size + 511) >> 9; | 179 | inode->i_blocks = (inode->i_size + 511) >> 9; |
180 | } | 180 | } |
181 | 181 | ||
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h index 035a767f958b..4791aacf3084 100644 --- a/fs/jffs2/os-linux.h +++ b/fs/jffs2/os-linux.h | |||
@@ -158,7 +158,7 @@ extern const struct inode_operations jffs2_dir_inode_operations; | |||
158 | extern const struct file_operations jffs2_file_operations; | 158 | extern const struct file_operations jffs2_file_operations; |
159 | extern const struct inode_operations jffs2_file_inode_operations; | 159 | extern const struct inode_operations jffs2_file_inode_operations; |
160 | extern const struct address_space_operations jffs2_file_address_operations; | 160 | extern const struct address_space_operations jffs2_file_address_operations; |
161 | int jffs2_fsync(struct file *, struct dentry *, int); | 161 | int jffs2_fsync(struct file *, int); |
162 | int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg); | 162 | int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg); |
163 | 163 | ||
164 | /* ioctl.c */ | 164 | /* ioctl.c */ |
diff --git a/fs/jfs/file.c b/fs/jfs/file.c index 85d9ec659225..127263cc8657 100644 --- a/fs/jfs/file.c +++ b/fs/jfs/file.c | |||
@@ -27,9 +27,9 @@ | |||
27 | #include "jfs_acl.h" | 27 | #include "jfs_acl.h" |
28 | #include "jfs_debug.h" | 28 | #include "jfs_debug.h" |
29 | 29 | ||
30 | int jfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 30 | int jfs_fsync(struct file *file, int datasync) |
31 | { | 31 | { |
32 | struct inode *inode = dentry->d_inode; | 32 | struct inode *inode = file->f_mapping->host; |
33 | int rc = 0; | 33 | int rc = 0; |
34 | 34 | ||
35 | if (!(inode->i_state & I_DIRTY) || | 35 | if (!(inode->i_state & I_DIRTY) || |
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h index 9e6bda30a6e8..11042b1f44b5 100644 --- a/fs/jfs/jfs_inode.h +++ b/fs/jfs/jfs_inode.h | |||
@@ -21,7 +21,7 @@ | |||
21 | struct fid; | 21 | struct fid; |
22 | 22 | ||
23 | extern struct inode *ialloc(struct inode *, umode_t); | 23 | extern struct inode *ialloc(struct inode *, umode_t); |
24 | extern int jfs_fsync(struct file *, struct dentry *, int); | 24 | extern int jfs_fsync(struct file *, int); |
25 | extern long jfs_ioctl(struct file *, unsigned int, unsigned long); | 25 | extern long jfs_ioctl(struct file *, unsigned int, unsigned long); |
26 | extern long jfs_compat_ioctl(struct file *, unsigned int, unsigned long); | 26 | extern long jfs_compat_ioctl(struct file *, unsigned int, unsigned long); |
27 | extern struct inode *jfs_iget(struct super_block *, unsigned long); | 27 | extern struct inode *jfs_iget(struct super_block *, unsigned long); |
diff --git a/fs/libfs.c b/fs/libfs.c index 232bea425b09..09e1016eb774 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); |
@@ -851,13 +922,22 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid, | |||
851 | } | 922 | } |
852 | EXPORT_SYMBOL_GPL(generic_fh_to_parent); | 923 | EXPORT_SYMBOL_GPL(generic_fh_to_parent); |
853 | 924 | ||
854 | int simple_fsync(struct file *file, struct dentry *dentry, int datasync) | 925 | /** |
926 | * generic_file_fsync - generic fsync implementation for simple filesystems | ||
927 | * @file: file to synchronize | ||
928 | * @datasync: only synchronize essential metadata if true | ||
929 | * | ||
930 | * This is a generic implementation of the fsync method for simple | ||
931 | * filesystems which track all non-inode metadata in the buffers list | ||
932 | * hanging off the address_space structure. | ||
933 | */ | ||
934 | int generic_file_fsync(struct file *file, int datasync) | ||
855 | { | 935 | { |
856 | struct writeback_control wbc = { | 936 | struct writeback_control wbc = { |
857 | .sync_mode = WB_SYNC_ALL, | 937 | .sync_mode = WB_SYNC_ALL, |
858 | .nr_to_write = 0, /* metadata-only; caller takes care of data */ | 938 | .nr_to_write = 0, /* metadata-only; caller takes care of data */ |
859 | }; | 939 | }; |
860 | struct inode *inode = dentry->d_inode; | 940 | struct inode *inode = file->f_mapping->host; |
861 | int err; | 941 | int err; |
862 | int ret; | 942 | int ret; |
863 | 943 | ||
@@ -872,7 +952,15 @@ int simple_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
872 | ret = err; | 952 | ret = err; |
873 | return ret; | 953 | return ret; |
874 | } | 954 | } |
875 | EXPORT_SYMBOL(simple_fsync); | 955 | EXPORT_SYMBOL(generic_file_fsync); |
956 | |||
957 | /* | ||
958 | * No-op implementation of ->fsync for in-memory filesystems. | ||
959 | */ | ||
960 | int noop_fsync(struct file *file, int datasync) | ||
961 | { | ||
962 | return 0; | ||
963 | } | ||
876 | 964 | ||
877 | EXPORT_SYMBOL(dcache_dir_close); | 965 | EXPORT_SYMBOL(dcache_dir_close); |
878 | EXPORT_SYMBOL(dcache_dir_lseek); | 966 | EXPORT_SYMBOL(dcache_dir_lseek); |
@@ -895,7 +983,7 @@ EXPORT_SYMBOL(simple_release_fs); | |||
895 | EXPORT_SYMBOL(simple_rename); | 983 | EXPORT_SYMBOL(simple_rename); |
896 | EXPORT_SYMBOL(simple_rmdir); | 984 | EXPORT_SYMBOL(simple_rmdir); |
897 | EXPORT_SYMBOL(simple_statfs); | 985 | EXPORT_SYMBOL(simple_statfs); |
898 | EXPORT_SYMBOL(simple_sync_file); | 986 | EXPORT_SYMBOL(noop_fsync); |
899 | EXPORT_SYMBOL(simple_unlink); | 987 | EXPORT_SYMBOL(simple_unlink); |
900 | EXPORT_SYMBOL(simple_read_from_buffer); | 988 | EXPORT_SYMBOL(simple_read_from_buffer); |
901 | EXPORT_SYMBOL(simple_write_to_buffer); | 989 | EXPORT_SYMBOL(simple_write_to_buffer); |
diff --git a/fs/logfs/file.c b/fs/logfs/file.c index 0de524071870..abe1cafbd4c2 100644 --- a/fs/logfs/file.c +++ b/fs/logfs/file.c | |||
@@ -219,9 +219,9 @@ int logfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | int logfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 222 | int logfs_fsync(struct file *file, int datasync) |
223 | { | 223 | { |
224 | struct super_block *sb = dentry->d_inode->i_sb; | 224 | struct super_block *sb = file->f_mapping->host->i_sb; |
225 | 225 | ||
226 | logfs_write_anchor(sb); | 226 | logfs_write_anchor(sb); |
227 | return 0; | 227 | return 0; |
diff --git a/fs/logfs/logfs.h b/fs/logfs/logfs.h index 1a9db84f8d8f..c838c4d72111 100644 --- a/fs/logfs/logfs.h +++ b/fs/logfs/logfs.h | |||
@@ -506,7 +506,7 @@ extern const struct address_space_operations logfs_reg_aops; | |||
506 | int logfs_readpage(struct file *file, struct page *page); | 506 | int logfs_readpage(struct file *file, struct page *page); |
507 | int logfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 507 | int logfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, |
508 | unsigned long arg); | 508 | unsigned long arg); |
509 | int logfs_fsync(struct file *file, struct dentry *dentry, int datasync); | 509 | int logfs_fsync(struct file *file, int datasync); |
510 | 510 | ||
511 | /* gc.c */ | 511 | /* gc.c */ |
512 | u32 get_best_cand(struct super_block *sb, struct candidate_list *list, u32 *ec); | 512 | u32 get_best_cand(struct super_block *sb, struct candidate_list *list, u32 *ec); |
diff --git a/fs/minix/dir.c b/fs/minix/dir.c index 6198731d7fcd..91969589131c 100644 --- a/fs/minix/dir.c +++ b/fs/minix/dir.c | |||
@@ -22,7 +22,7 @@ const struct file_operations minix_dir_operations = { | |||
22 | .llseek = generic_file_llseek, | 22 | .llseek = generic_file_llseek, |
23 | .read = generic_read_dir, | 23 | .read = generic_read_dir, |
24 | .readdir = minix_readdir, | 24 | .readdir = minix_readdir, |
25 | .fsync = simple_fsync, | 25 | .fsync = generic_file_fsync, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | static inline void dir_put_page(struct page *page) | 28 | static inline void dir_put_page(struct page *page) |
@@ -72,11 +72,8 @@ static struct page * dir_get_page(struct inode *dir, unsigned long n) | |||
72 | { | 72 | { |
73 | struct address_space *mapping = dir->i_mapping; | 73 | struct address_space *mapping = dir->i_mapping; |
74 | struct page *page = read_mapping_page(mapping, n, NULL); | 74 | struct page *page = read_mapping_page(mapping, n, NULL); |
75 | if (!IS_ERR(page)) { | 75 | if (!IS_ERR(page)) |
76 | kmap(page); | 76 | kmap(page); |
77 | if (!PageUptodate(page)) | ||
78 | goto fail; | ||
79 | } | ||
80 | return page; | 77 | return page; |
81 | 78 | ||
82 | fail: | 79 | fail: |
diff --git a/fs/minix/file.c b/fs/minix/file.c index 3eec3e607a87..d5320ff23faf 100644 --- a/fs/minix/file.c +++ b/fs/minix/file.c | |||
@@ -19,7 +19,7 @@ const struct file_operations minix_file_operations = { | |||
19 | .write = do_sync_write, | 19 | .write = do_sync_write, |
20 | .aio_write = generic_file_aio_write, | 20 | .aio_write = generic_file_aio_write, |
21 | .mmap = generic_file_mmap, | 21 | .mmap = generic_file_mmap, |
22 | .fsync = simple_fsync, | 22 | .fsync = generic_file_fsync, |
23 | .splice_read = generic_file_splice_read, | 23 | .splice_read = generic_file_splice_read, |
24 | }; | 24 | }; |
25 | 25 | ||
diff --git a/fs/minix/itree_v2.c b/fs/minix/itree_v2.c index f23010969369..13487ad16894 100644 --- a/fs/minix/itree_v2.c +++ b/fs/minix/itree_v2.c | |||
@@ -20,6 +20,9 @@ static inline block_t *i_data(struct inode *inode) | |||
20 | return (block_t *)minix_i(inode)->u.i2_data; | 20 | return (block_t *)minix_i(inode)->u.i2_data; |
21 | } | 21 | } |
22 | 22 | ||
23 | #define DIRCOUNT 7 | ||
24 | #define INDIRCOUNT(sb) (1 << ((sb)->s_blocksize_bits - 2)) | ||
25 | |||
23 | static int block_to_path(struct inode * inode, long block, int offsets[DEPTH]) | 26 | static int block_to_path(struct inode * inode, long block, int offsets[DEPTH]) |
24 | { | 27 | { |
25 | int n = 0; | 28 | int n = 0; |
@@ -34,21 +37,21 @@ static int block_to_path(struct inode * inode, long block, int offsets[DEPTH]) | |||
34 | printk("MINIX-fs: block_to_path: " | 37 | printk("MINIX-fs: block_to_path: " |
35 | "block %ld too big on dev %s\n", | 38 | "block %ld too big on dev %s\n", |
36 | block, bdevname(sb->s_bdev, b)); | 39 | block, bdevname(sb->s_bdev, b)); |
37 | } else if (block < 7) { | 40 | } else if (block < DIRCOUNT) { |
38 | offsets[n++] = block; | 41 | offsets[n++] = block; |
39 | } else if ((block -= 7) < 256) { | 42 | } else if ((block -= DIRCOUNT) < INDIRCOUNT(sb)) { |
40 | offsets[n++] = 7; | 43 | offsets[n++] = DIRCOUNT; |
41 | offsets[n++] = block; | 44 | offsets[n++] = block; |
42 | } else if ((block -= 256) < 256*256) { | 45 | } else if ((block -= INDIRCOUNT(sb)) < INDIRCOUNT(sb) * INDIRCOUNT(sb)) { |
43 | offsets[n++] = 8; | 46 | offsets[n++] = DIRCOUNT + 1; |
44 | offsets[n++] = block>>8; | 47 | offsets[n++] = block / INDIRCOUNT(sb); |
45 | offsets[n++] = block & 255; | 48 | offsets[n++] = block % INDIRCOUNT(sb); |
46 | } else { | 49 | } else { |
47 | block -= 256*256; | 50 | block -= INDIRCOUNT(sb) * INDIRCOUNT(sb); |
48 | offsets[n++] = 9; | 51 | offsets[n++] = DIRCOUNT + 2; |
49 | offsets[n++] = block>>16; | 52 | offsets[n++] = (block / INDIRCOUNT(sb)) / INDIRCOUNT(sb); |
50 | offsets[n++] = (block>>8) & 255; | 53 | offsets[n++] = (block / INDIRCOUNT(sb)) % INDIRCOUNT(sb); |
51 | offsets[n++] = block & 255; | 54 | offsets[n++] = block % INDIRCOUNT(sb); |
52 | } | 55 | } |
53 | return n; | 56 | return n; |
54 | } | 57 | } |
diff --git a/fs/namei.c b/fs/namei.c index 48e1f60520ea..868d0cb9d473 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1621,6 +1621,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, | |||
1621 | case LAST_DOTDOT: | 1621 | case LAST_DOTDOT: |
1622 | follow_dotdot(nd); | 1622 | follow_dotdot(nd); |
1623 | dir = nd->path.dentry; | 1623 | dir = nd->path.dentry; |
1624 | case LAST_DOT: | ||
1624 | if (nd->path.mnt->mnt_sb->s_type->fs_flags & FS_REVAL_DOT) { | 1625 | if (nd->path.mnt->mnt_sb->s_type->fs_flags & FS_REVAL_DOT) { |
1625 | if (!dir->d_op->d_revalidate(dir, nd)) { | 1626 | if (!dir->d_op->d_revalidate(dir, nd)) { |
1626 | error = -ESTALE; | 1627 | error = -ESTALE; |
@@ -1628,7 +1629,6 @@ static struct file *do_last(struct nameidata *nd, struct path *path, | |||
1628 | } | 1629 | } |
1629 | } | 1630 | } |
1630 | /* fallthrough */ | 1631 | /* fallthrough */ |
1631 | case LAST_DOT: | ||
1632 | case LAST_ROOT: | 1632 | case LAST_ROOT: |
1633 | if (open_flag & O_CREAT) | 1633 | if (open_flag & O_CREAT) |
1634 | goto exit; | 1634 | goto exit; |
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c index b93870892892..3639cc5cbdae 100644 --- a/fs/ncpfs/file.c +++ b/fs/ncpfs/file.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/ncp_fs.h> | 22 | #include <linux/ncp_fs.h> |
23 | #include "ncplib_kernel.h" | 23 | #include "ncplib_kernel.h" |
24 | 24 | ||
25 | static int ncp_fsync(struct file *file, struct dentry *dentry, int datasync) | 25 | static int ncp_fsync(struct file *file, int datasync) |
26 | { | 26 | { |
27 | return 0; | 27 | return 0; |
28 | } | 28 | } |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index db64854b7b09..782b431ef91c 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -53,7 +53,7 @@ static int nfs_link(struct dentry *, struct inode *, struct dentry *); | |||
53 | static int nfs_mknod(struct inode *, struct dentry *, int, dev_t); | 53 | static int nfs_mknod(struct inode *, struct dentry *, int, dev_t); |
54 | static int nfs_rename(struct inode *, struct dentry *, | 54 | static int nfs_rename(struct inode *, struct dentry *, |
55 | struct inode *, struct dentry *); | 55 | struct inode *, struct dentry *); |
56 | static int nfs_fsync_dir(struct file *, struct dentry *, int); | 56 | static int nfs_fsync_dir(struct file *, int); |
57 | static loff_t nfs_llseek_dir(struct file *, loff_t, int); | 57 | static loff_t nfs_llseek_dir(struct file *, loff_t, int); |
58 | 58 | ||
59 | const struct file_operations nfs_dir_operations = { | 59 | const struct file_operations nfs_dir_operations = { |
@@ -641,8 +641,10 @@ out: | |||
641 | * All directory operations under NFS are synchronous, so fsync() | 641 | * All directory operations under NFS are synchronous, so fsync() |
642 | * is a dummy operation. | 642 | * is a dummy operation. |
643 | */ | 643 | */ |
644 | static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync) | 644 | static int nfs_fsync_dir(struct file *filp, int datasync) |
645 | { | 645 | { |
646 | struct dentry *dentry = filp->f_path.dentry; | ||
647 | |||
646 | dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n", | 648 | dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n", |
647 | dentry->d_parent->d_name.name, dentry->d_name.name, | 649 | dentry->d_parent->d_name.name, dentry->d_name.name, |
648 | datasync); | 650 | datasync); |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index cac96bcc91e4..36a5e74f51b4 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
@@ -53,7 +53,7 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe, | |||
53 | static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, | 53 | static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, |
54 | unsigned long nr_segs, loff_t pos); | 54 | unsigned long nr_segs, loff_t pos); |
55 | static int nfs_file_flush(struct file *, fl_owner_t id); | 55 | static int nfs_file_flush(struct file *, fl_owner_t id); |
56 | static int nfs_file_fsync(struct file *, struct dentry *dentry, int datasync); | 56 | static int nfs_file_fsync(struct file *, int datasync); |
57 | static int nfs_check_flags(int flags); | 57 | static int nfs_check_flags(int flags); |
58 | static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); | 58 | static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); |
59 | static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); | 59 | static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); |
@@ -322,8 +322,9 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma) | |||
322 | * whether any write errors occurred for this process. | 322 | * whether any write errors occurred for this process. |
323 | */ | 323 | */ |
324 | static int | 324 | static int |
325 | nfs_file_fsync(struct file *file, struct dentry *dentry, int datasync) | 325 | nfs_file_fsync(struct file *file, int datasync) |
326 | { | 326 | { |
327 | struct dentry *dentry = file->f_path.dentry; | ||
327 | struct nfs_open_context *ctx = nfs_file_open_context(file); | 328 | struct nfs_open_context *ctx = nfs_file_open_context(file); |
328 | struct inode *inode = dentry->d_inode; | 329 | struct inode *inode = dentry->d_inode; |
329 | 330 | ||
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index 30292df443ce..c9a30d7ff6fc 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "nilfs.h" | 27 | #include "nilfs.h" |
28 | #include "segment.h" | 28 | #include "segment.h" |
29 | 29 | ||
30 | int nilfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | 30 | int nilfs_sync_file(struct file *file, int datasync) |
31 | { | 31 | { |
32 | /* | 32 | /* |
33 | * Called from fsync() system call | 33 | * Called from fsync() system call |
@@ -37,7 +37,7 @@ int nilfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
37 | * This function should be implemented when the writeback function | 37 | * This function should be implemented when the writeback function |
38 | * will be implemented. | 38 | * will be implemented. |
39 | */ | 39 | */ |
40 | struct inode *inode = dentry->d_inode; | 40 | struct inode *inode = file->f_mapping->host; |
41 | int err; | 41 | int err; |
42 | 42 | ||
43 | if (!nilfs_inode_dirty(inode)) | 43 | if (!nilfs_inode_dirty(inode)) |
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h index 8723e5bfd071..47d6d7928122 100644 --- a/fs/nilfs2/nilfs.h +++ b/fs/nilfs2/nilfs.h | |||
@@ -228,7 +228,7 @@ extern void nilfs_set_link(struct inode *, struct nilfs_dir_entry *, | |||
228 | struct page *, struct inode *); | 228 | struct page *, struct inode *); |
229 | 229 | ||
230 | /* file.c */ | 230 | /* file.c */ |
231 | extern int nilfs_sync_file(struct file *, struct dentry *, int); | 231 | extern int nilfs_sync_file(struct file *, int); |
232 | 232 | ||
233 | /* ioctl.c */ | 233 | /* ioctl.c */ |
234 | long nilfs_ioctl(struct file *, unsigned int, unsigned long); | 234 | long nilfs_ioctl(struct file *, unsigned int, unsigned long); |
diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c index fe44d3feee4a..0f48e7c5d9e1 100644 --- a/fs/ntfs/dir.c +++ b/fs/ntfs/dir.c | |||
@@ -1527,10 +1527,9 @@ static int ntfs_dir_open(struct inode *vi, struct file *filp) | |||
1527 | * this problem for now. We do write the $BITMAP attribute if it is present | 1527 | * this problem for now. We do write the $BITMAP attribute if it is present |
1528 | * which is the important one for a directory so things are not too bad. | 1528 | * which is the important one for a directory so things are not too bad. |
1529 | */ | 1529 | */ |
1530 | static int ntfs_dir_fsync(struct file *filp, struct dentry *dentry, | 1530 | static int ntfs_dir_fsync(struct file *filp, int datasync) |
1531 | int datasync) | ||
1532 | { | 1531 | { |
1533 | struct inode *bmp_vi, *vi = dentry->d_inode; | 1532 | struct inode *bmp_vi, *vi = filp->f_mapping->host; |
1534 | int err, ret; | 1533 | int err, ret; |
1535 | ntfs_attr na; | 1534 | ntfs_attr na; |
1536 | 1535 | ||
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index a1924a0d2ab0..113ebd9f25a4 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c | |||
@@ -2133,7 +2133,6 @@ static ssize_t ntfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2133 | /** | 2133 | /** |
2134 | * ntfs_file_fsync - sync a file to disk | 2134 | * ntfs_file_fsync - sync a file to disk |
2135 | * @filp: file to be synced | 2135 | * @filp: file to be synced |
2136 | * @dentry: dentry describing the file to sync | ||
2137 | * @datasync: if non-zero only flush user data and not metadata | 2136 | * @datasync: if non-zero only flush user data and not metadata |
2138 | * | 2137 | * |
2139 | * Data integrity sync of a file to disk. Used for fsync, fdatasync, and msync | 2138 | * Data integrity sync of a file to disk. Used for fsync, fdatasync, and msync |
@@ -2149,19 +2148,15 @@ static ssize_t ntfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2149 | * Also, if @datasync is true, we do not wait on the inode to be written out | 2148 | * Also, if @datasync is true, we do not wait on the inode to be written out |
2150 | * but we always wait on the page cache pages to be written out. | 2149 | * but we always wait on the page cache pages to be written out. |
2151 | * | 2150 | * |
2152 | * Note: In the past @filp could be NULL so we ignore it as we don't need it | ||
2153 | * anyway. | ||
2154 | * | ||
2155 | * Locking: Caller must hold i_mutex on the inode. | 2151 | * Locking: Caller must hold i_mutex on the inode. |
2156 | * | 2152 | * |
2157 | * TODO: We should probably also write all attribute/index inodes associated | 2153 | * TODO: We should probably also write all attribute/index inodes associated |
2158 | * with this inode but since we have no simple way of getting to them we ignore | 2154 | * with this inode but since we have no simple way of getting to them we ignore |
2159 | * this problem for now. | 2155 | * this problem for now. |
2160 | */ | 2156 | */ |
2161 | static int ntfs_file_fsync(struct file *filp, struct dentry *dentry, | 2157 | static int ntfs_file_fsync(struct file *filp, int datasync) |
2162 | int datasync) | ||
2163 | { | 2158 | { |
2164 | struct inode *vi = dentry->d_inode; | 2159 | struct inode *vi = filp->f_mapping->host; |
2165 | int err, ret = 0; | 2160 | int err, ret = 0; |
2166 | 2161 | ||
2167 | ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); | 2162 | ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 97e54b9e654b..6a13ea64c447 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -175,13 +175,12 @@ static int ocfs2_dir_release(struct inode *inode, struct file *file) | |||
175 | return 0; | 175 | return 0; |
176 | } | 176 | } |
177 | 177 | ||
178 | static int ocfs2_sync_file(struct file *file, | 178 | static int ocfs2_sync_file(struct file *file, int datasync) |
179 | struct dentry *dentry, | ||
180 | int datasync) | ||
181 | { | 179 | { |
182 | int err = 0; | 180 | int err = 0; |
183 | journal_t *journal; | 181 | journal_t *journal; |
184 | struct inode *inode = dentry->d_inode; | 182 | struct dentry *dentry = file->f_path.dentry; |
183 | struct inode *inode = file->f_mapping->host; | ||
185 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 184 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
186 | 185 | ||
187 | mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", file, dentry, datasync, | 186 | mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", file, dentry, datasync, |
@@ -1053,7 +1052,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) | |||
1053 | } | 1052 | } |
1054 | 1053 | ||
1055 | /* | 1054 | /* |
1056 | * This will intentionally not wind up calling vmtruncate(), | 1055 | * This will intentionally not wind up calling simple_setsize(), |
1057 | * since all the work for a size change has been done above. | 1056 | * since all the work for a size change has been done above. |
1058 | * Otherwise, we could get into problems with truncate as | 1057 | * Otherwise, we could get into problems with truncate as |
1059 | * ip_alloc_sem is used there to protect against i_size | 1058 | * ip_alloc_sem is used there to protect against i_size |
@@ -2119,9 +2118,13 @@ relock: | |||
2119 | * direct write may have instantiated a few | 2118 | * direct write may have instantiated a few |
2120 | * blocks outside i_size. Trim these off again. | 2119 | * blocks outside i_size. Trim these off again. |
2121 | * Don't need i_size_read because we hold i_mutex. | 2120 | * 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 | ||
2122 | */ | 2125 | */ |
2123 | if (*ppos + count > inode->i_size) | 2126 | if (*ppos + count > inode->i_size) |
2124 | vmtruncate(inode, inode->i_size); | 2127 | simple_setsize(inode, inode->i_size); |
2125 | ret = written; | 2128 | ret = written; |
2126 | goto out_dio; | 2129 | goto out_dio; |
2127 | } | 2130 | } |
diff --git a/fs/omfs/file.c b/fs/omfs/file.c index 399487c09364..6e7a3291bbe8 100644 --- a/fs/omfs/file.c +++ b/fs/omfs/file.c | |||
@@ -329,7 +329,7 @@ const struct file_operations omfs_file_operations = { | |||
329 | .aio_read = generic_file_aio_read, | 329 | .aio_read = generic_file_aio_read, |
330 | .aio_write = generic_file_aio_write, | 330 | .aio_write = generic_file_aio_write, |
331 | .mmap = generic_file_mmap, | 331 | .mmap = generic_file_mmap, |
332 | .fsync = simple_fsync, | 332 | .fsync = generic_file_fsync, |
333 | .splice_read = generic_file_splice_read, | 333 | .splice_read = generic_file_splice_read, |
334 | }; | 334 | }; |
335 | 335 | ||
@@ -1169,14 +1169,18 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1169 | 1169 | ||
1170 | switch (cmd) { | 1170 | switch (cmd) { |
1171 | case F_SETPIPE_SZ: | 1171 | case F_SETPIPE_SZ: |
1172 | if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) | 1172 | if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) { |
1173 | return -EINVAL; | 1173 | ret = -EINVAL; |
1174 | goto out; | ||
1175 | } | ||
1174 | /* | 1176 | /* |
1175 | * The pipe needs to be at least 2 pages large to | 1177 | * The pipe needs to be at least 2 pages large to |
1176 | * guarantee POSIX behaviour. | 1178 | * guarantee POSIX behaviour. |
1177 | */ | 1179 | */ |
1178 | if (arg < 2) | 1180 | if (arg < 2) { |
1179 | return -EINVAL; | 1181 | ret = -EINVAL; |
1182 | goto out; | ||
1183 | } | ||
1180 | ret = pipe_set_size(pipe, arg); | 1184 | ret = pipe_set_size(pipe, arg); |
1181 | break; | 1185 | break; |
1182 | case F_GETPIPE_SZ: | 1186 | case F_GETPIPE_SZ: |
@@ -1187,6 +1191,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1187 | break; | 1191 | break; |
1188 | } | 1192 | } |
1189 | 1193 | ||
1194 | out: | ||
1190 | mutex_unlock(&pipe->inode->i_mutex); | 1195 | mutex_unlock(&pipe->inode->i_mutex); |
1191 | return ret; | 1196 | return ret; |
1192 | } | 1197 | } |
diff --git a/fs/qnx4/dir.c b/fs/qnx4/dir.c index 3d3fd4692133..6e8fc62b40a8 100644 --- a/fs/qnx4/dir.c +++ b/fs/qnx4/dir.c | |||
@@ -80,7 +80,7 @@ const struct file_operations qnx4_dir_operations = | |||
80 | .llseek = generic_file_llseek, | 80 | .llseek = generic_file_llseek, |
81 | .read = generic_read_dir, | 81 | .read = generic_read_dir, |
82 | .readdir = qnx4_readdir, | 82 | .readdir = qnx4_readdir, |
83 | .fsync = simple_fsync, | 83 | .fsync = generic_file_fsync, |
84 | }; | 84 | }; |
85 | 85 | ||
86 | const struct inode_operations qnx4_dir_inode_operations = | 86 | const struct inode_operations qnx4_dir_inode_operations = |
diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c index 78f613cb9c76..4884ac5ae9be 100644 --- a/fs/ramfs/file-mmu.c +++ b/fs/ramfs/file-mmu.c | |||
@@ -43,12 +43,13 @@ const struct file_operations ramfs_file_operations = { | |||
43 | .write = do_sync_write, | 43 | .write = do_sync_write, |
44 | .aio_write = generic_file_aio_write, | 44 | .aio_write = generic_file_aio_write, |
45 | .mmap = generic_file_mmap, | 45 | .mmap = generic_file_mmap, |
46 | .fsync = simple_sync_file, | 46 | .fsync = noop_fsync, |
47 | .splice_read = generic_file_splice_read, | 47 | .splice_read = generic_file_splice_read, |
48 | .splice_write = generic_file_splice_write, | 48 | .splice_write = generic_file_splice_write, |
49 | .llseek = generic_file_llseek, | 49 | .llseek = generic_file_llseek, |
50 | }; | 50 | }; |
51 | 51 | ||
52 | const struct inode_operations ramfs_file_inode_operations = { | 52 | const struct inode_operations ramfs_file_inode_operations = { |
53 | .setattr = simple_setattr, | ||
53 | .getattr = simple_getattr, | 54 | .getattr = simple_getattr, |
54 | }; | 55 | }; |
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 5ea4ad81a429..d532c20fc179 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c | |||
@@ -42,7 +42,7 @@ const struct file_operations ramfs_file_operations = { | |||
42 | .aio_read = generic_file_aio_read, | 42 | .aio_read = generic_file_aio_read, |
43 | .write = do_sync_write, | 43 | .write = do_sync_write, |
44 | .aio_write = generic_file_aio_write, | 44 | .aio_write = generic_file_aio_write, |
45 | .fsync = simple_sync_file, | 45 | .fsync = noop_fsync, |
46 | .splice_read = generic_file_splice_read, | 46 | .splice_read = generic_file_splice_read, |
47 | .splice_write = generic_file_splice_write, | 47 | .splice_write = generic_file_splice_write, |
48 | .llseek = generic_file_llseek, | 48 | .llseek = generic_file_llseek, |
@@ -146,7 +146,7 @@ static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size) | |||
146 | return ret; | 146 | return ret; |
147 | } | 147 | } |
148 | 148 | ||
149 | ret = vmtruncate(inode, newsize); | 149 | ret = simple_setsize(inode, newsize); |
150 | 150 | ||
151 | return ret; | 151 | return ret; |
152 | } | 152 | } |
@@ -169,7 +169,8 @@ static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia) | |||
169 | 169 | ||
170 | /* pick out size-changing events */ | 170 | /* pick out size-changing events */ |
171 | if (ia->ia_valid & ATTR_SIZE) { | 171 | if (ia->ia_valid & ATTR_SIZE) { |
172 | loff_t size = i_size_read(inode); | 172 | loff_t size = inode->i_size; |
173 | |||
173 | if (ia->ia_size != size) { | 174 | if (ia->ia_size != size) { |
174 | ret = ramfs_nommu_resize(inode, ia->ia_size, size); | 175 | ret = ramfs_nommu_resize(inode, ia->ia_size, size); |
175 | if (ret < 0 || ia->ia_valid == ATTR_SIZE) | 176 | if (ret < 0 || ia->ia_valid == ATTR_SIZE) |
@@ -182,7 +183,7 @@ static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia) | |||
182 | } | 183 | } |
183 | } | 184 | } |
184 | 185 | ||
185 | ret = inode_setattr(inode, ia); | 186 | generic_setattr(inode, ia); |
186 | out: | 187 | out: |
187 | ia->ia_valid = old_ia_valid; | 188 | ia->ia_valid = old_ia_valid; |
188 | return ret; | 189 | return ret; |
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c index 4455fbe269a3..198dabf1b2bb 100644 --- a/fs/reiserfs/dir.c +++ b/fs/reiserfs/dir.c | |||
@@ -14,8 +14,7 @@ | |||
14 | extern const struct reiserfs_key MIN_KEY; | 14 | extern const struct reiserfs_key MIN_KEY; |
15 | 15 | ||
16 | static int reiserfs_readdir(struct file *, void *, filldir_t); | 16 | static int reiserfs_readdir(struct file *, void *, filldir_t); |
17 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, | 17 | static int reiserfs_dir_fsync(struct file *filp, int datasync); |
18 | int datasync); | ||
19 | 18 | ||
20 | const struct file_operations reiserfs_dir_operations = { | 19 | const struct file_operations reiserfs_dir_operations = { |
21 | .llseek = generic_file_llseek, | 20 | .llseek = generic_file_llseek, |
@@ -28,10 +27,9 @@ const struct file_operations reiserfs_dir_operations = { | |||
28 | #endif | 27 | #endif |
29 | }; | 28 | }; |
30 | 29 | ||
31 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, | 30 | static int reiserfs_dir_fsync(struct file *filp, int datasync) |
32 | int datasync) | ||
33 | { | 31 | { |
34 | struct inode *inode = dentry->d_inode; | 32 | struct inode *inode = filp->f_mapping->host; |
35 | int err; | 33 | int err; |
36 | reiserfs_write_lock(inode->i_sb); | 34 | reiserfs_write_lock(inode->i_sb); |
37 | err = reiserfs_commit_for_inode(inode); | 35 | err = reiserfs_commit_for_inode(inode); |
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c index 9977df9f3a54..b82cdd8a45dd 100644 --- a/fs/reiserfs/file.c +++ b/fs/reiserfs/file.c | |||
@@ -134,10 +134,9 @@ static void reiserfs_vfs_truncate_file(struct inode *inode) | |||
134 | * be removed... | 134 | * be removed... |
135 | */ | 135 | */ |
136 | 136 | ||
137 | static int reiserfs_sync_file(struct file *filp, | 137 | static int reiserfs_sync_file(struct file *filp, int datasync) |
138 | struct dentry *dentry, int datasync) | ||
139 | { | 138 | { |
140 | struct inode *inode = dentry->d_inode; | 139 | struct inode *inode = filp->f_mapping->host; |
141 | int err; | 140 | int err; |
142 | int barrier_done; | 141 | int barrier_done; |
143 | 142 | ||
diff --git a/fs/smbfs/file.c b/fs/smbfs/file.c index 84ecf0e43f91..8e187a0f94bb 100644 --- a/fs/smbfs/file.c +++ b/fs/smbfs/file.c | |||
@@ -28,8 +28,9 @@ | |||
28 | #include "proto.h" | 28 | #include "proto.h" |
29 | 29 | ||
30 | static int | 30 | static int |
31 | smb_fsync(struct file *file, struct dentry * dentry, int datasync) | 31 | smb_fsync(struct file *file, int datasync) |
32 | { | 32 | { |
33 | struct dentry *dentry = file->f_path.dentry; | ||
33 | struct smb_sb_info *server = server_from_dentry(dentry); | 34 | struct smb_sb_info *server = server_from_dentry(dentry); |
34 | int result; | 35 | int result; |
35 | 36 | ||
diff --git a/fs/smbfs/inode.c b/fs/smbfs/inode.c index dfa1d67f8fca..9551cb6f7fe4 100644 --- a/fs/smbfs/inode.c +++ b/fs/smbfs/inode.c | |||
@@ -714,7 +714,7 @@ smb_notify_change(struct dentry *dentry, struct iattr *attr) | |||
714 | error = server->ops->truncate(inode, attr->ia_size); | 714 | error = server->ops->truncate(inode, attr->ia_size); |
715 | if (error) | 715 | if (error) |
716 | goto out; | 716 | goto out; |
717 | error = vmtruncate(inode, attr->ia_size); | 717 | error = simple_setsize(inode, attr->ia_size); |
718 | if (error) | 718 | if (error) |
719 | goto out; | 719 | goto out; |
720 | refresh = 1; | 720 | refresh = 1; |
diff --git a/fs/super.c b/fs/super.c index 69688b15f1fa..a67409e5ad94 100644 --- a/fs/super.c +++ b/fs/super.c | |||
@@ -946,8 +946,8 @@ out: | |||
946 | EXPORT_SYMBOL_GPL(vfs_kern_mount); | 946 | EXPORT_SYMBOL_GPL(vfs_kern_mount); |
947 | 947 | ||
948 | /** | 948 | /** |
949 | * freeze_super -- lock the filesystem and force it into a consistent state | 949 | * freeze_super - lock the filesystem and force it into a consistent state |
950 | * @super: the super to lock | 950 | * @sb: the super to lock |
951 | * | 951 | * |
952 | * Syncs the super to make sure the filesystem is consistent and calls the fs's | 952 | * Syncs the super to make sure the filesystem is consistent and calls the fs's |
953 | * freeze_fs. Subsequent calls to this without first thawing the fs will return | 953 | * freeze_fs. Subsequent calls to this without first thawing the fs will return |
@@ -130,12 +130,10 @@ void emergency_sync(void) | |||
130 | 130 | ||
131 | /* | 131 | /* |
132 | * Generic function to fsync a file. | 132 | * Generic function to fsync a file. |
133 | * | ||
134 | * filp may be NULL if called via the msync of a vma. | ||
135 | */ | 133 | */ |
136 | int file_fsync(struct file *filp, struct dentry *dentry, int datasync) | 134 | int file_fsync(struct file *filp, int datasync) |
137 | { | 135 | { |
138 | struct inode * inode = dentry->d_inode; | 136 | struct inode *inode = filp->f_mapping->host; |
139 | struct super_block * sb; | 137 | struct super_block * sb; |
140 | int ret, err; | 138 | int ret, err; |
141 | 139 | ||
@@ -183,7 +181,7 @@ int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) | |||
183 | * livelocks in fsync_buffers_list(). | 181 | * livelocks in fsync_buffers_list(). |
184 | */ | 182 | */ |
185 | mutex_lock(&mapping->host->i_mutex); | 183 | mutex_lock(&mapping->host->i_mutex); |
186 | err = file->f_op->fsync(file, file->f_path.dentry, datasync); | 184 | err = file->f_op->fsync(file, datasync); |
187 | if (!ret) | 185 | if (!ret) |
188 | ret = err; | 186 | ret = err; |
189 | mutex_unlock(&mapping->host->i_mutex); | 187 | mutex_unlock(&mapping->host->i_mutex); |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index bbd77e95cf7f..bde1a4c3679a 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -117,13 +117,11 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
117 | if (error) | 117 | if (error) |
118 | goto out; | 118 | goto out; |
119 | 119 | ||
120 | iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */ | 120 | /* this ignores size changes */ |
121 | 121 | generic_setattr(inode, iattr); | |
122 | error = inode_setattr(inode, iattr); | ||
123 | if (error) | ||
124 | goto out; | ||
125 | 122 | ||
126 | error = sysfs_sd_setattr(sd, iattr); | 123 | error = sysfs_sd_setattr(sd, iattr); |
124 | |||
127 | out: | 125 | out: |
128 | mutex_unlock(&sysfs_mutex); | 126 | mutex_unlock(&sysfs_mutex); |
129 | return error; | 127 | return error; |
diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 1dabed286b4c..79941e4964a4 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c | |||
@@ -24,7 +24,7 @@ const struct file_operations sysv_dir_operations = { | |||
24 | .llseek = generic_file_llseek, | 24 | .llseek = generic_file_llseek, |
25 | .read = generic_read_dir, | 25 | .read = generic_read_dir, |
26 | .readdir = sysv_readdir, | 26 | .readdir = sysv_readdir, |
27 | .fsync = simple_fsync, | 27 | .fsync = generic_file_fsync, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | static inline void dir_put_page(struct page *page) | 30 | static inline void dir_put_page(struct page *page) |
diff --git a/fs/sysv/file.c b/fs/sysv/file.c index 96340c01f4a7..750cc22349bd 100644 --- a/fs/sysv/file.c +++ b/fs/sysv/file.c | |||
@@ -26,7 +26,7 @@ const struct file_operations sysv_file_operations = { | |||
26 | .write = do_sync_write, | 26 | .write = do_sync_write, |
27 | .aio_write = generic_file_aio_write, | 27 | .aio_write = generic_file_aio_write, |
28 | .mmap = generic_file_mmap, | 28 | .mmap = generic_file_mmap, |
29 | .fsync = simple_fsync, | 29 | .fsync = generic_file_fsync, |
30 | .splice_read = generic_file_splice_read, | 30 | .splice_read = generic_file_splice_read, |
31 | }; | 31 | }; |
32 | 32 | ||
diff --git a/fs/sysv/inode.c b/fs/sysv/inode.c index 4573734d723d..d4a5380b5669 100644 --- a/fs/sysv/inode.c +++ b/fs/sysv/inode.c | |||
@@ -43,6 +43,7 @@ static int sysv_sync_fs(struct super_block *sb, int wait) | |||
43 | * then attach current time stamp. | 43 | * then attach current time stamp. |
44 | * But if the filesystem was marked clean, keep it clean. | 44 | * But if the filesystem was marked clean, keep it clean. |
45 | */ | 45 | */ |
46 | sb->s_dirt = 0; | ||
46 | old_time = fs32_to_cpu(sbi, *sbi->s_sb_time); | 47 | old_time = fs32_to_cpu(sbi, *sbi->s_sb_time); |
47 | if (sbi->s_type == FSTYPE_SYSV4) { | 48 | if (sbi->s_type == FSTYPE_SYSV4) { |
48 | if (*sbi->s_sb_state == cpu_to_fs32(sbi, 0x7c269d38 - old_time)) | 49 | if (*sbi->s_sb_state == cpu_to_fs32(sbi, 0x7c269d38 - old_time)) |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 5692cf72b807..12f445cee9f7 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -967,12 +967,15 @@ static int do_writepage(struct page *page, int len) | |||
967 | * the page locked, and it locks @ui_mutex. However, write-back does take inode | 967 | * the page locked, and it locks @ui_mutex. However, write-back does take inode |
968 | * @i_mutex, which means other VFS operations may be run on this inode at the | 968 | * @i_mutex, which means other VFS operations may be run on this inode at the |
969 | * same time. And the problematic one is truncation to smaller size, from where | 969 | * 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 |
971 | * drops the truncated pages. And while dropping the pages, it takes the page | 971 | * 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 |
973 | * @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This | 973 | * @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This |
974 | * means that @inode->i_size is changed while @ui_mutex is unlocked. | 974 | * means that @inode->i_size is changed while @ui_mutex is unlocked. |
975 | * | 975 | * |
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 | * | ||
976 | * But in 'ubifs_writepage()' we have to guarantee that we do not write beyond | 979 | * But in 'ubifs_writepage()' we have to guarantee that we do not write beyond |
977 | * inode size. How do we do this if @inode->i_size may became smaller while we | 980 | * inode size. How do we do this if @inode->i_size may became smaller while we |
978 | * are in the middle of 'ubifs_writepage()'? The UBIFS solution is the | 981 | * 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, | |||
1125 | budgeted = 0; | 1128 | budgeted = 0; |
1126 | } | 1129 | } |
1127 | 1130 | ||
1128 | err = vmtruncate(inode, new_size); | 1131 | err = simple_setsize(inode, new_size); |
1129 | if (err) | 1132 | if (err) |
1130 | goto out_budg; | 1133 | goto out_budg; |
1131 | 1134 | ||
@@ -1214,7 +1217,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode, | |||
1214 | 1217 | ||
1215 | if (attr->ia_valid & ATTR_SIZE) { | 1218 | if (attr->ia_valid & ATTR_SIZE) { |
1216 | dbg_gen("size %lld -> %lld", inode->i_size, new_size); | 1219 | dbg_gen("size %lld -> %lld", inode->i_size, new_size); |
1217 | err = vmtruncate(inode, new_size); | 1220 | err = simple_setsize(inode, new_size); |
1218 | if (err) | 1221 | if (err) |
1219 | goto out; | 1222 | goto out; |
1220 | } | 1223 | } |
@@ -1223,7 +1226,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode, | |||
1223 | if (attr->ia_valid & ATTR_SIZE) { | 1226 | if (attr->ia_valid & ATTR_SIZE) { |
1224 | /* Truncation changes inode [mc]time */ | 1227 | /* Truncation changes inode [mc]time */ |
1225 | inode->i_mtime = inode->i_ctime = ubifs_current_time(inode); | 1228 | 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 */ |
1227 | ui->ui_size = inode->i_size; | 1230 | ui->ui_size = inode->i_size; |
1228 | } | 1231 | } |
1229 | 1232 | ||
@@ -1304,9 +1307,9 @@ static void *ubifs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
1304 | return NULL; | 1307 | return NULL; |
1305 | } | 1308 | } |
1306 | 1309 | ||
1307 | int ubifs_fsync(struct file *file, struct dentry *dentry, int datasync) | 1310 | int ubifs_fsync(struct file *file, int datasync) |
1308 | { | 1311 | { |
1309 | struct inode *inode = dentry->d_inode; | 1312 | struct inode *inode = file->f_mapping->host; |
1310 | struct ubifs_info *c = inode->i_sb->s_fs_info; | 1313 | struct ubifs_info *c = inode->i_sb->s_fs_info; |
1311 | int err; | 1314 | int err; |
1312 | 1315 | ||
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index bd2542dad014..2eef553d50c8 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -379,7 +379,7 @@ struct ubifs_gced_idx_leb { | |||
379 | * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses | 379 | * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses |
380 | * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot | 380 | * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot |
381 | * make sure @inode->i_size is always changed under @ui_mutex, because it | 381 | * 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 |
383 | * with 'ubifs_writepage()' (see file.c). All the other inode fields are | 383 | * with 'ubifs_writepage()' (see file.c). All the other inode fields are |
384 | * changed under @ui_mutex, so they do not need "shadow" fields. Note, one | 384 | * changed under @ui_mutex, so they do not need "shadow" fields. Note, one |
385 | * could consider to rework locking and base it on "shadow" fields. | 385 | * could consider to rework locking and base it on "shadow" fields. |
@@ -1678,7 +1678,7 @@ const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c); | |||
1678 | int ubifs_calc_dark(const struct ubifs_info *c, int spc); | 1678 | int ubifs_calc_dark(const struct ubifs_info *c, int spc); |
1679 | 1679 | ||
1680 | /* file.c */ | 1680 | /* file.c */ |
1681 | int ubifs_fsync(struct file *file, struct dentry *dentry, int datasync); | 1681 | int ubifs_fsync(struct file *file, int datasync); |
1682 | int ubifs_setattr(struct dentry *dentry, struct iattr *attr); | 1682 | int ubifs_setattr(struct dentry *dentry, struct iattr *attr); |
1683 | 1683 | ||
1684 | /* dir.c */ | 1684 | /* dir.c */ |
diff --git a/fs/udf/dir.c b/fs/udf/dir.c index 1660c81ffa3d..51552bf50225 100644 --- a/fs/udf/dir.c +++ b/fs/udf/dir.c | |||
@@ -211,5 +211,5 @@ const struct file_operations udf_dir_operations = { | |||
211 | .read = generic_read_dir, | 211 | .read = generic_read_dir, |
212 | .readdir = udf_readdir, | 212 | .readdir = udf_readdir, |
213 | .unlocked_ioctl = udf_ioctl, | 213 | .unlocked_ioctl = udf_ioctl, |
214 | .fsync = simple_fsync, | 214 | .fsync = generic_file_fsync, |
215 | }; | 215 | }; |
diff --git a/fs/udf/file.c b/fs/udf/file.c index baae3a723946..0660280aa180 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c | |||
@@ -224,7 +224,7 @@ const struct file_operations udf_file_operations = { | |||
224 | .write = do_sync_write, | 224 | .write = do_sync_write, |
225 | .aio_write = udf_file_aio_write, | 225 | .aio_write = udf_file_aio_write, |
226 | .release = udf_release_file, | 226 | .release = udf_release_file, |
227 | .fsync = simple_fsync, | 227 | .fsync = generic_file_fsync, |
228 | .splice_read = generic_file_splice_read, | 228 | .splice_read = generic_file_splice_read, |
229 | .llseek = generic_file_llseek, | 229 | .llseek = generic_file_llseek, |
230 | }; | 230 | }; |
diff --git a/fs/ufs/dir.c b/fs/ufs/dir.c index 317a0d444f6b..ec784756dc65 100644 --- a/fs/ufs/dir.c +++ b/fs/ufs/dir.c | |||
@@ -666,6 +666,6 @@ not_empty: | |||
666 | const struct file_operations ufs_dir_operations = { | 666 | const struct file_operations ufs_dir_operations = { |
667 | .read = generic_read_dir, | 667 | .read = generic_read_dir, |
668 | .readdir = ufs_readdir, | 668 | .readdir = ufs_readdir, |
669 | .fsync = simple_fsync, | 669 | .fsync = generic_file_fsync, |
670 | .llseek = generic_file_llseek, | 670 | .llseek = generic_file_llseek, |
671 | }; | 671 | }; |
diff --git a/fs/ufs/file.c b/fs/ufs/file.c index a8962cecde5b..d4c30d1bef86 100644 --- a/fs/ufs/file.c +++ b/fs/ufs/file.c | |||
@@ -42,6 +42,6 @@ const struct file_operations ufs_file_operations = { | |||
42 | .aio_write = generic_file_aio_write, | 42 | .aio_write = generic_file_aio_write, |
43 | .mmap = generic_file_mmap, | 43 | .mmap = generic_file_mmap, |
44 | .open = dquot_file_open, | 44 | .open = dquot_file_open, |
45 | .fsync = simple_fsync, | 45 | .fsync = generic_file_fsync, |
46 | .splice_read = generic_file_splice_read, | 46 | .splice_read = generic_file_splice_read, |
47 | }; | 47 | }; |
diff --git a/fs/ufs/truncate.c b/fs/ufs/truncate.c index f294c44577dc..3733057e7833 100644 --- a/fs/ufs/truncate.c +++ b/fs/ufs/truncate.c | |||
@@ -501,12 +501,10 @@ out: | |||
501 | return err; | 501 | return err; |
502 | } | 502 | } |
503 | 503 | ||
504 | |||
505 | /* | 504 | /* |
506 | * We don't define our `inode->i_op->truncate', and call it here, | 505 | * TODO: |
507 | * because of: | 506 | * - truncate case should use proper ordering instead of using |
508 | * - there is no way to know old size | 507 | * simple_setsize |
509 | * - there is no way inform user about error, if it happens in `truncate' | ||
510 | */ | 508 | */ |
511 | int ufs_setattr(struct dentry *dentry, struct iattr *attr) | 509 | int ufs_setattr(struct dentry *dentry, struct iattr *attr) |
512 | { | 510 | { |
@@ -530,7 +528,7 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr) | |||
530 | if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) { | 528 | if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) { |
531 | loff_t old_i_size = inode->i_size; | 529 | loff_t old_i_size = inode->i_size; |
532 | 530 | ||
533 | error = vmtruncate(inode, attr->ia_size); | 531 | error = simple_setsize(inode, attr->ia_size); |
534 | if (error) | 532 | if (error) |
535 | return error; | 533 | return error; |
536 | error = ufs_truncate(inode, old_i_size); | 534 | error = ufs_truncate(inode, old_i_size); |
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c index d8fb1b5d6cb5..257a56b127cf 100644 --- a/fs/xfs/linux-2.6/xfs_file.c +++ b/fs/xfs/linux-2.6/xfs_file.c | |||
@@ -100,10 +100,10 @@ xfs_iozero( | |||
100 | STATIC int | 100 | STATIC int |
101 | xfs_file_fsync( | 101 | xfs_file_fsync( |
102 | struct file *file, | 102 | struct file *file, |
103 | struct dentry *dentry, | ||
104 | int datasync) | 103 | int datasync) |
105 | { | 104 | { |
106 | struct xfs_inode *ip = XFS_I(dentry->d_inode); | 105 | struct inode *inode = file->f_mapping->host; |
106 | struct xfs_inode *ip = XFS_I(inode); | ||
107 | struct xfs_trans *tp; | 107 | struct xfs_trans *tp; |
108 | int error = 0; | 108 | int error = 0; |
109 | int log_flushed = 0; | 109 | int log_flushed = 0; |
@@ -140,8 +140,8 @@ xfs_file_fsync( | |||
140 | * might gets cleared when the inode gets written out via the AIL | 140 | * might gets cleared when the inode gets written out via the AIL |
141 | * or xfs_iflush_cluster. | 141 | * or xfs_iflush_cluster. |
142 | */ | 142 | */ |
143 | if (((dentry->d_inode->i_state & I_DIRTY_DATASYNC) || | 143 | if (((inode->i_state & I_DIRTY_DATASYNC) || |
144 | ((dentry->d_inode->i_state & I_DIRTY_SYNC) && !datasync)) && | 144 | ((inode->i_state & I_DIRTY_SYNC) && !datasync)) && |
145 | ip->i_update_core) { | 145 | ip->i_update_core) { |
146 | /* | 146 | /* |
147 | * Kick off a transaction to log the inode core to get the | 147 | * Kick off a transaction to log the inode core to get the |
@@ -868,7 +868,7 @@ write_retry: | |||
868 | mutex_lock(&inode->i_mutex); | 868 | mutex_lock(&inode->i_mutex); |
869 | xfs_ilock(ip, iolock); | 869 | xfs_ilock(ip, iolock); |
870 | 870 | ||
871 | error2 = -xfs_file_fsync(file, file->f_path.dentry, | 871 | error2 = -xfs_file_fsync(file, |
872 | (file->f_flags & __O_SYNC) ? 0 : 1); | 872 | (file->f_flags & __O_SYNC) ? 0 : 1); |
873 | if (!error) | 873 | if (!error) |
874 | error = error2; | 874 | error = error2; |
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 16ed0284d780..1b9ba193b789 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h | |||
@@ -203,6 +203,9 @@ int block_write_full_page_endio(struct page *page, get_block_t *get_block, | |||
203 | int block_read_full_page(struct page*, get_block_t*); | 203 | int block_read_full_page(struct page*, get_block_t*); |
204 | int block_is_partially_uptodate(struct page *page, read_descriptor_t *desc, | 204 | int block_is_partially_uptodate(struct page *page, read_descriptor_t *desc, |
205 | unsigned long from); | 205 | unsigned long from); |
206 | int block_write_begin_newtrunc(struct file *, struct address_space *, | ||
207 | loff_t, unsigned, unsigned, | ||
208 | struct page **, void **, get_block_t*); | ||
206 | int block_write_begin(struct file *, struct address_space *, | 209 | int block_write_begin(struct file *, struct address_space *, |
207 | loff_t, unsigned, unsigned, | 210 | loff_t, unsigned, unsigned, |
208 | struct page **, void **, get_block_t*); | 211 | struct page **, void **, get_block_t*); |
@@ -214,6 +217,9 @@ int generic_write_end(struct file *, struct address_space *, | |||
214 | struct page *, void *); | 217 | struct page *, void *); |
215 | void page_zero_new_buffers(struct page *page, unsigned from, unsigned to); | 218 | void page_zero_new_buffers(struct page *page, unsigned from, unsigned to); |
216 | int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*); | 219 | int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*); |
220 | int cont_write_begin_newtrunc(struct file *, struct address_space *, loff_t, | ||
221 | unsigned, unsigned, struct page **, void **, | ||
222 | get_block_t *, loff_t *); | ||
217 | int cont_write_begin(struct file *, struct address_space *, loff_t, | 223 | int cont_write_begin(struct file *, struct address_space *, loff_t, |
218 | unsigned, unsigned, struct page **, void **, | 224 | unsigned, unsigned, struct page **, void **, |
219 | get_block_t *, loff_t *); | 225 | get_block_t *, loff_t *); |
@@ -224,7 +230,10 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, | |||
224 | void block_sync_page(struct page *); | 230 | void block_sync_page(struct page *); |
225 | sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); | 231 | sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); |
226 | int block_truncate_page(struct address_space *, loff_t, get_block_t *); | 232 | int block_truncate_page(struct address_space *, loff_t, get_block_t *); |
227 | int file_fsync(struct file *, struct dentry *, int); | 233 | int file_fsync(struct file *, int); |
234 | int nobh_write_begin_newtrunc(struct file *, struct address_space *, | ||
235 | loff_t, unsigned, unsigned, | ||
236 | struct page **, void **, get_block_t*); | ||
228 | int nobh_write_begin(struct file *, struct address_space *, | 237 | int nobh_write_begin(struct file *, struct address_space *, |
229 | loff_t, unsigned, unsigned, | 238 | loff_t, unsigned, unsigned, |
230 | struct page **, void **, get_block_t*); | 239 | struct page **, void **, get_block_t*); |
diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h index 5f494b465097..7fc62d4550b2 100644 --- a/include/linux/ext3_fs.h +++ b/include/linux/ext3_fs.h | |||
@@ -868,7 +868,7 @@ extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, | |||
868 | extern void ext3_htree_free_dir_info(struct dir_private_info *p); | 868 | extern void ext3_htree_free_dir_info(struct dir_private_info *p); |
869 | 869 | ||
870 | /* fsync.c */ | 870 | /* fsync.c */ |
871 | extern int ext3_sync_file (struct file *, struct dentry *, int); | 871 | extern int ext3_sync_file(struct file *, int); |
872 | 872 | ||
873 | /* hash.c */ | 873 | /* hash.c */ |
874 | extern int ext3fs_dirhash(const char *name, int len, struct | 874 | extern int ext3fs_dirhash(const char *name, int len, struct |
diff --git a/include/linux/fb.h b/include/linux/fb.h index f3793ebc241c..907ace3a64c8 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h | |||
@@ -4,8 +4,6 @@ | |||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | #include <linux/i2c.h> | 5 | #include <linux/i2c.h> |
6 | 6 | ||
7 | struct dentry; | ||
8 | |||
9 | /* Definitions of frame buffers */ | 7 | /* Definitions of frame buffers */ |
10 | 8 | ||
11 | #define FB_MAX 32 /* sufficient for now */ | 9 | #define FB_MAX 32 /* sufficient for now */ |
@@ -1017,8 +1015,7 @@ extern void fb_deferred_io_open(struct fb_info *info, | |||
1017 | struct inode *inode, | 1015 | struct inode *inode, |
1018 | struct file *file); | 1016 | struct file *file); |
1019 | extern void fb_deferred_io_cleanup(struct fb_info *info); | 1017 | extern void fb_deferred_io_cleanup(struct fb_info *info); |
1020 | extern int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, | 1018 | extern int fb_deferred_io_fsync(struct file *file, int datasync); |
1021 | int datasync); | ||
1022 | 1019 | ||
1023 | static inline bool fb_be_math(struct fb_info *info) | 1020 | static inline bool fb_be_math(struct fb_info *info) |
1024 | { | 1021 | { |
diff --git a/include/linux/file.h b/include/linux/file.h index 5555508fd517..b1e12970f617 100644 --- a/include/linux/file.h +++ b/include/linux/file.h | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | struct file; | 12 | struct file; |
13 | 13 | ||
14 | extern void __fput(struct file *); | ||
15 | extern void fput(struct file *); | 14 | extern void fput(struct file *); |
16 | extern void drop_file_write_access(struct file *file); | 15 | extern void drop_file_write_access(struct file *file); |
17 | 16 | ||
diff --git a/include/linux/fs.h b/include/linux/fs.h index 85e823adcd4a..3428393942a6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -954,6 +954,7 @@ extern spinlock_t files_lock; | |||
954 | #define file_list_unlock() spin_unlock(&files_lock); | 954 | #define file_list_unlock() spin_unlock(&files_lock); |
955 | 955 | ||
956 | #define get_file(x) atomic_long_inc(&(x)->f_count) | 956 | #define get_file(x) atomic_long_inc(&(x)->f_count) |
957 | #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) | ||
957 | #define file_count(x) atomic_long_read(&(x)->f_count) | 958 | #define file_count(x) atomic_long_read(&(x)->f_count) |
958 | 959 | ||
959 | #ifdef CONFIG_DEBUG_WRITECOUNT | 960 | #ifdef CONFIG_DEBUG_WRITECOUNT |
@@ -1497,7 +1498,7 @@ struct file_operations { | |||
1497 | int (*open) (struct inode *, struct file *); | 1498 | int (*open) (struct inode *, struct file *); |
1498 | int (*flush) (struct file *, fl_owner_t id); | 1499 | int (*flush) (struct file *, fl_owner_t id); |
1499 | int (*release) (struct inode *, struct file *); | 1500 | int (*release) (struct inode *, struct file *); |
1500 | int (*fsync) (struct file *, struct dentry *, int datasync); | 1501 | int (*fsync) (struct file *, int datasync); |
1501 | int (*aio_fsync) (struct kiocb *, int datasync); | 1502 | int (*aio_fsync) (struct kiocb *, int datasync); |
1502 | int (*fasync) (int, struct file *, int); | 1503 | int (*fasync) (int, struct file *, int); |
1503 | int (*lock) (struct file *, int, struct file_lock *); | 1504 | int (*lock) (struct file *, int, struct file_lock *); |
@@ -2212,7 +2213,7 @@ extern int generic_segment_checks(const struct iovec *iov, | |||
2212 | /* fs/block_dev.c */ | 2213 | /* fs/block_dev.c */ |
2213 | extern ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, | 2214 | extern ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, |
2214 | unsigned long nr_segs, loff_t pos); | 2215 | unsigned long nr_segs, loff_t pos); |
2215 | extern int blkdev_fsync(struct file *filp, struct dentry *dentry, int datasync); | 2216 | extern int blkdev_fsync(struct file *filp, int datasync); |
2216 | 2217 | ||
2217 | /* fs/splice.c */ | 2218 | /* fs/splice.c */ |
2218 | extern ssize_t generic_file_splice_read(struct file *, loff_t *, | 2219 | extern ssize_t generic_file_splice_read(struct file *, loff_t *, |
@@ -2256,6 +2257,10 @@ typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode, | |||
2256 | loff_t file_offset); | 2257 | loff_t file_offset); |
2257 | void dio_end_io(struct bio *bio, int error); | 2258 | void dio_end_io(struct bio *bio, int error); |
2258 | 2259 | ||
2260 | ssize_t __blockdev_direct_IO_newtrunc(int rw, struct kiocb *iocb, struct inode *inode, | ||
2261 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | ||
2262 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | ||
2263 | dio_submit_t submit_io, int lock_type); | ||
2259 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 2264 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
2260 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 2265 | struct block_device *bdev, const struct iovec *iov, loff_t offset, |
2261 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 2266 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, |
@@ -2269,6 +2274,24 @@ enum { | |||
2269 | DIO_SKIP_HOLES = 0x02, | 2274 | DIO_SKIP_HOLES = 0x02, |
2270 | }; | 2275 | }; |
2271 | 2276 | ||
2277 | static inline ssize_t blockdev_direct_IO_newtrunc(int rw, struct kiocb *iocb, | ||
2278 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | ||
2279 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | ||
2280 | dio_iodone_t end_io) | ||
2281 | { | ||
2282 | return __blockdev_direct_IO_newtrunc(rw, iocb, inode, bdev, iov, offset, | ||
2283 | nr_segs, get_block, end_io, NULL, | ||
2284 | DIO_LOCKING | DIO_SKIP_HOLES); | ||
2285 | } | ||
2286 | |||
2287 | static inline ssize_t blockdev_direct_IO_no_locking_newtrunc(int rw, struct kiocb *iocb, | ||
2288 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | ||
2289 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | ||
2290 | dio_iodone_t end_io) | ||
2291 | { | ||
2292 | return __blockdev_direct_IO_newtrunc(rw, iocb, inode, bdev, iov, offset, | ||
2293 | nr_segs, get_block, end_io, NULL, 0); | ||
2294 | } | ||
2272 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, | 2295 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, |
2273 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 2296 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
2274 | loff_t offset, unsigned long nr_segs, get_block_t get_block, | 2297 | loff_t offset, unsigned long nr_segs, get_block_t get_block, |
@@ -2341,13 +2364,15 @@ extern int dcache_dir_open(struct inode *, struct file *); | |||
2341 | extern int dcache_dir_close(struct inode *, struct file *); | 2364 | extern int dcache_dir_close(struct inode *, struct file *); |
2342 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); | 2365 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); |
2343 | extern int dcache_readdir(struct file *, void *, filldir_t); | 2366 | extern int dcache_readdir(struct file *, void *, filldir_t); |
2367 | extern int simple_setattr(struct dentry *, struct iattr *); | ||
2344 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 2368 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
2345 | extern int simple_statfs(struct dentry *, struct kstatfs *); | 2369 | extern int simple_statfs(struct dentry *, struct kstatfs *); |
2346 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); | 2370 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); |
2347 | extern int simple_unlink(struct inode *, struct dentry *); | 2371 | extern int simple_unlink(struct inode *, struct dentry *); |
2348 | extern int simple_rmdir(struct inode *, struct dentry *); | 2372 | extern int simple_rmdir(struct inode *, struct dentry *); |
2349 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); | 2373 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); |
2350 | extern int simple_sync_file(struct file *, struct dentry *, int); | 2374 | extern int simple_setsize(struct inode *, loff_t); |
2375 | extern int noop_fsync(struct file *, int); | ||
2351 | extern int simple_empty(struct dentry *); | 2376 | extern int simple_empty(struct dentry *); |
2352 | extern int simple_readpage(struct file *file, struct page *page); | 2377 | extern int simple_readpage(struct file *file, struct page *page); |
2353 | extern int simple_write_begin(struct file *file, struct address_space *mapping, | 2378 | extern int simple_write_begin(struct file *file, struct address_space *mapping, |
@@ -2372,7 +2397,7 @@ extern ssize_t simple_read_from_buffer(void __user *to, size_t count, | |||
2372 | extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, | 2397 | extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, |
2373 | const void __user *from, size_t count); | 2398 | const void __user *from, size_t count); |
2374 | 2399 | ||
2375 | extern int simple_fsync(struct file *, struct dentry *, int); | 2400 | extern int generic_file_fsync(struct file *, int); |
2376 | 2401 | ||
2377 | #ifdef CONFIG_MIGRATION | 2402 | #ifdef CONFIG_MIGRATION |
2378 | extern int buffer_migrate_page(struct address_space *, | 2403 | extern int buffer_migrate_page(struct address_space *, |
@@ -2383,7 +2408,8 @@ extern int buffer_migrate_page(struct address_space *, | |||
2383 | 2408 | ||
2384 | extern int inode_change_ok(const struct inode *, struct iattr *); | 2409 | extern int inode_change_ok(const struct inode *, struct iattr *); |
2385 | extern int inode_newsize_ok(const struct inode *, loff_t offset); | 2410 | extern int inode_newsize_ok(const struct inode *, loff_t offset); |
2386 | extern int __must_check inode_setattr(struct inode *, struct iattr *); | 2411 | extern int __must_check inode_setattr(struct inode *, const struct iattr *); |
2412 | extern void generic_setattr(struct inode *inode, const struct iattr *attr); | ||
2387 | 2413 | ||
2388 | extern void file_update_time(struct file *file); | 2414 | extern void file_update_time(struct file *file); |
2389 | 2415 | ||
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 5d60ad4ebf78..f5b1ba90e952 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h | |||
@@ -606,9 +606,9 @@ TRACE_EVENT(ext4_free_blocks, | |||
606 | ); | 606 | ); |
607 | 607 | ||
608 | TRACE_EVENT(ext4_sync_file, | 608 | TRACE_EVENT(ext4_sync_file, |
609 | TP_PROTO(struct file *file, struct dentry *dentry, int datasync), | 609 | TP_PROTO(struct file *file, int datasync), |
610 | 610 | ||
611 | TP_ARGS(file, dentry, datasync), | 611 | TP_ARGS(file, datasync), |
612 | 612 | ||
613 | TP_STRUCT__entry( | 613 | TP_STRUCT__entry( |
614 | __field( dev_t, dev ) | 614 | __field( dev_t, dev ) |
@@ -618,6 +618,8 @@ TRACE_EVENT(ext4_sync_file, | |||
618 | ), | 618 | ), |
619 | 619 | ||
620 | TP_fast_assign( | 620 | TP_fast_assign( |
621 | struct dentry *dentry = file->f_path.dentry; | ||
622 | |||
621 | __entry->dev = dentry->d_inode->i_sb->s_dev; | 623 | __entry->dev = dentry->d_inode->i_sb->s_dev; |
622 | __entry->ino = dentry->d_inode->i_ino; | 624 | __entry->ino = dentry->d_inode->i_ino; |
623 | __entry->datasync = datasync; | 625 | __entry->datasync = datasync; |
@@ -273,16 +273,13 @@ static int shm_release(struct inode *ino, struct file *file) | |||
273 | return 0; | 273 | return 0; |
274 | } | 274 | } |
275 | 275 | ||
276 | static int shm_fsync(struct file *file, struct dentry *dentry, int datasync) | 276 | static int shm_fsync(struct file *file, int datasync) |
277 | { | 277 | { |
278 | int (*fsync) (struct file *, struct dentry *, int datasync); | ||
279 | struct shm_file_data *sfd = shm_file_data(file); | 278 | struct shm_file_data *sfd = shm_file_data(file); |
280 | int ret = -EINVAL; | ||
281 | 279 | ||
282 | fsync = sfd->file->f_op->fsync; | 280 | if (!sfd->file->f_op->fsync) |
283 | if (fsync) | 281 | return -EINVAL; |
284 | ret = fsync(sfd->file, sfd->file->f_path.dentry, datasync); | 282 | return sfd->file->f_op->fsync(sfd->file, datasync); |
285 | return ret; | ||
286 | } | 283 | } |
287 | 284 | ||
288 | static unsigned long shm_get_unmapped_area(struct file *file, | 285 | static unsigned long shm_get_unmapped_area(struct file *file, |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index e099650cd249..bd7ce8ca5bb9 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -4999,8 +4999,8 @@ SYSCALL_DEFINE5(perf_event_open, | |||
4999 | struct perf_event_context *ctx; | 4999 | struct perf_event_context *ctx; |
5000 | struct file *event_file = NULL; | 5000 | struct file *event_file = NULL; |
5001 | struct file *group_file = NULL; | 5001 | struct file *group_file = NULL; |
5002 | int event_fd; | ||
5002 | int fput_needed = 0; | 5003 | int fput_needed = 0; |
5003 | int fput_needed2 = 0; | ||
5004 | int err; | 5004 | int err; |
5005 | 5005 | ||
5006 | /* for future expandability... */ | 5006 | /* for future expandability... */ |
@@ -5021,12 +5021,18 @@ SYSCALL_DEFINE5(perf_event_open, | |||
5021 | return -EINVAL; | 5021 | return -EINVAL; |
5022 | } | 5022 | } |
5023 | 5023 | ||
5024 | event_fd = get_unused_fd_flags(O_RDWR); | ||
5025 | if (event_fd < 0) | ||
5026 | return event_fd; | ||
5027 | |||
5024 | /* | 5028 | /* |
5025 | * Get the target context (task or percpu): | 5029 | * Get the target context (task or percpu): |
5026 | */ | 5030 | */ |
5027 | ctx = find_get_context(pid, cpu); | 5031 | ctx = find_get_context(pid, cpu); |
5028 | if (IS_ERR(ctx)) | 5032 | if (IS_ERR(ctx)) { |
5029 | return PTR_ERR(ctx); | 5033 | err = PTR_ERR(ctx); |
5034 | goto err_fd; | ||
5035 | } | ||
5030 | 5036 | ||
5031 | /* | 5037 | /* |
5032 | * Look up the group leader (we will attach this event to it): | 5038 | * Look up the group leader (we will attach this event to it): |
@@ -5066,13 +5072,11 @@ SYSCALL_DEFINE5(perf_event_open, | |||
5066 | if (IS_ERR(event)) | 5072 | if (IS_ERR(event)) |
5067 | goto err_put_context; | 5073 | goto err_put_context; |
5068 | 5074 | ||
5069 | err = anon_inode_getfd("[perf_event]", &perf_fops, event, O_RDWR); | 5075 | event_file = anon_inode_getfile("[perf_event]", &perf_fops, event, O_RDWR); |
5070 | if (err < 0) | 5076 | if (IS_ERR(event_file)) { |
5071 | goto err_free_put_context; | 5077 | err = PTR_ERR(event_file); |
5072 | |||
5073 | event_file = fget_light(err, &fput_needed2); | ||
5074 | if (!event_file) | ||
5075 | goto err_free_put_context; | 5078 | goto err_free_put_context; |
5079 | } | ||
5076 | 5080 | ||
5077 | if (flags & PERF_FLAG_FD_OUTPUT) { | 5081 | if (flags & PERF_FLAG_FD_OUTPUT) { |
5078 | err = perf_event_set_output(event, group_fd); | 5082 | err = perf_event_set_output(event, group_fd); |
@@ -5093,19 +5097,19 @@ SYSCALL_DEFINE5(perf_event_open, | |||
5093 | list_add_tail(&event->owner_entry, ¤t->perf_event_list); | 5097 | list_add_tail(&event->owner_entry, ¤t->perf_event_list); |
5094 | mutex_unlock(¤t->perf_event_mutex); | 5098 | mutex_unlock(¤t->perf_event_mutex); |
5095 | 5099 | ||
5096 | err_fput_free_put_context: | 5100 | fput_light(group_file, fput_needed); |
5097 | fput_light(event_file, fput_needed2); | 5101 | fd_install(event_fd, event_file); |
5102 | return event_fd; | ||
5098 | 5103 | ||
5104 | err_fput_free_put_context: | ||
5105 | fput(event_file); | ||
5099 | err_free_put_context: | 5106 | err_free_put_context: |
5100 | if (err < 0) | 5107 | free_event(event); |
5101 | free_event(event); | ||
5102 | |||
5103 | err_put_context: | 5108 | err_put_context: |
5104 | if (err < 0) | ||
5105 | put_ctx(ctx); | ||
5106 | |||
5107 | fput_light(group_file, fput_needed); | 5109 | fput_light(group_file, fput_needed); |
5108 | 5110 | put_ctx(ctx); | |
5111 | err_fd: | ||
5112 | put_unused_fd(event_fd); | ||
5109 | return err; | 5113 | return err; |
5110 | } | 5114 | } |
5111 | 5115 | ||
diff --git a/mm/shmem.c b/mm/shmem.c index 855eaf5b8d5b..7e5030ae18ff 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -727,10 +727,11 @@ done2: | |||
727 | if (inode->i_mapping->nrpages && (info->flags & SHMEM_PAGEIN)) { | 727 | if (inode->i_mapping->nrpages && (info->flags & SHMEM_PAGEIN)) { |
728 | /* | 728 | /* |
729 | * Call truncate_inode_pages again: racing shmem_unuse_inode | 729 | * Call truncate_inode_pages again: racing shmem_unuse_inode |
730 | * may have swizzled a page in from swap since vmtruncate or | 730 | * may have swizzled a page in from swap since |
731 | * generic_delete_inode did it, before we lowered next_index. | 731 | * truncate_pagecache or generic_delete_inode did it, before we |
732 | * Also, though shmem_getpage checks i_size before adding to | 732 | * lowered next_index. Also, though shmem_getpage checks |
733 | * cache, no recheck after: so fix the narrow window there too. | 733 | * i_size before adding to cache, no recheck after: so fix the |
734 | * narrow window there too. | ||
734 | * | 735 | * |
735 | * Recalling truncate_inode_pages_range and unmap_mapping_range | 736 | * Recalling truncate_inode_pages_range and unmap_mapping_range |
736 | * every time for punch_hole (which never got a chance to clear | 737 | * every time for punch_hole (which never got a chance to clear |
@@ -760,19 +761,16 @@ done2: | |||
760 | } | 761 | } |
761 | } | 762 | } |
762 | 763 | ||
763 | static void shmem_truncate(struct inode *inode) | ||
764 | { | ||
765 | shmem_truncate_range(inode, inode->i_size, (loff_t)-1); | ||
766 | } | ||
767 | |||
768 | static int shmem_notify_change(struct dentry *dentry, struct iattr *attr) | 764 | static int shmem_notify_change(struct dentry *dentry, struct iattr *attr) |
769 | { | 765 | { |
770 | struct inode *inode = dentry->d_inode; | 766 | struct inode *inode = dentry->d_inode; |
771 | struct page *page = NULL; | ||
772 | int error; | 767 | int error; |
773 | 768 | ||
774 | if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { | 769 | if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { |
775 | if (attr->ia_size < inode->i_size) { | 770 | loff_t newsize = attr->ia_size; |
771 | struct page *page = NULL; | ||
772 | |||
773 | if (newsize < inode->i_size) { | ||
776 | /* | 774 | /* |
777 | * If truncating down to a partial page, then | 775 | * If truncating down to a partial page, then |
778 | * if that page is already allocated, hold it | 776 | * if that page is already allocated, hold it |
@@ -780,9 +778,9 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr) | |||
780 | * truncate_partial_page cannnot miss it were | 778 | * truncate_partial_page cannnot miss it were |
781 | * it assigned to swap. | 779 | * it assigned to swap. |
782 | */ | 780 | */ |
783 | if (attr->ia_size & (PAGE_CACHE_SIZE-1)) { | 781 | if (newsize & (PAGE_CACHE_SIZE-1)) { |
784 | (void) shmem_getpage(inode, | 782 | (void) shmem_getpage(inode, |
785 | attr->ia_size>>PAGE_CACHE_SHIFT, | 783 | newsize >> PAGE_CACHE_SHIFT, |
786 | &page, SGP_READ, NULL); | 784 | &page, SGP_READ, NULL); |
787 | if (page) | 785 | if (page) |
788 | unlock_page(page); | 786 | unlock_page(page); |
@@ -794,24 +792,29 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr) | |||
794 | * if it's being fully truncated to zero-length: the | 792 | * if it's being fully truncated to zero-length: the |
795 | * nrpages check is efficient enough in that case. | 793 | * nrpages check is efficient enough in that case. |
796 | */ | 794 | */ |
797 | if (attr->ia_size) { | 795 | if (newsize) { |
798 | struct shmem_inode_info *info = SHMEM_I(inode); | 796 | struct shmem_inode_info *info = SHMEM_I(inode); |
799 | spin_lock(&info->lock); | 797 | spin_lock(&info->lock); |
800 | info->flags &= ~SHMEM_PAGEIN; | 798 | info->flags &= ~SHMEM_PAGEIN; |
801 | spin_unlock(&info->lock); | 799 | spin_unlock(&info->lock); |
802 | } | 800 | } |
803 | } | 801 | } |
802 | |||
803 | error = simple_setsize(inode, newsize); | ||
804 | if (page) | ||
805 | page_cache_release(page); | ||
806 | if (error) | ||
807 | return error; | ||
808 | shmem_truncate_range(inode, newsize, (loff_t)-1); | ||
804 | } | 809 | } |
805 | 810 | ||
806 | error = inode_change_ok(inode, attr); | 811 | error = inode_change_ok(inode, attr); |
807 | if (!error) | 812 | if (!error) |
808 | error = inode_setattr(inode, attr); | 813 | generic_setattr(inode, attr); |
809 | #ifdef CONFIG_TMPFS_POSIX_ACL | 814 | #ifdef CONFIG_TMPFS_POSIX_ACL |
810 | if (!error && (attr->ia_valid & ATTR_MODE)) | 815 | if (!error && (attr->ia_valid & ATTR_MODE)) |
811 | error = generic_acl_chmod(inode); | 816 | error = generic_acl_chmod(inode); |
812 | #endif | 817 | #endif |
813 | if (page) | ||
814 | page_cache_release(page); | ||
815 | return error; | 818 | return error; |
816 | } | 819 | } |
817 | 820 | ||
@@ -819,11 +822,11 @@ static void shmem_delete_inode(struct inode *inode) | |||
819 | { | 822 | { |
820 | struct shmem_inode_info *info = SHMEM_I(inode); | 823 | struct shmem_inode_info *info = SHMEM_I(inode); |
821 | 824 | ||
822 | if (inode->i_op->truncate == shmem_truncate) { | 825 | if (inode->i_mapping->a_ops == &shmem_aops) { |
823 | truncate_inode_pages(inode->i_mapping, 0); | 826 | truncate_inode_pages(inode->i_mapping, 0); |
824 | shmem_unacct_size(info->flags, inode->i_size); | 827 | shmem_unacct_size(info->flags, inode->i_size); |
825 | inode->i_size = 0; | 828 | inode->i_size = 0; |
826 | shmem_truncate(inode); | 829 | shmem_truncate_range(inode, 0, (loff_t)-1); |
827 | if (!list_empty(&info->swaplist)) { | 830 | if (!list_empty(&info->swaplist)) { |
828 | mutex_lock(&shmem_swaplist_mutex); | 831 | mutex_lock(&shmem_swaplist_mutex); |
829 | list_del_init(&info->swaplist); | 832 | list_del_init(&info->swaplist); |
@@ -2022,7 +2025,6 @@ static const struct inode_operations shmem_symlink_inline_operations = { | |||
2022 | }; | 2025 | }; |
2023 | 2026 | ||
2024 | static const struct inode_operations shmem_symlink_inode_operations = { | 2027 | static const struct inode_operations shmem_symlink_inode_operations = { |
2025 | .truncate = shmem_truncate, | ||
2026 | .readlink = generic_readlink, | 2028 | .readlink = generic_readlink, |
2027 | .follow_link = shmem_follow_link, | 2029 | .follow_link = shmem_follow_link, |
2028 | .put_link = shmem_put_link, | 2030 | .put_link = shmem_put_link, |
@@ -2433,14 +2435,13 @@ static const struct file_operations shmem_file_operations = { | |||
2433 | .write = do_sync_write, | 2435 | .write = do_sync_write, |
2434 | .aio_read = shmem_file_aio_read, | 2436 | .aio_read = shmem_file_aio_read, |
2435 | .aio_write = generic_file_aio_write, | 2437 | .aio_write = generic_file_aio_write, |
2436 | .fsync = simple_sync_file, | 2438 | .fsync = noop_fsync, |
2437 | .splice_read = generic_file_splice_read, | 2439 | .splice_read = generic_file_splice_read, |
2438 | .splice_write = generic_file_splice_write, | 2440 | .splice_write = generic_file_splice_write, |
2439 | #endif | 2441 | #endif |
2440 | }; | 2442 | }; |
2441 | 2443 | ||
2442 | static const struct inode_operations shmem_inode_operations = { | 2444 | static const struct inode_operations shmem_inode_operations = { |
2443 | .truncate = shmem_truncate, | ||
2444 | .setattr = shmem_notify_change, | 2445 | .setattr = shmem_notify_change, |
2445 | .truncate_range = shmem_truncate_range, | 2446 | .truncate_range = shmem_truncate_range, |
2446 | #ifdef CONFIG_TMPFS_POSIX_ACL | 2447 | #ifdef CONFIG_TMPFS_POSIX_ACL |
diff --git a/mm/truncate.c b/mm/truncate.c index f42675a3615d..937571b8b233 100644 --- a/mm/truncate.c +++ b/mm/truncate.c | |||
@@ -548,18 +548,18 @@ EXPORT_SYMBOL(truncate_pagecache); | |||
548 | * NOTE! We have to be ready to update the memory sharing | 548 | * NOTE! We have to be ready to update the memory sharing |
549 | * between the file and the memory map for a potential last | 549 | * between the file and the memory map for a potential last |
550 | * incomplete page. Ugly, but necessary. | 550 | * incomplete page. Ugly, but necessary. |
551 | * | ||
552 | * This function is deprecated and simple_setsize or truncate_pagecache | ||
553 | * should be used instead. | ||
551 | */ | 554 | */ |
552 | int vmtruncate(struct inode *inode, loff_t offset) | 555 | int vmtruncate(struct inode *inode, loff_t offset) |
553 | { | 556 | { |
554 | loff_t oldsize; | ||
555 | int error; | 557 | int error; |
556 | 558 | ||
557 | error = inode_newsize_ok(inode, offset); | 559 | error = simple_setsize(inode, offset); |
558 | if (error) | 560 | if (error) |
559 | return error; | 561 | return error; |
560 | oldsize = inode->i_size; | 562 | |
561 | i_size_write(inode, offset); | ||
562 | truncate_pagecache(inode, oldsize, offset); | ||
563 | if (inode->i_op->truncate) | 563 | if (inode->i_op->truncate) |
564 | inode->i_op->truncate(inode); | 564 | inode->i_op->truncate(inode); |
565 | 565 | ||