int process_label_array(

  dynamic_string *feature_list,
  xmlNode        *node)

  {
  char     *attr_value;
  xmlNode  *child;
  int       first = 0;

  for (child = node->children; child != NULL; child = child->next)
    {
    if ((attr_value = (char *)xmlGetProp(child, (const xmlChar *)"name")) != NULL)
      {
      if (!strncmp(attr_value, "MOAB:FEATURE=", strlen("MOAB:FEATURE=")))
        {
        char *feature_name = attr_value + strlen("MOAB:FEATURE=");
        if (first == 0)
          {
          append_dynamic_string(feature_list, feature_name);
          first++;
          }
        else
          {
          append_dynamic_string(feature_list, ",");
          append_dynamic_string(feature_list, feature_name);
          }
        }

      free(attr_value);
      }
    }

  return(PBSE_NONE);
  } /* END process_label_array() */
Esempio n. 2
0
int save_current_reserve_param(

  dynamic_string *command,
  dynamic_string *node_list,
  unsigned int    width,
  unsigned int    nppn)

  {
  char            buf[MAXLINE * 2];
  int             rc; 

  /* print out the current reservation param element */
  /* place everything up to the node list */
  snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN, width, nppn);
  rc = append_dynamic_string(command, buf);
  
  /* add the node list */
  if (rc == PBSE_NONE)
    append_dynamic_string(command, node_list->str);
  
  /* end the reserve param element */
  if (rc == PBSE_NONE)
    append_dynamic_string(command, APBASIL_RESERVE_PARAM_END);

  return(rc);
  } /* END save_current_reserve_param() */
Esempio n. 3
0
dynamic_string *get_reservation_command(

  resizable_array *host_req_list,
  char            *username,
  char            *jobid,
  char            *apbasil_path,
  char            *apbasil_protocol)

  {
  dynamic_string *command = get_dynamic_string(-1, NULL);
  dynamic_string *node_list = get_dynamic_string(-1, NULL);
  char            buf[MAXLINE * 2];
  unsigned int    width = 0;
  unsigned int    nppn = 0;
  int             iter = -1;
  host_req       *hr;

  /* place the top header */
  snprintf(buf, sizeof(buf), APBASIL_RESERVE_REQ, 
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL);
  append_dynamic_string(command, buf);

  /* place the reserve header */
  snprintf(buf, sizeof(buf), APBASIL_RESERVE_ARRAY, username, jobid);
  append_dynamic_string(command, buf);

  while ((hr = (host_req *)next_thing(host_req_list, &iter)) != NULL)
    {
    width += hr->ppn;
    nppn = MAX(nppn,hr->ppn);
    
    if (node_list->used != 0)
      append_dynamic_string(node_list, ",");
    
    append_dynamic_string(node_list, hr->hostname);

    free_host_req(hr);
    }
      
  save_current_reserve_param(command, node_list, width, nppn);

  free_dynamic_string(node_list);

  /* pipe the output to apbasil */
  snprintf(buf, sizeof(buf), "</ReserveParamArray></BasilRequest>\" | %s",
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);
  append_dynamic_string(command, buf);

  return(command);
  } /* END get_reservation_command() */
Esempio n. 4
0
dynamic_string *get_dynamic_string(int initial_size, const char *str)
  {
  dynamic_string *ds = calloc(1, sizeof(dynamic_string));

  if (ds == NULL)
    return(ds);

  if (initial_size > 0)
    ds->size = initial_size;
  else
    ds->size = DS_INITIAL_SIZE;
    
  ds->str = calloc(1, ds->size);

  if (ds->str == NULL)
    {
    free(ds);
    return(NULL);
    }
    
  /* initialize empty str */
  ds->used = 0;

  /* add the string if it exists */
  if (str != NULL)
    {
    if (append_dynamic_string(ds,str) != PBSE_NONE)
      {
      free_dynamic_string(ds);
      return(NULL);
      }
    }

  return(ds);
  }
Esempio n. 5
0
dynamic_string *get_reservation_command(

  resizable_array *host_req_list,
  char            *username,
  char            *jobid,
  char            *apbasil_path,
  char            *apbasil_protocol,
  char            *multi_req_list,
  int              use_nppn,
  int              nppcu,
  int              mppdepth)

  {
  dynamic_string *command = get_dynamic_string(-1, NULL);
  dynamic_string *node_list = get_dynamic_string(-1, NULL);
  char            buf[MAXLINE * 2];

  /* place the top header */
  snprintf(buf, sizeof(buf), APBASIL_RESERVE_REQ, 
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL);
  append_dynamic_string(command, buf);

  /* place the reserve header */
  snprintf(buf, sizeof(buf), APBASIL_RESERVE_ARRAY, username, jobid);
  append_dynamic_string(command, buf);

  if (multi_req_list == NULL)
    {
    create_reserve_params_from_host_req_list(host_req_list, apbasil_protocol, use_nppn, nppcu, mppdepth, command);
    }
  else
    {
    /* no need to account for use_nppn here, this path always should */
    create_reserve_params_from_multi_req_list(multi_req_list, apbasil_protocol, nppcu, mppdepth, command);
    }

  free_dynamic_string(node_list);

  /* pipe the output to apbasil */
  snprintf(buf, sizeof(buf), "</ReserveParamArray></BasilRequest>\" | %s",
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);
  append_dynamic_string(command, buf);

  return(command);
  } /* END get_reservation_command() */
