static coroutine_fn void do_co_req(void *opaque)

{

    int ret;

    Coroutine *co;

    SheepdogReqCo *srco = opaque;

    int sockfd = srco->sockfd;

    SheepdogReq *hdr = srco->hdr;

    void *data = srco->data;

    unsigned int *wlen = srco->wlen;

    unsigned int *rlen = srco->rlen;



    co = qemu_coroutine_self();

    qemu_aio_set_fd_handler(sockfd, NULL, restart_co_req, co);



    ret = send_co_req(sockfd, hdr, data, wlen);

    if (ret < 0) {

        goto out;

    }



    qemu_aio_set_fd_handler(sockfd, restart_co_req, NULL, co);



    ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));

    if (ret < sizeof(*hdr)) {

        error_report("failed to get a rsp, %s", strerror(errno));

        ret = -errno;

        goto out;

    }



    if (*rlen > hdr->data_length) {

        *rlen = hdr->data_length;

    }



    if (*rlen) {

        ret = qemu_co_recv(sockfd, data, *rlen);

        if (ret < *rlen) {

            error_report("failed to get the data, %s", strerror(errno));

            ret = -errno;

            goto out;

        }

    }

    ret = 0;

out:

    /* there is at most one request for this sockfd, so it is safe to

     * set each handler to NULL. */

    qemu_aio_set_fd_handler(sockfd, NULL, NULL, NULL);



    srco->ret = ret;

    srco->finished = true;

}

static coroutine_fn void do_co_req(void *opaque)

{

    int ret;

    Coroutine *co;

    SheepdogReqCo *srco = opaque;

    int sockfd = srco->sockfd;

    SheepdogReq *hdr = srco->hdr;

    void *data = srco->data;

    unsigned int *wlen = srco->wlen;

    unsigned int *rlen = srco->rlen;



    co = qemu_coroutine_self();

    qemu_aio_set_fd_handler(sockfd, NULL, restart_co_req, co);



    ret = send_co_req(sockfd, hdr, data, wlen);

    if (ret < 0) {

        goto out;

    }



    qemu_aio_set_fd_handler(sockfd, restart_co_req, NULL, co);



    ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));

    if (ret < sizeof(*hdr)) {

        error_report("failed to get a rsp, %s", strerror(errno));

        ret = -errno;

        goto out;

    }



    if (*rlen > hdr->data_length) {

        *rlen = hdr->data_length;

    }



    if (*rlen) {

        ret = qemu_co_recv(sockfd, data, *rlen);

        if (ret < *rlen) {

            error_report("failed to get the data, %s", strerror(errno));

            ret = -errno;

            goto out;

        }

    }

    ret = 0;

out:

    



    qemu_aio_set_fd_handler(sockfd, NULL, NULL, NULL);



    srco->ret = ret;

    srco->finished = true;

}

static coroutine_fn void FUNC_0(void *opaque)

{

    int VAR_0;

    Coroutine *co;

    SheepdogReqCo *srco = opaque;

    int VAR_1 = srco->VAR_1;

    SheepdogReq *hdr = srco->hdr;

    void *VAR_2 = srco->VAR_2;

    unsigned int *VAR_3 = srco->VAR_3;

    unsigned int *VAR_4 = srco->VAR_4;



    co = qemu_coroutine_self();

    qemu_aio_set_fd_handler(VAR_1, NULL, restart_co_req, co);



    VAR_0 = send_co_req(VAR_1, hdr, VAR_2, VAR_3);

    if (VAR_0 < 0) {

        goto out;

    }



    qemu_aio_set_fd_handler(VAR_1, restart_co_req, NULL, co);



    VAR_0 = qemu_co_recv(VAR_1, hdr, sizeof(*hdr));

    if (VAR_0 < sizeof(*hdr)) {

        error_report("failed to get a rsp, %s", strerror(errno));

        VAR_0 = -errno;

        goto out;

    }



    if (*VAR_4 > hdr->data_length) {

        *VAR_4 = hdr->data_length;

    }



    if (*VAR_4) {

        VAR_0 = qemu_co_recv(VAR_1, VAR_2, *VAR_4);

        if (VAR_0 < *VAR_4) {

            error_report("failed to get the VAR_2, %s", strerror(errno));

            VAR_0 = -errno;

            goto out;

        }

    }

    VAR_0 = 0;

out:

    



    qemu_aio_set_fd_handler(VAR_1, NULL, NULL, NULL);



    srco->VAR_0 = VAR_0;

    srco->finished = true;

}

static coroutine_fn void FUNC_0(void *opaque)
{ int VAR_0; Coroutine *co; SheepdogReqCo *srco = opaque; int VAR_1 = srco->VAR_1; SheepdogReq *hdr = srco->hdr; void *VAR_2 = srco->VAR_2; unsigned int *VAR_3 = srco->VAR_3; unsigned int *VAR_4 = srco->VAR_4; co = qemu_coroutine_self(); qemu_aio_set_fd_handler(VAR_1, NULL, restart_co_req, co); VAR_0 = send_co_req(VAR_1, hdr, VAR_2, VAR_3); if (VAR_0 < 0) { goto out; } qemu_aio_set_fd_handler(VAR_1, restart_co_req, NULL, co); VAR_0 = qemu_co_recv(VAR_1, hdr, sizeof(*hdr)); if (VAR_0 < sizeof(*hdr)) { error_report("failed to get a rsp, %s", strerror(errno)); VAR_0 = -errno; goto out; } if (*VAR_4 > hdr->data_length) { *VAR_4 = hdr->data_length; } if (*VAR_4) { VAR_0 = qemu_co_recv(VAR_1, VAR_2, *VAR_4); if (VAR_0 < *VAR_4) { error_report("failed to get the VAR_2, %s", strerror(errno)); VAR_0 = -errno; goto out; } } VAR_0 = 0; out:
qemu_aio_set_fd_handler(VAR_1, NULL, NULL, NULL); srco->VAR_0 = VAR_0; srco->finished = true; }