Exemple #1
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() */
Exemple #2
0
int MCPRestore(
 
  int   CKIndex, /* I */
  char *OName,   /* I */
  void *O)       /* I (modified) */
 
  {
  int   count;
  char *ptr;
  char *tmp;
 
  char  Line[MAX_MLINE];

  const char *FName = "MCPRestore";
 
  DBG(4,fCKPT) DPrint("%s(%s,%s,Optr)\n",
    FName,
    MCPType[CKIndex],
    OName);

  if ((O == NULL) || (OName == NULL))
    {
    return(FAILURE);
    }
 
  /* load checkpoint file */

  if (MCP.Buffer == NULL)
    { 
    if ((MCP.Buffer = MFULoad(MCP.CPFileName,1,macmWrite,&count,NULL)) == NULL)
      {
      DBG(1,fCKPT) DPrint("WARNING:  cannot load checkpoint file '%s'\n",
        MCP.CPFileName);
 
      return(FAILURE);
      }
    }

  /* NOTE:  CP version should be verified */

  /* create header */
 
  sprintf(Line,"%-9s %20s ",
    MCPType[CKIndex],
    OName);
 
  if ((ptr = strstr(MCP.Buffer,Line)) == NULL)
    {
    /* no checkpoint entry for object */
 
    DBG(5,fCKPT) DPrint("INFO:     no checkpoint entry for object '%s'\n",
      Line); 
 
    return(SUCCESS);
    }
 
  /* terminate line */
 
  if (((tmp = strchr(ptr,'\n')) != NULL) && (tmp - ptr < MAX_MLINE))
    {
    MUStrCpy(Line,ptr,MIN(sizeof(Line),(tmp - ptr + 1)));
    }
  else
    {
    DBG(1,fCKPT) DPrint("WARNING:  cannot read checkpoint line '%s'\n",
      Line);
 
    return(FAILURE);
    }
 
  switch(CKIndex)
    {
    case mcpJob:
 
      MJobLoadCP((mjob_t *)O,Line);
 
      break;
 
    case mcpNode:
 
      MNodeLoadCP((mnode_t *)O,Line);
 
      break;
 
    case mcpUser:

      MUserLoadCP((mgcred_t *)O,Line);
 
      break; 
 
    case mcpGroup:

      MGroupLoadCP((mgcred_t *)O,Line);       
 
      break;
 
    case mcpAcct:

      MAcctLoadCP((mgcred_t *)O,Line);       
 
      break;

    case mcpSched:

      MCPLoadSched(&MCP,Line,(msched_t *)O); 

      break;

    case mcpSys:

      MCPLoadSys(&MCP,Line,(msched_t *)O);

      break;

    case mcpSRes:

      /* NYI */

      break;
 
    default:
 
      DBG(1,fCKPT) DPrint("ERROR:    unexpected checkpoint type, %d, detected in %s()\n",
        CKIndex,
        FName);
 
      break;
    }  /* END switch (CKIndex) */
 
  return(SUCCESS);
  }  /* END MCPRestore() */
Exemple #3
0
int CPRecordLostJobs(

  char *CPFile)

  {
  int   count;
  char *Buffer;
  char *head;
  char *ptr;

  char *tokptr;

  char  Line[MAX_MLINE];

  int   buflen;

  mjob_t tmpJ;
  mreq_t tmpRQ;

  mjob_t *J;

  char  tmpLine[MAX_MLINE];
  char  JobName[MAX_MLINE];

  DBG(3,fCKPT) DPrint("CPRecordLostJobs(%s)\n",
    CPFile);

  /* load checkpoint file */

  if ((Buffer = MFULoad(CPFile,1,macmWrite,&count,NULL)) == NULL)
    {
    DBG(1,fCKPT) DPrint("WARNING:  cannot load checkpoint file '%s'\n",
      CPFile);

    return(FAILURE);
    }

  head   = Buffer;
  buflen = strlen(head);

  ptr = MUStrTok(head,"\n",&tokptr);

  while (ptr != NULL)
    {
    head = ptr + strlen(ptr) + 1;

    if ((head - Buffer) > buflen)
      {
      head = Buffer + buflen;
      }

    if (!strncmp(ptr,MCPType[mcpJob],strlen(MCPType[mcpJob])))
      {
      /* determine job completion time estimate */

      sscanf(Line,"%s %s",
        tmpLine,
        JobName);

      if (MJobFind(JobName,&J,0) == FAILURE)
        {
        memset(&tmpJ,0,sizeof(tmpJ));
        memset(&tmpRQ,0,sizeof(tmpRQ));

        /* FIXME:  only one req handled in RecordLostJobs() */

        tmpJ.Req[0] = &tmpRQ;

        if (MJobLoadCP(&tmpJ,ptr) == SUCCESS)
          {
          /* create temp record */

          tmpJ.State = mjsLost;

          MJobWriteStats(&tmpJ);
          }
        }
      }      /* END if (!strcmp(ptr,MCPType[])) */
    }        /* END while (ptr != NULL) */

  return(SUCCESS);
  }  /* END CPRecordLostJobs() */
