Ejemplo n.º 1
0
/*
 * Now that an option and its argument have been read, validate them and
 * set the appropriate global configuration variables.
 */
static int
set_cfg_opt(char *cfg_option, char *cfg_arg)
  {
  char   *id = "set_cfg_opt";

  /* XXX Should smash case on these before doing string compares? */

  if (!strcmp(cfg_option, "TARGET_LOAD_PCT"))
    {
    schd_TARGET_LOAD_PCT = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "TARGET_LOAD_VARIANCE"))
    {
    return (get_variance(cfg_arg,
                         &schd_TARGET_LOAD_MINUS, &schd_TARGET_LOAD_PLUS));
    }

  if (!strcmp(cfg_option, "HIGH_SYSTIME"))
    {
    schd_HIGH_SYSTIME = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "MAX_JOBS"))
    {
    schd_MAX_JOBS = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "MIN_JOBS"))
    {
    schd_MIN_JOBS = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "MAX_DEDICATED_JOBS"))
    {
    schd_MAX_DEDICATED_JOBS = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "MAX_USER_RUN_JOBS"))
    {
    schd_MAX_USER_RUN_JOBS = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "ENFORCE_ALLOCATION"))
    {
    return schd_val2booltime(cfg_arg, &schd_ENFORCE_ALLOCATION);
    }

  if (!strcmp(cfg_option, "TEST_ONLY"))
    {
    return schd_val2bool(cfg_arg, &schd_TEST_ONLY);
    }

  if (!strcmp(cfg_option, "ENFORCE_DEDICATED_TIME"))
    {
    return schd_val2booltime(cfg_arg, &schd_ENFORCE_DEDTIME);
    }

  if (!strcmp(cfg_option, "DEDICATED_TIME_COMMAND"))
    {
    if (schd_DEDTIME_COMMAND)
      free(schd_DEDTIME_COMMAND);

    schd_DEDTIME_COMMAND = schd_strdup(cfg_arg);

    if (schd_DEDTIME_COMMAND == NULL)
      {
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                 "schd_strdup(schd_DEDTIME_COMMAND)");
      return (-1);
      }

    return (0);
    }

  if (!strcmp(cfg_option, "DEDICATED_TIME_CACHE_SECS"))
    {
    schd_DEDTIME_CACHE_SECS = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "DECAY_FACTOR"))
    {
    schd_DECAY_FACTOR = atof(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "OA_DECAY_FACTOR"))
    {
    schd_OA_DECAY_FACTOR = atof(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "SCHED_ACCT_DIR"))
    {
    if (schd_SCHED_ACCT_DIR)
      free(schd_SCHED_ACCT_DIR);

    schd_SCHED_ACCT_DIR = schd_strdup(cfg_arg);

    if (schd_SCHED_ACCT_DIR == NULL)
      {
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                 "schd_strdup(schd_SCHED_ACCT_DIR)");
      return (-1);
      }

    return (0);
    }

  if (!strcmp(cfg_option, "SYSTEM_NAME"))
    {
    if (schd_SYSTEM_NAME)
      free(schd_SYSTEM_NAME);

    schd_SYSTEM_NAME = schd_strdup(cfg_arg);

    schd_lowercase(schd_SYSTEM_NAME);

    return (0);
    }

  if (!strcmp(cfg_option, "SERVER_HOST"))
    {
    if (schd_SERVER_HOST)
      free(schd_SERVER_HOST);

    schd_SERVER_HOST = schd_strdup(cfg_arg);

    if (schd_SERVER_HOST == NULL)
      {
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                 "schd_strdup(schd_SERVER_HOST)");
      return (-1);
      }

    schd_lowercase(schd_SERVER_HOST);

    return (0);
    }

  if (!strcmp(cfg_option, "SCHED_HOST"))
    {
    if (schd_SCHED_HOST)
      free(schd_SCHED_HOST);

    schd_SCHED_HOST = schd_strdup(cfg_arg);

    if (schd_SCHED_HOST == NULL)
      {
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                 "schd_strdup(schd_SCHED_HOST)");
      return (-1);
      }

    schd_lowercase(schd_SCHED_HOST);

    return (0);
    }

  if (!strcmp(cfg_option, "SORTED_JOB_DUMPFILE"))
    {
    if (schd_JOB_DUMPFILE)
      free(schd_JOB_DUMPFILE);

    schd_JOB_DUMPFILE = schd_strdup(cfg_arg);

    if (schd_JOB_DUMPFILE == NULL)
      {
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                 "schd_strdup(schd_JOB_DUMPFILE)");
      return (-1);
      }

    return (0);
    }

  if (!strcmp(cfg_option, "SCHED_RESTART_ACTION"))
    {
    if (strcmp(cfg_arg, "NONE") == 0)
      {
      schd_SCHED_RESTART_ACTION = SCHD_RESTART_NONE;
      return (0);
      }

    if (strcmp(cfg_arg, "RESUBMIT") == 0)
      {
      schd_SCHED_RESTART_ACTION = SCHD_RESTART_RESUBMIT;
      return (0);
      }

    if (strcmp(cfg_arg, "RERUN") == 0)
      {
      schd_SCHED_RESTART_ACTION = SCHD_RESTART_RERUN;
      return (0);
      }

    return (-1);  /* Bad argument */
    }

  if (!strcmp(cfg_option, "SORT_BY_PAST_USAGE"))
    {
    return schd_val2bool(cfg_arg, &schd_SORT_BY_PAST_USAGE);
    }

  if (!strcmp(cfg_option, "ENFORCE_PRIME_TIME"))
    {
    return schd_val2booltime(cfg_arg, &schd_ENFORCE_PRIME_TIME);
    }

  if (!strcmp(cfg_option, "PRIME_TIME_START"))
    {
    schd_PRIME_TIME_START = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "PRIME_TIME_END"))
    {
    schd_PRIME_TIME_END = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "PRIME_TIME_SMALL_NODE_LIMIT"))
    {
    schd_PT_SMALL_NODE_LIMIT = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "PRIME_TIME_SMALL_WALLT_LIMIT"))
    {
    schd_PT_SMALL_WALLT_LIMIT = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "PRIME_TIME_WALLT_LIMIT"))
    {
    schd_PT_WALLT_LIMIT = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "NONPRIME_DRAIN_SYS"))
    {
    return schd_val2bool(cfg_arg, &schd_NONPRIME_DRAIN_SYS);
    }

  if (!strcmp(cfg_option, "NP_DRAIN_BACKTIME"))
    {
    schd_NP_DRAIN_BACKTIME = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "NP_DRAIN_IDLETIME"))
    {
    schd_NP_DRAIN_IDLETIME = schd_val2sec(cfg_arg);
    return (0);
    }


  if (!strcmp(cfg_option, "SMALL_JOB_MAX"))
    {
    schd_SMALL_JOB_MAX = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "WALLT_LIMIT_LARGE_JOB"))
    {
    schd_WALLT_LARGE_LIMIT = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "WALLT_LIMIT_SMALL_JOB"))
    {
    schd_WALLT_SMALL_LIMIT = schd_val2sec(cfg_arg);
    return (0);
    }


  if (!strcmp(cfg_option, "MAX_QUEUED_TIME"))
    {
    schd_MAX_QUEUED_TIME = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "SMALL_QUEUED_TIME"))
    {
    schd_SMALL_QUEUED_TIME = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "INTERACTIVE_LONG_WAIT"))
    {
    schd_INTERACTIVE_LONG_WAIT = schd_val2sec(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "SUBMIT_QUEUE"))
    {
    arg_to_qlist(cfg_arg, ",", &schd_SubmitQueue);
    return (0);
    }

  if (!strcmp(cfg_option, "BATCH_QUEUES"))
    {
    arg_to_qlist(cfg_arg, ",", &schd_BatchQueues);
    return (0);
    }

  if (!strcmp(cfg_option, "SPECIAL_QUEUE"))
    {
    arg_to_qlist(cfg_arg, ",", &schd_SpecialQueue);
    return (0);
    }

  if (!strcmp(cfg_option, "DEDICATED_QUEUES"))
    {
    arg_to_qlist(cfg_arg, ",", &schd_DedQueues);
    return (0);
    }

  if (!strcmp(cfg_option, "EXTERNAL_QUEUES"))
    {
    arg_to_qlist(cfg_arg, ",", &schd_ExternQueues);
    return (0);
    }

  if (!strcmp(cfg_option, "FAKE_MACHINE_MULT"))
    {
    schd_FAKE_MACH_MULT = atoi(cfg_arg);
    return (0);
    }

  if (!strcmp(cfg_option, "AVOID_FRAGMENTATION"))
    {
    return schd_val2bool(cfg_arg, &schd_AVOID_FRAGS);
    }

  if (!strcmp(cfg_option, "MANAGE_HPM_COUNTERS"))
    {
    return schd_val2bool(cfg_arg, &schd_MANAGE_HPM);
    }

  if (!strcmp(cfg_option, "REVOKE_HPM_COUNTERS"))
    {
    return schd_val2bool(cfg_arg, &schd_REVOKE_HPM);
    }

  /* Unknown option -- return an error. */
  return (-1);
  }
