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 <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20170920124507.18841-2-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2017-09-20 15:45:05 +03:00 committed by Eric Blake
parent cfa3ad635c
commit 319a56cde7

View File

@ -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,