int UIShowGrid( char *RBuffer, /* I */ char *Buffer, /* O */ int FLAGS, /* I */ char *Auth, /* I */ long *BufSize) /* I */ { int sindex; char GStat[MAX_MNAME]; const char *FName = "UIShowGrid"; DBG(3,fUI) DPrint("%s(RBuffer,Buffer,%d,%s,BufSize)\n", FName, FLAGS, Auth); MUSScanF(RBuffer,"%x%s", sizeof(GStat), GStat); /* determine statistics type requested */ for (sindex = 0;MStatType[sindex] != 0;sindex++) { if (!strcasecmp(MStatType[sindex],GStat)) break; } /* END for (sindex) */ if (MStatType[sindex] == NULL) { DBG(2,fUI) DPrint("INFO: invalid stat type '%s' requested\n", GStat); sprintf(Buffer,"ERROR: invalid statistics type requested\n"); strcat(Buffer,"\nvalid statistics types:\n"); for (sindex = 0;MStatType[sindex] != 0;sindex++) { strcat(Buffer,MStatType[sindex]); strcat(Buffer,"\n"); } /* END for (sindex) */ return(FAILURE); } /* END if (MStatType[sindex] == NULL) */ MStatBuildGrid(sindex,Buffer,0); return(SUCCESS); } /* END UIShowGrid() */
int MTraceLoadComputeNode( char *NodeLine, /* I */ mnode_t *N, /* O */ int Version) /* I */ { char *tok; char *TokPtr; char tmpLine[MAX_MLINE]; char tmpNLine[MAX_MLINE]; char ResourceType[MAX_MNAME]; char EventType[MAX_MNAME]; long ETime; char Name[MAX_MNAME]; char OpsysString[MAX_MNAME]; char ArchString[MAX_MNAME]; char FeatureString[MAX_MLINE]; char ClassString[MAX_MLINE]; char NetworkString[MAX_MLINE]; char GResString[MAX_MLINE]; char tmpSwapBuf[MAX_MNAME]; char tmpMemBuf[MAX_MNAME]; char tmpDiskBuf[MAX_MNAME]; int SlotsUsed; char RMName[MAX_MNAME]; int FIndex; int SIndex; int cindex; int rc; /* set default resource attributes */ memset(N,0,sizeof(mnode_t)); N->Load = 0.0; N->Speed = 1.0; N->PtIndex = 0; switch(Version) { case 230: if (strchr(NodeLine,';') != NULL) { sprintf(tmpNLine,"IFS-;%.*s", MAX_MLINE, NodeLine); } else { MUStrCpy(tmpNLine,NodeLine,sizeof(tmpNLine)); } /* FORMAT: <RESOURCETYPE> <EVENTTYPE> <EVENTTIME> <NAME> <RMINDEX> <SWAP> <MEMORY> <DISK> <MAXPROCS> <SLOTSUSED> <FRAMEINDEX> <SLOTINDEX> <OPSYS> <ARCH> [<FEATURE>]* [<CLASS>]* [<NETWORK>]* [<GRES>]* <RES1> <RES2> <RES3> */ rc = MUSScanF(tmpNLine,"%x%s %x%s %ld %x%s %x%s %x%s %x%s %x%s %d %d %d %d %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s %x%s", MAX_MNAME, ResourceType, MAX_MNAME, EventType, &ETime, MAX_MNAME, Name, MAX_MNAME, RMName, MAX_MNAME, tmpSwapBuf, MAX_MNAME, tmpMemBuf, MAX_MNAME, tmpDiskBuf, &N->CRes.Procs, &FIndex, &SIndex, &SlotsUsed, MAX_MNAME, OpsysString, MAX_MNAME, ArchString, MAX_MLINE, FeatureString, MAX_MLINE, ClassString, MAX_MLINE, NetworkString, MAX_MLINE, GResString, MAX_MLINE, tmpLine, /* RES1 */ MAX_MLINE, tmpLine, /* RES2 */ MAX_MLINE, tmpLine, /* RES3 */ MAX_MLINE, tmpLine /* check for too many lines */ ); if ((rc == EOF) || (rc != 21)) { DBG(3,fSIM) DPrint("ALERT: resource tracefile corruption (%d of %d fields detected) on line '%s'\n", rc, 21, NodeLine); return(FAILURE); } /* process node attributes */ N->CRes.Swap = MURSpecToL(tmpSwapBuf,mvmMega,mvmMega); N->CRes.Mem = MURSpecToL(tmpMemBuf,mvmMega,mvmMega); N->CRes.Disk = MURSpecToL(tmpDiskBuf,mvmMega,mvmMega); if (!strcmp(RMName,NONE)) MRMAdd(RMName,&N->RM); else MRMAdd(DEFAULT,&N->RM); /* load Opsys */ if (strstr(OpsysString,MAList[eOpsys][0]) == NULL) N->ActiveOS = MUMAGetIndex(eOpsys,OpsysString,mAdd); /* load Arch */ if (strstr(ArchString,MAList[eArch][0]) == NULL) N->Arch = MUMAGetIndex(eArch,ArchString,mAdd); memcpy(&N->ARes,&N->CRes,sizeof(N->ARes)); strcpy(N->Name,MNodeAdjustName(Name,0)); /* load classes */ if (MSim.Flags & ((1 << msimfIgnClass) | (1 << msimfIgnAll))) { mclass_t *C; /* ignore specified classes */ MClassAdd("DEFAULT",&C); N->CRes.PSlot[0].count = N->CRes.Procs; N->CRes.PSlot[C->Index].count = N->CRes.Procs; } else { MUNumListFromString(N->CRes.PSlot,ClassString,eClass); for (cindex = 1;cindex < MAX_MCLASS;cindex++) { if (N->CRes.PSlot[cindex].count > 0) MClassAdd(MAList[eClass][cindex],NULL); } } memcpy(N->ARes.PSlot,N->CRes.PSlot,sizeof(N->ARes.PSlot)); break; default: DBG(4,fSIM) DPrint("ALERT: cannot load version %d resource trace record\n", Version); return(FAILURE); /*NOTREACHED*/ break; } /* END switch(Version) */ if ((MSim.Flags & ((1 << msimfIgnFrame) | (1 << msimfIgnAll))) || (FIndex < 0)) { N->FrameIndex = -1; N->SlotIndex = -1; } else { MFrameAddNode(&MFrame[FIndex],N,SIndex); if ((N->FrameIndex > 0) && (N->FrameIndex < MAX_MFRAME) && (N->SlotIndex > 0) && (N->SlotIndex <= MAX_MSLOTPERFRAME)) { mhost_t *S; int nindex; S = &MSys[N->FrameIndex][N->SlotIndex]; S->SlotsUsed = SlotsUsed; for (nindex = 0;nindex < MAX_MNETTYPE;nindex++) strcpy(S->NetName[nindex],N->Name); if (!strstr(ClassString,"NONE")) S->Attributes |= (1 << attrBatch); S->MTime = MSched.Time; } /* END if ((N->FrameIndex > 0) ... ) */ } /* END else if (MSim.Flags & ((1 << msimfIgnFrame) | ...)) */ /* initialize statistics */ N->STTime = 0; N->SUTime = 0; N->SATime = 0; /* load state */ if (N->CRes.Procs <= 0) { N->State = mnsNone; } else { if (!strcmp(EventType,"AVAILABLE")) N->State = mnsIdle; else if (!strcmp(EventType,"DEFINED")) N->State = mnsDown; else if (!strcmp(EventType,"DRAINED")) N->State = mnsDrained; else N->State = mnsNONE; } /* END else (N->CRes.Procs <= 0) */ N->EState = N->State; memcpy(&N->ARes,&N->CRes,sizeof(N->ARes)); /* load features */ if (strstr(FeatureString,MAList[eFeature][0]) == NULL) { tok = MUStrTok(FeatureString,"[]",&TokPtr); do { MNodeProcessFeature(N,tok); DBG(6,fSIM) DPrint("INFO: feature '%s' added (%s)\n", tok, MUMAList(eFeature,N->FBM,sizeof(N->FBM))); } while ((tok = MUStrTok(NULL,"[]",&TokPtr)) != NULL); } /* load network adapters */ if (strstr(NetworkString,MAList[eNetwork][0]) == NULL) { tok = MUStrTok(NetworkString,"[]",&TokPtr); do { N->Network |= MUMAGetBM(eNetwork,tok,mAdd); DBG(6,fSIM) DPrint("INFO: network '%s' added (%s)\n", tok, MUListAttrs(eNetwork,N->Network)); } while ((tok = MUStrTok(NULL,"[]",&TokPtr)) != NULL); } /* load generic resources */ if (!strcmp(GResString,NONE) != 0) { MUNumListFromString(N->CRes.GRes,GResString,eGRes); } DBG(4,fSIM) DPrint("INFO: node '%s' F:%d/S:%d %06d %04d %06d %02d %02d %10s %10s %20s %20s\n", N->Name, N->FrameIndex, N->SlotIndex, N->CRes.Swap, N->CRes.Mem, N->CRes.Disk, N->CRes.Procs, SlotsUsed, OpsysString, ArchString, FeatureString, MUCAListToString(N->CRes.PSlot,NULL,NULL)); return(SUCCESS); } /* END MTraceLoadComputeNode() */
int MTraceLoadNetwork( char *NodeLine, /* I */ mnode_t *N, /* I/O */ int Version) /* I */ { char ResourceType[MAX_MNAME]; char EventType[MAX_MNAME]; char Name[MAX_MNAME]; long ETime; char ResType[MAX_MNAME]; char ResData[MAX_MNAME]; char tmpLine[MAX_MLINE]; int rindex; int rc; xres_t *R; if ((NodeLine == NULL) || (N == NULL)) { return(FAILURE); } switch (Version) { default: /* FORMAT: <RESOURCETYPE> <EVENTTYPE> <EVENTTIME> <NAME> <RESTYPE> <RESDATA> */ rc = MUSScanF(NodeLine,"%x%s %x%s %ld %x%s %x%s %x%s", MAX_MNAME, ResourceType, MAX_MNAME, EventType, &ETime, MAX_MNAME, Name, MAX_MNAME, ResType, MAX_MNAME, ResData); /* locate available X res slot */ for (rindex = 0;rindex < MAX_MNODE;rindex++) { R = &MPar[0].XRes[rindex]; if ((R->Name[0] != '\0') && (R->Name[0] != '\1')) { continue; } /* load xres driver */ MASGetDriver((void **)&R->Func,ResType,msdResource); /* create and initialize resource */ sprintf(tmpLine,"NAME=%s;STATE=ACTIVE;%s", Name, ResData); rc = (*R->Func)(&R->Data,mascCreate,tmpLine,NULL); MUStrCpy(R->Name,Name,sizeof(R->Name)); /* FIXME */ R->Type = msdResource; break; } break; } /* END switch(Version) */ return(rc); } /* END MTraceLoadNetwork() */
int ShowBackfillWindow( char *RBuffer, /* I */ char *Buffer, /* O */ int FLAGS, /* I */ char *Auth, /* I */ long *BufSize) /* I */ { int BFNodeCount; int BFProcCount; nodelist_t BFNodeList; long BFTime; long MinTime; long RequiredTime; long RequiredNodes; long RequiredProcs; char UserName[MAX_MNAME]; char GroupName[MAX_MNAME]; char AccountName[MAX_MNAME]; int Memory; char MemCmp[MAX_MNAME]; int DMemory; char PName[MAX_MNAME]; char CurrentPName[MAX_MNAME]; int index; int pindex; int mindex; int nindex; int ShowSMP; /* (boolean) */ char Affinity; int Type; int Flags; char QOSName[MAX_MNAME]; char ClassString[MAX_MLINE]; char FeatureString[MAX_MLINE]; mnode_t *N; mjob_t tmpJ; mjob_t *J; mreq_t tmpRQ; mcres_t DRes; mpar_t *P; mpar_t *SP; mrange_t ARange[MAX_MRANGE]; mrange_t RRange[2]; int NodeHeaderPrinted; int PCount; char tmpBuffer[MAX_MBUFFER]; const char *FName = "ShowBackfillWindow"; DBG(2,fUI) DPrint("%s(%s,Buffer,%d,%s,BufSize)\n", FName, RBuffer, FLAGS, Auth); if (MUSScanF(RBuffer,"%x%s %x%s %x%s %x%s %ld %ld %ld %d %d %x%s %d %d %x%s %x%s %x%s", sizeof(UserName), UserName, sizeof(GroupName), GroupName, sizeof(AccountName), AccountName, sizeof(PName), PName, &RequiredTime, &RequiredNodes, &RequiredProcs, &DMemory, &Memory, sizeof(MemCmp), MemCmp, &ShowSMP, &Flags, sizeof(ClassString), ClassString, sizeof(FeatureString), FeatureString, sizeof(QOSName), QOSName) == FAILURE) { /* invalid request string */ DBG(3,fUI) DPrint("INFO: cannot parse request\n"); sprintf(Buffer,"ERROR: cannot parse request\n"); return(FAILURE); } MParFind(PName,&SP); DBG(4,fUI) DPrint("INFO: locating backfill window for u: %s g: %s a: %s p: %s c: %s f: %s (%ld:%ld:%d)\n", UserName, GroupName, AccountName, MAList[ePartition][(SP != NULL) ? SP->Index : 0], ClassString, FeatureString, RequiredTime, RequiredNodes, Memory); if (ShowSMP == FALSE) /* NON-SMP */ { mindex = 0; if (Memory > 0) { for (mindex = 0;MComp[mindex] != NULL;mindex++) { if (!strcasecmp(MComp[mindex],MemCmp)) break; } if (MComp[mindex] == NULL) mindex = 0; } memset(&DRes,0,sizeof(DRes)); DRes.Procs = 1; DRes.Mem = DMemory; sprintf(Buffer,"backfill window (user: '******' group: '%s' partition: %s) %s\n", UserName, GroupName, PName, MULToDString((mulong *)&MSched.Time)); PCount = 0; for (pindex = 1;pindex < MAX_MPAR;pindex++) { if (MPar[pindex].ConfigNodes == 0) continue; PCount++; } index = 0; for (pindex = 0;pindex < MAX_MPAR;pindex++) { P = &MPar[pindex]; if ((SP != NULL) && (SP != P)) continue; if ((PCount == 1) && (SP == NULL) && (P->Index != 0)) break; if (P->ConfigNodes == 0) continue; MinTime = 0; DBG(7,fUI) DPrint("INFO: checking window in partition %s\n", P->Name); strcpy(CurrentPName,GLOBAL_MPARNAME); index = 0; while (MBFGetWindow( &BFNodeCount, &BFProcCount, BFNodeList, &BFTime, MinTime, P, UserName, GroupName, AccountName, mindex, Memory, MAX(1,RequiredTime), &DRes, ClassString, FeatureString, QOSName, (Flags & (1 << mcmVerbose)) ? tmpBuffer : NULL) == SUCCESS) { DBG(4,fUI) DPrint("INFO: located backfill window [%03d nodes : %06ld seconds]\n", BFNodeCount, BFTime); if ((BFTime >= RequiredTime) && (BFNodeCount >= RequiredNodes) && (BFProcCount >= RequiredProcs)) { if (strcasecmp(P->Name,CurrentPName) != 0) { if ((strcasecmp(CurrentPName,GLOBAL_MPARNAME)) && (index == 0)) { sprintf(Buffer,"%sno %s available\n", Buffer, (MSched.DisplayFlags & (1 << dfNodeCentric)) ? "nodes" : "procs"); } strcpy(CurrentPName,P->Name); sprintf(Buffer,"%s\npartition %s:\n", Buffer, P->Name); index = 0; } if (MSched.DisplayFlags & (1 << dfNodeCentric)) { /* node centric output */ if (BFNodeCount == 0) { sprintf(Buffer,"%sno nodes available\n", Buffer); } else if (BFTime < 100000000) { sprintf(Buffer,"%s%3d node%s available for %11s\n", Buffer, BFNodeCount, (BFNodeCount > 1) ? "s" : "", MULToTString(BFTime)); } else { sprintf(Buffer,"%s%3d node%s available with no timelimit\n", Buffer, BFNodeCount, (BFNodeCount > 1) ? "s" : ""); } } else { /* proc centric output */ if (BFProcCount == 0) { sprintf(Buffer,"%sno procs available\n", Buffer); } else if (BFTime < 100000000) { sprintf(Buffer,"%s%3d proc%s available for %11s\n", Buffer, BFProcCount, (BFProcCount > 1) ? "s" : "", MULToTString(BFTime)); } else { sprintf(Buffer,"%s%3d proc%s available with no timelimit\n", Buffer, BFProcCount, (BFProcCount > 1) ? "s" : ""); } } index++; } /* END if (BFTime) */ MinTime = BFTime; } /* END while (MBFGetWindow() == SUCCESS) */ if (Flags & (1 << mcmVerbose)) { strcat(Buffer,"\n\n"); strcat(Buffer,tmpBuffer); } } /* END for (pindex) */ if (index == 0) { sprintf(Buffer,"%sno procs available\n", Buffer); } strcat(Buffer,"\n\n"); } /* END if (ShowSMP == FALSE) */ else { /* SMP Mode */ RRange[0].StartTime = MSched.Time; RRange[0].EndTime = MAX_MTIME; RRange[1].EndTime = 0; memset(&tmpJ,0,sizeof(tmpJ)); memset(&tmpRQ,0,sizeof(tmpRQ)); J = &tmpJ; tmpRQ.DRes.Procs = 1; tmpRQ.DRes.Mem = DMemory; J->Req[0] = &tmpRQ; if (MJobSetCreds(J,ALL,ALL,ALL) == FAILURE) { DBG(3,fUI) DPrint("INFO: cannot setup showbf job creds\n"); sprintf(Buffer,"ERROR: cannot determine available resources\n"); return(FAILURE); } if (MQOSFind(QOSName,&J->QReq) == FAILURE) { /* cannot locate requested QOS */ MQOSFind(DEFAULT,&J->QReq); } MJobSetQOS(J,J->QReq,0); MJobBuildCL(J); sprintf(Buffer,"%s%20s %5s %6s %7s %7s %14s\n", Buffer, "HostName", "Procs", "Memory", "Disk", "Swap", "Time Available"); sprintf(Buffer,"%s%20s %5s %6s %7s %7s %14s\n", Buffer, "----------", "-----", "------", "-------", "-------", "--------------"); for (nindex = 0;nindex < MAX_MNODE;nindex++) { N = MNode[nindex]; if ((N == NULL) || (N->Name[0] == '\0')) break; if (N->Name[0] == '\1') continue; if ((N->State != mnsActive) && (N->State != mnsIdle)) continue; if ((SP != NULL) && (SP->Index != 0) && (N->PtIndex != SP->Index)) continue; NodeHeaderPrinted = FALSE; for (RRange[0].TaskCount = 1;RRange[0].TaskCount < N->CRes.Procs;RRange[0].TaskCount = ARange[0].TaskCount + 1) { if (MJobGetSNRange( J, J->Req[0], N, RRange, 1, &Affinity, &Type, ARange, &DRes, NULL) == SUCCESS) { if (ARange[0].StartTime != MSched.Time) { /* resources not available immediately */ break; } if (NodeHeaderPrinted == FALSE) { strcat(Buffer,"\n"); NodeHeaderPrinted = TRUE; } sprintf(Buffer,"%s%20s %5d %6d %7d %7d %14s\n", Buffer, N->Name, DRes.Procs, DRes.Mem, DRes.Disk, DRes.Swap, MULToTString(ARange[0].EndTime - MSched.Time)); } else { /* resources not available */ break; } } } /* END for (nindex) */ } /* END else (ShowSMP == FALSE) */ return(SUCCESS); } /* END ShowBackfillWindow() */
int SetJobUserPrio( char *RBuffer, char *Buffer, int FLAGS, char *Auth, long *BufSize) { char Name[MAX_MNAME]; int Priority; mjob_t *J; const char *FName = "SetJobUserPrio"; DBG(2,fUI) DPrint("%s(RBuffer,Buffer,%d,%s,BufSize)\n", FName, FLAGS, Auth); MUSScanF(RBuffer,"%x%s %d", sizeof(Name), Name, &Priority); if ((Priority < 0) || (Priority > 100)) { strcpy(Buffer,"ERROR: user priority must be in the range 0 - 100\n"); return(FAILURE); } if (MJobFind(Name,&J,0) == FAILURE) { sprintf(Buffer,"Error: cannot locate job '%s'\n", Name); return(FAILURE); } /* security check */ if (!(FLAGS & ((1 << fAdmin1) | (1 << fAdmin2)))) { if (strcasecmp(J->Cred.U->Name,Auth) != 0) { DBG(2,fUI) DPrint("INFO: user %s is not authorized to set user priority on job %s\n", Auth, J->Name); sprintf(Buffer,"user %s is not authorized to set user priority on job %s\n", Auth, J->Name); return(FAILURE); } } J->UPriority = Priority; DBG(2,fUI) DPrint("INFO: user priority on job '%s' set to %d\n", Name, Priority); return(SUCCESS); } /* END JobSetUserPrio() */
int MCfgAdjustBuffer( char **Buf, /* I (modified) */ mbool_t AllowExtension) /* I */ { char *ptr; int State; char IFile[MAX_MLINE]; /* change all parameters to upper case */ /* replace all comments with spaces */ /* replace tabs with space */ /* replace '"' with space */ /* replace unprint chars with space */ /* extend '\' lines */ enum { cbPreParm = 0, cbOnParm, cbPreVal, cbOnVal, cbComment }; const char *FName = "MCfgAdjustBuffer"; DBG(3,fCONFIG) DPrint("%s(Buf)\n", FName); if ((Buf == NULL) || (*Buf == NULL) || (strlen(*Buf) < 1)) { return(SUCCESS); } ptr = *Buf; State = cbPreParm; IFile[0] = '\0'; while (*ptr != '\0') { /* remove comments */ if (*ptr == '#') { if (AllowExtension == TRUE) { /* look for include */ if (!strncmp(ptr,"#INCLUDE",strlen("#INCLUDE"))) { int rc; /* FORMAT: #INCLUDE <FILENAME> */ rc = MUSScanF(ptr + strlen("#INCLUDE"),"%x%s", MAX_SULINE, IFile); } } State = cbComment; } /* END if (*ptr == '#') */ else if ((*ptr == '\\') && (State != cbComment)) { *ptr = ' '; while(isspace(*ptr)) { *ptr = ' '; ptr++; } } else if (*ptr == '\n') { if ((State == cbComment) && (IFile[0] != '\0')) { char *IBuf; int blen; int offset; /* include file at end */ /* load file */ if ((IBuf = MFULoad(IFile,1,macmWrite,NULL,NULL)) == NULL) { /* cannot load include file */ } else { blen = strlen(*Buf); offset = ptr - *Buf; if ((*Buf = (char *)realloc(*Buf,blen + 2 + strlen(IBuf))) == NULL) { /* NOTE: memory failure */ MUFree(&IBuf); return(FAILURE); } /* append file */ strcat(*Buf,"\n"); strcat(*Buf,IBuf); MUFree(&IBuf); ptr = *Buf + offset; } IFile[0] = '\0'; } /* END if ((State == cbComment) && (IFile[0] != '\0')) */ State = cbPreParm; } else if ((State == cbComment) || (*ptr == '\\')) { *ptr = ' '; } else if (isspace(*ptr) || (*ptr == '=')) { if (*ptr == '=') { if (State != cbOnVal) *ptr = ' '; } else { if (State == cbOnParm) State = cbPreVal; *ptr = ' '; } } else if (isprint(*ptr)) { if (State == cbPreParm) { State = cbOnParm; /* if (isalpha(*ptr)) *ptr = toupper(*ptr); */ } else if (State == cbPreVal) { State = cbOnVal; } } else { *ptr = ' '; } ptr++; } /* END while (ptr != '\0') */ DBG(5,fCONFIG) DPrint("INFO: adjusted config Buffer ------\n%s\n------\n", *Buf); return(SUCCESS); } /* END MCfgAdjustBuffer() */