int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)

{

    MultiwriteCB *mcb;

    int i;



    /* don't submit writes if we don't have a medium */

    if (bs->drv == NULL) {

        for (i = 0; i < num_reqs; i++) {

            reqs[i].error = -ENOMEDIUM;

        }

        return -1;

    }



    if (num_reqs == 0) {

        return 0;

    }



    // Create MultiwriteCB structure

    mcb = g_malloc0(sizeof(*mcb) + num_reqs * sizeof(*mcb->callbacks));

    mcb->num_requests = 0;

    mcb->num_callbacks = num_reqs;



    for (i = 0; i < num_reqs; i++) {

        mcb->callbacks[i].cb = reqs[i].cb;

        mcb->callbacks[i].opaque = reqs[i].opaque;

    }



    // Check for mergable requests

    num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb);



    trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, num_reqs);



    /* Run the aio requests. */

    mcb->num_requests = num_reqs;

    for (i = 0; i < num_reqs; i++) {

        bdrv_co_aio_rw_vector(bs, reqs[i].sector, reqs[i].qiov,

                              reqs[i].nb_sectors, reqs[i].flags,

                              multiwrite_cb, mcb,

                              true);

    }



    return 0;

}

int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)

{

    MultiwriteCB *mcb;

    int i;



    

    if (bs->drv == NULL) {

        for (i = 0; i < num_reqs; i++) {

            reqs[i].error = -ENOMEDIUM;

        }

        return -1;

    }



    if (num_reqs == 0) {

        return 0;

    }



    

    mcb = g_malloc0(sizeof(*mcb) + num_reqs * sizeof(*mcb->callbacks));

    mcb->num_requests = 0;

    mcb->num_callbacks = num_reqs;



    for (i = 0; i < num_reqs; i++) {

        mcb->callbacks[i].cb = reqs[i].cb;

        mcb->callbacks[i].opaque = reqs[i].opaque;

    }



    

    num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb);



    trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, num_reqs);



    

    mcb->num_requests = num_reqs;

    for (i = 0; i < num_reqs; i++) {

        bdrv_co_aio_rw_vector(bs, reqs[i].sector, reqs[i].qiov,

                              reqs[i].nb_sectors, reqs[i].flags,

                              multiwrite_cb, mcb,

                              true);

    }



    return 0;

}

int FUNC_0(BlockDriverState *VAR_0, BlockRequest *VAR_1, int VAR_2)

{

    MultiwriteCB *mcb;

    int VAR_3;



    

    if (VAR_0->drv == NULL) {

        for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) {

            VAR_1[VAR_3].error = -ENOMEDIUM;

        }

        return -1;

    }



    if (VAR_2 == 0) {

        return 0;

    }



    

    mcb = g_malloc0(sizeof(*mcb) + VAR_2 * sizeof(*mcb->callbacks));

    mcb->num_requests = 0;

    mcb->num_callbacks = VAR_2;



    for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) {

        mcb->callbacks[VAR_3].cb = VAR_1[VAR_3].cb;

        mcb->callbacks[VAR_3].opaque = VAR_1[VAR_3].opaque;

    }



    

    VAR_2 = multiwrite_merge(VAR_0, VAR_1, VAR_2, mcb);



    trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, VAR_2);



    

    mcb->num_requests = VAR_2;

    for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) {

        bdrv_co_aio_rw_vector(VAR_0, VAR_1[VAR_3].sector, VAR_1[VAR_3].qiov,

                              VAR_1[VAR_3].nb_sectors, VAR_1[VAR_3].flags,

                              multiwrite_cb, mcb,

                              true);

    }



    return 0;

}

int FUNC_0(BlockDriverState *VAR_0, BlockRequest *VAR_1, int VAR_2)
{ MultiwriteCB *mcb; int VAR_3; if (VAR_0->drv == NULL) { for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { VAR_1[VAR_3].error = -ENOMEDIUM; } return -1; } if (VAR_2 == 0) { return 0; } mcb = g_malloc0(sizeof(*mcb) + VAR_2 * sizeof(*mcb->callbacks)); mcb->num_requests = 0; mcb->num_callbacks = VAR_2; for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { mcb->callbacks[VAR_3].cb = VAR_1[VAR_3].cb; mcb->callbacks[VAR_3].opaque = VAR_1[VAR_3].opaque; } VAR_2 = multiwrite_merge(VAR_0, VAR_1, VAR_2, mcb); trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, VAR_2); mcb->num_requests = VAR_2; for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { bdrv_co_aio_rw_vector(VAR_0, VAR_1[VAR_3].sector, VAR_1[VAR_3].qiov,
VAR_1[VAR_3].nb_sectors, VAR_1[VAR_3].flags,
multiwrite_cb, mcb,
true); } return 0; }