Ejemplo n.º 2
0
/*ARGSUSED*/
int
schedinit(int argc, char *argv[])
  {
  char   *id = "schedinit";

  struct utsname name;

  struct sigaction act, oact;
  char   *ptr, canon[PBS_MAXHOSTNAME + 1];

  DBPRT(("\n%s\n", schd_VersionString));
  log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
             schd_VersionString);

  /*
   * If this is the initial startup configuration, then schd_TimeNow will
   * be 0.  Initialize it to the current time, so it can be tested against
   * various times when initializing.
   */

  if (schd_TimeNow == 0)
    {
    schd_TimeNow = time(NULL);
    DBPRT(("%s: initialize/startup at %s", id, ctime(&schd_TimeNow)));
    }

  /*
   * Determine location of configuration file.  Check for the presence of
   * the PBSSCHED_CONFIG environment variable.  If not defined, fall back
   * to the compiled default CONFIGFILE.
   *
   * Since neither the environment variables nor the compiled-in default
   * can be changed (with the exception of someone wreaking havoc with
   * a debugger or something), this only needs to be done once.
   */
  if (schd_CfgFilename == NULL)
    {
    ptr = getenv("PBSSCHED_CONFIG");

    if (ptr == NULL)
      ptr = CONFIGFILE;

    schd_CfgFilename = schd_strdup(ptr);

    if (schd_CfgFilename == NULL)
      {
      (void)sprintf(log_buffer, "schd_strdup() failed for configfile");
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
      DBPRT(("%s: %s\n", id, log_buffer));
      return (-1);
      }

    }

  /*
   * From this point on, goto cleanup_and_error: to clean up any allocated
   * storage for filenames.
   */

  DBPRT(("SCHEDINIT: Reading configuration from '%s'\n", schd_CfgFilename));

  /* Reset the configuration to a "known" state. */
  reset_config();

  /* Determine on what host this scheduler running. */
  uname(&name);

  if (get_fullhostname(name.nodename, canon, PBS_MAXHOSTNAME) == 0)
    {
    strncpy(schd_ThisHost, canon, PBS_MAXHOSTNAME);
    }
  else
    {
    (void)sprintf(log_buffer,
                  "Failed to canonicalize uname %s (using it anyway)",
                  name.nodename);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    strncpy(schd_ThisHost, name.nodename, PBS_MAXHOSTNAME);
    }

  schd_lowercase(schd_ThisHost);

  DBPRT(("%s: This host is '%s'\n", id, schd_ThisHost));

  /*
   * Register the state of the config file.  The call to reset_config()
   * above will have cleared all file watches.
   */

  if (schd_register_file(schd_CfgFilename))
    {
    (void)sprintf(log_buffer, "cannot watch %s", schd_CfgFilename);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    goto cleanup_and_error;
    }

  /* Read the configuration file. */
  if (schd_get_config(schd_CfgFilename))
    return (-1);


  /* if we are NOT making a distinction between Prime and Non-Prime Time,
   * then simply empty the holidays array; otherwise, try to read and load
   * the holidays file.
   */
  if (!schd_ENFORCE_PRIME_TIME)
    init_holidays();
  else
    {
    /*
     * Register the state of the holidays file.  This allows schd_req() to
     * reload it if it is changed.
     */
    if (schd_register_file(HOLIDAYS_FILE))
      {
      (void)sprintf(log_buffer, "cannot watch %s", HOLIDAYS_FILE);
      log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
      DBPRT(("%s: %s\n", id, log_buffer));

      goto cleanup_and_error;
      }

    /* Get a list of prime/non-prime times from the holidays file */
    if (schd_read_holidays() < 0)
      return (-1);
    }

  /*
   * Set up a signal handler for SIGHUP.  catch_HUP() will re-read the
   * configuration file.
   */
  act.sa_flags   = 0;

  act.sa_handler = catch_HUP;

  sigemptyset(&act.sa_mask);

  if (sigaction(SIGHUP, &act, &oact))
    {
    (void)sprintf(log_buffer, "Failed to setup SIGHUP handler.");
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    }

  DBPRT(("SCHEDINIT: configuration complete.\n"));

  return (0);

cleanup_and_error:

  /*
   * Some error occurred.  Remove watches and free the storage allocated
   * for the filenames.
   */

  if (schd_CfgFilename)
    {
    schd_forget_file(schd_CfgFilename);
    free(schd_CfgFilename);
    }

  schd_CfgFilename     = NULL;

  return (-1);
  }