mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: v9fs-developer@lists.sourceforge.net
Cc: sstabellini@kernel.org, ericvh@gmail.com, rminnich@sandia.gov,
	lucho@ionkov.net, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/7] 9p: introduce async read requests
Date: Thu, 15 Dec 2016 14:13:51 -0800	[thread overview]
Message-ID: <1481840034-2113-4-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <1481840034-2113-1-git-send-email-sstabellini@kernel.org>

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 <sstabellini@kernel.org>

---

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 <linux/module.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/pagemap.h>
 #include <linux/poll.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
@@ -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);
-- 
1.9.1

  parent reply	other threads:[~2016-12-15 22:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-15 22:12 [PATCH v2 0/7] async requests support for 9pfs Stefano Stabellini
2016-12-15 22:13 ` [PATCH v2 1/7] 9p: add iocb parameter to p9_client_read and p9_client_write Stefano Stabellini
2016-12-15 22:13   ` [PATCH v2 2/7] 9p: store req details and workqueue in struct p9_req_t Stefano Stabellini
2016-12-15 22:13   ` [PATCH v2 3/7] 9p: introduce p9_client_get_req Stefano Stabellini
2016-12-15 22:13   ` Stefano Stabellini [this message]
2016-12-15 22:13   ` [PATCH v2 5/7] 9p: introduce async write requests Stefano Stabellini
2016-12-15 22:13   ` [PATCH v2 6/7] 9p: handle large aio read requests Stefano Stabellini
2016-12-15 22:13   ` [PATCH v2 7/7] 9p: handle large aio write requests Stefano Stabellini
2017-01-03 23:37 ` [PATCH v2 0/7] async requests support for 9pfs Stefano Stabellini
2017-02-17  1:00   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481840034-2113-4-git-send-email-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=ericvh@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=rminnich@sandia.gov \
    --cc=v9fs-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome