Exemplo n.º 1
0
Arquivo: MGroup.c Projeto: hocks/TSCC
int MGroupAdd(

    char      *GName,  /* I */
    mgcred_t **GP)     /* O (optional) */

{
    int           gindex;

    unsigned long hashkey;

    mgcred_t      *Gtmp;

    const char *FName = "MGroupAdd";

    DBG(6,fSTRUCT) DPrint("%s(%s,%s)\n",
                          FName,
                          (GName != NULL) ? "GName" : "NULL",
                          (GP != NULL) ? "GP" : "NULL");

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

    if (GP != NULL)
        *GP = NULL;

    hashkey = MAX(1,MUGetHash(GName) % MAX_MGROUP);

    for (gindex = hashkey; gindex < MAX_MGROUP + MAX_MHBUF; gindex++)
    {
        Gtmp = &MGroup[gindex];

        /* if group already in hash table */

        if (hashkey == Gtmp->Key)
        {
            if (!strcmp(Gtmp->Name,GName))
            {
                if (GP != NULL)
                    *GP = Gtmp;

                return(SUCCESS);
            }
        }

        /* if empty slot found */

        if (Gtmp->Key == 0)
        {
            /* setup new record */

            if (GP != NULL)
                *GP = Gtmp;

            Gtmp->Key = hashkey;

            Gtmp->Index = gindex;

            MUStrCpy(Gtmp->Name,GName,sizeof(Gtmp->Name));

            if (strcmp(GName,ALL) && strcmp(GName,NONE))
            {
                /* update group record */

                if (MSched.Mode != msmSim)
                    MCPRestore(mcpGroup,GName,(void *)Gtmp);

                Gtmp->OID = MUGIDFromName(Gtmp->Name);

                DBG(5,fSTRUCT) DPrint("INFO:     group %s added\n",
                                      GName);
            }
            else
            {
                /* NYI */
            }

            return(SUCCESS);
        }
    }    /* END for (gindex) */

    /* end of table reached */

    DBG(1,fSTRUCT) DPrint("ALERT:    group table overflow.  cannot add %s\n",
                          GName);

    return(FAILURE);
}  /* END MGroupAdd() */
Exemplo n.º 2
0
int MAcctAdd(

    char *AName,  /* I */
    mgcred_t **A) /* O (optional) */

