Skip to content
Snippets Groups Projects
Commit 519897a1 authored by Christopher J. Morrone's avatar Christopher J. Morrone
Browse files

Have net_stream_listen() return the port number in HOST byte order,

and KEEP the port in host byte order until absolutely necessary to change
it back to network byte order.
parent c2232dc7
No related branches found
No related tags found
No related merge requests found
......@@ -570,8 +570,8 @@ static listen_t *_create_allocation_response_socket(char *interface_hostname)
return NULL;
}
listen->hostname = xstrdup(interface_hostname);
/* FIXME - screw it! I can't seem to get the port number through slurm_*
functions */
/* FIXME - screw it! I can't seem to get the port number through
slurm_* functions */
listen->port = ntohs(listen->address.sin_port);
fd_set_nonblocking(listen->fd);
......
......@@ -106,8 +106,6 @@ extern int slurm_spawn (slurm_step_ctx ctx, int *fd_array)
int i, rc = SLURM_SUCCESS;
uint16_t slurmd_debug = 0;
char *env_var;
/* hostlist_t hostlist = NULL; */
/* hostlist_iterator_t itr = NULL; */
int task_cnt = 0;
uint32_t *cpus = NULL;
slurm_step_layout_t *step_layout = ctx->step_resp->step_layout;
......@@ -154,9 +152,6 @@ extern int slurm_spawn (slurm_step_ctx ctx, int *fd_array)
req_array_ptr = xmalloc(sizeof(slurm_msg_t) *
step_layout->node_cnt);
//hostlist = hostlist_create(step_layout->node_list);
//itr = hostlist_iterator_create(hostlist);
for (i=0; i<step_layout->node_cnt; i++) {
spawn_task_request_msg_t *r = &msg_array_ptr[i];
slurm_msg_t *m = &req_array_ptr[i];
......@@ -179,7 +174,7 @@ extern int slurm_spawn (slurm_step_ctx ctx, int *fd_array)
r->global_task_id = step_layout->tids[i][0];
r->cpus_allocated = cpus[i];
r->srun_node_id = (uint32_t) i;
r->io_port = ntohs(sock_array[i]);
r->io_port = sock_array[i];
m->msg_type = REQUEST_SPAWN_TASK;
m->data = r;
......@@ -191,8 +186,6 @@ extern int slurm_spawn (slurm_step_ctx ctx, int *fd_array)
fd_array[i], r->io_port, i);
#endif
}
//hostlist_iterator_destroy(itr);
//hostlist_destroy(hostlist);
rc = _p_launch(req_array_ptr, ctx);
xfree(msg_array_ptr);
......@@ -222,6 +215,9 @@ slurm_spawn_kill (slurm_step_ctx ctx, uint16_t signal)
}
/*
* Returns the port number in host byte order.
*/
static int _sock_bind_wild(int sockfd)
{
socklen_t len;
......@@ -237,7 +233,7 @@ static int _sock_bind_wild(int sockfd)
len = sizeof(sin);
if (getsockname(sockfd, (struct sockaddr *) &sin, &len) < 0)
return (-1);
return (sin.sin_port);
return ntohs(sin.sin_port);
}
......
......@@ -94,7 +94,7 @@ slurm_step_ctx_create (const job_step_create_request_msg_t *user_step_req)
_free_step_req(step_req);
goto fail;
}
step_req->port = ntohs(port);
step_req->port = port;
step_req->host = xshort_hostname();
}
......
......@@ -1195,15 +1195,13 @@ client_io_handler_create(slurm_step_io_fds_t fds,
for (i = 0; i < cio->num_listen; i++) {
eio_obj_t *obj;
short port;
if (net_stream_listen(&cio->listensock[i],
&port) < 0) {
&cio->listenport[i]) < 0) {
fatal("unable to initialize stdio listen socket: %m");
}
cio->listenport[i] = ntohs(port);
debug("initialized stdio listening socket, port %d\n",
ntohs(cio->listenport[i]));
cio->listenport[i]);
/*net_set_low_water(cio->listensock[i], 140);*/
obj = _create_listensock_eio(cio->listensock[i], cio);
eio_new_initial_obj(cio->eio, obj);
......
......@@ -172,7 +172,7 @@ int slurm_step_launch (slurm_step_ctx ctx,
env_array_for_step(&env,
ctx->step_resp,
launcher_hostname,
htons(ctx->launch_state->resp_port[0]),
ctx->launch_state->resp_port[0],
ent->h_addr_list[0]);
xfree(launcher_hostname);
}
......@@ -234,7 +234,7 @@ int slurm_step_launch (slurm_step_ctx ctx,
launch.num_resp_port = ctx->launch_state->num_resp_port;
launch.resp_port = xmalloc(sizeof(uint16_t) * launch.num_resp_port);
for (i = 0; i < launch.num_resp_port; i++) {
launch.resp_port[i] = ntohs(ctx->launch_state->resp_port[i]);
launch.resp_port[i] = ctx->launch_state->resp_port[i];
}
_launch_tasks(ctx, &launch);
......
......@@ -57,7 +57,10 @@
# define NET_DEFAULT_BACKLOG 1024
#endif
static uint16_t _sock_bind_wild(int sockfd)
/*
* Returns the port number in host byte order.
*/
static short _sock_bind_wild(int sockfd)
{
socklen_t len;
struct sockaddr_in sin;
......@@ -72,14 +75,15 @@ static uint16_t _sock_bind_wild(int sockfd)
len = sizeof(sin);
if (getsockname(sockfd, (struct sockaddr *) &sin, &len) < 0)
return (-1);
return (uint16_t)sin.sin_port;
return ntohs(sin.sin_port);
}
/* open a stream socket on an ephemereal port and put it into
* the listen state. fd and port are filled in with the new
* socket's file descriptor and port #.
*
* NOTE: port is in network byte order!
* OUT fd - listening socket file descriptor number
* OUT port - TCP port number in host byte order
*/
int net_stream_listen(int *fd, short *port)
{
......
......@@ -45,7 +45,8 @@
* the listen state. fd and port are filled in with the new
* socket's file descriptor and port #.
*
* NOTE: port is in network byte order!
* OUT fd - listening socket file descriptor number
* OUT port - TCP port number in host byte order
*/
int net_stream_listen(int *fd, short *port);
......
......@@ -335,7 +335,7 @@ extern int gmpi_thr_create(srun_job_t *job)
return -1;
}
slurm_attr_destroy(&attr);
setenvf (NULL, "GMPI_PORT", "%u", ntohs(port));
setenvf (NULL, "GMPI_PORT", "%u", port);
setenvf (NULL, "GMPI_MAGIC", "%u", job->jobid);
setenvf (NULL, "GMPI_NP", "%d", job->ntasks);
setenvf (NULL, "GMPI_SHMEM", "1");
......
......@@ -80,19 +80,17 @@ extern salloc_msg_thread_t *msg_thr_create(uint16_t *port)
{
int sock = -1;
eio_obj_t *obj;
short port_tmp;
salloc_msg_thread_t *msg_thr = NULL;
debug("Entering _msg_thr_create()");
slurm_uid = (uid_t) slurm_get_slurm_user_id();
msg_thr = (salloc_msg_thread_t *)xmalloc(sizeof(salloc_msg_thread_t));
if (net_stream_listen(&sock, &port_tmp) < 0) {
if (net_stream_listen(&sock, (short *)port) < 0) {
error("unable to intialize step launch listening socket: %m");
xfree(msg_thr);
return NULL;
}
*port = ntohs(port_tmp);
debug("port from net_stream_listen is %hu", *port);
obj = eio_obj_create(sock, &message_socket_ops, NULL);
......
......@@ -418,7 +418,7 @@ static int _msg_thr_create(struct message_thread_state *mts, int num_nodes)
error("unable to intialize step launch listening socket: %m");
return SLURM_ERROR;
}
mts->resp_port[i] = ntohs(port);
mts->resp_port[i] = port;
obj = eio_obj_create(sock, &message_socket_ops, (void *)mts);
eio_new_initial_obj(mts->msg_handle, obj);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment