コード例 #1
0
ファイル: MGroup.c プロジェクト: hocks/TSCC
char *MGroupShow(

    mgcred_t *G,        /* I */
    char     *SBuffer,  /* O (optional) */
    long     *SBufSize, /* I */
    long      Mode)     /* I */

{
    static char Line[MAX_MLINE];

    char FlagLine[MAX_MLINE];

    char QALLine[MAX_MLINE];
    char QALChar;

    char GLLine[MAX_MLINE];

    char *Head;

    char *BPtr;
    int   BSpace;

    const char *FName = "MGroupShow";

    DBG(3,fUI) DPrint("%s(%s,Buf,BufSize,%ld)\n",
                      FName,
                      (G != NULL) ? G->Name : "NULL",
                      Mode);

    if (SBuffer != NULL)
    {
        BPtr   = SBuffer;
        BSpace = *SBufSize;
    }
    else
    {
        BPtr   = Line;
        BSpace = sizeof(Line);
    }

    BPtr[0] = '\0';

    Head = BPtr;

    if (G == NULL)
    {
        /* build header */

        /*            NAME PRI FLAG QDEF QLST * PLST TRG LIMITS */

        MUSNPrintF(&BPtr,&BSpace,"%-12s %8s %12s %12s %12s%s %20s %6s %7s\n\n",
                   "Name",
                   "Priority",
                   "Flags",
                   "QDef",
                   "QOSList",
                   "*",
                   "PartitionList",
                   "Target",
                   "Limits");
    }
    else
    {
        /* build job info line */

        MUBMToString(G->F.JobFlags,MJobFlags,':',FlagLine,NONE);

        MUStrCpy(QALLine,MQOSBMToString(G->F.QAL),sizeof(QALLine));

        if (G->F.QALType == qalAND)
            QALChar = '&';
        else if (G->F.QALType == qalONLY)
            QALChar = '^';
        else
            QALChar = ' ';

        MUStrCpy(GLLine,
                 MCredShowAttrs(&G->L.AP,G->L.IP,NULL,NULL,NULL,&G->F,0,(1 << mcsLimits)),sizeof(GLLine));

        /*            NAME PRIO FLAG QDEF QLST * PLST FSTARG LIMITS */

        MUSNPrintF(&BPtr,&BSpace,"%-12s %8ld %12s %12s %12s%c %20s %6.2lf %7s\n",
                   G->Name,
                   G->F.Priority,
                   FlagLine,
                   ((mqos_t *)G->F.QDef) != NULL ?
                   ((mqos_t *)G->F.QDef)->Name  :
                   NONE,
                   (QALLine[0] != '\0') ? QALLine : NONE,
                   QALChar,
                   (G->F.PAL[0] == 0) ?
                   NONE :
                   MUListAttrs(ePartition,G->F.PAL[0]),
                   G->F.FSTarget,
                   (GLLine[0] != '\0') ? GLLine : NONE);

        /* add group attributes */

        if (G->L.APC != NULL)
        {
            int cindex;

            for (cindex = 0; cindex < MAX_MCLASS; cindex++)
            {
                if (G->L.APC[cindex].SLimit[mptMaxProc][0] > 0)
                {
                    MUSNPrintF(&BPtr,&BSpace,"  MAXPROC[CLASS:%s]=%d,%d\n",
                               MClass[cindex].Name,
                               G->L.APC[cindex].SLimit[mptMaxProc][0],
                               G->L.APC[cindex].HLimit[mptMaxProc][0]);
                }
            }  /* END for (cindex) */
        }    /* END if (G->L.APC != NULL) */

        if (G->L.APQ != NULL)
        {
            int cindex;

            for (cindex = 0; cindex < MAX_MQOS; cindex++)
            {
                if (G->L.APQ[cindex].SLimit[mptMaxProc][0] > 0)
                {
                    MUSNPrintF(&BPtr,&BSpace,"  MAXPROC[QOS:%s]=%d,%d\n",
                               MQOS[cindex].Name,
                               G->L.APQ[cindex].SLimit[mptMaxProc][0],
                               G->L.APQ[cindex].HLimit[mptMaxProc][0]);
                }
            }  /* END for (cindex) */
        }    /* END if (G->L.APQ != NULL) */

        if (Mode & (1 << mcmVerbose))
        {
            char tmpLine[MAX_MLINE];

            /* display additional attributes */

            MCredConfigLShow(
                (void *)G,
                mxoGroup,
                TRUE,
                -1,
                tmpLine);

            if (tmpLine[0] != '\0')
            {
                MUSNPrintF(&BPtr,&BSpace,"  %s\n",
                           tmpLine);
            }
        }    /* END if (Mode == Verbose) */
    }      /* END else (G == NULL) */

    return(Head);
}  /* END MGroupShow() */
コード例 #2
0
ファイル: MTrace.c プロジェクト: BradleyMorgan/maui
int MTraceBuildResource(

  mnode_t *N,       /* I */
  int      Version, /* I */
  char    *Buf,     /* O */
  int      BufSize) /* I */

  {
  int  cindex;

  char Features[MAX_MLINE];
  char Classes[MAX_MLINE];
  char Networks[MAX_MLINE];

  char *BPtr;
  int   BSpace;

  const char *FName = "MTraceBuildResource";

  DBG(3,fSIM) DPrint("%s(%s,%d,Buf,%d)\n",
    FName,
    (N != NULL) ? N->Name : "NULL",
    Version,
    BufSize);

  if ((N == NULL) || (Buf == NULL))
    {
    return(FAILURE);
    }

  BPtr   = Buf;
  BSpace = BufSize;

  BPtr[0] = '\0';

  strcpy(Features,MUMAList(eFeature,N->FBM,sizeof(N->FBM)));
  strcpy(Networks,MUListAttrs(eNetwork,N->Network));

  switch(Version)
    {
    case 230:

      Classes[0] = '\0';

      for (cindex = 1;cindex < MAX_MCLASS;cindex++)
        {
        if (N->CRes.PSlot[cindex].count > 0) 
          sprintf(Classes,"%s[%s:%d]",
            Classes,
            MAList[eClass][cindex],
            N->CRes.PSlot[cindex].count);
        }  /* END for (cindex) */

      if (Classes[0] == '\0')
        strcpy(Classes,NONE);

      /* FORMAT:  <RESOURCETYPE> <EVENTTYPE> <EVENTTIME> <NAME> <RMINDEX> <SWAP> <MEMORY> <DISK> <MAXPROCS> <SLOTSUSED> <FRAMEINDEX> <SLOTINDEX> <OPSYS> <ARCH> [<FEATURE>]* [<CLASS>]* [<NETWORK>]* <RES1> <RES2> <RES3> <RES4> */

      MUSNPrintF(&BPtr,&BSpace,"%s %s %d %s %s %dM %dM %dM %d %d %d %d %s %s %s %s %s %s %s %s %s",
        "COMPUTENODE",
        "AVAILABLE",
        0,
        N->Name,
        (N->RM != NULL) ? N->RM->Name : NONE,
        N->CRes.Swap,
        N->CRes.Mem,
        N->CRes.Disk,
        N->CRes.Procs,
        N->FrameIndex,
        N->SlotIndex,
        (N->FrameIndex > 0) ? MSys[N->FrameIndex][N->SlotIndex].SlotsUsed : 1,
        MAList[eOpsys][N->ActiveOS],
        MAList[eArch][N->Arch],
        Features,
        Classes,
        Networks,
        NONE,
        NONE,
        NONE,
        NONE
        );

      break;

    default:

      DBG(4,fSIM) DPrint("ALERT:    cannot create version %d resource trace record\n",
        Version);

      return(FAILURE);

      /*NOTREACHED*/

      break;
    }    /* END switch(Version) */

  return(SUCCESS);
  }  /* END MTraceBuildResource() */
コード例 #3
0
ファイル: MRMJobValidate.c プロジェクト: dhh1128/cbase
int MRMJobValidate(

  mjob_t              *J,              /* I */
  mrm_t               *R,              /* I */
  char                *EMsg,           /* O (optional,minsize=MMAX_LINE) */
  enum MJobCtlCmdEnum *FailureAction,  /* I (optional) */
  int                 *SC)             /* O (optional) */

  {
  enum MWJobAttrEnum aindex;
  enum MRMSubTypeEnum SType;

  int     index;

  char    SPath[MMAX_BUFFER];

  char   *BPtr;
  int     BSpace;

  char   *ptr;
  char   *TokPtr;

  char   *ptr2;
  char   *TokPtr2;

  char    tEMsg[MMAX_LINE];

  enum MStatusCodeEnum tmpSC;

  mbool_t GRes = FALSE;

  const char *FName = "MRMJobValidate";

  MDB(2,fRM) MLog("%s(%s,%s,EMsg,FailureAction,SC)\n",
    FName,
    (J != NULL) ? J->Name : "NULL",
    (R != NULL) ? R->Name : "NULL");

  if (EMsg != NULL)
    EMsg[0] = '\0';

  if (SC != NULL)
    *SC = 0;

  if (J == NULL)
    {
    return(FAILURE);
    }

  if (R->ND.URL[mrmXJobValidate] == NULL)
    {
    /* no job validate script specified */

    return(SUCCESS);
    }

  MUSNInit(&BPtr,&BSpace,SPath,sizeof(SPath));

  MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
    MWikiJobAttr[mwjaUName],
    J->Credential.U->Name);

  if (J->EUser != NULL)
    {
    /* report execution user */

    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      "EUSER",
      J->EUser);
    }

  if (J->Credential.G != NULL)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaGName],
      J->Credential.G->Name);
    }

  if (J->SpecWCLimit[0] > 0)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s=%ld ",
      MWikiJobAttr[mwjaWCLimit],
      J->SpecWCLimit[0]);
    }

