static int archipelago_submit_request(BDRVArchipelagoState *s,

                                        uint64_t bufidx,

                                        size_t count,

                                        off_t offset,

                                        ArchipelagoAIOCB *aio_cb,

                                        ArchipelagoSegmentedRequest *segreq,

                                        int op)

{

    int ret, targetlen;

    char *target;

    void *data = NULL;

    struct xseg_request *req;

    AIORequestData *reqdata = g_malloc(sizeof(AIORequestData));



    targetlen = strlen(s->volname);

    req = xseg_get_request(s->xseg, s->srcport, s->vportno, X_ALLOC);

    if (!req) {

        archipelagolog("Cannot get XSEG request\n");

        goto err_exit2;

    }

    ret = xseg_prep_request(s->xseg, req, targetlen, count);

    if (ret < 0) {

        archipelagolog("Cannot prepare XSEG request\n");

        goto err_exit;

    }

    target = xseg_get_target(s->xseg, req);

    if (!target) {

        archipelagolog("Cannot get XSEG target\n");

        goto err_exit;

    }

    memcpy(target, s->volname, targetlen);

    req->size = count;

    req->offset = offset;



    switch (op) {

    case ARCHIP_OP_READ:

        req->op = X_READ;

        break;

    case ARCHIP_OP_WRITE:

        req->op = X_WRITE;

        break;

    case ARCHIP_OP_FLUSH:

        req->op = X_FLUSH;

        break;

    }

    reqdata->volname = s->volname;

    reqdata->offset = offset;

    reqdata->size = count;

    reqdata->bufidx = bufidx;

    reqdata->aio_cb = aio_cb;

    reqdata->segreq = segreq;

    reqdata->op = op;



    xseg_set_req_data(s->xseg, req, reqdata);

    if (op == ARCHIP_OP_WRITE) {

        data = xseg_get_data(s->xseg, req);

        if (!data) {

            archipelagolog("Cannot get XSEG data\n");

            goto err_exit;

        }

        qemu_iovec_to_buf(aio_cb->qiov, bufidx, data, count);

    }



    xport p = xseg_submit(s->xseg, req, s->srcport, X_ALLOC);

    if (p == NoPort) {

        archipelagolog("Could not submit XSEG request\n");

        goto err_exit;

    }

    xseg_signal(s->xseg, p);

    return 0;



err_exit:

    g_free(reqdata);

    xseg_put_request(s->xseg, req, s->srcport);

    return -EIO;

err_exit2:

    g_free(reqdata);

    return -EIO;

}

static int archipelago_submit_request(BDRVArchipelagoState *s,

                                        uint64_t bufidx,

                                        size_t count,

                                        off_t offset,

                                        ArchipelagoAIOCB *aio_cb,

                                        ArchipelagoSegmentedRequest *segreq,

                                        int op)

{

    int ret, targetlen;

    char *target;

    void *data = NULL;

    struct xseg_request *req;

    AIORequestData *reqdata = g_malloc(sizeof(AIORequestData));



    targetlen = strlen(s->volname);

    req = xseg_get_request(s->xseg, s->srcport, s->vportno, X_ALLOC);

    if (!req) {

        archipelagolog("Cannot get XSEG request\n");

        goto err_exit2;

    }

    ret = xseg_prep_request(s->xseg, req, targetlen, count);

    if (ret < 0) {

        archipelagolog("Cannot prepare XSEG request\n");

        goto err_exit;

    }

    target = xseg_get_target(s->xseg, req);

    if (!target) {

        archipelagolog("Cannot get XSEG target\n");

        goto err_exit;

    }

    memcpy(target, s->volname, targetlen);

    req->size = count;

    req->offset = offset;



    switch (op) {

    case ARCHIP_OP_READ:

        req->op = X_READ;

        break;

    case ARCHIP_OP_WRITE:

        req->op = X_WRITE;

        break;

    case ARCHIP_OP_FLUSH:

        req->op = X_FLUSH;

        break;

    }

    reqdata->volname = s->volname;

    reqdata->offset = offset;

    reqdata->size = count;

    reqdata->bufidx = bufidx;

    reqdata->aio_cb = aio_cb;

    reqdata->segreq = segreq;

    reqdata->op = op;



    xseg_set_req_data(s->xseg, req, reqdata);

    if (op == ARCHIP_OP_WRITE) {

        data = xseg_get_data(s->xseg, req);

        if (!data) {

            archipelagolog("Cannot get XSEG data\n");

            goto err_exit;

        }

        qemu_iovec_to_buf(aio_cb->qiov, bufidx, data, count);

    }



    xport p = xseg_submit(s->xseg, req, s->srcport, X_ALLOC);

    if (p == NoPort) {

        archipelagolog("Could not submit XSEG request\n");

        goto err_exit;

    }

    xseg_signal(s->xseg, p);

    return 0;



err_exit:

    g_free(reqdata);

    xseg_put_request(s->xseg, req, s->srcport);

    return -EIO;

err_exit2:

    g_free(reqdata);

    return -EIO;

}

    AIORequestData *reqdata = g_malloc(sizeof(AIORequestData));     AIORequestData *reqdata = g_malloc(sizeof(AIORequestData));
static int FUNC_0(BDRVArchipelagoState *VAR_0,

                                        uint64_t VAR_1,

                                        size_t VAR_2,

                                        off_t VAR_3,

                                        ArchipelagoAIOCB *VAR_4,

                                        ArchipelagoSegmentedRequest *VAR_5,

                                        int VAR_6)

