>On 09/24/2013 04:05 PM, majianpeng wrote: >> diff --git a/fs/ceph/file.c b/fs/ceph/file.c >> index 3de8982..5422d8e 100644 >> --- a/fs/ceph/file.c >> +++ b/fs/ceph/file.c >> @@ -408,51 +408,94 @@ more: >> * >> * If the read spans object boundary, just do multiple reads. >> */ >> -static ssize_t ceph_sync_read(struct file *file, char __user *data, >> - unsigned len, loff_t *poff, int *checkeof) >> +static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *i, >> + int *checkeof) >> { >> + struct file *file = iocb->ki_filp; >> struct inode *inode = file_inode(file); >> struct page **pages; >> - u64 off = *poff; >> + u64 off = iocb->ki_pos; >> int num_pages, ret; >> >> - dout("sync_read on file %p %llu~%u %s\n", file, off, len, >> + dout("sync_read on file %p %llu~%u %s\n", file, off, >> + (unsigned)iocb->ki_left, >> (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); >> - >> - if (file->f_flags & O_DIRECT) { >> - num_pages = calc_pages_for((unsigned long)data, len); >> - pages = ceph_get_direct_page_vector(data, num_pages, true); >> - } else { >> - num_pages = calc_pages_for(off, len); >> - pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); >> - } >> - if (IS_ERR(pages)) >> - return PTR_ERR(pages); >> - >> /* >> * flush any page cache pages in this range. this >> * will make concurrent normal and sync io slow, >> * but it will at least behave sensibly when they are >> * in sequence. >> */ >> - ret = filemap_write_and_wait(inode->i_mapping); >> + ret = filemap_write_and_wait_range(inode->i_mapping, off, >> + off + iocb->ki_left); >> if (ret < 0) >> - goto done; >> - >> - ret = striped_read(inode, off, len, pages, num_pages, checkeof, >> - file->f_flags & O_DIRECT, >> - (unsigned long)data & ~PAGE_MASK); >> + return ret; >> >> - if (ret >= 0 && (file->f_flags & O_DIRECT) == 0) >> - ret = ceph_copy_page_vector_to_user(pages, data, off, ret); >> - if (ret >= 0) >> - *poff = off + ret; >> + if (file->f_flags & O_DIRECT) { >> + while (iov_iter_count(i)) { >> + void __user *data = i->iov[0].iov_base + i->iov_offset; >> + size_t len = i->iov[0].iov_len - i->iov_offset; >> + >> + num_pages = calc_pages_for((unsigned long)data, len); >> + pages = ceph_get_direct_page_vector(data, >> + num_pages, true); >> + if (IS_ERR(pages)) >> + return PTR_ERR(pages); >> + >> + ret = striped_read(inode, off, len, >> + pages, num_pages, checkeof, >> + 1, (unsigned long)data & ~PAGE_MASK); >> + ceph_put_page_vector(pages, num_pages, true); >> + >> + if (ret <= 0) >> + break; >> + off += ret; >> + iov_iter_advance(i, ret); >> + if (ret < len) >> + break; >> + } >> + } else { >> + size_t len = iocb->ki_left; >> >> -done: >> - if (file->f_flags & O_DIRECT) >> - ceph_put_page_vector(pages, num_pages, true); >> - else >> + num_pages = calc_pages_for(off, len); >> + pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); >> + if (IS_ERR(pages)) >> + return PTR_ERR(pages); >> + ret = striped_read(inode, off, len, pages, >> + num_pages, checkeof, 0, 0); >> + if (ret > 0) { >> + int l, k = 0; >> + size_t left = len = ret; >> + >> + while (left) { >> + void __user *data = i->iov[0].iov_base >> + + i->iov_offset; >> + l = min(i->iov[0].iov_len - i->iov_offset, >> + left); >> + >> + ret = ceph_copy_page_vector_to_user(&pages[k], >> + data, off, >> + l); >> + if (ret > 0) { >> + iov_iter_advance(i, ret); >> + left -= ret; >> + off += ret; >> + k = calc_pages_for(iocb->ki_pos, >> + len - left + 1) - 1; >> + BUG_ON(k >= num_pages && left); >> + } else >> + break; >> + } >> + } >> ceph_release_page_vector(pages, num_pages); >> + } >> + >> + if (off > iocb->ki_pos) { >> + ret = off - iocb->ki_pos; >> + iocb->ki_pos = off; >> + iocb->ki_left -= ret; >> + } >> + >> dout("sync_read result %d\n", ret); >> return ret; >> } >> @@ -647,17 +690,16 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, >> { >> struct file *filp = iocb->ki_filp; >> struct ceph_file_info *fi = filp->private_data; >> - loff_t *ppos = &iocb->ki_pos; >> - size_t len = iov->iov_len; >> + size_t len = 0; > >len = iocb->ki_left; Because commit 73a7075e3f6ec63dc359064e, remove the "iocb->ki_left = len" in func do_sync_read. So using iocb->ki_nbytes. Thanks! Jianpeng Maÿôèº{.nÇ+?·?®??+%?Ëÿ±éݶ¥?wÿº{.nÇ+?·?z?ÿuëÞ?ø§¶?¡Ü¨}©?²Æ zÚ&j:+v?¨þø¯ù®w¥þ?à2?Þ?¨èÚ&¢)ß¡«a¶Úÿÿûàz¿äz¹Þ?ú+?ù???Ý¢jÿ?wèþf