Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers

Btrfs needs to be able to control how filemap_write_and_wait_range() is called
in fsync to make it less of a painful operation, so push down taking i_mutex and
the calling of filemap_write_and_wait() down into the ->fsync() handlers. Some
file systems can drop taking the i_mutex altogether it seems, like ext3 and
ocfs2. For correctness sake I just pushed everything down in all cases to make
sure that we keep the current behavior the same for everybody, and then each
individual fs maintainer can make up their mind about what to do from there.
Thanks,

Acked-by: Jan Kara <jack@suse.cz>
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Josef Bacik and committed by
Al Viro
02c24a82 22735068

+462 -164
+2 -4
Documentation/filesystems/Locking
··· 412 412 int (*open) (struct inode *, struct file *); 413 413 int (*flush) (struct file *); 414 414 int (*release) (struct inode *, struct file *); 415 - int (*fsync) (struct file *, int datasync); 415 + int (*fsync) (struct file *, loff_t start, loff_t end, int datasync); 416 416 int (*aio_fsync) (struct kiocb *, int datasync); 417 417 int (*fasync) (int, struct file *, int); 418 418 int (*lock) (struct file *, int, struct file_lock *); ··· 438 438 439 439 locking rules: 440 440 All may block except for ->setlease. 441 - No VFS locks held on entry except for ->fsync and ->setlease. 442 - 443 - ->fsync() has i_mutex on inode. 441 + No VFS locks held on entry except for ->setlease. 444 442 445 443 ->setlease has the file_list_lock held and must not sleep. 446 444
+7
Documentation/filesystems/porting
··· 421 421 offset is less than i_size and SEEK_DATA is specified, return the same offset. 422 422 If the above is true for the offset and you are given SEEK_HOLE, return the end 423 423 of the file. If the offset is i_size or greater return -ENXIO in either case. 424 + 425 + [mandatory] 426 + If you have your own ->fsync() you must make sure to call 427 + filemap_write_and_wait_range() so that all dirty pages are synced out properly. 428 + You must also keep in mind that ->fsync() is not called with i_mutex held 429 + anymore, so if you require i_mutex locking you must make sure to take it and 430 + release it yourself.
+1 -1
Documentation/filesystems/vfs.txt
··· 777 777 int (*open) (struct inode *, struct file *); 778 778 int (*flush) (struct file *); 779 779 int (*release) (struct inode *, struct file *); 780 - int (*fsync) (struct file *, int datasync); 780 + int (*fsync) (struct file *, loff_t, loff_t, int datasync); 781 781 int (*aio_fsync) (struct kiocb *, int datasync); 782 782 int (*fasync) (int, struct file *, int); 783 783 int (*lock) (struct file *, int, struct file_lock *);
+9 -2
arch/powerpc/platforms/cell/spufs/file.c
··· 1850 1850 return ret; 1851 1851 } 1852 1852 1853 - static int spufs_mfc_fsync(struct file *file, int datasync) 1853 + static int spufs_mfc_fsync(struct file *file, loff_t start, loff_t end, int datasync) 1854 1854 { 1855 - return spufs_mfc_flush(file, NULL); 1855 + struct inode *inode = file->f_path.dentry->d_inode; 1856 + int err = filemap_write_and_wait_range(inode->i_mapping, start, end); 1857 + if (!err) { 1858 + mutex_lock(&inode->i_mutex); 1859 + err = spufs_mfc_flush(file, NULL); 1860 + mutex_unlock(&inode->i_mutex); 1861 + } 1862 + return err; 1856 1863 } 1857 1864 1858 1865 static int spufs_mfc_fasync(int fd, struct file *file, int on)
+7 -2
drivers/char/ps3flash.c
··· 309 309 return ps3flash_writeback(ps3flash_dev); 310 310 } 311 311 312 - static int ps3flash_fsync(struct file *file, int datasync) 312 + static int ps3flash_fsync(struct file *file, loff_t start, loff_t end, int datasync) 313 313 { 314 - return ps3flash_writeback(ps3flash_dev); 314 + struct inode *inode = file->f_path.dentry->d_inode; 315 + int err; 316 + mutex_lock(&inode->i_mutex); 317 + err = ps3flash_writeback(ps3flash_dev); 318 + mutex_unlock(&inode->i_mutex); 319 + return err; 315 320 } 316 321 317 322 static irqreturn_t ps3flash_interrupt(int irq, void *data)
+7 -3
drivers/mtd/ubi/cdev.c
··· 189 189 return new_offset; 190 190 } 191 191 192 - static int vol_cdev_fsync(struct file *file, int datasync) 192 + static int vol_cdev_fsync(struct file *file, loff_t start, loff_t end, int datasync) 193 193 { 194 194 struct ubi_volume_desc *desc = file->private_data; 195 195 struct ubi_device *ubi = desc->vol->ubi; 196 - 197 - return ubi_sync(ubi->ubi_num); 196 + struct inode *inode = file->f_path.dentry->d_inode; 197 + int err; 198 + mutex_lock(&inode->i_mutex); 199 + err = ubi_sync(ubi->ubi_num); 200 + mutex_unlock(&inode->i_mutex); 201 + return err; 198 202 } 199 203 200 204
+8 -3
drivers/staging/pohmelfs/inode.c
··· 887 887 /* 888 888 * We want fsync() to work on POHMELFS. 889 889 */ 890 - static int pohmelfs_fsync(struct file *file, int datasync) 890 + static int pohmelfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 891 891 { 892 892 struct inode *inode = file->f_mapping->host; 893 - 894 - return sync_inode_metadata(inode, 1); 893 + int err = filemap_write_and_wait_range(inode->i_mapping, start, end); 894 + if (!err) { 895 + mutex_lock(&inode->i_mutex); 896 + err = sync_inode_metadata(inode, 1); 897 + mutex_unlock(&inode->i_mutex); 898 + } 899 + return err; 895 900 } 896 901 897 902 ssize_t pohmelfs_write(struct file *file, const char __user *buf,
+4 -1
drivers/usb/gadget/printer.c
··· 795 795 } 796 796 797 797 static int 798 - printer_fsync(struct file *fd, int datasync) 798 + printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) 799 799 { 800 800 struct printer_dev *dev = fd->private_data; 801 + struct inode *inode = fd->f_path.dentry->d_inode; 801 802 unsigned long flags; 802 803 int tx_list_empty; 803 804 805 + mutex_lock(&inode->i_mutex); 804 806 spin_lock_irqsave(&dev->lock, flags); 805 807 tx_list_empty = (likely(list_empty(&dev->tx_reqs))); 806 808 spin_unlock_irqrestore(&dev->lock, flags); ··· 812 810 wait_event_interruptible(dev->tx_flush_wait, 813 811 (likely(list_empty(&dev->tx_reqs_active)))); 814 812 } 813 + mutex_unlock(&inode->i_mutex); 815 814 816 815 return 0; 817 816 }
+9 -2
drivers/video/fb_defio.c
··· 66 66 return 0; 67 67 } 68 68 69 - int fb_deferred_io_fsync(struct file *file, int datasync) 69 + int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasync) 70 70 { 71 71 struct fb_info *info = file->private_data; 72 + struct inode *inode = file->f_path.dentry->d_inode; 73 + int err = filemap_write_and_wait_range(inode->i_mapping, start, end); 74 + if (err) 75 + return err; 72 76 73 77 /* Skip if deferred io is compiled-in but disabled on this fbdev */ 74 78 if (!info->fbdefio) 75 79 return 0; 76 80 81 + mutex_lock(&inode->i_mutex); 77 82 /* Kill off the delayed work */ 78 83 cancel_delayed_work_sync(&info->deferred_work); 79 84 80 85 /* Run it immediately */ 81 - return schedule_delayed_work(&info->deferred_work, 0); 86 + err = schedule_delayed_work(&info->deferred_work, 0); 87 + mutex_unlock(&inode->i_mutex); 88 + return err; 82 89 } 83 90 EXPORT_SYMBOL_GPL(fb_deferred_io_fsync); 84 91
+2 -1
fs/9p/v9fs_vfs.h
··· 70 70 ssize_t v9fs_fid_readn(struct p9_fid *, char *, char __user *, u32, u64); 71 71 void v9fs_blank_wstat(struct p9_wstat *wstat); 72 72 int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *); 73 - int v9fs_file_fsync_dotl(struct file *filp, int datasync); 73 + int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end, 74 + int datasync); 74 75 ssize_t v9fs_file_write_internal(struct inode *, struct p9_fid *, 75 76 const char __user *, size_t, loff_t *, int); 76 77 int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode);
+20 -2
fs/9p/vfs_file.c
··· 519 519 } 520 520 521 521 522 - static int v9fs_file_fsync(struct file *filp, int datasync) 522 + static int v9fs_file_fsync(struct file *filp, loff_t start, loff_t end, 523 + int datasync) 523 524 { 524 525 struct p9_fid *fid; 526 + struct inode *inode = filp->f_mapping->host; 525 527 struct p9_wstat wstat; 526 528 int retval; 527 529 530 + retval = filemap_write_and_wait_range(inode->i_mapping, start, end); 531 + if (retval) 532 + return retval; 533 + 534 + mutex_lock(&inode->i_mutex); 528 535 P9_DPRINTK(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync); 529 536 530 537 fid = filp->private_data; 531 538 v9fs_blank_wstat(&wstat); 532 539 533 540 retval = p9_client_wstat(fid, &wstat); 541 + mutex_unlock(&inode->i_mutex); 542 + 534 543 return retval; 535 544 } 536 545 537 - int v9fs_file_fsync_dotl(struct file *filp, int datasync) 546 + int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end, 547 + int datasync) 538 548 { 539 549 struct p9_fid *fid; 550 + struct inode *inode = filp->f_mapping->host; 540 551 int retval; 541 552 553 + retval = filemap_write_and_wait_range(inode->i_mapping, start, end); 554 + if (retval) 555 + return retval; 556 + 557 + mutex_lock(&inode->i_mutex); 542 558 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_file_fsync_dotl: filp %p datasync %x\n", 543 559 filp, datasync); 544 560 545 561 fid = filp->private_data; 546 562 547 563 retval = p9_client_fsync(fid, datasync); 564 + mutex_unlock(&inode->i_mutex); 565 + 548 566 return retval; 549 567 } 550 568
+1 -1
fs/affs/affs.h
··· 182 182 183 183 void affs_free_prealloc(struct inode *inode); 184 184 extern void affs_truncate(struct inode *); 185 - int affs_file_fsync(struct file *, int); 185 + int affs_file_fsync(struct file *, loff_t, loff_t, int); 186 186 187 187 /* dir.c */ 188 188
+7 -1
fs/affs/file.c
··· 923 923 affs_free_prealloc(inode); 924 924 } 925 925 926 - int affs_file_fsync(struct file *filp, int datasync) 926 + int affs_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) 927 927 { 928 928 struct inode *inode = filp->f_mapping->host; 929 929 int ret, err; 930 930 931 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 932 + if (err) 933 + return err; 934 + 935 + mutex_lock(&inode->i_mutex); 931 936 ret = write_inode_now(inode, 0); 932 937 err = sync_blockdev(inode->i_sb->s_bdev); 933 938 if (!ret) 934 939 ret = err; 940 + mutex_unlock(&inode->i_mutex); 935 941 return ret; 936 942 }
+1 -1
fs/afs/internal.h
··· 750 750 extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, 751 751 unsigned long, loff_t); 752 752 extern int afs_writeback_all(struct afs_vnode *); 753 - extern int afs_fsync(struct file *, int); 753 + extern int afs_fsync(struct file *, loff_t, loff_t, int); 754 754 755 755 756 756 /*****************************************************************************/
+14 -4
fs/afs/write.c
··· 681 681 * - the return status from this call provides a reliable indication of 682 682 * whether any write errors occurred for this process. 683 683 */ 684 - int afs_fsync(struct file *file, int datasync) 684 + int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 685 685 { 686 686 struct dentry *dentry = file->f_path.dentry; 687 + struct inode *inode = file->f_mapping->host; 687 688 struct afs_writeback *wb, *xwb; 688 689 struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); 689 690 int ret; ··· 693 692 vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name, 694 693 datasync); 695 694 695 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 696 + if (ret) 697 + return ret; 698 + mutex_lock(&inode->i_mutex); 699 + 696 700 /* use a writeback record as a marker in the queue - when this reaches 697 701 * the front of the queue, all the outstanding writes are either 698 702 * completed or rejected */ 699 703 wb = kzalloc(sizeof(*wb), GFP_KERNEL); 700 - if (!wb) 701 - return -ENOMEM; 704 + if (!wb) { 705 + ret = -ENOMEM; 706 + goto out; 707 + } 702 708 wb->vnode = vnode; 703 709 wb->first = 0; 704 710 wb->last = -1; ··· 728 720 if (ret < 0) { 729 721 afs_put_writeback(wb); 730 722 _leave(" = %d [wb]", ret); 731 - return ret; 723 + goto out; 732 724 } 733 725 734 726 /* wait for the preceding writes to actually complete */ ··· 737 729 vnode->writebacks.next == &wb->link); 738 730 afs_put_writeback(wb); 739 731 _leave(" = %d", ret); 732 + out: 733 + mutex_unlock(&inode->i_mutex); 740 734 return ret; 741 735 } 742 736
+2 -1
fs/bad_inode.c
··· 87 87 return -EIO; 88 88 } 89 89 90 - static int bad_file_fsync(struct file *file, int datasync) 90 + static int bad_file_fsync(struct file *file, loff_t start, loff_t end, 91 + int datasync) 91 92 { 92 93 return -EIO; 93 94 }
+1 -5
fs/block_dev.c
··· 378 378 return retval; 379 379 } 380 380 381 - int blkdev_fsync(struct file *filp, int datasync) 381 + int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync) 382 382 { 383 383 struct inode *bd_inode = filp->f_mapping->host; 384 384 struct block_device *bdev = I_BDEV(bd_inode); ··· 389 389 * i_mutex and doing so causes performance issues with concurrent 390 390 * O_SYNC writers to a block device. 391 391 */ 392 - mutex_unlock(&bd_inode->i_mutex); 393 - 394 392 error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL); 395 393 if (error == -EOPNOTSUPP) 396 394 error = 0; 397 - 398 - mutex_lock(&bd_inode->i_mutex); 399 395 400 396 return error; 401 397 }
+1 -1
fs/btrfs/ctree.h
··· 2605 2605 int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, 2606 2606 struct inode *inode); 2607 2607 int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); 2608 - int btrfs_sync_file(struct file *file, int datasync); 2608 + int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2609 2609 int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, 2610 2610 int skip_pinned); 2611 2611 extern const struct file_operations btrfs_file_operations;
+15 -6
fs/btrfs/file.c
··· 1452 1452 * important optimization for directories because holding the mutex prevents 1453 1453 * new operations on the dir while we write to disk. 1454 1454 */ 1455 - int btrfs_sync_file(struct file *file, int datasync) 1455 + int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 1456 1456 { 1457 1457 struct dentry *dentry = file->f_path.dentry; 1458 1458 struct inode *inode = dentry->d_inode; ··· 1462 1462 1463 1463 trace_btrfs_sync_file(file, datasync); 1464 1464 1465 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 1466 + if (ret) 1467 + return ret; 1468 + mutex_lock(&inode->i_mutex); 1469 + 1465 1470 /* we wait first, since the writeback may change the inode */ 1466 1471 root->log_batch++; 1467 - /* the VFS called filemap_fdatawrite for us */ 1468 1472 btrfs_wait_ordered_range(inode, 0, (u64)-1); 1469 1473 root->log_batch++; 1470 1474 ··· 1476 1472 * check the transaction that last modified this inode 1477 1473 * and see if its already been committed 1478 1474 */ 1479 - if (!BTRFS_I(inode)->last_trans) 1475 + if (!BTRFS_I(inode)->last_trans) { 1476 + mutex_unlock(&inode->i_mutex); 1480 1477 goto out; 1478 + } 1481 1479 1482 1480 /* 1483 1481 * if the last transaction that changed this file was before ··· 1490 1484 if (BTRFS_I(inode)->last_trans <= 1491 1485 root->fs_info->last_trans_committed) { 1492 1486 BTRFS_I(inode)->last_trans = 0; 1487 + mutex_unlock(&inode->i_mutex); 1493 1488 goto out; 1494 1489 } 1495 1490 ··· 1503 1496 trans = btrfs_start_transaction(root, 0); 1504 1497 if (IS_ERR(trans)) { 1505 1498 ret = PTR_ERR(trans); 1499 + mutex_unlock(&inode->i_mutex); 1506 1500 goto out; 1507 1501 } 1508 1502 1509 1503 ret = btrfs_log_dentry_safe(trans, root, dentry); 1510 - if (ret < 0) 1504 + if (ret < 0) { 1505 + mutex_unlock(&inode->i_mutex); 1511 1506 goto out; 1507 + } 1512 1508 1513 1509 /* we've logged all the items and now have a consistent 1514 1510 * version of the file in the log. It is possible that ··· 1523 1513 * file again, but that will end up using the synchronization 1524 1514 * inside btrfs_sync_log to keep things safe. 1525 1515 */ 1526 - mutex_unlock(&dentry->d_inode->i_mutex); 1516 + mutex_unlock(&inode->i_mutex); 1527 1517 1528 1518 if (ret != BTRFS_NO_LOG_SYNC) { 1529 1519 if (ret > 0) { ··· 1538 1528 } else { 1539 1529 ret = btrfs_end_transaction(trans, root); 1540 1530 } 1541 - mutex_lock(&dentry->d_inode->i_mutex); 1542 1531 out: 1543 1532 return ret > 0 ? -EIO : ret; 1544 1533 }
+4 -2
fs/ceph/caps.c
··· 1811 1811 spin_unlock(&ci->i_unsafe_lock); 1812 1812 } 1813 1813 1814 - int ceph_fsync(struct file *file, int datasync) 1814 + int ceph_fsync(struct file *file, loff_t start, loff_t end, int datasync) 1815 1815 { 1816 1816 struct inode *inode = file->f_mapping->host; 1817 1817 struct ceph_inode_info *ci = ceph_inode(inode); ··· 1822 1822 dout("fsync %p%s\n", inode, datasync ? " datasync" : ""); 1823 1823 sync_write_wait(inode); 1824 1824 1825 - ret = filemap_write_and_wait(inode->i_mapping); 1825 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 1826 1826 if (ret < 0) 1827 1827 return ret; 1828 + mutex_lock(&inode->i_mutex); 1828 1829 1829 1830 dirty = try_flush_caps(inode, NULL, &flush_tid); 1830 1831 dout("fsync dirty caps are %s\n", ceph_cap_string(dirty)); ··· 1842 1841 } 1843 1842 1844 1843 dout("fsync %p%s done\n", inode, datasync ? " datasync" : ""); 1844 + mutex_unlock(&inode->i_mutex); 1845 1845 return ret; 1846 1846 } 1847 1847
+9 -1
fs/ceph/dir.c
··· 1118 1118 * an fsync() on a dir will wait for any uncommitted directory 1119 1119 * operations to commit. 1120 1120 */ 1121 - static int ceph_dir_fsync(struct file *file, int datasync) 1121 + static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end, 1122 + int datasync) 1122 1123 { 1123 1124 struct inode *inode = file->f_path.dentry->d_inode; 1124 1125 struct ceph_inode_info *ci = ceph_inode(inode); ··· 1129 1128 int ret = 0; 1130 1129 1131 1130 dout("dir_fsync %p\n", inode); 1131 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 1132 + if (ret) 1133 + return ret; 1134 + mutex_lock(&inode->i_mutex); 1135 + 1132 1136 spin_lock(&ci->i_unsafe_lock); 1133 1137 if (list_empty(head)) 1134 1138 goto out; ··· 1167 1161 } while (req->r_tid < last_tid); 1168 1162 out: 1169 1163 spin_unlock(&ci->i_unsafe_lock); 1164 + mutex_unlock(&inode->i_mutex); 1165 + 1170 1166 return ret; 1171 1167 } 1172 1168
+2 -1
fs/ceph/super.h
··· 728 728 729 729 extern void ceph_queue_caps_release(struct inode *inode); 730 730 extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc); 731 - extern int ceph_fsync(struct file *file, int datasync); 731 + extern int ceph_fsync(struct file *file, loff_t start, loff_t end, 732 + int datasync); 732 733 extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc, 733 734 struct ceph_mds_session *session); 734 735 extern struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci,
+2 -2
fs/cifs/cifsfs.h
··· 91 91 extern ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, 92 92 unsigned long nr_segs, loff_t pos); 93 93 extern int cifs_lock(struct file *, int, struct file_lock *); 94 - extern int cifs_fsync(struct file *, int); 95 - extern int cifs_strict_fsync(struct file *, int); 94 + extern int cifs_fsync(struct file *, loff_t, loff_t, int); 95 + extern int cifs_strict_fsync(struct file *, loff_t, loff_t, int); 96 96 extern int cifs_flush(struct file *, fl_owner_t id); 97 97 extern int cifs_file_mmap(struct file * , struct vm_area_struct *); 98 98 extern int cifs_file_strict_mmap(struct file * , struct vm_area_struct *);
+16 -2
fs/cifs/file.c
··· 1401 1401 return rc; 1402 1402 } 1403 1403 1404 - int cifs_strict_fsync(struct file *file, int datasync) 1404 + int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, 1405 + int datasync) 1405 1406 { 1406 1407 int xid; 1407 1408 int rc = 0; ··· 1410 1409 struct cifsFileInfo *smbfile = file->private_data; 1411 1410 struct inode *inode = file->f_path.dentry->d_inode; 1412 1411 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1412 + 1413 + rc = filemap_write_and_wait_range(inode->i_mapping, start, end); 1414 + if (rc) 1415 + return rc; 1416 + mutex_lock(&inode->i_mutex); 1413 1417 1414 1418 xid = GetXid(); 1415 1419 ··· 1434 1428 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); 1435 1429 1436 1430 FreeXid(xid); 1431 + mutex_unlock(&inode->i_mutex); 1437 1432 return rc; 1438 1433 } 1439 1434 1440 - int cifs_fsync(struct file *file, int datasync) 1435 + int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 1441 1436 { 1442 1437 int xid; 1443 1438 int rc = 0; 1444 1439 struct cifs_tcon *tcon; 1445 1440 struct cifsFileInfo *smbfile = file->private_data; 1446 1441 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1442 + struct inode *inode = file->f_mapping->host; 1443 + 1444 + rc = filemap_write_and_wait_range(inode->i_mapping, start, end); 1445 + if (rc) 1446 + return rc; 1447 + mutex_lock(&inode->i_mutex); 1447 1448 1448 1449 xid = GetXid(); 1449 1450 ··· 1462 1449 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); 1463 1450 1464 1451 FreeXid(xid); 1452 + mutex_unlock(&inode->i_mutex); 1465 1453 return rc; 1466 1454 } 1467 1455
+1 -1
fs/coda/coda_int.h
··· 11 11 12 12 void coda_destroy_inodecache(void); 13 13 int coda_init_inodecache(void); 14 - int coda_fsync(struct file *coda_file, int datasync); 14 + int coda_fsync(struct file *coda_file, loff_t start, loff_t end, int datasync); 15 15 void coda_sysctl_init(void); 16 16 void coda_sysctl_clean(void); 17 17
+7 -1
fs/coda/file.c
··· 199 199 return 0; 200 200 } 201 201 202 - int coda_fsync(struct file *coda_file, int datasync) 202 + int coda_fsync(struct file *coda_file, loff_t start, loff_t end, int datasync) 203 203 { 204 204 struct file *host_file; 205 205 struct inode *coda_inode = coda_file->f_path.dentry->d_inode; ··· 210 210 S_ISLNK(coda_inode->i_mode))) 211 211 return -EINVAL; 212 212 213 + err = filemap_write_and_wait_range(coda_inode->i_mapping, start, end); 214 + if (err) 215 + return err; 216 + mutex_lock(&coda_inode->i_mutex); 217 + 213 218 cfi = CODA_FTOC(coda_file); 214 219 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 215 220 host_file = cfi->cfi_container; ··· 222 217 err = vfs_fsync(host_file, datasync); 223 218 if (!err && !datasync) 224 219 err = venus_fsync(coda_inode->i_sb, coda_i2f(coda_inode)); 220 + mutex_unlock(&coda_inode->i_mutex); 225 221 226 222 return err; 227 223 }
+4 -3
fs/ecryptfs/file.c
··· 270 270 } 271 271 272 272 static int 273 - ecryptfs_fsync(struct file *file, int datasync) 273 + ecryptfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 274 274 { 275 275 int rc = 0; 276 276 277 - rc = generic_file_fsync(file, datasync); 277 + rc = generic_file_fsync(file, start, end, datasync); 278 278 if (rc) 279 279 goto out; 280 - rc = vfs_fsync(ecryptfs_file_to_lower(file), datasync); 280 + rc = vfs_fsync_range(ecryptfs_file_to_lower(file), start, end, 281 + datasync); 281 282 out: 282 283 return rc; 283 284 }
+9 -1
fs/exofs/file.c
··· 42 42 * Note, in exofs all metadata is written as part of inode, regardless. 43 43 * The writeout is synchronous 44 44 */ 45 - static int exofs_file_fsync(struct file *filp, int datasync) 45 + static int exofs_file_fsync(struct file *filp, loff_t start, loff_t end, 46 + int datasync) 46 47 { 48 + struct inode *inode = filp->f_mapping->host; 47 49 int ret; 48 50 51 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 52 + if (ret) 53 + return ret; 54 + 55 + mutex_lock(&inode->i_mutex); 49 56 ret = sync_inode_metadata(filp->f_mapping->host, 1); 57 + mutex_unlock(&inode->i_mutex); 50 58 return ret; 51 59 } 52 60
+2 -1
fs/ext2/ext2.h
··· 150 150 extern const struct file_operations ext2_dir_operations; 151 151 152 152 /* file.c */ 153 - extern int ext2_fsync(struct file *file, int datasync); 153 + extern int ext2_fsync(struct file *file, loff_t start, loff_t end, 154 + int datasync); 154 155 extern const struct inode_operations ext2_file_inode_operations; 155 156 extern const struct file_operations ext2_file_operations; 156 157 extern const struct file_operations ext2_xip_file_operations;
+2 -2
fs/ext2/file.c
··· 40 40 return 0; 41 41 } 42 42 43 - int ext2_fsync(struct file *file, int datasync) 43 + int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync) 44 44 { 45 45 int ret; 46 46 struct super_block *sb = file->f_mapping->host->i_sb; 47 47 struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; 48 48 49 - ret = generic_file_fsync(file, datasync); 49 + ret = generic_file_fsync(file, start, end, datasync); 50 50 if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) { 51 51 /* We don't really know where the IO error happened... */ 52 52 ext2_error(sb, __func__,
+16 -2
fs/ext3/fsync.c
··· 43 43 * inode to disk. 44 44 */ 45 45 46 - int ext3_sync_file(struct file *file, int datasync) 46 + int ext3_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 47 47 { 48 48 struct inode *inode = file->f_mapping->host; 49 49 struct ext3_inode_info *ei = EXT3_I(inode); ··· 53 53 54 54 if (inode->i_sb->s_flags & MS_RDONLY) 55 55 return 0; 56 + 57 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 58 + if (ret) 59 + return ret; 60 + 61 + /* 62 + * Taking the mutex here just to keep consistent with how fsync was 63 + * called previously, however it looks like we don't need to take 64 + * i_mutex at all. 65 + */ 66 + mutex_lock(&inode->i_mutex); 56 67 57 68 J_ASSERT(ext3_journal_current_handle() == NULL); 58 69 ··· 81 70 * (they were dirtied by commit). But that's OK - the blocks are 82 71 * safe in-journal, which is all fsync() needs to ensure. 83 72 */ 84 - if (ext3_should_journal_data(inode)) 73 + if (ext3_should_journal_data(inode)) { 74 + mutex_unlock(&inode->i_mutex); 85 75 return ext3_force_commit(inode->i_sb); 76 + } 86 77 87 78 if (datasync) 88 79 commit_tid = atomic_read(&ei->i_datasync_tid); ··· 104 91 */ 105 92 if (needs_barrier) 106 93 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 94 + mutex_unlock(&inode->i_mutex); 107 95 return ret; 108 96 }
+1 -1
fs/ext4/ext4.h
··· 1758 1758 extern void ext4_htree_free_dir_info(struct dir_private_info *p); 1759 1759 1760 1760 /* fsync.c */ 1761 - extern int ext4_sync_file(struct file *, int); 1761 + extern int ext4_sync_file(struct file *, loff_t, loff_t, int); 1762 1762 extern int ext4_flush_completed_IO(struct inode *); 1763 1763 1764 1764 /* hash.c */
+35 -3
fs/ext4/fsync.c
··· 151 151 return ret; 152 152 } 153 153 154 + /** 155 + * __sync_file - generic_file_fsync without the locking and filemap_write 156 + * @inode: inode to sync 157 + * @datasync: only sync essential metadata if true 158 + * 159 + * This is just generic_file_fsync without the locking. This is needed for 160 + * nojournal mode to make sure this inodes data/metadata makes it to disk 161 + * properly. The i_mutex should be held already. 162 + */ 163 + static int __sync_inode(struct inode *inode, int datasync) 164 + { 165 + int err; 166 + int ret; 167 + 168 + ret = sync_mapping_buffers(inode->i_mapping); 169 + if (!(inode->i_state & I_DIRTY)) 170 + return ret; 171 + if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) 172 + return ret; 173 + 174 + err = sync_inode_metadata(inode, 1); 175 + if (ret == 0) 176 + ret = err; 177 + return ret; 178 + } 179 + 154 180 /* 155 181 * akpm: A new design for ext4_sync_file(). 156 182 * ··· 191 165 * i_mutex lock is held when entering and exiting this function 192 166 */ 193 167 194 - int ext4_sync_file(struct file *file, int datasync) 168 + int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 195 169 { 196 170 struct inode *inode = file->f_mapping->host; 197 171 struct ext4_inode_info *ei = EXT4_I(inode); ··· 204 178 205 179 trace_ext4_sync_file_enter(file, datasync); 206 180 181 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 182 + if (ret) 183 + return ret; 184 + mutex_lock(&inode->i_mutex); 185 + 207 186 if (inode->i_sb->s_flags & MS_RDONLY) 208 - return 0; 187 + goto out; 209 188 210 189 ret = ext4_flush_completed_IO(inode); 211 190 if (ret < 0) 212 191 goto out; 213 192 214 193 if (!journal) { 215 - ret = generic_file_fsync(file, datasync); 194 + ret = __sync_inode(inode, datasync); 216 195 if (!ret && !list_empty(&inode->i_dentry)) 217 196 ret = ext4_sync_parent(inode); 218 197 goto out; ··· 251 220 if (needs_barrier) 252 221 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 253 222 out: 223 + mutex_unlock(&inode->i_mutex); 254 224 trace_ext4_sync_file_exit(inode, ret); 255 225 return ret; 256 226 }
+2 -1
fs/fat/fat.h
··· 310 310 extern void fat_truncate_blocks(struct inode *inode, loff_t offset); 311 311 extern int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, 312 312 struct kstat *stat); 313 - extern int fat_file_fsync(struct file *file, int datasync); 313 + extern int fat_file_fsync(struct file *file, loff_t start, loff_t end, 314 + int datasync); 314 315 315 316 /* fat/inode.c */ 316 317 extern void fat_attach(struct inode *inode, loff_t i_pos);
+2 -2
fs/fat/file.c
··· 149 149 return 0; 150 150 } 151 151 152 - int fat_file_fsync(struct file *filp, int datasync) 152 + int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) 153 153 { 154 154 struct inode *inode = filp->f_mapping->host; 155 155 int res, err; 156 156 157 - res = generic_file_fsync(filp, datasync); 157 + res = generic_file_fsync(filp, start, end, datasync); 158 158 err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping); 159 159 160 160 return res ? res : err;
+3 -2
fs/fuse/dir.c
··· 1176 1176 return 0; 1177 1177 } 1178 1178 1179 - static int fuse_dir_fsync(struct file *file, int datasync) 1179 + static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end, 1180 + int datasync) 1180 1181 { 1181 - return fuse_fsync_common(file, datasync, 1); 1182 + return fuse_fsync_common(file, start, end, datasync, 1); 1182 1183 } 1183 1184 1184 1185 static bool update_mtime(unsigned ivalid)
+18 -6
fs/fuse/file.c
··· 400 400 fuse_release_nowrite(inode); 401 401 } 402 402 403 - int fuse_fsync_common(struct file *file, int datasync, int isdir) 403 + int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 404 + int datasync, int isdir) 404 405 { 405 406 struct inode *inode = file->f_mapping->host; 406 407 struct fuse_conn *fc = get_fuse_conn(inode); ··· 413 412 if (is_bad_inode(inode)) 414 413 return -EIO; 415 414 415 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 416 + if (err) 417 + return err; 418 + 416 419 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir)) 417 420 return 0; 421 + 422 + mutex_lock(&inode->i_mutex); 418 423 419 424 /* 420 425 * Start writeback against all dirty pages of the inode, then ··· 429 422 */ 430 423 err = write_inode_now(inode, 0); 431 424 if (err) 432 - return err; 425 + goto out; 433 426 434 427 fuse_sync_writes(inode); 435 428 436 429 req = fuse_get_req(fc); 437 - if (IS_ERR(req)) 438 - return PTR_ERR(req); 430 + if (IS_ERR(req)) { 431 + err = PTR_ERR(req); 432 + goto out; 433 + } 439 434 440 435 memset(&inarg, 0, sizeof(inarg)); 441 436 inarg.fh = ff->fh; ··· 457 448 fc->no_fsync = 1; 458 449 err = 0; 459 450 } 451 + out: 452 + mutex_unlock(&inode->i_mutex); 460 453 return err; 461 454 } 462 455 463 - static int fuse_fsync(struct file *file, int datasync) 456 + static int fuse_fsync(struct file *file, loff_t start, loff_t end, 457 + int datasync) 464 458 { 465 - return fuse_fsync_common(file, datasync, 0); 459 + return fuse_fsync_common(file, start, end, datasync, 0); 466 460 } 467 461 468 462 void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos,
+2 -1
fs/fuse/fuse_i.h
··· 589 589 /** 590 590 * Send FSYNC or FSYNCDIR request 591 591 */ 592 - int fuse_fsync_common(struct file *file, int datasync, int isdir); 592 + int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 593 + int datasync, int isdir); 593 594 594 595 /** 595 596 * Notify poll wakeup
+14 -3
fs/gfs2/file.c
··· 544 544 545 545 /** 546 546 * gfs2_fsync - sync the dirty data for a file (across the cluster) 547 - * @file: the file that points to the dentry (we ignore this) 547 + * @file: the file that points to the dentry 548 + * @start: the start position in the file to sync 549 + * @end: the end position in the file to sync 548 550 * @datasync: set if we can ignore timestamp changes 549 551 * 550 552 * The VFS will flush data for us. We only need to worry ··· 555 553 * Returns: errno 556 554 */ 557 555 558 - static int gfs2_fsync(struct file *file, int datasync) 556 + static int gfs2_fsync(struct file *file, loff_t start, loff_t end, 557 + int datasync) 559 558 { 560 559 struct inode *inode = file->f_mapping->host; 561 560 int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); 562 561 struct gfs2_inode *ip = GFS2_I(inode); 563 562 int ret; 564 563 564 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 565 + if (ret) 566 + return ret; 567 + mutex_lock(&inode->i_mutex); 568 + 565 569 if (datasync) 566 570 sync_state &= ~I_DIRTY_SYNC; 567 571 568 572 if (sync_state) { 569 573 ret = sync_inode_metadata(inode, 1); 570 - if (ret) 574 + if (ret) { 575 + mutex_unlock(&inode->i_mutex); 571 576 return ret; 577 + } 572 578 gfs2_ail_flush(ip->i_gl); 573 579 } 574 580 581 + mutex_unlock(&inode->i_mutex); 575 582 return 0; 576 583 } 577 584
+8 -1
fs/hfs/inode.c
··· 627 627 return 0; 628 628 } 629 629 630 - static int hfs_file_fsync(struct file *filp, int datasync) 630 + static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, 631 + int datasync) 631 632 { 632 633 struct inode *inode = filp->f_mapping->host; 633 634 struct super_block * sb; 634 635 int ret, err; 636 + 637 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 638 + if (ret) 639 + return ret; 640 + mutex_lock(&inode->i_mutex); 635 641 636 642 /* sync the inode to buffers */ 637 643 ret = write_inode_now(inode, 0); ··· 655 649 err = sync_blockdev(sb->s_bdev); 656 650 if (!ret) 657 651 ret = err; 652 + mutex_unlock(&inode->i_mutex); 658 653 return ret; 659 654 } 660 655
+2 -1
fs/hfsplus/hfsplus_fs.h
··· 392 392 int hfsplus_cat_write_inode(struct inode *); 393 393 struct inode *hfsplus_new_inode(struct super_block *, int); 394 394 void hfsplus_delete_inode(struct inode *); 395 - int hfsplus_file_fsync(struct file *file, int datasync); 395 + int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, 396 + int datasync); 396 397 397 398 /* ioctl.c */ 398 399 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
+9 -1
fs/hfsplus/inode.c
··· 308 308 return 0; 309 309 } 310 310 311 - int hfsplus_file_fsync(struct file *file, int datasync) 311 + int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, 312 + int datasync) 312 313 { 313 314 struct inode *inode = file->f_mapping->host; 314 315 struct hfsplus_inode_info *hip = HFSPLUS_I(inode); 315 316 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb); 316 317 int error = 0, error2; 318 + 319 + error = filemap_write_and_wait_range(inode->i_mapping, start, end); 320 + if (error) 321 + return error; 322 + mutex_lock(&inode->i_mutex); 317 323 318 324 /* 319 325 * Sync inode metadata into the catalog and extent trees. ··· 347 341 348 342 if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags)) 349 343 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 344 + 345 + mutex_unlock(&inode->i_mutex); 350 346 351 347 return error; 352 348 }
+13 -2
fs/hostfs/hostfs_kern.c
··· 362 362 return 0; 363 363 } 364 364 365 - int hostfs_fsync(struct file *file, int datasync) 365 + int hostfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 366 366 { 367 - return fsync_file(HOSTFS_I(file->f_mapping->host)->fd, datasync); 367 + struct inode *inode = file->f_mapping->host; 368 + int ret; 369 + 370 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 371 + if (ret) 372 + return ret; 373 + 374 + mutex_lock(&inode->i_mutex); 375 + ret = fsync_file(HOSTFS_I(inode)->fd, datasync); 376 + mutex_unlock(&inode->i_mutex); 377 + 378 + return ret; 368 379 } 369 380 370 381 static const struct file_operations hostfs_file_fops = {
+6 -1
fs/hpfs/file.c
··· 18 18 return 0; 19 19 } 20 20 21 - int hpfs_file_fsync(struct file *file, int datasync) 21 + int hpfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) 22 22 { 23 23 struct inode *inode = file->f_mapping->host; 24 + int ret; 25 + 26 + ret = filemap_write_and_wait_range(file->f_mapping, start, end); 27 + if (ret) 28 + return ret; 24 29 return sync_blockdev(inode->i_sb->s_bdev); 25 30 } 26 31
+1 -1
fs/hpfs/hpfs_fn.h
··· 258 258 259 259 /* file.c */ 260 260 261 - int hpfs_file_fsync(struct file *, int); 261 + int hpfs_file_fsync(struct file *, loff_t, loff_t, int); 262 262 extern const struct file_operations hpfs_file_ops; 263 263 extern const struct inode_operations hpfs_file_iops; 264 264 extern const struct address_space_operations hpfs_aops;
+3 -2
fs/hppfs/hppfs.c
··· 573 573 return err; 574 574 } 575 575 576 - static int hppfs_fsync(struct file *file, int datasync) 576 + static int hppfs_fsync(struct file *file, loff_t start, loff_t end, 577 + int datasync) 577 578 { 578 - return 0; 579 + return filemap_write_and_wait_range(file->f_mapping, start, end); 579 580 } 580 581 581 582 static const struct file_operations hppfs_dir_fops = {
+8 -1
fs/jffs2/file.c
··· 27 27 struct page **pagep, void **fsdata); 28 28 static int jffs2_readpage (struct file *filp, struct page *pg); 29 29 30 - int jffs2_fsync(struct file *filp, int datasync) 30 + int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync) 31 31 { 32 32 struct inode *inode = filp->f_mapping->host; 33 33 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); 34 + int ret; 34 35 36 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 37 + if (ret) 38 + return ret; 39 + 40 + mutex_lock(&inode->i_mutex); 35 41 /* Trigger GC to flush any pending writes for this inode */ 36 42 jffs2_flush_wbuf_gc(c, inode->i_ino); 43 + mutex_unlock(&inode->i_mutex); 37 44 38 45 return 0; 39 46 }
+1 -1
fs/jffs2/os-linux.h
··· 158 158 extern const struct file_operations jffs2_file_operations; 159 159 extern const struct inode_operations jffs2_file_inode_operations; 160 160 extern const struct address_space_operations jffs2_file_address_operations; 161 - int jffs2_fsync(struct file *, int); 161 + int jffs2_fsync(struct file *, loff_t, loff_t, int); 162 162 int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg); 163 163 164 164 /* ioctl.c */
+8 -1
fs/jfs/file.c
··· 28 28 #include "jfs_acl.h" 29 29 #include "jfs_debug.h" 30 30 31 - int jfs_fsync(struct file *file, int datasync) 31 + int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 32 32 { 33 33 struct inode *inode = file->f_mapping->host; 34 34 int rc = 0; 35 35 36 + rc = filemap_write_and_wait_range(inode->i_mapping, start, end); 37 + if (rc) 38 + return rc; 39 + 40 + mutex_lock(&inode->i_mutex); 36 41 if (!(inode->i_state & I_DIRTY) || 37 42 (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) { 38 43 /* Make sure committed changes hit the disk */ 39 44 jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1); 45 + mutex_unlock(&inode->i_mutex); 40 46 return rc; 41 47 } 42 48 43 49 rc |= jfs_commit_inode(inode, 1); 50 + mutex_unlock(&inode->i_mutex); 44 51 45 52 return rc ? -EIO : 0; 46 53 }
+1 -1
fs/jfs/jfs_inode.h
··· 21 21 struct fid; 22 22 23 23 extern struct inode *ialloc(struct inode *, umode_t); 24 - extern int jfs_fsync(struct file *, int); 24 + extern int jfs_fsync(struct file *, loff_t, loff_t, int); 25 25 extern long jfs_ioctl(struct file *, unsigned int, unsigned long); 26 26 extern long jfs_compat_ioctl(struct file *, unsigned int, unsigned long); 27 27 extern struct inode *jfs_iget(struct super_block *, unsigned long);
+12 -4
fs/libfs.c
··· 905 905 * filesystems which track all non-inode metadata in the buffers list 906 906 * hanging off the address_space structure. 907 907 */ 908 - int generic_file_fsync(struct file *file, int datasync) 908 + int generic_file_fsync(struct file *file, loff_t start, loff_t end, 909 + int datasync) 909 910 { 910 911 struct inode *inode = file->f_mapping->host; 911 912 int err; 912 913 int ret; 913 914 915 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 916 + if (err) 917 + return err; 918 + 919 + mutex_lock(&inode->i_mutex); 914 920 ret = sync_mapping_buffers(inode->i_mapping); 915 921 if (!(inode->i_state & I_DIRTY)) 916 - return ret; 922 + goto out; 917 923 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) 918 - return ret; 924 + goto out; 919 925 920 926 err = sync_inode_metadata(inode, 1); 921 927 if (ret == 0) 922 928 ret = err; 929 + out: 930 + mutex_unlock(&inode->i_mutex); 923 931 return ret; 924 932 } 925 933 EXPORT_SYMBOL(generic_file_fsync); ··· 964 956 /* 965 957 * No-op implementation of ->fsync for in-memory filesystems. 966 958 */ 967 - int noop_fsync(struct file *file, int datasync) 959 + int noop_fsync(struct file *file, loff_t start, loff_t end, int datasync) 968 960 { 969 961 return 0; 970 962 }
+10 -1
fs/logfs/file.c
··· 219 219 } 220 220 } 221 221 222 - int logfs_fsync(struct file *file, int datasync) 222 + int logfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 223 223 { 224 224 struct super_block *sb = file->f_mapping->host->i_sb; 225 + struct inode *inode = file->f_mapping->host; 226 + int ret; 225 227 228 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 229 + if (ret) 230 + return ret; 231 + 232 + mutex_lock(&inode->i_mutex); 226 233 logfs_write_anchor(sb); 234 + mutex_unlock(&inode->i_mutex); 235 + 227 236 return 0; 228 237 } 229 238
+1 -1
fs/logfs/logfs.h
··· 506 506 extern const struct address_space_operations logfs_reg_aops; 507 507 int logfs_readpage(struct file *file, struct page *page); 508 508 long logfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 509 - int logfs_fsync(struct file *file, int datasync); 509 + int logfs_fsync(struct file *file, loff_t start, loff_t end, int datasync); 510 510 511 511 /* gc.c */ 512 512 u32 get_best_cand(struct super_block *sb, struct candidate_list *list, u32 *ec);
+2 -2
fs/ncpfs/file.c
··· 20 20 21 21 #include "ncp_fs.h" 22 22 23 - static int ncp_fsync(struct file *file, int datasync) 23 + static int ncp_fsync(struct file *file, loff_t start, loff_t end, int datasync) 24 24 { 25 - return 0; 25 + return filemap_write_and_wait_range(file->f_mapping, start, end); 26 26 } 27 27 28 28 /*
+6 -2
fs/nfs/dir.c
··· 56 56 static int nfs_mknod(struct inode *, struct dentry *, int, dev_t); 57 57 static int nfs_rename(struct inode *, struct dentry *, 58 58 struct inode *, struct dentry *); 59 - static int nfs_fsync_dir(struct file *, int); 59 + static int nfs_fsync_dir(struct file *, loff_t, loff_t, int); 60 60 static loff_t nfs_llseek_dir(struct file *, loff_t, int); 61 61 static void nfs_readdir_clear_array(struct page*); 62 62 ··· 945 945 * All directory operations under NFS are synchronous, so fsync() 946 946 * is a dummy operation. 947 947 */ 948 - static int nfs_fsync_dir(struct file *filp, int datasync) 948 + static int nfs_fsync_dir(struct file *filp, loff_t start, loff_t end, 949 + int datasync) 949 950 { 950 951 struct dentry *dentry = filp->f_path.dentry; 952 + struct inode *inode = dentry->d_inode; 951 953 952 954 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n", 953 955 dentry->d_parent->d_name.name, dentry->d_name.name, 954 956 datasync); 955 957 958 + mutex_lock(&inode->i_mutex); 956 959 nfs_inc_stats(dentry->d_inode, NFSIOS_VFSFSYNC); 960 + mutex_unlock(&inode->i_mutex); 957 961 return 0; 958 962 } 959 963
+8 -3
fs/nfs/file.c
··· 55 55 static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, 56 56 unsigned long nr_segs, loff_t pos); 57 57 static int nfs_file_flush(struct file *, fl_owner_t id); 58 - static int nfs_file_fsync(struct file *, int datasync); 58 + static int nfs_file_fsync(struct file *, loff_t, loff_t, int datasync); 59 59 static int nfs_check_flags(int flags); 60 60 static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); 61 61 static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); ··· 308 308 * fall back to doing a synchronous write. 309 309 */ 310 310 static int 311 - nfs_file_fsync(struct file *file, int datasync) 311 + nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) 312 312 { 313 313 struct dentry *dentry = file->f_path.dentry; 314 314 struct nfs_open_context *ctx = nfs_file_open_context(file); ··· 316 316 int have_error, status; 317 317 int ret = 0; 318 318 319 - 320 319 dprintk("NFS: fsync file(%s/%s) datasync %d\n", 321 320 dentry->d_parent->d_name.name, dentry->d_name.name, 322 321 datasync); 322 + 323 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 324 + if (ret) 325 + return ret; 326 + mutex_lock(&inode->i_mutex); 323 327 324 328 nfs_inc_stats(inode, NFSIOS_VFSFSYNC); 325 329 have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags); ··· 336 332 if (!ret && !datasync) 337 333 /* application has asked for meta-data sync */ 338 334 ret = pnfs_layoutcommit_inode(inode, true); 335 + mutex_unlock(&inode->i_mutex); 339 336 return ret; 340 337 } 341 338
+10 -2
fs/nilfs2/file.c
··· 27 27 #include "nilfs.h" 28 28 #include "segment.h" 29 29 30 - int nilfs_sync_file(struct file *file, int datasync) 30 + int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 31 31 { 32 32 /* 33 33 * Called from fsync() system call ··· 40 40 struct inode *inode = file->f_mapping->host; 41 41 int err; 42 42 43 - if (!nilfs_inode_dirty(inode)) 43 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 44 + if (err) 45 + return err; 46 + mutex_lock(&inode->i_mutex); 47 + 48 + if (!nilfs_inode_dirty(inode)) { 49 + mutex_unlock(&inode->i_mutex); 44 50 return 0; 51 + } 45 52 46 53 if (datasync) 47 54 err = nilfs_construct_dsync_segment(inode->i_sb, inode, 0, ··· 56 49 else 57 50 err = nilfs_construct_segment(inode->i_sb); 58 51 52 + mutex_unlock(&inode->i_mutex); 59 53 return err; 60 54 } 61 55
+1 -1
fs/nilfs2/nilfs.h
··· 235 235 struct page *, struct inode *); 236 236 237 237 /* file.c */ 238 - extern int nilfs_sync_file(struct file *, int); 238 + extern int nilfs_sync_file(struct file *, loff_t, loff_t, int); 239 239 240 240 /* ioctl.c */ 241 241 long nilfs_ioctl(struct file *, unsigned int, unsigned long);
+9 -1
fs/ntfs/dir.c
··· 1527 1527 * this problem for now. We do write the $BITMAP attribute if it is present 1528 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, int datasync) 1530 + static int ntfs_dir_fsync(struct file *filp, loff_t start, loff_t end, 1531 + int datasync) 1531 1532 { 1532 1533 struct inode *bmp_vi, *vi = filp->f_mapping->host; 1533 1534 int err, ret; 1534 1535 ntfs_attr na; 1535 1536 1536 1537 ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); 1538 + 1539 + err = filemap_write_and_wait_range(vi->i_mapping, start, end); 1540 + if (err) 1541 + return err; 1542 + mutex_lock(&vi->i_mutex); 1543 + 1537 1544 BUG_ON(!S_ISDIR(vi->i_mode)); 1538 1545 /* If the bitmap attribute inode is in memory sync it, too. */ 1539 1546 na.mft_no = vi->i_ino; ··· 1562 1555 else 1563 1556 ntfs_warning(vi->i_sb, "Failed to f%ssync inode 0x%lx. Error " 1564 1557 "%u.", datasync ? "data" : "", vi->i_ino, -ret); 1558 + mutex_unlock(&vi->i_mutex); 1565 1559 return ret; 1566 1560 } 1567 1561
+9 -1
fs/ntfs/file.c
··· 2152 2152 * with this inode but since we have no simple way of getting to them we ignore 2153 2153 * this problem for now. 2154 2154 */ 2155 - static int ntfs_file_fsync(struct file *filp, int datasync) 2155 + static int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end, 2156 + int datasync) 2156 2157 { 2157 2158 struct inode *vi = filp->f_mapping->host; 2158 2159 int err, ret = 0; 2159 2160 2160 2161 ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); 2162 + 2163 + err = filemap_write_and_wait_range(vi->i_mapping, start, end); 2164 + if (err) 2165 + return err; 2166 + mutex_lock(&vi->i_mutex); 2167 + 2161 2168 BUG_ON(S_ISDIR(vi->i_mode)); 2162 2169 if (!datasync || !NInoNonResident(NTFS_I(vi))) 2163 2170 ret = __ntfs_write_inode(vi, 1); ··· 2182 2175 else 2183 2176 ntfs_warning(vi->i_sb, "Failed to f%ssync inode 0x%lx. Error " 2184 2177 "%u.", datasync ? "data" : "", vi->i_ino, -ret); 2178 + mutex_unlock(&vi->i_mutex); 2185 2179 return ret; 2186 2180 } 2187 2181
+13 -1
fs/ocfs2/file.c
··· 171 171 return 0; 172 172 } 173 173 174 - static int ocfs2_sync_file(struct file *file, int datasync) 174 + static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end, 175 + int datasync) 175 176 { 176 177 int err = 0; 177 178 journal_t *journal; ··· 185 184 file->f_path.dentry->d_name.name, 186 185 (unsigned long long)datasync); 187 186 187 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 188 + if (err) 189 + return err; 190 + 191 + /* 192 + * Probably don't need the i_mutex at all in here, just putting it here 193 + * to be consistent with how fsync used to be called, someone more 194 + * familiar with the fs could possibly remove it. 195 + */ 196 + mutex_lock(&inode->i_mutex); 188 197 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) { 189 198 /* 190 199 * We still have to flush drive's caches to get data to the ··· 211 200 bail: 212 201 if (err) 213 202 mlog_errno(err); 203 + mutex_unlock(&inode->i_mutex); 214 204 215 205 return (err < 0) ? -EIO : 0; 216 206 }
+11 -2
fs/reiserfs/dir.c
··· 14 14 extern const struct reiserfs_key MIN_KEY; 15 15 16 16 static int reiserfs_readdir(struct file *, void *, filldir_t); 17 - static int reiserfs_dir_fsync(struct file *filp, int datasync); 17 + static int reiserfs_dir_fsync(struct file *filp, loff_t start, loff_t end, 18 + int datasync); 18 19 19 20 const struct file_operations reiserfs_dir_operations = { 20 21 .llseek = generic_file_llseek, ··· 28 27 #endif 29 28 }; 30 29 31 - static int reiserfs_dir_fsync(struct file *filp, int datasync) 30 + static int reiserfs_dir_fsync(struct file *filp, loff_t start, loff_t end, 31 + int datasync) 32 32 { 33 33 struct inode *inode = filp->f_mapping->host; 34 34 int err; 35 + 36 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 37 + if (err) 38 + return err; 39 + 40 + mutex_lock(&inode->i_mutex); 35 41 reiserfs_write_lock(inode->i_sb); 36 42 err = reiserfs_commit_for_inode(inode); 37 43 reiserfs_write_unlock(inode->i_sb); 44 + mutex_unlock(&inode->i_mutex); 38 45 if (err < 0) 39 46 return err; 40 47 return 0;
+8 -1
fs/reiserfs/file.c
··· 140 140 * be removed... 141 141 */ 142 142 143 - static int reiserfs_sync_file(struct file *filp, int datasync) 143 + static int reiserfs_sync_file(struct file *filp, loff_t start, loff_t end, 144 + int datasync) 144 145 { 145 146 struct inode *inode = filp->f_mapping->host; 146 147 int err; 147 148 int barrier_done; 148 149 150 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 151 + if (err) 152 + return err; 153 + 154 + mutex_lock(&inode->i_mutex); 149 155 BUG_ON(!S_ISREG(inode->i_mode)); 150 156 err = sync_mapping_buffers(inode->i_mapping); 151 157 reiserfs_write_lock(inode->i_sb); ··· 159 153 reiserfs_write_unlock(inode->i_sb); 160 154 if (barrier_done != 1 && reiserfs_barrier_flush(inode->i_sb)) 161 155 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 156 + mutex_unlock(&inode->i_mutex); 162 157 if (barrier_done < 0) 163 158 return barrier_done; 164 159 return (err < 0) ? -EIO : 0;
+3 -22
fs/sync.c
··· 165 165 */ 166 166 int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) 167 167 { 168 - struct address_space *mapping = file->f_mapping; 169 - int err, ret; 170 - 171 - if (!file->f_op || !file->f_op->fsync) { 172 - ret = -EINVAL; 173 - goto out; 174 - } 175 - 176 - ret = filemap_write_and_wait_range(mapping, start, end); 177 - 178 - /* 179 - * We need to protect against concurrent writers, which could cause 180 - * livelocks in fsync_buffers_list(). 181 - */ 182 - mutex_lock(&mapping->host->i_mutex); 183 - err = file->f_op->fsync(file, datasync); 184 - if (!ret) 185 - ret = err; 186 - mutex_unlock(&mapping->host->i_mutex); 187 - 188 - out: 189 - return ret; 168 + if (!file->f_op || !file->f_op->fsync) 169 + return -EINVAL; 170 + return file->f_op->fsync(file, start, end, datasync); 190 171 } 191 172 EXPORT_SYMBOL(vfs_fsync_range); 192 173
+11 -10
fs/ubifs/file.c
··· 1304 1304 return NULL; 1305 1305 } 1306 1306 1307 - int ubifs_fsync(struct file *file, int datasync) 1307 + int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 1308 1308 { 1309 1309 struct inode *inode = file->f_mapping->host; 1310 1310 struct ubifs_info *c = inode->i_sb->s_fs_info; ··· 1319 1319 */ 1320 1320 return 0; 1321 1321 1322 - /* 1323 - * VFS has already synchronized dirty pages for this inode. Synchronize 1324 - * the inode unless this is a 'datasync()' call. 1325 - */ 1322 + err = filemap_write_and_wait_range(inode->i_mapping, start, end); 1323 + if (err) 1324 + return err; 1325 + mutex_lock(&inode->i_mutex); 1326 + 1327 + /* Synchronize the inode unless this is a 'datasync()' call. */ 1326 1328 if (!datasync || (inode->i_state & I_DIRTY_DATASYNC)) { 1327 1329 err = inode->i_sb->s_op->write_inode(inode, NULL); 1328 1330 if (err) 1329 - return err; 1331 + goto out; 1330 1332 } 1331 1333 1332 1334 /* ··· 1336 1334 * them. 1337 1335 */ 1338 1336 err = ubifs_sync_wbufs_by_inode(c, inode); 1339 - if (err) 1340 - return err; 1341 - 1342 - return 0; 1337 + out: 1338 + mutex_unlock(&inode->i_mutex); 1339 + return err; 1343 1340 } 1344 1341 1345 1342 /**
+1 -1
fs/ubifs/ubifs.h
··· 1720 1720 int ubifs_calc_dark(const struct ubifs_info *c, int spc); 1721 1721 1722 1722 /* file.c */ 1723 - int ubifs_fsync(struct file *file, int datasync); 1723 + int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync); 1724 1724 int ubifs_setattr(struct dentry *dentry, struct iattr *attr); 1725 1725 1726 1726 /* dir.c */
+8 -9
fs/xfs/linux-2.6/xfs_file.c
··· 127 127 STATIC int 128 128 xfs_file_fsync( 129 129 struct file *file, 130 + loff_t start, 131 + loff_t end, 130 132 int datasync) 131 133 { 132 134 struct inode *inode = file->f_mapping->host; ··· 139 137 int log_flushed = 0; 140 138 141 139 trace_xfs_file_fsync(ip); 140 + 141 + error = filemap_write_and_wait_range(inode->i_mapping, start, end); 142 + if (error) 143 + return error; 142 144 143 145 if (XFS_FORCED_SHUTDOWN(mp)) 144 146 return -XFS_ERROR(EIO); ··· 881 875 /* Handle various SYNC-type writes */ 882 876 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) { 883 877 loff_t end = pos + ret - 1; 884 - int error, error2; 885 878 886 879 xfs_rw_iunlock(ip, iolock); 887 - error = filemap_write_and_wait_range(mapping, pos, end); 880 + ret = -xfs_file_fsync(file, pos, end, 881 + (file->f_flags & __O_SYNC) ? 0 : 1); 888 882 xfs_rw_ilock(ip, iolock); 889 - 890 - error2 = -xfs_file_fsync(file, 891 - (file->f_flags & __O_SYNC) ? 0 : 1); 892 - if (error) 893 - ret = error; 894 - else if (error2) 895 - ret = error2; 896 883 } 897 884 898 885 out_unlock:
+1 -1
include/linux/ext3_fs.h
··· 877 877 extern void ext3_htree_free_dir_info(struct dir_private_info *p); 878 878 879 879 /* fsync.c */ 880 - extern int ext3_sync_file(struct file *, int); 880 + extern int ext3_sync_file(struct file *, loff_t, loff_t, int); 881 881 882 882 /* hash.c */ 883 883 extern int ext3fs_dirhash(const char *name, int len, struct
+2 -1
include/linux/fb.h
··· 1043 1043 struct inode *inode, 1044 1044 struct file *file); 1045 1045 extern void fb_deferred_io_cleanup(struct fb_info *info); 1046 - extern int fb_deferred_io_fsync(struct file *file, int datasync); 1046 + extern int fb_deferred_io_fsync(struct file *file, loff_t start, 1047 + loff_t end, int datasync); 1047 1048 1048 1049 static inline bool fb_be_math(struct fb_info *info) 1049 1050 {
+5 -4
include/linux/fs.h
··· 1572 1572 int (*open) (struct inode *, struct file *); 1573 1573 int (*flush) (struct file *, fl_owner_t id); 1574 1574 int (*release) (struct inode *, struct file *); 1575 - int (*fsync) (struct file *, int datasync); 1575 + int (*fsync) (struct file *, loff_t, loff_t, int datasync); 1576 1576 int (*aio_fsync) (struct kiocb *, int datasync); 1577 1577 int (*fasync) (int, struct file *, int); 1578 1578 int (*lock) (struct file *, int, struct file_lock *); ··· 2360 2360 /* fs/block_dev.c */ 2361 2361 extern ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, 2362 2362 unsigned long nr_segs, loff_t pos); 2363 - extern int blkdev_fsync(struct file *filp, int datasync); 2363 + extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end, 2364 + int datasync); 2364 2365 2365 2366 /* fs/splice.c */ 2366 2367 extern ssize_t generic_file_splice_read(struct file *, loff_t *, ··· 2491 2490 extern int simple_unlink(struct inode *, struct dentry *); 2492 2491 extern int simple_rmdir(struct inode *, struct dentry *); 2493 2492 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 2494 - extern int noop_fsync(struct file *, int); 2493 + extern int noop_fsync(struct file *, loff_t, loff_t, int); 2495 2494 extern int simple_empty(struct dentry *); 2496 2495 extern int simple_readpage(struct file *file, struct page *page); 2497 2496 extern int simple_write_begin(struct file *file, struct address_space *mapping, ··· 2516 2515 extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, 2517 2516 const void __user *from, size_t count); 2518 2517 2519 - extern int generic_file_fsync(struct file *, int); 2518 + extern int generic_file_fsync(struct file *, loff_t, loff_t, int); 2520 2519 2521 2520 extern int generic_check_addressable(unsigned, u64); 2522 2521
+2 -2
ipc/shm.c
··· 277 277 return 0; 278 278 } 279 279 280 - static int shm_fsync(struct file *file, int datasync) 280 + static int shm_fsync(struct file *file, loff_t start, loff_t end, int datasync) 281 281 { 282 282 struct shm_file_data *sfd = shm_file_data(file); 283 283 284 284 if (!sfd->file->f_op->fsync) 285 285 return -EINVAL; 286 - return sfd->file->f_op->fsync(sfd->file, datasync); 286 + return sfd->file->f_op->fsync(sfd->file, start, end, datasync); 287 287 } 288 288 289 289 static unsigned long shm_get_unmapped_area(struct file *file,