static int nbd_co_send_request(NbdClientSession *s,

    struct nbd_request *request,

    QEMUIOVector *qiov, int offset)

{

    AioContext *aio_context;

    int rc, ret;



    qemu_co_mutex_lock(&s->send_mutex);

    s->send_coroutine = qemu_coroutine_self();

    aio_context = bdrv_get_aio_context(s->bs);

    aio_set_fd_handler(aio_context, s->sock,

                       nbd_reply_ready, nbd_restart_write, s);

    if (qiov) {

        if (!s->is_unix) {

            socket_set_cork(s->sock, 1);

        }

        rc = nbd_send_request(s->sock, request);

        if (rc >= 0) {

            ret = qemu_co_sendv(s->sock, qiov->iov, qiov->niov,

                                offset, request->len);

            if (ret != request->len) {

                rc = -EIO;

            }

        }

        if (!s->is_unix) {

            socket_set_cork(s->sock, 0);

        }

    } else {

        rc = nbd_send_request(s->sock, request);

    }

    aio_set_fd_handler(aio_context, s->sock, nbd_reply_ready, NULL, s);

    s->send_coroutine = NULL;

    qemu_co_mutex_unlock(&s->send_mutex);

    return rc;

}

static int nbd_co_send_request(NbdClientSession *s,

    struct nbd_request *request,

    QEMUIOVector *qiov, int offset)

{

    AioContext *aio_context;

    int rc, ret;



    qemu_co_mutex_lock(&s->send_mutex);

    s->send_coroutine = qemu_coroutine_self();

    aio_context = bdrv_get_aio_context(s->bs);

    aio_set_fd_handler(aio_context, s->sock,

                       nbd_reply_ready, nbd_restart_write, s);

    if (qiov) {

        if (!s->is_unix) {

            socket_set_cork(s->sock, 1);

        }

        rc = nbd_send_request(s->sock, request);

        if (rc >= 0) {

            ret = qemu_co_sendv(s->sock, qiov->iov, qiov->niov,

                                offset, request->len);

            if (ret != request->len) {

                rc = -EIO;

            }

        }

        if (!s->is_unix) {

            socket_set_cork(s->sock, 0);

        }

    } else {

        rc = nbd_send_request(s->sock, request);

    }

    aio_set_fd_handler(aio_context, s->sock, nbd_reply_ready, NULL, s);

    s->send_coroutine = NULL;

    qemu_co_mutex_unlock(&s->send_mutex);

    return rc;

}

static int FUNC_0(NbdClientSession *VAR_0,

    struct nbd_request *VAR_1,

    QEMUIOVector *VAR_2, int VAR_3)

{

    AioContext *aio_context;

    int VAR_4, VAR_5;



    qemu_co_mutex_lock(&VAR_0->send_mutex);

    VAR_0->send_coroutine = qemu_coroutine_self();

    aio_context = bdrv_get_aio_context(VAR_0->bs);

    aio_set_fd_handler(aio_context, VAR_0->sock,

                       nbd_reply_ready, nbd_restart_write, VAR_0);

    if (VAR_2) {

        if (!VAR_0->is_unix) {

            socket_set_cork(VAR_0->sock, 1);

        }

        VAR_4 = nbd_send_request(VAR_0->sock, VAR_1);

        if (VAR_4 >= 0) {

            VAR_5 = qemu_co_sendv(VAR_0->sock, VAR_2->iov, VAR_2->niov,

                                VAR_3, VAR_1->len);

            if (VAR_5 != VAR_1->len) {

                VAR_4 = -EIO;

            }

        }

        if (!VAR_0->is_unix) {

            socket_set_cork(VAR_0->sock, 0);

        }

    } else {

        VAR_4 = nbd_send_request(VAR_0->sock, VAR_1);

    }

    aio_set_fd_handler(aio_context, VAR_0->sock, nbd_reply_ready, NULL, VAR_0);

    VAR_0->send_coroutine = NULL;

    qemu_co_mutex_unlock(&VAR_0->send_mutex);

    return VAR_4;

}

static int FUNC_0(NbdClientSession *VAR_0,
struct nbd_request *VAR_1,
QEMUIOVector *VAR_2, int VAR_3)
{ AioContext *aio_context; int VAR_4, VAR_5; qemu_co_mutex_lock(&VAR_0->send_mutex); VAR_0->send_coroutine = qemu_coroutine_self(); aio_context = bdrv_get_aio_context(VAR_0->bs); aio_set_fd_handler(aio_context, VAR_0->sock,
nbd_reply_ready, nbd_restart_write, VAR_0); if (VAR_2) { if (!VAR_0->is_unix) { socket_set_cork(VAR_0->sock, 1); } VAR_4 = nbd_send_request(VAR_0->sock, VAR_1); if (VAR_4 >= 0) { VAR_5 = qemu_co_sendv(VAR_0->sock, VAR_2->iov, VAR_2->niov,
VAR_3, VAR_1->len); if (VAR_5 != VAR_1->len) { VAR_4 = -EIO; } } if (!VAR_0->is_unix) { socket_set_cork(VAR_0->sock, 0); } } else { VAR_4 = nbd_send_request(VAR_0->sock, VAR_1); } aio_set_fd_handler(aio_context, VAR_0->sock, nbd_reply_ready, NULL, VAR_0); VAR_0->send_coroutine = NULL; qemu_co_mutex_unlock(&VAR_0->send_mutex); return VAR_4; }