Exemplo n.º 1
0
/* trove_handle_get_statistics()
 *
 * retrieves handle usage statistics from given collection; right now
 * this simply means returning the count of free handles
 *
 * returns 0 on success, -1 on error
 */
int trove_handle_get_statistics(TROVE_coll_id coll_id, uint64_t* free_count)
{
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger)
        {
	    trove_handle_ledger_get_statistics(ledger->ledger, 
		free_count);
            gen_mutex_unlock(&trove_handle_mutex);
	    return(0);
        }
	else
	{
            gen_mutex_unlock(&trove_handle_mutex);
	    return(-PVFS_ENOENT);
	}
    }
    else
    {
        gen_mutex_unlock(&trove_handle_mutex);
	return(-PVFS_ENOENT);
    }
}
Exemplo n.º 2
0
int trove_handle_peek(
    TROVE_coll_id coll_id,
    TROVE_handle *out_handle_array,
    int max_num_handles,
    int *returned_handle_count)
{
    int ret = -TROVE_EINVAL;
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;

    if (!out_handle_array || !returned_handle_count)
    {
        return ret;
    }

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger && (ledger->have_valid_ranges == 1))
        {
            ret = trove_ledger_peek_handles(
                ledger->ledger, out_handle_array,
                max_num_handles, returned_handle_count);
        }
    }
    gen_mutex_unlock(&trove_handle_mutex);
    return ret;
}
Exemplo n.º 3
0
TROVE_handle trove_handle_alloc_from_range(
    TROVE_coll_id coll_id,
    TROVE_handle_extent_array *extent_array)
{
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;
    TROVE_handle handle = TROVE_HANDLE_NULL;
    int i = 0;

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table, &(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger && (ledger->have_valid_ranges == 1))
        {
            for(i = 0; i < extent_array->extent_count; i++)
            {
                handle = trove_ledger_handle_alloc_from_range(
                    ledger->ledger, &(extent_array->extent_array[i]));
                if (handle != TROVE_HANDLE_NULL)
                {
                    break;
                }
            }
        }
    }
    gen_mutex_unlock(&trove_handle_mutex);
    return handle;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
int trove_handle_peek_from_range(
    TROVE_coll_id coll_id,
    TROVE_handle_extent_array *extent_array,
    TROVE_handle *out_handle_array,
    int max_num_handles,
    int *returned_handle_count)
{
    int ret = -TROVE_EINVAL, i = 0;
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;

    if (!extent_array || !out_handle_array || !returned_handle_count)
    {
        return ret;
    }

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger && (ledger->have_valid_ranges == 1))
        {
            for(i = 0; i < extent_array->extent_count; i++)
            {
                ret = trove_ledger_peek_handles_from_extent(
                    ledger->ledger, &(extent_array->extent_array[i]),
                    out_handle_array, max_num_handles,
                    returned_handle_count);
                /*
                  if we get any handles back, just return, even if
                  it's not the full amount requested
                */
                if (ret == 0)
                {
                    assert(*returned_handle_count > 0);
                    break;
                }
            }
        }
    }
    gen_mutex_unlock(&trove_handle_mutex);
    return ret;
}
Exemplo n.º 6
0
int trove_handle_free(TROVE_coll_id coll_id, TROVE_handle handle)
{
    int ret = -1;
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger)
        {
            ret = trove_ledger_handle_free(ledger->ledger, handle);
        }
    }
    gen_mutex_unlock(&trove_handle_mutex);
    return ret;
}
Exemplo n.º 7
0
TROVE_handle trove_handle_alloc(TROVE_coll_id coll_id)
{
    handle_ledger_t *ledger = NULL;
    struct qlist_head *hash_link = NULL;
    TROVE_handle handle = TROVE_HANDLE_NULL;

    gen_mutex_lock(&trove_handle_mutex);
    hash_link = qhash_search(s_fsid_to_ledger_table,&(coll_id));
    if (hash_link)
    {
        ledger = qlist_entry(hash_link, handle_ledger_t, hash_link);
        if (ledger && (ledger->have_valid_ranges == 1))
        {
            handle = trove_ledger_handle_alloc(ledger->ledger);
        }
    }
    gen_mutex_unlock(&trove_handle_mutex);
    return handle;
}
Exemplo n.º 8
0
void *id_gen_safe_lookup(BMI_id_gen_t id)
{
    void *ret = NULL;
    id_gen_safe_t *id_elem = NULL;
    struct qlist_head *hash_link = NULL;

    if (ID_GEN_SAFE_INITIALIZED())
    {
        gen_mutex_lock(&s_id_gen_safe_mutex);

        hash_link = qhash_search(s_id_gen_safe_table, &id);
        if (hash_link)
        {
            id_elem = qlist_entry(hash_link, id_gen_safe_t, hash_link);
            assert(id_elem);
            assert(id_elem->id == id);
            assert(id_elem->item);

            ret = id_elem->item;
        }
        gen_mutex_unlock(&s_id_gen_safe_mutex);
    }
    return ret;
}
Exemplo n.º 9
0
int pvfs2_mmap_ra_cache_get_block(
    PVFS_object_ref refn, PVFS_size offset,
    PVFS_size len, void *dest, int *amt_returned)
{
    int ret = -1;
    void *ptr = NULL;
    struct qlist_head *hash_link = NULL;
    mmap_ra_cache_elem_t *cache_elem = NULL;

    if (MMAP_RA_CACHE_INITIALIZED())
    {
        gen_mutex_lock(&s_mmap_ra_cache_mutex);
        hash_link = qhash_search(s_key_to_data_table, &refn);
        if (hash_link)
        {
            cache_elem = qhash_entry(
                hash_link, mmap_ra_cache_elem_t, hash_link);
            assert(cache_elem);

            if (cache_elem->data_sz > (offset + len))
            {
                gossip_debug(GOSSIP_MMAP_RCACHE_DEBUG,
                             "mmap_ra_cache_get_block got block at "
                             "offset %llu, len %llu\n",  llu(offset),
                             llu(len));

                ptr = (void *)(((char *)cache_elem->data + offset));
                memcpy(dest, ptr, len);

                if (amt_returned)
                {
                    *amt_returned = len;
                }
                ret = 0;
            }
            else
            {
                int actual_len = (int)
                    ((offset + len) - cache_elem->data_sz);

                gossip_debug(
                    GOSSIP_MMAP_RCACHE_DEBUG, "mmap_ra_cache_get_block "
                    "found invalid block [%llu/%llu]\n",
                    llu(offset), llu(len));

                if (actual_len > 0)
                {
                    gossip_debug(
                        GOSSIP_MMAP_RCACHE_DEBUG, " data_sz is %llu, "
                        "offset is %llu len is %llu\n\t(filling partial %d "
                        "bytes)\n", llu(cache_elem->data_sz), llu(offset),
                        llu(len), actual_len);

                    ptr = (void *)(((char *)cache_elem->data + offset));
                    memcpy(dest, ptr, actual_len);

                    if (amt_returned)
                    {
                        *amt_returned = actual_len;
                    }
                    ret = 0;
                }
            }
        }
        else
        {
            gossip_debug(
                GOSSIP_MMAP_RCACHE_DEBUG, "mmap_ra_cache_get_block "
                "clean cache miss (nothing here)\n");
        }
        gen_mutex_unlock(&s_mmap_ra_cache_mutex);
    }
    return ret;
}