int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,

    int nb_sectors, enum qcow2_discard_type type, bool full_discard)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t end_offset;

    uint64_t nb_clusters;

    int ret;



    end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);



    /* Round start up and end down */

    offset = align_offset(offset, s->cluster_size);

    end_offset = start_of_cluster(s, end_offset);



    if (offset > end_offset) {

        return 0;

    }



    nb_clusters = size_to_clusters(s, end_offset - offset);



    s->cache_discards = true;



    /* Each L2 table is handled by its own loop iteration */

    while (nb_clusters > 0) {

        ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);

        if (ret < 0) {

            goto fail;

        }



        nb_clusters -= ret;

        offset += (ret * s->cluster_size);

    }



    ret = 0;

fail:

    s->cache_discards = false;

    qcow2_process_discards(bs, ret);



    return ret;

}

int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,

    int nb_sectors, enum qcow2_discard_type type, bool full_discard)

{

    BDRVQcow2State *s = bs->opaque;

    uint64_t end_offset;

    uint64_t nb_clusters;

    int ret;



    end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);



    

    offset = align_offset(offset, s->cluster_size);

    end_offset = start_of_cluster(s, end_offset);



    if (offset > end_offset) {

        return 0;

    }



    nb_clusters = size_to_clusters(s, end_offset - offset);



    s->cache_discards = true;



    

    while (nb_clusters > 0) {

        ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);

        if (ret < 0) {

            goto fail;

        }



        nb_clusters -= ret;

        offset += (ret * s->cluster_size);

    }



    ret = 0;

fail:

    s->cache_discards = false;

    qcow2_process_discards(bs, ret);



    return ret;

}

    offset = align_offset(offset, s->cluster_size);     end_offset = start_of_cluster(s, end_offset);     if (offset > end_offset) {         return 0;
int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

    int VAR_2, enum qcow2_discard_type VAR_3, bool VAR_4)

{

    BDRVQcow2State *s = VAR_0->opaque;

    uint64_t end_offset;

    uint64_t nb_clusters;

    int VAR_5;



    end_offset = VAR_1 + (VAR_2 << BDRV_SECTOR_BITS);



    

    VAR_1 = align_offset(VAR_1, s->cluster_size);

    end_offset = start_of_cluster(s, end_offset);



    if (VAR_1 > end_offset) {

        return 0;

    }



    nb_clusters = size_to_clusters(s, end_offset - VAR_1);



    s->cache_discards = true;



    

    while (nb_clusters > 0) {

        VAR_5 = discard_single_l2(VAR_0, VAR_1, nb_clusters, VAR_3, VAR_4);

        if (VAR_5 < 0) {

            goto fail;

        }



        nb_clusters -= VAR_5;

        VAR_1 += (VAR_5 * s->cluster_size);

    }



    VAR_5 = 0;

fail:

    s->cache_discards = false;

    qcow2_process_discards(VAR_0, VAR_5);



    return VAR_5;

}

int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
int VAR_2, enum qcow2_discard_type VAR_3, bool VAR_4)
{ BDRVQcow2State *s = VAR_0->opaque; uint64_t end_offset; uint64_t nb_clusters; int VAR_5; end_offset = VAR_1 + (VAR_2 << BDRV_SECTOR_BITS); VAR_1 = align_offset(VAR_1, s->cluster_size); end_offset = start_of_cluster(s, end_offset); if (VAR_1 > end_offset) { return 0; } nb_clusters = size_to_clusters(s, end_offset - VAR_1); s->cache_discards = true; while (nb_clusters > 0) { VAR_5 = discard_single_l2(VAR_0, VAR_1, nb_clusters, VAR_3, VAR_4); if (VAR_5 < 0) { goto fail; } nb_clusters -= VAR_5; VAR_1 += (VAR_5 * s->cluster_size); } VAR_5 = 0; fail:
s->cache_discards = false; qcow2_process_discards(VAR_0, VAR_5); return VAR_5; }