[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 15/17] block/nbd-client: refactor reading reply
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH 15/17] block/nbd-client: refactor reading reply |
Date: |
Fri, 4 Aug 2017 18:14:38 +0300 |
Read the whole reply in one place - in nbd_read_reply_entry.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/nbd-client.h | 1 +
block/nbd-client.c | 27 +++++++++++++--------------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/block/nbd-client.h b/block/nbd-client.h
index aa36be8950..0f84ccc073 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -30,6 +30,7 @@ typedef struct NBDClientSession {
struct {
Coroutine *co;
NBDRequest *request;
+ QEMUIOVector *qiov;
} requests[MAX_NBD_REQUESTS];
NBDReply reply;
} NBDClientSession;
diff --git a/block/nbd-client.c b/block/nbd-client.c
index 0e12db4be3..61780c5df9 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -94,6 +94,18 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
break;
}
+ if (s->reply.error == 0 &&
+ s->requests[i].request->type == NBD_CMD_READ)
+ {
+ assert(s->requests[i].qiov != NULL);
+ ret = nbd_rwv(s->ioc, s->requests[i].qiov->iov,
+ s->requests[i].qiov->niov,
+ s->requests[i].request->len, true, NULL);
+ if (ret != s->requests[i].request->len) {
+ break;
+ }
+ }
+
/* We're woken up by the receiving coroutine itself. Note that there
* is no race between yielding and reentering read_reply_co. This
* is because:
@@ -138,6 +150,7 @@ static int nbd_co_request(BlockDriverState *bs,
assert(i < MAX_NBD_REQUESTS);
request->handle = INDEX_TO_HANDLE(s, i);
s->requests[i].request = request;
+ s->requests[i].qiov = qiov;
if (!s->ioc) {
qemu_co_mutex_unlock(&s->send_mutex);
@@ -165,12 +178,6 @@ static int nbd_co_request(BlockDriverState *bs,
goto out;
}
- if (request->type == NBD_CMD_READ) {
- assert(qiov != NULL);
- } else {
- qiov = NULL;
- }
-
/* Wait until we're woken up by nbd_read_reply_entry. */
qemu_coroutine_yield();
if (!s->ioc || s->reply.handle == 0) {
@@ -180,14 +187,6 @@ static int nbd_co_request(BlockDriverState *bs,
assert(s->reply.handle == request->handle);
- if (qiov && s->reply.error == 0) {
- ret = nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, true, NULL);
- if (ret != request->len) {
- rc = -EIO;
- goto out;
- }
- }
-
rc = -s->reply.error;
out:
--
2.11.1
- Re: [Qemu-block] [PATCH 07/17] block/nbd-client: refactor request send/receive, (continued)
- [Qemu-block] [PATCH 11/17] block/nbd-client: fix nbd_co_request: set s->reply.handle to 0 on error, Vladimir Sementsov-Ogievskiy, 2017/08/04
- [Qemu-block] [PATCH 08/17] block/nbd-client: rename nbd_recv_coroutines_enter_all, Vladimir Sementsov-Ogievskiy, 2017/08/04
- [Qemu-block] [PATCH 09/17] block/nbd-client: move nbd_co_receive_reply content into nbd_co_request, Vladimir Sementsov-Ogievskiy, 2017/08/04
- [Qemu-block] [PATCH 15/17] block/nbd-client: refactor reading reply,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH 01/17] nbd/client: fix nbd_opt_go, Vladimir Sementsov-Ogievskiy, 2017/08/04
- [Qemu-block] [PATCH 05/17] block/nbd-client: get rid of ssize_t, Vladimir Sementsov-Ogievskiy, 2017/08/04
- Re: [Qemu-block] [PATCH 05/17] block/nbd-client: get rid of ssize_t, Eric Blake, 2017/08/25
- [Qemu-block] [PATCH 02/17] nbd/client: refactor nbd_read_eof, Vladimir Sementsov-Ogievskiy, 2017/08/04