/* 
  if (J->Request.TC > 0)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s=%d ",
      MWikiJobAttr[mwjaTasks],
      J->Request.TC);
    }
*/

  if (J->Credential.C != NULL)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaRClass],
      J->Credential.C->Name);
    }

  if (J->QOSRequested != NULL)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaQOS],
      J->QOSRequested->Name);
    }

  if (J->Env.Cmd != NULL)
    {
    char *ptr;
    char *TokPtr;

    char tmpLine[MMAX_LINE];

    MUStrCpy(tmpLine,J->Env.Cmd,sizeof(tmpLine));

    ptr = MUStrTok(tmpLine," ",&TokPtr);

    MUStringChop(ptr);

    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaExec],
      ptr);
    }    /* END if (J->E.Cmd != NULL) */

  if (!bmisclear(&J->Req[0]->ReqFBM))
    {
    char tmpLine[MMAX_LINE];

    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaRFeatures],
      MUNodeFeaturesToString(',',&J->Req[0]->ReqFBM,tmpLine));
    }

  if (J->Variables.Table != NULL)
    {
    mstring_t tmp(MMAX_LINE);

    MJobAToMString(J,mjaVariables,&tmp);

    MUSNPrintF(&BPtr,&BSpace,"%s=%s ",
      MWikiJobAttr[mwjaVariables],
      tmp.c_str());
    }

  /* display generic resources */

  for (index = 1;index < MSched.M[mxoxGRes];index++)
    { 
    if (MGRes.Name[index][0] == '\0')
      break;
 
    if (MSNLGetIndexCount(&J->Req[0]->DRes.GenericRes,index) == 0)
      continue;

    if (GRes == FALSE)
      {
      MUSNPrintF(&BPtr,&BSpace,"GRES=%s:%d",
        MGRes.Name[index],
        MSNLGetIndexCount(&J->Req[0]->DRes.GenericRes,index));

      GRes = TRUE;
      }
    else
      {
      MUSNPrintF(&BPtr,&BSpace,",%s:%d",
        MGRes.Name[index],
        MSNLGetIndexCount(&J->Req[0]->DRes.GenericRes,index));
      }
    }  /* END for (index) */

  /* send this off to JOBVALIDATEURL */
  
  SType = R->ND.NatType;

  R->ND.NatType = mrmstX1E;

  mstring_t Response(MMAX_LINE);

  /* NOTE: should we pass-in Job Validate specific timeout, ie 2 seconds? (NYI) */

  if (MNatDoCommand(
        &R->ND,
        SPath,
        mrmXJobValidate,
        R->ND.Protocol[mrmXJobValidate],
        FALSE,
        NULL,
        NULL,
        &Response,
        tEMsg,               /* O */
        &tmpSC) == FAILURE)
    {
    R->ND.NatType = SType;

    /* make failure action configurable */

    if ((ptr = strstr(tEMsg,"ACTION=")) != NULL)
      {
      ptr += strlen("ACTION=");

      ptr2 = MUStrTok(ptr," \n\t",&TokPtr);

      if (FailureAction != NULL)
        *FailureAction = (enum MJobCtlCmdEnum)MUGetIndexCI(ptr2,MJobCtlCmds,FALSE,mjcmNONE);
      }

    if (EMsg != NULL)
      MUStrCpy(EMsg,tEMsg,MMAX_LINE);

    if (SC != NULL)
      *SC = (int)tmpSC;

    return(FAILURE);
    }

  if (SC != NULL)
    *SC = (int)tmpSC;

  R->ND.NatType = SType;

  for (index = 0;Response[index] != '\0';index++)
    {
    if (Response[index] == '\n')
      Response[index] = ' ';
    }

  mstring_t tmpString(MMAX_LINE);

  MWikiFromAVP(NULL,Response.c_str(),&tmpString);

  /* Need a char array that can be modified, not the immutable tmpString  */
  char *mutableResponse = NULL;
  MUStrDup(&mutableResponse,tmpString.c_str());

  ptr = MUStrTok(mutableResponse,";",&TokPtr);

  int rc = SUCCESS;

  /* NYI:  change other job attributes such as NodeCount RMXString User/Group */

  while (ptr != NULL)
    {
    ptr2 = MUStrTok(ptr,"=",&TokPtr2);

    aindex = (enum MWJobAttrEnum)MUGetIndexCI(ptr2,MWikiJobAttr,FALSE,mwjaNONE);

    switch (aindex)
      {
      case mwjaAccount:

        if ((J->Credential.A == NULL) || (strcmp(TokPtr2,J->Credential.A->Name)))
          {
          if (MRMJobModify(
                J,
                "Account_Name",
                NULL,
                TokPtr2,
                mSet,
                "account modified by jobvalidate interface",
                tEMsg,              /* O */
                NULL) != SUCCESS)
            {
            MDB(2,fSCHED) MLog("INFO:     cannot set account on job %s to '%s' - invalid account - %s\n",
              J->Name,
              TokPtr2,
              tEMsg);

            if (EMsg != NULL)
              strcpy(EMsg,"cannot set account");

            rc = FAILURE;
            goto cleanupExit;
            }

          MAcctAdd(TokPtr2,&J->Credential.A);

          bmset(&J->IFlags,mjifAccountLocked);
          }

        break;

      case mwjaRClass:

        if ((J->Credential.C == NULL) || (strcmp(TokPtr2,J->Credential.C->Name)))
          {
          mclass_t *C;

          if (MClassFind(TokPtr2,&C) == FAILURE)
            {
            MDB(2,fSCHED) MLog("INFO:     cannot set class on job %s to '%s' - invalid class\n",
              J->Name,
              TokPtr2);

            if (EMsg != NULL)
              strcpy(EMsg,"cannot locate class");

            rc = FAILURE;
            goto cleanupExit;
            }
          
          if (MJobSetClass(J,C,TRUE,tEMsg) == FAILURE)
            {
            MDB(2,fSCHED) MLog("INFO:     cannot set class on job %s to '%s' - %s\n",
              J->Name,
              C->Name,
              tEMsg);

            if (EMsg != NULL)
              strcpy(EMsg,"cannot set class");

            rc = FAILURE;
            goto cleanupExit;
            }

          bmset(&J->IFlags,mjifClassLocked);
          }  /* END if ((J->Cred.C == NULL) || ...) */

        break;

      case mwjaQOS:

        /* bypass qos checks and put qos directly onto job */

        J->QOSRequested = NULL;

        if (MQOSFind(TokPtr2,&J->Credential.Q) != SUCCESS)
          {
          MDB(2,fSCHED) MLog("INFO:     cannot set qos on job %s to '%s' - invalid QoS\n",
            J->Name,
            TokPtr2);

          if (EMsg != NULL)
            strcpy(EMsg,"cannot locate qos");

          rc = FAILURE;
          goto cleanupExit;
          }

        bmset(&J->IFlags,mjifQOSLocked);

        break;

      case mwjaRFeatures:

        MReqSetAttr(J,J->Req[0],mrqaReqNodeFeature,(void **)TokPtr2,mdfString,mSet);

        break;

      case mwjaWCLimit:

        if (MRMJobModify(
             J,
             "Resource_List",
             "walltime",
             TokPtr2,
             mSet,
             "walltime modified by jobvalidate interface",
             tEMsg,
             NULL) == FAILURE)
          {
          MDB(2,fSCHED) MLog("INFO:     cannot modify walltime for rm job %s - '%s'\n",
            J->Name,
            tEMsg);

          if (EMsg != NULL)
            strcpy(EMsg,"cannot modify walltime");

          rc = FAILURE;
          goto cleanupExit;
          }

        break;

      case mwjaVariables:

        MJobSetAttr(J,mjaVariables,(void **)TokPtr2,mdfString,mAdd);

        break;

      default:

        /* NO-OP */
 
        break;
      }  /* END switch (aindex) */

    ptr = MUStrTok(NULL,";",&TokPtr);
    }    /* END while (ptr != NULL) */

cleanupExit:
  MUFree(&mutableResponse);

  return(rc);
  }  /* END MRMJobValidate() */
コード例 #4
0
ファイル: MUsersGroups.c プロジェクト: dhh1128/cbase
int MUNameGetGroups(

  char *UName,      /* I */
  int   GID,        /* I (optional,-1 = not set) */
  int  *GList,      /* O (optional,minsize=GListSize) - list of GIDs */
  char *GString,    /* O (optional,minsize=GLISTSIZE) - comma delimited list of group names */
  int  *NumEntries, /* O (optional) - number of entries returned in the GList */
  int   GListSize)  /* I (size of GList and/or GString!!!) */

  {
  int  gindex;
  int  tgcount;

  int  tList[MMAX_USERGROUPCOUNT];

  char GName[MMAX_NAME];

  int  PGID;

  if ((UName == NULL) || (UName[0] == '\0'))
    {
    return(FAILURE);
    }

  if ((GList != NULL) && (GString != NULL))
    {
    return(FAILURE);
    }

  PGID = MUGIDFromUser(-1,UName,GName);

#if defined(__LINUX) && !defined(__CYGWIN)
  
  tgcount = MMAX_USERGROUPCOUNT;

  if (getgrouplist(UName,PGID,(gid_t *)tList,&tgcount) == -1)
    {
    return(FAILURE);
    }

  if (NumEntries != NULL)
      *NumEntries = 0;

  if (GList != NULL)
    {
    memcpy(GList,tList,MIN(tgcount,GListSize) * sizeof(gid_t));

    if (NumEntries != NULL)
      *NumEntries = MIN(tgcount,GListSize);
    }

  if (GString != NULL)
    {
    char *BPtr = NULL;
    int   BSpace = 0;
    char  tmpGName[MMAX_NAME];

    MUSNInit(&BPtr,&BSpace,GString,GListSize);

    for (gindex = 0;gindex < tgcount;gindex++)
      {
      MUSNPrintF(&BPtr,&BSpace,"%s%s",
        (gindex > 0) ? "," : "",
        MUGIDToName(tList[gindex],tmpGName));
      }  /* END for (gindex) */
    }    /* END if (GString != NULL) */

#else /* __LINUX && !__CYGWIN */

  if (GString != NULL)
    {
    /* only returns secondary groups */

    MOSGetGListFromUName(UName,GString,NULL,GListSize,NULL);

    tList[0] = -1;
    }
  else
    { 
    MOSGetGListFromUName(UName,NULL,tList,0,&tgcount);

    if (GList != NULL)
      memcpy(GList,tList,MIN(tgcount,GListSize) * sizeof(gid_t));
    }

#endif /* __LINUX && !__CYGWIN */

  if (GID >= 0)
    {
    /* verify user has access to specified group */

    if (PGID == GID)
      {
      return(SUCCESS);
      }

    for (gindex = 0;gindex < tgcount;gindex++)
      {
      if ((int)tList[gindex] == GID)
        break;
      }

    if ((int)tList[gindex] != GID)
      {
      return(FAILURE);
      }
    }    /* END if (GID >= 0) */

  return(SUCCESS);
  }  /* END MUNameGetGroups() */
