Skip to content

Commit c3d8e0b

Browse files
lxbszidryomov
authored andcommitted
ceph: return the real size read when it hits EOF
Currently, if the sync read handler ends up reading more from the last object in the file than the i_size indicates, then it'll end up returning the wrong length. Ensure that we cap the returned length and pos at the EOF. Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 8cfc0c7 commit c3d8e0b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fs/ceph/file.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
847847
ssize_t ret;
848848
u64 off = iocb->ki_pos;
849849
u64 len = iov_iter_count(to);
850+
u64 i_size;
850851

851852
dout("sync_read on file %p %llu~%u %s\n", file, off, (unsigned)len,
852853
(file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
@@ -870,7 +871,6 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
870871
struct page **pages;
871872
int num_pages;
872873
size_t page_off;
873-
u64 i_size;
874874
bool more;
875875
int idx;
876876
size_t left;
@@ -953,11 +953,14 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
953953
}
954954

955955
if (off > iocb->ki_pos) {
956-
if (ret >= 0 &&
957-
iov_iter_count(to) > 0 && off >= i_size_read(inode))
956+
if (off >= i_size) {
958957
*retry_op = CHECK_EOF;
959-
ret = off - iocb->ki_pos;
960-
iocb->ki_pos = off;
958+
ret = i_size - iocb->ki_pos;
959+
iocb->ki_pos = i_size;
960+
} else {
961+
ret = off - iocb->ki_pos;
962+
iocb->ki_pos = off;
963+
}
961964
}
962965

963966
dout("sync_read result %zd retry_op %d\n", ret, *retry_op);

0 commit comments

Comments
 (0)