Esempio n. 1
0
void assoc_prefix_unlink(struct default_engine *engine, hash_item *it,
                         const size_t item_size, bool drop_if_empty)
{
    prefix_t *pt;
    assert(it->nprefix != 0);

    if (it->nprefix == it->nkey) {
        pt = root_pt;
    } else {
        pt = assoc_prefix_find(engine, engine->server.core->hash(item_get_key(it), it->nprefix, 0),
                               item_get_key(it), it->nprefix);
    }
    assert(pt != NULL);

    // update prefix information
    if ((it->iflag & ITEM_IFLAG_LIST) != 0) {
        pt->list_hash_items--;
        pt->list_hash_items_bytes -= item_size;
    } else if ((it->iflag & ITEM_IFLAG_SET) != 0) {
        pt->set_hash_items--;
        pt->set_hash_items_bytes -= item_size;
    } else if ((it->iflag & ITEM_IFLAG_BTREE) != 0) {
        pt->btree_hash_items--;
        pt->btree_hash_items_bytes -= item_size;
    } else {
        pt->hash_items--;
        pt->hash_items_bytes -= item_size;
    }
#if 0 // might be used later
    if (1) {
        prefix_t *curr_pt = pt->parent_prefix;
        while (curr_pt != NULL) {
            curr_pt->tot_hash_items--;
            curr_pt->tot_hash_items_bytes -= item_size;
            curr_pt = curr_pt->parent_prefix;
        }
    }
#endif
    if (drop_if_empty) {
        while (pt != NULL) {
            prefix_t *parent_pt = pt->parent_prefix;

            if (pt != root_pt && pt->prefix_items == 0 && pt->hash_items == 0 &&
                pt->list_hash_items == 0 && pt->set_hash_items == 0 && pt->btree_hash_items == 0) {
                assert(pt->hash_items_bytes == 0 && pt->list_hash_items_bytes == 0 &&
                       pt->set_hash_items_bytes == 0 && pt->btree_hash_items_bytes == 0);
                _prefix_delete(engine, engine->server.core->hash(_get_prefix(pt), pt->nprefix, 0),
                               _get_prefix(pt), pt->nprefix);
            } else {
                break;
            }
            pt = parent_pt;
        }
    }
}
Esempio n. 2
0
static int _prefix_insert(struct default_engine *engine, uint32_t hash, prefix_t *pt)
{
    assert(assoc_prefix_find(engine, hash, _get_prefix(pt), pt->nprefix) == NULL);

    pt->h_next = engine->assoc.prefix_hashtable[hash & hashmask(DEFAULT_PREFIX_HASHPOWER)];
    engine->assoc.prefix_hashtable[hash & hashmask(DEFAULT_PREFIX_HASHPOWER)] = pt;

    assert(pt->parent_prefix != NULL);
    pt->parent_prefix->prefix_items++;
    engine->assoc.tot_prefix_items++;
    return 1;
}
Esempio n. 3
0
prefix_t *assoc_prefix_find(struct default_engine *engine, uint32_t hash,
                            const char *prefix, const int nprefix)
{
    prefix_t *pt = engine->assoc.prefix_hashtable[hash & hashmask(DEFAULT_PREFIX_HASHPOWER)];
    while (pt) {
        if ((nprefix == pt->nprefix) && (memcmp(prefix, _get_prefix(pt), nprefix) == 0)) {
            return pt;
        }
        pt = pt->h_next;
    }
    return NULL;
}
Esempio n. 4
0
void assoc_prefix_unlink(struct default_engine *engine, hash_item *it,
                         const size_t item_size, bool drop_if_empty)
{
    prefix_t *pt = it->pfxptr;
    it->pfxptr = NULL;
    assert(pt != NULL);

    /* update prefix information */
    int item_type = GET_ITEM_TYPE(it);
    pt->items_count[item_type] -= 1;
    pt->items_bytes[item_type] -= item_size;
    pt->total_count_exclusive -= 1;
    pt->total_bytes_exclusive -= item_size;
#if 0 // might be used later
    if (1) {
        prefix_t *curr_pt = pt->parent_prefix;
        while (curr_pt != NULL) {
            curr_pt->total_count_inclusive -= 1;
            curr_pt->total_bytes_inclusive -= item_size;
            curr_pt = curr_pt->parent_prefix;
        }
    }
#endif

    if (drop_if_empty) {
        while (pt != NULL && pt != root_pt) {
            prefix_t *parent_pt = pt->parent_prefix;

            if (pt->prefix_items > 0 || pt->total_count_exclusive > 0)
                break; /* NOT empty */
            assert(pt->total_bytes_exclusive == 0);
            _prefix_delete(engine, engine->server.core->hash(_get_prefix(pt), pt->nprefix, 0),
                           _get_prefix(pt), pt->nprefix);

            pt = parent_pt;
        }
    }
}
Esempio n. 5
0
static void _prefix_delete(struct default_engine *engine, uint32_t hash,
                           const char *prefix, const int nprefix)
{
    int bucket = hash & hashmask(DEFAULT_PREFIX_HASHPOWER);
    prefix_t *prev_pt = NULL;
    prefix_t *pt = engine->assoc.prefix_hashtable[bucket];
    while (pt) {
        if ((nprefix == pt->nprefix) && (memcmp(prefix, _get_prefix(pt), nprefix) == 0))
            break; /* found */
        prev_pt = pt; pt = pt->h_next;
    }
    if (pt) {
        assert(pt->parent_prefix != NULL);
        pt->parent_prefix->prefix_items--;
        engine->assoc.tot_prefix_items--;

        /* unlink and free the prefix structure */
        if (prev_pt) prev_pt->h_next = pt->h_next;
        else         engine->assoc.prefix_hashtable[bucket] = pt->h_next;
        free(pt);
    }
}
Esempio n. 6
0
/* Take the user's format specification and use it to build build the
 *	format specifications (internalize it to print.c data structures) */
