summaryrefslogtreecommitdiffstats
path: root/nbd
diff options
context:
space:
mode:
authorPeter Maydell2017-08-31 14:51:40 +0200
committerPeter Maydell2017-08-31 14:51:42 +0200
commit2e75021eb64485f7a7cec98d18f40650516641d0 (patch)
tree738c204041586917bfefb491767b674daa27e6f8 /nbd
parentMerge remote-tracking branch 'remotes/cohuck/tags/s390x-20170830' into staging (diff)
parentblock/nbd-client: refactor request send/receive (diff)
downloadqemu-2e75021eb64485f7a7cec98d18f40650516641d0.tar.gz
qemu-2e75021eb64485f7a7cec98d18f40650516641d0.tar.xz
qemu-2e75021eb64485f7a7cec98d18f40650516641d0.zip
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2017-08-30' into staging
nbd patches for 2017-08-30 - Kashyap Chamarthy: qemu-iotests: Extend non-shared storage migration test (194) - Stefan Hajnaczi: 0/3 nbd-client: enter read_reply_co during init to avoid crash - Vladimir Sementsov-Ogievskiy: portions of 0/17 nbd client refactoring and fixing # gpg: Signature made Wed 30 Aug 2017 19:03:46 BST # gpg: using RSA key 0xA7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" # gpg: aka "[jpeg image of size 6874]" # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * remotes/ericb/tags/pull-nbd-2017-08-30: block/nbd-client: refactor request send/receive block/nbd-client: rename nbd_recv_coroutines_enter_all block/nbd-client: get rid of ssize_t nbd/client: fix nbd_send_request to return int nbd/client: refactor nbd_receive_reply nbd/client: refactor nbd_read_eof nbd/client: fix nbd_opt_go qemu-iotests: test NBD over UNIX domain sockets in 083 qemu-iotests: improve nbd-fault-injector.py startup protocol nbd-client: avoid read_reply_co entry if send failed qemu-iotests: Extend non-shared storage migration test (194) Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'nbd')
-rw-r--r--nbd/client.c21
-rw-r--r--nbd/nbd-internal.h33
2 files changed, 34 insertions, 20 deletions
diff --git a/nbd/client.c b/nbd/client.c
index 0a17de80b5..68a0bc1ffc 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -399,12 +399,10 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
phase, but make sure it sent flags */
if (len) {
error_setg(errp, "server sent invalid NBD_REP_ACK");
- nbd_send_opt_abort(ioc);
return -1;
}
if (!info->flags) {
error_setg(errp, "broken server omitted NBD_INFO_EXPORT");
- nbd_send_opt_abort(ioc);
return -1;
}
trace_nbd_opt_go_success();
@@ -898,7 +896,7 @@ int nbd_disconnect(int fd)
}
#endif
-ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)
+int nbd_send_request(QIOChannel *ioc, NBDRequest *request)
{
uint8_t buf[NBD_REQUEST_SIZE];
@@ -916,22 +914,22 @@ 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) {
return ret;
}
- if (ret != sizeof(buf)) {
- error_setg(errp, "read failed");
- return -EINVAL;
- }
-
/* Reply
[ 0 .. 3] magic (NBD_REPLY_MAGIC)
[ 4 .. 7] error (0 == no error)
@@ -955,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;
}
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
index 396ddb4d3e..03549e3f39 100644
--- a/nbd/nbd-internal.h
+++ b/nbd/nbd-internal.h
@@ -77,21 +77,36 @@
#define NBD_ESHUTDOWN 108
/* nbd_read_eof
- * Tries to read @size bytes from @ioc. Returns number of bytes actually read.
- * May return a value >= 0 and < size only on EOF, i.e. when iteratively called
- * qio_channel_readv() returns 0. So, there is no need to call nbd_read_eof
- * iteratively.
+ * Tries to read @size bytes from @ioc.
+ * Returns 1 on success
+ * 0 on eof, when no data was read (errp is not set)
+ * negative errno on failure (errp is set)
*/
-static inline ssize_t nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size,
- Error **errp)
+static inline int nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size,
+ Error **errp)
{
struct iovec iov = { .iov_base = buffer, .iov_len = size };
+ ssize_t ret;
+
/* Sockets are kept in blocking mode in the negotiation phase. After
* that, a non-readable socket simply means that another thread stole
* our request/reply. Synchronization is done with recv_coroutine, so
* that this is coroutine-safe.
*/
- return nbd_rwv(ioc, &iov, 1, size, true, errp);
+
+ assert(size);
+
+ ret = nbd_rwv(ioc, &iov, 1, size, true, errp);
+ if (ret <= 0) {
+ return ret;
+ }
+
+ if (ret != size) {
+ error_setg(errp, "End of file");
+ return -EINVAL;
+ }
+
+ return 1;
}
/* nbd_read
@@ -100,9 +115,9 @@ static inline ssize_t nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size,
static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
Error **errp)
{
- ssize_t ret = nbd_read_eof(ioc, buffer, size, errp);
+ int ret = nbd_read_eof(ioc, buffer, size, errp);
- if (ret >= 0 && ret != size) {
+ if (ret == 0) {
ret = -EINVAL;
error_setg(errp, "End of file");
}