From c58c495baba9a9e61230fe8b75b9f56a581a2979 Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Fri, 8 Oct 2010 13:14:23 +0000 Subject: [PATCH] Replace most calls of hostlist_ranged_string() and hostlist_deranged_string() with equivalent functions that allocate the memory --- slurm/slurm.h.in | 10 ++++ src/api/slurm_hostlist.c | 10 ++++ src/api/step_launch.c | 5 +- src/common/forward.c | 20 ++++---- src/common/hostlist.c | 1 + src/common/hostlist.h | 5 +- src/common/slurm_step_layout.c | 6 +-- .../block_allocator/block_allocator.c | 5 +- .../select/bluegene/plugin/block_sys.c | 8 +--- src/plugins/select/linear/select_linear.c | 2 +- src/plugins/topology/tree/topology_tree.c | 4 +- src/sbatch/opt.c | 4 +- src/sbcast/agent.c | 5 +- src/sinfo/opts.c | 2 +- src/sinfo/print.c | 14 +++--- src/slurmctld/agent.c | 5 +- src/slurmctld/node_mgr.c | 20 ++++---- src/slurmctld/node_scheduler.c | 6 +-- src/slurmctld/ping_nodes.c | 23 +++++---- src/slurmctld/port_mgr.c | 7 +-- src/slurmctld/step_mgr.c | 8 +--- src/squeue/print.c | 5 +- src/srun/allocate.c | 9 ++-- src/srun/opt.c | 4 +- src/srun/srun_job.c | 47 ++++++++++--------- src/sview/node_info.c | 4 +- 26 files changed, 118 insertions(+), 121 deletions(-) diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in index 3c9ae9c3579..00879be6502 100644 --- a/slurm/slurm.h.in +++ b/slurm/slurm.h.in @@ -678,6 +678,16 @@ extern ssize_t slurm_hostlist_ranged_string PARAMS((hostlist_t hl, */ extern char *slurm_hostlist_ranged_string_malloc PARAMS((hostlist_t hl)); +/* hostlist_ranged_string_xmalloc(): + * + * Wrapper of hostlist_ranged_string(), with result buffer dynamically + * allocated using xmalloc(). + * The result will be NULL on failure (out of memory). + * + * Caller should free the result string using xfree(). + */ +extern char *slurm_hostlist_ranged_string_xmalloc PARAMS((hostlist_t hl)); + /* * slurm_hostlist_shift(): * diff --git a/src/api/slurm_hostlist.c b/src/api/slurm_hostlist.c index 01fc85e442c..eee8016430f 100644 --- a/src/api/slurm_hostlist.c +++ b/src/api/slurm_hostlist.c @@ -82,6 +82,16 @@ extern ssize_t slurm_hostlist_ranged_string(hostlist_t hl, size_t n, char *buf) return hostlist_ranged_string(hl, n, buf); } +extern char * slurm_hostlist_ranged_string_malloc(hostlist_t hl) +{ + return hostlist_ranged_string_malloc(hl); +} + +extern char * slurm_hostlist_ranged_string_xmalloc(hostlist_t hl) +{ + return hostlist_ranged_string_xmalloc(hl); +} + extern char *slurm_hostlist_shift(hostlist_t hl) { return hostlist_shift(hl); diff --git a/src/api/step_launch.c b/src/api/step_launch.c index ac114d5ca88..455f778c80e 100644 --- a/src/api/step_launch.c +++ b/src/api/step_launch.c @@ -1384,19 +1384,20 @@ static void _print_launch_msg(launch_tasks_request_msg_t *msg, char *hostname, int nodeid) { int i; - char tmp_str[10], task_list[4096]; + char tmp_str[10], *task_list = NULL; hostlist_t hl = hostlist_create(""); for (i=0; i<msg->tasks_to_launch[nodeid]; i++) { sprintf(tmp_str, "%u", msg->global_task_ids[nodeid][i]); hostlist_push(hl, tmp_str); } - hostlist_ranged_string(hl, 4096, task_list); + task_list = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); info("launching %u.%u on host %s, %u tasks: %s", msg->job_id, msg->job_step_id, hostname, msg->tasks_to_launch[nodeid], task_list); + xfree(task_list); debug3("uid:%ld gid:%ld cwd:%s %d", (long) msg->uid, (long) msg->gid, msg->cwd, nodeid); diff --git a/src/common/forward.c b/src/common/forward.c index 4cc50e66ffa..b0f68411f1e 100644 --- a/src/common/forward.c +++ b/src/common/forward.c @@ -91,7 +91,7 @@ void *_forward_thread(void *arg) char *name = NULL; hostlist_t hl = hostlist_create(fwd_msg->header.forward.nodelist); slurm_addr_t addr; - char buf[8196]; + char *buf = NULL; int steps = 0; int start_timeout = fwd_msg->timeout; @@ -124,10 +124,10 @@ void *_forward_thread(void *arg) } goto cleanup; } - hostlist_ranged_string(hl, sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(hl); xfree(fwd_msg->header.forward.nodelist); - fwd_msg->header.forward.nodelist = xstrdup(buf); + fwd_msg->header.forward.nodelist = buf; fwd_msg->header.forward.cnt = hostlist_count(hl); /* info("sending %d forwards (%s) to %s", */ /* fwd_msg->header.forward.cnt, */ @@ -307,7 +307,7 @@ void *_fwd_tree_thread(void *arg) fwd_tree_t *fwd_tree = (fwd_tree_t *)arg; List ret_list = NULL; char *name = NULL; - char buf[8196]; + char *buf = NULL; slurm_msg_t send_msg; slurm_msg_t_init(&send_msg); @@ -332,9 +332,9 @@ void *_fwd_tree_thread(void *arg) send_msg.forward.timeout = fwd_tree->timeout; if((send_msg.forward.cnt = hostlist_count(fwd_tree->tree_hl))) { - hostlist_ranged_string(fwd_tree->tree_hl, - sizeof(buf), buf); - send_msg.forward.nodelist = xstrdup(buf); + buf = hostlist_ranged_string_xmalloc( + fwd_tree->tree_hl); + send_msg.forward.nodelist = buf; } else send_msg.forward.nodelist = NULL; @@ -444,7 +444,7 @@ extern int forward_msg(forward_struct_t *forward_struct, while((name = hostlist_shift(hl))) { pthread_attr_t attr_agent; pthread_t thread_agent; - char buf[8192]; + char *buf = NULL; slurm_attr_init(&attr_agent); if (pthread_attr_setdetachstate @@ -487,10 +487,10 @@ extern int forward_msg(forward_struct_t *forward_struct, free(name); } - hostlist_ranged_string(forward_hl, sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(forward_hl); hostlist_destroy(forward_hl); forward_init(&forward_msg->header.forward, NULL); - forward_msg->header.forward.nodelist = xstrdup(buf); + forward_msg->header.forward.nodelist = buf; while(pthread_create(&thread_agent, &attr_agent, _forward_thread, (void *)forward_msg)) { diff --git a/src/common/hostlist.c b/src/common/hostlist.c index 4803f524d4a..d3f7855673c 100644 --- a/src/common/hostlist.c +++ b/src/common/hostlist.c @@ -3207,6 +3207,7 @@ notbox: // info("time was %s", TIME_STR); return truncated ? -1 : len; } + /* ----[ hostlist iterator functions ]---- */ static hostlist_iterator_t hostlist_iterator_new(void) diff --git a/src/common/hostlist.h b/src/common/hostlist.h index 86f117fcc23..d2d61e63ef4 100644 --- a/src/common/hostlist.h +++ b/src/common/hostlist.h @@ -345,7 +345,7 @@ void hostlist_parse_int_to_array(int in, int *out, int dims, int hostlist_base); ssize_t hostlist_ranged_string(hostlist_t hl, size_t n, char *buf); /* Variant of hostlist_ranged_string(). - * Returns the buffer which must be released using free(). + * Returns the buffer which must be released using free() or NULL on failure. */ char *hostlist_ranged_string_malloc(hostlist_t hl); @@ -366,7 +366,7 @@ char *hostlist_ranged_string_xmalloc(hostlist_t hl); ssize_t hostlist_deranged_string(hostlist_t hl, size_t n, char *buf); /* Variant of hostlist_deranged_string(). - * Returns the buffer which must be released using free(). + * Returns the buffer which must be released using free() or NULL on failure. */ char *hostlist_deranged_string_malloc(hostlist_t hl); @@ -377,7 +377,6 @@ char *hostlist_deranged_string_xmalloc(hostlist_t hl); /* ----[ hostlist utility functions ]---- */ - /* hostlist_nranges(): * * Return the number of ranges currently held in hostlist hl. diff --git a/src/common/slurm_step_layout.c b/src/common/slurm_step_layout.c index 5c9023dbfc9..f2a4c26768e 100644 --- a/src/common/slurm_step_layout.c +++ b/src/common/slurm_step_layout.c @@ -103,16 +103,16 @@ slurm_step_layout_t *slurm_step_layout_create( step_layout->task_dist = task_dist; if(task_dist == SLURM_DIST_ARBITRARY) { hostlist_t hl = NULL; - char buf[65536]; + char *buf = NULL; /* set the node list for the task layout later if user supplied could be different that the job allocation */ arbitrary_nodes = xstrdup(tlist); hl = hostlist_create(tlist); hostlist_uniq(hl); - hostlist_ranged_string(hl, sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(hl); num_hosts = hostlist_count(hl); hostlist_destroy(hl); - step_layout->node_list = xstrdup(buf); + step_layout->node_list = buf; } else { step_layout->node_list = xstrdup(tlist); } diff --git a/src/plugins/select/bluegene/block_allocator/block_allocator.c b/src/plugins/select/bluegene/block_allocator/block_allocator.c index 85d0bf79cb0..072e23757fa 100644 --- a/src/plugins/select/bluegene/block_allocator/block_allocator.c +++ b/src/plugins/select/bluegene/block_allocator/block_allocator.c @@ -273,7 +273,6 @@ extern int parse_blockreq(void **dest, slurm_parser_enum_t type, char *tmp = NULL; blockreq_t *n = NULL; hostlist_t hl = NULL; - char temp[BUFSIZE]; tbl = s_p_hashtbl_create(block_options); s_p_parse_line(tbl, *leftover, leftover); @@ -282,10 +281,8 @@ extern int parse_blockreq(void **dest, slurm_parser_enum_t type, } n = xmalloc(sizeof(blockreq_t)); hl = hostlist_create(value); - hostlist_ranged_string(hl, BUFSIZE, temp); + n->block = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); - - n->block = xstrdup(temp); #ifdef HAVE_BGL s_p_get_string(&n->blrtsimage, "BlrtsImage", tbl); s_p_get_string(&n->linuximage, "LinuxImage", tbl); diff --git a/src/plugins/select/bluegene/plugin/block_sys.c b/src/plugins/select/bluegene/plugin/block_sys.c index 386b2fb659b..b95dca90bbc 100755 --- a/src/plugins/select/bluegene/plugin/block_sys.c +++ b/src/plugins/select/bluegene/plugin/block_sys.c @@ -773,13 +773,7 @@ int read_bg_blocks(List curr_block_list) hostlist_push(hostlist, node_name_tmp); } - i = 1024; - bg_record->nodes = xmalloc(i); - while (hostlist_ranged_string(hostlist, i, - bg_record->nodes) < 0) { - i *= 2; - xrealloc(bg_record->nodes, i); - } + bg_record->nodes = hostlist_ranged_string_xmalloc(hostlist); hostlist_destroy(hostlist); debug3("got nodes of %s", bg_record->nodes); // need to get the 000x000 range for nodes diff --git a/src/plugins/select/linear/select_linear.c b/src/plugins/select/linear/select_linear.c index 61a73bfceb9..33812e39170 100644 --- a/src/plugins/select/linear/select_linear.c +++ b/src/plugins/select/linear/select_linear.c @@ -2709,7 +2709,7 @@ extern int select_p_select_nodeinfo_get(select_nodeinfo_t *nodeinfo, } if (nodeinfo->magic != NODEINFO_MAGIC) { - error("get_nodeinfo: jobinfo magic bad"); + error("get_nodeinfo: nodeinfo magic bad"); return SLURM_ERROR; } diff --git a/src/plugins/topology/tree/topology_tree.c b/src/plugins/topology/tree/topology_tree.c index b1632a8d51c..8fb27ac181b 100644 --- a/src/plugins/topology/tree/topology_tree.c +++ b/src/plugins/topology/tree/topology_tree.c @@ -154,7 +154,6 @@ extern int topo_get_node_addr(char* node_name, char** paddr, char** ppattern) int node_inx; hostlist_t sl = NULL; - char buf[8192]; int s_max_level = 0; int i, j; @@ -199,8 +198,9 @@ extern int topo_get_node_addr(char* node_name, char** paddr, char** ppattern) } } if ( sl ) { - hostlist_ranged_string(sl, sizeof(buf), buf); + char *buf = hostlist_ranged_string_xmalloc(sl); xstrcat(*paddr,buf); + xfree(buf); hostlist_destroy(sl); sl = NULL; } diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c index 41e9e2bf3fb..914f47999fd 100644 --- a/src/sbatch/opt.c +++ b/src/sbatch/opt.c @@ -1823,7 +1823,6 @@ static void _parse_pbs_nodes_opts(char *node_opts) { int i = 0; char *temp = NULL; - char buf[255]; int ppn = 0; int node_cnt = 0; hostlist_t hl = hostlist_create(NULL); @@ -1859,9 +1858,8 @@ static void _parse_pbs_nodes_opts(char *node_opts) } if(hostlist_count(hl) > 0) { - hostlist_ranged_string(hl, sizeof(buf), buf); xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = hostlist_ranged_string_xmalloc(hl); #ifdef HAVE_BG info("\tThe nodelist option should only be used if\n" "\tthe block you are asking for can be created.\n" diff --git a/src/sbcast/agent.c b/src/sbcast/agent.c index 2ea8eb6f735..0a9ce8af843 100644 --- a/src/sbcast/agent.c +++ b/src/sbcast/agent.c @@ -133,7 +133,6 @@ extern void send_rpc(file_bcast_msg_t *bcast_msg, hostlist_t hl; hostlist_t new_hl; int *span = NULL; - char buf[8192]; char *name = NULL; if (params.fanout) @@ -164,9 +163,9 @@ extern void send_rpc(file_bcast_msg_t *bcast_msg, free(name); i++; } - hostlist_ranged_string(new_hl, sizeof(buf), buf); + thread_info[threads_used].nodelist = + hostlist_ranged_string_xmalloc(new_hl); hostlist_destroy(new_hl); - thread_info[threads_used].nodelist = xstrdup(buf); slurm_msg_t_init(&thread_info[threads_used].msg); thread_info[threads_used].msg.msg_type = REQUEST_FILE_BCAST; diff --git a/src/sinfo/opts.c b/src/sinfo/opts.c index 2a95bde9372..13edb8df11a 100644 --- a/src/sinfo/opts.c +++ b/src/sinfo/opts.c @@ -833,7 +833,7 @@ Usage: sinfo [OPTIONS]\n\ -d, --dead show only non-responding nodes\n\ -e, --exact group nodes only on exact match of configuration\n\ -h, --noheader no headers on output\n\ - -hide do not show hidden or non-accessible partitions\n\ + --hide do not show hidden or non-accessible partitions\n\ -i, --iterate=seconds specify an iteration period\n\ -l, --long long output - displays more information\n\ -n, --nodes=NODES report on specific node(s)\n\ diff --git a/src/sinfo/print.c b/src/sinfo/print.c index 1b412102eed..9a58f73430e 100644 --- a/src/sinfo/print.c +++ b/src/sinfo/print.c @@ -247,14 +247,15 @@ format_add_function(List list, int width, bool right, char *suffix, static void _set_node_field_size(List sinfo_list) { - char tmp[MAXHOSTRANGELEN]; + char *tmp = NULL; ListIterator i = list_iterator_create(sinfo_list); sinfo_data_t *current; int max_width = MIN_NODE_FIELD_SIZE, this_width = 0; while ((current = (sinfo_data_t *) list_next(i)) != NULL) { - this_width = hostlist_ranged_string(current->nodes, - sizeof(tmp), tmp); + tmp = hostlist_ranged_string_xmalloc(current->nodes); + this_width = strlen(tmp); + xfree(tmp); max_width = MAX(max_width, this_width); } list_iterator_destroy(i); @@ -556,10 +557,11 @@ int _print_node_list(sinfo_data_t * sinfo_data, int width, width = params.node_field_size; if (sinfo_data) { - char tmp[MAXHOSTRANGELEN]; - hostlist_ranged_string(sinfo_data->nodes, - sizeof(tmp), tmp); + char *tmp = NULL; + tmp = hostlist_ranged_string_xmalloc( + sinfo_data->nodes); _print_str(tmp, width, right_justify, true); + xfree(tmp); } else { char *title = "NODELIST"; if(params.cluster_flags & CLUSTER_FLAG_BG) diff --git a/src/slurmctld/agent.c b/src/slurmctld/agent.c index 774ebe08e06..bc9aec81fb5 100644 --- a/src/slurmctld/agent.c +++ b/src/slurmctld/agent.c @@ -383,7 +383,6 @@ static agent_info_t *_make_agent_info(agent_arg_t *agent_arg_ptr) int *span = NULL; int thr_count = 0; hostlist_t hl = NULL; - char buf[8192]; char *name = NULL; agent_info_ptr = xmalloc(sizeof(agent_info_t)); @@ -446,9 +445,9 @@ static agent_info_t *_make_agent_info(agent_arg_t *agent_arg_ptr) i++; } hostlist_uniq(hl); - hostlist_ranged_string(hl, sizeof(buf), buf); + thread_ptr[thr_count].nodelist = + hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); - thread_ptr[thr_count].nodelist = xstrdup(buf); #if 0 info("sending to nodes %s", thread_ptr[thr_count].nodelist); #endif diff --git a/src/slurmctld/node_mgr.c b/src/slurmctld/node_mgr.c index ad3dd273467..f28dee2fff3 100644 --- a/src/slurmctld/node_mgr.c +++ b/src/slurmctld/node_mgr.c @@ -1738,7 +1738,7 @@ extern int validate_nodes_via_front_end( ListIterator job_iterator; hostlist_t return_hostlist = NULL, reg_hostlist = NULL; hostlist_t prolog_hostlist = NULL; - char host_str[64]; + char *host_str = NULL; uint16_t node_flags; if (reg_msg->up_time > now) { @@ -1967,23 +1967,23 @@ extern int validate_nodes_via_front_end( if (prolog_hostlist) { hostlist_uniq(prolog_hostlist); - hostlist_ranged_string(prolog_hostlist, sizeof(host_str), - host_str); + host_str = hostlist_ranged_string_xmalloc(prolog_hostlist); error("Prolog failure on nodes %s, set to DOWN", host_str); + xfree(host_str); hostlist_destroy(prolog_hostlist); } if (reg_hostlist) { hostlist_uniq(reg_hostlist); - hostlist_ranged_string(reg_hostlist, sizeof(host_str), - host_str); + host_str = hostlist_ranged_string_xmalloc(reg_hostlist); debug("Nodes %s have registered", host_str); + xfree(host_str); hostlist_destroy(reg_hostlist); } if (return_hostlist) { hostlist_uniq(return_hostlist); - hostlist_ranged_string(return_hostlist, sizeof(host_str), - host_str); + host_str = hostlist_ranged_string_xmalloc(return_hostlist); info("Nodes %s returned to service", host_str); + xfree(host_str); hostlist_destroy(return_hostlist); } @@ -2146,7 +2146,7 @@ extern void node_no_resp_msg(void) { int i; struct node_record *node_ptr; - char host_str[1024]; + char *host_str = NULL; hostlist_t no_resp_hostlist = NULL; for (i=0; i<node_record_count; i++) { @@ -2162,9 +2162,9 @@ extern void node_no_resp_msg(void) } if (no_resp_hostlist) { hostlist_uniq(no_resp_hostlist); - hostlist_ranged_string(no_resp_hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc(no_resp_hostlist); error("Nodes %s not responding", host_str); + xfree(host_str); hostlist_destroy(no_resp_hostlist); } } diff --git a/src/slurmctld/node_scheduler.c b/src/slurmctld/node_scheduler.c index 504df36888f..b73f1d0ae49 100644 --- a/src/slurmctld/node_scheduler.c +++ b/src/slurmctld/node_scheduler.c @@ -1878,7 +1878,7 @@ extern void re_kill_job(struct job_record *job_ptr) kill_job_msg_t *kill_job; agent_arg_t *agent_args; hostlist_t kill_hostlist = hostlist_create(""); - char host_str[64]; + char *host_str = NULL; static uint32_t last_job_id = 0; xassert(job_ptr); @@ -1940,8 +1940,7 @@ extern void re_kill_job(struct job_record *job_ptr) return; } hostlist_uniq(kill_hostlist); - hostlist_ranged_string(kill_hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc(kill_hostlist); #ifdef HAVE_BG if (job_ptr->job_id != last_job_id) { info("Resending TERMINATE_JOB request JobId=%u BPlist=%s", @@ -1959,6 +1958,7 @@ extern void re_kill_job(struct job_record *job_ptr) job_ptr->job_id, host_str); } #endif + xfree(host_str); last_job_id = job_ptr->job_id; hostlist_destroy(kill_hostlist); agent_args->msg_args = kill_job; diff --git a/src/slurmctld/ping_nodes.c b/src/slurmctld/ping_nodes.c index 872d12dce3a..57057e50b9a 100644 --- a/src/slurmctld/ping_nodes.c +++ b/src/slurmctld/ping_nodes.c @@ -127,7 +127,7 @@ void ping_nodes (void) static time_t last_ping_time = (time_t) 0; bool restart_flag; hostlist_t down_hostlist = NULL; - char host_str[MAX_SLURM_NAME]; + char *host_str = NULL; agent_arg_t *ping_agent_args = NULL; agent_arg_t *reg_agent_args = NULL; struct node_record *node_ptr; @@ -237,9 +237,10 @@ void ping_nodes (void) xfree (ping_agent_args); } else { hostlist_uniq(ping_agent_args->hostlist); - hostlist_ranged_string(ping_agent_args->hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc( + ping_agent_args->hostlist); debug("Spawning ping agent for %s", host_str); + xfree(host_str); ping_begin(); agent_queue_request(ping_agent_args); } @@ -249,19 +250,20 @@ void ping_nodes (void) xfree (reg_agent_args); } else { hostlist_uniq(reg_agent_args->hostlist); - hostlist_ranged_string(reg_agent_args->hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc( + reg_agent_args->hostlist); debug("Spawning registration agent for %s %d hosts", host_str, reg_agent_args->node_count); + xfree(host_str); ping_begin(); agent_queue_request(reg_agent_args); } if (down_hostlist) { hostlist_uniq(down_hostlist); - hostlist_ranged_string(down_hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc(down_hostlist); error("Nodes %s not responding, setting DOWN", host_str); + xfree(host_str); hostlist_destroy(down_hostlist); } } @@ -270,7 +272,7 @@ void ping_nodes (void) extern void run_health_check(void) { int i; - char host_str[MAX_SLURM_NAME]; + char *host_str = NULL; agent_arg_t *check_agent_args = NULL; struct node_record *node_ptr; @@ -298,9 +300,10 @@ extern void run_health_check(void) xfree (check_agent_args); } else { hostlist_uniq(check_agent_args->hostlist); - hostlist_ranged_string(check_agent_args->hostlist, - sizeof(host_str), host_str); + host_str = hostlist_ranged_string_xmalloc( + check_agent_args->hostlist); debug("Spawning health check agent for %s", host_str); + xfree(host_str); ping_begin(); agent_queue_request(check_agent_args); } diff --git a/src/slurmctld/port_mgr.c b/src/slurmctld/port_mgr.c index a032e631539..d72f22952ff 100644 --- a/src/slurmctld/port_mgr.c +++ b/src/slurmctld/port_mgr.c @@ -266,12 +266,7 @@ extern int resv_port_alloc(struct step_record *step_ptr) hostlist_push(hl, port_str); } hostlist_sort(hl); - for (i=1024; ; i*=2) { - step_ptr->resv_ports = xmalloc(i); - if (hostlist_ranged_string(hl, i, step_ptr->resv_ports) >= 0) - break; - xfree(step_ptr->resv_ports); - } + step_ptr->resv_ports = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); step_ptr->resv_port_array = port_array; diff --git a/src/slurmctld/step_mgr.c b/src/slurmctld/step_mgr.c index 595df0ed222..8d190eaeddc 100644 --- a/src/slurmctld/step_mgr.c +++ b/src/slurmctld/step_mgr.c @@ -2300,16 +2300,10 @@ extern int step_partial_comp(step_complete_msg_t *req, uid_t uid, * must translate range numbers to nodelist */ hostlist_t hl; char *node_list; - int new_size = 8096; hl = _step_range_to_hostlist(step_ptr, req->range_first, req->range_last); - node_list = (char *) xmalloc(new_size); - while (hostlist_ranged_string(hl, new_size, - node_list) == -1) { - new_size *= 2; - xrealloc(node_list, new_size ); - } + node_list = hostlist_ranged_string_xmalloc(hl); debug2("partitial switch release for step %u.%u, " "nodes %s", req->job_id, req->job_step_id, node_list); diff --git a/src/squeue/print.c b/src/squeue/print.c index 0e9200afc60..4892485703a 100644 --- a/src/squeue/print.c +++ b/src/squeue/print.c @@ -179,10 +179,11 @@ static int _print_str(char *str, int width, bool right, bool cut_output) int _print_nodes(char *nodes, int width, bool right, bool cut) { hostlist_t hl = hostlist_create(nodes); - char buf[MAXHOSTRANGELEN]; + char *buf = NULL; int retval; - hostlist_ranged_string(hl, MAXHOSTRANGELEN, buf); + buf = hostlist_ranged_string_xmalloc(hl); retval = _print_str(buf, width, right, false); + xfree(buf); hostlist_destroy(hl); return retval; } diff --git a/src/srun/allocate.c b/src/srun/allocate.c index 5e2be54fa0c..ed354473733 100644 --- a/src/srun/allocate.c +++ b/src/srun/allocate.c @@ -592,7 +592,6 @@ job_desc_msg_t * job_desc_msg_create_from_opts (void) { job_desc_msg_t *j = xmalloc(sizeof(*j)); - char buf[8192]; hostlist_t hl = NULL; slurm_init_job_desc_msg(j); @@ -617,15 +616,13 @@ job_desc_msg_create_from_opts (void) * not laying out tasks until step */ if(j->req_nodes) { hl = hostlist_create(j->req_nodes); - hostlist_ranged_string(hl, sizeof(buf), buf); xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = hostlist_ranged_string_xmalloc(hl); hostlist_uniq(hl); - hostlist_ranged_string(hl, sizeof(buf), buf); + xfree(j->req_nodes); + j->req_nodes = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); - xfree(j->req_nodes); - j->req_nodes = xstrdup(buf); } if(opt.distribution == SLURM_DIST_ARBITRARY diff --git a/src/srun/opt.c b/src/srun/opt.c index 54f93073b18..69863a754f5 100644 --- a/src/srun/opt.c +++ b/src/srun/opt.c @@ -1698,7 +1698,6 @@ static bool _opt_verify(void) int count = hostlist_count(hl); if(count > opt.max_nodes) { int i = 0; - char buf[8192]; error("Required nodelist includes more nodes than " "permitted by max-node count (%d > %d). " "Eliminating nodes from the nodelist.", @@ -1712,9 +1711,8 @@ static bool _opt_verify(void) break; i++; } - hostlist_ranged_string(hl, sizeof(buf), buf); xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = hostlist_ranged_string_xmalloc(hl); } hostlist_destroy(hl); } diff --git a/src/srun/srun_job.c b/src/srun/srun_job.c index 2b4898b09f5..80650b5f00e 100644 --- a/src/srun/srun_job.c +++ b/src/srun/srun_job.c @@ -147,7 +147,7 @@ job_step_create_allocation(resource_allocation_response_msg_t *resp) srun_job_t *job = NULL; allocation_info_t *ai = xmalloc(sizeof(*ai)); hostlist_t hl = NULL; - char buf[8192]; + char *buf = NULL; int count = 0; uint32_t alloc_count = 0; @@ -230,31 +230,30 @@ job_step_create_allocation(resource_allocation_response_msg_t *resp) hostlist_t tmp_hl = hostlist_copy(hl); int i=0; int diff = ai->nnodes - count; - hostlist_ranged_string(inc_hl, - sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(inc_hl); hostlist_delete(tmp_hl, buf); - while((node_name = hostlist_shift(tmp_hl)) - && (i < diff)) { + xfree(buf); + while ((node_name = hostlist_shift(tmp_hl)) && + (i < diff)) { hostlist_push(inc_hl, node_name); i++; } hostlist_destroy(tmp_hl); } - hostlist_ranged_string(inc_hl, sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(inc_hl); hostlist_destroy(inc_hl); xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = buf; } else { - if(count > ai->nnodes) { + if (count > ai->nnodes) { /* remove more nodes than needed for allocation */ int i=0; - for(i=count; i>ai->nnodes; i--) + for (i=count; i>ai->nnodes; i--) hostlist_delete_nth(hl, i); } - hostlist_ranged_string(hl, sizeof(buf), buf); xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = hostlist_ranged_string_xmalloc(hl); } hostlist_destroy(hl); @@ -280,21 +279,21 @@ job_step_create_allocation(resource_allocation_response_msg_t *resp) * opt.nodelist is what is used for the allocation. */ /* xfree(ai->nodelist); */ -/* ai->nodelist = xstrdup(buf); */ + /* ai->nodelist = xstrdup(buf); */ } /* get the correct number of hosts to run tasks on */ - if(opt.nodelist) { + if (opt.nodelist) { hl = hostlist_create(opt.nodelist); - if(opt.distribution != SLURM_DIST_ARBITRARY) + if (opt.distribution != SLURM_DIST_ARBITRARY) hostlist_uniq(hl); - if(!hostlist_count(hl)) { + if (!hostlist_count(hl)) { error("Hostlist is now nothing! Can not run job."); hostlist_destroy(hl); goto error; } - hostlist_ranged_string(hl, sizeof(buf), buf); + buf = hostlist_ranged_string_xmalloc(hl); count = hostlist_count(hl); hostlist_destroy(hl); /* Don't reset the ai->nodelist because that is the @@ -302,13 +301,13 @@ job_step_create_allocation(resource_allocation_response_msg_t *resp) * opt.nodelist is what is used for the allocation. */ /* xfree(ai->nodelist); */ -/* ai->nodelist = xstrdup(buf); */ + /* ai->nodelist = xstrdup(buf); */ xfree(opt.nodelist); - opt.nodelist = xstrdup(buf); + opt.nodelist = buf; } - if(opt.distribution == SLURM_DIST_ARBITRARY) { - if(count != opt.ntasks) { + if (opt.distribution == SLURM_DIST_ARBITRARY) { + if (count != opt.ntasks) { error("You asked for %d tasks but specified %d nodes", opt.ntasks, count); goto error; @@ -512,12 +511,14 @@ job_update_io_fnames(srun_job_t *job) static char * _normalize_hostlist(const char *hostlist) { + char *buf = NULL; hostlist_t hl = hostlist_create(hostlist); - char buf[4096]; - if (!hl || (hostlist_ranged_string(hl, 4096, buf) < 0)) + if (hl) + buf = hostlist_ranged_string_xmalloc(hl); + if (!hl || !buf) return xstrdup(hostlist); - return xstrdup(buf); + return buf; } diff --git a/src/sview/node_info.c b/src/sview/node_info.c index 2750c1a12b1..f806262f1e4 100644 --- a/src/sview/node_info.c +++ b/src/sview/node_info.c @@ -1599,7 +1599,6 @@ extern void select_admin_nodes(GtkTreeModel *model, { if(treeview) { char *old_value = NULL; - char tmp[1024]; hostlist_t hl = NULL; process_node_t process_node; memset(&process_node, 0, sizeof(process_node_t)); @@ -1615,8 +1614,7 @@ extern void select_admin_nodes(GtkTreeModel *model, hostlist_uniq(hl); hostlist_sort(hl); xfree(process_node.nodelist); - hostlist_ranged_string(hl, sizeof(tmp), tmp); - process_node.nodelist = xstrdup(tmp); + process_node.nodelist = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); if(!strcasecmp("Update Features", display_data->name)) { -- GitLab