From patchwork Thu Dec 15 22:13:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9476999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58CCF60828 for ; Thu, 15 Dec 2016 22:14:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 485422885C for ; Thu, 15 Dec 2016 22:14:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D63D28861; Thu, 15 Dec 2016 22:14:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 74BB128862 for ; Thu, 15 Dec 2016 22:14:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cHeI2-0000kU-CU; Thu, 15 Dec 2016 22:14:14 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cHeI0-0000kD-WD for v9fs-developer@lists.sourceforge.net; Thu, 15 Dec 2016 22:14:13 +0000 X-ACL-Warn: Received: from mail.kernel.org ([198.145.29.136]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cHeI0-000606-1T for v9fs-developer@lists.sourceforge.net; Thu, 15 Dec 2016 22:14:12 +0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71060203B0; Thu, 15 Dec 2016 22:14:05 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3ADC02052C; Thu, 15 Dec 2016 22:14:04 +0000 (UTC) From: Stefano Stabellini To: v9fs-developer@lists.sourceforge.net Date: Thu, 15 Dec 2016 14:13:51 -0800 Message-Id: <1481840034-2113-4-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481840034-2113-1-git-send-email-sstabellini@kernel.org> References: <1481840034-2113-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP X-Headers-End: 1cHeI0-000606-1T Cc: ericvh@gmail.com, rminnich@sandia.gov, sstabellini@kernel.org, linux-kernel@vger.kernel.org, lucho@ionkov.net Subject: [V9fs-developer] [PATCH v2 4/7] 9p: introduce async read requests X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP If the read is an async operation, send a 9p request and return EIOCBQUEUED. Do not wait for completion. Complete the read operation from a callback instead. Signed-off-by: Stefano Stabellini --- Changes in v2: - use work_struct to schedule callback - a few variable renames - improve the completion function so that it can be called multiple times on the same request --- net/9p/client.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 0ff1216..c17596f 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1558,13 +1559,74 @@ int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) } EXPORT_SYMBOL(p9_client_unlinkat); +static void +p9_client_read_complete(struct work_struct *work) +{ + struct p9_req_t *req = container_of(work, struct p9_req_t, work); + struct p9_client *clnt = req->fid->clnt; + uint32_t count = 0, n = 0, total = 0; + u64 offset; + int err, i; + char *dataptr, *to; + + if (req->status == REQ_STATUS_ERROR) { + p9_debug(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err); + err = req->t_err; + goto out; + } + err = p9_check_errors(clnt, req); + if (err) + goto out; + + err = p9pdu_readf(req->rc, clnt->proto_version, + "D", &count, &dataptr); + if (err) { + trace_9p_protocol_dump(clnt, req->rc); + goto out; + } + if (!count) { + p9_debug(P9_DEBUG_ERROR, "count=%d\n", count); + err = 0; + goto out; + } + + p9_debug(P9_DEBUG_9P, "<<< RREAD count %d\n", count); + if (count > req->rsize) + count = req->rsize; + + offset = req->page_offset; + total = count; + for (i = offset / PAGE_SIZE; i < ((total + PAGE_SIZE - 1) / PAGE_SIZE); i++) { + to = kmap(req->pagevec[i]); + to += offset; + n = PAGE_SIZE - offset; + if (n > count) + n = count; + else + offset = 0; + memcpy(to, dataptr, n); + kunmap(req->pagevec[i]); + count -= n; + } + + err = total; + req->kiocb->ki_pos += total; + +out: + req->kiocb->ki_complete(req->kiocb, err, 0); + + release_pages(req->pagevec, (req->tot_size + PAGE_SIZE - 1) / PAGE_SIZE, false); + kvfree(req->pagevec); + p9_free_req(clnt, req); +} + int p9_client_read(struct p9_fid *fid, struct kiocb *iocb, u64 offset, struct iov_iter *to, int *err) { struct p9_client *clnt = fid->clnt; struct p9_req_t *req; - int total = 0; + int total = 0, i; *err = 0; p9_debug(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", @@ -1591,10 +1653,41 @@ int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) req = p9_client_zc_rpc(clnt, P9_TREAD, to, NULL, rsize, 0, 11, "dqd", fid->fid, offset, rsize); - } else { + /* sync request */ + } else if(iocb == NULL || is_sync_kiocb(iocb)) { non_zc = 1; req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize); + /* async request */ + } else { + req = p9_client_get_req(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize); + if (IS_ERR(req)) { + *err = PTR_ERR(req); + break; + } + req->fid = fid; + req->file_offset = offset; + req->rsize = rsize; + req->tot_size = iov_iter_get_pages_alloc(to, &req->pagevec, + (size_t)rsize, &req->page_offset); + req->kiocb = iocb; + for (i = 0; i < req->tot_size; i += PAGE_SIZE) + page_cache_get_speculative(req->pagevec[i/PAGE_SIZE]); + INIT_WORK(&req->work, p9_client_read_complete); + + *err = clnt->trans_mod->request(clnt, req); + if (*err < 0) { + clnt->status = Disconnected; + release_pages(req->pagevec, + (req->tot_size + PAGE_SIZE - 1) / PAGE_SIZE, + true); + kvfree(req->pagevec); + p9_free_req(clnt, req); + break; + } + + *err = -EIOCBQUEUED; + break; } if (IS_ERR(req)) { *err = PTR_ERR(req);