From patchwork Tue Sep 10 03:13:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: majianpeng X-Patchwork-Id: 2863781 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BB039BF43F for ; Tue, 10 Sep 2013 03:13:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B44CE2035D for ; Tue, 10 Sep 2013 03:13:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83D2A2034E for ; Tue, 10 Sep 2013 03:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752377Ab3IJDNU (ORCPT ); Mon, 9 Sep 2013 23:13:20 -0400 Received: from mail-pd0-f169.google.com ([209.85.192.169]:62424 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210Ab3IJDNT (ORCPT ); Mon, 9 Sep 2013 23:13:19 -0400 Received: by mail-pd0-f169.google.com with SMTP id r10so7048832pdi.14 for ; Mon, 09 Sep 2013 20:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:reply-to:subject:references:mime-version:message-id :content-type:content-transfer-encoding; bh=NJjPGnV/GMDwo1nLxQb7ALE2zfTrUPF+cqYvfaDxT9o=; b=G1LjYF4oZ5NMYmHQofRU1G8YARS6+4B/Avx9LyZ03ztgmkkDApsoKYLKm6EB2R2cwb kJH3P5VYybB5ypqublJo0Rmm7zBGU+sYWMIwJS9j2BnJXhxS4D/gqcaKF0naBwHIwFCp ZqN8pRUsRkdBsGQxn7CDMN4nYB2YnX9SBhi4qk3GqxjPGro89NNYZFA4CqK2BTz672TG 954G6Oy4rf2n8hGcIjobAH48WzQ21Mk2DBFinHLxj8B5MBMpNIKU/a/gx3EPY/h2CFVV 058Ns98OZo1/xmacL2xomE04teArSvpOi8zrrbwAktGhgSZ5tZazTLCpwB1+O70J19XZ XYUA== X-Received: by 10.66.254.170 with SMTP id aj10mr6600630pad.142.1378782796086; Mon, 09 Sep 2013 20:13:16 -0700 (PDT) Received: from majianpeng ([218.242.10.182]) by mx.google.com with ESMTPSA id xe9sm21232374pab.0.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 09 Sep 2013 20:13:15 -0700 (PDT) Date: Tue, 10 Sep 2013 11:13:03 +0800 From: majianpeng To: =?iso-8859-1?B?WWFuLCBaaGVuZw==?= Cc: sage , ceph-devel Reply-To: majianpeng Subject: Re: Re: [PATCH V3 1/2] ceph: Implement readv/preadv for sync operation. References: <201309101004260763874@gmail.com>, <522E8748.8010406@intel.com> X-Priority: 3 X-GUID: 170E9B18-A781-4EF9-864D-60A0E5877D76 X-Has-Attach: no X-Mailer: Foxmail 7.0.1.93[cn] Mime-Version: 1.0 Message-ID: <201309101112568427989@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >On 09/10/2013 10:04 AM, majianpeng wrote: >> For readv/preadv sync-operatoin, ceph only do the first iov. >> It don't think other iovs.Now implement this. >> >> V3: >> modify some bug. >> V2: >> -add generic_segment_checks >> -using struct iov_iter replace cloning the iovs. >> -return previous successfully copied if ceph_copy_page_vector_to_user >> met error. >> >> >> Signed-off-by: Jianpeng Ma >> Reviewed-by: Yan, Zheng > >don't add people's Reviewed-by unless they say "you can" > >> --- >> fs/ceph/file.c | 157 ++++++++++++++++++++++++++++++++++++++------------------- >> 1 file changed, 106 insertions(+), 51 deletions(-) >> >> diff --git a/fs/ceph/file.c b/fs/ceph/file.c >> index 3de8982..8f20eb4 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) should be here. > Yes, Thanks very much! >Rest change looks good. After fixing this, you can add my reviewed-by to your patch > >Regards >Yan, Zheng > >> + if (ret < len) >> + break; >> + iov_iter_advance(i, ret); >> + } >> + } 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,55 +690,67 @@ 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; >> struct inode *inode = file_inode(filp); >> struct ceph_inode_info *ci = ceph_inode(inode); >> - void __user *base = iov->iov_base; >> ssize_t ret; >> int want, got = 0; >> int checkeof = 0, read = 0; >> >> dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", >> inode, ceph_vinop(inode), pos, (unsigned)len, inode); >> -again: >> + >> + ret = generic_segment_checks(iov, &nr_segs, &len, VERIFY_WRITE); >> + if (ret) >> + return ret; >> + >> if (fi->fmode & CEPH_FILE_MODE_LAZY) >> want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO; >> else >> want = CEPH_CAP_FILE_CACHE; >> ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, &got, -1); >> if (ret < 0) >> - goto out; >> + return ret; >> + >> dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", >> inode, ceph_vinop(inode), pos, (unsigned)len, >> ceph_cap_string(got)); >> >> if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 || >> (iocb->ki_filp->f_flags & O_DIRECT) || >> - (fi->flags & CEPH_F_SYNC)) >> + (fi->flags & CEPH_F_SYNC)) { >> + struct iov_iter i; >> + >> + iocb->ki_left = len; >> + iov_iter_init(&i, iov, nr_segs, len, 0); >> +again: >> /* hmm, this isn't really async... */ >> - ret = ceph_sync_read(filp, base, len, ppos, &checkeof); >> - else >> + ret = ceph_sync_read(iocb, &i, &checkeof); >> + >> + if (checkeof && ret >= 0) { >> + int statret = ceph_do_getattr(inode, >> + CEPH_STAT_CAP_SIZE); >> + >> + /* hit EOF or hole? */ >> + if (statret == 0 && iocb->ki_pos < inode->i_size && >> + iocb->ki_left) { >> + dout("sync_read hit hole, ppos %lld < size %lld" >> + ", reading more\n", iocb->ki_pos, >> + inode->i_size); >> + >> + read += ret; >> + checkeof = 0; >> + goto again; >> + } >> + } >> + >> + } else >> ret = generic_file_aio_read(iocb, iov, nr_segs, pos); >> >> -out: >> dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", >> inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret); >> ceph_put_cap_refs(ci, got); >> >> - if (checkeof && ret >= 0) { >> - int statret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE); >> - >> - /* hit EOF or hole? */ >> - if (statret == 0 && *ppos < inode->i_size) { >> - dout("aio_read sync_read hit hole, ppos %lld < size %lld, reading more\n", *ppos, inode->i_size); >> - read += ret; >> - base += ret; >> - len -= ret; >> - checkeof = 0; >> - goto again; >> - } >> - } >> if (ret >= 0) >> ret += read; >> >> > Subject: ceph: Implement readv/preadv for sync operation. For readv/preadv sync-operatoin, ceph only do the first iov. It don't think other iovs.Now implement this. V3: modify some bug. V2: -add generic_segment_checks -using struct iov_iter replace cloning the iovs. -return previous successfully copied if ceph_copy_page_vector_to_user met error. Signed-off-by: Jianpeng Ma Reviewed-by: Yan, Zheng --- fs/ceph/file.c | 157 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 106 insertions(+), 51 deletions(-) -- 1.8.3 diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 3de8982..bc7fa52 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,55 +690,67 @@ 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; struct inode *inode = file_inode(filp); struct ceph_inode_info *ci = ceph_inode(inode); - void __user *base = iov->iov_base; ssize_t ret; int want, got = 0; int checkeof = 0, read = 0; dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", inode, ceph_vinop(inode), pos, (unsigned)len, inode); -again: + + ret = generic_segment_checks(iov, &nr_segs, &len, VERIFY_WRITE); + if (ret) + return ret; + if (fi->fmode & CEPH_FILE_MODE_LAZY) want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO; else want = CEPH_CAP_FILE_CACHE; ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, &got, -1); if (ret < 0) - goto out; + return ret; + dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", inode, ceph_vinop(inode), pos, (unsigned)len, ceph_cap_string(got)); if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 || (iocb->ki_filp->f_flags & O_DIRECT) || - (fi->flags & CEPH_F_SYNC)) + (fi->flags & CEPH_F_SYNC)) { + struct iov_iter i; + + iocb->ki_left = len; + iov_iter_init(&i, iov, nr_segs, len, 0); +again: /* hmm, this isn't really async... */ - ret = ceph_sync_read(filp, base, len, ppos, &checkeof); - else + ret = ceph_sync_read(iocb, &i, &checkeof); + + if (checkeof && ret >= 0) { + int statret = ceph_do_getattr(inode, + CEPH_STAT_CAP_SIZE); + + /* hit EOF or hole? */ + if (statret == 0 && iocb->ki_pos < inode->i_size && + iocb->ki_left) { + dout("sync_read hit hole, ppos %lld < size %lld" + ", reading more\n", iocb->ki_pos, + inode->i_size); + + read += ret; + checkeof = 0; + goto again; + } + } + + } else ret = generic_file_aio_read(iocb, iov, nr_segs, pos); -out: dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret); ceph_put_cap_refs(ci, got); - if (checkeof && ret >= 0) { - int statret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE); - - /* hit EOF or hole? */ - if (statret == 0 && *ppos < inode->i_size) { - dout("aio_read sync_read hit hole, ppos %lld < size %lld, reading more\n", *ppos, inode->i_size); - read += ret; - base += ret; - len -= ret; - checkeof = 0; - goto again; - } - } if (ret >= 0) ret += read;