static int l2_load(BlockDriverState *bs, uint64_t l2_offset,

    uint64_t **l2_table)

{

    BDRVQcowState *s = bs->opaque;

    int min_index;

    int ret;



    /* seek if the table for the given offset is in the cache */



    *l2_table = seek_l2_table(s, l2_offset);

    if (*l2_table != NULL) {

        return 0;

    }



    /* not found: load a new entry in the least used one */



    min_index = l2_cache_new_entry(bs);

    *l2_table = s->l2_cache + (min_index << s->l2_bits);



    BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);

    ret = bdrv_pread(bs->file, l2_offset, *l2_table,

        s->l2_size * sizeof(uint64_t));

    if (ret < 0) {


        return ret;

    }



    s->l2_cache_offsets[min_index] = l2_offset;

    s->l2_cache_counts[min_index] = 1;



    return 0;

}
static int l2_load(BlockDriverState *bs, uint64_t l2_offset,

    uint64_t **l2_table)

{

    BDRVQcowState *s = bs->opaque;

    int min_index;

    int ret;



    



    *l2_table = seek_l2_table(s, l2_offset);

    if (*l2_table != NULL) {

        return 0;

    }



    



    min_index = l2_cache_new_entry(bs);

    *l2_table = s->l2_cache + (min_index << s->l2_bits);



    BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);

    ret = bdrv_pread(bs->file, l2_offset, *l2_table,

        s->l2_size * sizeof(uint64_t));

    if (ret < 0) {


        return ret;

    }



    s->l2_cache_offsets[min_index] = l2_offset;

    s->l2_cache_counts[min_index] = 1;



    return 0;

}
static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

    uint64_t **VAR_2)

{

    BDRVQcowState *s = VAR_0->opaque;

    int VAR_3;

    int VAR_4;



    



    *VAR_2 = seek_l2_table(s, VAR_1);

    if (*VAR_2 != NULL) {

        return 0;

    }



    



    VAR_3 = l2_cache_new_entry(VAR_0);

    *VAR_2 = s->l2_cache + (VAR_3 << s->l2_bits);



    BLKDBG_EVENT(VAR_0->file, BLKDBG_L2_LOAD);

    VAR_4 = bdrv_pread(VAR_0->file, VAR_1, *VAR_2,

        s->l2_size * sizeof(uint64_t));

    if (VAR_4 < 0) {


        return VAR_4;

    }



    s->l2_cache_offsets[VAR_3] = VAR_1;

    s->l2_cache_counts[VAR_3] = 1;



    return 0;

}
static int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
uint64_t **VAR_2)
{ BDRVQcowState *s = VAR_0->opaque; int VAR_3; int VAR_4; *VAR_2 = seek_l2_table(s, VAR_1); if (*VAR_2 != NULL) { return 0; } VAR_3 = l2_cache_new_entry(VAR_0); *VAR_2 = s->l2_cache + (VAR_3 << s->l2_bits); BLKDBG_EVENT(VAR_0->file, BLKDBG_L2_LOAD); VAR_4 = bdrv_pread(VAR_0->file, VAR_1, *VAR_2,
s->l2_size * sizeof(uint64_t)); if (VAR_4 < 0) { return VAR_4; } s->l2_cache_offsets[VAR_3] = VAR_1; s->l2_cache_counts[VAR_3] = 1; return 0; }