static int
_parse_format( char* format )
{
	int field_size;
	bool right_justify;
	char *prefix = NULL, *suffix = NULL, *token = NULL,
		*tmp_char = NULL, *tmp_format = NULL;
	char field[1];

	if (format == NULL) {
		fprintf( stderr, "Format option lacks specification\n" );
		exit( 1 );
	}

	params.format_list = list_create( NULL );
	if ((prefix = _get_prefix(format)))
		format_add_prefix( params.format_list, 0, 0, prefix);

	tmp_format = xstrdup( format );
	token = strtok_r( tmp_format, "%", &tmp_char);
	if (token && (format[0] != '%'))	/* toss header */
		token = strtok_r( NULL, "%", &tmp_char );
	while (token) {
		_parse_token( token, field, &field_size, &right_justify,
			      &suffix);
		if        (field[0] == 'a') {
			params.match_flags.avail_flag = true;
			format_add_avail( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'A') {
			format_add_nodes_ai( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'c') {
			params.match_flags.cpus_flag = true;
			format_add_cpus( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'C') {
			params.match_flags.cpus_flag = true;
			format_add_cpus_aiot( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'd') {
			params.match_flags.disk_flag = true;
			format_add_disk( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'D') {
			format_add_nodes( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'E') {
			params.match_flags.reason_flag = true;
			format_add_reason( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'f') {
			params.match_flags.features_flag = true;
			format_add_features( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'F') {
			format_add_nodes_aiot( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'g') {
			params.match_flags.groups_flag = true;
			format_add_groups( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'G') {
			params.match_flags.gres_flag = true;
			format_add_gres( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'h') {
			params.match_flags.share_flag = true;
			format_add_share( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'H') {
			params.match_flags.reason_timestamp_flag = true;
			format_add_timestamp( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (field[0] == 'l') {
			params.match_flags.max_time_flag = true;
			format_add_time( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'L') {
			params.match_flags.default_time_flag = true;
			format_add_default_time( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'm') {
			params.match_flags.memory_flag = true;
			format_add_memory( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'M') {
			params.match_flags.preempt_mode_flag = true;
			format_add_preempt_mode( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'n') {
			params.match_flags.hostnames_flag = true;
			format_add_node_hostnames( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'N') {
			format_add_node_list( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'o') {
			params.match_flags.node_addr_flag = true;
			format_add_node_address( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'O') {
			params.match_flags.cpu_load_flag = true;
			format_add_cpu_load( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'p') {
			params.match_flags.priority_flag = true;
			format_add_priority( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'P') {
			params.match_flags.partition_flag = true;
			format_add_partition( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'r') {
			params.match_flags.root_flag = true;
			format_add_root( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'R') {
			params.match_flags.partition_flag = true;
			format_add_partition_name( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 's') {
			params.match_flags.job_size_flag = true;
			format_add_size( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (field[0] == 'S') {
			format_add_alloc_nodes( params.format_list,
						field_size,
						right_justify,
						suffix );
		} else if (field[0] == 't') {
			params.match_flags.state_flag = true;
			format_add_state_compact( params.format_list,
						  field_size,
						  right_justify,
						  suffix );
		} else if (field[0] == 'T') {
			params.match_flags.state_flag = true;
			format_add_state_long( params.format_list,
					       field_size,
					       right_justify,
					       suffix );
		} else if (field[0] == 'u') {
			params.match_flags.reason_user_flag = true;
			format_add_user( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'U') {
			params.match_flags.reason_user_flag = true;
			format_add_user_long( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (field[0] == 'w') {
			params.match_flags.weight_flag = true;
			format_add_weight( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'X') {
			params.match_flags.sockets_flag = true;
			format_add_sockets( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'Y') {
			params.match_flags.cores_flag = true;
			format_add_cores( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'Z') {
			params.match_flags.threads_flag = true;
			format_add_threads( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'z') {
			params.match_flags.sct_flag = true;
			format_add_sct( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else {
			prefix = xstrdup("%");
			xstrcat(prefix, token);
			xfree(suffix);
			suffix = prefix;
			format_add_invalid( params.format_list,
					    field_size,
					    right_justify,
					    suffix );
			fprintf(stderr, "Invalid node format specification: %c\n",
				field[0] );
		}
		token = strtok_r( NULL, "%", &tmp_char);
	}

	xfree( tmp_format );
	return SLURM_SUCCESS;
}
Esempio n. 7
0
static ENGINE_ERROR_CODE do_assoc_get_prefix_stats(struct default_engine *engine,
                                                   const char *prefix, const int  nprefix, void *prefix_data)
{
    prefix_t *pt;

    if (nprefix < 0) { // all prefix information
        char *buf;
        struct tm *t;
        const char *format = "PREFIX %s itm %llu kitm %llu litm %llu sitm %llu bitm %llu "
                             "tsz %llu ktsz %llu ltsz %llu stsz %llu btsz %llu time %04d%02d%02d%02d%02d%02d\r\n";
        uint32_t i, hsize = hashsize(DEFAULT_PREFIX_HASHPOWER);
        uint32_t num_prefixes = engine->assoc.tot_prefix_items;
        uint32_t tot_prefix_name_len = 0;
        uint32_t msize, pos, written;

        pt = root_pt;
        if (pt != NULL && (pt->hash_items > 0 || pt->list_hash_items > 0 || pt->set_hash_items > 0 || pt->btree_hash_items > 0)) {
            /* including null prefix */
            num_prefixes += 1;
            tot_prefix_name_len = strlen("<null>");
        }
        for (i = 0; i < hsize; i++) {
            pt = engine->assoc.prefix_hashtable[i];
            while (pt) {
                tot_prefix_name_len += pt->nprefix;
                pt = pt->h_next;
            }
        }

        msize = sizeof(uint32_t) + strlen(format) + tot_prefix_name_len
                + num_prefixes * (strlen(format) - 2 /* %s */
                                  + (10 * (20 - 4))) /* %llu replaced by 20-digit num */
                - (5 * (4 - 2)) /* %02d replaced by 2-digit num */
                + sizeof("END\r\n");

        buf = malloc(msize);
        if (buf == NULL) {
            return ENGINE_ENOMEM;
        }
        pos = sizeof(uint32_t);

        pt = root_pt;
        if (pt != NULL && (pt->hash_items > 0 || pt->list_hash_items > 0 || pt->set_hash_items > 0 || pt->btree_hash_items > 0)) {
            /* including null prefix */
            t = localtime(&pt->create_time);
            written = snprintf(buf+pos, msize-pos, format, "<null>",
                               pt->hash_items+pt->list_hash_items+pt->set_hash_items+pt->btree_hash_items,
                               pt->hash_items,pt->list_hash_items,pt->set_hash_items,pt->btree_hash_items,
                               pt->hash_items_bytes+pt->list_hash_items_bytes+pt->set_hash_items_bytes+pt->btree_hash_items_bytes,
                               pt->hash_items_bytes,pt->list_hash_items_bytes,pt->set_hash_items_bytes,pt->btree_hash_items_bytes,
                               t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
            pos += written;
        }

        for (i = 0; i < hsize; i++) {
            pt = engine->assoc.prefix_hashtable[i];
            while (pt) {
                t = localtime(&pt->create_time);
                written = snprintf(buf+pos, msize-pos, format, _get_prefix(pt),
                               pt->hash_items+pt->list_hash_items+pt->set_hash_items+pt->btree_hash_items,
                               pt->hash_items,pt->list_hash_items,pt->set_hash_items,pt->btree_hash_items,
                               pt->hash_items_bytes+pt->list_hash_items_bytes+pt->set_hash_items_bytes+pt->btree_hash_items_bytes,
                               pt->hash_items_bytes,pt->list_hash_items_bytes,pt->set_hash_items_bytes,pt->btree_hash_items_bytes,
                               t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
                pos += written;
                assert(pos < msize);
                pt = pt->h_next;
            }
        }
        memcpy(buf+pos, "END\r\n", 6);
        *(uint32_t*)buf = pos + 5 - sizeof(uint32_t);

        *(char**)prefix_data = buf;
    } else {
        prefix_engine_stats *prefix_stats = (prefix_engine_stats*)prefix_data;

        if (prefix != NULL) {
            pt = assoc_prefix_find(engine, engine->server.core->hash(prefix,nprefix,0), prefix, nprefix);
        } else {
            pt = root_pt;
        }
        if (pt == NULL) {
            return ENGINE_PREFIX_ENOENT;
        }

        prefix_stats->hash_items = pt->hash_items;
        prefix_stats->hash_items_bytes = pt->hash_items_bytes;
        prefix_stats->prefix_items = pt->prefix_items;
        if (prefix != NULL)
            prefix_stats->tot_prefix_items = pt->prefix_items;
        else
            prefix_stats->tot_prefix_items = engine->assoc.tot_prefix_items;
    }
    return ENGINE_SUCCESS;
}
Esempio n. 8
0
static ENGINE_ERROR_CODE
do_assoc_get_prefix_stats(struct default_engine *engine,
                          const char *prefix, const int nprefix,
                          void *prefix_data)
{
    struct assoc *assoc = &engine->assoc;
    prefix_t *pt;

    if (nprefix < 0) /* all prefix stats */
    {
        const char *format = "PREFIX %s "
                             "itm %llu kitm %llu litm %llu sitm %llu mitm %llu bitm %llu " /* total item count */
                             "tsz %llu ktsz %llu ltsz %llu stsz %llu mtsz %llu btsz %llu " /* total item bytes */
                             "time %04d%02d%02d%02d%02d%02d\r\n"; /* create time */
        char *buffer;
        struct tm *t;
        uint32_t prefix_hsize = hashsize(DEFAULT_PREFIX_HASHPOWER);
        uint32_t num_prefixes = assoc->tot_prefix_items;
        uint32_t sum_nameleng = 0; /* sum of prefix name length */
        uint32_t i, buflen, pos;

        /* get # of prefixes and num of prefix names */
        assert(root_pt != NULL);
        if (root_pt->total_count_exclusive > 0) {
            /* Include the valid null prefix (that is root prefix) */
            num_prefixes += 1;
            sum_nameleng += strlen("<null>");
        }
        for (i = 0; i < prefix_hsize; i++) {
            pt = assoc->prefix_hashtable[i];
            while (pt) {
                sum_nameleng += pt->nprefix;
                pt = pt->h_next;
            }
        }

        /* Allocate stats buffer: <length, prefix stats list, tail>.
         * Check the count of "%llu" and "%02d" in the above format string.
         *   - 10 : the count of "%llu" strings.
         *   -  5 : the count of "%02d" strings.
         */
        buflen = sizeof(uint32_t) /* length */
               + sum_nameleng
               + num_prefixes * (strlen(format) - 2 /* %s replaced by prefix name */
                                 + (12 * (20 - 4))  /* %llu replaced by 20-digit num */
                                 - ( 5 * ( 4 - 2))) /* %02d replaced by 2-digit num */
               + sizeof("END\r\n"); /* tail string */

        if ((buffer = malloc(buflen)) == NULL) {
            return ENGINE_ENOMEM;
        }

        /* write prefix stats in the buffer */
        pos = sizeof(uint32_t);
        if (num_prefixes > assoc->tot_prefix_items) { /* include root prefix */
            pt = root_pt;
            t = localtime(&pt->create_time);
            pos += snprintf(buffer+pos, buflen-pos, format, "<null>",
                            pt->total_count_exclusive,
                            pt->items_count[ITEM_TYPE_KV],
                            pt->items_count[ITEM_TYPE_LIST],
                            pt->items_count[ITEM_TYPE_SET],
                            pt->items_count[ITEM_TYPE_MAP],
                            pt->items_count[ITEM_TYPE_BTREE],
                            pt->total_bytes_exclusive,
                            pt->items_bytes[ITEM_TYPE_KV],
                            pt->items_bytes[ITEM_TYPE_LIST],
                            pt->items_bytes[ITEM_TYPE_SET],
                            pt->items_bytes[ITEM_TYPE_MAP],
                            pt->items_bytes[ITEM_TYPE_BTREE],
                            t->tm_year+1900, t->tm_mon+1, t->tm_mday,
                            t->tm_hour, t->tm_min, t->tm_sec);
            assert(pos < buflen);
        }
        for (i = 0; i < prefix_hsize; i++) {
            pt = assoc->prefix_hashtable[i];
            while (pt) {
                t = localtime(&pt->create_time);
                pos += snprintf(buffer+pos, buflen-pos, format, _get_prefix(pt),
                                pt->total_count_exclusive,
                                pt->items_count[ITEM_TYPE_KV],
                                pt->items_count[ITEM_TYPE_LIST],
                                pt->items_count[ITEM_TYPE_SET],
                                pt->items_count[ITEM_TYPE_MAP],
                                pt->items_count[ITEM_TYPE_BTREE],
                                pt->total_bytes_exclusive,
                                pt->items_bytes[ITEM_TYPE_KV],
                                pt->items_bytes[ITEM_TYPE_LIST],
                                pt->items_bytes[ITEM_TYPE_SET],
                                pt->items_bytes[ITEM_TYPE_MAP],
                                pt->items_bytes[ITEM_TYPE_BTREE],
                                t->tm_year+1900, t->tm_mon+1, t->tm_mday,
                                t->tm_hour, t->tm_min, t->tm_sec);
                assert(pos < buflen);
                pt = pt->h_next;
            }
        }
        memcpy(buffer+pos, "END\r\n", 6);
        *(uint32_t*)buffer = pos + 5 - sizeof(uint32_t);

        *(char**)prefix_data = buffer;
    }
    else /* prefix stats on the given prefix */
    {
        prefix_engine_stats *prefix_stats = (prefix_engine_stats*)prefix_data;

        if (prefix != NULL) {
            pt = assoc_prefix_find(engine, engine->server.core->hash(prefix,nprefix,0),
                                   prefix, nprefix);
        } else {
            pt = root_pt;
        }
        if (pt == NULL) {
            return ENGINE_PREFIX_ENOENT;
        }

        prefix_stats->hash_items = pt->items_count[ITEM_TYPE_KV];
        prefix_stats->hash_items_bytes = pt->items_bytes[ITEM_TYPE_KV];
        prefix_stats->prefix_items = pt->prefix_items;
        if (prefix != NULL)
            prefix_stats->tot_prefix_items = pt->prefix_items;
        else
            prefix_stats->tot_prefix_items = assoc->tot_prefix_items;
    }
    return ENGINE_SUCCESS;
}
Esempio n. 9
0
/*
 * parse_format - Take the user's format specification and use it to build
 *	build the format specifications (internalize it to print.c data
 *	structures)
 * IN format - user's format specification
 * RET zero or error code
 */
extern int parse_format( char* format )
{
	int field_size;
	bool right_justify;
	char *prefix = NULL, *suffix = NULL, *token = NULL;
	char *tmp_char = NULL, *tmp_format = NULL;
	char field[1];

	if (format == NULL) {
		error ("Format option lacks specification.");
		exit( 1 );
	}

	params.format_list = list_create( NULL );
	if ((prefix = _get_prefix(format))) {
		job_format_add_prefix( params.format_list, 0, 0, prefix);
	}

	field_size = strlen( format );
	tmp_format = xmalloc( field_size + 1 );
	strcpy( tmp_format, format );

	token = strtok_r( tmp_format, "%", &tmp_char);
	if (token && (format[0] != '%'))	/* toss header */
		token = strtok_r( NULL, "%", &tmp_char );
	while (token) {
		_parse_token( token, field, &field_size, &right_justify,
			      &suffix);
		if (field[0] == 'a')
			job_format_add_age_priority_normalized(params.format_list,
							       field_size,
							       right_justify,
							       suffix );
		else if (field[0] == 'A')
			job_format_add_age_priority_weighted(params.format_list,
							     field_size,
							     right_justify,
							     suffix );
		else if (field[0] == 'f')
			job_format_add_fs_priority_normalized(params.format_list,
							      field_size,
							      right_justify,
							      suffix );
		else if (field[0] == 'F')
			job_format_add_fs_priority_weighted(params.format_list,
							    field_size,
							    right_justify,
							    suffix );
		else if (field[0] == 'i')
			job_format_add_job_id(params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		else if (field[0] == 'j')
			job_format_add_js_priority_normalized(params.format_list,
							      field_size,
							      right_justify,
							      suffix );
		else if (field[0] == 'J')
			job_format_add_js_priority_weighted(params.format_list,
							    field_size,
							    right_justify,
							    suffix );
		else if (field[0] == 'N')
			job_format_add_job_nice(params.format_list,
						field_size,
						right_justify,
						suffix );
		else if (field[0] == 'p')
			job_format_add_part_priority_normalized(params.format_list,
								field_size,
								right_justify,
								suffix );
		else if (field[0] == 'P')
			job_format_add_part_priority_weighted(params.format_list,
							      field_size,
							      right_justify,
							      suffix );
		else if (field[0] == 'q')
			job_format_add_qos_priority_normalized(params.format_list,
							       field_size,
							       right_justify,
							       suffix );
		else if (field[0] == 'Q')
			job_format_add_qos_priority_weighted(params.format_list,
							     field_size,
							     right_justify,
							     suffix );
		else if (field[0] == 'u')
			job_format_add_user_name(params.format_list,
						 field_size,
						 right_justify,
						 suffix );
		else if (field[0] == 'y')
			job_format_add_job_priority_normalized(params.format_list,
							       field_size,
							       right_justify,
							       suffix );
		else if (field[0] == 'Y')
			job_format_add_job_priority_weighted(params.format_list,
							     field_size,
							     right_justify,
							     suffix );
		else if (field[0] == 't')
			job_format_add_tres_normalized(params.format_list,
						     field_size, right_justify,
						     suffix);
		else if (field[0] == 'T')
			job_format_add_tres_weighted(params.format_list,
						     field_size, right_justify,
						     suffix);
		else
			error( "Invalid job format specification: %c",
			       field[0] );

		token = strtok_r( NULL, "%", &tmp_char);
	}

	xfree( tmp_format );
	return SLURM_SUCCESS;
}
Esempio n. 10
0
/*
 * parse_format - Take the user's format specification and use it to build
 *	build the format specifications (internalize it to print.c data
 *	structures)
 * IN format - user's format specification
 * RET zero or error code
 */
extern int parse_format( char* format )
{
	int field_size;
	bool right_justify;
	char *prefix = NULL, *suffix = NULL, *token = NULL;
	char *tmp_char = NULL, *tmp_format = NULL;
	char field[1];

	if (format == NULL) {
		error ("Format option lacks specification.");
		exit( 1 );
	}

	params.format_list = list_create( NULL );
	if ((prefix = _get_prefix(format))) {
		if (params.step_flag)
			step_format_add_prefix( params.format_list, 0, 0,
						prefix);
		else
			job_format_add_prefix( params.format_list, 0, 0,
					       prefix);
	}

	field_size = strlen( format );
	tmp_format = xmalloc( field_size + 1 );
	strcpy( tmp_format, format );

	token = strtok_r( tmp_format, "%", &tmp_char);
	if (token && (format[0] != '%'))	/* toss header */
		token = strtok_r( NULL, "%", &tmp_char );
	while (token) {
		_parse_token( token, field, &field_size, &right_justify,
			      &suffix);
		if (params.step_flag) {
			if      (field[0] == 'A')
				step_format_add_num_tasks( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'b')
				step_format_add_gres( params.format_list,
						      field_size,
						      right_justify, suffix );
			else if (field[0] == 'i')
				step_format_add_id( params.format_list,
						    field_size,
						    right_justify, suffix );
			else if (field[0] == 'j')
				step_format_add_name( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'l')
				step_format_add_time_limit( params.format_list,
							    field_size,
							    right_justify,
							    suffix );
			else if (field[0] == 'M')
				step_format_add_time_used( params.format_list,
							    field_size,
							    right_justify,
							    suffix );
			else if (field[0] == 'N')
				step_format_add_nodes( params.format_list,
						       field_size,
						       right_justify, suffix );
			else if (field[0] == 'P')
				step_format_add_partition( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'S')
				step_format_add_time_start( params.format_list,
							    field_size,
							    right_justify,
							    suffix );
			else if (field[0] == 'U')
				step_format_add_user_id( params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'u')
				step_format_add_user_name( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else {
				prefix = xstrdup("%");
				xstrcat(prefix, token);
				xfree(suffix);
				suffix = prefix;
				
				step_format_add_invalid( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
				error ( "Invalid job step format "
					"specification: %c",
					field[0] );
			}
		} else {
			if (field[0] == 'a')
				job_format_add_account( params.format_list,
							field_size,
							right_justify,
							suffix  );
			else if (field[0] == 'b')
				job_format_add_gres( params.format_list,
						     field_size, right_justify,
						     suffix );
			else if (field[0] == 'B')
				job_format_add_batch_host( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'c')
				job_format_add_min_cpus( params.format_list,
							 field_size,
							 right_justify,
							 suffix  );
			else if (field[0] == 'C')
				job_format_add_num_cpus( params.format_list,
							 field_size,
							 right_justify,
							 suffix  );
			else if (field[0] == 'd')
				job_format_add_min_tmp_disk(
							  params.format_list,
							  field_size,
							  right_justify,
							  suffix  );
			else if (field[0] == 'D')
				job_format_add_num_nodes( params.format_list,
							  field_size,
							  right_justify,
							  suffix  );
			else if (field[0] == 'e')
				job_format_add_time_end( params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'E')
				job_format_add_dependency( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'f')
				job_format_add_features( params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'g')
				job_format_add_group_name( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'G')
				job_format_add_group_id( params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'h')
				job_format_add_shared( params.format_list,
						       field_size,
						       right_justify,
						       suffix );
			else if (field[0] == 'H')
				job_format_add_sockets( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'i')
				job_format_add_job_id( params.format_list,
						       field_size,
						       right_justify,
						       suffix );
			else if (field[0] == 'I')
				job_format_add_cores( params.format_list,
						      field_size,
						      right_justify, suffix );
			else if (field[0] == 'j')
				job_format_add_name( params.format_list,
						     field_size,
						     right_justify, suffix );
			else if (field[0] == 'J')
				job_format_add_threads( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'k')
				job_format_add_comment( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'l')
				job_format_add_time_limit( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'L')
				job_format_add_time_left( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'm')
				job_format_add_min_memory( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'M')
				job_format_add_time_used( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'n')
				job_format_add_req_nodes( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'N')
				job_format_add_nodes( params.format_list,
						      field_size,
						      right_justify, suffix );
			else if (field[0] == 'O')
				job_format_add_contiguous( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 'p')
				job_format_add_priority( params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'P')
				job_format_add_partition( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'q')
				job_format_add_qos( params.format_list,
						    field_size,
						    right_justify,
						    suffix );
			else if (field[0] == 'Q')
				 job_format_add_priority_long(
							params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'r')
				job_format_add_reason( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'R')
				job_format_add_reason_list( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 's')
				job_format_add_select_jobinfo(
							 params.format_list,
							 field_size,
							 right_justify,
							 suffix );
			else if (field[0] == 'S')
				job_format_add_time_start( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else if (field[0] == 't')
				job_format_add_job_state_compact(
							params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'T')
				job_format_add_job_state( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'U')
				job_format_add_user_id( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'u')
				job_format_add_user_name( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'v')
				job_format_add_reservation( params.format_list,
							field_size,
							right_justify,
							suffix );
			else if (field[0] == 'w')
				job_format_add_wckey( params.format_list,
						      field_size,
						      right_justify,
						      suffix );
			else if (field[0] == 'W')
				job_format_add_licenses( params.format_list,
						     field_size,
						     right_justify, suffix );
			else if (field[0] == 'x')
				job_format_add_exc_nodes( params.format_list,
							  field_size,
							  right_justify,
							  suffix );
			else if (field[0] == 'z')
				job_format_add_num_sct( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
			else {
				prefix = xstrdup("%");
				xstrcat(prefix, token);
				xfree(suffix);
				suffix = prefix;
				
				job_format_add_invalid( params.format_list,
							   field_size,
							   right_justify,
							   suffix );
				error( "Invalid job format specification: %c",
				       field[0] );
			}
		}
		token = strtok_r( NULL, "%", &tmp_char);
	}

	xfree( tmp_format );
	return SLURM_SUCCESS;
}