Esempio n. 6
0
int create_reserve_params_from_host_req_list(

  resizable_array *host_req_list, /* I */
  char            *apbasil_protocol, /* I */
  int              use_nppn,      /* I */
  int              nppcu,         /* I */
  int              mppdepth,      /* I */
  dynamic_string  *command)       /* O */

  {
  dynamic_string *node_list = get_dynamic_string(-1, NULL);
  host_req       *hr;
  unsigned int    nppn = 0;
  unsigned int    width = 0;
  int             iter = -1;
  
  while ((hr = (host_req *)next_thing(host_req_list, &iter)) != NULL)
    {
    width += hr->ppn;
    nppn = MAX((unsigned int)nppn, hr->ppn);
    
    if (node_list->used != 0)
      append_dynamic_string(node_list, ",");
    
    append_dynamic_string(node_list, hr->hostname);
    
    free_host_req(hr);
    }

  if (use_nppn == FALSE)
    nppn = -1;

  adjust_for_depth(width, nppn, mppdepth);
  
  save_current_reserve_param(command, apbasil_protocol, node_list, width, nppn, nppcu, mppdepth);

  if (node_list != NULL)
    free(node_list);

  return(PBSE_NONE);
  } /* END create_reserve_params_from_host_req_list() */
Esempio n. 7
0
int append_char_to_dynamic_string(
    
  dynamic_string *ds,
  char            c)

  {
  char str[2];
  str[0] = c;
  str[1] = '\0';

  return(append_dynamic_string(ds, str));
  } /* END append_char_to_dynamic_string() */
Esempio n. 8
0
int execute_reservation(

  char  *command_str,
  char **reservation_id)

  {
  int             rc;
  FILE           *alps_pipe;
  int             fd;
  dynamic_string *output = NULL;
  char            tmpBuf[MAXLINE];
  int             bytes_read;
  int             total_bytes_read = 0;


  if ((alps_pipe = popen(command_str, "r")) == NULL)
    {
    snprintf(log_buffer, sizeof(log_buffer),
      "Unable to open command %s for apbasil",
      command_str);
    log_err(errno, __func__, log_buffer);

    return(WRITING_PIPE_ERROR);
    }

  fd = fileno(alps_pipe);

  /* now read from the pipe */
  output = get_dynamic_string(-1, NULL);
  while ((bytes_read = read(fd, tmpBuf, sizeof(tmpBuf) - 1)) > 0)
    {
    total_bytes_read += bytes_read;
    tmpBuf[bytes_read] = '\0';
    append_dynamic_string(output, tmpBuf);
    }

  /* perform post-processing */
  pclose(alps_pipe);

  if ((bytes_read == -1) ||
      (total_bytes_read == 0))
    rc = READING_PIPE_ERROR;
  else
    {
    rc = parse_reservation_output(output->str, reservation_id);
    }

  free_dynamic_string(output);

  return(rc);
  } /* END execute_reservation() */
int process_accelerator_array(

  dynamic_string *status,
  xmlNode        *node)

  {
  xmlNode       *child;
  char          *attr_value;
  char          *attr_value2;
  char           buf[MAXLINE];

  copy_to_end_of_dynamic_string(status, CRAY_GPU_STATUS_START);

  for (child = node->children; child != NULL; child = child->next)
    {
    if (!strcmp((const char *)child->name, accelerator))
      {
      /* write the gpu id */
      attr_value = (char *)xmlGetProp(child, (const xmlChar *)type);
      attr_value2 = (char *)xmlGetProp(child, (const xmlChar *)ordinal);
      snprintf(buf, sizeof(buf), "%s-%d", attr_value, atoi(attr_value2));
      copy_to_end_of_dynamic_string(status, "gpu_id=");
      append_dynamic_string(status, buf);
      free(attr_value);
      free(attr_value2);

      attr_value = (char *)xmlGetProp(child, (const xmlChar *)state);
      copy_to_end_of_dynamic_string(status, "state=");
      append_dynamic_string(status, attr_value);
      free(attr_value);

      attr_value = (char *)xmlGetProp(child, (const xmlChar *)family);
      copy_to_end_of_dynamic_string(status, "family=");
      append_dynamic_string(status, attr_value);
      free(attr_value);

      attr_value = (char *)xmlGetProp(child, (const xmlChar *)memory_mb);
      copy_to_end_of_dynamic_string(status, "memory=");
      append_dynamic_string(status, attr_value);
      append_dynamic_string(status, "mb");
      free(attr_value);

      attr_value = (char *)xmlGetProp(child, (const xmlChar *)clock_mhz);
      copy_to_end_of_dynamic_string(status, "clock_mhz=");
      append_dynamic_string(status, attr_value);
      free(attr_value);
      }
    }
  
  copy_to_end_of_dynamic_string(status, CRAY_GPU_STATUS_END);

  return(PBSE_NONE);
  } /* END process_accelerator_array() */
