qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com,
	eblake@redhat.com, vsementsov@virtuozzo.com, den@openvz.org
Subject: [Qemu-devel] [PATCH v2 4/7] block/nbd-client: drop reply field from NBDClientSession
Date: Mon,  9 Oct 2017 20:27:13 +0300	[thread overview]
Message-ID: <20171009172723.190282-8-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20171009172723.190282-1-vsementsov@virtuozzo.com>

Drop 'reply' from NBDClientSession. It's used to only deliver request
return code to receiving coroutine. Instead introduce per-request ret
variable to simplify the scheme and make further refactoring possible.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/nbd-client.h |  2 +-
 block/nbd-client.c | 22 +++++++++-------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/block/nbd-client.h b/block/nbd-client.h
index 3f97d31013..4bc8fe3993 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -22,6 +22,7 @@ typedef struct {
     bool receiving;         /* waiting for read_reply_co? */
     NBDRequest *request;
     QEMUIOVector *qiov;
+    int ret;
 } NBDClientRequest;
 
 typedef struct NBDClientSession {
@@ -35,7 +36,6 @@ typedef struct NBDClientSession {
     int in_flight;
 
     NBDClientRequest requests[MAX_NBD_REQUESTS];
-    NBDReply reply;
     bool quit;
 } NBDClientSession;
 
diff --git a/block/nbd-client.c b/block/nbd-client.c
index f7b642f079..f331f08a9a 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -74,10 +74,10 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
     uint64_t i;
     int ret = 0;
     Error *local_err = NULL;
+    NBDReply reply;
 
     while (!s->quit) {
-        assert(s->reply.handle == 0);
-        ret = nbd_receive_reply(s->ioc, &s->reply, &local_err);
+        ret = nbd_receive_reply(s->ioc, &reply, &local_err);
         if (ret < 0) {
             error_report_err(local_err);
         }
@@ -89,18 +89,18 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
          * handler acts as a synchronization point and ensures that only
          * one coroutine is called until the reply finishes.
          */
-        i = HANDLE_TO_INDEX(s, s->reply.handle);
+        i = HANDLE_TO_INDEX(s, reply.handle);
         if (i >= MAX_NBD_REQUESTS ||
             !s->requests[i].coroutine ||
             !s->requests[i].receiving ||
-            s->reply.handle != s->requests[i].request->handle)
+            reply.handle != s->requests[i].request->handle)
         {
             break;
         }
 
-        if (s->reply.error == 0 &&
-            s->requests[i].request->type == NBD_CMD_READ)
-        {
+        s->requests[i].ret = -reply.error;
+
+        if (reply.error == 0 && s->requests[i].request->type == NBD_CMD_READ) {
             QEMUIOVector *qiov = s->requests[i].qiov;
             assert(qiov != NULL);
             assert(s->requests[i].request->len ==
@@ -108,7 +108,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
             if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov,
                                       NULL) < 0)
             {
-                s->reply.error = EIO;
+                s->requests[i].ret = -EIO;
                 break;
             }
         }
@@ -211,11 +211,7 @@ static int nbd_co_receive_reply(NBDClientSession *s, NBDRequest *request)
     if (!s->ioc || s->quit) {
         ret = -EIO;
     } else {
-        assert(s->reply.handle == request->handle);
-        ret = -s->reply.error;
-
-        /* Tell the read handler to read another header.  */
-        s->reply.handle = 0;
+        ret = s->requests[i].ret;
     }
 
     s->requests[i].coroutine = NULL;
-- 
2.11.1

  parent reply	other threads:[~2017-10-09 17:27 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 17:27 [Qemu-devel] [PATCH v2 00/10] nbd minimal structured read Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 01/10] block/nbd-client: assert qiov len once in nbd_co_request Vladimir Sementsov-Ogievskiy
2017-10-09 18:37   ` Eric Blake
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 1/7] block/nbd-client: refactor nbd_co_receive_reply Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit reply-reading coroutine on incorrect handle Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 02/10] block/nbd-client: refactor nbd_co_receive_reply Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 3/7] block/nbd-client: refactor reading reply Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 03/10] nbd: rename NBD_REPLY_MAGIC to NBD_SIMPLE_REPLY_MAGIC Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` Vladimir Sementsov-Ogievskiy [this message]
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 04/10] nbd-server: refactor simple reply sending Vladimir Sementsov-Ogievskiy
2017-10-09 19:18   ` Eric Blake
2017-10-10  8:40     ` Daniel P. Berrange
2017-10-10  9:13       ` Paolo Bonzini
2017-10-11 17:24     ` Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 5/7] block/nbd-client: nbd_co_send_request: return -EIO if s->quit was set in parallel Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 05/10] nbd: header constants indenting Vladimir Sementsov-Ogievskiy
2017-10-09 19:21   ` Eric Blake
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 6/7] block/nbd-client: early fail nbd_read_reply_entry if s->quit is set Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 06/10] nbd: Minimal structured read for server Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 7/7] block/nbd-client: do not yield from nbd_read_reply_entry Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 07/10] nbd/client: refactor nbd_receive_starttls Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 08/10] nbd: share some nbd entities to be reused in block/nbd-client.c Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 09/10] nbd/client: prepare nbd_receive_reply for structured reply Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 10/10] nbd: Minimal structured read for client Vladimir Sementsov-Ogievskiy
2017-10-10  8:02   ` Paolo Bonzini
2017-10-10 14:55     ` Vladimir Sementsov-Ogievskiy
2017-10-10 15:00       ` Paolo Bonzini
2017-10-11  9:22         ` Vladimir Sementsov-Ogievskiy
2017-10-11 16:59     ` Vladimir Sementsov-Ogievskiy
2017-10-10 14:43   ` Vladimir Sementsov-Ogievskiy
2017-10-09 17:33 ` [Qemu-devel] [PATCH v2 00/10] nbd minimal structured read Vladimir Sementsov-Ogievskiy
  -- strict thread matches above, loose matches on Subject: below --
2017-09-18 13:59 [Qemu-devel] [PATCH v2 0/7] nbd client refactoring and fixing Vladimir Sementsov-Ogievskiy
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 4/7] block/nbd-client: drop reply field from NBDClientSession Vladimir Sementsov-Ogievskiy
2017-09-18 22:00   ` Eric Blake

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=20171009172723.190282-8-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).