/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { char *env_val = NULL; int opt_char; int option_index; hostlist_t host_list; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bg", no_argument, 0, 'b'}, {"dead", no_argument, 0, 'd'}, {"exact", no_argument, 0, 'e'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"Node", no_argument, 0, 'N'}, {"format", required_argument, 0, 'o'}, {"partition", required_argument, 0, 'p'}, {"responding",no_argument, 0, 'r'}, {"list-reasons", no_argument, 0, 'R'}, {"summarize", no_argument, 0, 's'}, {"sort", required_argument, 0, 'S'}, {"states", required_argument, 0, 't'}, {"reservation",no_argument, 0, 'T'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {NULL, 0, 0, 0} }; if (getenv("SINFO_ALL")) params.all_flag = true; if ( ( env_val = getenv("SINFO_PARTITION") ) ) { params.partition = xstrdup(env_val); params.all_flag = true; } if ( ( env_val = getenv("SINFO_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { print_db_notok(env_val, 1); exit(1); } working_cluster_rec = list_peek(params.clusters); } while((opt_char = getopt_long(argc, argv, "abdehi:lM:n:No:p:rRsS:t:TvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sinfo --help\" for more information\n"); exit(1); break; case (int)'a': params.all_flag = true; break; case (int)'b': params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.cluster_flags & CLUSTER_FLAG_BG) params.bg_flag = true; else { error("Must be on a BG system to use --bg " "option, if using --cluster option " "put the --bg option " "after the --cluster option."); exit(1); } break; case (int)'d': params.dead_nodes = true; break; case (int)'e': params.exact_match = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("Error: invalid entry for " "--iterate=%s", optarg); exit(1); } break; case (int) 'l': params.long_output = true; break; case (int) 'M': if (params.clusters) list_destroy(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int) 'n': xfree(params.nodes); params.nodes = xstrdup(optarg); /* * confirm valid nodelist entry */ host_list = hostlist_create(params.nodes); if (!host_list) { error("'%s' invalid entry for --nodes", optarg); exit(1); } if (hostlist_count(host_list) == 1) params.node_name_single = true; else params.node_name_single = false; hostlist_destroy(host_list); break; case (int) 'N': params.node_flag = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'p': xfree(params.partition); params.partition = xstrdup(optarg); params.all_flag = true; break; case (int) 'r': params.responding_nodes = true; break; case (int) 'R': params.list_reasons = true; break; case (int) 's': params.summarize = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); if (!(params.state_list = _build_state_list(optarg))) { error ("valid states: %s", _node_state_list ()); exit (1); } break; case (int) 'T': params.reservation_flag = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; } } params.cluster_flags = slurmdb_setup_cluster_flags(); if ( params.format == NULL ) { if ( params.summarize ) { params.part_field_flag = true; /* compute size later */ if (params.cluster_flags & CLUSTER_FLAG_BG) params.format = "%9P %.5a %.10l %.32F %N"; else params.format = "%9P %.5a %.10l %.16F %N"; } else if ( params.node_flag ) { params.node_field_flag = true; /* compute size later */ params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%N %.6D %.9P %.11T %.4c %.8z %.6m %.8d %.6w %.8f %20E" : "%N %.6D %.9P %6t"; } else if (params.list_reasons) { params.format = params.long_output ? "%20E %12U %19H %6t %N" : "%20E %9u %19H %N"; } else if ((env_val = getenv ("SINFO_FORMAT"))) { params.format = xstrdup(env_val); } else { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %.5a %.10l %.10s %.4r %.5h %.10g %.6D %.11T %N" : "%9P %.5a %.10l %.6D %.6t %N"; } } _parse_format( params.format ); if (params.list_reasons && (params.state_list == NULL)) { params.states = xstrdup ("down,drain,error"); if (!(params.state_list = _build_state_list (params.states))) fatal ("Unable to build state list for -R!"); } if (params.dead_nodes || params.nodes || params.partition || params.responding_nodes ||params.state_list) params.filtering = true; if (params.verbose) _print_options(); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char **argv) { char *env_val = NULL; int opt_char; int option_index; hostlist_t host_list; bool long_form = false; bool opt_a_set = false, opt_p_set = false; bool env_a_set = false, env_p_set = false; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bg", no_argument, 0, 'b'}, {"dead", no_argument, 0, 'd'}, {"exact", no_argument, 0, 'e'}, {"federation",no_argument, 0, OPT_LONG_FEDR}, {"help", no_argument, 0, OPT_LONG_HELP}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {"iterate", required_argument, 0, 'i'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"noconvert", no_argument, 0, OPT_LONG_NOCONVERT}, {"noheader", no_argument, 0, 'h'}, {"Node", no_argument, 0, 'N'}, {"format", required_argument, 0, 'o'}, {"Format", required_argument, 0, 'O'}, {"partition", required_argument, 0, 'p'}, {"responding",no_argument, 0, 'r'}, {"list-reasons", no_argument, 0, 'R'}, {"summarize", no_argument, 0, 's'}, {"sort", required_argument, 0, 'S'}, {"states", required_argument, 0, 't'}, {"reservation",no_argument, 0, 'T'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; params.convert_flags = CONVERT_NUM_UNIT_EXACT; if (slurmctld_conf.fed_params && strstr(slurmctld_conf.fed_params, "fed_display")) params.federation_flag = true; if (getenv("SINFO_ALL")) { env_a_set = true; params.all_flag = true; } if (getenv("SINFO_FEDERATION")) params.federation_flag = true; if (getenv("SINFO_LOCAL")) params.local = true; if ( ( env_val = getenv("SINFO_PARTITION") ) ) { env_p_set = true; params.partition = xstrdup(env_val); params.part_list = _build_part_list(env_val); params.all_flag = true; } if (env_a_set && env_p_set) { error("Conflicting options, SINFO_ALL and SINFO_PARTITION, specified. " "Please choose one or the other."); exit(1); } if ( ( env_val = getenv("SINFO_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { print_db_notok(env_val, 1); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local = true; } while ((opt_char = getopt_long(argc, argv, "abdehi:lM:n:No:O:p:rRsS:t:TvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sinfo --help\" for more information\n"); exit(1); break; case (int)'a': opt_a_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.all_flag = true; break; case (int)'b': params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.cluster_flags & CLUSTER_FLAG_BG) params.bg_flag = true; else { error("Must be on a BG system to use --bg " "option, if using --cluster option " "put the --bg option " "after the --cluster option."); exit(1); } break; case (int)'d': params.dead_nodes = true; break; case (int)'e': params.exact_match = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("Error: invalid entry for " "--iterate=%s", optarg); exit(1); } break; case (int) 'l': params.long_output = true; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local = true; break; case OPT_LONG_NOCONVERT: params.convert_flags |= CONVERT_NUM_UNIT_NO; break; case (int) 'n': xfree(params.nodes); params.nodes = xstrdup(optarg); /* * confirm valid nodelist entry */ host_list = hostlist_create(params.nodes); if (!host_list) { error("'%s' invalid entry for --nodes", optarg); exit(1); } if (hostlist_count(host_list) == 1) { params.node_name_single = true; xfree(params.nodes); params.nodes = hostlist_deranged_string_xmalloc(host_list); } else params.node_name_single = false; hostlist_destroy(host_list); break; case (int) 'N': params.node_flag = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'O': long_form = true; xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'p': opt_p_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.partition = xstrdup(optarg); params.part_list = _build_part_list(optarg); params.all_flag = true; break; case (int) 'r': params.responding_nodes = true; break; case (int) 'R': params.list_reasons = true; break; case (int) 's': params.summarize = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); if (!(params.state_list = _build_state_list(optarg))) { error ("valid states: %s", _node_state_list ()); exit (1); } break; case (int) 'T': params.reservation_flag = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) OPT_LONG_FEDR: params.federation_flag = true; break; case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_LOCAL: params.local = true; break; } } if (opt_a_set && opt_p_set) { error("Conflicting options, -a and -p, specified. " "Please choose one or the other."); exit(1); } params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.federation_flag && !params.clusters && !params.local) { void *ptr = NULL; char *cluster_name = slurm_get_cluster_name(); if (slurm_load_federation(&ptr) || !cluster_in_federation(ptr, cluster_name)) { /* Not in federation */ params.local = true; slurm_destroy_federation_rec(ptr); } else { params.fed = (slurmdb_federation_rec_t *) ptr; } xfree(cluster_name); } if ( params.format == NULL ) { if ( params.summarize ) { params.part_field_flag = true; /* compute size later */ if (params.cluster_flags & CLUSTER_FLAG_BG) params.format = "%9P %.5a %.10l %.32F %N"; else params.format = "%9P %.5a %.10l %.16F %N"; } else if ( params.node_flag ) { params.node_field_flag = true; /* compute size later */ params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%N %.6D %.9P %.11T %.4c %.8z %.6m %.8d %.6w %.8f %20E" : "%N %.6D %.9P %6t"; } else if (params.list_reasons) { params.format = params.long_output ? "%20E %12U %19H %6t %N" : "%20E %9u %19H %N"; } else if ((env_val = getenv ("SINFO_FORMAT"))) { params.format = xstrdup(env_val); } else if (params.fed) { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %8V %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %8V %.5a %.10l %.6D %.6t %N"; } else { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %.5a %.10l %.6D %.6t %N"; } } if (long_form) _parse_long_format(params.format); else _parse_format(params.format); if (params.list_reasons && (params.state_list == NULL)) { params.states = xstrdup ("down,drain,error"); if (!(params.state_list = _build_state_list (params.states))) fatal ("Unable to build state list for -R!"); } if (params.dead_nodes || params.nodes || params.partition || params.responding_nodes ||params.state_list) params.filtering = true; if (params.verbose) _print_options(); }
/* * opt_args() : set options via commandline args and getopt_long */ static void _opt_args(int argc, char **argv) { int opt_char; int option_index; static struct option long_options[] = { {"account", required_argument, 0, 'A'}, {"batch", no_argument, 0, 'b'}, {"ctld", no_argument, 0, OPT_LONG_CTLD}, {"help", no_argument, 0, OPT_LONG_HELP}, {"interactive", no_argument, 0, 'i'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"name", required_argument, 0, 'n'}, {"nodelist", required_argument, 0, 'w'}, {"partition", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"quiet", no_argument, 0, 'Q'}, {"reservation", required_argument, 0, 'R'}, {"signal", required_argument, 0, 's'}, {"state", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckey", required_argument, 0, OPT_LONG_WCKEY}, {NULL, 0, 0, 0} }; while ((opt_char = getopt_long(argc, argv, "A:biM:n:p:Qq:R:s:t:u:vVw:", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"scancel --help\" for more " "information\n"); exit(1); break; case (int)'A': opt.account = xstrtolower(xstrdup(optarg)); break; case (int)'b': opt.batch = true; break; case OPT_LONG_CTLD: opt.ctld = true; break; case (int)'i': opt.interactive = true; break; case (int)'M': opt.ctld = true; FREE_NULL_LIST(opt.clusters); opt.clusters = slurmdb_get_info_cluster(optarg); if (!opt.clusters) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(opt.clusters); break; case (int)'n': opt.job_name = xstrdup(optarg); break; case (int)'p': opt.partition = xstrdup(optarg); break; case (int)'Q': opt.verbose = -1; break; case (int)'q': opt.qos = xstrtolower(xstrdup(optarg)); break; case (int)'R': opt.reservation = xstrdup(optarg); break; case (int)'s': opt.signal = _xlate_signal_name(optarg); break; case (int)'t': opt.state = _xlate_state_name(optarg, false); break; case (int)'u': opt.user_name = xstrdup(optarg); break; case (int)'v': opt.verbose++; break; case (int)'V': print_slurm_version (); exit(0); case (int)'w': opt.nodelist = xstrdup(optarg); break; case OPT_LONG_WCKEY: opt.wckey = xstrdup(optarg); break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { char **rest = argv + optind; opt.job_list = rest; _xlate_job_step_ids(rest); } if (!_opt_verify()) exit(1); }
int main (int argc, char **argv) { int opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"helpformat",0,0, 'e'}, {"long", 0, 0, 'l'}, {"partition",0, 0, 'm'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'n'}, {"format", 1, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"Users", 0, 0, 'U'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); slurm_conf_init(NULL); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while ((opt_char = getopt_long(argc, argv, "aA:ehlM:no:pPqUu:t:vVm", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if (!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'e': _help_format_msg(); exit(0); break; case 'h': print_fields_have_header = 0; break; case 'l': long_flag = 1; break; case 'M': FREE_NULL_LIST(clusters); if (!(clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'm': options |= PRINT_PARTITIONS; break; case 'n': print_fields_have_header = 0; break; case 'o': xstrfmtcat(opt_field_list, "%s,", optarg); break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if (!xstrcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'U': options |= PRINT_USERS_ONLY; break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if (all_users) { if (req_msg.user_list && list_count(req_msg.user_list)) { FREE_NULL_LIST(req_msg.user_list); } if (verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while ((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if (!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd; if ((pwd = getpwuid(getuid()))) { if (!req_msg.user_list) { req_msg.user_list = list_create(slurm_destroy_char); } temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if (verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } } if (req_msg.acct_list && list_count(req_msg.acct_list)) { if (verbosity) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while ((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } } else { if (req_msg.acct_list && list_count(req_msg.acct_list)) { FREE_NULL_LIST(req_msg.acct_list); } if (verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } if (clusters) exit_code = _multi_cluster(&req_msg); else exit_code = _single_cluster(&req_msg); exit(exit_code); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; uid_t some_uid; long tmp_l; static struct option long_options[] = { {"primary_slurmctld_failure", no_argument, 0, 'a'}, {"primary_slurmctld_resumed_operation", no_argument, 0, 'A'}, {"primary_slurmctld_resumed_control", no_argument, 0, 'b'}, {"backup_slurmctld_failure", no_argument, 0, 'B'}, {"backup_slurmctld_resumed_operation", no_argument, 0, 'c'}, {"backup_slurmctld_assumed_control", no_argument, 0, 'C'}, {"down", no_argument, 0, 'd'}, {"drained", no_argument, 0, 'D'}, {"primary_slurmctld_acct_buffer_full", no_argument, 0, 'e'}, {"fini", no_argument, 0, 'f'}, {"fail", no_argument, 0, 'F'}, {"primary_slurmdbd_failure", no_argument, 0, 'g'}, {"primary_slurmdbd_resumed_operation", no_argument, 0, 'G'}, {"primary_database_failure", no_argument, 0, 'h'}, {"primary_database_resumed_operation", no_argument, 0, 'H'}, {"id", required_argument, 0, 'i'}, {"idle", no_argument, 0, 'I'}, {"jobid", required_argument, 0, 'j'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"node", optional_argument, 0, 'n'}, {"noheader", no_argument, 0, 'N'}, {"offset", required_argument, 0, 'o'}, {"program", required_argument, 0, 'p'}, {"quiet", no_argument, 0, 'Q'}, {"reconfig", no_argument, 0, 'r'}, {"time", no_argument, 0, 't'}, {"up", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"block_err", no_argument, 0, OPT_LONG_BLOCK_ERR}, {"clear", no_argument, 0, OPT_LONG_CLEAR}, {"flags", required_argument, 0, OPT_LONG_FLAGS}, {"front_end", no_argument, 0, OPT_LONG_FRONT_END}, {"get", no_argument, 0, OPT_LONG_GET}, {"help", no_argument, 0, OPT_LONG_HELP}, {"set", no_argument, 0, OPT_LONG_SET}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, OPT_LONG_USER}, {NULL, 0, 0, 0} }; _init_options(); optind = 0; while ((opt_char = getopt_long(argc, argv, "aAbBcCdDeFfgGhHi:Ij:M:n::No:p:QrtuvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"strigger --help\" for " "more information\n"); exit(1); break; case (int)'a': params.pri_ctld_fail = true; break; case (int)'A': params.pri_ctld_res_op = true; break; case (int)'b': params.pri_ctld_res_ctrl = true; break; case (int)'B': params.bu_ctld_fail = true; break; case (int)'c': params.bu_ctld_res_op = true; break; case (int)'C': params.bu_ctld_as_ctrl = true; break; case (int)'d': params.node_down = true; break; case (int)'D': params.node_drained = true; break; case (int)'e': params.pri_ctld_acct_buffer_full = true; break; case (int)'f': params.job_fini = true; break; case (int)'F': params.node_fail = true; break; case (int)'g': params.pri_dbd_fail = true; break; case (int)'G': params.pri_dbd_res_op = true; break; case (int)'h': params.pri_db_fail = true; break; case (int)'H': params.pri_db_res_op = true; break; case (int)'i': params.trigger_id = atoi(optarg); break; case (int)'I': params.node_idle = true; break; case (int)'j': tmp_l = atol(optarg); if (tmp_l <= 0) { error("Invalid jobid %s", optarg); exit(1); } params.job_id = tmp_l; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int)'n': xfree(params.node_id); if (optarg) params.node_id = xstrdup(optarg); else params.node_id = xstrdup("*"); break; case (int)'N': params.no_header = true; break; case (int)'o': params.offset = atoi(optarg); break; case (int)'p': xfree(params.program); params.program = xstrdup(optarg); break; case (int)'Q': params.quiet = true; break; case (int)'r': params.reconfig = true; break; case (int)'t': params.time_limit = true; break; case (int)'u': params.node_up = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case (int) OPT_LONG_BLOCK_ERR: params.block_err = true; break; case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case (int) OPT_LONG_CLEAR: params.mode_clear = true; break; case (int) OPT_LONG_FLAGS: if (!strncasecmp(optarg, "perm", 4)) params.flags = TRIGGER_FLAG_PERM; else { error("Invalid flags %s", optarg); exit(1); } break; case (int) OPT_LONG_FRONT_END: params.front_end = true; break; case (int) OPT_LONG_GET: params.mode_get = true; break; case (int) OPT_LONG_SET: params.mode_set = true; break; case (int) OPT_LONG_USER: if ( uid_from_string( optarg, &some_uid ) != 0 ) { error("Invalid user %s", optarg); exit(1); } params.user_id = (uint32_t) some_uid; break; } } if (params.verbose) _print_options(); _validate_options(); }
/* * parse_command_line */ extern void parse_command_line( int argc, char* *argv ) { int opt_char; int option_index; static struct option long_options[] = { {"noheader", no_argument, 0, 'h'}, {"jobs", optional_argument, 0, 'j'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"norm", no_argument, 0, 'n'}, {"format", required_argument, 0, 'o'}, {"user", required_argument, 0, 'u'}, {"users", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"weights", no_argument, 0, 'w'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; /* get defaults from environment */ _opt_env(); while((opt_char = getopt_long(argc, argv, "hj::lM:no:u:vVw", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sprio --help\" " "for more information\n"); exit(1); case (int)'h': params.no_header = true; break; case (int) 'j': if (optarg) { params.jobs = xstrdup(optarg); params.job_list = _build_job_list(params.jobs); } params.job_flag = true; break; case (int) 'l': params.long_list = true; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } break; case (int) 'n': params.normalized = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'u': xfree(params.users); params.users = xstrdup(optarg); params.user_list = _build_user_list(params.users); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) 'w': params.weights = true; break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { if (params.job_flag) { params.jobs = xstrdup(argv[optind++]); params.job_list = _build_job_list(params.jobs); } if (optind < argc) { error("Unrecognized option: %s",argv[optind]); _usage(); exit(1); } } if (params.verbose) _print_options(); if (params.clusters) { if (list_count(params.clusters) > 1) { fatal("Only one cluster can be used at a time with " "sprio"); } working_cluster_rec = list_peek(params.clusters); } }
/* * Allocate nodes for heterogeneous/pack job from the slurm controller -- * retrying the attempt if the controller appears to be down, and optionally * waiting for resources if none are currently available (see opt.immediate) * * Returns a pointer to a resource_allocation_response_msg which must * be freed with slurm_free_resource_allocation_response_msg() */ List allocate_pack_nodes(bool handle_signals) { resource_allocation_response_msg_t *resp = NULL; bool jobid_log = true; job_desc_msg_t *j, *first_job = NULL; slurm_allocation_callbacks_t callbacks; ListIterator opt_iter, resp_iter; slurm_opt_t *opt_local, *first_opt = NULL; List job_req_list = NULL, job_resp_list = NULL; uint32_t my_job_id = 0; int i, k; job_req_list = list_create(NULL); opt_iter = list_iterator_create(opt_list); while ((opt_local = list_next(opt_iter))) { srun_opt_t *srun_opt = opt_local->srun_opt; xassert(srun_opt); if (!first_opt) first_opt = opt_local; if (srun_opt->relative_set && srun_opt->relative) fatal("--relative option invalid for job allocation request"); if ((j = _job_desc_msg_create_from_opts(opt_local)) == NULL) return NULL; if (!first_job) first_job = j; j->origin_cluster = xstrdup(slurmctld_conf.cluster_name); /* Do not re-use existing job id when submitting new job * from within a running job */ if ((j->job_id != NO_VAL) && !opt_local->jobid_set) { if (jobid_log) { jobid_log = false; /* log once */ info("WARNING: Creating SLURM job allocation from within " "another allocation"); info("WARNING: You are attempting to initiate a second job"); } if (!opt_local->jobid_set) /* Let slurmctld set jobid */ j->job_id = NO_VAL; } list_append(job_req_list, j); } list_iterator_destroy(opt_iter); if (!first_job) { error("%s: No job requests found", __func__); return NULL; } if (first_opt && first_opt->clusters && (slurmdb_get_first_pack_cluster(job_req_list, first_opt->clusters, &working_cluster_rec) != SLURM_SUCCESS)) { print_db_notok(first_opt->clusters, 0); return NULL; } callbacks.ping = _ping_handler; callbacks.timeout = _timeout_handler; callbacks.job_complete = _job_complete_handler; callbacks.job_suspend = NULL; callbacks.user_msg = _user_msg_handler; callbacks.node_fail = _node_fail_handler; /* create message thread to handle pings and such from slurmctld */ msg_thr = slurm_allocation_msg_thr_create(&first_job->other_port, &callbacks); /* NOTE: Do not process signals in separate pthread. The signal will * cause slurm_allocate_resources_blocking() to exit immediately. */ if (handle_signals) { xsignal_unblock(sig_array); for (i = 0; sig_array[i]; i++) xsignal(sig_array[i], _signal_while_allocating); } while (first_opt && !job_resp_list) { job_resp_list = slurm_allocate_pack_job_blocking(job_req_list, first_opt->immediate, _set_pending_job_id); if (destroy_job) { /* cancelled by signal */ break; } else if (!job_resp_list && !_retry()) { break; } } if (job_resp_list && !destroy_job) { /* * Allocation granted! */ opt_iter = list_iterator_create(opt_list); resp_iter = list_iterator_create(job_resp_list); while ((opt_local = list_next(opt_iter))) { resp = (resource_allocation_response_msg_t *) list_next(resp_iter); if (!resp) break; if (pending_job_id == 0) pending_job_id = resp->job_id; if (my_job_id == 0) { my_job_id = resp->job_id; i = list_count(opt_list); k = list_count(job_resp_list); if (i != k) { error("%s: request count != response count (%d != %d)", __func__, i, k); goto relinquish; } } /* * These values could be changed while the job was * pending so overwrite the request with what was * allocated so we don't have issues when we use them * in the step creation. * * NOTE: pn_min_memory here is an int64, not uint64. * These operations may have some bizarre side effects */ if (opt_local->pn_min_memory != NO_VAL64) opt_local->pn_min_memory = (resp->pn_min_memory & (~MEM_PER_CPU)); else if (opt_local->mem_per_cpu != NO_VAL64) opt_local->mem_per_cpu = (resp->pn_min_memory & (~MEM_PER_CPU)); #ifdef HAVE_BG uint32_t node_cnt = 0; select_g_select_jobinfo_get(resp->select_jobinfo, SELECT_JOBDATA_NODE_CNT, &node_cnt); if ((node_cnt == 0) || (node_cnt == NO_VAL)) { opt_local->min_nodes = node_cnt; opt_local->max_nodes = node_cnt; } /* else we just use the original request */ if (!_wait_bluegene_block_ready(resp)) { if (!destroy_job) error("Something is wrong with the " "boot of the block."); goto relinquish; } #else opt_local->min_nodes = resp->node_cnt; opt_local->max_nodes = resp->node_cnt; if (resp->working_cluster_rec) slurm_setup_remote_working_cluster(resp); if (!_wait_nodes_ready(resp)) { if (!destroy_job) error("Something is wrong with the " "boot of the nodes."); goto relinquish; } #endif } list_iterator_destroy(resp_iter); list_iterator_destroy(opt_iter); } else if (destroy_job) { goto relinquish; } if (handle_signals) xsignal_block(sig_array); return job_resp_list; relinquish: if (job_resp_list) { if (!destroy_job && my_job_id) slurm_complete_job(my_job_id, 1); list_destroy(job_resp_list); } exit(error_exit); return NULL; }
/* * Allocate nodes from the slurm controller -- retrying the attempt * if the controller appears to be down, and optionally waiting for * resources if none are currently available (see opt.immediate) * * Returns a pointer to a resource_allocation_response_msg which must * be freed with slurm_free_resource_allocation_response_msg() */ extern resource_allocation_response_msg_t * allocate_nodes(bool handle_signals, slurm_opt_t *opt_local) { srun_opt_t *srun_opt = opt_local->srun_opt; resource_allocation_response_msg_t *resp = NULL; job_desc_msg_t *j; slurm_allocation_callbacks_t callbacks; int i; xassert(srun_opt); if (srun_opt->relative_set && srun_opt->relative) fatal("--relative option invalid for job allocation request"); if ((j = _job_desc_msg_create_from_opts(&opt)) == NULL) return NULL; if (opt_local->clusters && (slurmdb_get_first_avail_cluster(j, opt_local->clusters, &working_cluster_rec) != SLURM_SUCCESS)) { print_db_notok(opt_local->clusters, 0); return NULL; } j->origin_cluster = xstrdup(slurmctld_conf.cluster_name); /* Do not re-use existing job id when submitting new job * from within a running job */ if ((j->job_id != NO_VAL) && !opt_local->jobid_set) { info("WARNING: Creating SLURM job allocation from within " "another allocation"); info("WARNING: You are attempting to initiate a second job"); if (!opt_local->jobid_set) /* Let slurmctld set jobid */ j->job_id = NO_VAL; } callbacks.ping = _ping_handler; callbacks.timeout = _timeout_handler; callbacks.job_complete = _job_complete_handler; callbacks.job_suspend = NULL; callbacks.user_msg = _user_msg_handler; callbacks.node_fail = _node_fail_handler; /* create message thread to handle pings and such from slurmctld */ msg_thr = slurm_allocation_msg_thr_create(&j->other_port, &callbacks); /* NOTE: Do not process signals in separate pthread. The signal will * cause slurm_allocate_resources_blocking() to exit immediately. */ if (handle_signals) { xsignal_unblock(sig_array); for (i = 0; sig_array[i]; i++) xsignal(sig_array[i], _signal_while_allocating); } while (!resp) { resp = slurm_allocate_resources_blocking(j, opt_local->immediate, _set_pending_job_id); if (destroy_job) { /* cancelled by signal */ break; } else if (!resp && !_retry()) { break; } } if (resp) print_multi_line_string(resp->job_submit_user_msg, -1); if (resp && !destroy_job) { /* * Allocation granted! */ pending_job_id = resp->job_id; /* * These values could be changed while the job was * pending so overwrite the request with what was * allocated so we don't have issues when we use them * in the step creation. */ opt_local->pn_min_memory = NO_VAL64; opt_local->mem_per_cpu = NO_VAL64; if (resp->pn_min_memory != NO_VAL64) { if (resp->pn_min_memory & MEM_PER_CPU) { opt_local->mem_per_cpu = (resp->pn_min_memory & (~MEM_PER_CPU)); } else { opt_local->pn_min_memory = resp->pn_min_memory; } } #ifdef HAVE_BG uint32_t node_cnt = 0; select_g_select_jobinfo_get(resp->select_jobinfo, SELECT_JOBDATA_NODE_CNT, &node_cnt); if ((node_cnt == 0) || (node_cnt == NO_VAL)) { opt_local->min_nodes = node_cnt; opt_local->max_nodes = node_cnt; } /* else we just use the original request */ if (!_wait_bluegene_block_ready(resp)) { if (!destroy_job) error("Something is wrong with the " "boot of the block."); goto relinquish; } #else opt_local->min_nodes = resp->node_cnt; opt_local->max_nodes = resp->node_cnt; if (resp->working_cluster_rec) slurm_setup_remote_working_cluster(resp); if (!_wait_nodes_ready(resp)) { if (!destroy_job) error("Something is wrong with the boot of the nodes."); goto relinquish; } #endif } else if (destroy_job) { goto relinquish; } if (handle_signals) xsignal_block(sig_array); job_desc_msg_destroy(j); return resp; relinquish: if (resp) { if (!destroy_job) slurm_complete_job(resp->job_id, 1); slurm_free_resource_allocation_response_msg(resp); } exit(error_exit); return NULL; }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; shares_response_msg_t *resp_msg = NULL; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"long", 0, 0, 'l'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'h'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "aA:hlM:npPqu:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if (!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'h': print_fields_have_header = 0; break; exit(exit_code); break; case 'l': long_flag = 1; break; case 'M': if (clusters) list_destroy(clusters); if (!(clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'n': print_fields_have_header = 0; break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if (!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if (all_users) { if (req_msg.user_list && list_count(req_msg.user_list)) { list_destroy(req_msg.user_list); req_msg.user_list = NULL; } if (verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if (!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd = getpwuid(getuid()); if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if (verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } if (req_msg.acct_list && list_count(req_msg.acct_list)) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else { if (req_msg.acct_list && list_count(req_msg.acct_list)) { list_destroy(req_msg.acct_list); req_msg.acct_list = NULL; } if (verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } error_code = _get_info(&req_msg, &resp_msg); if (req_msg.acct_list) list_destroy(req_msg.acct_list); if (req_msg.user_list) list_destroy(req_msg.user_list); if (error_code) { slurm_perror("Couldn't get shares from controller"); exit(error_code); } /* do stuff with it */ process(resp_msg); slurm_free_shares_response_msg(resp_msg); exit(exit_code); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; int tmp = 0; static struct option long_options[] = { {"commandline", no_argument, 0, 'c'}, {"command", required_argument, 0, 'C'}, {"display", required_argument, 0, 'D'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, {"ionodes", required_argument, 0, 'I'}, {"cluster", required_argument, 0, 'M'}, {"clusters",required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"quiet", no_argument, 0, 'Q'}, {"resolve", required_argument, 0, 'R'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"show_hidden", no_argument, 0, 'H'}, {NULL, 0, 0, 0} }; memset(¶ms, 0, sizeof(params)); while ((opt_char = getopt_long(argc, argv, "cC:D:hi:I:Hn:M:QR:vV", long_options, &option_index)) != -1) { switch (opt_char) { case '?': fprintf(stderr, "Try \"smap --help\" for more information\n"); exit(1); break; case 'c': params.commandline = true; break; case 'C': params.command = xstrdup(optarg); break; case 'D': if (!xstrcmp(optarg, "j")) tmp = JOBS; else if (!xstrcmp(optarg, "s")) tmp = SLURMPART; else if (!xstrcmp(optarg, "b")) tmp = BGPART; else if (!xstrcmp(optarg, "c")) tmp = COMMANDS; else if (!xstrcmp(optarg, "r")) tmp = RESERVATIONS; params.display = tmp; break; case 'h': params.no_header = true; break; case 'H': params.all_flag = true; break; case 'i': params.iterate = atoi(optarg); if (params.iterate <= 0) { error("Error: --iterate=%s", optarg); exit(1); } break; case 'I': /* * confirm valid ionodelist entry (The 128 is * a large number here to avoid having to do a * lot more querying to figure out the correct * pset size. This number should be large enough. */ params.io_bit = bit_alloc(128); if (bit_unfmt(params.io_bit, optarg) == -1) { error("'%s' invalid entry for --ionodes", optarg); exit(1); } break; case 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case 'n': /* * confirm valid nodelist entry */ params.hl = hostlist_create(optarg); if (!params.hl) { error("'%s' invalid entry for --nodes", optarg); exit(1); } break; case 'Q': quiet_flag = 1; break; case 'R': params.commandline = true; params.resolve = xstrdup(optarg); break; case 'v': params.verbose++; break; case 'V': print_slurm_version(); exit(0); case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } params.cluster_dims = slurmdb_setup_cluster_dims(); if (params.cluster_dims > 4) fatal("smap is unable to support more than four dimensions"); params.cluster_base = hostlist_get_base(params.cluster_dims); params.cluster_flags = slurmdb_setup_cluster_flags(); }