Esempio n. 10
0
int create_reserve_params_from_multi_req_list(

  char           *multi_req_list, /* I */
  char           *apbasil_protocol, /* I */
  int             nppcu,          /* I */
  int             mppdepth,       /* I */
  dynamic_string *command)        /* O */

  {
  dynamic_string *node_list = get_dynamic_string(-1, NULL);
  char           *tok;
  char           *str = multi_req_list;
  int             node_count;
  char           *comma;
  unsigned int    width;
  unsigned int    nppn;
  
  while ((tok = threadsafe_tokenizer(&str, "*")) != NULL)
    {
    node_count = 1;

    clear_dynamic_string(node_list);
    append_dynamic_string(node_list, tok);
    
    comma = tok;
    while ((comma = strchr(comma+1, ',')) != NULL)
      node_count++;
    
    tok = threadsafe_tokenizer(&str, "|");
    nppn = atoi(tok);
    
    width = nppn * node_count;

    adjust_for_depth(width, nppn, mppdepth);

    save_current_reserve_param(command, apbasil_protocol, node_list, width, nppn, nppcu, mppdepth);
    }

  if (node_list != NULL)
    free(node_list);

  return(PBSE_NONE);
  } /* END create_reserve_params_from_multi_req_list() */
Esempio n. 11
0
/* 
 * initializes a dynamic string and returns it, or NULL if there is no memory 
 *
 * @param initial_size - the initial size of the string, use default if -1
 * @param str - the initial string to place in the dynamic string if not NULL
 * @return - the dynamic string object or NULL if no memory
 */
dynamic_string *get_dynamic_string(
    
  int         initial_size, /* I (-1 means default) */
  const char *str)          /* I (optional) */

  {
  dynamic_string *ds = (dynamic_string *)calloc(1, sizeof(dynamic_string));

  if (ds == NULL)
    return(ds);

  if (initial_size > 0)
    ds->size = initial_size;
  else
    ds->size = DS_INITIAL_SIZE;
    
  ds->str = (char *)calloc(1, ds->size);

  if (ds->str == NULL)
    {
    free(ds);
    return(NULL);
    }
    
  /* initialize empty str */
  ds->used = 0;

  /* add the string if it exists */
  if (str != NULL)
    {
    if (append_dynamic_string(ds,str) != PBSE_NONE)
      {
      free_dynamic_string(ds);
      return(NULL);
      }
    }

  return(ds);
  } /* END get_dynamic_string() */
Esempio n. 12
0
int parse_variable_list(

  memmgr   **mm,        /* memory manager */
  job_data **dest_hash, /* This is the dest hashmap for vars found */
  job_data  *user_env,  /* This is the source hashmap */
  int        var_type,  /* Type for vars not pulled from the source hash */
  int        op_type,   /* Op for vars not pulled from the source hash */
  char      *the_list)  /* name=value,name1=value1,etc to be parsed */

  {
  int             alloc_size = 0;
  dynamic_string *job_env = get_dynamic_string(-1, NULL);
  char            name[JOB_ENV_START_SIZE];
  char           *s = NULL;
  char           *c = NULL;
  char           *delim = NULL;

  s = the_list;

  while (s)
    {
    delim = strpbrk(s, "=,");

    if (delim == s)
      {
      fprintf(stderr, "invalid -v syntax\n");
      return(3);
      }

    /* If delim is ','or NULL we have no value. Get the environment variable in s */ 
    /* If delim is '=' and delim+1 is ',' or NULL we also need to get 
       the environment variable in s */
    if (delim == NULL || *delim == ',' ||
       ((*delim == '=') && (*(delim + 1) == ',')) ||
       ((*delim == '=') && ((delim + 1) == NULL)))
      {
      if (delim == NULL)
        alloc_size = strlen(s);
      else
        alloc_size = delim - s;

      memcpy(name, s, alloc_size);
      name[alloc_size] = '\0';
      c = getenv(name);

      if (c != NULL)
        {
        append_dynamic_string(job_env, name);
        append_dynamic_string(job_env, "=");
        append_dynamic_string(job_env, c);
        if (delim == NULL)
          s = NULL;
        else
          {
          append_dynamic_string(job_env, ",");
          s = delim + 1;
          if (*s == ',') /* This ended in '='. Move one more */
            s++;
          }
        }
      else
        {
        /* No environment variable set for this name. Pass it on with value "" */
        if (delim == NULL)
          {
          snprintf(name, sizeof(name), "%s", s);
          append_dynamic_string(job_env, name);
          append_dynamic_string(job_env, "=");
          s = NULL;
          }
        else
          {
          memcpy(name, s, delim - s);
          name[delim - s] = '\0';
          append_dynamic_string(job_env, name);
          append_dynamic_string(job_env, "=,");
          s = delim + 1;
          }
        }
      }
    else
      {
      /* We have a key value pair */
      delim = strchr(s, ',');
      if (delim == NULL)
        {
        alloc_size = strlen(s);
        /* we are at the end */
        append_dynamic_string(job_env, s);
        s = NULL;
        }
      else
        {
        /* We have another variable in the list. Take care of the current one */
        alloc_size = delim - s;
        memcpy(name, s, alloc_size);
        name[alloc_size] = '\0';
        append_dynamic_string(job_env, name);
        append_dynamic_string(job_env, ",");
        s = delim + 1;
        }
      }
    }

  hash_add_or_exit(mm, dest_hash, ATTR_v, job_env->str, ENV_DATA);
  free_dynamic_string(job_env);

  return(PBSE_NONE);
  } /* END parse_variable_list() */ 
Esempio n. 13
0
/*
 * attr_to_str
 *
 * @param ds - the dynamic string we're printing the pbs_attribute into
 * @param aindex - the pbs_attribute's index
 * @param attr - the pbs_attribute
 * @param XML - boolean telling us whether to print XML or not
 */
int attr_to_str(

  dynamic_string   *ds,     /* O */
  attribute_def    *at_def, /* I */
  pbs_attribute     attr,   /* I */
  int               XML)    /* I */

  {
  /* used to print numbers and chars as strings */
  char local_buf[MAXLINE];
  int  rc = PBSE_NONE;

  if ((attr.at_flags & ATR_VFLAG_SET) == FALSE)
    return(NO_ATTR_DATA);

  switch (at_def->at_type)
    {
    case ATR_TYPE_LONG:

      snprintf(local_buf, sizeof(local_buf), "%ld", attr.at_val.at_long);
      rc = append_dynamic_string(ds, local_buf);

      break;

    case ATR_TYPE_CHAR:

      sprintf(local_buf, "%c", attr.at_val.at_char);
      rc = append_dynamic_string(ds, local_buf);

      break;

    case ATR_TYPE_STR:

      if (attr.at_val.at_str == NULL)
        return(NO_ATTR_DATA);

      if (strlen(attr.at_val.at_str) == 0)
        return(NO_ATTR_DATA);

      if (XML)
        rc = append_dynamic_string_xml(ds, attr.at_val.at_str);
      else
        rc = append_dynamic_string(ds, attr.at_val.at_str);

      break;

    case ATR_TYPE_ARST:
    case ATR_TYPE_ACL:

      {
      int j;
      struct array_strings *arst = attr.at_val.at_arst;

      if (arst == NULL)
        return(NO_ATTR_DATA);

      /* concatenate all of the array strings into one string */
      for (j = 0; j < arst->as_usedptr; j++)
        {
        if (j > 0)
          append_dynamic_string(ds, ",");

        if (XML)
          rc = append_dynamic_string_xml(ds, arst->as_string[j]);
        else
          rc = append_dynamic_string(ds, arst->as_string[j]);
        }
      }

      break;

    case ATR_TYPE_SIZE:

      rc = size_to_dynamic_string(ds, &(attr.at_val.at_size));

      break;

    case ATR_TYPE_RESC:

      {
      resource *current = (resource *)GET_NEXT(attr.at_val.at_list);

      if (current == NULL)
        return(NO_ATTR_DATA);

      /* print all of the resources */
      while (current != NULL)
        {

        /* there are only 3 resource types used */
        switch (current->rs_value.at_type)
          {
          case ATR_TYPE_LONG:

            append_dynamic_string(ds, "\t\t<");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            append_dynamic_string(ds, ">");

            snprintf(local_buf, sizeof(local_buf), "%ld", current->rs_value.at_val.at_long);
            append_dynamic_string(ds, local_buf);

            append_dynamic_string(ds, "</");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            rc = append_dynamic_string(ds, ">");

            break;

          case ATR_TYPE_STR:

            /* Patch provided by Martin Siegert to fix seg-fault
             * when current->rs_value.at_val.at_str is NULL 
             * Bugzilla bug 101 
             */

            if (current->rs_value.at_val.at_str == NULL)
              break;

            if (strlen(current->rs_value.at_val.at_str) == 0)
              break;

            append_dynamic_string(ds, "\t\t<");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            append_dynamic_string(ds, ">");

            
            if (XML)
              append_dynamic_string_xml(ds, current->rs_value.at_val.at_str);
            else
              append_dynamic_string(ds, current->rs_value.at_val.at_str);

            append_dynamic_string(ds, "</");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            rc = append_dynamic_string(ds, ">");

            break;

          case ATR_TYPE_SIZE:

            append_dynamic_string(ds, "\t\t<");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            append_dynamic_string(ds, ">");

            size_to_dynamic_string(ds, &(current->rs_value.at_val.at_size));

            append_dynamic_string(ds, "</");
            append_dynamic_string(ds, current->rs_defin->rs_name);
            rc = append_dynamic_string(ds, ">");

            break;
          }
        
        if (rc != PBSE_NONE)
          break;

        current = (resource *)GET_NEXT(current->rs_link);
        append_dynamic_string(ds, "\n");
        }
      }

      break;

    /* NYI */
    case ATR_TYPE_LIST:
    case ATR_TYPE_LL:
    case ATR_TYPE_SHORT:
    case ATR_TYPE_JINFOP:

      break;
    } /* END switch pbs_attribute type */

  return(rc);
  } /* END attr_to_str */