コード例 #5
0
ファイル: MUtilMisc.c プロジェクト: dhh1128/cbase
int MOSGetGListFromUName(

  char *UName,    /* I */
  char *Buf,      /* O (optional) */
  int  *GList,    /* O (optional) - terminated w/-1 */
  int   BufSize,  /* I */
  int  *GCount)   /* I (optional) */

  {
  char *BPtr = NULL;
  int   BSpace = 0;

  struct group *GPtr;
  int           uindex;
  int           gindex;

  char GName[MMAX_NAME];

  if ((UName == NULL) || (MSched.OSCredLookup == mapNever))
    {
    return(FAILURE);
    }

  /* FORMAT:  <GNAME>[,<GNAME>]... */

  if (Buf != NULL)
    MUSNInit(&BPtr,&BSpace,Buf,BufSize);

  gindex = MUGIDFromUser(-1,UName,GName);

  if (GList != NULL)
    GList[0] = gindex;

  if (Buf != NULL)
    {
    MUSNPrintF(&BPtr,&BSpace,"%s",
      GName);
    }

  setgrent();

  /* walk all groups, walk all users in each group (less efficient) */

  gindex = 1;

  while ((GPtr = getgrent()) != NULL)
    {
    for (uindex = 0;GPtr->gr_mem[uindex] != NULL;uindex++)
      {
      if (!strcmp(GPtr->gr_mem[uindex],UName))
        {
        if (Buf != NULL)
          {
          if (BPtr > Buf)
            MUSNCat(&BPtr,&BSpace,",");

          MUSNPrintF(&BPtr,&BSpace,"%s",
            GPtr->gr_name);
          }
        else 
          {
          if (GList != NULL)
            GList[gindex] = GPtr->gr_gid;
     
          gindex++;

          if (gindex >= (BufSize - 1))
            break;
          }

        break;
        }
      }  /* END for (uindex) */
    }    /* END while (getgrent() != NULL) */

  endgrent();

  if (GList != NULL)
    GList[gindex] = -1;

  if (GCount != NULL)
    *GCount = gindex;

  return(SUCCESS);
  }  /* END MOSGetGListFromUName() */
