diff options
author | Peter Maydell | 2017-08-31 14:51:40 +0200 |
---|---|---|
committer | Peter Maydell | 2017-08-31 14:51:42 +0200 |
commit | 2e75021eb64485f7a7cec98d18f40650516641d0 (patch) | |
tree | 738c204041586917bfefb491767b674daa27e6f8 /block | |
parent | Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20170830' into staging (diff) | |
parent | block/nbd-client: refactor request send/receive (diff) | |
download | qemu-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 'block')
-rw-r--r-- | block/nbd-client.c | 102 |
1 files changed, 37 insertions, 65 deletions
diff --git a/block/nbd-client.c b/block/nbd-client.c index 25bcaa2346..f0dbea24d3 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -34,7 +34,7 @@ #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs)) #define INDEX_TO_HANDLE(bs, index) ((index) ^ ((uint64_t)(intptr_t)bs)) -static void nbd_recv_coroutines_enter_all(NBDClientSession *s) +static void nbd_recv_coroutines_wake_all(NBDClientSession *s) { int i; @@ -112,7 +112,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) } s->quit = true; - nbd_recv_coroutines_enter_all(s); + nbd_recv_coroutines_wake_all(s); s->read_reply_co = NULL; } @@ -144,12 +144,12 @@ static int nbd_co_send_request(BlockDriverState *bs, request->handle = INDEX_TO_HANDLE(s, i); if (s->quit) { - qemu_co_mutex_unlock(&s->send_mutex); - return -EIO; + rc = -EIO; + goto err; } if (!s->ioc) { - qemu_co_mutex_unlock(&s->send_mutex); - return -EPIPE; + rc = -EPIPE; + goto err; } if (qiov) { @@ -166,8 +166,13 @@ static int nbd_co_send_request(BlockDriverState *bs, } else { rc = nbd_send_request(s->ioc, request); } + +err: if (rc < 0) { s->quit = true; + s->requests[i].coroutine = NULL; + s->in_flight--; + qemu_co_queue_next(&s->free_sema); } qemu_co_mutex_unlock(&s->send_mutex); return rc; @@ -201,13 +206,6 @@ static void nbd_co_receive_reply(NBDClientSession *s, /* Tell the read handler to read another header. */ s->reply.handle = 0; } -} - -static void nbd_coroutine_end(BlockDriverState *bs, - NBDRequest *request) -{ - NBDClientSession *s = nbd_get_client_session(bs); - int i = HANDLE_TO_INDEX(s, request->handle); s->requests[i].coroutine = NULL; @@ -222,29 +220,40 @@ static void nbd_coroutine_end(BlockDriverState *bs, qemu_co_mutex_unlock(&s->send_mutex); } +static int nbd_co_request(BlockDriverState *bs, + NBDRequest *request, + QEMUIOVector *qiov) +{ + NBDClientSession *client = nbd_get_client_session(bs); + NBDReply reply; + int ret; + + assert(!qiov || request->type == NBD_CMD_WRITE || + request->type == NBD_CMD_READ); + ret = nbd_co_send_request(bs, request, + request->type == NBD_CMD_WRITE ? qiov : NULL); + if (ret < 0) { + reply.error = -ret; + } else { + nbd_co_receive_reply(client, request, &reply, + request->type == NBD_CMD_READ ? qiov : NULL); + } + return -reply.error; +} + int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { - NBDClientSession *client = nbd_get_client_session(bs); NBDRequest request = { .type = NBD_CMD_READ, .from = offset, .len = bytes, }; - NBDReply reply; - ssize_t ret; assert(bytes <= NBD_MAX_BUFFER_SIZE); assert(!flags); - ret = nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error = -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, qiov); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, qiov); } int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, @@ -256,8 +265,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, .from = offset, .len = bytes, }; - NBDReply reply; - ssize_t ret; if (flags & BDRV_REQ_FUA) { assert(client->info.flags & NBD_FLAG_SEND_FUA); @@ -266,27 +273,18 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, assert(bytes <= NBD_MAX_BUFFER_SIZE); - ret = nbd_co_send_request(bs, &request, qiov); - if (ret < 0) { - reply.error = -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, qiov); } int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - ssize_t ret; NBDClientSession *client = nbd_get_client_session(bs); NBDRequest request = { .type = NBD_CMD_WRITE_ZEROES, .from = offset, .len = bytes, }; - NBDReply reply; if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; @@ -300,22 +298,13 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, request.flags |= NBD_CMD_FLAG_NO_HOLE; } - ret = nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error = -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, NULL); } int nbd_client_co_flush(BlockDriverState *bs) { NBDClientSession *client = nbd_get_client_session(bs); NBDRequest request = { .type = NBD_CMD_FLUSH }; - NBDReply reply; - ssize_t ret; if (!(client->info.flags & NBD_FLAG_SEND_FLUSH)) { return 0; @@ -324,14 +313,7 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from = 0; request.len = 0; - ret = nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error = -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, NULL); } int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) @@ -342,22 +324,12 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) .from = offset, .len = bytes, }; - NBDReply reply; - ssize_t ret; if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; } - ret = nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error = -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; - + return nbd_co_request(bs, &request, NULL); } void nbd_client_detach_aio_context(BlockDriverState *bs) |