Esempio n. 14
0
int save_current_reserve_param(

  dynamic_string *command,
  char           *apbasil_protocol,
  dynamic_string *node_list,
  unsigned int    width,
  int             nppn,
  int             nppcu,
  int             mppdepth)

  {
  char            buf[MAXLINE * 2];
  int             rc; 
  float           apbasil_protocol_float;

  if (apbasil_protocol != NULL)
    sscanf(apbasil_protocol, "%f", &apbasil_protocol_float);
  else
    sscanf(DEFAULT_APBASIL_PROTOCOL, "%f", &apbasil_protocol_float);

  /* print out the current reservation param element */
  /* place everything up to the node list */
  if (nppn == -1)
    {
    if (mppdepth == 0)
      {
      if (apbasil_protocol_float >= APBASIL_PROTOCOL_v13)
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_SANS_NPPN_13, width, nppcu);
      else
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_SANS_NPPN, width);
      }
    else
      {
      if (apbasil_protocol_float >= APBASIL_PROTOCOL_v13)
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_DEPTH_SANS_NPPN_13, width, nppcu, mppdepth);
      else
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_DEPTH_SANS_NPPN, width, mppdepth);
      }
    }
  else
    {
    if (mppdepth == 0)
      {
      if (apbasil_protocol_float >= APBASIL_PROTOCOL_v13)
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_13, width, nppcu, nppn);
      else
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN, width, nppn);
      }
    else
      {
      if (apbasil_protocol_float >= APBASIL_PROTOCOL_v13)
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_DEPTH_13, width, nppcu, nppn, mppdepth);
      else
        snprintf(buf, sizeof(buf), APBASIL_RESERVE_PARAM_BEGIN_DEPTH, width, nppn, mppdepth);
      }
    }

  rc = append_dynamic_string(command, buf);
  
  /* add the node list */
  if (rc == PBSE_NONE)
    append_dynamic_string(command, node_list->str);
  
  /* end the reserve param element */
  if (rc == PBSE_NONE)
    append_dynamic_string(command, APBASIL_RESERVE_PARAM_END);

  return(rc);
  } /* END save_current_reserve_param() */
Esempio n. 15
0
void account_jobend(

  job  *pjob,
  char *used) /* job usage information, see req_jobobit() */

  {
  dynamic_string     *ds;
  char                local_buf[MAXLINE * 4];
#ifdef USESAVEDRESOURCES
  pbs_attribute      *pattr;
  long                walltime_val = 0;
#else
  time_t              time_now = time(NULL);
#endif

  /* pack in general information about the job */
  if ((ds = get_dynamic_string(-1, NULL)) == NULL)
    return;

  if ((acct_job(pjob, ds)) != PBSE_NONE)
    {
    free_dynamic_string(ds);
    return;
    }

  /* session */
  sprintf(local_buf, "session=%ld ",
    pjob->ji_wattr[JOB_ATR_session_id].at_val.at_long);

  if (append_dynamic_string(ds, local_buf) != PBSE_NONE)
    {
    free_dynamic_string(ds);
    return;
    }

  /* Alternate id if present */
  if (pjob->ji_wattr[JOB_ATR_altid].at_flags & ATR_VFLAG_SET)
    {
    sprintf(local_buf, "alt_id=%s ",
      pjob->ji_wattr[JOB_ATR_altid].at_val.at_str);

    if (append_dynamic_string(ds, local_buf) != PBSE_NONE)
      {
      free_dynamic_string(ds);
      return;
      }
    }

  /* add the execution end time */
#ifdef USESAVEDRESOURCES
  pattr = &pjob->ji_wattr[JOB_ATR_resc_used];

  if (pattr->at_flags & ATR_VFLAG_SET)
    {
    resource *pres;
    char     *pname;

    pres = (resource *)GET_NEXT(pattr->at_val.at_list);
    
    /* find the walltime resource */
    for (;pres != NULL;pres = (resource *)GET_NEXT(pres->rs_link))
      {
      pname = pres->rs_defin->rs_name;
      
      if (strcmp(pname, "walltime") == 0)
        {
        /* found walltime */
        walltime_val = pres->rs_value.at_val.at_long;
        break;
        }
      }
    }
  sprintf(local_buf, "end=%ld ", (long)pjob->ji_qs.ji_stime + walltime_val);
#else
  sprintf(local_buf, "end=%ld ", (long)time_now);
#endif /* USESAVEDRESOURCES */

  if (append_dynamic_string(ds, local_buf) != PBSE_NONE)
    {
    free_dynamic_string(ds);
    return;
    }

  /* finally add on resources used from req_jobobit() */
  if (append_dynamic_string(ds, used) != PBSE_NONE)
    {
    free_dynamic_string(ds);
    return;
    }

  account_record(PBS_ACCT_END, pjob, ds->str);

  free_dynamic_string(ds);
  return;
  }  /* END account_jobend() */
