/* * slurm_job_will_run - determine if a job would execute immediately if * submitted now * IN job_desc_msg - description of resource allocation request * RET 0 on success, otherwise return -1 and set errno to indicate the error */ int slurm_job_will_run(job_desc_msg_t *req) { will_run_response_msg_t *will_run_resp = NULL; char buf[64], local_hostname[64]; int rc; uint32_t cluster_flags = slurmdb_setup_cluster_flags(); char *type = "processors"; char *cluster_name = NULL; void *ptr = NULL; if ((req->alloc_node == NULL) && (gethostname_short(local_hostname, sizeof(local_hostname)) == 0)) { req->alloc_node = local_hostname; } if (working_cluster_rec) cluster_name = working_cluster_rec->name; else cluster_name = slurmctld_conf.cluster_name; if (!slurm_load_federation(&ptr) && cluster_in_federation(ptr, cluster_name)) rc = _fed_job_will_run(req, &will_run_resp, ptr); else rc = slurm_job_will_run2(req, &will_run_resp); if ((rc == 0) && will_run_resp) { if (cluster_flags & CLUSTER_FLAG_BG) type = "cnodes"; slurm_make_time_str(&will_run_resp->start_time, buf, sizeof(buf)); info("Job %u to start at %s using %u %s on %s", will_run_resp->job_id, buf, will_run_resp->proc_cnt, type, will_run_resp->node_list); if (will_run_resp->preemptee_job_id) { ListIterator itr; uint32_t *job_id_ptr; char *job_list = NULL, *sep = ""; itr = list_iterator_create(will_run_resp-> preemptee_job_id); while ((job_id_ptr = list_next(itr))) { if (job_list) sep = ","; xstrfmtcat(job_list, "%s%u", sep, *job_id_ptr); } list_iterator_destroy(itr); info(" Preempts: %s", job_list); xfree(job_list); } slurm_free_will_run_response_msg(will_run_resp); } if (req->alloc_node == local_hostname) req->alloc_node = NULL; if (ptr) slurm_destroy_federation_rec(ptr); return rc; }
static char *_build_cluster_string(void) { char *cluster_str = NULL; slurmdb_federation_rec_t *fed = NULL; slurmdb_federation_cond_t fed_cond; List fed_list = NULL; List cluster_list = list_create(NULL); list_append(cluster_list, slurmctld_conf.cluster_name); slurmdb_init_federation_cond(&fed_cond, 0); fed_cond.cluster_list = cluster_list; if ((fed_list = slurmdb_federations_get(db_conn, &fed_cond)) && list_count(fed_list) == 1) { fed = list_pop(fed_list); fed_name = xstrdup(fed->name); list_for_each(fed->cluster_list, _foreach_cluster_list_to_str, &cluster_str); } slurm_destroy_federation_rec(fed); FREE_NULL_LIST(cluster_list); FREE_NULL_LIST(fed_list); return cluster_str; }
/* * slurm_load_node - issue RPC to get slurm all node configuration information * if changed since update_time * IN update_time - time of current configuration data * OUT resp - place to store a node configuration pointer * IN show_flags - node filtering options * RET 0 or a slurm error code * NOTE: free the response using slurm_free_node_info_msg */ extern int slurm_load_node(time_t update_time, node_info_msg_t **resp, uint16_t show_flags) { slurm_msg_t req_msg; node_info_request_msg_t req; char *cluster_name = NULL; void *ptr = NULL; slurmdb_federation_rec_t *fed; int rc; if (working_cluster_rec) cluster_name = xstrdup(working_cluster_rec->name); else cluster_name = slurm_get_cluster_name(); if ((show_flags & SHOW_FEDERATION) && !(show_flags & SHOW_LOCAL) && (slurm_load_federation(&ptr) == SLURM_SUCCESS) && cluster_in_federation(ptr, cluster_name)) { /* In federation. Need full info from all clusters */ update_time = (time_t) 0; show_flags &= (~SHOW_LOCAL); } else { /* Report local cluster info only */ show_flags |= SHOW_LOCAL; show_flags &= (~SHOW_FEDERATION); } slurm_msg_t_init(&req_msg); memset(&req, 0, sizeof(req)); req.last_update = update_time; req.show_flags = show_flags; req_msg.msg_type = REQUEST_NODE_INFO; req_msg.data = &req; if ((show_flags & SHOW_FEDERATION) && ptr) { /* "ptr" check for CLANG */ fed = (slurmdb_federation_rec_t *) ptr; rc = _load_fed_nodes(&req_msg, resp, show_flags, cluster_name, fed); } else { rc = _load_cluster_nodes(&req_msg, resp, working_cluster_rec, show_flags); } if (ptr) slurm_destroy_federation_rec(ptr); xfree(cluster_name); return rc; }
/* * 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(); }
/* * slurm_job_will_run - determine if a job would execute immediately if * submitted now * IN job_desc_msg - description of resource allocation request * RET SLURM_SUCCESS on success, otherwise return SLURM_ERROR with errno set */ int slurm_job_will_run(job_desc_msg_t *req) { will_run_response_msg_t *will_run_resp = NULL; char buf[64]; int rc; char *cluster_name = NULL; void *ptr = NULL; if (working_cluster_rec) cluster_name = working_cluster_rec->name; else cluster_name = slurmctld_conf.cluster_name; if (!slurm_load_federation(&ptr) && cluster_in_federation(ptr, cluster_name)) rc = _fed_job_will_run(req, &will_run_resp, ptr); else rc = slurm_job_will_run2(req, &will_run_resp); if (will_run_resp) print_multi_line_string( will_run_resp->job_submit_user_msg, -1, LOG_LEVEL_INFO); if ((rc == 0) && will_run_resp) { slurm_make_time_str(&will_run_resp->start_time, buf, sizeof(buf)); if (will_run_resp->part_name) { info("Job %u to start at %s using %u processors on nodes %s in partition %s", will_run_resp->job_id, buf, will_run_resp->proc_cnt, will_run_resp->node_list, will_run_resp->part_name); } else { /* * Partition name not provided from slurmctld v17.11 * or earlier. Remove this in the future. */ info("Job %u to start at %s using %u processors on nodes %s", will_run_resp->job_id, buf, will_run_resp->proc_cnt, will_run_resp->node_list); } if (will_run_resp->preemptee_job_id) { ListIterator itr; uint32_t *job_id_ptr; char *job_list = NULL, *sep = ""; itr = list_iterator_create(will_run_resp-> preemptee_job_id); while ((job_id_ptr = list_next(itr))) { if (job_list) sep = ","; xstrfmtcat(job_list, "%s%u", sep, *job_id_ptr); } list_iterator_destroy(itr); info(" Preempts: %s", job_list); xfree(job_list); } slurm_free_will_run_response_msg(will_run_resp); } if (ptr) slurm_destroy_federation_rec(ptr); return rc; }