Instead of counting the number of bytes read from the filesystem, functions gfs2_file_direct_read and gfs2_file_read_iter count the number of bytes written into the user buffer. Conversely, functions gfs2_file_direct_write and gfs2_file_buffered_write count the number of bytes read from the user buffer. This is nothing but confusing, so change the read functions to count how many bytes they have read, and the write functions to count how many bytes they have written.
Unified · Split
| @@ -807,7 +807,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to, · 806 unmodified lines | |||
| 807 | struct file *file = iocb->ki_filp; | 807 | struct file *file = iocb->ki_filp; |
| 808 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); | 808 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
| 809 | size_t prev_count = 0, window_size = 0; | 809 | size_t prev_count = 0, window_size = 0; |
| 810 | size_t written = 0; | 810 | size_t read = 0; |
| 811 | ssize_t ret; | 811 | ssize_t ret; |
| 812 | 812 | ||
| 813 | /* | 813 | /* |
| @@ -839,11 +839,11 @@ retry_under_glock: · 25 unmodified lines | |||
| 839 | pagefault_disable(); | 839 | pagefault_disable(); |
| 840 | to->nofault = true; | 840 | to->nofault = true; |
| 841 | ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL, | 841 | ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL, |
| 842 | IOMAP_DIO_PARTIAL, written); | 842 | IOMAP_DIO_PARTIAL, read); |
| 843 | to->nofault = false; | 843 | to->nofault = false; |
| 844 | pagefault_enable(); | 844 | pagefault_enable(); |
| 845 | if (ret > 0) | 845 | if (ret > 0) |
| 846 | written = ret; | 846 | read = ret; |
| 847 | 847 | ||
| 848 | if (should_fault_in_pages(ret, to, &prev_count, &window_size)) { | 848 | if (should_fault_in_pages(ret, to, &prev_count, &window_size)) { |
| 849 | size_t leftover; | 849 | size_t leftover; |
| @@ -863,7 +863,7 @@ out_uninit: · 13 unmodified lines | |||
| 863 | gfs2_holder_uninit(gh); | 863 | gfs2_holder_uninit(gh); |
| 864 | if (ret < 0) | 864 | if (ret < 0) |
| 865 | return ret; | 865 | return ret; |
| 866 | return written; | 866 | return read; |
| 867 | } | 867 | } |
| 868 | 868 | ||
| 869 | static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, | 869 | static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, |
| @@ -873,7 +873,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, · 3 unmodified lines | |||
| 873 | struct inode *inode = file->f_mapping->host; | 873 | struct inode *inode = file->f_mapping->host; |
| 874 | struct gfs2_inode *ip = GFS2_I(inode); | 874 | struct gfs2_inode *ip = GFS2_I(inode); |
| 875 | size_t prev_count = 0, window_size = 0; | 875 | size_t prev_count = 0, window_size = 0; |
| 876 | size_t read = 0; | 876 | size_t written = 0; |
| 877 | ssize_t ret; | 877 | ssize_t ret; |
| 878 | 878 | ||
| 879 | /* | 879 | /* |
| @@ -906,13 +906,13 @@ retry_under_glock: · 26 unmodified lines | |||
| 906 | 906 | ||
| 907 | from->nofault = true; | 907 | from->nofault = true; |
| 908 | ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL, | 908 | ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL, |
| 909 | IOMAP_DIO_PARTIAL, read); | 909 | IOMAP_DIO_PARTIAL, written); |
| 910 | from->nofault = false; | 910 | from->nofault = false; |
| 911 | 911 | ||
| 912 | if (ret == -ENOTBLK) | 912 | if (ret == -ENOTBLK) |
| 913 | ret = 0; | 913 | ret = 0; |
| 914 | if (ret > 0) | 914 | if (ret > 0) |
| 915 | read = ret; | 915 | written = ret; |
| 916 | 916 | ||
| 917 | if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { | 917 | if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { |
| 918 | size_t leftover; | 918 | size_t leftover; |
| @@ -933,7 +933,7 @@ out_uninit: · 14 unmodified lines | |||
| 933 | gfs2_holder_uninit(gh); | 933 | gfs2_holder_uninit(gh); |
| 934 | if (ret < 0) | 934 | if (ret < 0) |
| 935 | return ret; | 935 | return ret; |
| 936 | return read; | 936 | return written; |
| 937 | } | 937 | } |
| 938 | 938 | ||
| 939 | static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) | 939 | static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) |
| @@ -941,7 +941,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) · 1 unmodified line | |||
| 941 | struct gfs2_inode *ip; | 941 | struct gfs2_inode *ip; |
| 942 | struct gfs2_holder gh; | 942 | struct gfs2_holder gh; |
| 943 | size_t prev_count = 0, window_size = 0; | 943 | size_t prev_count = 0, window_size = 0; |
| 944 | size_t written = 0; | 944 | size_t read = 0; |
| 945 | ssize_t ret; | 945 | ssize_t ret; |
| 946 | 946 | ||
| 947 | /* | 947 | /* |
| @@ -962,7 +962,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) · 14 unmodified lines | |||
| 962 | if (ret >= 0) { | 962 | if (ret >= 0) { |
| 963 | if (!iov_iter_count(to)) | 963 | if (!iov_iter_count(to)) |
| 964 | return ret; | 964 | return ret; |
| 965 | written = ret; | 965 | read = ret; |
| 966 | } else if (ret != -EFAULT) { | 966 | } else if (ret != -EFAULT) { |
| 967 | if (ret != -EAGAIN) | 967 | if (ret != -EAGAIN) |
| 968 | return ret; | 968 | return ret; |
| @@ -980,7 +980,7 @@ retry_under_glock: · 11 unmodified lines | |||
| 980 | ret = generic_file_read_iter(iocb, to); | 980 | ret = generic_file_read_iter(iocb, to); |
| 981 | pagefault_enable(); | 981 | pagefault_enable(); |
| 982 | if (ret > 0) | 982 | if (ret > 0) |
| 983 | written += ret; | 983 | read += ret; |
| 984 | 984 | ||
| 985 | if (should_fault_in_pages(ret, to, &prev_count, &window_size)) { | 985 | if (should_fault_in_pages(ret, to, &prev_count, &window_size)) { |
| 986 | size_t leftover; | 986 | size_t leftover; |
| @@ -998,7 +998,7 @@ retry_under_glock: · 11 unmodified lines | |||
| 998 | gfs2_glock_dq(&gh); | 998 | gfs2_glock_dq(&gh); |
| 999 | out_uninit: | 999 | out_uninit: |
| 1000 | gfs2_holder_uninit(&gh); | 1000 | gfs2_holder_uninit(&gh); |
| 1001 | return written ? written : ret; | 1001 | return read ? read : ret; |
| 1002 | } | 1002 | } |
| 1003 | 1003 | ||
| 1004 | static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, | 1004 | static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, |
| @@ -1012,7 +1012,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, · 7 unmodified lines | |||
| 1012 | struct gfs2_holder *statfs_gh = NULL; | 1012 | struct gfs2_holder *statfs_gh = NULL; |
| 1013 | size_t prev_count = 0, window_size = 0; | 1013 | size_t prev_count = 0, window_size = 0; |
| 1014 | size_t orig_count = iov_iter_count(from); | 1014 | size_t orig_count = iov_iter_count(from); |
| 1015 | size_t read = 0; | 1015 | size_t written = 0; |
| 1016 | ssize_t ret; | 1016 | ssize_t ret; |
| 1017 | 1017 | ||
| 1018 | /* | 1018 | /* |
| @@ -1050,13 +1050,13 @@ retry_under_glock: · 31 unmodified lines | |||
| 1050 | current->backing_dev_info = NULL; | 1050 | current->backing_dev_info = NULL; |
| 1051 | if (ret > 0) { | 1051 | if (ret > 0) { |
| 1052 | iocb->ki_pos += ret; | 1052 | iocb->ki_pos += ret; |
| 1053 | read += ret; | 1053 | written += ret; |
| 1054 | } | 1054 | } |
| 1055 | 1055 | ||
| 1056 | if (inode == sdp->sd_rindex) | 1056 | if (inode == sdp->sd_rindex) |
| 1057 | gfs2_glock_dq_uninit(statfs_gh); | 1057 | gfs2_glock_dq_uninit(statfs_gh); |
| 1058 | 1058 | ||
| 1059 | from->count = orig_count - read; | 1059 | from->count = orig_count - written; |
| 1060 | if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { | 1060 | if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { |
| 1061 | size_t leftover; | 1061 | size_t leftover; |
| 1062 | 1062 | ||
| @@ -1077,8 +1077,8 @@ out_uninit: · 14 unmodified lines | |||
| 1077 | gfs2_holder_uninit(gh); | 1077 | gfs2_holder_uninit(gh); |
| 1078 | if (statfs_gh) | 1078 | if (statfs_gh) |
| 1079 | kfree(statfs_gh); | 1079 | kfree(statfs_gh); |
| 1080 | from->count = orig_count - read; | 1080 | from->count = orig_count - written; |
| 1081 | return read ? read : ret; | 1081 | return written ? written : ret; |
| 1082 | } | 1082 | } |
| 1083 | 1083 | ||
| 1084 | /** | 1084 | /** |