static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request,

                               struct iovec *iov, int offset)

{

    int rc, ret;



    qemu_co_mutex_lock(&s->send_mutex);

    s->send_coroutine = qemu_coroutine_self();

    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 >= 0 && iov) {

        ret = qemu_co_sendv(s->sock, iov, request->len, offset);

        if (ret != request->len) {

            errno = -EIO;

            rc = -1;

        }

    }

    qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL,

                            nbd_have_request, NULL, s);

    s->send_coroutine = NULL;

    qemu_co_mutex_unlock(&s->send_mutex);

    return rc;

}

static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request,

                               struct iovec *iov, int offset)

{

    int rc, ret;



    qemu_co_mutex_lock(&s->send_mutex);

    s->send_coroutine = qemu_coroutine_self();

    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 >= 0 && iov) {

        ret = qemu_co_sendv(s->sock, iov, request->len, offset);

        if (ret != request->len) {

            errno = -EIO;

            rc = -1;

        }

    }

    qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL,

                            nbd_have_request, NULL, s);

    s->send_coroutine = NULL;

    qemu_co_mutex_unlock(&s->send_mutex);

    return rc;

}

static int FUNC_0(BDRVNBDState *VAR_0, struct nbd_request *VAR_1,

                               struct iovec *VAR_2, int VAR_3)

{

    int VAR_4, VAR_5;



    qemu_co_mutex_lock(&VAR_0->send_mutex);

    VAR_0->send_coroutine = qemu_coroutine_self();

    qemu_aio_set_fd_handler(VAR_0->sock, nbd_reply_ready, nbd_restart_write,

                            nbd_have_request, NULL, VAR_0);

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

    if (VAR_4 >= 0 && VAR_2) {

        VAR_5 = qemu_co_sendv(VAR_0->sock, VAR_2, VAR_1->len, VAR_3);

        if (VAR_5 != VAR_1->len) {

            errno = -EIO;

            VAR_4 = -1;

        }

    }

    qemu_aio_set_fd_handler(VAR_0->sock, nbd_reply_ready, NULL,

                            nbd_have_request, NULL, VAR_0);

    VAR_0->send_coroutine = NULL;

    qemu_co_mutex_unlock(&VAR_0->send_mutex);

    return VAR_4;

}

static int FUNC_0(BDRVNBDState *VAR_0, struct nbd_request *VAR_1,
struct iovec *VAR_2, int VAR_3)
{ int VAR_4, VAR_5; qemu_co_mutex_lock(&VAR_0->send_mutex); VAR_0->send_coroutine = qemu_coroutine_self(); qemu_aio_set_fd_handler(VAR_0->sock, nbd_reply_ready, nbd_restart_write,
nbd_have_request, NULL, VAR_0); VAR_4 = nbd_send_request(VAR_0->sock, VAR_1); if (VAR_4 >= 0 && VAR_2) { VAR_5 = qemu_co_sendv(VAR_0->sock, VAR_2, VAR_1->len, VAR_3); if (VAR_5 != VAR_1->len) { errno = -EIO; VAR_4 = -1; } } qemu_aio_set_fd_handler(VAR_0->sock, nbd_reply_ready, NULL,
nbd_have_request, NULL, VAR_0); VAR_0->send_coroutine = NULL; qemu_co_mutex_unlock(&VAR_0->send_mutex); return VAR_4; }