qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	"open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 07/11] nbd/client: refactor nbd_receive_reply
Date: Wed, 30 Aug 2017 13:07:07 -0500	[thread overview]
Message-ID: <20170830180711.7974-8-eblake@redhat.com> (raw)
In-Reply-To: <20170830180711.7974-1-eblake@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

Refactor nbd_receive_reply to return 1 on success, 0 on eof, when no
data was read and <0 for other cases, because returned size of read
data is not actually used.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20170804151440.320927-4-vsementsov@virtuozzo.com>
[eblake: tweak function comments]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 include/block/nbd.h |  2 +-
 nbd/client.c        | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/block/nbd.h b/include/block/nbd.h
index 9c3d0a5868..f7450608b4 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -164,7 +164,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
 int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info,
              Error **errp);
 ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request);
-ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp);
+int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp);
 int nbd_client(int fd);
 int nbd_disconnect(int fd);

diff --git a/nbd/client.c b/nbd/client.c
index 4556056daa..f8c213bc96 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -914,11 +914,16 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)
     return nbd_write(ioc, buf, sizeof(buf), NULL);
 }

-ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
+/* nbd_receive_reply
+ * Returns 1 on success
+ *         0 on eof, when no data was read (errp is not set)
+ *         negative errno on failure (errp is set)
+ */
+int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
 {
     uint8_t buf[NBD_REPLY_SIZE];
     uint32_t magic;
-    ssize_t ret;
+    int ret;

     ret = nbd_read_eof(ioc, buf, sizeof(buf), errp);
     if (ret <= 0) {
@@ -948,6 +953,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
         error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic);
         return -EINVAL;
     }
-    return sizeof(buf);
+
+    return 1;
 }

-- 
2.13.5

  parent reply	other threads:[~2017-08-30 18:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 18:07 [Qemu-devel] [PULL 00/11] NBD patches for 2.11 Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 01/11] qemu-iotests: Extend non-shared storage migration test (194) Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 02/11] nbd-client: avoid read_reply_co entry if send failed Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 03/11] qemu-iotests: improve nbd-fault-injector.py startup protocol Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 04/11] qemu-iotests: test NBD over UNIX domain sockets in 083 Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 05/11] nbd/client: fix nbd_opt_go Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 06/11] nbd/client: refactor nbd_read_eof Eric Blake
2017-08-30 18:07 ` Eric Blake [this message]
2017-08-30 18:07 ` [Qemu-devel] [PULL 08/11] nbd/client: fix nbd_send_request to return int Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 09/11] block/nbd-client: get rid of ssize_t Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 10/11] block/nbd-client: rename nbd_recv_coroutines_enter_all Eric Blake
2017-08-30 18:07 ` [Qemu-devel] [PULL 11/11] block/nbd-client: refactor request send/receive Eric Blake
2017-08-31 14:51 ` [Qemu-devel] [PULL 00/11] NBD patches for 2.11 Peter Maydell

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=20170830180711.7974-8-eblake@redhat.com \
    --to=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 \
    --cc=vsementsov@virtuozzo.com \
    /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).