Skip to content

Commit 7238226

Browse files
author
Andreas Gruenbacher
committed
gfs2: Pull return value test out of should_fault_in_pages
Pull the return value test of the previous read or write operation out of should_fault_in_pages(). In a following patch, we'll fault in pages before the I/O and there will be no return value to check. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 6d22ff4 commit 7238226

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

fs/gfs2/file.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
770770
return ret ? ret : ret1;
771771
}
772772

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,
774774
size_t *prev_count,
775775
size_t *window_size)
776776
{
@@ -779,8 +779,6 @@ static inline bool should_fault_in_pages(ssize_t ret, struct iov_iter *i,
779779

780780
if (likely(!count))
781781
return false;
782-
if (ret <= 0 && ret != -EFAULT)
783-
return false;
784782
if (!iter_is_iovec(i))
785783
return false;
786784

@@ -842,10 +840,12 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
842840
IOMAP_DIO_PARTIAL, read);
843841
to->nofault = false;
844842
pagefault_enable();
843+
if (ret <= 0 && ret != -EFAULT)
844+
goto out_unlock;
845845
if (ret > 0)
846846
read = ret;
847847

848-
if (should_fault_in_pages(ret, to, &prev_count, &window_size)) {
848+
if (should_fault_in_pages(to, &prev_count, &window_size)) {
849849
gfs2_holder_allow_demote(gh);
850850
window_size -= fault_in_iov_iter_writeable(to, window_size);
851851
gfs2_holder_disallow_demote(gh);
@@ -855,6 +855,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
855855
goto retry;
856856
}
857857
}
858+
out_unlock:
858859
if (gfs2_holder_queued(gh))
859860
gfs2_glock_dq(gh);
860861
out_uninit:
@@ -899,20 +900,23 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
899900
goto out_uninit;
900901
/* Silently fall back to buffered I/O when writing beyond EOF */
901902
if (iocb->ki_pos + iov_iter_count(from) > i_size_read(&ip->i_inode))
902-
goto out;
903+
goto out_unlock;
903904
retry_under_glock:
904905

905906
from->nofault = true;
906907
ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL,
907908
IOMAP_DIO_PARTIAL, written);
908909
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+
}
912916
if (ret > 0)
913917
written = ret;
914918

915-
if (should_fault_in_pages(ret, from, &prev_count, &window_size)) {
919+
if (should_fault_in_pages(from, &prev_count, &window_size)) {
916920
gfs2_holder_allow_demote(gh);
917921
window_size -= fault_in_iov_iter_readable(from, window_size);
918922
gfs2_holder_disallow_demote(gh);
@@ -922,7 +926,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
922926
goto retry;
923927
}
924928
}
925-
out:
929+
out_unlock:
926930
if (gfs2_holder_queued(gh))
927931
gfs2_glock_dq(gh);
928932
out_uninit:
@@ -975,10 +979,12 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
975979
pagefault_disable();
976980
ret = generic_file_read_iter(iocb, to);
977981
pagefault_enable();
982+
if (ret <= 0 && ret != -EFAULT)
983+
goto out_unlock;
978984
if (ret > 0)
979985
read += ret;
980986

981-
if (should_fault_in_pages(ret, to, &prev_count, &window_size)) {
987+
if (should_fault_in_pages(to, &prev_count, &window_size)) {
982988
gfs2_holder_allow_demote(&gh);
983989
window_size -= fault_in_iov_iter_writeable(to, window_size);
984990
gfs2_holder_disallow_demote(&gh);
@@ -988,6 +994,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
988994
goto retry;
989995
}
990996
}
997+
out_unlock:
991998
if (gfs2_holder_queued(&gh))
992999
gfs2_glock_dq(&gh);
9931000
out_uninit:
@@ -1050,8 +1057,11 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10501057
if (inode == sdp->sd_rindex)
10511058
gfs2_glock_dq_uninit(statfs_gh);
10521059

1060+
if (ret <= 0 && ret != -EFAULT)
1061+
goto out_unlock;
1062+
10531063
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)) {
10551065
gfs2_holder_allow_demote(gh);
10561066
window_size -= fault_in_iov_iter_readable(from, window_size);
10571067
gfs2_holder_disallow_demote(gh);

0 commit comments

Comments
 (0)