@@ -770,7 +770,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
770
770
return ret ? ret : ret1 ;
771
771
}
772
772
773
- static inline bool should_fault_in_pages (ssize_t ret , struct iov_iter * i ,
773
+ static inline bool should_fault_in_pages (struct iov_iter * i ,
774
774
size_t * prev_count ,
775
775
size_t * window_size )
776
776
{
@@ -779,8 +779,6 @@ static inline bool should_fault_in_pages(ssize_t ret, struct iov_iter *i,
779
779
780
780
if (likely (!count ))
781
781
return false;
782
- if (ret <= 0 && ret != - EFAULT )
783
- return false;
784
782
if (!iter_is_iovec (i ))
785
783
return false;
786
784
@@ -842,10 +840,12 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
842
840
IOMAP_DIO_PARTIAL , read );
843
841
to -> nofault = false;
844
842
pagefault_enable ();
843
+ if (ret <= 0 && ret != - EFAULT )
844
+ goto out_unlock ;
845
845
if (ret > 0 )
846
846
read = ret ;
847
847
848
- if (should_fault_in_pages (ret , to , & prev_count , & window_size )) {
848
+ if (should_fault_in_pages (to , & prev_count , & window_size )) {
849
849
gfs2_holder_allow_demote (gh );
850
850
window_size -= fault_in_iov_iter_writeable (to , window_size );
851
851
gfs2_holder_disallow_demote (gh );
@@ -855,6 +855,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
855
855
goto retry ;
856
856
}
857
857
}
858
+ out_unlock :
858
859
if (gfs2_holder_queued (gh ))
859
860
gfs2_glock_dq (gh );
860
861
out_uninit :
@@ -899,20 +900,23 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
899
900
goto out_uninit ;
900
901
/* Silently fall back to buffered I/O when writing beyond EOF */
901
902
if (iocb -> ki_pos + iov_iter_count (from ) > i_size_read (& ip -> i_inode ))
902
- goto out ;
903
+ goto out_unlock ;
903
904
retry_under_glock :
904
905
905
906
from -> nofault = true;
906
907
ret = iomap_dio_rw (iocb , from , & gfs2_iomap_ops , NULL ,
907
908
IOMAP_DIO_PARTIAL , written );
908
909
from -> nofault = false;
909
-
910
- if (ret == - ENOTBLK )
911
- ret = 0 ;
910
+ if (ret <= 0 ) {
911
+ if (ret == - ENOTBLK )
912
+ ret = 0 ;
913
+ if (ret != - EFAULT )
914
+ goto out_unlock ;
915
+ }
912
916
if (ret > 0 )
913
917
written = ret ;
914
918
915
- if (should_fault_in_pages (ret , from , & prev_count , & window_size )) {
919
+ if (should_fault_in_pages (from , & prev_count , & window_size )) {
916
920
gfs2_holder_allow_demote (gh );
917
921
window_size -= fault_in_iov_iter_readable (from , window_size );
918
922
gfs2_holder_disallow_demote (gh );
@@ -922,7 +926,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
922
926
goto retry ;
923
927
}
924
928
}
925
- out :
929
+ out_unlock :
926
930
if (gfs2_holder_queued (gh ))
927
931
gfs2_glock_dq (gh );
928
932
out_uninit :
@@ -975,10 +979,12 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
975
979
pagefault_disable ();
976
980
ret = generic_file_read_iter (iocb , to );
977
981
pagefault_enable ();
982
+ if (ret <= 0 && ret != - EFAULT )
983
+ goto out_unlock ;
978
984
if (ret > 0 )
979
985
read += ret ;
980
986
981
- if (should_fault_in_pages (ret , to , & prev_count , & window_size )) {
987
+ if (should_fault_in_pages (to , & prev_count , & window_size )) {
982
988
gfs2_holder_allow_demote (& gh );
983
989
window_size -= fault_in_iov_iter_writeable (to , window_size );
984
990
gfs2_holder_disallow_demote (& gh );
@@ -988,6 +994,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
988
994
goto retry ;
989
995
}
990
996
}
997
+ out_unlock :
991
998
if (gfs2_holder_queued (& gh ))
992
999
gfs2_glock_dq (& gh );
993
1000
out_uninit :
@@ -1050,8 +1057,11 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
1050
1057
if (inode == sdp -> sd_rindex )
1051
1058
gfs2_glock_dq_uninit (statfs_gh );
1052
1059
1060
+ if (ret <= 0 && ret != - EFAULT )
1061
+ goto out_unlock ;
1062
+
1053
1063
from -> count = orig_count - written ;
1054
- if (should_fault_in_pages (ret , from , & prev_count , & window_size )) {
1064
+ if (should_fault_in_pages (from , & prev_count , & window_size )) {
1055
1065
gfs2_holder_allow_demote (gh );
1056
1066
window_size -= fault_in_iov_iter_readable (from , window_size );
1057
1067
gfs2_holder_disallow_demote (gh );
0 commit comments