{

    int VAR_7, VAR_8;

    char *VAR_9;

    void *VAR_10 = NULL;

    struct xseg_request *VAR_11;

    AIORequestData *reqdata = g_malloc(sizeof(AIORequestData));



    VAR_8 = strlen(VAR_0->volname);

    VAR_11 = xseg_get_request(VAR_0->xseg, VAR_0->srcport, VAR_0->vportno, X_ALLOC);

    if (!VAR_11) {

        archipelagolog("Cannot get XSEG request\n");

        goto err_exit2;

    }

    VAR_7 = xseg_prep_request(VAR_0->xseg, VAR_11, VAR_8, VAR_2);

    if (VAR_7 < 0) {

        archipelagolog("Cannot prepare XSEG request\n");

        goto err_exit;

    }

    VAR_9 = xseg_get_target(VAR_0->xseg, VAR_11);

    if (!VAR_9) {

        archipelagolog("Cannot get XSEG VAR_9\n");

        goto err_exit;

    }

    memcpy(VAR_9, VAR_0->volname, VAR_8);

    VAR_11->size = VAR_2;

    VAR_11->VAR_3 = VAR_3;



    switch (VAR_6) {

    case ARCHIP_OP_READ:

        VAR_11->VAR_6 = X_READ;

        break;

    case ARCHIP_OP_WRITE:

        VAR_11->VAR_6 = X_WRITE;

        break;

    case ARCHIP_OP_FLUSH:

        VAR_11->VAR_6 = X_FLUSH;

        break;

    }

    reqdata->volname = VAR_0->volname;

    reqdata->VAR_3 = VAR_3;

    reqdata->size = VAR_2;

    reqdata->VAR_1 = VAR_1;

    reqdata->VAR_4 = VAR_4;

    reqdata->VAR_5 = VAR_5;

    reqdata->VAR_6 = VAR_6;



    xseg_set_req_data(VAR_0->xseg, VAR_11, reqdata);

    if (VAR_6 == ARCHIP_OP_WRITE) {

        VAR_10 = xseg_get_data(VAR_0->xseg, VAR_11);

        if (!VAR_10) {

            archipelagolog("Cannot get XSEG VAR_10\n");

            goto err_exit;

        }

        qemu_iovec_to_buf(VAR_4->qiov, VAR_1, VAR_10, VAR_2);

    }



    xport p = xseg_submit(VAR_0->xseg, VAR_11, VAR_0->srcport, X_ALLOC);

    if (p == NoPort) {

        archipelagolog("Could not submit XSEG request\n");

        goto err_exit;

    }

    xseg_signal(VAR_0->xseg, p);

    return 0;



err_exit:

    g_free(reqdata);

    xseg_put_request(VAR_0->xseg, VAR_11, VAR_0->srcport);

    return -EIO;

err_exit2:

    g_free(reqdata);

    return -EIO;

}

static int FUNC_0(BDRVArchipelagoState *VAR_0,
uint64_t VAR_1,
size_t VAR_2,
off_t VAR_3,
ArchipelagoAIOCB *VAR_4,
ArchipelagoSegmentedRequest *VAR_5,
int VAR_6)
{ int VAR_7, VAR_8; char *VAR_9; void *VAR_10 = NULL; struct xseg_request *VAR_11; AIORequestData *reqdata = g_malloc(sizeof(AIORequestData)); VAR_8 = strlen(VAR_0->volname); VAR_11 = xseg_get_request(VAR_0->xseg, VAR_0->srcport, VAR_0->vportno, X_ALLOC); if (!VAR_11) { archipelagolog("Cannot get XSEG request\n"); goto err_exit2; } VAR_7 = xseg_prep_request(VAR_0->xseg, VAR_11, VAR_8, VAR_2); if (VAR_7 < 0) { archipelagolog("Cannot prepare XSEG request\n"); goto err_exit; } VAR_9 = xseg_get_target(VAR_0->xseg, VAR_11); if (!VAR_9) { archipelagolog("Cannot get XSEG VAR_9\n"); goto err_exit; } memcpy(VAR_9, VAR_0->volname, VAR_8); VAR_11->size = VAR_2; VAR_11->VAR_3 = VAR_3; switch (VAR_6) { case ARCHIP_OP_READ:
VAR_11->VAR_6 = X_READ; break; case ARCHIP_OP_WRITE:
VAR_11->VAR_6 = X_WRITE; break; case ARCHIP_OP_FLUSH:
VAR_11->VAR_6 = X_FLUSH; break; } reqdata->volname = VAR_0->volname; reqdata->VAR_3 = VAR_3; reqdata->size = VAR_2; reqdata->VAR_1 = VAR_1; reqdata->VAR_4 = VAR_4; reqdata->VAR_5 = VAR_5; reqdata->VAR_6 = VAR_6; xseg_set_req_data(VAR_0->xseg, VAR_11, reqdata); if (VAR_6 == ARCHIP_OP_WRITE) { VAR_10 = xseg_get_data(VAR_0->xseg, VAR_11); if (!VAR_10) { archipelagolog("Cannot get XSEG VAR_10\n"); goto err_exit; } qemu_iovec_to_buf(VAR_4->qiov, VAR_1, VAR_10, VAR_2); } xport p = xseg_submit(VAR_0->xseg, VAR_11, VAR_0->srcport, X_ALLOC); if (p == NoPort) { archipelagolog("Could not submit XSEG request\n"); goto err_exit; } xseg_signal(VAR_0->xseg, p); return 0; err_exit:
g_free(reqdata); xseg_put_request(VAR_0->xseg, VAR_11, VAR_0->srcport); return -EIO; err_exit2:
g_free(reqdata); return -EIO; }