コード例 #6
0
ファイル: MReqSched.c プロジェクト: dhh1128/cbase
int MReqGetFNL(

  const mjob_t *J,
  const mreq_t *RQ,
  const mpar_t *P,
  const mnl_t  *SrcNL,
  mnl_t        *DstNL,
  int          *NC,
  int          *TC,
  long          StartTime,
  mbitmap_t    *ResMode,
  char         *EMsg)

  {
  mnode_t *N;

  int  rindex;
  int  nindex;

  enum MAllocRejEnum RIndex;

  int  tc;

  int  TasksAllowed;
  int  EffNC;

  mrm_t *RM;
  mrm_t *InternalRM;

  char  *BPtr;
  int    BSpace;

  const char *FName = "MReqGetFNL";

  MDB(4,fSCHED) MLog("%s(%s,%d,%s,%s,DstNL,NC,TC,%ld,%ld,EMsg)\n",
    FName,
    (J != NULL) ? J->Name : "NULL",
    (RQ != NULL) ? RQ->Index : -1,
    (P != NULL) ? P->Name : "NULL",
    (SrcNL != NULL) ? "SrcNL" : "NULL",
    StartTime,
    ResMode);

  if (EMsg != NULL)
    {
    MUSNInit(&BPtr,&BSpace,EMsg,MMAX_LINE);
    }

  if (NC != NULL)
    *NC = 0;

  if (TC != NULL)
    *TC = 0;

  MNLClear(DstNL);

  if ((J == NULL) || (RQ == NULL) || (P == NULL))
    {
    return(FAILURE);
    }

  /* step through all nodes */

  rindex = 0;
  EffNC  = 0;

  tc = 0;

  for (nindex = 0;nindex < MSched.M[mxoNode];nindex++)
    {
    if (SrcNL != NULL)
      {
      if (MNLGetNodeAtIndex(SrcNL,nindex,&N) == FAILURE)
        break;

      if ((bmisset(ResMode,1)) &&
          (N != MSched.GN) && /* jobs can always backfill on GLOBAL node. */
          (MNodeCannotRunJobNow(N,J) == TRUE))
        {
        /* this is a special case for backfill (only MBFFirstFit sets ResMode == 1).
           If a large reservation is in place then backfill can be very slow as it
           literally schedules every job in the system only to find none of them can start.
           this is an optimization that tests whether the job can run "right now" on this
           node.  All it checks is if there is a reservation on the entire node to which
           the job does not have access. If there is the the node is not considered further */

        MDB(7,fSCHED) MLog("INFO:     node %s cannot run job %s right now\n",
          N->Name,
          J->Name);

        continue;
        } 

      /* if the node does not match specified par, and node is not shared, and job
       * is not coalloc'd, reject node from consideration */

      if ((N->PtIndex != P->Index) &&
          (N->PtIndex != MSched.SharedPtIndex) &&
          (P->Index != 0) &&
          (N->PtIndex != 0) &&
         !(bmisset(&J->Flags,mjfCoAlloc)))
        {
        MDB(7,fSCHED) MLog("INFO:     node %s is not in requested partition\n",
          N->Name);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s is not in requested partition (%s)\n",
            N->Name,
            P->Name);
          }

        continue;
        }

      /* make sure that the node in consideration belongs to a 
       * partition we have access to */

      if (P->Index == 0)
        {
        if (bmisset(&J->PAL,N->PtIndex) == FALSE)
          {
          /* job cannot access partition */

          continue;
          }
        }

      if (N->ACL != NULL)
        {
        mbool_t IsInclusive=FALSE;

        MACLCheckAccess(N->ACL,J->Credential.CL,NULL,NULL,&IsInclusive);

        if (IsInclusive == FALSE)
          {
          RIndex = marACL;

          MDB(7,fSCHED) MLog("INFO:     node %s has exclusive ACL\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s has exclusive ACL\n",
              N->Name);
            }

          continue;
          }
        }  /* END if (N->ACL != NULL) */
      }    /* END if (SrcNL != NULL) */
    else
      {
      N = MNode[nindex];

      if ((N == NULL) || (N->Name[0] == '\0'))
        break;

      if (N->Name[0] == '\1')
        continue;

      /* if the node does not match specified par, and node is not shared, and job
       * is not coalloc'd, reject node from consideration */

      if ((N->PtIndex != P->Index) &&
          (N->PtIndex != MSched.SharedPtIndex) &&
          (P->Index != 0) &&
          (N->PtIndex != 0) &&
         !(bmisset(&J->Flags,mjfCoAlloc)))
        {
        MDB(7,fSCHED) MLog("INFO:     node %s is not in requested partition\n",
          N->Name);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s is not in requested partition (%s)\n",
            N->Name,
            P->Name);
          }

        continue;
        }

      /* make sure that the node in consideration belongs to a 
       * partition we have access to */

      if (P->Index == 0)
        {
        if (bmisset(&J->PAL,N->PtIndex) == FALSE)
          {
          /* job cannot access partition */

          continue;
          }
        }

      if (N->ACL != NULL)
        {
        mbool_t IsInclusive;

        MACLCheckAccess(N->ACL,J->Credential.CL,NULL,NULL,&IsInclusive);

        if (IsInclusive == FALSE)
          {
          RIndex = marACL;

          MDB(7,fSCHED) MLog("INFO:     node %s has exclusive ACL\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s has exclusive ACL\n",
              N->Name);
            }

          continue;
          }
        }  /* end if (N->ACL != NULL) */

      /* enforces hostlist constraints */

      if (MReqCheckResourceMatch(
           J,
           RQ,
           N,
           &RIndex,    /* O */
           StartTime,
           FALSE,
           P,
           NULL,
           NULL) == FAILURE)
        {
        MDB(7,fSCHED) MLog("INFO:     node %s does not satisfy %s:%d (%s)\n",
          N->Name,
          J->Name,
          RQ->Index,
          MAllocRejType[RIndex]);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s does not satisfy %s:%d (%s)\n",
            N->Name,
            J->Name,
            RQ->Index,
            MAllocRejType[RIndex]);
          }

        continue;
        }
      }  /* END else (SrcNL != NULL) */

    if (StartTime != MMAX_TIME)
      {
      if ((N->State != mnsIdle) &&
          (N->State != mnsActive) &&
          (N->State != mnsBusy))
        {
        MDB(7,fSCHED) MLog("INFO:     node %s is in unavailable state %s\n",
          N->Name,
          MNodeState[N->State]);

        continue;
        }
      }

    if (SrcNL != NULL)
      {
      mnode_t *tmpN;

      /* NOTE:  For non-SrcNL nodes, MReqCheckResourceMatch() above enforces hostlist constraints */

      /* check exclude list */

      if (!MNLIsEmpty(&J->ExcHList))
        {
        int hlindex;

        for (hlindex = 0;MNLGetNodeAtIndex(&J->ExcHList,hlindex,&tmpN) == SUCCESS;hlindex++)
          {
          if (tmpN->Index == nindex)
            break;
          }  /* END for (hlindex) */

        if (tmpN != NULL)
          {
          MDB(7,fSCHED) MLog("INFO:     node %s is in excluded hostlist\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s is in excluded hostlist\n",
              N->Name);
            }

          continue;
          }
        }  /* END if (J->ExcHList != NULL) */

      if (J->ReqVMList != NULL)
        {
        int vmindex;

        if (N->VMList == NULL)
          {
          MDB(7,fSCHED) MLog("INFO:     node %s does not provide required VM\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s does not provide required VM\n",
              N->Name);
            }
          }

        /* report success if ANY required VM is located */

        for (vmindex = 0;J->ReqVMList[vmindex] != NULL;vmindex++)
          {
          if (MULLCheckP(N->VMList,J->ReqVMList[vmindex],NULL) == SUCCESS)
            {
            /* matching VM located */

            break; 
            }
          }  /* END for (vmindex) */

        if (J->ReqVMList[vmindex] == NULL)
          {
          MDB(7,fSCHED) MLog("INFO:     node %s does not provide required VM\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s does not provide required VM\n",
              N->Name);
            }
          }
        }

      if ((bmisset(&J->IFlags,mjifHostList)) &&
          (!MNLIsEmpty(&J->ReqHList)) &&
          (N->PtIndex != MSched.SharedPtIndex) &&
          (J->ReqHLMode != mhlmSubset))
        {
        mnode_t *tmpN;

        int hlindex;

        /* check hostlist constraints */

        for (hlindex = 0;MNLGetNodeAtIndex(&J->ReqHList,hlindex,&tmpN) == SUCCESS;hlindex++)
          {
          if (tmpN == N)
            break;
          }  /* END for (hlindex) */

        if (tmpN == NULL)
          {
          MDB(7,fSCHED) MLog("INFO:     node %s is not in required hostlist\n",
            N->Name);

          if (EMsg != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"node %s is not in required hostlist\n",
              N->Name);
            }

          continue;
          }
        }
      }    /* END if (SrcNL != NULL) */

    /* check node state */

    if (!bmisset(&J->SpecFlags,mjfIgnState))
      {
      if (MNODEISDRAINING(N) &&
          (MPar[0].NodeDrainStateDelayTime > 0) &&
         ((long)(StartTime - MSched.Time) < MPar[0].NodeDrainStateDelayTime))
        {
        MDB(7,fSCHED) MLog("INFO:     node %s is unavailable (state %s)\n",
          N->Name,
          MNodeState[N->State]);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s is unavailable (state %s)\n",
            N->Name,
            MNodeState[N->State]);
          }

        continue;
        }
      else if ((N->State == mnsNone) ||
               (N->State == mnsUnknown) ||
               (N->State == mnsUp) ||
               ((N->State == mnsDown) && 
                ((long)(StartTime - MSched.Time) < MPar[0].NodeDownStateDelayTime)))
        {
        MDB(7,fSCHED) MLog("INFO:     node %s is unavailable (state %s)\n",
          N->Name,
          MNodeState[N->State]);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s is unavailable (state %s)\n",
            N->Name,
            MNodeState[N->State]);
          }
 
        continue;
        }
      }    /* END if (!bmisset(&J->SpecFlags,mjfIgnState)) */

    /* check node policies */

    TasksAllowed = (N->CRes.Procs != 0) ? N->CRes.Procs : 9999;

    if (MNodeCheckPolicies(J,N,MMAX_TIME,&TasksAllowed,NULL) == FAILURE)
      {
      MDB(7,fSCHED) MLog("INFO:     node %s is unavailable (policies)\n",
        N->Name);

      if (EMsg != NULL)
        {
        MUSNPrintF(&BPtr,&BSpace,"node %s is unavailable (policies)\n",
          N->Name);
        }

      continue;
      }

    MRMGetInternal(&InternalRM);

    if ((bmisset(&J->Flags,mjfCoAlloc)) && 
        (RQ->RMIndex > 0) && 
        (&MRM[RQ->RMIndex] != InternalRM))
      {
      /* req locked into specific RM */

      RM = &MRM[RQ->RMIndex];

      if ((N->RM != NULL) && (N->RM->Index != RM->Index))
        {
        RIndex = marRM;

        MDB(7,fSCHED) MLog("INFO:     node %s does not meet requirements for job %s:%d (%s)\n",
          N->Name,
          J->Name,
          RQ->Index,
          MAllocRejType[RIndex]);

        if (EMsg != NULL)
          {
          MUSNPrintF(&BPtr,&BSpace,"node %s does not meet requirements (%s)\n",
            N->Name,
            MAllocRejType[RIndex]);
          }

        continue;
        }
      }
 
    if (MReqCheckNRes(
          J,
          N,
          RQ,
          StartTime,
          &TasksAllowed,  /* O */
          1.0,
          0,
          &RIndex,        /* O */
          NULL,
          NULL,
          TRUE,
          FALSE,
          NULL) == FAILURE)
      {
      MDB(7,fSCHED) MLog("INFO:     node %s does not meet requirements for job %s:%d (%s)\n",
        N->Name,
        J->Name,
        RQ->Index,
        MAllocRejType[RIndex]);

      if (EMsg != NULL)
        {
        MUSNPrintF(&BPtr,&BSpace,"node %s does not meet requirements (%s)\n",
          N->Name,
          MAllocRejType[RIndex]);
        }

      continue;
      }

    MDB(6,fSCHED) MLog("INFO:     node %s added to feasible list (%d tasks)\n",
      N->Name,
      TasksAllowed);

    if ((bmisset(&J->IFlags,mjifExactTPN) || bmisset(&J->IFlags,mjifMaxTPN)) && (RQ->TasksPerNode > 0))
      TasksAllowed = MIN(TasksAllowed,RQ->TasksPerNode);

    if ((RQ->NAccessPolicy == mnacSingleTask) || 
        (N->SpecNAPolicy == mnacSingleTask) || 
        (MPar[N->PtIndex].NAccessPolicy == mnacSingleTask))
      TasksAllowed = MIN(TasksAllowed,1);

    MNLSetNodeAtIndex(DstNL,rindex,N);
    MNLSetTCAtIndex(DstNL,rindex,TasksAllowed);

    tc += TasksAllowed;

    EffNC++;

    rindex++;
    }     /* END for (nindex) */

  MNLTerminateAtIndex(DstNL,rindex);

  if (rindex > 0)
    {
    /* determine if NodeSets are optional */

    mbool_t NodeSetIsOptional = TRUE;

    enum MResourceSetSelectionEnum tmpRSS;

    tmpRSS = (RQ->SetSelection != mrssNONE) ?
      RQ->SetSelection :
      MPar[0].NodeSetPolicy;

    if (RQ->SetBlock != MBNOTSET)
      {
      /* job is overriding the system setting */

      NodeSetIsOptional = !RQ->SetBlock;
      }
    else if (MPar[0].NodeSetIsOptional == FALSE)
      {
      /* nothing on the job, use the system setting */

      NodeSetIsOptional = FALSE;
      }

    if ((NodeSetIsOptional == FALSE) &&
        (tmpRSS == mrssNONE))
      {
      /* if the system does not have a nodeset and the job does not have a nodeset
         then there is no nodeset */

      NodeSetIsOptional = TRUE;
      }

    /* don't check NodeSet here if SpanEvenly is specified, nodesets will be enforced in
       MJobGetRangeValue */

    if ((NodeSetIsOptional == FALSE) &&
        (MSched.NodeSetPlus != mnspSpanEvenly))
      {
      mnl_t   *tmpNodeList[MMAX_REQ_PER_JOB];

      /* use tmpNodeList because we are only doing a general 
         "are any nodesets valid" query here and not a query
         for a specific nodeset, we will throw away the results
         and only care about whether MJobSelectResourceSet()
         succeeds or fails */

      /* TODO: MJobSelectResourceSet() should be able to return
         a list of feasible nodes from any nodeset, that way we 
         can eliminate later costly checks on nodes that won't
         fit any requested nodeset */

      MNLMultiInit(tmpNodeList);

      MNLCopy(tmpNodeList[0],DstNL);

      /* best effort node set */
 
      if (MJobSelectResourceSet(
            J,
            RQ,
            StartTime,
            (RQ->SetType != mrstNONE) ? RQ->SetType : MPar[0].NodeSetAttribute,
            (tmpRSS != mrssFirstOf) ? tmpRSS : mrssOneOf,
            ((RQ->SetList != NULL) && (RQ->SetList[0] != NULL)) ? RQ->SetList : MPar[0].NodeSetList,
            tmpNodeList[0],
            NULL,
            -1,
            NULL,
            NULL,
            NULL) == FAILURE)
        {
        tc = 0;

        MNLClear(DstNL);
        }
      else
        {
        /* NOTE:  how to handle if multiple options available? */

        /* FIXME */

        tc = MNLSumTC(DstNL);
        }

      MNLMultiFree(tmpNodeList);
      }    /* END if ((MPar[0].NodeSetIsOptional == TRUE) && ...) */

    if ((bmisset(&J->Flags,mjfCoAlloc)) && (RQ->RMIndex > 0))
      {
      /* req locked into specific RM */

      RM = &MRM[RQ->RMIndex];
      }
    else if (J->SubmitRM != NULL)
      {
      RM = J->SubmitRM;
      }
    else
      {
      RM = &MRM[0];
      }
    }    /* END if (rindex > 0) */

  MDB(5,fSCHED) MLog("INFO:     %d feasible tasks found for job %s:%d in partition %s (%d Needed)\n",
    tc,
    J->Name,
    RQ->Index,
    (P != NULL) ? P->Name : "NULL",
    RQ->TaskCount);

  if (NC != NULL)
    *NC = EffNC;

  if (TC != NULL)
    *TC = tc;

  if (tc <= 0)
    {
    MDB(7,fSCHED) MLog("INFO:     inadequate feasible tasks found for job %s:%d\n",
      J->Name,
      RQ->Index);

    return(FAILURE);
    }

  if (!bmisset(&J->Flags,mjfBestEffort))
    {
    if (tc < RQ->TaskCount)
      {
      MDB(4,fSCHED) MLog("INFO:     inadequate feasible tasks found for job %s:%d in partition %s (%d < %d)\n",
        J->Name,
        RQ->Index,
        (P != NULL) ? P->Name : "NULL",
        tc,
        RQ->TaskCount);

      return(FAILURE);
      }

    if (EffNC < RQ->NodeCount)
      {
      MDB(2,fSCHED) MLog("INFO:     inadequate feasible nodes found for job %s:%d in partition %s (%d < %d)\n",
        J->Name,
        RQ->Index,
        (P != NULL) ? P->Name : "NULL",
        EffNC,
        RQ->NodeCount);

      return(FAILURE);
      }
    }    /* END if (!bmisset(&J->Flags,mjfBestEffort)) */

  return(SUCCESS);
  }   /* END MReqGetFNL() */
