Skip to content

Commit c3cd628

Browse files
committed
ceph: fix short sync reads from the OSD
If we get a short read from the OSD because the object is small, we need to zero the remainder of the buffer. For O_DIRECT reads, the attempted range is not trimmed to i_size by the VFS, so we were actually looping indefinitely. Fix by trimming by i_size, and the unconditionally zeroing the trailing range. Reported-by: Jeff Wu <cpwu@tnsoft.com.cn> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 2584547 commit c3cd628

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

‎fs/ceph/file.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int ceph_release(struct inode *inode, struct file *file)
283283
static int striped_read(struct inode *inode,
284284
u64 off, u64 len,
285285
struct page **pages, int num_pages,
286-
int *checkeof, bool align_to_pages,
286+
int *checkeof, bool o_direct,
287287
unsigned long buf_align)
288288
{
289289
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
@@ -308,7 +308,7 @@ static int striped_read(struct inode *inode,
308308
io_align = off & ~PAGE_MASK;
309309

310310
more:
311-
if (align_to_pages)
311+
if (o_direct)
312312
page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
313313
else
314314
page_align = pos & ~PAGE_MASK;
@@ -346,20 +346,22 @@ static int striped_read(struct inode *inode,
346346
}
347347

348348
if (was_short) {
349-
/* was original extent fully inside i_size? */
350-
if (pos + left <= inode->i_size) {
351-
dout("zero tail\n");
352-
ceph_zero_page_vector_range(page_off + read, len - read,
349+
/* did we bounce off eof? */
350+
if (pos + left > inode->i_size)
351+
*checkeof = 1;
352+
353+
/* zero trailing bytes (inside i_size) */
354+
if (left > 0 && pos < inode->i_size) {
355+
if (pos + left > inode->i_size)
356+
left = inode->i_size - pos;
357+
358+
dout("zero tail %d\n", left);
359+
ceph_zero_page_vector_range(page_off + read, left,
353360
pages);
354-
read = len;
355-
goto out;
361+
read += left;
356362
}
357-
358-
/* check i_size */
359-
*checkeof = 1;
360363
}
361364

362-
out:
363365
if (ret >= 0)
364366
ret = read;
365367
dout("striped_read returns %d\n", ret);
@@ -659,7 +661,7 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
659661

660662
/* hit EOF or hole? */
661663
if (statret == 0 && *ppos < inode->i_size) {
662-
dout("aio_read sync_read hit hole, reading more\n");
664+
dout("aio_read sync_read hit hole, ppos %lld < size %lld, reading more\n", *ppos, inode->i_size);
663665
read += ret;
664666
base += ret;
665667
len -= ret;

0 commit comments

Comments
 (0)