int process_node(

  dynamic_string *status,
  xmlNode        *node)

  {
  char               *attr_value;
  char               *role_value;
  xmlNode            *child;
  xmlNode            *segments;
  xmlNode            *segment_child;
  dynamic_string     *features;
  char                buf[MAXLINE];
  int                 num_procs     = 0;
  int                 avail_procs   = 0;
  unsigned long       memory        = 0;
  unsigned long long  mem_kb;
  char               *rsv_id        = NULL;

  if ((features = get_dynamic_string(-1, NULL)) == NULL)
    return(ENOMEM);

  copy_to_end_of_dynamic_string(status, "node=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)node_id);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  /* check to see if the role is interactive - report these as down */
  role_value = (char *)xmlGetProp(node, (const xmlChar *)role);

  copy_to_end_of_dynamic_string(status, "ARCH=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)architecture);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  copy_to_end_of_dynamic_string(status, "name=");
  attr_value = (char *)xmlGetProp(node, (const xmlChar *)name);
  append_dynamic_string(status, attr_value);
  free(attr_value);

  /* process the children */
  for (child = node->children; child != NULL; child = child->next)
    {
    if (!strcmp((const char *)child->name, segment_array))
      {
      for (segments = child->children; segments != NULL; segments = segments->next)
        {
        for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next)
          {
          if (!strcmp((const char *)segment_child->name, processor_array))
            process_processor_array(segment_child, &num_procs, &avail_procs, &rsv_id);
          else if (!strcmp((const char *)segment_child->name, memory_array))
            process_memory_array(segment_child, &memory);
          else if (!strcmp((const char *)segment_child->name, label_array))
            process_label_array(features, segment_child);
          }
        }
      }
    else if (!strcmp((const char *)child->name, processor_array))
      {
      process_processor_array(child, &num_procs, &avail_procs, &rsv_id);
      }
    else if (!strcmp((const char *)child->name, memory_array))
      {
      process_memory_array(child, &memory);
      }
    else if (!strcmp((const char *)child->name, label_array))
      {
      process_label_array(features, child);
      }
    else if (!strcmp((const char *)child->name, accelerator_array))
      {
      process_accelerator_array(status, child);
      }
    } /* END the loop for processing the children */

  /* once done, add the procs, available procs, memory info, reservation, and features */
  snprintf(buf, sizeof(buf), "CPROC=%d", num_procs);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "APROC=%d", avail_procs);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "CMEMORY=%lu", memory);
  copy_to_end_of_dynamic_string(status, buf);

  mem_kb = memory * 1024;

  snprintf(buf, sizeof(buf), "totmem=%llukb", mem_kb);
  copy_to_end_of_dynamic_string(status, buf);

  snprintf(buf, sizeof(buf), "physmem=%llukb", mem_kb);
  copy_to_end_of_dynamic_string(status, buf);

  if (rsv_id != NULL)
    {
    /* don't write the reservation id if we're in interactive mode */
    if ((role_value == NULL) ||
        (strcmp(role_value, interactive_caps)))
      {
      copy_to_end_of_dynamic_string(status, "reservation_id=");
      append_dynamic_string(status, rsv_id);
      }

    free(rsv_id);

    /* if there's a reservation on this node, the state is busy */
    copy_to_end_of_dynamic_string(status, "state=BUSY");
    
    snprintf(buf, sizeof(buf), "availmem=0kb");
    copy_to_end_of_dynamic_string(status, buf);
    }
  else
    {
    /* no reservation, evaluate the state normally */
    copy_to_end_of_dynamic_string(status, "state=");
    attr_value = (char *)xmlGetProp(node, (const xmlChar *)state);
    
    if ((role_value != NULL) &&
        (!strcmp(role_value, interactive_caps)))
      {
      append_dynamic_string(status, "DOWN");
      
      snprintf(buf, sizeof(buf), "availmem=0kb");
      copy_to_end_of_dynamic_string(status, buf);
      }
    else
      {
      append_dynamic_string(status, attr_value);
     
      snprintf(buf, sizeof(buf), "availmem=%llukb", mem_kb);
      copy_to_end_of_dynamic_string(status, buf);
      }

    free(attr_value);
    }

  if (role_value != NULL)
    free(role_value);

  if (features->used > 0)
    {
    copy_to_end_of_dynamic_string(status, "feature_list=");
    append_dynamic_string(status, features->str);
    }

  free_dynamic_string(features);

  return(PBSE_NONE);
  } /* END process_node() */
int generate_alps_status(

  dynamic_string *status,
  const char     *apbasil_path,
  const char     *apbasil_protocol)

  {
  FILE           *alps_pipe;
  int             fd;
  int             rc;
  int             bytes_read;
  int             total_bytes_read = 0;
  char            inventory_command[MAXLINE * 2];
  char            input_buffer[MAXLINE];
  char           *ptr;
  dynamic_string *alps_output;

  if ((alps_output = get_dynamic_string(-1, NULL)) == NULL)
    return(ENOMEM);

  snprintf(inventory_command, sizeof(inventory_command), APBASIL_QUERY,
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL,
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);

  if ((alps_pipe = popen(inventory_command, "r")) == NULL)
    {
    snprintf(log_buffer, sizeof(log_buffer),
      "Unable to open command %s for apbasil",
      inventory_command);
    log_err(errno, __func__, log_buffer);

    return(WRITING_PIPE_ERROR);
    }

  fd = fileno(alps_pipe);

  /* now read from the pipe */
  ptr = input_buffer;
  memset(input_buffer, 0, sizeof(input_buffer));

  while ((bytes_read = read(fd, ptr, sizeof(input_buffer) - 1)) > 0)
    {
    append_dynamic_string(alps_output, ptr);
    memset(input_buffer, 0, sizeof(input_buffer));
    total_bytes_read += bytes_read;
    }

  /* perform post-processing */
  pclose(alps_pipe);

  if ((bytes_read == -1) ||
      (total_bytes_read == 0))
    rc = READING_PIPE_ERROR;
  else
    {
    int index = alps_output->used - 1;
    while (alps_output->str[index] != '>')
      {
      alps_output->str[index] = '\0';
      index--;
      }

    alps_output->used -= 1;
    rc = parse_alps_output(alps_output, status);
    }

  free_dynamic_string(alps_output);

  return(rc);
  } /* END generate_alps_status() */
