From patchwork Thu Dec 8 20:59:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9467137 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 D9A036071E for ; Thu, 8 Dec 2016 20:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C684E283E2 for ; Thu, 8 Dec 2016 20:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB72E285F4; Thu, 8 Dec 2016 20:59:23 +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 55FFE283E2 for ; Thu, 8 Dec 2016 20:59:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cF5mk-0007Sl-KD; Thu, 08 Dec 2016 20:59:22 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cF5mj-0007SF-7e for v9fs-developer@lists.sourceforge.net; Thu, 08 Dec 2016 20:59:21 +0000 X-ACL-Warn: Received: from mail.kernel.org ([198.145.29.136]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cF5mi-0003dm-CA for v9fs-developer@lists.sourceforge.net; Thu, 08 Dec 2016 20:59:21 +0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E236D20379; Thu, 8 Dec 2016 20:59:13 +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 B55A82038F; Thu, 8 Dec 2016 20:59:12 +0000 (UTC) From: Stefano Stabellini To: v9fs-developer@lists.sourceforge.net Date: Thu, 8 Dec 2016 12:59:06 -0800 Message-Id: <1481230746-16741-5-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481230746-16741-1-git-send-email-sstabellini@kernel.org> References: <1481230746-16741-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP X-Headers-End: 1cF5mi-0003dm-CA Cc: ericvh@gmail.com, rminnich@sandia.gov, sstabellini@kernel.org, linux-kernel@vger.kernel.org, lucho@ionkov.net Subject: [V9fs-developer] [PATCH 5/5] 9p: introduce async write 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 write is an async operation, send a 9p request and return EIOCBQUEUED. Do not wait for completion. Complete the write operation from a callback instead. Signed-off-by: Stefano Stabellini --- net/9p/client.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index f9f09db..18942b7 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1719,6 +1719,61 @@ int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) } EXPORT_SYMBOL(p9_client_read); +static void +p9_client_write_complete(struct p9_client *clnt, struct p9_req_t *req, int status) +{ + int err, count; + struct file *file; + struct inode *inode; + unsigned long pg_start, pg_end; + loff_t i_size; + + 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); + 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, "<<< RWRITE count %d\n", count); + + if (count > req->rsize) + count = req->rsize; + + err = count; + file = req->kiocb->ki_filp; + inode = file_inode(file); + pg_start = req->kiocb->ki_pos >> PAGE_SHIFT; + pg_end = (req->kiocb->ki_pos + count - 1) >> PAGE_SHIFT; + + if (inode->i_mapping && inode->i_mapping->nrpages) + invalidate_inode_pages2_range(inode->i_mapping, + pg_start, pg_end); + req->kiocb->ki_pos += count; + i_size = i_size_read(inode); + if (req->kiocb->ki_pos > i_size) { + inode_add_bytes(inode, req->kiocb->ki_pos - i_size); + i_size_write(inode, req->kiocb->ki_pos); + } +out: + req->kiocb->ki_complete(req->kiocb, err, 0); + + p9_free_req(clnt, req); +} + int p9_client_write(struct p9_fid *fid, struct kiocb *iocb, u64 offset, struct iov_iter *from, int *err) @@ -1746,9 +1801,32 @@ int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, from, 0, rsize, P9_ZC_HDR_SZ, "dqd", fid->fid, offset, rsize); - } else { + /* sync request */ + } else if(iocb == NULL || is_sync_kiocb(iocb)) { req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid, offset, rsize, from); + /* async request */ + } else { + req = p9_client_get_req(clnt, P9_TWRITE, "dqV", fid->fid, + offset, rsize, from); + if (IS_ERR(req)) { + *err = PTR_ERR(req); + break; + } + req->rsize = rsize; + req->kiocb = iocb; + req->callback = p9_client_write_complete; + + *err = clnt->trans_mod->request(clnt, req); + if (*err < 0) { + clnt->status = Disconnected; + p9_free_req(clnt, req); + break; + } + + iov_iter_advance(from, rsize); + *err = -EIOCBQUEUED; + break; } if (IS_ERR(req)) { *err = PTR_ERR(req);