nbd: consistently return negative errno values

In the next patch we need to look at the return code of nbd_wr_sync.
To avoid percolating the socket_error() ugliness all around, let's
handle errors by returning negative errno values.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2012-03-05 08:56:10 +01:00
parent fc19f8a02e
commit 185b43386a
4 changed files with 93 additions and 96 deletions

View file

@ -200,8 +200,7 @@ static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request,
if (rc >= 0 && iov) {
ret = qemu_co_sendv(s->sock, iov, request->len, offset);
if (ret != request->len) {
errno = -EIO;
rc = -1;
return -EIO;
}
}
qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL,
@ -271,7 +270,7 @@ static int nbd_establish_connection(BlockDriverState *bs)
if (ret < 0) {
logout("Failed to negotiate with the NBD server\n");
closesocket(sock);
return -errno;
return ret;
}
/* Now that we're connected, set the socket to be non-blocking and
@ -340,7 +339,7 @@ static int nbd_co_readv_1(BlockDriverState *bs, int64_t sector_num,
nbd_coroutine_start(s, &request);
ret = nbd_co_send_request(s, &request, NULL, 0);
if (ret < 0) {
reply.error = errno;
reply.error = -ret;
} else {
nbd_co_receive_reply(s, &request, &reply, qiov->iov, offset);
}
@ -369,7 +368,7 @@ static int nbd_co_writev_1(BlockDriverState *bs, int64_t sector_num,
nbd_coroutine_start(s, &request);
ret = nbd_co_send_request(s, &request, qiov->iov, offset);
if (ret < 0) {
reply.error = errno;
reply.error = -ret;
} else {
nbd_co_receive_reply(s, &request, &reply, NULL, 0);
}
@ -437,7 +436,7 @@ static int nbd_co_flush(BlockDriverState *bs)
nbd_coroutine_start(s, &request);
ret = nbd_co_send_request(s, &request, NULL, 0);
if (ret < 0) {
reply.error = errno;
reply.error = -ret;
} else {
nbd_co_receive_reply(s, &request, &reply, NULL, 0);
}
@ -463,7 +462,7 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num,
nbd_coroutine_start(s, &request);
ret = nbd_co_send_request(s, &request, NULL, 0);
if (ret < 0) {
reply.error = errno;
reply.error = -ret;
} else {
nbd_co_receive_reply(s, &request, &reply, NULL, 0);
}