From 319a56cde7313ca42a72e0a145ffa8e7832ada86 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 20 Sep 2017 15:45:05 +0300 Subject: block/nbd-client: refactor nbd_co_receive_reply "NBDReply *reply" parameter of nbd_co_receive_reply is used only to pass return value for nbd_co_request (reply.error). Remove it and use function return value instead. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20170920124507.18841-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'block') diff --git a/block/nbd-client.c b/block/nbd-client.c index cc05e73..5168a2c 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -178,26 +178,26 @@ err: return rc; } -static void nbd_co_receive_reply(NBDClientSession *s, - NBDRequest *request, - NBDReply *reply, - QEMUIOVector *qiov) +static int nbd_co_receive_reply(NBDClientSession *s, + NBDRequest *request, + QEMUIOVector *qiov) { + int ret; int i = HANDLE_TO_INDEX(s, request->handle); /* Wait until we're woken up by nbd_read_reply_entry. */ s->requests[i].receiving = true; qemu_coroutine_yield(); s->requests[i].receiving = false; - *reply = s->reply; - if (reply->handle != request->handle || !s->ioc || s->quit) { - reply->error = EIO; + if (s->reply.handle != request->handle || !s->ioc || s->quit) { + ret = -EIO; } else { - if (qiov && reply->error == 0) { + ret = -s->reply.error; + if (qiov && s->reply.error == 0) { assert(request->len == iov_size(qiov->iov, qiov->niov)); if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { - reply->error = EIO; + ret = -EIO; s->quit = true; } } @@ -217,6 +217,8 @@ static void nbd_co_receive_reply(NBDClientSession *s, s->in_flight--; qemu_co_queue_next(&s->free_sema); qemu_co_mutex_unlock(&s->send_mutex); + + return ret; } static int nbd_co_request(BlockDriverState *bs, @@ -224,7 +226,6 @@ static int nbd_co_request(BlockDriverState *bs, QEMUIOVector *qiov) { NBDClientSession *client = nbd_get_client_session(bs); - NBDReply reply; int ret; assert(!qiov || request->type == NBD_CMD_WRITE || @@ -232,12 +233,11 @@ static int nbd_co_request(BlockDriverState *bs, 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 ret; } - return -reply.error; + + return nbd_co_receive_reply(client, request, + request->type == NBD_CMD_READ ? qiov : NULL); } int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, -- cgit v1.1