コード例 #7
0
ファイル: MVMAttribute.c プロジェクト: dhh1128/cbase
int MVMAToString(

  mvm_t     *V,
  mnode_t   *N,
  enum MVMAttrEnum AIndex,
  char      *Buf,
  int        BufSize,
  mbitmap_t *DModeBM)

  {
  if (BufSize <= 0)
    BufSize = MMAX_LINE;

  if (Buf == NULL)
    {
    return(FAILURE);
    }

  Buf[0] = '\0';

  if (V == NULL)
    {
    return(FAILURE);
    }

  switch (AIndex)
    {
    case mvmaActiveOS:

      if (V->ActiveOS != 0)
        strcpy(Buf,MAList[meOpsys][V->ActiveOS]);

      break;

    case mvmaADisk:

      if ((V->ARes.Disk >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->ARes.Disk);
        }

      break;

    case mvmaAlias:

      {
      char   *BPtr;
      int     BSpace;
      mln_t  *Alias = NULL;
      mbool_t AliasPrinted = FALSE;

      MUSNInit(&BPtr,&BSpace,Buf,BufSize);

      while (MULLIterate(V->Aliases,&Alias) == SUCCESS)
        {
        if (AliasPrinted)
          MUSNPrintF(&BPtr,&BSpace,",");

        MUSNPrintF(&BPtr,&BSpace,"%s",
          Alias->Name);

        AliasPrinted = TRUE;
        }
      }

      break;

    case mvmaAMem:

      if ((V->ARes.Mem >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->ARes.Mem);
        }

      break;

    case mvmaAProcs:

      if ((V->ARes.Procs >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->ARes.Procs);
        }

      break;

    case mvmaCDisk:

      if ((V->CRes.Disk >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->CRes.Disk);
        }

      break;

    case mvmaCPULoad:

      sprintf(Buf,"%f",
        V->CPULoad);

      break;

    case mvmaCMem:

      if ((V->CRes.Mem >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->CRes.Mem);
        }

      break;

    case mvmaCProcs:

      if ((V->CRes.Procs >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->CRes.Procs);
        }

      break;

    case mvmaContainerNode:

      if (V->N != NULL)
        {
        snprintf(Buf,BufSize,"%s",V->N->Name);
        }

      break;

    case mvmaDDisk:

      if ((V->DRes.Disk >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->DRes.Disk);
        }

      break;

    case mvmaDMem:

      if ((V->DRes.Mem >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->DRes.Mem);
        }

      break;

    case mvmaDProcs:

      if ((V->DRes.Procs >= 0) || (bmisset(DModeBM,mcmVerbose)))
        {
        sprintf(Buf,"%d",
          V->DRes.Procs);
        }

      break;

    case mvmaDescription:

      if ((V->Description != NULL) &&
          (V->Description[0] != '\0'))
        {
        strcpy(Buf,V->Description);
        }

      break;

    case mvmaEffectiveTTL:

      {
      sprintf(Buf,"%ld",V->EffectiveTTL);
      }

      break;

    case mvmaFlags:

      {
      mstring_t tmp(MMAX_LINE);

      bmtostring(&V->Flags,MVMFlags,&tmp);

      MUStrCpy(Buf,tmp.c_str(),BufSize);
      }    /* END BLOCK (case mvmaFlags) */

      break;

    case mvmaGMetric:

      {

      MVMGMetricAToString(V->GMetric,Buf,BufSize,DModeBM);

#if 0
      char *BPtr;
      int   BSpace;

      int   gmindex;

      /* FORMAT:  GMETRIC=<GMNAME>:<VAL>[,<GMNAME>:<VAL>]... */

      MUSNInit(&BPtr,&BSpace,Buf,BufSize);

      if (V->GMetric != NULL)
        {
        for (gmindex = 1;gmindex < MSched.M[mxoxGMetric];gmindex++)
          {
          if (V->GMetric[gmindex] == NULL)
            {
            continue;
            }

          if (MGMetric.Name[gmindex][0] == '\0')
            break;

          if (V->GMetric[gmindex]->SampleCount <= 0)
            continue; 

          if (Buf[0] != '\0')
            MUSNCat(&BPtr,&BSpace,",");

          if (bmisset(DModeBM,mcmUser))
            {
            /* NOTE:  0th entry in MAList is always "NONE" */
            MUSNPrintF(&BPtr,&BSpace,"%s=%.2f",
              MGMetric.Name[gmindex],
              V->GMetric[gmindex]->IntervalLoad);
            }
          else
            {
            MUSNPrintF(&BPtr,&BSpace,"%s:%.2f",
              MGMetric.Name[gmindex],
              V->GMetric[gmindex]->IntervalLoad);
            }
          }  /* END for (gmindex) */
        }  /* END if (V->GMetric != NULL) */
#endif

      }  /* END BLOCK (case mvmaGMetric) */

      break;

    case mvmaID:

      if (V->VMID[0] != '\0')
        strcpy(Buf,V->VMID);
       
      break;

    case mvmaJobID:

      if (V->JobID[0] != '\0')
       strcpy(Buf,V->JobID);

      break;

    case mvmaLastMigrateTime:

      if (V->LastMigrationTime > 0)
        sprintf(Buf,"%lu",V->LastMigrationTime);

      break;

    case mvmaLastSubState:

      if (V->LastSubState != NULL)
        MUStrCpy(Buf,V->LastSubState,BufSize);

      break;

    case mvmaLastSubStateMTime:

      if (V->LastSubStateMTime > 0)
        sprintf(Buf,"%lu",V->LastSubStateMTime);

      break;

    case mvmaLastUpdateTime:

      if (V->UpdateTime <= 0)
        {
        /* What happens in this case? */
        }
      else
        {
        sprintf(Buf,"%lu",V->UpdateTime);
        }

      break;

    case mvmaMigrateCount:

      if (V->MigrationCount > 0)
        sprintf(Buf,"%d",V->MigrationCount);

      break;

    case mvmaNextOS:

      if ((V->NextOS > 0) && (V->NextOS != V->ActiveOS))
        {
        strcpy(Buf,MAList[meOpsys][V->NextOS]);
        }

      break;

    case mvmaNetAddr:

      if (V->NetAddr != NULL)
        MUStrCpy(Buf,V->NetAddr,BufSize);

      break;

    case mvmaOSList:

      if (V->OSList != NULL)
        {
        char *BPtr;
        int   BSpace;

        int   osindex;

        MUSNInit(&BPtr,&BSpace,Buf,BufSize);

        for (osindex = 0;V->OSList[osindex].AIndex > 0;osindex++)
          {
          if (Buf[0] != '\0')
            {
            MUSNPrintF(&BPtr,&BSpace,",%s",
              MAList[meOpsys][V->OSList[osindex].AIndex]);
            }
          else
            {
            MUSNCat(&BPtr,&BSpace,MAList[meOpsys][V->OSList[osindex].AIndex]);
            }
          }  /* END for (osindex) */
        }    /* END if (V->OSList != NULL) */

      break;

    case mvmaPowerIsEnabled:

      {
      mbool_t IsOn = TRUE;

      switch (V->PowerState)
        {
        case mpowOff:

          IsOn = FALSE;

          break;

        default:

          break;
        }

      strcpy(Buf,MBool[IsOn]);
      }  /* END BLOCK */

      break;

    case mvmaPowerState:

      if (V->PowerState != mpowNONE)
        {
        strcpy(Buf,MPowerState[V->PowerState]);
        }

      break;

    case mvmaProvData:

      {
      mstring_t tmp(MMAX_LINE);

      /* sync with MNodeSetAttr#mnaProvData */
      mnode_t tmpN;
      memset(&tmpN,0,sizeof(tmpN));

      tmpN.ActiveOS = V->ActiveOS;
      tmpN.NextOS =   V->NextOS;
      tmpN.LastOSModRequestTime = V->LastOSModRequestTime;

      tmpN.OSList = (V->N == NULL) ? NULL : V->N->VMOSList;

      if (tmpN.OSList == NULL)
        {
        tmpN.OSList = MSched.DefaultN.VMOSList;

        if (tmpN.OSList == NULL)
          /* No valid OS information */
          break;
        }

      MNodeAToString(&tmpN,mnaProvData,&tmp,DModeBM);

      MUStrCpy(Buf,tmp.c_str(),BufSize);
      }  /* END BLOCK */

      break;

    case mvmaRackIndex:

      if (V->Rack >= 0)
        {
        sprintf(Buf,"%d",
          V->Rack);
        }

      break;

    case mvmaSlotIndex:

      if (V->Slot >= 0)
        {
        sprintf(Buf,"%d",
          V->Slot);
        }

      break;

    case mvmaSpecifiedTTL:

      {
      sprintf(Buf,"%ld",V->SpecifiedTTL);
      }

      break;

    case mvmaStartTime:

      {
      sprintf(Buf,"%lu",V->StartTime);
      }

      break;

    case mvmaState:
      
      if (V->State != mnsNONE)
        {
        strcpy(Buf,MNodeState[V->State]);
        }

      break;

    case mvmaSubState:

      if ((bmisset(&V->Flags,mvmfInitializing)) &&
          (V->SubState != NULL) &&
          (strstr(V->SubState,"pbs")))
        {
        strcpy(Buf,"rminitializing");
        }
      else if (V->SubState != NULL)
        {
        MUStrCpy(Buf,V->SubState,BufSize);
        }

      break;

    case mvmaStorageRsvNames:

      if (V->StorageRsvs != NULL)
        {
        char *BPtr;
        int   BSpace;
        mln_t *LLIter = NULL;

        MUSNInit(&BPtr,&BSpace,Buf,BufSize);

        while (MULLIterate(V->StorageRsvs,&LLIter) == SUCCESS)
          {
          if (Buf[0] != '\0')
            MUSNPrintF(&BPtr,&BSpace,",");

          MUSNPrintF(&BPtr,&BSpace,"%s",
            ((mrsv_t *)LLIter->Ptr)->Name);
          }
        } /* END case mvmaStorageRsvNames */

      break;

    case mvmaTrackingJob:

      if ((V->TrackingJ != NULL) && (V->TrackingJ->Name != NULL))
        MUStrCpy(Buf,V->TrackingJ->Name,BufSize);

      break;

    case mvmaVariables:

      if (V->Variables.NumItems > 0)
        {
        char *BPtr;
        int   BSpace;
        char *VarName;
        char *VarValue;

        mhashiter_t VarIter;

        MUHTIterInit(&VarIter);
        MUSNInit(&BPtr,&BSpace,Buf,BufSize);

        while (MUHTIterate(&V->Variables,&VarName,(void **)&VarValue,NULL,&VarIter) == SUCCESS)
          {
          if (Buf[0] != '\0')
            {
            MUSNPrintF(&BPtr,&BSpace,"+%s",
              VarName);
            }
          else
            {
            MUSNPrintF(&BPtr,&BSpace,"%s",
              VarName);
            }

          /* Add the value, if its not null */

          if (VarValue != NULL)
            {
            MUSNCat(&BPtr,&BSpace,":");
            MUSNCat(&BPtr,&BSpace,VarValue);
            }
          } /* END while (MUHTIterate(...) == SUCCESS) */
        } /* END case mvmaAttrs */

      break;

    default:

      /* NO-OP */

      break;
    }  /* END switch (AIndex) */

  return(SUCCESS);
  }  /* END MVMAToString() */
