END_TEST START_TEST(update_nodes_file_test) { int result = -1; struct pbsnode node; initialize_pbsnode(&node, NULL, NULL, 0, FALSE); result = update_nodes_file(NULL); fail_unless(result != PBSE_NONE, "update_nodes_file_test NULL input fail"); result = update_nodes_file(&node); fail_unless(result != PBSE_NONE, "update_nodes_file_test empty node fail"); }
int handle_auto_np( struct pbsnode *np, /* M */ const char *str) /* I */ { pbs_attribute nattr; /* first we decode str into nattr... + 6 is because str has format * ncpus=X, and 6 = strlen(ncpus=) */ if ((node_attr_def + ND_ATR_np)->at_decode(&nattr, ATTR_NODE_np, NULL, str + 6, 0) == 0) { /* ... and if MOM's ncpus is different than our np... */ if (nattr.at_val.at_long != np->nd_slots.get_total_execution_slots()) { /* ... then we do the defined magic to create new subnodes */ (node_attr_def + ND_ATR_np)->at_action(&nattr, (void *)np, ATR_ACTION_ALTER); update_nodes_file(np); } } return(PBSE_NONE); } /* END handle_auto_np() */
void mgr_node_modify( struct batch_request *preq) /* I */ { int need_todo = 0; int rc; int bad = 0; const char *nodename = NULL; svrattrl *plist; node_check_info nci; struct pbsnode *pnode = NULL; nodename = preq->rq_ind.rq_manager.rq_objname; pnode = find_nodebyname(nodename); if (pnode == NULL) { req_reject(PBSE_UNKNODE, 0, preq, NULL, NULL); return; } plist = (svrattrl *)GET_NEXT(preq->rq_ind.rq_manager.rq_attr); save_characteristic(pnode,&nci); rc = mgr_modify_node( &pnode, node_attr_def, ND_ATR_LAST, plist, preq->rq_perm, &bad, ATR_ACTION_ALTER); if (rc != 0) { /* In the specific node case, reply w/ error and return*/ switch (rc) { case PBSE_INTERNAL: case PBSE_SYSTEM: req_reject(rc, bad, preq, NULL, NULL); break; case PBSE_NOATTR: case PBSE_ATTRRO: case PBSE_MUTUALEX: case PBSE_BADNDATVAL: reply_badattr(rc, bad, plist, preq); break; default: req_reject(rc, 0, preq, NULL, NULL); break; } if(pnode != NULL) { unlock_node(pnode, "mgr_node_set", (char *)"error", LOGLEVEL); pnode = NULL; } return; } /* END if (rc != 0) */ else { /* modifications succeeded for this node */ if(pnode != NULL) { chk_characteristic(pnode, &nci, &need_todo); } } if(pnode != NULL) { unlock_node(pnode, "mgr_node_set", (char *)"single_node", LOGLEVEL); pnode = NULL; } if (need_todo & WRITENODE_STATE) { /*some nodes set to "offline"*/ write_node_state(); need_todo &= ~(WRITENODE_STATE); } if (need_todo & WRITENODE_POWER_STATE) { /*some nodes changed power state*/ write_node_power_state(); need_todo &= ~(WRITENODE_POWER_STATE); } if (need_todo & WRITENODE_NOTE) { /*some nodes have new "note"s*/ write_node_note(); need_todo &= ~(WRITENODE_NOTE); } if (need_todo & WRITE_NEW_NODESFILE) { /*create/delete/prop/ntype change*/ if (!update_nodes_file(NULL)) need_todo &= ~(WRITE_NEW_NODESFILE); /*successful on update*/ } recompute_ntype_cnts(); reply_ack(preq); /*request completely successful*/ return; } /* END void mgr_node_set() */
int is_gpustat_get( struct pbsnode *np, /* I (modified) */ unsigned int &i, std::vector<std::string> &status_info) { pbs_attribute temp; const char *gpuid = NULL; char log_buf[LOCAL_LOG_BUF_SIZE]; int gpuidx = -1; std::stringstream gpuinfo; int need_delimiter = FALSE; int reportedgpucnt = 0; int startgpucnt = 0; int drv_ver = 0; if (np == NULL) { sprintf(log_buf, "Invalid parameter for np passed to is_gpustat_get"); log_event(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, __func__, log_buf); return(PBSE_BAD_PARAMETER); } if (LOGLEVEL >= 7) { sprintf(log_buf, "received gpu status from node %s", np->nd_name); log_record(PBSEVENT_SCHED, PBS_EVENTCLASS_REQUEST, __func__, log_buf); } /* save current gpu count for node */ startgpucnt = np->nd_ngpus; /* * Before filling the "temp" pbs_attribute, initialize it. * The second and third parameter to decode_arst are never * used, so just leave them empty. (GBS) */ memset(&temp, 0, sizeof(temp)); if (decode_arst(&temp, NULL, NULL, NULL, 0)) { DBPRT(("is_gpustat_get: cannot initialize attribute\n")); return(DIS_NOCOMMIT); } i++; for (; i < status_info.size(); i++) { /* add the info to the "temp" attribute */ const char *str = status_info[i].c_str(); /* get timestamp */ if (!strncmp(str, "timestamp=", 10)) { if (decode_arst(&temp, NULL, NULL, str, 0)) { DBPRT(("is_gpustat_get: cannot add attributes\n")); free_arst(&temp); move_past_gpu_status(i, status_info); return(DIS_NOCOMMIT); } continue; } /* get driver version, if there is one */ if (!strncmp(str, "driver_ver=", 11)) { if (decode_arst(&temp, NULL, NULL, str, 0)) { DBPRT(("is_gpustat_get: cannot add attributes\n")); free_arst(&temp); move_past_gpu_status(i, status_info); return(DIS_NOCOMMIT); } drv_ver = atoi(str + 11); continue; } else if (!strcmp(str, END_GPU_STATUS)) { break; } /* gpuid must come before the rest or we will be in trouble */ if (!strncmp(str, "gpuid=", 6)) { if (gpuinfo.str().size() > 0) { if (decode_arst(&temp, NULL, NULL, gpuinfo.str().c_str(), 0)) { DBPRT(("is_gpustat_get: cannot add attributes\n")); free_arst(&temp); move_past_gpu_status(i, status_info); return(DIS_NOCOMMIT); } gpuinfo.str(""); } gpuid = &str[6]; /* * Get this gpus index, if it does not yet exist then find an empty entry. * We need to allow for the gpu status results being returned in * different orders since the nvidia order may change upon mom's reboot */ gpuidx = gpu_entry_by_id(np, gpuid, TRUE); if (gpuidx == -1) { /* * Failure - we could not get / create a nd_gpusn entry for this gpu, * log an error message. */ if (LOGLEVEL >= 3) { sprintf(log_buf, "Failed to get/create entry for gpu %s on node %s\n", gpuid, np->nd_name); log_ext(-1, __func__, log_buf, LOG_DEBUG); } free_arst(&temp); move_past_gpu_status(i, status_info); return(DIS_SUCCESS); } gpuinfo << "gpu[" << gpuidx << "]=gpu_id=" << gpuid << ";"; need_delimiter = FALSE; reportedgpucnt++; np->nd_gpusn[gpuidx].driver_ver = drv_ver; /* mark that this gpu node is not virtual */ np->nd_gpus_real = TRUE; /* * if we have not filled in the gpu_id returned by the mom node * then fill it in */ if ((gpuidx >= 0) && (np->nd_gpusn[gpuidx].gpuid == NULL)) { np->nd_gpusn[gpuidx].gpuid = strdup(gpuid); } } else { if (need_delimiter) { gpuinfo << ";"; } gpuinfo << str; need_delimiter = TRUE; } /* check current gpu mode and determine gpu state */ if (!memcmp(str, "gpu_mode=", 9)) { if ((!memcmp(str + 9, "Normal", 6)) || (!memcmp(str + 9, "Default", 7))) { np->nd_gpusn[gpuidx].mode = gpu_normal; if (gpu_has_job(np, gpuidx)) { np->nd_gpusn[gpuidx].state = gpu_shared; } else { np->nd_gpusn[gpuidx].inuse = 0; np->nd_gpusn[gpuidx].state = gpu_unallocated; } } else if ((!memcmp(str + 9, "Exclusive", 9)) || (!memcmp(str + 9, "Exclusive_Thread", 16))) { np->nd_gpusn[gpuidx].mode = gpu_exclusive_thread; if (gpu_has_job(np, gpuidx)) { np->nd_gpusn[gpuidx].state = gpu_exclusive; } else { np->nd_gpusn[gpuidx].inuse = 0; np->nd_gpusn[gpuidx].state = gpu_unallocated; } } else if (!memcmp(str + 9, "Exclusive_Process", 17)) { np->nd_gpusn[gpuidx].mode = gpu_exclusive_process; if (gpu_has_job(np, gpuidx)) { np->nd_gpusn[gpuidx].state = gpu_exclusive; } else { np->nd_gpusn[gpuidx].inuse = 0; np->nd_gpusn[gpuidx].state = gpu_unallocated; } } else if (!memcmp(str + 9, "Prohibited", 10)) { np->nd_gpusn[gpuidx].mode = gpu_prohibited; np->nd_gpusn[gpuidx].state = gpu_unavailable; } else { /* unknown mode, default to prohibited */ np->nd_gpusn[gpuidx].mode = gpu_prohibited; np->nd_gpusn[gpuidx].state = gpu_unavailable; if (LOGLEVEL >= 3) { sprintf(log_buf, "GPU %s has unknown mode on node %s", gpuid, np->nd_name); log_ext(-1, __func__, log_buf, LOG_DEBUG); } } /* add gpu_mode so it gets added to the pbs_attribute */ if (need_delimiter) { gpuinfo << ";"; } switch (np->nd_gpusn[gpuidx].state) { case gpu_unallocated: gpuinfo << "gpu_state=Unallocated"; break; case gpu_shared: gpuinfo << "gpu_state=Shared"; break; case gpu_exclusive: gpuinfo << "gpu_state=Exclusive"; break; case gpu_unavailable: gpuinfo << "gpu_state=Unavailable"; break; } } } /* end of while disrst */ if (gpuinfo.str().size() > 0) { if (decode_arst(&temp, NULL, NULL, gpuinfo.str().c_str(), 0)) { DBPRT(("is_gpustat_get: cannot add attributes\n")); free_arst(&temp); move_past_gpu_status(i, status_info); return(DIS_NOCOMMIT); } } /* maintain the gpu count, if it has changed we need to update the nodes file */ if (reportedgpucnt != startgpucnt) { np->nd_ngpus = reportedgpucnt; /* update the nodes file */ update_nodes_file(np); } node_gpustatus_list(&temp, np, ATR_ACTION_ALTER); move_past_gpu_status(i, status_info); return(DIS_SUCCESS); } /* END is_gpustat_get() */