int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,

    int nb_clusters)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t cluster_index, refcount;

    uint64_t i;

    int ret;



    assert(nb_clusters >= 0);

    if (nb_clusters == 0) {

        return 0;

    }



    do {

        /* Check how many clusters there are free */

        cluster_index = offset >> s->cluster_bits;

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

            ret = qcow2_get_refcount(bs, cluster_index++, &refcount);

            if (ret < 0) {

                return ret;

            } else if (refcount != 0) {

                break;

            }

        }



        /* And then allocate them */

        ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false,

                              QCOW2_DISCARD_NEVER);

    } while (ret == -EAGAIN);



    if (ret < 0) {

        return ret;

    }



    return i;

}

int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,

    int nb_clusters)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t cluster_index, refcount;

    uint64_t i;

    int ret;



    assert(nb_clusters >= 0);

    if (nb_clusters == 0) {

        return 0;

    }



    do {

        

        cluster_index = offset >> s->cluster_bits;

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

            ret = qcow2_get_refcount(bs, cluster_index++, &refcount);

            if (ret < 0) {

                return ret;

            } else if (refcount != 0) {

                break;

            }

        }



        

        ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false,

                              QCOW2_DISCARD_NEVER);

    } while (ret == -EAGAIN);



    if (ret < 0) {

        return ret;

    }



    return i;

}

int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

    int VAR_2)

{

    BDRVQcow2State *s = VAR_0->opaque;

    uint64_t cluster_index, refcount;

    uint64_t i;

    int VAR_3;



    assert(VAR_2 >= 0);

    if (VAR_2 == 0) {

        return 0;

    }



    do {

        

        cluster_index = VAR_1 >> s->cluster_bits;

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

            VAR_3 = qcow2_get_refcount(VAR_0, cluster_index++, &refcount);

            if (VAR_3 < 0) {

                return VAR_3;

            } else if (refcount != 0) {

                break;

            }

        }



        

        VAR_3 = update_refcount(VAR_0, VAR_1, i << s->cluster_bits, 1, false,

                              QCOW2_DISCARD_NEVER);

    } while (VAR_3 == -EAGAIN);



    if (VAR_3 < 0) {

        return VAR_3;

    }



    return i;

}

int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
int VAR_2)
{ BDRVQcow2State *s = VAR_0->opaque; uint64_t cluster_index, refcount; uint64_t i; int VAR_3; assert(VAR_2 >= 0); if (VAR_2 == 0) { return 0; } do { cluster_index = VAR_1 >> s->cluster_bits; for(i = 0; i < VAR_2; i++) { VAR_3 = qcow2_get_refcount(VAR_0, cluster_index++, &refcount); if (VAR_3 < 0) { return VAR_3; } else if (refcount != 0) { break; } } VAR_3 = update_refcount(VAR_0, VAR_1, i << s->cluster_bits, 1, false,
QCOW2_DISCARD_NEVER); } while (VAR_3 == -EAGAIN); if (VAR_3 < 0) { return VAR_3; } return i; }