From 185b43386ad999c80bdc58e41b87f05e5b3e8463 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 5 Mar 2012 08:56:10 +0100 Subject: 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 --- block/nbd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'block/nbd.c') diff --git a/block/nbd.c b/block/nbd.c index 25e5268..1b0e384 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -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); } -- cgit v1.1