예제 #1
0
static handle_ledger_t *get_or_add_handle_ledger(TROVE_coll_id coll_id)
{
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;

    /* search for a matching entry */
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        /* return it if it exists */
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
    }
    else
    {
        /* alloc, initialize, then return otherwise */
        ledger = (handle_ledger_t *)malloc(sizeof(handle_ledger_t));
        if (ledger)
        {
            ledger->coll_id = coll_id;
            ledger->have_valid_ranges = 0;
            ledger->ledger = trove_handle_ledger_init(coll_id,NULL);
            if (ledger->ledger)
            {
                qhash_add(s_fsid_to_ledger_table,
                          &(coll_id),&(ledger->hash_link));
            }
            else
            {
                free(ledger);
                ledger = NULL;
            }
        }
    }
    return ledger;
}
예제 #2
0
파일: mmap-ra-cache.c 프로젝트: Goon83/SALB
int pvfs2_mmap_ra_cache_register(PVFS_object_ref refn,
                                 void *data, int data_len)
{
    int ret = -1;
    mmap_ra_cache_elem_t *cache_elem = NULL;

    if (MMAP_RA_CACHE_INITIALIZED())
    {
        pvfs2_mmap_ra_cache_flush(refn);

        cache_elem = (mmap_ra_cache_elem_t *)
            malloc(sizeof(mmap_ra_cache_elem_t));
        if (!cache_elem)
        {
            goto return_exit;
        }
        memset(cache_elem, 0, sizeof(mmap_ra_cache_elem_t));
        cache_elem->refn = refn;
        cache_elem->data = malloc(data_len);
        if (!cache_elem->data)
        {
            goto return_exit;
        }
        memcpy(cache_elem->data, data, data_len);
        cache_elem->data_sz = data_len;

        gen_mutex_lock(&s_mmap_ra_cache_mutex);
        qhash_add(s_key_to_data_table,
                  &refn, &cache_elem->hash_link);
        gen_mutex_unlock(&s_mmap_ra_cache_mutex);

        gossip_debug(GOSSIP_MMAP_RCACHE_DEBUG, "Inserted mmap ra cache "
                     "element %llu, %d of size %llu\n",
                     llu(cache_elem->refn.handle),
                     cache_elem->refn.fs_id,
                     llu(cache_elem->data_sz));

        ret = 0;
    }

  return_exit:
    return ret;
}
예제 #3
0
int id_gen_safe_register(
    BMI_id_gen_t *new_id,
    void *item)
{
    id_gen_safe_t *id_elem = NULL;

    assert(s_id_gen_safe_table != NULL);

    if (!item)
    {
	return -EINVAL;
    }

    gen_mutex_lock(&s_id_gen_safe_mutex);

    id_elem = (id_gen_safe_t *)malloc(sizeof(id_gen_safe_t));
    if (!id_elem)
    {
        return -ENOMEM;
    }

    id_elem->id = ++s_id_gen_safe_tag;
    if(id_elem->id == 0)
    {
        /* don't want this to land on zero */
        id_elem->id = ++s_id_gen_safe_tag;
    }
    id_elem->item = item;

    qhash_add(s_id_gen_safe_table, &id_elem->id, &id_elem->hash_link);

    *new_id = id_elem->id;

    gen_mutex_unlock(&s_id_gen_safe_mutex);
    return 0;
}