diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-03-07 11:05:34 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-04-19 16:36:43 +0200 |
commit | fc19f8a02e45c4d8ad24dd7eb374330b03dfc28e (patch) | |
tree | 8e7950d8379ec4d6bf00efc1f800e27fecb1fd04 /block | |
parent | 94e7340b5db8bce7866e44e700ffa8fd26585c7e (diff) | |
download | qemu-fc19f8a02e45c4d8ad24dd7eb374330b03dfc28e.tar.gz qemu-fc19f8a02e45c4d8ad24dd7eb374330b03dfc28e.tar.bz2 qemu-fc19f8a02e45c4d8ad24dd7eb374330b03dfc28e.zip |
nbd: consistently check for <0 or >=0
This prepares for the following patch, which changes -1 return values
to negative errno.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/nbd.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/block/nbd.c b/block/nbd.c index 9972cdb655..25e52689d1 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -197,7 +197,7 @@ static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request, qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, nbd_restart_write, nbd_have_request, NULL, s); rc = nbd_send_request(s->sock, request); - if (rc != -1 && iov) { + if (rc >= 0 && iov) { ret = qemu_co_sendv(s->sock, iov, request->len, offset); if (ret != request->len) { errno = -EIO; @@ -260,7 +260,7 @@ static int nbd_establish_connection(BlockDriverState *bs) } /* Failed to establish connection */ - if (sock == -1) { + if (sock < 0) { logout("Failed to establish connection to NBD server\n"); return -errno; } @@ -268,7 +268,7 @@ static int nbd_establish_connection(BlockDriverState *bs) /* NBD handshake */ ret = nbd_receive_negotiate(sock, s->export_name, &s->nbdflags, &size, &blocksize); - if (ret == -1) { + if (ret < 0) { logout("Failed to negotiate with the NBD server\n"); closesocket(sock); return -errno; @@ -331,13 +331,15 @@ static int nbd_co_readv_1(BlockDriverState *bs, int64_t sector_num, BDRVNBDState *s = bs->opaque; struct nbd_request request; struct nbd_reply reply; + ssize_t ret; request.type = NBD_CMD_READ; request.from = sector_num * 512; request.len = nb_sectors * 512; nbd_coroutine_start(s, &request); - if (nbd_co_send_request(s, &request, NULL, 0) == -1) { + ret = nbd_co_send_request(s, &request, NULL, 0); + if (ret < 0) { reply.error = errno; } else { nbd_co_receive_reply(s, &request, &reply, qiov->iov, offset); @@ -354,6 +356,7 @@ static int nbd_co_writev_1(BlockDriverState *bs, int64_t sector_num, BDRVNBDState *s = bs->opaque; struct nbd_request request; struct nbd_reply reply; + ssize_t ret; request.type = NBD_CMD_WRITE; if (!bdrv_enable_write_cache(bs) && (s->nbdflags & NBD_FLAG_SEND_FUA)) { @@ -364,7 +367,8 @@ static int nbd_co_writev_1(BlockDriverState *bs, int64_t sector_num, request.len = nb_sectors * 512; nbd_coroutine_start(s, &request); - if (nbd_co_send_request(s, &request, qiov->iov, offset) == -1) { + ret = nbd_co_send_request(s, &request, qiov->iov, offset); + if (ret < 0) { reply.error = errno; } else { nbd_co_receive_reply(s, &request, &reply, NULL, 0); @@ -416,6 +420,7 @@ static int nbd_co_flush(BlockDriverState *bs) BDRVNBDState *s = bs->opaque; struct nbd_request request; struct nbd_reply reply; + ssize_t ret; if (!(s->nbdflags & NBD_FLAG_SEND_FLUSH)) { return 0; @@ -430,7 +435,8 @@ static int nbd_co_flush(BlockDriverState *bs) request.len = 0; nbd_coroutine_start(s, &request); - if (nbd_co_send_request(s, &request, NULL, 0) == -1) { + ret = nbd_co_send_request(s, &request, NULL, 0); + if (ret < 0) { reply.error = errno; } else { nbd_co_receive_reply(s, &request, &reply, NULL, 0); @@ -445,6 +451,7 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num, BDRVNBDState *s = bs->opaque; struct nbd_request request; struct nbd_reply reply; + ssize_t ret; if (!(s->nbdflags & NBD_FLAG_SEND_TRIM)) { return 0; @@ -454,7 +461,8 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num, request.len = nb_sectors * 512; nbd_coroutine_start(s, &request); - if (nbd_co_send_request(s, &request, NULL, 0) == -1) { + ret = nbd_co_send_request(s, &request, NULL, 0); + if (ret < 0) { reply.error = errno; } else { nbd_co_receive_reply(s, &request, &reply, NULL, 0); |