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;

    if (s->reply.handle != request->handle || !s->ioc || s->quit) {

        ret = -EIO;

    } else {

        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;

                s->quit = true;

            }

        }



        /* Tell the read handler to read another header.  */

        s->reply.handle = 0;

    }



    s->requests[i].coroutine = NULL;



    /* Kick the read_reply_co to get the next reply.  */

    if (s->read_reply_co) {

        aio_co_wake(s->read_reply_co);

    }



    qemu_co_mutex_lock(&s->send_mutex);

    s->in_flight--;

    qemu_co_queue_next(&s->free_sema);

    qemu_co_mutex_unlock(&s->send_mutex);



    return ret;

}

static int nbd_co_receive_reply(NBDClientSession *s,

                                NBDRequest *request,

                                QEMUIOVector *qiov)

{

    int ret;

    int i = HANDLE_TO_INDEX(s, request->handle);



    

    s->requests[i].receiving = true;

    qemu_coroutine_yield();

    s->requests[i].receiving = false;

    if (s->reply.handle != request->handle || !s->ioc || s->quit) {

        ret = -EIO;

    } else {

        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;

                s->quit = true;

            }

        }



        

        s->reply.handle = 0;

    }



    s->requests[i].coroutine = NULL;



    

    if (s->read_reply_co) {

        aio_co_wake(s->read_reply_co);

    }



    qemu_co_mutex_lock(&s->send_mutex);

    s->in_flight--;

    qemu_co_queue_next(&s->free_sema);

    qemu_co_mutex_unlock(&s->send_mutex);



    return ret;

}

static int FUNC_0(NBDClientSession *VAR_0,

                                NBDRequest *VAR_1,

                                QEMUIOVector *VAR_2)

{

    int VAR_3;

    int VAR_4 = HANDLE_TO_INDEX(VAR_0, VAR_1->handle);



    

    VAR_0->requests[VAR_4].receiving = true;

    qemu_coroutine_yield();

    VAR_0->requests[VAR_4].receiving = false;

    if (VAR_0->reply.handle != VAR_1->handle || !VAR_0->ioc || VAR_0->quit) {

        VAR_3 = -EIO;

    } else {

        VAR_3 = -VAR_0->reply.error;

        if (VAR_2 && VAR_0->reply.error == 0) {

            assert(VAR_1->len == iov_size(VAR_2->iov, VAR_2->niov));

            if (qio_channel_readv_all(VAR_0->ioc, VAR_2->iov, VAR_2->niov,

                                      NULL) < 0) {

                VAR_3 = -EIO;

                VAR_0->quit = true;

            }

        }



        

        VAR_0->reply.handle = 0;

    }



    VAR_0->requests[VAR_4].coroutine = NULL;



    

    if (VAR_0->read_reply_co) {

        aio_co_wake(VAR_0->read_reply_co);

    }



    qemu_co_mutex_lock(&VAR_0->send_mutex);

    VAR_0->in_flight--;

    qemu_co_queue_next(&VAR_0->free_sema);

    qemu_co_mutex_unlock(&VAR_0->send_mutex);



    return VAR_3;

}

static int FUNC_0(NBDClientSession *VAR_0,
NBDRequest *VAR_1,
QEMUIOVector *VAR_2)
{ int VAR_3; int VAR_4 = HANDLE_TO_INDEX(VAR_0, VAR_1->handle); VAR_0->requests[VAR_4].receiving = true; qemu_coroutine_yield(); VAR_0->requests[VAR_4].receiving = false; if (VAR_0->reply.handle != VAR_1->handle || !VAR_0->ioc || VAR_0->quit) { VAR_3 = -EIO; } else { VAR_3 = -VAR_0->reply.error; if (VAR_2 && VAR_0->reply.error == 0) { assert(VAR_1->len == iov_size(VAR_2->iov, VAR_2->niov)); if (qio_channel_readv_all(VAR_0->ioc, VAR_2->iov, VAR_2->niov,
NULL) < 0) { VAR_3 = -EIO; VAR_0->quit = true; } } VAR_0->reply.handle = 0; } VAR_0->requests[VAR_4].coroutine = NULL; if (VAR_0->read_reply_co) { aio_co_wake(VAR_0->read_reply_co); } qemu_co_mutex_lock(&VAR_0->send_mutex); VAR_0->in_flight--; qemu_co_queue_next(&VAR_0->free_sema); qemu_co_mutex_unlock(&VAR_0->send_mutex); return VAR_3; }