Exemple #4
0
int MCPCreate(
 
  char *CPFile)
 
  {
  int   count;

  mckpt_t *CP;
 
  char  tmpCPFileName[MAX_MLINE];

  char  tmpBuf[MAX_MBUFFER];

  const char *FName = "MCPCreate";
 
  DBG(3,fCKPT) DPrint("%s(%s)\n",
    FName,
    (CPFile != NULL) ? CPFile : "NULL");
 
  if ((CPFile == NULL) || (CPFile[0] == '\0'))
    return(FAILURE);

  CP = &MCP;
 
  /* load old checkpoint file */

  if (MCPIsSupported(CP,CP->DVersion) == TRUE)
    { 
    if ((CP->OBuffer = MFULoad(CPFile,1,macmRead,&count,NULL)) == NULL)
      {
      DBG(1,fCKPT) DPrint("WARNING:  cannot load checkpoint file '%s'\n",
        CPFile);
      }
    }
  else
    {
    CP->OBuffer = NULL;
    }
 
  MUStrCpy(tmpCPFileName,CPFile,sizeof(tmpCPFileName));
  MUStrCat(tmpCPFileName,".tmp",sizeof(tmpCPFileName));
 
  /* open checkpoint file */
 
  if ((CP->fp = fopen(tmpCPFileName,"w+")) == NULL)
    { 
    DBG(1,fCKPT) DPrint("WARNING:  cannot open checkpoint file '%s'.  errno: %d (%s)\n",
      CPFile,
      errno,
      strerror(errno));
 
    return(FAILURE);
    }
 
  /* checkpoint scheduler, job, reservation, and node state information */
 
  MSchedToString(&MSched,tmpBuf);
  MCPStoreObj(CP->fp,mcpSched,"sched",tmpBuf);
 
  MSysToString(&MSched,tmpBuf,TRUE);
  MCPStoreObj(CP->fp,mcpSys,"sys",tmpBuf);
 
  MCPStoreQueue(CP,MJob);

  MCPStoreResList(CP,MRes);
 
  MCPStoreSRList(CP,SRes); 
 
  MCPStoreCluster(CP,MNode);
 
  MCPStoreUserList(CP,MUser);
  MCPStoreGroupList(CP,MGroup);
  MCPStoreAcctList(CP,MAcct);
 
  MCPWriteGridStats(CP->fp);
 
  MCPWriteSystemStats(CP->fp);
 
  fclose(CP->fp);
 
  MUStrCpy(tmpCPFileName,CPFile,sizeof(tmpCPFileName));
  MUStrCat(tmpCPFileName,".1",sizeof(tmpCPFileName));
 
  if (rename(CPFile,tmpCPFileName) == -1)
    {
    DBG(0,fCORE) DPrint("ERROR:    cannot rename checkpoint file '%s' to '%s' errno: %d (%s)\n",
      CPFile,
      tmpCPFileName, 
      errno,
      strerror(errno));
    }
 
  MUStrCpy(tmpCPFileName,CPFile,sizeof(tmpCPFileName));
  MUStrCat(tmpCPFileName,".tmp",sizeof(tmpCPFileName));
 
  if (rename(tmpCPFileName,CPFile) == -1)
    {
    DBG(0,fCORE) DPrint("ERROR:    cannot rename checkpoint file '%s' to '%s' errno: %d (%s)\n",
      tmpCPFileName,
      CPFile,
      errno,
      strerror(errno));
    }
 
  return(SUCCESS);
  }  /* END MCPCreate() */
Exemple #5
0
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() */