struct pbsnode *find_fitting_node( struct prop *needed) { struct pbsnode *pnode = NULL; login_node *ln; login_node *ordered_ln; int iter = -1; int ordered_iter; int index; resizable_array *ordered = initialize_resizable_array(logins.ra->num + 1); /* create a sorted list of the logins */ while ((ln = (login_node *)next_thing(logins.ra, &iter)) != NULL) { /* if ordered is empty just insert without attempting to sort */ if (ordered->num == 0) insert_thing(ordered, ln); else { ordered_iter = -1; index = ordered->slots[ALWAYS_EMPTY_INDEX].next; while ((ordered_ln = (login_node *)next_thing(ordered, &ordered_iter)) != NULL) { if (ln->times_used <= ordered_ln->times_used) { insert_thing_before(ordered, ln, index); break; } index = ordered_iter; } /* insert if it hasn't been inserted yet */ if (ordered_ln == NULL) insert_thing(ordered, ln); } } iter = -1; while ((ln = (login_node *)next_thing(ordered, &iter)) != NULL) { if ((pnode = check_node(ln, needed)) != NULL) { ln->times_used++; free_resizable_array(ordered); return(pnode); } } free_resizable_array(ordered); return(NULL); } /* END find_fitting_node() */
int add_node_names( alps_reservation *ar, job *pjob) { char *exec_str = strdup(pjob->ji_wattr[JOB_ATR_exec_host].at_val.at_str); char *host_tok; char *str_ptr = exec_str; char *slash; int rc = PBSE_NONE; char *prev_node = NULL; ar->ar_node_names = initialize_resizable_array(INITIAL_NODE_LIST_SIZE); while ((host_tok = threadsafe_tokenizer(&str_ptr, "+")) != NULL) { if ((slash = strchr(host_tok, '/')) != NULL) *slash = '\0'; if ((prev_node == NULL) || (strcmp(prev_node, host_tok))) { if ((rc = insert_thing(ar->ar_node_names, host_tok)) < 0) break; else rc = PBSE_NONE; } prev_node = host_tok; } return(rc); } /* END add_node_names() */
int insert_batch_request( batch_request *preq) { int rc; pthread_mutex_lock(brh.brh_mutex); if ((rc = insert_thing(brh.brh_ra, preq)) < 0) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE\n"); } else { add_hash(brh.brh_ht, rc, preq->rq_id); rc = PBSE_NONE; } pthread_mutex_unlock(brh.brh_mutex); return(rc); } /* END insert_batch_request() */
int insert_queue( all_queues *aq, pbs_queue *pque) { int rc; pthread_mutex_lock(aq->allques_mutex); if ((rc = insert_thing(aq->ra,pque)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"No memory to resize the array"); } else { add_hash(aq->ht,rc,pque->qu_qs.qu_name); rc = PBSE_NONE; } pthread_mutex_unlock(aq->allques_mutex); return(rc); } /* END insert_queue() */
int insert_queue( all_queues *aq, pbs_queue *pque) { int rc; lock_allques_mutex(aq, __func__, NULL, LOGLEVEL); if ((rc = insert_thing(aq->ra,pque)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array"); } else { add_hash(aq->ht,rc,pque->qu_qs.qu_name); rc = PBSE_NONE; } unlock_allques_mutex(aq, __func__, NULL, LOGLEVEL); return(rc); } /* END insert_queue() */
/* * insert a new job into the array * * @param pjob - the job to be inserted * @return PBSE_NONE on success */ int insert_job( struct all_jobs *aj, job *pjob) { int rc; pthread_mutex_lock(aj->alljobs_mutex); if ((rc = insert_thing(aj->ra,pjob)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE\n"); } else { add_hash(aj->ht, rc, pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job() */
int add_to_hash_map( hash_map *hm, void *obj, char *key) { int index; int rc = PBSE_NONE; pthread_mutex_lock(hm->hm_mutex); if (get_value_hash(hm->hm_ht, key) >= 0) { rc = ALREADY_IN_HASH_MAP; } else { if ((index = insert_thing(hm->hm_ra, obj)) == -1) { rc = ENOMEM; log_err(rc, __func__, "Memory failure"); } else add_hash(hm->hm_ht, index, key); } pthread_mutex_unlock(hm->hm_mutex); return(rc); } /* END add_to_hash_map() */
void tasks_free( job *pj) { task *tp = (task *)GET_NEXT(pj->ji_tasks); obitent *op; infoent *ip; resizable_array *freed_chans = initialize_resizable_array(30); while (tp != NULL) { op = (obitent *)GET_NEXT(tp->ti_obits); while (op != NULL) { delete_link(&op->oe_next); free(op); op = (obitent *)GET_NEXT(tp->ti_obits); } /* END while (op != NULL) */ ip = (infoent *)GET_NEXT(tp->ti_info); while (ip != NULL) { delete_link(&ip->ie_next); free(ip->ie_name); free(ip->ie_info); free(ip); ip = (infoent *)GET_NEXT(tp->ti_info); } if (tp->ti_chan != NULL) { if (is_present(freed_chans, tp->ti_chan) == FALSE) { insert_thing(freed_chans, tp->ti_chan); close_conn(tp->ti_chan->sock, FALSE); DIS_tcp_cleanup(tp->ti_chan); } tp->ti_chan = NULL; } delete_link(&tp->ti_jobtask); free(tp); tp = (task *)GET_NEXT(pj->ji_tasks); } /* END while (tp != NULL) */ free_resizable_array(freed_chans); return; } /* END tasks_free() */
resizable_array *sort_exec_hosts( resizable_array *exec_hosts, const char *mppnodes) { if(mppnodes == NULL) { return exec_hosts; } char *tmp = strdup(mppnodes); char *tmp_str = tmp; resizable_array *tmp_host_list = initialize_resizable_array(100); char *tok; int iter; host_req *pHr; while((tok = threadsafe_tokenizer(&tmp_str,",")) != NULL) { iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { if(strcmp(pHr->hostname,tok) == 0) { insert_thing(tmp_host_list,pHr); remove_thing(exec_hosts,pHr); break; } } } iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { insert_thing(tmp_host_list,pHr); } free_resizable_array(exec_hosts); free(tmp); return tmp_host_list; }
int insert_alps_reservation( alps_reservation *ar) { int index; int rc; pthread_mutex_lock(alps_reservations.rh_mutex); if ((index = insert_thing(alps_reservations.rh_alps_rsvs, ar)) >= 0) rc = add_hash(alps_reservations.rh_ht, index, ar->rsv_id); else rc = ENOMEM; pthread_mutex_unlock(alps_reservations.rh_mutex); return(rc); } /* insert_alps_reservation() */
/* * insert pa into the global array */ int insert_array( job_array *pa) { int rc; pthread_mutex_lock(allarrays.allarrays_mutex); if ((rc = insert_thing(allarrays.ra,pa)) == -1) { log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE\n"); } pthread_mutex_unlock(allarrays.allarrays_mutex); return(rc); } /* END insert_array() */
int increment_queued_jobs( user_info_holder *uih, char *user_name, job *pjob) { int rc = PBSE_NONE; user_info *ui; int index; unsigned int num_submitted = count_jobs_submitted(pjob); pthread_mutex_lock(uih->ui_mutex); /* get the user if there is one */ if ((index = get_value_hash(uih->ui_ht, user_name)) > 0) { ui = uih->ui_ra->slots[index].item; ui->num_jobs_queued += num_submitted; } else { /* user doesn't exist, create a new one and insert */ ui = calloc(1, sizeof(user_info)); ui->user_name = strdup(user_name); ui->num_jobs_queued = num_submitted; if ((index = insert_thing(uih->ui_ra, ui)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"Can't resize the user info array"); } else { add_hash(uih->ui_ht, index, ui->user_name); } } pthread_mutex_unlock(uih->ui_mutex); return(rc); } /* END increment_queued_jobs() */
resizable_array *parse_exec_hosts( char *exec_hosts_param) { char *slash; char *host_tok; char *exec_hosts = strdup(exec_hosts_param); char *str_ptr = exec_hosts; char *delims = "+"; char *prev_host_tok = NULL; host_req *hr; resizable_array *host_req_list = initialize_resizable_array(100); while ((host_tok = threadsafe_tokenizer(&str_ptr, delims)) != NULL) { if ((slash = strchr(host_tok, '/')) != NULL) *slash = '\0'; /* skip this host - the login shouldn't be part of the alps reservation */ if ((strcmp(mom_host, host_tok)) && (strcmp(mom_alias, host_tok))) { if ((prev_host_tok != NULL) && (!strcmp(prev_host_tok, host_tok))) { hr = (host_req *)host_req_list->slots[host_req_list->last].item; hr->ppn += 1; } else { prev_host_tok = host_tok; hr = get_host_req(host_tok); insert_thing(host_req_list, hr); } } } free(exec_hosts); return(host_req_list); } /* END parse_exec_hosts() */
int add_to_login_holder( struct pbsnode *pnode) { login_node *ln = (login_node *)calloc(1, sizeof(login_node)); int rc; ln->pnode = pnode; pthread_mutex_lock(logins.ln_mutex); if ((rc = insert_thing(logins.ra, ln)) >= 0) { logins.next_node = rc; rc = PBSE_NONE; } pthread_mutex_unlock(logins.ln_mutex); return(rc); } /* END add_to_login_holder() */
int insert_task( all_tasks *at, work_task *wt) { int rc; pthread_mutex_lock(at->alltasks_mutex); if ((rc = insert_thing(at->ra,wt)) == -1) { rc = ENOMEM; log_err(rc, __func__, "Cannot allocate space to resize the array"); } wt->wt_tasklist = at; pthread_mutex_unlock(at->alltasks_mutex); return(rc); } /* END insert_task() */
int insert_addr_name_info( char *hostname, char *full_hostname, struct sockaddr_in *sai) { int rc = PBSE_NONE; int index; network_info *ni; char s_addr_key[65]; if (cache.nc_mutex == NULL) return(-1); pthread_mutex_lock(cache.nc_mutex); /* only insert if it isn't already there */ if (get_value_hash(cache.nc_namekey, hostname) < 0) { ni = get_network_info_holder(hostname, full_hostname, sai); if ((index = insert_thing(cache.nc_ra, ni)) < 0) rc = ENOMEM; else { /* store the key in both hash tables so we can look things up either way */ add_hash(cache.nc_namekey, index, ni->hostname); sprintf (s_addr_key, "%d", sai->sin_addr.s_addr); add_hash(cache.nc_saikey, index, strdup(s_addr_key)); } } pthread_mutex_unlock(cache.nc_mutex); return(rc); } /* END insert_addr_name_info() */
int add_network_entry( mom_hierarchy_t *nt, char *name, struct addrinfo *addr_info, unsigned short rm_port, int path, int level) { int rc; node_comm_t *nc = (node_comm_t *)calloc(1, sizeof(node_comm_t)); resizable_array *levels; resizable_array *node_comm_entries; /* check if the path is already in the array */ if (nt->paths->num > path) levels = (resizable_array *)nt->paths->slots[path+1].item; else { /* insert a new path */ levels = initialize_resizable_array(INITIAL_SIZE_NETWORK); if (levels == NULL) { free(nc); return(-1); } if ((rc = insert_thing(nt->paths,levels)) < 0) { free(nc); return(rc); } } /* check if the level is in the array already */ if (levels->num > level) node_comm_entries = (resizable_array *)levels->slots[level+1].item; else { /* insert a new level */ node_comm_entries = initialize_resizable_array(INITIAL_SIZE_NETWORK); if (node_comm_entries == NULL) return(-1); if ((rc = insert_thing(levels,node_comm_entries)) < 0) { free(nc); return(rc); } } /* finally, insert the entry into the node_comm_entries */ /* initialize the node comm entry */ nc->sock_addr.sin_addr = ((struct sockaddr_in *)addr_info->ai_addr)->sin_addr; nc->sock_addr.sin_family = AF_INET; nc->sock_addr.sin_port = htons(rm_port); nc->stream = -1; if ((nc->name = (char *)calloc(1, strlen(name) + 1)) == NULL) { free(nc); return(ENOMEM); } else strcpy(nc->name,name); if ((rc = insert_thing(node_comm_entries,nc)) < 0) return(rc); else return(PBSE_NONE); } /* END add_network_entry() */