{
    int aindex;

    int Key;

    mgcred_t *Atmp;

    const char *FName = "MAcctAdd";

    DBG(5, fSTRUCT)
    DPrint("%s(%s,A)\n", FName, (AName != NULL) ? AName : "NULL");

    if (A != NULL) *A = NULL;

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

    Key = (int)(MUGetHash(AName) % MAX_MACCT);

    for (aindex = Key; aindex < MAX_MACCT + MAX_MHBUF; aindex++) {
        Atmp = &MAcct[aindex];

        /* if account already in table */

        if (!strcmp(Atmp->Name, AName)) {
            if (A != NULL) *A = Atmp;

            return (SUCCESS);
        }

        /* if empty slot found */

        if (Atmp->Name[0] == '\0') {
            /* setup new record */

            if (A != NULL) *A = Atmp;

            if (!strcmp(AName, NONE))
                Atmp->Key = 0;
            else
                Atmp->Key = Key;

            MUStrCpy(Atmp->Name, AName, sizeof(Atmp->Name));

            Atmp->Index = aindex;

            if (strcmp(AName, ALL) && strcmp(AName, NONE)) {
                /* update account record */

                if (MSched.Mode != msmSim)
                    MCPRestore(mcpAcct, Atmp->Name, (void *)Atmp);

                DBG(5, fSTRUCT) DPrint("INFO:     account %s added\n", AName);
            } else {
                /* do nothing */
            }

            return (SUCCESS);
        }
    } /* END for (aindex) */

    /* end of table reached */

    DBG(1, fSTRUCT)
    DPrint("ALERT:    account table overflow  (cannot add account %s)\n",
           AName);

    return (FAILURE);
} /* END MAcctAdd() */
Exemplo n.º 3
0
int MCPLoad(
 
  char *CPFile,  /* I (utilized) */
  int   Mode)    /* I */
 
  {
  char *ptr;
 
  char *head;
 
  int   ckindex;
  int   count;
 
  int   buflen;
 
  char *tokptr;
 
  static int FailureIteration = -999;

  const char *FName = "MCPLoad";
 
  DBG(3,fCKPT) DPrint("%s(%s,%s)\n",
    FName,
    CPFile,
    (Mode == mckptResOnly) ? "ResOnly" : "NonRes");
 
  if ((MSched.Mode == msmSim) && 
      (getenv(MSCHED_ENVCKTESTVAR) == NULL))
    {
    /* checkpointing not enabled */
 
    return(SUCCESS);
    }
 
  if (FailureIteration == MSched.Iteration) 
    {
    return(FAILURE);
    }
 
  /* load checkpoint file */
 
  if ((MCP.OBuffer = MFULoad(CPFile,1,macmWrite,&count,NULL)) == NULL)
    {
    DBG(1,fCKPT) DPrint("WARNING:  cannot load checkpoint file '%s'\n",
      CPFile);
 
    FailureIteration = MSched.Iteration;
 
    return(FAILURE);
    }
 
  head   = MCP.OBuffer;
  buflen = strlen(head);

  /* determine checkpoint version */

  if (MCP.DVersion[0] == '\0')
    {
    MCPRestore(mcpSched,"sched",(void *)&MSched);

    if (MCPIsSupported(&MCP,MCP.DVersion) == FALSE)
      {
      /* cannot load checkpoint file */

      return(FAILURE);
      }
    }
 
  ptr = MUStrTok(head,"\n",&tokptr);
 
  while (ptr != NULL)
    {
    head = ptr + strlen(ptr) + 1;
 
    if ((head - MCP.OBuffer) > buflen)
      {
      head = MCP.OBuffer + buflen;
      }
 
    for (ckindex = 0;MCPType[ckindex] != NULL;ckindex++)
      {
      if (strncmp(ptr,MCPType[ckindex],strlen(MCPType[ckindex])))
        continue;

      if ((Mode == mckptResOnly) &&
          (ckindex != mcpRes) &&
          (ckindex != mcpSRes) && 
          (ckindex != mcpSched))
        {
        break;
        }
      else if ((Mode == mckptNonRes) &&
               (ckindex == mcpRes))
        {
        break;
        }
 
      DBG(5,fCKPT) DPrint("INFO:     loading %s checkpoint data '%s'\n",
        MCPType[ckindex],
        ptr);

      switch(ckindex)
        {
        case mcpSched:

          if (MCPLoadSched(&MCP,ptr,&MSched) == FAILURE)
            {
            DBG(1,fCKPT) DPrint("ALERT:    cannot load sched data.  aborting checkpoint load\n");

            free(MCP.OBuffer);

            MCP.OBuffer = NULL;

            return(FAILURE);
            }

          break;

        case mcpSys:

          MCPLoadSys(&MCP,ptr,&MSched);

          break;

        case mcpJob:

          MJobLoadCP(NULL,ptr);

          break;
 
        case mcpRes: 

          MResLoadCP(NULL,ptr);

          break;

        case mcpSRes:

          MCPLoadSR(ptr);

          break;

        case mcpNode:

          MNodeLoadCP(NULL,ptr);

          break;

        case mcpUser:

          MUserLoadCP(NULL,ptr);

          break;

        case mcpGroup:

          MGroupLoadCP(NULL,ptr);

          break;

        case mcpAcct:

          MAcctLoadCP(NULL,ptr);

          break;

        case mcpTotal:
        case mcpRTotal:
        case mcpCTotal:
        case mcpGTotal:

          MCPLoadStats(ptr);

          break;

        case mcpSysStats:

          MCPLoadSysStats(ptr);

          break;

        default:

          DBG(1,fCKPT) DPrint("ERROR:    line '%s' not handled in checkPoint file '%s'\n",
            ptr,
            CPFile);

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

      break; 
      }      /* END for (ckindex) */
 
    if (MCPType[ckindex] == NULL)
      {
      DBG(3,fCKPT) DPrint("WARNING:  unexpected line '%s' in checkpoint file '%s'\n",
        ptr,
        CPFile);
      }
 
    ptr = MUStrTok(NULL,"\n",&tokptr);
    }        /* END while (ptr != NULL) */
 
  free(MCP.OBuffer);

  MCP.OBuffer = NULL;

  if (Mode == mckptNonRes)
    {
    MSysSynchronize();
    }
 
  return(SUCCESS);
  }  /* END MCPLoad() */
Exemplo n.º 4
0
int MRMLoadJobCP(

  mrm_t   *R,       /* I */
  mjob_t  *J,       /* I (modified) */
  char    *EMsg)    /* O (optional,minsize=MMAX_LINE) */

  {
  mbool_t IsFound = FALSE;

  mdb_t *MDBInfo;

  MSchedGetAttr(msaDBHandle,mdfNONE,(void **)&MDBInfo,-1);

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

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

  if (bmisset(&R->Flags,mrmfFullCP) || 
      bmisset(&R->IFlags,mrmifLocalQueue) || 
     (R->Type == mrmtMoab))
    {
    IsFound = TRUE;

    if ((MCP.UseDatabase == FALSE) || (MDBInfo->DBType == mdbNONE))
      {
      char *CPFile=NULL;  /* NULL it: returned pointer to read buffer */

      /* Load full job record from spool file */
   
      char FileName[MMAX_PATH_LEN];

      MCPGetCPFileName(J,FileName,sizeof(FileName));

      /* note - MFULoadAllocReadBuffer does the MUCalloc on CPFile.
                This routine must do the MUFree on CPFile 
                ON SUCCESS ONLY. */

      if (MFULoadAllocReadBuffer(FileName,&CPFile,EMsg,NULL) == FAILURE)
        {
        IsFound = FALSE;
   
        if (J->Req[0] == NULL)
          {
          /* job is invalid */
   
          MDB(1,fRM) MLog("ERROR:    cannot load job checkpoint file for job %s - %s\n",
            J->Name,
            EMsg);
   
          return(FAILURE);
          }
        }
      else if (MJobLoadCPNew(J,CPFile) == FAILURE)
        {
        IsFound = FALSE;
   
        if (bmisset(&J->SpecFlags,mjfNoRMStart))
          {
          if (EMsg != NULL)
            strcpy(EMsg,"cannot load job checkpoint info");
   
          MDB(1,fRM) MLog("ERROR:    cannot load job checkpoint info for job %s\n",
            J->Name);
   
          /* MFULoadAllocReadBuffer was successful, so free its read buffer it passed back */
          MUFree(&CPFile);

          return(FAILURE);
          }    /* END if (bmisset(&J->SpecFlags,mjfNoRMStart)) */
        }      /* END else if (MJobLoadCPNew(J,CPFile) == FAILURE) */

      /* Free the read buffer which was allocated */
      MUFree(&CPFile);
      }        /* END if ((MCP.UseDatabase == FALSE) || (MDBInfo->DBType == mdbNONE)) */
    else
      {
      mstring_t MString(MMAX_BUFFER);
      int queryRC;
      int loadRC = FAILURE;

      /* check database for job, create new entry if job does not exist in database */

      queryRC = MDBQueryCP(MDBInfo,(char *)MCPType[mcpJob],J->Name,NULL,1,&MString,NULL);

      if (queryRC == SUCCESS)
        loadRC = MJobLoadCPNew(J,MString.c_str());

      if ((queryRC == SUCCESS) && (loadRC == FAILURE))
        {
        IsFound = FALSE;
   
        if (bmisset(&J->SpecFlags,mjfNoRMStart))
          {
          if (EMsg != NULL)
            strcpy(EMsg,"cannot load job checkpoint info");
   
          MDB(1,fRM) MLog("ERROR:    cannot load job checkpoint info for job %s\n",
            J->Name);
   
          return(FAILURE);
          }
        }
      else
        {
        IsFound = FALSE;

        /* MOCheckpoint(mxoJob,(void *)J,TRUE,NULL); -- why are we doing this?
         * this function is called in MRMJobPostLoad and we checkpoint in there as well */
        }
      }
    }        /* END if (bmisset(&R->Flags,mrmfFullCP) || ... */
  else if ((MSched.Iteration == 0) ||
           (MSched.EnableHighThroughput == FALSE) ||
           bmisset(&R->IFlags,mrmifLocalQueue))
    {
    /* in high throughput mode, only look in checkpoint record on iteration 0 */

    char tmpName[MMAX_NAME];

    if (J->SRMJID != NULL)
      {
      /* use source RM job id over job name */

      MJobGetName(NULL,J->SRMJID,R,tmpName,sizeof(tmpName),mjnShortName);
      }
    else
      {
      MUStrCpy(tmpName,J->Name,sizeof(tmpName));
      }

    MCPRestore(mcpJob,tmpName,(void *)J,&IsFound);
     
    /* Looking up the job name by SRMJID in the checkpoint file may not be correct.
     * The job may have been stored with J->Name instead of SRMJID.
     * If so, the check above could fail to load the job from the checkpoint, so we
     * would lose the information that was checkpointed.
     * Thus we try again if MCPRestore fails.
     */

    if ((IsFound == FALSE) && 
        (J->SRMJID != NULL) && 
        (strcmp(J->SRMJID,tmpName)))
      {
      MUStrCpy(tmpName,J->Name,sizeof(tmpName));

      MCPRestore(mcpJob,tmpName,(void *)J,&IsFound);
      }

    if (IsFound == FALSE)
      {
      MDB(4,fRM) MLog("INFO:     job checkpoint info for job %s (%s) not found\n",
        J->Name,
        (J->SRMJID == NULL) ? "" : J->SRMJID);
      } 
    }    /* END else (bmisset(&R->Flags,mrmfFullCP) || ...) */

  /* need to process RM ext. string from newly checkpointed jobs */

  if (IsFound == TRUE)
    {
#if 0
    char *FirstPartition;
    char *LastPartition;
    char *SearchString = "partition:";
#endif

    /* mark this job as being loaded from the checkpoint file so
     * routines know to handle some data differently */
    
    bmset(&J->IFlags,mjifWasLoadedFromCP);

#if 0
    /* WARNING - this code is a temporary bug fix for the llnl 5.2 branch only
       Do not port this code to other branches
       The fix is for ticket 5097 - if we discover how the ALL partition list (including internal)
       is being written to the checkpoint file we can remove this code. */

    /* Due to a bug in the client software we could have the default submit partition and a partition specified in the command
       script show up in the RMXString as follows...
       
       "x=partition:g02;partition:g04"
       
       Since llnl does not want to update all of their client systems we are putting this temporary fix in the moab code
       that reads in the checkpoint records to remove the first partition entry if multiple partition entries are found.
       This is a legal syntax, but we are assuming that we have encoutnered it due to the client bug.

       Note that if a user specifies multiple partitions that the RMXString has the format "x=partition:g02:g04" */
 
    if ((J->RMXString != NULL) &&
        ((FirstPartition = MUStrStr(J->RMXString,SearchString,0,TRUE,FALSE)) != NULL))
      {
      /* See if there is another partition:xyz in the RMXString */

      if ((LastPartition = MUStrStr(FirstPartition + strlen(SearchString),SearchString,0,TRUE,TRUE)) != NULL)
        {
        /* we assume that all the partitions are grouped together - x=partition:g02;partition:g03;partition:g04; */

        while (*LastPartition != '\0')
          {
          *FirstPartition++ = *LastPartition++;
          }
        *FirstPartition = '\0';
        }
      }
    /* END WARNING */
#endif

    MJobProcessExtensionString(J,J->RMXString,mxaNONE,NULL,NULL);
    }

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