-
Notifications
You must be signed in to change notification settings - Fork 629
/
slurmstepd_job.c
717 lines (622 loc) · 20.1 KB
/
slurmstepd_job.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*****************************************************************************\
* src/slurmd/slurmstepd/slurmstepd_job.c - stepd_step_rec_t routines
* $Id$
*****************************************************************************
* Copyright (C) 2002-2007 The Regents of the University of California.
* Copyright (C) 2008-2010 Lawrence Livermore National Security.
* Copyright (C) 2013 Intel, Inc.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Mark Grondona <mgrondona@llnl.gov>.
* CODE-OCEC-09-009. All rights reserved.
*
* This file is part of SLURM, a resource management program.
* For details, see <http://slurm.schedmd.com/>.
* Please also read the included file: DISCLAIMER.
*
* SLURM is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* In addition, as a special exception, the copyright holders give permission
* to link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two. You must obey the GNU
* General Public License in all respects for all of the code used other than
* OpenSSL. If you modify file(s) with this exception, you may extend this
* exception to your version of the file(s), but you are not obligated to do
* so. If you do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source files in
* the program, then also delete it here.
*
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with SLURM; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#include <grp.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include "src/common/eio.h"
#include "src/common/fd.h"
#include "src/common/gres.h"
#include "src/common/log.h"
#include "src/common/node_select.h"
#include "src/common/slurm_jobacct_gather.h"
#include "src/common/slurm_acct_gather_profile.h"
#include "src/common/slurm_protocol_api.h"
#include "src/common/xassert.h"
#include "src/common/xmalloc.h"
#include "src/common/xstring.h"
#include "src/slurmd/slurmd/slurmd.h"
#include "src/slurmd/slurmstepd/io.h"
#include "src/slurmd/slurmstepd/fname.h"
#include "src/slurmd/slurmstepd/multi_prog.h"
#include "src/slurmd/slurmstepd/slurmstepd_job.h"
static char ** _array_copy(int n, char **src);
static void _array_free(char ***array);
static void _srun_info_destructor(void *arg);
static void _job_init_task_info(stepd_step_rec_t *job, uint32_t **gtid,
char *ifname, char *ofname, char *efname);
static void _task_info_destroy(stepd_step_task_info_t *t, uint16_t multi_prog);
/* returns 0 if invalid gid, otherwise returns 1. Set gid with
* correct gid if root launched job. Also set user_name
* if not already set. */
static int
_valid_uid_gid(uid_t uid, gid_t *gid, char **user_name)
{
struct passwd *pwd;
struct group *grp;
int i;
#ifdef HAVE_NATIVE_CRAY
/* already verified */
if (*user_name)
return 1;
#endif
znovu:
errno = 0;
pwd = getpwuid(uid);
if (!pwd) {
if (errno == EINTR)
goto znovu;
error("uid %ld not found on system", (long) uid);
slurm_seterrno(ESLURMD_UID_NOT_FOUND);
return 0;
}
if (!*user_name)
*user_name = xstrdup(pwd->pw_name);
if (pwd->pw_gid == *gid)
return 1;
grp = getgrgid(*gid);
if (!grp) {
error("gid %ld not found on system", (long)(*gid));
slurm_seterrno(ESLURMD_GID_NOT_FOUND);
return 0;
}
/* Allow user root to use any valid gid */
if (pwd->pw_uid == 0) {
pwd->pw_gid = *gid;
return 1;
}
for (i = 0; grp->gr_mem[i]; i++) {
if (!strcmp(pwd->pw_name, grp->gr_mem[i])) {
pwd->pw_gid = *gid;
return 1;
}
}
/* root user may have launched this job for this user, but
* root did not explicitly set the gid. This would set the
* gid to 0. In this case we should set the appropriate
* default gid for the user (from the passwd struct).
*/
if (*gid == 0) {
*gid = pwd->pw_gid;
return 1;
}
error("uid %ld is not a member of gid %ld",
(long)pwd->pw_uid, (long)(*gid));
slurm_seterrno(ESLURMD_GID_NOT_FOUND);
return 0;
}
/*
* return the default output filename for a batch job
*/
static char *
_batchfilename(stepd_step_rec_t *job, const char *name)
{
if (name == NULL) {
if (job->array_task_id == NO_VAL)
return fname_create(job, "slurm-%J.out", 0);
else
return fname_create(job, "slurm-%A_%a.out", 0);
} else
return fname_create(job, name, 0);
}
/*
* Expand a stdio file name.
*
* If "filename" is NULL it means that an eio object should be created
* for that stdio file rather than a directly connecting it to a file.
*
* If the "filename" is a valid task number in string form and the
* number matches "taskid", then NULL is returned so that an eio
* object will be used. If is a valid number, but it does not match
* "taskid", then the file descriptor will be connected to /dev/null.
*/
static char *
_expand_stdio_filename(char *filename, int gtaskid, stepd_step_rec_t *job)
{
int id;
if (filename == NULL)
return NULL;
id = fname_single_task_io(filename);
if (id < 0)
return fname_create(job, filename, gtaskid);
if (id >= job->ntasks) {
error("Task ID in filename is invalid");
return NULL;
}
if (id == gtaskid)
return NULL;
else
return xstrdup("/dev/null");
}
static void
_job_init_task_info(stepd_step_rec_t *job, uint32_t **gtid,
char *ifname, char *ofname, char *efname)
{
int i, node_id = job->nodeid;
char *in, *out, *err;
#if defined(HAVE_NATIVE_CRAY)
int j;
#endif
if (job->node_tasks == 0) {
error("User requested launch of zero tasks!");
job->task = NULL;
return;
}
#if defined(HAVE_NATIVE_CRAY)
for (i = 0; i < job->nnodes; i++) {
for (j = 1; j < job->task_cnts[i]; j++) {
if (gtid[i][j] != gtid[i][j-1] + 1)) {
job->non_smp = 1;
break;
}
}
}
#endif
job->task = (stepd_step_task_info_t **)
xmalloc(job->node_tasks * sizeof(stepd_step_task_info_t *));
for (i = 0; i < job->node_tasks; i++) {
in = _expand_stdio_filename(ifname, gtid[node_id][i], job);
out = _expand_stdio_filename(ofname, gtid[node_id][i], job);
err = _expand_stdio_filename(efname, gtid[node_id][i], job);
job->task[i] = task_info_create(i, gtid[node_id][i], in, out,
err);
if (!job->multi_prog) {
job->task[i]->argc = job->argc;
job->task[i]->argv = job->argv;
}
}
if (job->multi_prog) {
char *switch_type = slurm_get_switch_type();
if (!strcmp(switch_type, "switch/cray"))
multi_prog_parse(job, gtid);
xfree(switch_type);
for (i = 0; i < job->node_tasks; i++){
multi_prog_get_argv(job->argv[1], job->env,
gtid[node_id][i],
&job->task[i]->argc,
&job->task[i]->argv,
job->argc, job->argv);
}
}
}
static char **
_array_copy(int n, char **src)
{
char **dst = xmalloc((n+1) * sizeof(char *));
int i;
for (i = 0; i < n; i++) {
dst[i] = xstrdup(src[i]);
}
dst[n] = NULL;
return dst;
}
static void
_array_free(char ***array)
{
int i = 0;
while ((*array)[i] != NULL)
xfree((*array)[i++]);
xfree(*array);
*array = NULL;
}
/* destructor for list routines */
static void
_srun_info_destructor(void *arg)
{
srun_info_t *srun = (srun_info_t *)arg;
srun_info_destroy(srun);
}
static void
_task_info_destroy(stepd_step_task_info_t *t, uint16_t multi_prog)
{
slurm_mutex_lock(&t->mutex);
slurm_mutex_unlock(&t->mutex);
slurm_mutex_destroy(&t->mutex);
if (multi_prog) {
xfree(t->argv);
} /* otherwise, t->argv is a pointer to job->argv */
xfree(t);
}
/* create a slurmd job structure from a launch tasks message */
extern stepd_step_rec_t *
stepd_step_rec_create(launch_tasks_request_msg_t *msg, uint16_t protocol_version)
{
stepd_step_rec_t *job = NULL;
srun_info_t *srun = NULL;
slurm_addr_t resp_addr;
slurm_addr_t io_addr;
int i, nodeid = NO_VAL;
xassert(msg != NULL);
xassert(msg->complete_nodelist != NULL);
debug3("entering stepd_step_rec_create");
if (!_valid_uid_gid((uid_t)msg->uid, &(msg->gid), &(msg->user_name)))
return NULL;
if (acct_gather_check_acct_freq_task(msg->job_mem_lim, msg->acctg_freq))
return NULL;
job = xmalloc(sizeof(stepd_step_rec_t));
job->msg = msg;
#ifndef HAVE_FRONT_END
nodeid = nodelist_find(msg->complete_nodelist, conf->node_name);
job->node_name = xstrdup(conf->node_name);
#else
nodeid = 0;
job->node_name = xstrdup(msg->complete_nodelist);
#endif
if (nodeid < 0) {
error("couldn't find node %s in %s",
job->node_name, msg->complete_nodelist);
stepd_step_rec_destroy(job);
return NULL;
}
job->state = SLURMSTEPD_STEP_STARTING;
job->node_tasks = msg->tasks_to_launch[nodeid];
i = sizeof(uint16_t) * msg->nnodes;
job->task_cnts = xmalloc(i);
memcpy(job->task_cnts, msg->tasks_to_launch, i);
job->ntasks = msg->ntasks;
job->jobid = msg->job_id;
job->stepid = msg->job_step_id;
job->uid = (uid_t) msg->uid;
job->user_name = xstrdup(msg->user_name);
job->gid = (gid_t) msg->gid;
job->cwd = xstrdup(msg->cwd);
job->task_dist = msg->task_dist;
job->cpu_bind_type = msg->cpu_bind_type;
job->cpu_bind = xstrdup(msg->cpu_bind);
job->mem_bind_type = msg->mem_bind_type;
job->mem_bind = xstrdup(msg->mem_bind);
job->cpu_freq_min = msg->cpu_freq_min;
job->cpu_freq_max = msg->cpu_freq_max;
job->cpu_freq_gov = msg->cpu_freq_gov;
job->ckpt_dir = xstrdup(msg->ckpt_dir);
job->restart_dir = xstrdup(msg->restart_dir);
job->cpus_per_task = msg->cpus_per_task;
job->env = _array_copy(msg->envc, msg->env);
job->array_job_id = msg->job_id;
job->array_task_id = NO_VAL;
for (i = 0; i < msg->envc; i++) {
/* 1234567890123456789 */
if (!strncmp(msg->env[i], "SLURM_ARRAY_JOB_ID=", 19))
job->array_job_id = atoi(msg->env[i] + 19);
/* 12345678901234567890 */
if (!strncmp(msg->env[i], "SLURM_ARRAY_TASK_ID=", 20))
job->array_task_id = atoi(msg->env[i] + 20);
}
job->eio = eio_handle_create(0);
job->sruns = list_create((ListDelF) _srun_info_destructor);
job->clients = list_create(NULL); /* FIXME! Needs destructor */
job->stdout_eio_objs = list_create(NULL); /* FIXME! Needs destructor */
job->stderr_eio_objs = list_create(NULL); /* FIXME! Needs destructor */
job->free_incoming = list_create(NULL); /* FIXME! Needs destructor */
job->incoming_count = 0;
job->free_outgoing = list_create(NULL); /* FIXME! Needs destructor */
job->outgoing_count = 0;
job->outgoing_cache = list_create(NULL); /* FIXME! Needs destructor */
job->envtp = xmalloc(sizeof(env_t));
job->envtp->jobid = -1;
job->envtp->stepid = -1;
job->envtp->procid = -1;
job->envtp->localid = -1;
job->envtp->nodeid = -1;
job->envtp->distribution = 0;
job->envtp->cpu_bind_type = 0;
job->envtp->cpu_bind = NULL;
job->envtp->mem_bind_type = 0;
job->envtp->mem_bind = NULL;
job->envtp->ckpt_dir = NULL;
if (!msg->resp_port)
msg->num_resp_port = 0;
if (msg->num_resp_port) {
job->envtp->comm_port =
msg->resp_port[nodeid % msg->num_resp_port];
memcpy(&resp_addr, &msg->orig_addr, sizeof(slurm_addr_t));
slurm_set_addr(&resp_addr,
msg->resp_port[nodeid % msg->num_resp_port],
NULL);
}
job->user_managed_io = msg->user_managed_io;
if (!msg->io_port)
msg->user_managed_io = 1;
if (!msg->user_managed_io) {
memcpy(&io_addr, &msg->orig_addr, sizeof(slurm_addr_t));
slurm_set_addr(&io_addr,
msg->io_port[nodeid % msg->num_io_port],
NULL);
}
srun = srun_info_create(msg->cred, &resp_addr, &io_addr,
protocol_version);
job->buffered_stdio = msg->buffered_stdio;
job->labelio = msg->labelio;
job->profile = msg->profile;
job->task_prolog = xstrdup(msg->task_prolog);
job->task_epilog = xstrdup(msg->task_epilog);
job->argc = msg->argc;
job->argv = _array_copy(job->argc, msg->argv);
job->nnodes = msg->nnodes;
job->nodeid = nodeid;
job->debug = msg->slurmd_debug;
job->cpus = msg->node_cpus;
job->job_core_spec = msg->job_core_spec;
/* This needs to happen before acct_gather_profile_startpoll
and only really looks at the profile in the job.
*/
acct_gather_profile_g_node_step_start(job);
acct_gather_profile_startpoll(msg->acctg_freq,
conf->job_acct_gather_freq);
job->multi_prog = msg->multi_prog;
job->timelimit = (time_t) -1;
job->task_flags = msg->task_flags;
job->switch_job = msg->switch_job;
job->pty = msg->pty;
job->open_mode = msg->open_mode;
job->options = msg->options;
format_core_allocs(msg->cred, conf->node_name, conf->cpus,
&job->job_alloc_cores, &job->step_alloc_cores,
&job->job_mem, &job->step_mem);
/* If users have configured MemLimitEnforce=no
* in their slurm.conf keep going.
*/
if (job->step_mem
&& conf->mem_limit_enforce) {
jobacct_gather_set_mem_limit(job->jobid, job->stepid,
job->step_mem);
} else if (job->job_mem
&& conf->mem_limit_enforce) {
jobacct_gather_set_mem_limit(job->jobid, job->stepid,
job->job_mem);
}
#ifdef HAVE_ALPS_CRAY
/* This is only used for Cray emulation mode where slurmd is used to
* launch job steps. On a real Cray system, ALPS is used to launch
* the tasks instead of SLURM. SLURM's task launch RPC does NOT
* contain the reservation ID, so just use some non-zero value here
* for testing purposes. */
job->resv_id = 1;
select_g_select_jobinfo_set(msg->select_jobinfo, SELECT_JOBDATA_RESV_ID,
&job->resv_id);
#endif
get_cred_gres(msg->cred, conf->node_name,
&job->job_gres_list, &job->step_gres_list);
list_append(job->sruns, (void *) srun);
_job_init_task_info(job, msg->global_task_ids,
msg->ifname, msg->ofname, msg->efname);
return job;
}
extern stepd_step_rec_t *
batch_stepd_step_rec_create(batch_job_launch_msg_t *msg)
{
stepd_step_rec_t *job;
srun_info_t *srun = NULL;
char *in_name;
xassert(msg != NULL);
debug3("entering batch_stepd_step_rec_create");
if (!_valid_uid_gid((uid_t)msg->uid, &(msg->gid), &(msg->user_name)))
return NULL;
if (acct_gather_check_acct_freq_task(msg->job_mem, msg->acctg_freq))
return NULL;
job = xmalloc(sizeof(stepd_step_rec_t));
job->state = SLURMSTEPD_STEP_STARTING;
if (msg->cpus_per_node)
job->cpus = msg->cpus_per_node[0];
job->node_tasks = 1;
job->ntasks = msg->ntasks;
job->jobid = msg->job_id;
job->stepid = msg->step_id;
job->array_job_id = msg->array_job_id;
job->array_task_id = msg->array_task_id;
job->job_core_spec = msg->job_core_spec;
job->batch = true;
job->node_name = xstrdup(conf->node_name);
/* This needs to happen before acct_gather_profile_startpoll
and only really looks at the profile in the job.
*/
acct_gather_profile_g_node_step_start(job);
/* needed for the jobacct_gather plugin to start */
acct_gather_profile_startpoll(msg->acctg_freq,
conf->job_acct_gather_freq);
job->multi_prog = 0;
job->open_mode = msg->open_mode;
job->overcommit = (bool) msg->overcommit;
job->uid = (uid_t) msg->uid;
job->user_name = xstrdup(msg->user_name);
job->gid = (gid_t) msg->gid;
job->cwd = xstrdup(msg->work_dir);
job->ckpt_dir = xstrdup(msg->ckpt_dir);
job->restart_dir = xstrdup(msg->restart_dir);
job->env = _array_copy(msg->envc, msg->environment);
job->eio = eio_handle_create(0);
job->sruns = list_create((ListDelF) _srun_info_destructor);
job->envtp = xmalloc(sizeof(env_t));
job->envtp->jobid = -1;
job->envtp->stepid = -1;
job->envtp->procid = -1;
job->envtp->localid = -1;
job->envtp->nodeid = -1;
job->envtp->distribution = 0;
job->cpu_bind_type = msg->cpu_bind_type;
job->cpu_bind = xstrdup(msg->cpu_bind);
job->envtp->mem_bind_type = 0;
job->envtp->mem_bind = NULL;
job->envtp->ckpt_dir = NULL;
job->envtp->restart_cnt = msg->restart_cnt;
if (msg->cpus_per_node)
job->cpus = msg->cpus_per_node[0];
format_core_allocs(msg->cred, conf->node_name, conf->cpus,
&job->job_alloc_cores, &job->step_alloc_cores,
&job->job_mem, &job->step_mem);
if (job->step_mem
&& conf->mem_limit_enforce)
jobacct_gather_set_mem_limit(job->jobid, NO_VAL, job->step_mem);
else if (job->job_mem
&& conf->mem_limit_enforce)
jobacct_gather_set_mem_limit(job->jobid, NO_VAL, job->job_mem);
get_cred_gres(msg->cred, conf->node_name,
&job->job_gres_list, &job->step_gres_list);
srun = srun_info_create(NULL, NULL, NULL, (uint16_t)NO_VAL);
list_append(job->sruns, (void *) srun);
if (msg->argc) {
job->argc = msg->argc;
job->argv = _array_copy(job->argc, msg->argv);
} else {
job->argc = 1;
/* job script has not yet been written out to disk --
* argv will be filled in later by _make_batch_script()
*/
job->argv = (char **) xmalloc(2 * sizeof(char *));
}
job->task = xmalloc(sizeof(stepd_step_task_info_t *));
if (msg->std_err == NULL)
msg->std_err = xstrdup(msg->std_out);
if (msg->std_in == NULL)
in_name = xstrdup("/dev/null");
else
in_name = fname_create(job, msg->std_in, 0);
job->task[0] = task_info_create(0, 0,
in_name,
_batchfilename(job, msg->std_out),
_batchfilename(job, msg->std_err));
job->task[0]->argc = job->argc;
job->task[0]->argv = job->argv;
#ifdef HAVE_ALPS_CRAY
select_g_select_jobinfo_get(msg->select_jobinfo, SELECT_JOBDATA_RESV_ID,
&job->resv_id);
#endif
return job;
}
extern void
stepd_step_rec_destroy(stepd_step_rec_t *job)
{
int i;
_array_free(&job->env);
_array_free(&job->argv);
for (i = 0; i < job->node_tasks; i++)
_task_info_destroy(job->task[i], job->multi_prog);
list_destroy(job->sruns);
xfree(job->envtp);
xfree(job->node_name);
mpmd_free(job);
xfree(job->task_prolog);
xfree(job->task_epilog);
xfree(job->job_alloc_cores);
xfree(job->step_alloc_cores);
xfree(job->task_cnts);
xfree(job->user_name);
xfree(job);
}
extern srun_info_t *
srun_info_create(slurm_cred_t *cred, slurm_addr_t *resp_addr,
slurm_addr_t *ioaddr, uint16_t protocol_version)
{
char *data = NULL;
uint32_t len = 0;
srun_info_t *srun = xmalloc(sizeof(srun_info_t));
srun_key_t *key = xmalloc(sizeof(srun_key_t));
srun->key = key;
if (!protocol_version || (protocol_version == (uint16_t)NO_VAL))
protocol_version = SLURM_PROTOCOL_VERSION;
srun->protocol_version = protocol_version;
/*
* If no credential was provided, return the empty
* srun info object. (This is used, for example, when
* creating a batch job structure)
*/
if (!cred) return srun;
slurm_cred_get_signature(cred, &data, &len);
len = len > SLURM_IO_KEY_SIZE ? SLURM_IO_KEY_SIZE : len;
if (data != NULL) {
memcpy((void *) key->data, data, len);
if (len < SLURM_IO_KEY_SIZE)
memset( (void *) (key->data + len), 0,
SLURM_IO_KEY_SIZE - len);
}
if (ioaddr != NULL)
srun->ioaddr = *ioaddr;
if (resp_addr != NULL)
srun->resp_addr = *resp_addr;
return srun;
}
extern void
srun_info_destroy(srun_info_t *srun)
{
xfree(srun->key);
xfree(srun);
}
extern stepd_step_task_info_t *
task_info_create(int taskid, int gtaskid,
char *ifname, char *ofname, char *efname)
{
stepd_step_task_info_t *t = xmalloc(sizeof(stepd_step_task_info_t));
xassert(taskid >= 0);
xassert(gtaskid >= 0);
slurm_mutex_init(&t->mutex);
slurm_mutex_lock(&t->mutex);
t->state = STEPD_STEP_TASK_INIT;
t->id = taskid;
t->gtid = gtaskid;
t->pid = (pid_t) -1;
t->ifname = ifname;
t->ofname = ofname;
t->efname = efname;
t->stdin_fd = -1;
t->to_stdin = -1;
t->stdout_fd = -1;
t->from_stdout = -1;
t->stderr_fd = -1;
t->from_stderr = -1;
t->in = NULL;
t->out = NULL;
t->err = NULL;
t->killed_by_cmd = false;
t->aborted = false;
t->esent = false;
t->exited = false;
t->estatus = -1;
t->argc = 0;
t->argv = NULL;
slurm_mutex_unlock(&t->mutex);
return t;
}