示例#1
0
resource_service_fn_t *rs_simple_create(void *arg, tbx_inip_file_t *kf, char *section)
{
    service_manager_t *ess = (service_manager_t *)arg;
    rs_simple_priv_t *rss;
    resource_service_fn_t *rs;

    //** Create the new RS list
    tbx_type_malloc_clear(rss, rs_simple_priv_t, 1);

    assert_result(apr_pool_create(&(rss->mpool), NULL), APR_SUCCESS);
    apr_thread_mutex_create(&(rss->lock), APR_THREAD_MUTEX_DEFAULT, rss->mpool);
    apr_thread_mutex_create(&(rss->update_lock), APR_THREAD_MUTEX_DEFAULT, rss->mpool);
    apr_thread_cond_create(&(rss->cond), rss->mpool);
    rss->rid_mapping = apr_hash_make(rss->mpool);
    rss->mapping_updates = apr_hash_make(rss->mpool);

    rss->ds = lookup_service(ess, ESS_RUNNING, ESS_DS);
    rss->da = lookup_service(ess, ESS_RUNNING, ESS_DA);

    //** Set the resource service fn ptrs
    tbx_type_malloc_clear(rs, resource_service_fn_t, 1);
    rs->priv = rss;
    rs->get_rid_config = rss_get_rid_config;
    rs->register_mapping_updates = rss_mapping_register;
    rs->unregister_mapping_updates = rss_mapping_unregister;
    rs->translate_cap_set = rss_translate_cap_set;
    rs->query_new = rs_query_base_new;
    rs->query_dup = rs_query_base_dup;
    rs->query_add = rs_query_base_add;
    rs->query_append = rs_query_base_append;
    rs->query_destroy = rs_query_base_destroy;
    rs->query_print = rs_query_base_print;
    rs->query_parse = rs_query_base_parse;
    rs->get_rid_value = rs_simple_get_rid_value;
    rs->data_request = rs_simple_request;
    rs->destroy_service = rs_simple_destroy;
    rs->type = RS_TYPE_SIMPLE;

    //** This is the file to use for loading the RID table
    rss->fname = tbx_inip_get_string(kf, section, "fname", NULL);
    rss->dynamic_mapping = tbx_inip_get_integer(kf, section, "dynamic_mapping", 0);
    rss->check_interval = tbx_inip_get_integer(kf, section, "check_interval", 300);
    rss->check_timeout = tbx_inip_get_integer(kf, section, "check_timeout", 60);
    rss->min_free = tbx_inip_get_integer(kf, section, "min_free", 100*1024*1024);

    //** Set the modify time to force a change
    rss->modify_time = 0;

    //** Load the RID table
    assert_result(_rs_simple_refresh(rs), 0);

    //** Launch the check thread
    tbx_thread_create_assert(&(rss->check_thread), NULL, rss_check_thread, (void *)rs, rss->mpool);

    return(rs);
}
示例#2
0
resource_service_fn_t *rs_remote_server_create(void *arg, tbx_inip_file_t *fd, char *section)
{
    service_manager_t *ess = (service_manager_t *)arg;
    resource_service_fn_t *rs;
    rs_remote_server_priv_t *rsrs;
    rs_create_t *rs_create;
    mq_command_table_t *ctable;
    char *stype, *ctype;

    if (section == NULL) section = "rs_remote_server";

    tbx_type_malloc_clear(rs, resource_service_fn_t, 1);
    tbx_type_malloc_clear(rsrs, rs_remote_server_priv_t, 1);
    rs->priv = (void *)rsrs;

    //** Make the locks and cond variables
    assert_result(apr_pool_create(&(rsrs->mpool), NULL), APR_SUCCESS);
    apr_thread_mutex_create(&(rsrs->lock), APR_THREAD_MUTEX_DEFAULT, rsrs->mpool);
    apr_thread_cond_create(&(rsrs->cond), rsrs->mpool);

    rsrs->pending = tbx_stack_new();
    memset(&(rsrs->my_map_version), 0, sizeof(rsrs->my_map_version));
    memset(&(rsrs->notify_map_version), 0, sizeof(rsrs->notify_map_version));
    rsrs->notify_map_version.lock = rsrs->lock;
    rsrs->notify_map_version.cond = rsrs->cond;

    //** Get the host name we bind to
    rsrs->hostname= tbx_inip_get_string(fd, section, "address", NULL);

    //** Start the child RS.   The update above should have dumped a RID config for it to load
    stype = tbx_inip_get_string(fd, section, "rs_local", NULL);
    if (stype == NULL) {  //** Oops missing child RS
        log_printf(0, "ERROR: Mising child RS  section=%s key=rs_local!\n", section);
        tbx_log_flush();
        free(stype);
        abort();
    }

    //** and load it
    ctype = tbx_inip_get_string(fd, stype, "type", RS_TYPE_SIMPLE);
    rs_create = lookup_service(ess, RS_SM_AVAILABLE, ctype);
    rsrs->rs_child = (*rs_create)(ess, fd, stype);
    if (rsrs->rs_child == NULL) {
        log_printf(1, "ERROR loading child RS!  type=%s section=%s\n", ctype, stype);
        tbx_log_flush();
        abort();
    }
    free(ctype);
    free(stype);

    //** Get the MQC
    rsrs->mqc = lookup_service(ess, ESS_RUNNING, ESS_MQ); assert(rsrs->mqc != NULL);

    //** Make the server portal
    rsrs->server_portal = mq_portal_create(rsrs->mqc, rsrs->hostname, MQ_CMODE_SERVER);
    ctable = mq_portal_command_table(rsrs->server_portal);
    mq_command_set(ctable, RSR_GET_RID_CONFIG_KEY, RSR_GET_RID_CONFIG_SIZE, rs, rsrs_rid_config_cb);
    mq_command_set(ctable, RSR_GET_UPDATE_CONFIG_KEY, RSR_GET_UPDATE_CONFIG_SIZE, rs, rsrs_rid_config_cb);
    mq_command_set(ctable, RSR_ABORT_KEY, RSR_ABORT_SIZE, rs, rsrs_abort_cb);
    mq_portal_install(rsrs->mqc, rsrs->server_portal);

    //** Launch the config changes thread
    tbx_thread_create_assert(&(rsrs->monitor_thread), NULL, rsrs_monitor_thread, (void *)rs, rsrs->mpool);

    //** Set up the fn ptrs.  This is just for syncing the rid configuration and state
    //** so very little is implemented
    rs->destroy_service = rs_remote_server_destroy;

    rs->type = RS_TYPE_REMOTE_SERVER;

    return(rs);
}
示例#3
0
文件: data_block.c 项目: accre/lstore
lio_data_block_t *data_block_deserialize_text(lio_service_manager_t *sm, ex_id_t id, lio_exnode_exchange_t *exp)
{
    int bufsize=1024;
    char capgrp[bufsize];
    char *text, *etext;
    int i;
    lio_data_block_t *b;
    lio_data_service_fn_t *ds;
    tbx_inip_file_t *cfd;
    tbx_inip_group_t *cg;
    tbx_inip_element_t *ele;
    char *key;
    lio_data_block_attr_t *attr;

    //** Parse the ini text
    cfd = exp->text.fd;

    //** Find the cooresponding cap
    snprintf(capgrp, bufsize, "block-" XIDT, id);
    cg = tbx_inip_group_find(cfd, capgrp);
    if (cg == NULL) {
        log_printf(0, "data_block_deserialize_text: id=" XIDT " not found!\n", id);
        return(NULL);
    }

    //** Determine the type and make a blank block
    text = tbx_inip_get_string(cfd, capgrp, "type", "");
    ds = lio_lookup_service(sm, DS_SM_RUNNING, text);
    if (ds == NULL) {
        log_printf(0, "data_block_deserialize_text: b->id=" XIDT " Unknown data service tpye=%s!\n", id, text);
        return(NULL);;
    }
    free(text);

    //** Make the space
    b = data_block_create_with_id(ds, id);

    //** and parse the fields
    b->rid_key = tbx_inip_get_string(cfd, capgrp, "rid_key", "");
    b->size = tbx_inip_get_integer(cfd, capgrp, "size", b->size);
    b->max_size = tbx_inip_get_integer(cfd, capgrp, "max_size", b->max_size);
    i = tbx_inip_get_integer(cfd, capgrp, "ref_count", b->ref_count);
    tbx_atomic_set(b->ref_count, 0);
    tbx_atomic_set(b->initial_ref_count, i);
    etext = tbx_inip_get_string(cfd, capgrp, "read_cap", "");
    ds_set_cap(b->ds, b->cap, DS_CAP_READ, tbx_stk_unescape_text('\\', etext));
    free(etext);
    etext = tbx_inip_get_string(cfd, capgrp, "write_cap", "");
    ds_set_cap(b->ds, b->cap, DS_CAP_WRITE, tbx_stk_unescape_text('\\', etext));
    free(etext);
    etext = tbx_inip_get_string(cfd, capgrp, "manage_cap", "");
    ds_set_cap(b->ds, b->cap, DS_CAP_MANAGE, tbx_stk_unescape_text('\\', etext));
    free(etext);

    //** Now cycle through any misc attributes set
    ele = tbx_inip_ele_first(tbx_inip_group_find(cfd, capgrp));
    while (ele != NULL) {
        key = tbx_inip_ele_get_key(ele);

        //** Ignore the builtin commands
        if ((strcmp("rid_key", key) != 0) && (strcmp("size", key) != 0) && (strcmp("max_size", key) != 0) && (strcmp("type", key) != 0) &&
                (strcmp("ref_count", key) != 0) && (strcmp("read_cap", key) != 0) && (strcmp("write_cap", key) != 0) && (strcmp("manage_cap", key) != 0)) {
            tbx_type_malloc(attr, lio_data_block_attr_t, 1);
            attr->key = tbx_stk_unescape_text('\\', tbx_inip_ele_get_key(ele));
            attr->value = tbx_stk_unescape_text('\\', tbx_inip_ele_get_value(ele));
            if (b->attr_stack == NULL) b->attr_stack = tbx_stack_new();
            tbx_stack_push(b->attr_stack, attr);
        }

        ele = tbx_inip_ele_next(ele);
    }

    return(b);
}