int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)

{

    int ret;



    qed_unref_l2_cache_entry(request->l2_table);



    /* Check for cached L2 entry */

    request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);

    if (request->l2_table) {

        return 0;

    }



    request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache);

    request->l2_table->table = qed_alloc_table(s);



    BLKDBG_EVENT(s->bs->file, BLKDBG_L2_LOAD);

    ret = qed_read_table(s, offset, request->l2_table->table);



    qed_acquire(s);

    if (ret) {

        /* can't trust loaded L2 table anymore */

        qed_unref_l2_cache_entry(request->l2_table);

        request->l2_table = NULL;

    } else {

        request->l2_table->offset = offset;



        qed_commit_l2_cache_entry(&s->l2_cache, request->l2_table);



        /* This is guaranteed to succeed because we just committed the entry

         * to the cache.

         */

        request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);

        assert(request->l2_table != NULL);

    }

    qed_release(s);



    return ret;

}

int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)

{

    int ret;



    qed_unref_l2_cache_entry(request->l2_table);



    

    request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);

    if (request->l2_table) {

        return 0;

    }



    request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache);

    request->l2_table->table = qed_alloc_table(s);



    BLKDBG_EVENT(s->bs->file, BLKDBG_L2_LOAD);

    ret = qed_read_table(s, offset, request->l2_table->table);



    qed_acquire(s);

    if (ret) {

        

        qed_unref_l2_cache_entry(request->l2_table);

        request->l2_table = NULL;

    } else {

        request->l2_table->offset = offset;



        qed_commit_l2_cache_entry(&s->l2_cache, request->l2_table);



        





        request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset);

        assert(request->l2_table != NULL);

    }

    qed_release(s);



    return ret;

}

int FUNC_0(BDRVQEDState *VAR_0, QEDRequest *VAR_1, uint64_t VAR_2)

{

    int VAR_3;



    qed_unref_l2_cache_entry(VAR_1->l2_table);



    

    VAR_1->l2_table = qed_find_l2_cache_entry(&VAR_0->l2_cache, VAR_2);

    if (VAR_1->l2_table) {

        return 0;

    }



    VAR_1->l2_table = qed_alloc_l2_cache_entry(&VAR_0->l2_cache);

    VAR_1->l2_table->table = qed_alloc_table(VAR_0);



    BLKDBG_EVENT(VAR_0->bs->file, BLKDBG_L2_LOAD);

    VAR_3 = qed_read_table(VAR_0, VAR_2, VAR_1->l2_table->table);



    qed_acquire(VAR_0);

    if (VAR_3) {

        

        qed_unref_l2_cache_entry(VAR_1->l2_table);

        VAR_1->l2_table = NULL;

    } else {

        VAR_1->l2_table->VAR_2 = VAR_2;



        qed_commit_l2_cache_entry(&VAR_0->l2_cache, VAR_1->l2_table);



        





        VAR_1->l2_table = qed_find_l2_cache_entry(&VAR_0->l2_cache, VAR_2);

        assert(VAR_1->l2_table != NULL);

    }

    qed_release(VAR_0);



    return VAR_3;

}

int FUNC_0(BDRVQEDState *VAR_0, QEDRequest *VAR_1, uint64_t VAR_2)
{ int VAR_3; qed_unref_l2_cache_entry(VAR_1->l2_table); VAR_1->l2_table = qed_find_l2_cache_entry(&VAR_0->l2_cache, VAR_2); if (VAR_1->l2_table) { return 0; } VAR_1->l2_table = qed_alloc_l2_cache_entry(&VAR_0->l2_cache); VAR_1->l2_table->table = qed_alloc_table(VAR_0); BLKDBG_EVENT(VAR_0->bs->file, BLKDBG_L2_LOAD); VAR_3 = qed_read_table(VAR_0, VAR_2, VAR_1->l2_table->table); qed_acquire(VAR_0); if (VAR_3) { qed_unref_l2_cache_entry(VAR_1->l2_table); VAR_1->l2_table = NULL; } else { VAR_1->l2_table->VAR_2 = VAR_2; qed_commit_l2_cache_entry(&VAR_0->l2_cache, VAR_1->l2_table); VAR_1->l2_table = qed_find_l2_cache_entry(&VAR_0->l2_cache, VAR_2); assert(VAR_1->l2_table != NULL); } qed_release(VAR_0); return VAR_3; }