Esempio n. 18
0
int process_gpu_status(

  struct pbsnode  *pnode,
  char           **str_ptr)

  {
  char           *str = *str_ptr;
  pbs_attribute   temp;
  int             gpu_count = 0;
  int             rc;
  char            buf[MAXLINE * 2];
  dynamic_string *gpu_info;

  memset(&temp, 0, sizeof(temp));
  
  if ((gpu_info = get_dynamic_string(-1, NULL)) == NULL)
    {
    *str_ptr = finish_gpu_status(str);

    return(ENOMEM);
    }

  if ((rc = decode_arst(&temp, NULL, NULL, NULL, 0)) != PBSE_NONE)
    {
    log_record(PBSEVENT_DEBUG, PBS_EVENTCLASS_NODE, __func__, "cannot initialize attribute");

    *str_ptr = finish_gpu_status(str);
    free_dynamic_string(gpu_info);

    return(rc);
    }

  /* move past the initial gpu status */
  str += strlen(str) + 1;
  
  for (; str != NULL && *str != '\0'; str += strlen(str) + 1)
    {
    if (!strcmp(str, CRAY_GPU_STATUS_END))
      break;

    if (!strncmp(str, "gpu_id=", strlen("gpu_id=")))
      {
      snprintf(buf, sizeof(buf), "gpu[%d]=%s;", gpu_count, str);
      rc = append_dynamic_string(gpu_info, buf);
      gpu_count++;
      }
    else
      {
      rc = append_dynamic_string(gpu_info, str);
      rc = append_char_to_dynamic_string(gpu_info, ';');
      }

    if (rc != PBSE_NONE)
      {
      free_dynamic_string(gpu_info);

      *str_ptr = finish_gpu_status(str);

      return(rc);
      }
    }

  set_ngpus(pnode, gpu_count);
  decode_arst(&temp, NULL, NULL, gpu_info->str, 0);
  node_gpustatus_list(&temp, pnode, ATR_ACTION_ALTER);
  
  free_arst(&temp);
  free_dynamic_string(gpu_info);

  *str_ptr = str;

  return(PBSE_NONE);
  } /* END process_gpu_status() */
Esempio n. 19
0
int acct_job(

  job            *pjob, /* I */
  dynamic_string *ds)   /* O */

  {
  int         rc;
  long        cray_enabled = FALSE;
  int         resc_access_perm = READ_ONLY;
  char        local_buf[MAXLINE*4];
  pbs_queue  *pque;

  tlist_head  attrlist;
  svrattrl   *pal;

  if (pjob == NULL)
    {
    return(PBSE_NONE);
    }

  CLEAR_HEAD(attrlist);

  /* user */

	/* acct_job is only called from account_jobstr and account_jobend. BufSize should be
	 	 PBS_ACCT_MAX_RCD + 1 in size. */
  sprintf(local_buf, "user=%s ",
    pjob->ji_wattr[JOB_ATR_euser].at_val.at_str);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* group */
  sprintf(local_buf, "group=%s ",
    pjob->ji_wattr[JOB_ATR_egroup].at_val.at_str);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* account */
  if (pjob->ji_wattr[JOB_ATR_account].at_flags & ATR_VFLAG_SET)
    {
    sprintf(local_buf, "account=%s ",
      pjob->ji_wattr[JOB_ATR_account].at_val.at_str);
    if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
      return(rc);
    }

  /* job name */
  sprintf(local_buf, "jobname=%s ",
    pjob->ji_wattr[JOB_ATR_jobname].at_val.at_str);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  if ((pque = get_jobs_queue(&pjob)) != NULL)
    {
    /* queue name */
    sprintf(local_buf, "queue=%s ", pque->qu_qs.qu_name);
    unlock_queue(pque, __func__, NULL, LOGLEVEL);

    if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
      return(rc);
    }
  else if (pjob == NULL)
    {
    log_err(PBSE_JOBNOTFOUND, __func__, "Job lost while acquiring queue 1");
    return(PBSE_JOBNOTFOUND);
    }

  /* create time */
  sprintf(local_buf, "ctime=%ld ",
    pjob->ji_wattr[JOB_ATR_ctime].at_val.at_long);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* queued time */
  sprintf(local_buf, "qtime=%ld ",
    pjob->ji_wattr[JOB_ATR_qtime].at_val.at_long);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* eligible time, how long ready to run */
  sprintf(local_buf, "etime=%ld ",
    pjob->ji_wattr[JOB_ATR_etime].at_val.at_long);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* execution start time */
  sprintf(local_buf, "start=%ld ",
    (long)pjob->ji_qs.ji_stime);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);

  /* user */
  sprintf(local_buf, "owner=%s ",
    pjob->ji_wattr[JOB_ATR_job_owner].at_val.at_str);
  if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
    return(rc);
 
  /* For large clusters strings can get pretty long. We need to see if there
     is a need to allocate a bigger buffer */
  /* execution host name */
  if (pjob->ji_wattr[JOB_ATR_exec_host].at_val.at_str != NULL)
    {
    append_dynamic_string(ds, "exec_host=");
    append_dynamic_string(ds, pjob->ji_wattr[JOB_ATR_exec_host].at_val.at_str);
    if ((rc = append_dynamic_string(ds, " ")) != PBSE_NONE)
      return(rc);
    }

  get_svr_attr_l(SRV_ATR_CrayEnabled, &cray_enabled);
  if ((cray_enabled == TRUE) &&
      (pjob->ji_wattr[JOB_ATR_login_node_id].at_flags & ATR_VFLAG_SET))
    {
    append_dynamic_string(ds, "login_node=");
    append_dynamic_string(ds, pjob->ji_wattr[JOB_ATR_login_node_id].at_val.at_str);
    if ((rc = append_dynamic_string(ds, " ")) != PBSE_NONE)
      return(rc);
    }

  /* now encode the job's resource_list pbs_attribute */
  job_attr_def[JOB_ATR_resource].at_encode(
    &pjob->ji_wattr[JOB_ATR_resource],
    &attrlist,
    job_attr_def[JOB_ATR_resource].at_name,
    NULL,
    ATR_ENCODE_CLIENT,
    resc_access_perm);

  while ((pal = GET_NEXT(attrlist)) != NULL)
    {
		/* exec_host can use a lot of buffer space. Use a dynamic string */
    append_dynamic_string(ds, pal->al_name);

    if (pal->al_resc != NULL)
      {
      append_dynamic_string(ds, ".");
      append_dynamic_string(ds, pal->al_resc);
      }

    append_dynamic_string(ds, "=");
    append_dynamic_string(ds, pal->al_value);
    if ((rc = append_dynamic_string(ds, " ")) != PBSE_NONE)
      return(rc);

    delete_link(&pal->al_link);
    free(pal);
    }  /* END while (pal != NULL) */