コード例 #8
0
ファイル: MDAG.c プロジェクト: dhh1128/cbase
int MDAGCheckMultiWithHT(

  marray_t    *DAList,
  mdepend_t   *DDList,
  mhash_t    **HList,
  int         *HListFlags,
  mbitmap_t   *EMsgFlags,
  mstring_t   *EMsg,
  mln_t       *VCs)

  {
  int hindex;

  mbool_t DSatisfied;
  mbool_t Failure;
  mbool_t VarNotSet;  /* used for type mdVarNotSet */

  mdepend_t *tmpD;
  char      *tmpVal;

  mln_t     *tmpVCL;
  mvc_t     *tmpVC;

  int        RemainingDeps;

  mhash_t OutstandingDepHT;  /* used to eliminate duplicates in display */

  const char *FName = "MDAGCheckMultiWithHT";

  MDB(5,fALL) MLog("%s(DList,HList,HListFlags,EMsg)\n",
    FName);

  if (EMsg != NULL)
    *EMsg = "";

  if (DAList != NULL)
    tmpD = (mdepend_t *)MUArrayListGetPtr(DAList,0);
  else
    tmpD = DDList;

  Failure = FALSE;
  RemainingDeps = 0;

  MUHTCreate(&OutstandingDepHT,-1);

  while (tmpD != NULL)
    {
    /* step through each dependency */

    hindex = 0;

    DSatisfied = FALSE;
    VarNotSet = TRUE;

    while (HList[hindex] != NULL)
      {
      /* search all lists to satisfy dependency */

      if ((HListFlags[hindex] == 1) && !bmisset(&tmpD->BM,mdbmExtSearch))
        break;

      switch (tmpD->Type)
        {
        case mdVarNotSet:
   
          /* verify that variable has NOT been set */
   
          if (MUHTGet(HList[hindex],tmpD->Value,NULL,NULL) == SUCCESS)
            {
            /* dependency is not met since this variable is defined */

            VarNotSet = FALSE;
            }
   
          break;
  
        case mdVarEQ:
        case mdVarNE:
        case mdVarGE:
        case mdVarLE:
        case mdVarLT:
        case mdVarGT:

          if ((MUHTGet(HList[hindex],
                ((tmpD->Value[0] != '$') && (tmpD->Value[0] != '+')) ? tmpD->Value : &tmpD->Value[1],
                (void **)&tmpVal,
                NULL) == SUCCESS) &&
              (tmpVal != NULL))
            {
            int Value    = (int)strtol(tmpVal,NULL,10);
            int ReqValue = (int)strtol(tmpD->SValue,NULL,10);

            switch (tmpD->Type)
              {
              case mdVarEQ:

                if (!strcmp(tmpVal,tmpD->SValue))
                  DSatisfied = TRUE;

                break;

              case mdVarNE:

                if (strcmp(tmpVal,tmpD->SValue))
                  DSatisfied = TRUE;

                break;

              case mdVarGE:

                if (Value >= ReqValue)
                  DSatisfied = TRUE;

                break;

              case mdVarGT:

                if (Value > ReqValue)
                  DSatisfied = TRUE;

                break;

              case mdVarLT:

                if (Value < ReqValue)
                  DSatisfied = TRUE;

                break;

              case mdVarLE:

                if (Value <= ReqValue)
                  DSatisfied = TRUE;

                break;

              default:

                /* NO-OP */

                break;
              }
            }

          break;

        case mdJobStart:                /* job must have previously started */
        case mdJobCompletion:           /* job must have previously completed */
        case mdJobSuccessfulCompletion: /* job must have previosuly completed successfully */
        case mdJobFailedCompletion:
        case mdJobSyncMaster:           /* slave jobs must start at same time */
        case mdJobSyncSlave:            /* must start at same time as master */

          /* how to handle job events here? */

          /* ignore for now */

          DSatisfied = TRUE;

          /* NYI */

          break;
 
        case mdVarSet:
        default:
   
          /* verify that variable has been set */
   
          if (MUHTGet(
                HList[hindex],
                (tmpD->Value[0] != '$') ? tmpD->Value : &tmpD->Value[1],
                (void **)&tmpVal,
                NULL) == SUCCESS)
            {
            MDB(6,fSTRUCT) MLog("INFO:     dependency satisfied ('%s')\n",
              tmpD->Value);

            DSatisfied = TRUE;
            }
   
          if ((tmpD->Value[0] == '$') && (tmpVal != NULL))
            {
            MDB(6,fSTRUCT) MLog("INFO:     dependency satisfied ('%s')\n",
              tmpD->Value);

            DSatisfied = TRUE;
            }
   
          break;
        }  /* END switch (tmpD->Type) */

      if (DSatisfied == TRUE)
        break;

      if ((tmpD->Type == mdVarNotSet) &&
          (VarNotSet == FALSE))
        {
        /* we can shortcircuit since we already found the variable set */

        break;
        }
   
      hindex++;
      }    /* END while (HList[eindex] != NULL) */

    if (DSatisfied == FALSE)
      {
      /* Check VCs */

      for (tmpVCL = VCs;tmpVCL != NULL;tmpVCL = tmpVCL->Next)
        {
        mln_t *tmpResults = NULL;

        tmpVC = (mvc_t *)tmpVCL->Ptr;

        if (MVCSearchForVar(tmpVC,tmpD->Value,&tmpResults,TRUE,FALSE) == SUCCESS)
          {
          MULLFree(&tmpResults,MUFREE);

          switch (tmpD->Type)
            {
            case mdVarNotSet:

              /* Variable was found, dependency failed */

              VarNotSet = FALSE;

              break;

            case mdVarEQ:
            case mdVarNE:
            case mdVarGE:
            case mdVarLE:
            case mdVarLT:
            case mdVarGT:
            case mdJobStart:                /* job must have previously started */
            case mdJobCompletion:           /* job must have previously completed */
            case mdJobSuccessfulCompletion: /* job must have previosuly completed successfully */
            case mdJobFailedCompletion:
            case mdJobSyncMaster:           /* slave jobs must start at same time */
            case mdJobSyncSlave:            /* must start at same time as master */

              /* Not handled for VCs */

              break;

            case mdVarSet:
            default:

              MDB(6,fSTRUCT) MLog("INFO:     dependency satisfied ('%s')\n",
                tmpD->Value);

              DSatisfied = TRUE;

              break;
            }  /* END switch (tmpD->Type) */
          }  /* END if (MVCSearchForVar() == SUCCESS) */
        }  /* END for (tmpVCL) */
      }  /* END if (DSatisfied == FALSE) */

    if ((tmpD->Type == mdVarNotSet) &&
        (VarNotSet == TRUE))
      {
      /* dependency IS satisfied for VarNotSet deps ONLY if 
       * the variable is not set! */

      DSatisfied = TRUE;
      }

    if (DSatisfied == FALSE)
      {
      Failure = TRUE;

      MDB(6,fSTRUCT) MLog("INFO:     dependency not satisfied ('%s')\n",
        tmpD->Value);

      /* only display extra dependency failures if we are in verbose mode */

      if ((RemainingDeps < 1) || bmisset(EMsgFlags,mcmVerbose2))
        {
        RemainingDeps++;

        /* Store so that all unfulfilled dependencies can be listed */

        MUHTAdd(&OutstandingDepHT,tmpD->Value,NULL,NULL,NULL);
        }

      if (bmisset(&tmpD->BM,mdbmImport))
        {
        MRMInfoQueryRegister(NULL,tmpD->Value,NULL,NULL);
        }
      }  /* END if (DSatisfied == FALSE) */

    if (tmpD->NextAnd != NULL)
      tmpD = tmpD->NextAnd;
    else
      tmpD = tmpD->NextOr;
    }    /* END while (tmpD != NULL) */

  /* List unfinished dependencies */

  if ((RemainingDeps > 0) && (EMsg != NULL))
    {
    mhashiter_t HTIter;
    char *DepName = NULL;
    char *BPtr;
    int   BSpace;
    char  tmpBuf[MMAX_BUFFER];

    MUHTIterInit(&HTIter);
    MUSNInit(&BPtr,&BSpace,tmpBuf,sizeof(tmpBuf));

    while (MUHTIterate(&OutstandingDepHT,&DepName,NULL,NULL,&HTIter) == SUCCESS)
      {
      if (tmpBuf[0] != '\0')
        MUSNPrintF(&BPtr,&BSpace,",'%s'",DepName);
      else
        MUSNPrintF(&BPtr,&BSpace,"'%s'",DepName);
      }

    /* Determine singular or plural output string */
    if (RemainingDeps == 1)
      {
      *EMsg = "cannot satisfy dependency ";
      }
    else
      {
      *EMsg = "cannot satisfy dependencies ";
      }

    *EMsg += tmpBuf;
    }

  MUHTFree(&OutstandingDepHT,FALSE,NULL);

  if (Failure == TRUE)
    return(FAILURE);

  return(SUCCESS);
  } /* END MDAGCheckMultiWithHT() */
