block/nbd-client: assert qiov len once in nbd_co_request

Also improve the assertion: check that qiov is NULL for other commands
than CMD_READ and CMD_WRITE.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171012095319.136610-2-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2017-10-12 12:53:07 +03:00 committed by Eric Blake
parent e8d3eb74bf
commit 4bfe4478d1
1 changed files with 6 additions and 4 deletions

View File

@ -156,7 +156,6 @@ static int nbd_co_send_request(BlockDriverState *bs,
qio_channel_set_cork(s->ioc, true);
rc = nbd_send_request(s->ioc, request);
if (rc >= 0 && !s->quit) {
assert(request->len == iov_size(qiov->iov, qiov->niov));
if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov,
NULL) < 0) {
rc = -EIO;
@ -197,7 +196,6 @@ static int nbd_co_receive_reply(NBDClientSession *s,
assert(s->reply.handle == request->handle);
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) {
ret = -EIO;
@ -231,8 +229,12 @@ static int nbd_co_request(BlockDriverState *bs,
NBDClientSession *client = nbd_get_client_session(bs);
int ret;
assert(!qiov || request->type == NBD_CMD_WRITE ||
request->type == NBD_CMD_READ);
if (qiov) {
assert(request->type == NBD_CMD_WRITE || request->type == NBD_CMD_READ);
assert(request->len == iov_size(qiov->iov, qiov->niov));
} else {
assert(request->type != NBD_CMD_WRITE && request->type != NBD_CMD_READ);
}
ret = nbd_co_send_request(bs, request,
request->type == NBD_CMD_WRITE ? qiov : NULL);
if (ret < 0) {