@@ -623,7 +623,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
623
623
struct inode * inode = file_inode (file );
624
624
unsigned long written = 0 ;
625
625
ssize_t result ;
626
- size_t count = iov_iter_count (from );
627
626
628
627
result = nfs_key_timeout_notify (file , inode );
629
628
if (result )
@@ -633,9 +632,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
633
632
return nfs_file_direct_write (iocb , from );
634
633
635
634
dprintk ("NFS: write(%pD2, %zu@%Ld)\n" ,
636
- file , count , (long long ) iocb -> ki_pos );
635
+ file , iov_iter_count ( from ) , (long long ) iocb -> ki_pos );
637
636
638
- result = - EBUSY ;
639
637
if (IS_SWAPFILE (inode ))
640
638
goto out_swapfile ;
641
639
/*
@@ -647,28 +645,33 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
647
645
goto out ;
648
646
}
649
647
650
- result = count ;
651
- if (!count )
648
+ inode_lock (inode );
649
+ result = generic_write_checks (iocb , from );
650
+ if (result > 0 ) {
651
+ current -> backing_dev_info = inode_to_bdi (inode );
652
+ result = generic_perform_write (file , from , iocb -> ki_pos );
653
+ current -> backing_dev_info = NULL ;
654
+ }
655
+ inode_unlock (inode );
656
+ if (result <= 0 )
652
657
goto out ;
653
658
654
- result = generic_file_write_iter (iocb , from );
655
- if (result > 0 )
656
- written = result ;
659
+ written = generic_write_sync (iocb , result );
660
+ iocb -> ki_pos += written ;
657
661
658
662
/* Return error values */
659
- if (result >= 0 && nfs_need_check_write (file , inode )) {
663
+ if (nfs_need_check_write (file , inode )) {
660
664
int err = vfs_fsync (file , 0 );
661
665
if (err < 0 )
662
666
result = err ;
663
667
}
664
- if (result > 0 )
665
- nfs_add_stats (inode , NFSIOS_NORMALWRITTENBYTES , written );
668
+ nfs_add_stats (inode , NFSIOS_NORMALWRITTENBYTES , written );
666
669
out :
667
670
return result ;
668
671
669
672
out_swapfile :
670
673
printk (KERN_INFO "NFS: attempt to write to active swap file!\n" );
671
- goto out ;
674
+ return - EBUSY ;
672
675
}
673
676
EXPORT_SYMBOL_GPL (nfs_file_write );
674
677
0 commit comments