コード例 #9
0
ファイル: MMB.c プロジェクト: dhh1128/cbase
char *MMBPrintMessages(

  mmb_t               *Head,        /* I (optional) */
  enum MFormatModeEnum DFormat,     /* I */
  mbool_t              ShowVerbose, /* I */
  int                  MinPrio,     /* I (only display messages of this priority or higher) */
  char                *Buf,         /* O (optional,char * or mxml_t *) */
  int                  BufSize)     /* I */

  {
  mmb_t *mptr;

  char *BPtr = NULL;
  int   BSpace;

  char *hptr = NULL;

  static char tmpMBuf[MMAX_BUFFER];

  char  tmpLine[MMAX_LINE << 2];
  char  tmpLine2[MMAX_LINE << 2];

  if (Buf != NULL)
    {
    BPtr = Buf;
    BSpace = BufSize;
    }
  else
    {
    BPtr = tmpMBuf;
    BSpace = sizeof(tmpMBuf);
    }

  hptr = BPtr;

  switch (DFormat)
    {
    case mfmXML:
    case mfmAVP:  /* KLUDGE - use AVP to create packed XML data */

      {
      mxml_t *DE;
      mxml_t *CE;
      mxml_t *UE;

      int     count = 0;

      DE = (mxml_t *)Buf;

      if (DE == NULL)
        break;

      if (Head == NULL)
        {
        /* header not required in XML */

        break;
        }  /* END if (Head == NULL) */

      if (DFormat == mfmAVP)
        {
        /* initialize temporary parent XML element */

        UE = NULL;
        }
    
      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        CE = NULL;

        MXMLCreateE(&CE,"message");

        MXMLSetAttr(CE,"index",(void *)&count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCTime],(void *)&mptr->CTime,mdfLong);

        if (mptr->Owner != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaOwner],(void *)mptr->Owner,mdfString);

        MXMLSetAttr(CE,(char *)MMBAttr[mmbaPriority],(void *)&mptr->Priority,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCount],(void *)&mptr->Count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaExpireTime],(void *)&mptr->ExpireTime,mdfLong);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaType],(void *)MMBType[mptr->Type],mdfString);

        if (mptr->Data != NULL)
          {
          if (strchr(mptr->Data,'\n') != NULL)
            {
            char tmpData[MMAX_BUFFER];

            MUStrCpy(tmpData,mptr->Data,sizeof(tmpData));

            MUStrReplaceChar(tmpData,'\n',' ',FALSE);

            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)tmpData,mdfString);
            }
          else
            { 
            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)mptr->Data,mdfString);
            }
          }

        if (mptr->Label != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaLabel],(void *)mptr->Label,mdfString);

        if (DFormat == mfmAVP)
          {
          /* create/update temporary XML */

          if (UE == NULL)
            MXMLCreateE(&UE,(char*) MSON[msonData]);

          MXMLAddE(UE,CE);
          }
        else
          {
          MXMLAddE(DE,CE);
          }

        count++;
        }  /* END for (mptr) */

      if ((DFormat == mfmAVP) && (UE != NULL))
        {
        /* NOTE:  Buf is mxml_t *, do not populate */

        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

        hptr = BPtr;

        MXMLToString(UE,tmpLine,sizeof(tmpLine),NULL,TRUE);

        MXMLDestroyE(&UE);

        MUStringPack(tmpLine,tmpLine2,sizeof(tmpLine2));

        MUSNCat(&BPtr,&BSpace,tmpLine2);
        }
      }    /* END BLOCK */

      break;

    case mfmHuman:
    default:

      {
      int count = 0;

      char tmpBuf[MMAX_NAME];
      char label[MMAX_NAME];

      if (Buf != NULL)
        MUSNInit(&BPtr,&BSpace,Buf,BufSize);
      else
        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

      hptr = BPtr;

      if (Head == NULL)
        {
        if (ShowVerbose == TRUE)
          {
          MUSNPrintF(&BPtr,&BSpace,"%-7s %10s %10s %8.8s %4.4s %3.3s %s\n",
            "Label",
            "CreateTime",
            "ExpireTime",
            "Owner",
            "Prio",
            "Num",
            "Message");
          }

        break;
        }  /* END if (Head == NULL) */

      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        if (mptr->Label != NULL)
          {
          strncpy(label,mptr->Label,sizeof(label));
          }
        else
          {
          sprintf(label,"%d",
            count);
          }

        count++;

        if (ShowVerbose == TRUE)
          {
          char TString[MMAX_LINE];
          /* display w/relative time */

          MULToTString(mptr->CTime - MSched.Time,TString);

          strcpy(tmpBuf,TString);

          MULToTString(mptr->ExpireTime - MSched.Time,TString);

          MUSNPrintF(&BPtr,&BSpace,"%-8.8s %10s %10s %8.8s %4d %3d %s\n",
            label,
            tmpBuf,
            TString,
            (mptr->Owner != NULL) ? mptr->Owner : "N/A",
            mptr->Priority,
            mptr->Count,
            (mptr->Data != NULL) ? mptr->Data : "-");
          }
        else
          {
          if (mptr->Source != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] (from %s) %s\n",
              label,
              mptr->Source,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          else
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] %s\n",
              label,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          }
        }  /* END for (mptr) */
      }    /* END BLOCK (case mfmHuman) */

      break;
    }  /* END switch (DFormat) */

  return(hptr);
  }  /* END MMBPrintMessages() */
