-
Notifications
You must be signed in to change notification settings - Fork 26
/
step_mgr.c
778 lines (683 loc) · 22.6 KB
/
step_mgr.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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/*****************************************************************************\
* step_mgr.c - manage the job step information of slurm
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Morris Jette <jette1@llnl.gov>, Joseph Ekstrom <ekstrom1@llnl.gov>
* UCRL-CODE-2002-040.
*
* This file is part of SLURM, a resource management program.
* For details, see <http://www.llnl.gov/linux/slurm/>.
*
* 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.
*
* 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <slurm/slurm_errno.h>
#include "src/common/bitstring.h"
#include "src/common/checkpoint.h"
#include "src/common/slurm_protocol_interface.h"
#include "src/common/switch.h"
#include "src/common/xstring.h"
#include "src/slurmctld/agent.h"
#include "src/slurmctld/locks.h"
#include "src/slurmctld/slurmctld.h"
#define MAX_RETRIES 10
static int _job_step_ckpt_error(struct step_record *step_ptr, slurm_fd conn_fd);
static void _pack_ctld_job_step_info(struct step_record *step, Buf buffer);
static bitstr_t * _pick_step_nodes (struct job_record *job_ptr,
step_specs *step_spec );
/*
* create_step_record - create an empty step_record for the specified job.
* IN job_ptr - pointer to job table entry to have step record added
* RET a pointer to the record or NULL if error
* NOTE: allocates memory that should be xfreed with delete_step_record
*/
struct step_record *
create_step_record (struct job_record *job_ptr)
{
struct step_record *step_ptr;
xassert(job_ptr);
step_ptr = (struct step_record *) xmalloc (sizeof (struct step_record));
last_job_update = time(NULL);
step_ptr->job_ptr = job_ptr;
step_ptr->step_id = (job_ptr->next_step_id)++;
step_ptr->start_time = time ( NULL ) ;
if (list_append (job_ptr->step_list, step_ptr) == NULL)
fatal ("create_step_record: unable to allocate memory");
return step_ptr;
}
/*
* delete_all_step_records - delete all step record for specified job_ptr
* IN job_ptr - pointer to job table entry to have step record added
*/
void
delete_all_step_records (struct job_record *job_ptr)
{
ListIterator step_iterator;
struct step_record *step_ptr;
xassert(job_ptr);
step_iterator = list_iterator_create (job_ptr->step_list);
last_job_update = time(NULL);
while ((step_ptr = (struct step_record *) list_next (step_iterator))) {
list_remove (step_iterator);
switch_free_jobinfo(step_ptr->switch_job);
checkpoint_free_jobinfo(step_ptr->check_job);
xfree(step_ptr->host);
xfree(step_ptr->step_node_list);
FREE_NULL_BITMAP(step_ptr->step_node_bitmap);
xfree(step_ptr);
}
list_iterator_destroy (step_iterator);
}
/*
* delete_step_record - delete record for job step for specified job_ptr
* and step_id
* IN job_ptr - pointer to job table entry to have step record removed
* IN step_id - id of the desired job step
* RET 0 on success, errno otherwise
*/
int
delete_step_record (struct job_record *job_ptr, uint32_t step_id)
{
ListIterator step_iterator;
struct step_record *step_ptr;
int error_code;
xassert(job_ptr);
error_code = ENOENT;
step_iterator = list_iterator_create (job_ptr->step_list);
last_job_update = time(NULL);
while ((step_ptr = (struct step_record *) list_next (step_iterator))) {
if (step_ptr->step_id == step_id) {
list_remove (step_iterator);
switch_free_jobinfo (step_ptr->switch_job);
checkpoint_free_jobinfo (step_ptr->check_job);
xfree(step_ptr->host);
xfree(step_ptr->step_node_list);
FREE_NULL_BITMAP(step_ptr->step_node_bitmap);
xfree(step_ptr);
error_code = 0;
break;
}
}
list_iterator_destroy (step_iterator);
return error_code;
}
/*
* dump_step_desc - dump the incoming step initiate request message
* IN step_spec - job step request specification from RPC
*/
void
dump_step_desc(step_specs *step_spec)
{
if (step_spec == NULL)
return;
debug3("StepDesc: user_id=%u job_id=%u node_count=%u, cpu_count=%u",
step_spec->user_id, step_spec->job_id,
step_spec->node_count, step_spec->cpu_count);
debug3(" num_tasks=%u relative=%u task_dist=%u node_list=%s",
step_spec->num_tasks, step_spec->relative,
step_spec->task_dist, step_spec->node_list);
debug3(" host=%s port=%u",
step_spec->host, step_spec->port);
}
/*
* find_step_record - return a pointer to the step record with the given
* job_id and step_id
* IN job_ptr - pointer to job table entry to have step record added
* IN step_id - id of the desired job step
* RET pointer to the job step's record, NULL on error
*/
struct step_record *
find_step_record(struct job_record *job_ptr, uint16_t step_id)
{
ListIterator step_iterator;
struct step_record *step_ptr;
if (job_ptr == NULL)
return NULL;
step_iterator = list_iterator_create (job_ptr->step_list);
while ((step_ptr = (struct step_record *) list_next (step_iterator))) {
if (step_ptr->step_id == step_id) {
break;
}
}
list_iterator_destroy (step_iterator);
return step_ptr;
}
/*
* job_step_signal - signal the specified job step
* IN job_id - id of the job to be cancelled
* IN step_id - id of the job step to be cancelled
* IN signal - user id of user issuing the RPC
* IN uid - user id of user issuing the RPC
* RET 0 on success, otherwise ESLURM error code
* global: job_list - pointer global job list
* last_job_update - time of last job table update
*/
int job_step_signal(uint32_t job_id, uint32_t step_id,
uint16_t signal, uid_t uid)
{
struct job_record *job_ptr;
struct step_record *step_ptr;
job_ptr = find_job_record(job_id);
if (job_ptr == NULL) {
error("job_step_cancel: invalid job id %u", job_id);
return ESLURM_INVALID_JOB_ID;
}
if (IS_JOB_FINISHED(job_ptr))
return ESLURM_ALREADY_DONE;
if ((job_ptr->user_id != uid) && (uid != 0) && (uid != getuid())) {
error("Security violation, JOB_CANCEL RPC from uid %d",
uid);
return ESLURM_USER_ID_MISSING;
}
step_ptr = find_step_record(job_ptr, (uint16_t)step_id);
if (step_ptr == NULL) {
info("job_step_cancel step %u.%u not found",
job_id, step_id);
return ESLURM_INVALID_JOB_ID;
}
signal_step_tasks(step_ptr, signal);
return SLURM_SUCCESS;
}
/*
* signal_step_tasks - send specific signal to specific job step
* IN step_ptr - step record pointer
* IN signal - signal to send
*/
void signal_step_tasks(struct step_record *step_ptr, uint16_t signal)
{
int i;
kill_tasks_msg_t *kill_tasks_msg;
agent_arg_t *agent_args;
int buf_rec_size = 0;
xassert(step_ptr);
agent_args = xmalloc(sizeof(agent_arg_t));
agent_args->msg_type = REQUEST_KILL_TASKS;
agent_args->retry = 1;
kill_tasks_msg = xmalloc(sizeof(kill_tasks_msg_t));
kill_tasks_msg->job_id = step_ptr->job_ptr->job_id;
kill_tasks_msg->job_step_id = step_ptr->step_id;
kill_tasks_msg->signal = signal;
for (i = 0; i < node_record_count; i++) {
if (bit_test(step_ptr->step_node_bitmap, i) == 0)
continue;
if ((agent_args->node_count + 1) > buf_rec_size) {
buf_rec_size += 128;
xrealloc((agent_args->slurm_addr),
(sizeof(struct sockaddr_in) *
buf_rec_size));
xrealloc((agent_args->node_names),
(MAX_NAME_LEN * buf_rec_size));
}
agent_args->slurm_addr[agent_args->node_count] =
node_record_table_ptr[i].slurm_addr;
strncpy(&agent_args->
node_names[MAX_NAME_LEN * agent_args->node_count],
node_record_table_ptr[i].name, MAX_NAME_LEN);
agent_args->node_count++;
}
if (agent_args->node_count == 0) {
xfree(kill_tasks_msg);
xfree(agent_args);
return;
}
agent_args->msg_args = kill_tasks_msg;
agent_queue_request(agent_args);
return;
}
/*
* job_step_complete - note normal completion the specified job step
* IN job_id - id of the job to be completed
* IN step_id - id of the job step to be completed
* IN uid - user id of user issuing the RPC
* IN requeue - job should be run again if possible
* IN job_return_code - job's return code, if set then set state to JOB_FAILED
* RET 0 on success, otherwise ESLURM error code
* global: job_list - pointer global job list
* last_job_update - time of last job table update
*/
int job_step_complete(uint32_t job_id, uint32_t step_id, uid_t uid,
bool requeue, uint32_t job_return_code)
{
struct job_record *job_ptr;
int error_code;
job_ptr = find_job_record(job_id);
if (job_ptr == NULL) {
info("job_step_complete: invalid job id %u", job_id);
return ESLURM_INVALID_JOB_ID;
}
if ((job_ptr->kill_on_step_done) &&
(list_count(job_ptr->step_list) <= 1))
return job_complete(job_id, uid, requeue, job_return_code);
if (IS_JOB_FINISHED(job_ptr))
return ESLURM_ALREADY_DONE;
if ((job_ptr->user_id != uid) && (uid != 0) && (uid != getuid())) {
error("Security violation, JOB_COMPLETE RPC from uid %d",
uid);
return ESLURM_USER_ID_MISSING;
}
last_job_update = time(NULL);
error_code = delete_step_record(job_ptr, step_id);
if (error_code == ENOENT) {
info("job_step_complete step %u.%u not found", job_id,
step_id);
return ESLURM_ALREADY_DONE;
}
return SLURM_SUCCESS;
}
/*
* _pick_step_nodes - select nodes for a job step that satify its requirements
* we satify the super-set of constraints.
* IN job_ptr - pointer to job to have new step started
* IN step_spec - job step specification
* global: node_record_table_ptr - pointer to global node table
* NOTE: returns all of a job's nodes if step_spec->node_count == INFINITE
* NOTE: returned bitmap must be freed by the caller using bit_free()
*/
static bitstr_t *
_pick_step_nodes (struct job_record *job_ptr, step_specs *step_spec ) {
bitstr_t *nodes_avail = NULL, *nodes_picked = NULL, *node_tmp = NULL;
int error_code, nodes_picked_cnt = 0, cpus_picked_cnt, i;
if (job_ptr->node_bitmap == NULL)
return NULL;
nodes_avail = bit_copy (job_ptr->node_bitmap);
if (nodes_avail == NULL)
fatal("bit_copy malloc failure");
bit_and (nodes_avail, avail_node_bitmap);
if ( step_spec->node_count == INFINITE) /* use all nodes */
return nodes_avail;
if (step_spec->node_list) {
error_code = node_name2bitmap (step_spec->node_list, false,
&nodes_picked);
if (error_code) {
info ("_pick_step_nodes: invalid node list %s",
step_spec->node_list);
goto cleanup;
}
if (bit_super_set (nodes_picked, job_ptr->node_bitmap) == 0) {
info ("_pick_step_nodes: requested nodes %s not part "
"of job %u",
step_spec->node_list, job_ptr->job_id);
goto cleanup;
}
}
else if (step_spec->relative) {
/* Remove first (step_spec->relative) nodes from
* available list */
bitstr_t *relative_nodes = NULL;
relative_nodes =
bit_pick_cnt (nodes_avail, step_spec->relative);
if (relative_nodes == NULL) {
info ("_pick_step_nodes: Invalid relative value (%u) for job %u",
step_spec->relative, job_ptr->job_id);
goto cleanup;
}
bit_not (relative_nodes);
bit_and (nodes_avail, relative_nodes);
bit_free (relative_nodes);
}
else {
nodes_picked = bit_alloc (bit_size (nodes_avail) );
if (nodes_picked == NULL)
fatal("bit_alloc malloc failure");
}
/* if user specifies step needs a specific processor count and */
/* all nodes have the same processor count, just translate this to */
/* a node count */
if (step_spec->cpu_count && (job_ptr->num_cpu_groups == 1)) {
i = (step_spec->cpu_count + (job_ptr->cpus_per_node[0] - 1) )
/ job_ptr->cpus_per_node[0];
step_spec->node_count = (i > step_spec->node_count) ?
i : step_spec->node_count ;
step_spec->cpu_count = 0;
}
if (step_spec->node_count) {
nodes_picked_cnt = bit_set_count(nodes_picked);
if (step_spec->node_count > nodes_picked_cnt) {
node_tmp = bit_pick_cnt(nodes_avail,
(step_spec->node_count -
nodes_picked_cnt));
if (node_tmp == NULL)
goto cleanup;
bit_or (nodes_picked, node_tmp);
bit_not (node_tmp);
bit_and (nodes_avail, node_tmp);
bit_free (node_tmp);
node_tmp = NULL;
nodes_picked_cnt = step_spec->node_count;
}
}
if (step_spec->cpu_count) {
cpus_picked_cnt = count_cpus(nodes_picked);
if (step_spec->cpu_count > cpus_picked_cnt) {
int first_bit, last_bit;
first_bit = bit_ffs(nodes_avail);
last_bit = bit_fls(nodes_avail);
for (i = first_bit; i <= last_bit; i++) {
if (bit_test (nodes_avail, i) != 1)
continue;
bit_set (nodes_picked, i);
cpus_picked_cnt +=
node_record_table_ptr[i].cpus;
if (cpus_picked_cnt >= step_spec->cpu_count)
break;
}
if (step_spec->cpu_count > cpus_picked_cnt)
goto cleanup;
}
}
FREE_NULL_BITMAP(nodes_avail);
return nodes_picked;
cleanup:
FREE_NULL_BITMAP(nodes_avail);
FREE_NULL_BITMAP(nodes_picked);
return NULL;
}
/*
* step_create - creates a step_record in step_specs->job_id, sets up the
* according to the step_specs.
* IN step_specs - job step specifications
* OUT new_step_record - pointer to the new step_record (NULL on error)
* IN kill_job_when_step_done - if set kill the job on step completion
* RET - 0 or error code
* NOTE: don't free the returned step_record because that is managed through
* the job.
*/
int
step_create ( step_specs *step_specs, struct step_record** new_step_record,
bool kill_job_when_step_done )
{
struct step_record *step_ptr;
struct job_record *job_ptr;
bitstr_t *nodeset;
int node_count;
time_t now = time(NULL);
*new_step_record = NULL;
job_ptr = find_job_record (step_specs->job_id);
if (job_ptr == NULL)
return ESLURM_INVALID_JOB_ID ;
if ((step_specs->user_id != job_ptr->user_id) &&
(step_specs->user_id != 0))
return ESLURM_ACCESS_DENIED ;
if (IS_JOB_PENDING(job_ptr))
return ESLURM_INVALID_JOB_ID ;
if (IS_JOB_FINISHED(job_ptr) ||
(job_ptr->end_time <= time(NULL)))
return ESLURM_ALREADY_DONE;
if ((step_specs->task_dist != SLURM_DIST_CYCLIC) &&
(step_specs->task_dist != SLURM_DIST_BLOCK))
return ESLURM_BAD_DIST;
if (job_ptr->kill_on_step_done)
/* Don't start more steps, job already being cancelled */
return ESLURM_ALREADY_DONE;
job_ptr->kill_on_step_done = kill_job_when_step_done;
job_ptr->time_last_active = now;
nodeset = _pick_step_nodes (job_ptr, step_specs);
if (nodeset == NULL)
return ESLURM_REQUESTED_NODE_CONFIG_UNAVAILABLE ;
node_count = bit_set_count(nodeset);
if (step_specs->num_tasks == NO_VAL) {
if (step_specs->cpu_count != NO_VAL)
step_specs->num_tasks = step_specs->cpu_count;
else
step_specs->num_tasks = node_count;
}
if ((step_specs->num_tasks < 1) ||
(step_specs->num_tasks > (node_count*MAX_TASKS_PER_NODE)))
return ESLURM_BAD_TASK_COUNT;
step_ptr = create_step_record (job_ptr);
if (step_ptr == NULL)
fatal ("create_step_record failed with no memory");
/* set the step_record values */
step_ptr->step_node_list = bitmap2node_name(nodeset);
step_ptr->step_node_bitmap = nodeset;
step_ptr->cyclic_alloc =
(uint16_t) (step_specs->task_dist == SLURM_DIST_CYCLIC);
step_ptr->num_tasks = step_specs->num_tasks;
step_ptr->time_last_active = now;
step_ptr->port = step_specs->port;
step_ptr->host = xstrdup(step_specs->host);
if (switch_alloc_jobinfo (&step_ptr->switch_job) < 0)
fatal ("step_create: switch_alloc_jobinfo error");
if (switch_build_jobinfo(step_ptr->switch_job,
step_ptr->step_node_list,
step_specs->num_tasks,
step_ptr->cyclic_alloc) < 0) {
error("switch_build_jobinfo: %m");
delete_step_record (job_ptr, step_ptr->step_id);
return ESLURM_INTERCONNECT_FAILURE;
}
if (checkpoint_alloc_jobinfo (&step_ptr->check_job) < 0)
fatal ("step_create: checkpoint_alloc_jobinfo error");
*new_step_record = step_ptr;
return SLURM_SUCCESS;
}
/* Pack the data for a specific job step record
* IN step - pointer to a job step record
* IN/OUT buffer - location to store data, pointers automatically advanced
*/
static void _pack_ctld_job_step_info(struct step_record *step, Buf buffer)
{
pack_job_step_info_members(step->job_ptr->job_id,
step->step_id,
step->job_ptr->user_id,
step->num_tasks,
step->start_time,
step->job_ptr->partition,
step->step_node_list, buffer);
}
/*
* pack_ctld_job_step_info_response_msg - packs job step info
* IN job_id - specific id or zero for all
* IN step_id - specific id or zero for all
* IN uid - user issuing request
* IN show_flags - job step filtering options
* OUT buffer - location to store data, pointers automatically advanced
* RET - 0 or error code
* NOTE: MUST free_buf buffer
*/
extern int pack_ctld_job_step_info_response_msg(uint32_t job_id,
uint32_t step_id, uid_t uid,
uint16_t show_flags, Buf buffer)
{
ListIterator job_iterator;
ListIterator step_iterator;
int error_code = 0;
uint32_t steps_packed = 0, tmp_offset;
struct step_record *step_ptr;
struct job_record *job_ptr;
time_t now = time(NULL);
pack_time(now, buffer);
pack32(steps_packed, buffer); /* steps_packed placeholder */
part_filter_set(uid);
if (job_id == 0) {
/* Return all steps for all jobs */
job_iterator = list_iterator_create(job_list);
while ((job_ptr =
(struct job_record *)
list_next(job_iterator))) {
if (((show_flags & SHOW_ALL) == 0) &&
(job_ptr->part_ptr) &&
(job_ptr->part_ptr->hidden))
continue;
step_iterator =
list_iterator_create(job_ptr->step_list);
while ((step_ptr =
(struct step_record *)
list_next(step_iterator))) {
_pack_ctld_job_step_info(step_ptr, buffer);
steps_packed++;
}
list_iterator_destroy(step_iterator);
}
list_iterator_destroy(job_iterator);
} else if (step_id == 0) {
/* Return all steps for specific job_id */
job_ptr = find_job_record(job_id);
if (((show_flags & SHOW_ALL) == 0) &&
(job_ptr->part_ptr) &&
(job_ptr->part_ptr->hidden))
job_ptr = NULL;
if (job_ptr) {
step_iterator =
list_iterator_create(job_ptr->step_list);
while ((step_ptr =
(struct step_record *)
list_next(step_iterator))) {
_pack_ctld_job_step_info(step_ptr, buffer);
steps_packed++;
}
list_iterator_destroy(step_iterator);
} else
error_code = ESLURM_INVALID_JOB_ID;
} else {
/* Return data for specific job_id.step_id */
job_ptr = find_job_record(job_id);
if (((show_flags & SHOW_ALL) == 0) &&
(job_ptr->part_ptr) &&
(job_ptr->part_ptr->hidden))
job_ptr = NULL;
step_ptr = find_step_record(job_ptr, step_id);
if (step_ptr == NULL)
error_code = ESLURM_INVALID_JOB_ID;
else {
_pack_ctld_job_step_info(step_ptr, buffer);
steps_packed++;
}
}
part_filter_clear();
/* put the real record count in the message body header */
tmp_offset = get_buf_offset(buffer);
set_buf_offset(buffer, 0);
pack_time(now, buffer);
pack32(steps_packed, buffer);
set_buf_offset(buffer, tmp_offset);
return error_code;
}
/*
* step_on_node - determine if the specified job has any job steps allocated to
* the specified node
* IN job_ptr - pointer to an active job record
* IN node_ptr - pointer to a node record
* RET true of job has step on the node, false otherwise
*/
bool step_on_node(struct job_record *job_ptr, struct node_record *node_ptr)
{
ListIterator step_iterator;
struct step_record *step_ptr;
bool found = false;
int bit_position;
if ((job_ptr == NULL) || (node_ptr == NULL))
return false;
bit_position = node_ptr - node_record_table_ptr;
step_iterator = list_iterator_create (job_ptr->step_list);
while ((step_ptr = (struct step_record *) list_next (step_iterator))) {
if (bit_test(step_ptr->step_node_bitmap, bit_position)) {
found = true;
break;
}
}
list_iterator_destroy (step_iterator);
return found;
}
/*
* job_step_checkpoint - perform some checkpoint operation
* IN op - the operation to be performed (see enum check_opts)
* IN data - operation-specific data
* IN job_id - id of the job
* IN step_id - id of the job step, NO_VAL indicates all steps of the indicated job
* IN uid - user id of the user issuing the RPC
* IN conn_fd - file descriptor on which to send reply
* RET 0 on success, otherwise ESLURM error code
*/
extern int job_step_checkpoint(uint16_t op, uint16_t data,
uint32_t job_id, uint32_t step_id,
uid_t uid, slurm_fd conn_fd)
{
int rc = SLURM_SUCCESS;
struct job_record *job_ptr;
struct step_record *step_ptr;
/* find the job */
job_ptr = find_job_record (job_id);
if (job_ptr == NULL)
return ESLURM_INVALID_JOB_ID;
if ((uid != job_ptr->user_id) && (uid != 0))
return ESLURM_ACCESS_DENIED ;
/* find the individual job step */
if (step_id != NO_VAL) {
step_ptr = find_step_record(job_ptr, (uint32_t) step_id);
if (step_ptr == NULL)
return ESLURM_INVALID_JOB_ID;
if (op == CHECK_ERROR) {
rc = _job_step_ckpt_error(step_ptr, conn_fd);
} else {
rc = checkpoint_op(op, data, (void *)step_ptr);
last_job_update = time(NULL);
}
}
/* operate on all of a job's steps */
else {
int update_rc = -2;
bool error_reply = false;
ListIterator step_iterator;
step_iterator = list_iterator_create (job_ptr->step_list);
while ((step_ptr = (struct step_record *)
list_next (step_iterator))) {
if (op == CHECK_ERROR) {
rc = _job_step_ckpt_error(step_ptr, conn_fd);
error_reply = true;
break;
} else {
update_rc = checkpoint_op(op, data, (void *)step_ptr);
rc = MAX(rc, update_rc);
}
}
if (update_rc != -2) /* some work done */
last_job_update = time(NULL);
if ((op == CHECK_ERROR) &&
(!error_reply)) /* no steps found */
rc = ESLURM_INVALID_JOB_ID;
list_iterator_destroy (step_iterator);
}
return rc;
}
static int _job_step_ckpt_error(struct step_record *step_ptr, slurm_fd conn_fd)
{
int rc;
uint16_t ckpt_errno;
char *ckpt_strerror;
slurm_msg_t resp_msg;
checkpoint_resp_msg_t resp_data;
rc = checkpoint_error((void *)step_ptr, &ckpt_errno, &ckpt_strerror);
if (rc)
return rc;
resp_data.ckpt_errno = ckpt_errno;
resp_data.ckpt_strerror = ckpt_strerror;
resp_msg.msg_type = RESPONSE_CHECKPOINT;
resp_msg.data = &resp_data;
if (slurm_send_node_msg(conn_fd, &resp_msg) < 0)
rc = SLURM_SOCKET_ERROR;
return rc;
}