Message ID | 20180718110427.7775-5-cgxu519@gmx.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Jul 18, 2018 at 7:08 PM Chengguang Xu <cgxu519@gmx.com> wrote: > > if the offset is larger or equal to both real file size > and max file size, then do nothing. > > Signed-off-by: Chengguang Xu <cgxu519@gmx.com> > --- > fs/ceph/file.c | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c > index 7a01fe627bd7..23b30cf8caf4 100644 > --- a/fs/ceph/file.c > +++ b/fs/ceph/file.c > @@ -1248,9 +1248,12 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) > struct inode *inode = file_inode(filp); > struct ceph_inode_info *ci = ceph_inode(inode); > struct page *pinned_page = NULL; > + struct ceph_fs_client *fsc = inode->i_sb->s_fs_info; > ssize_t ret; > int want, got = 0; > int retry_op = 0, read = 0; > + loff_t limit = max(i_size_read(inode), fsc->max_file_size); > + loff_t pos = iocb->ki_pos; > > again: > dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", > @@ -1285,13 +1288,18 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) > retry_op = READ_INLINE; > } > } else { > - CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); > - dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", > - inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, > - ceph_cap_string(got)); > - ceph_add_rw_context(fi, &rw_ctx); > - ret = generic_file_read_iter(iocb, to); > - ceph_del_rw_context(fi, &rw_ctx); > + if (unlikely(pos >= limit)) { > + ret = 0; > + } else { > + CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); > + iov_iter_truncate(to, limit - pos); > + dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", > + inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, > + ceph_cap_string(got)); > + ceph_add_rw_context(fi, &rw_ctx); > + ret = generic_file_read_iter(iocb, to); > + ceph_del_rw_context(fi, &rw_ctx); > + } > } > dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", > inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret); > -- > 2.17.1 > Above code is useless because VFS does not allow read to exceed EOF. Please squash the rest patches Regards Yan, Zheng > -- > To unsubscribe from this list: send the line "unsubscribe ceph-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 7a01fe627bd7..23b30cf8caf4 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1248,9 +1248,12 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) struct inode *inode = file_inode(filp); struct ceph_inode_info *ci = ceph_inode(inode); struct page *pinned_page = NULL; + struct ceph_fs_client *fsc = inode->i_sb->s_fs_info; ssize_t ret; int want, got = 0; int retry_op = 0, read = 0; + loff_t limit = max(i_size_read(inode), fsc->max_file_size); + loff_t pos = iocb->ki_pos; again: dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", @@ -1285,13 +1288,18 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) retry_op = READ_INLINE; } } else { - CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); - dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", - inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, - ceph_cap_string(got)); - ceph_add_rw_context(fi, &rw_ctx); - ret = generic_file_read_iter(iocb, to); - ceph_del_rw_context(fi, &rw_ctx); + if (unlikely(pos >= limit)) { + ret = 0; + } else { + CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); + iov_iter_truncate(to, limit - pos); + dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", + inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, + ceph_cap_string(got)); + ceph_add_rw_context(fi, &rw_ctx); + ret = generic_file_read_iter(iocb, to); + ceph_del_rw_context(fi, &rw_ctx); + } } dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);
if the offset is larger or equal to both real file size and max file size, then do nothing. Signed-off-by: Chengguang Xu <cgxu519@gmx.com> --- fs/ceph/file.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)