static int zero_single_l2(BlockDriverState *bs, uint64_t offset,

    unsigned int nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t *l2_table;

    int l2_index;

    int ret;

    int i;



    ret = get_cluster_table(bs, offset, &l2_table, &l2_index);

    if (ret < 0) {

        return ret;

    }



    /* Limit nb_clusters to one L2 table */

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);



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

        uint64_t old_offset;



        old_offset = be64_to_cpu(l2_table[l2_index + i]);



        /* Update L2 entries */

        qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);

        if (old_offset & QCOW_OFLAG_COMPRESSED) {

            l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);

            qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);

        } else {

            l2_table[l2_index + i] |= cpu_to_be64(QCOW_OFLAG_ZERO);

        }

    }



    ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);

    if (ret < 0) {

        return ret;

    }



    return nb_clusters;

}

static int zero_single_l2(BlockDriverState *bs, uint64_t offset,

    unsigned int nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t *l2_table;

    int l2_index;

    int ret;

    int i;



    ret = get_cluster_table(bs, offset, &l2_table, &l2_index);

    if (ret < 0) {

        return ret;

    }



    

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);



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

        uint64_t old_offset;



        old_offset = be64_to_cpu(l2_table[l2_index + i]);



        

        qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);

        if (old_offset & QCOW_OFLAG_COMPRESSED) {

            l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);

            qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);

        } else {

            l2_table[l2_index + i] |= cpu_to_be64(QCOW_OFLAG_ZERO);

        }

    }



    ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);

    if (ret < 0) {

        return ret;

    }



    return nb_clusters;

}

static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

    unsigned int VAR_2)

{

    BDRVQcowState *s = VAR_0->opaque;

    uint64_t *l2_table;

    int VAR_3;

    int VAR_4;

    int VAR_5;



    VAR_4 = get_cluster_table(VAR_0, VAR_1, &l2_table, &VAR_3);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    

    VAR_2 = MIN(VAR_2, s->l2_size - VAR_3);



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

        uint64_t old_offset;



        old_offset = be64_to_cpu(l2_table[VAR_3 + VAR_5]);



        

        qcow2_cache_entry_mark_dirty(VAR_0, s->l2_table_cache, l2_table);

        if (old_offset & QCOW_OFLAG_COMPRESSED) {

            l2_table[VAR_3 + VAR_5] = cpu_to_be64(QCOW_OFLAG_ZERO);

            qcow2_free_any_clusters(VAR_0, old_offset, 1, QCOW2_DISCARD_REQUEST);

        } else {

            l2_table[VAR_3 + VAR_5] |= cpu_to_be64(QCOW_OFLAG_ZERO);

        }

    }



    VAR_4 = qcow2_cache_put(VAR_0, s->l2_table_cache, (void**) &l2_table);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    return VAR_2;

}

static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
unsigned int VAR_2)
{ BDRVQcowState *s = VAR_0->opaque; uint64_t *l2_table; int VAR_3; int VAR_4; int VAR_5; VAR_4 = get_cluster_table(VAR_0, VAR_1, &l2_table, &VAR_3); if (VAR_4 < 0) { return VAR_4; } VAR_2 = MIN(VAR_2, s->l2_size - VAR_3); for (VAR_5 = 0; VAR_5 < VAR_2; VAR_5++) { uint64_t old_offset; old_offset = be64_to_cpu(l2_table[VAR_3 + VAR_5]); qcow2_cache_entry_mark_dirty(VAR_0, s->l2_table_cache, l2_table); if (old_offset & QCOW_OFLAG_COMPRESSED) { l2_table[VAR_3 + VAR_5] = cpu_to_be64(QCOW_OFLAG_ZERO); qcow2_free_any_clusters(VAR_0, old_offset, 1, QCOW2_DISCARD_REQUEST); } else { l2_table[VAR_3 + VAR_5] |= cpu_to_be64(QCOW_OFLAG_ZERO); } } VAR_4 = qcow2_cache_put(VAR_0, s->l2_table_cache, (void**) &l2_table); if (VAR_4 < 0) { return VAR_4; } return VAR_2; }