コード例 #10
0
ファイル: MClass.c プロジェクト: BradleyMorgan/maui
int MClassShow(

  mclass_t *CP,       /* I */
  char     *SBuffer,  /* O */
  long     *SBufSize, /* O */
  int       DMode)    /* I */
 
  {
  int       cindex;
  int       aindex;

  char      tmpLine[MAX_MLINE];
 
  char      tmpQALString[MAX_MLINE];
  char      tmpLString[MAX_MLINE];
 
  int       findex;
 
  char      QALChar;
 
  mclass_t *C;

  int ClAList[] = {
    mclaOCNode,
    mclaOCDProcFactor,
    mclaDefReqFeature,
    mclaMaxProcPerNode,
    mclaWCOverrun,
    -1 };

  int CAList[] = {
    mcaMaxProcPerUser,
    mcaMaxNodePerUser,
    mcaDefWCLimit,
    mcaMaxWCLimit,
    mcaMaxNodePerJob,
    mcaMaxProcPerJob,
    mcaMaxJobPerUser,
    -1 };

  char     *BPtr;
  int       BSpace;

  const char *FName = "MClassShow";

  DBG(3,fUI) DPrint("%s(%s,SBuffer,SBufSize,%d)\n",
    FName,
    (CP != NULL) ? CP->Name : "NULL",
    DMode);

  if (SBuffer == NULL)
    {
    return(FAILURE);
    }

  BPtr   =  SBuffer;
  BSpace = *SBufSize;

  MUSNPrintF(&BPtr,&BSpace,"Class/Queue Status\n\n");
 
  /*                        NAME PRI  FLAG  QDEF  QLST M PLST  FST  Limits */

  MUSNPrintF(&BPtr,&BSpace,"%-14s %-8s %-12s %-12s %12s%c %-20s %-6s %s\n\n",
    "Name",
    "Priority",
    "Flags",
    "QDef",
    "QOSList",
    '*',
    "PartitionList",
    "Target",
    "Limits");
 
  for (cindex = 0;cindex < MAX_MCLASS;cindex++)
    {
    C = &MClass[cindex];
 
    DBG(8,fUI) DPrint("INFO:     checking MClass[%02d]: %s\n",
      cindex,
      C->Name);
 
    if (C->Name[0] == '\0')
      continue;

    if (!strcmp(C->Name,NONE) || !strcmp(C->Name,ALL))
      continue;

    if ((CP != NULL) && (strcmp(CP->Name,NONE) != 0) && (C != CP))
      continue;
 
    tmpLine[0] = '\0';
 
    for (findex = 0;MJobFlags[findex] != NULL;findex++)
      {
      if (!(C->F.JobFlags & (1 << findex)))
        continue;
 
      if (tmpLine[0] != '\0')
        strcat(tmpLine,":");
 
      strcat(tmpLine,MJobFlags[findex]);
      }  /* END for (findex) */
 
    if (C->F.QALType == qalAND)
      QALChar = '&';
    else if (C->F.QALType == qalONLY)
      QALChar = '^';
    else
      QALChar = ' ';
 
    MUStrCpy(tmpQALString,MQOSBMToString(C->F.QAL),sizeof(tmpQALString));

    MUStrCpy(tmpLString,
      MCredShowAttrs(
        &C->L.AP,
        C->L.IP,
        NULL,
        NULL,
        NULL,
        &C->F,
        0,
        (1 << mcsLimits) | (1 << mcsUsage)),
        sizeof(tmpLString));
 
    /*                         NAME PRIO FLAG  QDEF  QLST M PLST  FSTARG Limits */
 
    MUSNPrintF(&BPtr,&BSpace,"%-14s %8ld %-12s %-12s %12s%c %-20s %5.2lf %7s\n",
      C->Name,
      C->F.Priority,
      (tmpLine[0] != '\0') ? tmpLine : NONE,
      ((mqos_t *)C->F.QDef) != NULL ?
        ((mqos_t *)C->F.QDef)->Name :
        NONE,
      (tmpQALString[0] != '\0') ? tmpQALString : NONE,
      QALChar,
      (C->F.PAL[0] == 0) ?
        NONE :
        MUListAttrs(ePartition,C->F.PAL[0]),
      C->F.FSTarget,
      (tmpLString[0] != '\0') ? tmpLString : NONE);

    /* list extended class attributes */

    tmpLine[0] = '\0';

    for (aindex = 0;ClAList[aindex] != -1;aindex++)
      {
      if ((MClassAToString(C,ClAList[aindex],tmpLString,mdfString,0) == SUCCESS) && 
          (tmpLString[0] != '\0') && 
           strcmp(tmpLString,NONE))
        {
        sprintf(&tmpLine[strlen(tmpLine)],"  %s=%s",
          MClassAttr[ClAList[aindex]],
          tmpLString);
        }
      }    /* END for (aindex) */

    /* list extended cred attributes */

    for (aindex = 0;CAList[aindex] != -1;aindex++)
      {
      if ((MCredAToString((void *)C,mxoClass,CAList[aindex],tmpLString,mdfString) == SUCCESS) &&
          (tmpLString[0] != '\0'))
        {
        sprintf(&tmpLine[strlen(tmpLine)],"  %s=%s",
          MCredAttr[CAList[aindex]],
          tmpLString);
        }
      }    /* END for (aindex) */

    if (tmpLine[0] != '\0')
      {
      MUStrNCat(&BPtr,&BSpace,tmpLine);
      MUStrNCat(&BPtr,&BSpace,"\n");
      }
    }  /* END for (cindex) */

  return(SUCCESS);
  }  /* END MClassShow() */
コード例 #11
0
ファイル: MTrig.c プロジェクト: dhh1128/cbase
int MTrigQuery(

  mtrig_t *T,        /* I */
  char    *Attr,     /* I */
  mbool_t  DoGlobal) /* I */

  {
  if (T == NULL)
    {
    return(FAILURE);
    }

  switch (T->OType)
    {
    case mxoRsv:
      {
      mrsv_t *R;
      mrsv_t *tmpR;

      char *ptr;
      char *TokPtr = NULL;

      char *tmpVar;

      char *BPtr = NULL;
      int   BSpace = 0;

      char *Label;

      char  AllHostList[MMAX_BUFFER];
      char  tmpBuf[MMAX_BUFFER];

      char  tmpName[MMAX_NAME];
      char  Action[MMAX_NAME];

      marray_t  RList;

      int rindex;

      enum MRsvAttrEnum AIndex;

      R = (mrsv_t *)T->O;

      if (R == NULL)
        {
        return(FAILURE);
        }

      MUArrayListCreate(&RList,sizeof(mrsv_t *),10);

      MRsvGroupGetList(R->RsvGroup,&RList,NULL,0);
      
      if (RList.NumItems <= 0)
        {
        T->State = mtsSuccessful;

        MUArrayListFree(&RList);

        return(SUCCESS);
        }

      MUStrCpy(Action,Attr,sizeof(Action));

      MUSNInit(&BPtr,&BSpace,AllHostList,sizeof(AllHostList));

      /* FORMAT:  <ATTR>=<VALUE> */

      Label = MUStrTok(Action,":",&TokPtr);

      ptr = MUStrTok(NULL," =\n\t",&TokPtr);

      tmpVar = MUStrTok(NULL," \n\t",&TokPtr);

      AIndex = (enum MRsvAttrEnum)MUGetIndexCI(ptr,MRsvAttr,FALSE,mraNONE);

      for (rindex = 0;rindex < RList.NumItems;rindex++)
        {
        tmpR = (mrsv_t *)MUArrayListGetPtr(&RList,rindex);

        /* all error checking done above */

        if ((tmpR->Label == NULL) || strcmp(Label,tmpR->Label))
          continue;

        switch (AIndex)
          {
          case mraAllocNodeList:

            if (MNLToString(&tmpR->NL,FALSE,",",'\0',tmpBuf,sizeof(tmpBuf)) == SUCCESS)
              {
              if (rindex == 0)
                {
                snprintf(tmpName,sizeof(tmpName),"%s-HOSTLIST",
                  Label);
                }
              else
                {
                snprintf(tmpName,sizeof(tmpName),"%s-HOSTLIST-%d",
                  Label,
                  rindex);
                }

              if (rindex == 0)
                MUSNCat(&BPtr,&BSpace,tmpBuf);
              else
                MUSNPrintF(&BPtr,&BSpace,",%s",tmpBuf);

              MTrigAddVariable(T,tmpName,0,tmpBuf,TRUE);
              }

            break;

          case mraReqOS:

            if (tmpR->ReqOS != 0)
              {
              if (rindex == 0)
                {
                snprintf(tmpName,sizeof(tmpName),"%s-OS",Label);
                }
              else
                {
                snprintf(tmpName,sizeof(tmpName),"%s-OS-%d",Label,rindex);
                }

              MUStrCpy(tmpBuf,MAList[meOpsys][tmpR->ReqOS],sizeof(tmpBuf));

              MTrigAddVariable(T,tmpName,0,tmpBuf,TRUE);
              }

            break;

          case mraVariables:

            {
            mln_t *tmpL;
            mln_t *Head;

            char *vptr;

            if (tmpVar == NULL)
              break;

            /* search variable lists for tmpVar */

            if (!strncasecmp(tmpVar,"owner.",strlen("owner.")))
              {
              switch (tmpR->OType)
                {
                case mxoUser:
                case mxoGroup:
                case mxoAcct:

                  Head = ((mgcred_t *)tmpR->O)->Variables;

                  vptr = &tmpVar[strlen("owner.")];

                  break;

                default:

                  Head = NULL;

                  vptr = NULL;

                  break;
                }
              }
            else
              {
              Head = tmpR->Variables;

              vptr = tmpVar;
              }

            if (vptr == NULL)
              {
              break;
              }

            if (MULLCheck(Head,vptr,&tmpL) == SUCCESS)
              {
              snprintf(tmpName,sizeof(tmpName),"%s-%s",Label,vptr);

              MUStrCpy(tmpBuf,(char *)tmpL->Ptr,sizeof(tmpBuf));

              MTrigAddVariable(T,tmpName,0,tmpBuf,TRUE);
              }
            else if (&tmpR->NL != NULL)
              {
              char *VarValue = NULL;

              mnode_t *N = MNLReturnNodeAtIndex(&tmpR->NL,0);

              if (MUHTGet(&N->Variables,vptr,(void **)&VarValue,NULL) == SUCCESS)
                {
                snprintf(tmpName,sizeof(tmpName),"%s-%s",Label,vptr);

                MUStrCpy(tmpBuf,VarValue,sizeof(tmpBuf));

                MTrigAddVariable(T,tmpName,0,tmpBuf,TRUE);
                }
              }    /* END else if (tmpR->NL != NULL) */
            }      /* END BLOCK mraVariables */

            break;

          default:

            /* NYI */

            break;
          }  /* END switch (AIndex) */
        }    /* END for (rindex) */

      switch (AIndex)
        {
        case mraAllocNodeList:

          snprintf(tmpName,sizeof(tmpName),"%s-HOSTLIST",Label);

          MTrigAddVariable(T,tmpName,0,AllHostList,TRUE);

          break;

        default:

          /* NYI */

          break;
        }   /* END switch (AIndex) */

      MUArrayListFree(&RList);
      }     /* END case mxoRsv */

      break;

    case mxoJob:

      break;

    default:

      break;

    }  /* END switch (T->OType) */

  T->State = mtsSuccessful;

  return(SUCCESS);
  }  /* END MTrigQuery() */