#ifdef ATTR_X_ACCT

  /* x attributes */
  if (pjob->ji_wattr[JOB_SITE_ATR_x].at_flags & ATR_VFLAG_SET)
    {
    sprintf(local_buf, "x=%s ",
            pjob->ji_wattr[JOB_SITE_ATR_x].at_val.at_str);
    if ((rc = append_dynamic_string(ds, local_buf)) != PBSE_NONE)
      return(rc);
    }

#endif

  /* SUCCESS */

  return(PBSE_NONE);
  }  /* END acct_job() */
Esempio n. 20
0
int process_mic_status(
    
  struct pbsnode  *pnode, 
  char           **str_ptr)

  {
  char           *str = *str_ptr;
  int             rc = PBSE_NONE;
  pbs_attribute   temp;
  int             mic_count = 0;
  dynamic_string *single_mic_status = get_dynamic_string(-1, NULL);
  char            mic_id_buf[MAXLINE];
  
  memset(&temp, 0, sizeof(temp));
  if ((rc = decode_arst(&temp, NULL, NULL, NULL, 0)) != PBSE_NONE)
    {
    log_record(PBSEVENT_DEBUG, PBS_EVENTCLASS_NODE, __func__, "cannot initialize attribute");
    *str_ptr = move_past_mic_status(str);
    return(rc);
    }

  for (str = str + strlen(str) + 1; str != NULL && str[0] != '\0'; str += strlen(str) + 1)
    {
    if (!strcmp(str, END_MIC_STATUS))
      break;

    if (!strncmp(str, "mic_id=", strlen("mic_id=")))
      {
      if ((rc = save_single_mic_status(single_mic_status, &temp)) != PBSE_NONE)
        break;

      snprintf(mic_id_buf, sizeof(mic_id_buf), "mic[%d]=%s", mic_count, str);
      append_dynamic_string(single_mic_status, mic_id_buf);

      mic_count++;
      }
    else
      {
      append_char_to_dynamic_string(single_mic_status, ';');
      append_dynamic_string(single_mic_status, str);
      }
    }

  rc = save_single_mic_status(single_mic_status, &temp);

  if (mic_count > pnode->nd_nmics)
    {
    pnode->nd_nmics_free += mic_count - pnode->nd_nmics;
    pnode->nd_nmics = mic_count;

    if (mic_count > pnode->nd_nmics_alloced)
      {
      struct jobinfo *tmp = (struct jobinfo *)calloc(mic_count, sizeof(struct jobinfo));
      
      if (tmp == NULL)
        return(ENOMEM);

      memcpy(tmp, pnode->nd_micjobs, sizeof(struct jobinfo) * pnode->nd_nmics_alloced);
      free(pnode->nd_micjobs);
      pnode->nd_micjobs = tmp;

      pnode->nd_nmics_alloced = mic_count;
      }
    }

  *str_ptr = move_past_mic_status(str);
  
  node_micstatus_list(&temp, pnode, ATR_ACTION_ALTER);

  return(rc);
  } /* END process_mic_status() */