Beispiel #1
0
rss_rid_entry_t *rss_load_entry(tbx_inip_group_t *grp)
{
    rss_rid_entry_t *rse;
    tbx_inip_element_t *ele;
    char *key, *value;
    // SO noisy
    //log_printf(0, "loading\n");
    //** Create the new RS list
    tbx_type_malloc_clear(rse, rss_rid_entry_t, 1);
    rse->status = RS_STATUS_UP;
    rse->attr = tbx_list_create(1, &tbx_list_string_compare, tbx_list_string_dup, tbx_list_simple_free, tbx_list_simple_free);

    //** Now cycle through the attributes
    ele = tbx_inip_ele_first(grp);
    while (ele != NULL) {
        key = tbx_inip_ele_get_key(ele);
        value = tbx_inip_ele_get_value(ele);
        if (strcmp(key, "rid_key") == 0) {  //** This is the RID so store it separate
            rse->rid_key = strdup(value);
            tbx_list_insert(rse->attr, key, rse->rid_key);
//QWERTY        tbx_list_insert(rse->attr, key, strdup(value));
        } else if (strcmp(key, "ds_key") == 0) {  //** This is what gets passed to the data service
            rse->ds_key = strdup(value);
        } else if (strcmp(key, "status") == 0) {  //** Current status
            rse->status = atoi(value);
        } else if (strcmp(key, "space_free") == 0) {  //** Free space
            rse->space_free = tbx_stk_string_get_integer(value);
        } else if (strcmp(key, "space_used") == 0) {  //** Used bytes
            rse->space_used = tbx_stk_string_get_integer(value);
        } else if (strcmp(key, "space_total") == 0) {  //** Total bytes
            rse->space_total = tbx_stk_string_get_integer(value);
        } else if ((key != NULL) && (value != NULL)) {  //** Anything else is an attribute
            tbx_list_insert(rse->attr, key, strdup(value));
        }

        log_printf(15, "rss_load_entry: key=%s value=%s\n", key, value);

        ele = tbx_inip_ele_next(ele);
    }

//log_printf(0, "rse->ds_key=%s rse->attr=%p\n", rse->ds_key, rse->attr);

    //** Make sure we have an RID and DS link
    if ((rse->rid_key == NULL) || (rse->ds_key == NULL)) {
        log_printf(1, "rss_load_entry: missing RID or ds_key! rid=%s ds_key=%s\n", rse->rid_key, rse->ds_key);
        rs_simple_rid_free(rse);
        rse = NULL;
    }

    return(rse);
}
Beispiel #2
0
void print_rid_summary(char *config, int base)
{
    tbx_list_t *table;
    tbx_list_iter_t it;
    tbx_inip_group_t *ig;
    tbx_inip_file_t *kf;
    tbx_inip_element_t *ele;
    char *key, *value;
    char fbuf[20], ubuf[20], tbuf[20];
    char *state[5] = { "UP      ", "IGNORE  ", "NO_SPACE", "DOWN    ", "INVALID " };
    int n, n_usable;
    rid_summary_t *rsum;
    ex_off_t space_total, space_free, space_used;
    ex_off_t up_total, up_free, up_used;

    space_total = space_free = space_used = 0;
    up_total = up_free = up_used = n_usable = 0;

    //** Create the table where we hold the info
    table = tbx_list_create(0, &tbx_list_string_compare, NULL, NULL, free);

    //** Open the file
    kf = tbx_inip_string_read(config); assert(kf);

    //** And load it
    ig = tbx_inip_group_first(kf);
    while (ig != NULL) {
        key = tbx_inip_group_get(ig);
        if (strcmp("rid", key) == 0) {  //** Found a resource
            tbx_type_malloc_clear(rsum, rid_summary_t, 1);

            //** Now cycle through the attributes
            ele = tbx_inip_ele_first(ig);
            while (ele != NULL) {
                key = tbx_inip_ele_get_key(ele);
                value = tbx_inip_ele_get_value(ele);
                if (strcmp(key, "rid_key") == 0) {  //** This is the RID so store it separate
                    rsum->rid = value;
                } else if (strcmp(key, "ds_key") == 0) {  //** Data service key
                    rsum->ds_key = value;
                } else if (strcmp(key, "host") == 0) {  //** Host
                    rsum->host = value;
                } else if (strcmp(key, "status") == 0) {  //** Free space
                    sscanf(value, "%d", &n);
                    rsum->status = ((n>=0) && (n<=3)) ? n : 4;
                } else if (strcmp(key, "space_free") == 0) {  //** Free space
                    sscanf(value, XOT, &(rsum->free));
                    space_free += rsum->free;
                } else if (strcmp(key, "space_used") == 0) {  //** Used space
                    sscanf(value, XOT, &(rsum->used));
                    space_used += rsum->used;
                } else if (strcmp(key, "space_total") == 0) {  //** Total space
                    sscanf(value, XOT, &(rsum->total));
                    space_total += rsum->total;
                }

                ele = tbx_inip_ele_next(ele);
            }

            if (rsum->status == 0) {
                n_usable++;
                up_free += rsum->free;
                up_used += rsum->used;
                up_total += rsum->total;
            }
            tbx_list_insert(table, rsum->rid, rsum);
        }

        ig = tbx_inip_group_next(ig);
    }


    //** Now print the summary
    printf("        RID             State             Host                      Used       Free        Total\n");
    printf("--------------------  --------  ------------------------------   ---------   ---------   ---------\n");
    it = tbx_list_iter_search(table, NULL, 0);
    while (tbx_list_next(&it, (tbx_list_key_t **)&key, (tbx_list_data_t **)&rsum) == 0) {
        printf("%-20s  %8s  %-30s   %8s   %8s   %8s\n", rsum->rid, state[rsum->status], rsum->host,
               tbx_stk_pretty_print_double_with_scale(base, (double)rsum->used, ubuf),
               tbx_stk_pretty_print_double_with_scale(base, (double)rsum->free, fbuf),
               tbx_stk_pretty_print_double_with_scale(base, (double)rsum->total, tbuf));
    }

    printf("--------------------------------------------------------------   ---------   ---------   ---------\n");
    printf("Usable Resources:%4d                                            %8s   %8s   %8s\n", n_usable,
           tbx_stk_pretty_print_double_with_scale(base, (double)up_used, ubuf),
           tbx_stk_pretty_print_double_with_scale(base, (double)up_free, fbuf),
           tbx_stk_pretty_print_double_with_scale(base, (double)up_total, tbuf));
    printf("Total Resources: %4d                                            %8s   %8s   %8s\n", tbx_list_key_count(table),
           tbx_stk_pretty_print_double_with_scale(base, (double)space_used, ubuf),
           tbx_stk_pretty_print_double_with_scale(base, (double)space_free, fbuf),
           tbx_stk_pretty_print_double_with_scale(base, (double)space_total, tbuf));

    tbx_list_destroy(table);

    //** Close the file
    tbx_inip_destroy(kf);
}
Beispiel #3
0
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);
}