/** * Internal function used to dump and free the contents of the list * If verbose is set to true, then _dump_node is called for each * node in the list. Otherwise, _dump_node is only called for * nodes that failed. */ static void _dump_list(bool verbose) { bool allpass = true; printf("Results: \n"); struct Node* temp = head; struct Node* next = NULL; while(temp != NULL) { if(verbose) { _dump_node(temp); if(!temp->pass) allpass = false; } else { if(!temp->pass) { allpass = false; _dump_node(temp); } } free(temp->expected); free(temp->actual); next = temp->next; free(temp); temp = next; } if(allpass) printf("\tAll tests passed.\n"); }
static char * _dump_all_nodes(int *node_cnt, time_t update_time) { int i, cnt = 0, rc; struct node_record *node_ptr = node_record_table_ptr; char *tmp_buf = NULL, *buf = NULL; struct node_record *uniq_node_ptr = NULL; hostlist_t hl = NULL; for (i=0; i<node_record_count; i++, node_ptr++) { if (node_ptr->name == NULL) continue; if (IS_NODE_FUTURE(node_ptr)) continue; if (_hidden_node(node_ptr)) continue; if (use_host_exp == 2) { rc = _same_info(uniq_node_ptr, node_ptr, update_time); if (rc == 0) { uniq_node_ptr = node_ptr; if (hl) { hostlist_push(hl, node_ptr->name); } else { hl = hostlist_create(node_ptr->name); if (hl == NULL) fatal("malloc failure"); } continue; } else { tmp_buf = _dump_node(uniq_node_ptr, hl, update_time); hostlist_destroy(hl); hl = hostlist_create(node_ptr->name); if (hl == NULL) fatal("malloc failure"); uniq_node_ptr = node_ptr; } } else { tmp_buf = _dump_node(node_ptr, hl, update_time); } if (cnt > 0) xstrcat(buf, "#"); xstrcat(buf, tmp_buf); xfree(tmp_buf); cnt++; } if (hl) { tmp_buf = _dump_node(uniq_node_ptr, hl, update_time); hostlist_destroy(hl); if (cnt > 0) xstrcat(buf, "#"); xstrcat(buf, tmp_buf); xfree(tmp_buf); cnt++; } *node_cnt = cnt; return buf; }
void cc_trie_match(struct cc_trie* tp, const char* prefix, trie_visit func, void* ud) { char c; struct cc_node* cur = pos2node(tp, tp->root); for(; (prefix && (c=*prefix++)); ) { struct cc_node* next = node_next(tp, cur, c); if(!next) return; cur = next; } // dump _dump_node(tp, cur, func, ud); }
static void _dump_node(struct cc_trie* tp, struct cc_node* root, trie_visit func, void* ud) { int i; if(root->has_ud) { func(root->ud, ud); } for(i=0; i<root->count; i++){ int idx = root->list[i]; struct cc_node* next = pos2node(tp, root->childs[idx]); _dump_node(tp, next, func, ud); } }
static void _dump_node(struct cc_trie* tp, struct cc_node* root, trie_visit func, void* ud) { int i; for(i=0; i<root->ud_slot.pos; i++) { unsigned int *p = root->ud_slot.p; unsigned int v = (p)?(p[i]):(root->ud_slot.tmp); func(v, ud); } for(i=0; i<root->count; i++) { int idx = root->list[i]; struct cc_node* next = pos2node(tp, root->childs[idx]); _dump_node(tp, next, func, ud); } }
static char * _dump_all_nodes(int *node_cnt, time_t update_time) { int i, cnt = 0; struct node_record *node_ptr = node_record_table_ptr; char *tmp_buf, *buf = NULL; for (i=0; i<node_record_count; i++, node_ptr++) { if (node_ptr->name == NULL) continue; if (IS_NODE_FUTURE(node_ptr)) continue; if (_hidden_node(node_ptr)) continue; tmp_buf = _dump_node(node_ptr, update_time); if (cnt > 0) xstrcat(buf, "#"); xstrcat(buf, tmp_buf); xfree(tmp_buf); cnt++; } *node_cnt = cnt; return buf; }
/* * get_nodes - get information on specific node(s) changed since some time * cmd_ptr IN - CMD=GETNODES ARG=[<UPDATETIME>:<NODEID>[:<NODEID>]...] * [<UPDATETIME>:ALL] * err_code OUT - 0 or an error code * err_msg OUT - response message * NOTE: xfree() err_msg if err_code is zero * RET 0 on success, -1 on failure * * Response format * ARG=<cnt>#<NODEID>: * STATE=<state>; Moab equivalent node state * [CAT=<reason>]; Reason for a node being down or drained * colon separator * CCLASS=<[part:cpus]>; SLURM partition with CPU count of node, * make have more than one partition * [CPULOAD=<load_ave>;] One minute BSD load average * [ARCH=<architecture>;] Computer architecture * [OS=<operating_system>;] Operating system * CMEMORY=<MB>; MB of memory on node * CDISK=<MB>; MB of disk space on node * CPROC=<cpus>; CPU count on node * [FEATURE=<feature>;] Features associated with node, if any * [GRES=<name>[:<count>],...;] generic resources on the node * [#<NODEID>:...]; */ extern int get_nodes(char *cmd_ptr, int *err_code, char **err_msg) { char *arg_ptr = NULL, *tmp_char = NULL, *tmp_buf = NULL, *buf = NULL; time_t update_time; /* Locks: read node, read partition */ slurmctld_lock_t node_read_lock = { NO_LOCK, NO_LOCK, READ_LOCK, READ_LOCK }; int node_rec_cnt = 0, buf_size = 0; #ifdef HAVE_ALPS_CRAY /* Locks: write node */ slurmctld_lock_t node_write_lock = { NO_LOCK, NO_LOCK, WRITE_LOCK, NO_LOCK }; /* * Run a Basil Inventory immediately before scheduling, to avoid * race conditions caused by ALPS node state change (caused e.g. * by the node health checker). * This relies on the above write lock for the node state. */ lock_slurmctld(node_write_lock); if (select_g_reconfigure()) { unlock_slurmctld(node_write_lock); *err_code = -720; *err_msg = "Unable to run ALPS inventory"; error("wiki: Unable to run ALPS inventory"); return -1; } unlock_slurmctld(node_write_lock); #endif arg_ptr = strstr(cmd_ptr, "ARG="); if (arg_ptr == NULL) { *err_code = -300; *err_msg = "GETNODES lacks ARG"; error("wiki: GETNODES lacks ARG"); return -1; } update_time = (time_t) strtoul(arg_ptr+4, &tmp_char, 10); if (tmp_char[0] != ':') { *err_code = -300; *err_msg = "Invalid ARG value"; error("wiki: GETNODES has invalid ARG value"); return -1; } tmp_char++; lock_slurmctld(node_read_lock); if (strncmp(tmp_char, "ALL", 3) == 0) { /* report all nodes */ buf = _dump_all_nodes(&node_rec_cnt, update_time); } else { struct node_record *node_ptr = NULL; char *node_name, *slurm_hosts; int node_cnt; hostset_t slurm_hostset; slurm_hosts = moab2slurm_task_list(tmp_char, &node_cnt); if ((slurm_hostset = hostset_create(slurm_hosts))) { while ((node_name = hostset_shift(slurm_hostset))) { node_ptr = find_node_record(node_name); if (node_ptr == NULL) { error("sched/wiki2: bad hostname %s", node_name); continue; } if (_hidden_node(node_ptr)) continue; tmp_buf = _dump_node(node_ptr, NULL, update_time); if (node_rec_cnt > 0) xstrcat(buf, "#"); xstrcat(buf, tmp_buf); xfree(tmp_buf); node_rec_cnt++; } hostset_destroy(slurm_hostset); } else { error("hostset_create(%s): %m", slurm_hosts); } xfree(slurm_hosts); } unlock_slurmctld(node_read_lock); /* Prepend ("ARG=%d", node_rec_cnt) to reply message */ if (buf) buf_size = strlen(buf); tmp_buf = xmalloc(buf_size + 32); if (node_rec_cnt) sprintf(tmp_buf, "SC=0 ARG=%d#%s", node_rec_cnt, buf); else sprintf(tmp_buf, "SC=0 ARG=0#"); xfree(buf); *err_code = 0; *err_msg = tmp_buf; return 0; }