Newer
Older
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
/*****************************************************************************\
* sched_upcalls.c - functions available to scheduler plugins
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Moe Jette <jette@llnl.gov>, Kevin Tew <tew1@llnl.gov>, et. al.
* 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.
\*****************************************************************************/
#include <string.h>
#include <signal.h>
#include <slurm/slurm.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include "src/common/hostlist.h"
#include "src/common/list.h"
#include "src/common/xassert.h"
#include "src/common/xstring.h"
#include "sched_plugin.h"
#include "slurmctld.h"
#include "locks.h"
/*
* Implementation of the opaque list of nodes, jobs, etc., passed down
* to the scheduler plugin.
*
* XXX - Make the accessor name-function mapping part of the object
* instead of global.
*/
/* ***************************************************************************/
/* TAG( sched_obj_list ) */
/*
* "Base" object for the controller lists passed to plugins. Contains a
* destructor appropriate to the data, a count of items in the list, and
* a cache of intermediate values computed by accessors that they might
* want back on subsequent invocations.
*/
struct sched_obj_list
{
int (*destructor)( sched_obj_list_t );
int32_t count;
void *data;
List cache;
};
/* ***************************************************************************/
/* TAG( sched_obj_cache_entry ) */
/*
* Maps a field name to a cached chunk of data in the list. If an accessor
* needs to convert the internal SLURM value into one more appropriate for
* a plugin or anything like that, it can cache the computed value in the
* obj_list under its field name to satisfy future calls. The data cached
* is opaque but must be freeable via xfree(). When the object list is
* destroyed, the cached data is automatically freed.
*
* This type maps field name to data. The cache in the sched_obj_list
* is a List of these.
*/
struct sched_obj_cache_entry
{
/*
* These constants give accessors something to point to for customary
* default or missing values.
*/
static int32_t zero_32 = 0;

jwindley
committed
static time_t unspecified_time = (time_t) NO_VAL;
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
static struct job_details *copy_job_details( struct job_details *from );
static void free_job_details( struct job_details *doomed );
/*
* Forward declarations of accessor functions. These functions, when
* passed a reference to an opaque data structure and an index return
* the appropriate attribute of that object.
*/
static void * sched_get_job_id( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_name( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_last_active( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_state( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_time_limit( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_num_tasks( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_submit_time( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_start_time( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_end_time( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_user_id( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_group_name( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_req_nodes( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_min_nodes( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_partition( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_min_disk( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_min_memory( sched_obj_list_t, int32_t, char * );
#if 0
static void * sched_get_job_features( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_priority( sched_obj_list_t, int32_t, char * );
static void * sched_get_job_work_dir( sched_obj_list_t, int32_t, char * );
#endif
static void * sched_get_node_name( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_state( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_num_cpus( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_real_mem( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_tmp_disk( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_partition( sched_obj_list_t, int32_t, char * );
static void * sched_get_node_mod_time( sched_obj_list_t, int32_t, char * );
/* ************************************************************************ */
/* TAG( sched_get_port ) */
/* ************************************************************************ */
const u_int16_t
sched_get_port( void )
{
return slurmctld_conf.schedport;
}
/* ************************************************************************ */
/* TAG( sched_get_auth ) */
/* ************************************************************************ */
const char * const
sched_get_auth( void )
{
return slurmctld_conf.schedauth;
}
/* ************************************************************************ */
/* TAG( sched_get_obj_count ) */
/* ************************************************************************ */
int32_t sched_get_obj_count( sched_obj_list_t list )
{
xassert( list );
return( list->count );
}
/* ************************************************************************ */
/* TAG( sched_get_accessor ) */
/* ************************************************************************ */
sched_accessor_fn_t
sched_get_accessor( char *field )
{
struct accessor_map_struct {
char *field_name;
sched_accessor_fn_t func;
};
static struct accessor_map_struct accessor_map[] = {
{ JOB_FIELD_ID, sched_get_job_id },
{ JOB_FIELD_NAME, sched_get_job_name },
{ JOB_FIELD_LAST_ACTIVE, sched_get_job_last_active },
{ JOB_FIELD_STATE, sched_get_job_state },
{ JOB_FIELD_TIME_LIMIT, sched_get_job_time_limit },
{ JOB_FIELD_NUM_TASKS, sched_get_job_num_tasks },
{ JOB_FIELD_SUBMIT_TIME, sched_get_job_submit_time },
{ JOB_FIELD_START_TIME, sched_get_job_start_time },
{ JOB_FIELD_END_TIME, sched_get_job_end_time },
{ JOB_FIELD_USER_ID, sched_get_job_user_id },
{ JOB_FIELD_GROUP_ID, sched_get_job_group_name },
{ JOB_FIELD_REQ_NODES, sched_get_job_req_nodes },
{ JOB_FIELD_MIN_NODES, sched_get_job_min_nodes },
{ JOB_FIELD_PARTITION, sched_get_job_partition },
{ JOB_FIELD_MIN_DISK, sched_get_job_min_disk },
{ JOB_FIELD_MIN_MEMORY, sched_get_job_min_memory },
#if 0
{ JOB_FIELD_FEATURES, sched_get_job_features },
{ JOB_FIELD_PRIORITY, sched_get_job_priority },
{ JOB_FIELD_WORK_DIR, sched_get_job_work_dir },
#endif
{ NODE_FIELD_NAME, sched_get_node_name },
{ NODE_FIELD_STATE, sched_get_node_state },
{ NODE_FIELD_NUM_CPUS, sched_get_node_num_cpus },
{ NODE_FIELD_REAL_MEM, sched_get_node_real_mem },
{ NODE_FIELD_TMP_DISK, sched_get_node_tmp_disk },
{ NODE_FIELD_PARTITION, sched_get_node_partition },
{ NODE_FIELD_MOD_TIME, sched_get_node_mod_time },
{ NULL, NULL }
};
struct accessor_map_struct *p;
for ( p = accessor_map; p->field_name != NULL; ++p ) {
if ( strcmp( p->field_name, field ) == 0 )
return p->func;
}
return NULL;
}
/* ************************************************************************ */
/* TAG( sched_free_obj_list ) */
/* ************************************************************************ */
int
sched_free_obj_list( sched_obj_list_t objlist )
{
if ( objlist->count > 0 ) {
(*objlist->destructor)( objlist );
}
list_destroy( objlist->cache );
xfree( objlist );
return SLURM_SUCCESS;
}
/* ************************************************************** */
/* TAG( sched_obj_cache_entry_destructor ) */
/* ************************************************************** */
/* DESCRIPTION
* Destructor for an item in the accessor's cache. This is intended to
* be called by list_destroy().
*
* ARGUMENTS
* ent - pointer to the sched_obj_cache_entry to be freed.
*
* RETURNS
* None.
*
**************************************************************** */
static void
sched_obj_cache_entry_destructor( void *ent )
{
struct sched_obj_cache_entry *e =
(struct sched_obj_cache_entry *) ent;
xfree( e->data );
}
/* ************************************************************************ */
/* TAG( sched_obj_cache_entry_find ) */
/* ************************************************************************ */
void *
sched_obj_cache_entry_find( sched_obj_list_t objlist,
int32_t idx,
char *field )
{
ListIterator i;
struct sched_obj_cache_entry *e;
i = list_iterator_create( objlist->cache );
while ( ( e = (struct sched_obj_cache_entry *) list_next( i ) ) != NULL ) {
if ( ( e->idx == idx ) && ( strcmp( e->field, field ) == 0 ) ) {
list_iterator_destroy( i );
return e->data;
}
}
list_iterator_destroy( i );
return NULL;
}
/* ************************************************************************ */
/* TAG( sched_obj_cache_entry_add ) */
/* ************************************************************************ */
void
sched_obj_cache_entry_add( sched_obj_list_t objlist,
int32_t idx,
char *field,
void *data )
{
struct sched_obj_cache_entry *e =
(struct sched_obj_cache_entry *) xmalloc( sizeof( *e ) );
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
e->field = field;
e->data = data;
list_push( objlist->cache, e );
}
/* ************************************************************************ */
/* TAG( sched_free_job_list ) */
/* ************************************************************************ */
int
sched_free_job_list( sched_obj_list_t objlist )
{
int32_t i;
struct job_record *job;
for ( i = 0, job = (struct job_record *) objlist->data;
i < objlist->count;
++i, ++job ) {
if ( job->details ) {
free_job_details( job->details );
}
}
xfree( objlist->data );
return SLURM_SUCCESS;
}
/* ************************************************************************ */
/* TAG( sched_get_job_list ) */
/* ************************************************************************ */
sched_obj_list_t
sched_get_job_list( void )
{
ListIterator it;
struct job_record *to, *from;
int32_t i;
sched_obj_list_t objlist;
/* read lock on job info, no other locks needed */
slurmctld_lock_t job_read_lock = {
NO_LOCK,
READ_LOCK,
NO_LOCK,
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
NO_LOCK
};
/* Allocate the structure. */
objlist = (sched_obj_list_t )
xmalloc( sizeof( struct sched_obj_list ) );
objlist->destructor = sched_free_job_list;
objlist->cache = list_create( sched_obj_cache_entry_destructor );
lock_slurmctld( job_read_lock );
objlist->count = (int32_t) list_count( job_list );
if ( ! objlist->count ) {
unlock_slurmctld( job_read_lock );
objlist->data = NULL;
return objlist;
}
objlist->data = xmalloc( sizeof( struct job_record ) *
(objlist->count) );
it = list_iterator_create( job_list );
for ( i = 0, to = (struct job_record *) objlist->data;
i < objlist->count;
++i, ++to ) {
from = (struct job_record *) list_next( it );
memcpy( to, from, sizeof( struct job_record ) );
to->nodes = NULL;
to->details = NULL;
to->node_bitmap = NULL;
to->cpus_per_node = NULL;
to->cpu_count_reps = NULL;
to->alloc_node = NULL;
to->node_addr = NULL;
if ( from->details ) {
to->details = copy_job_details( from->details );
}
}
unlock_slurmctld( job_read_lock );
return objlist;
}
/* ************************************************************** */
/* TAG( copy_job_details ) */
/* ************************************************************** */
/* DESCRIPTION
* Make a copy of a job_details structure.
*
* ARGUMENTS
* from (in) - the job_details structure to copy.
*
* RETURNS
* A copy of the job_details structure.
*
**************************************************************** */
static struct job_details *
copy_job_details( struct job_details *from )
{
struct job_details *to;
to = (struct job_details *) xmalloc( sizeof( struct job_details ) );
memcpy( to, from, sizeof( struct job_details ) );
/*
* The default is not to copy subordinate objects stored
* out a pointer. This is to speed up creating the copy.
* If you write an accessor that needs data stored in
* these subordinate objects, write code below in this
* function -- not in your accessor -- to copy that data.
*/
to->req_nodes = NULL;
to->exc_nodes = NULL;
to->req_node_bitmap = NULL;
to->exc_node_bitmap = NULL;
to->features = NULL;
to->err = NULL;
to->in = NULL;
to->out = NULL;
to->work_dir = NULL;
/* Copy the subordinates we actually need. */
if ( from->req_nodes ) to->req_nodes = xstrdup( from->req_nodes );
return to;
}
/* ************************************************************** */
/* TAG( free_job_details ) */
/* ************************************************************** */
/* DESCRIPTION
* Free a job_details structure.
*
* ARGUMENTS
* doomed (in) - the job_details structure to destroy.
*
* RETURNS
* None.
*
**************************************************************** */
static void
free_job_details( struct job_details *doomed )
{
if ( ! doomed ) return;
/* Free subordinate objects here. */
if ( doomed->req_nodes ) xfree( doomed->req_nodes );
xfree( doomed );
}
/* ************************************************************************ */
/* TAG( sched_get_job_id ) */
/* ************************************************************************ */
static void *
sched_get_job_id( sched_obj_list_t job_data,
int32_t idx,
char *type )
{

jwindley
committed
void *cache;
char str[ 16 ];
/*
* This is the primary key for the job record which means that
* consolidated plugin code will want this as a string and not
* an integer.
*/

jwindley
committed
if ( ( cache = sched_obj_cache_entry_find( job_data,

jwindley
committed
"job_id" ) ) != NULL )
return cache;
snprintf( str, 16,
"%u",
( (struct job_record *)job_data->data )[ idx ].job_id );

jwindley
committed
cache = xstrdup( str );
sched_obj_cache_entry_add( job_data, idx, "job_id", cache );

jwindley
committed
return cache;
}
/* ************************************************************************ */
/* TAG( sched_get_job_name ) */
/* ************************************************************************ */
static void *
sched_get_job_name( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
if ( type ) *type = 's';
return (void *) ( (struct job_record *)job_data->data )[ idx ].name;
}
/* ************************************************************************ */
/* TAG( sched_get_job_last_active ) */
/* ************************************************************************ */
static void *
sched_get_job_last_active( sched_obj_list_t job_data,
int32_t idx,
char *type )
{

jwindley
committed
if ( type ) *type = 't';
return (void *) &( (struct job_record *)job_data->data )[ idx ].time_last_active;
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
}
/* ************************************************************************ */
/* TAG( sched_get_job_state ) */
/* ************************************************************************ */
static void *
sched_get_job_state( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
static struct job_state_rel {
enum job_states id;
char *label;
} job_state_map[] = {
{ JOB_PENDING, JOB_STATE_LABEL_PENDING },
{ JOB_RUNNING, JOB_STATE_LABEL_RUNNING },
{ JOB_COMPLETE, JOB_STATE_LABEL_COMPLETE },
{ JOB_FAILED, JOB_STATE_LABEL_FAILED },
{ JOB_TIMEOUT, JOB_STATE_LABEL_TIMEOUT },
{ JOB_NODE_FAIL, JOB_STATE_LABEL_NODE_FAIL },
{ JOB_END, "" }
}, *p;
enum job_states cur_state = ( (struct job_record *)job_data->data )[ idx ].job_state;
if ( type ) *type = 'e';
for ( p = job_state_map; p->id != JOB_END; ++p ) {
if ( p->id == cur_state ) {
return (void *) p->label;
}
}
error( "scheduler adapter: unmapped job state %d in job %u",
cur_state,
( (struct job_record *)job_data->data )[ idx ].job_id );
return (void *) "UNKNOWN";
}
/* ************************************************************************ */
/* TAG( sched_get_job_time_limit ) */
/* ************************************************************************ */
static void *
sched_get_job_time_limit( sched_obj_list_t job_data,
int32_t idx,
char *type )
{

jwindley
committed
time_t *cache;

jwindley
committed
if ( type ) *type = 't';
if ( ( cache = sched_obj_cache_entry_find( job_data, idx, "time_limit" ) ) != NULL )

jwindley
committed
return cache;
cache = xmalloc( sizeof( time_t ) );
*cache = ( (struct job_record *)job_data->data )[ idx ].time_limit;

jwindley
committed
switch ( *cache ) {

jwindley
committed
*cache = (time_t) 0;
break;

jwindley
committed
*cache *= 60; // seconds, not mins.
break;
sched_obj_cache_entry_add( job_data, idx, "time_limit", cache );

jwindley
committed
return cache;
}
/* ************************************************************************ */
/* TAG( sched_get_job_num_tasks ) */
/* ************************************************************************ */
static void *
sched_get_job_num_tasks( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
static uint16_t one = 1;
struct job_details *det = ( (struct job_record *)job_data->data )[ idx ].details;
if ( type ) *type = 'u';
if ( det ) {
return (void *) &det->req_tasks;
return (void *) &one;
}
}
/* ************************************************************************ */
/* TAG( sched_get_job_submit_time ) */
/* ************************************************************************ */
static void *
sched_get_job_submit_time( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct job_details *det = ( (struct job_record *)job_data->data )[ idx ].details;

jwindley
committed
if ( type ) *type = 't';
return (void *) &det->submit_time;
return (void *) &zero_32;
}
}
/* ************************************************************************ */
/* TAG( sched_get_job_start_time ) */
/* ************************************************************************ */
static void *
sched_get_job_start_time( sched_obj_list_t job_data,
int32_t idx,
char *type )
{

jwindley
committed
time_t start = ( (struct job_record *)job_data->data )[ idx ].start_time;

jwindley
committed
if ( type ) *type = 't';

jwindley
committed
if ( start != (time_t) 0 )
return (void *) &( (struct job_record *)job_data->data )[ idx ].start_time;
else
return (void *) &unspecified_time;
}
/* ************************************************************************ */
/* TAG( sched_get_job_end_time ) */
/* ************************************************************************ */
static void *
sched_get_job_end_time( sched_obj_list_t job_data,
int32_t idx,
char *type )
{

jwindley
committed
if ( type ) *type = 't';
return (void *) &( (struct job_record *)job_data->data )[ idx ].end_time;
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
}
/* ************************************************************************ */
/* TAG( sched_get_job_user_id ) */
/* ************************************************************************ */
static void *
sched_get_job_user_id( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
// * This is probably not thread-safe.
struct passwd *pwent;
if ( type ) *type = 's';
pwent = getpwuid( (uid_t) ( (struct job_record *)job_data->data )[ idx ].user_id );
return (void *) ( pwent ? pwent->pw_name : "nobody" );
}
/* ************************************************************************ */
/* TAG( sched_get_job_group_name ) */
/* ************************************************************************ */
static void *
sched_get_job_group_name( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct group *grp;
if ( type ) *type = 's';
grp = getgrgid( (gid_t) ( (struct job_record *)job_data->data )[ idx ].group_id );
return (void *) ( grp ? grp->gr_name : "nobody" );
}
/* ************************************************************************ */
/* TAG( expand_hostlist ) */
/* ************************************************************************ */
static char *
expand_hostlist( char *ranged )
{
size_t new_size = 64;
char *str;
hostlist_t h = hostlist_create( ranged );
if ( ! h ) return NULL;
str = (char *) xmalloc( new_size );
while ( hostlist_deranged_string( h, new_size, str ) == -1 ) {
new_size *= 2;
xrealloc( str, new_size );
}
hostlist_destroy( h );
return str;
}
/* ************************************************************************ */
/* TAG( sched_get_job_req_nodes ) */
/* ************************************************************************ */
static void *
sched_get_job_req_nodes( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct job_details *details;
void *cache;
if ( type ) *type = 'S';
details = ( (struct job_record *)job_data->data )[ idx ].details;
if ( details && details->req_nodes ) {
if ( ( cache = sched_obj_cache_entry_find( job_data,
"req_nodes" ) ) != NULL ) {
return cache;
}
cache = expand_hostlist( details->req_nodes );
if ( ! cache )
return details->req_nodes;
sched_obj_cache_entry_add( job_data, idx, "req_nodes", cache );
return cache;
}
return "";
}
/* ************************************************************************ */
/* TAG( sched_get_job_min_nodes ) */
/* ************************************************************************ */
static void *
sched_get_job_min_nodes( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct job_details *details;
if ( type ) *type = 'U';
details = ( (struct job_record *)job_data->data )[ idx ].details;
if ( details && details->min_nodes ) {
return (void *) &details->min_nodes;
} else {
return (void *) &zero_32;
}
}
/* ************************************************************************ */
/* TAG( sched_get_job_partition ) */
/* ************************************************************************ */
static void *
sched_get_job_partition( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
if ( type ) *type = 's';
return ( (struct job_record *)job_data->data )[ idx ].partition;
}
/* ************************************************************************ */
/* TAG( sched_get_job_min_memory ) */
/* ************************************************************************ */
static void *
sched_get_job_min_memory( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct job_details *details;
if ( type ) *type = 'U';
details = ( (struct job_record *)job_data->data )[ idx ].details;
if ( details ) {
return (void *) &details->min_memory;
} else {
return (void *) &zero_32;
}
}
/* ************************************************************************ */
/* TAG( sched_get_job_min_disk ) */
/* ************************************************************************ */
static void *
sched_get_job_min_disk( sched_obj_list_t job_data,
int32_t idx,
char *type )
{
struct job_details *details;
if ( type ) *type = 'U';
details = ( (struct job_record *)job_data->data )[ idx ].details;
if ( details ) {
return (void *) &details->min_tmp_disk;
} else {
return (void *) &zero_32;
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
}
}
/* ************************************************************************ */
/* TAG( sched_free_node_list ) */
/* ************************************************************************ */
int
sched_free_node_list( sched_obj_list_t objlist )
{
xfree( objlist->data );
return SLURM_SUCCESS;
}
/* ************************************************************************ */
/* TAG( sched_get_node_list ) */
/* ************************************************************************ */
sched_obj_list_t
sched_get_node_list( void )
{
size_t node_list_size;
slurmctld_lock_t node_read_lock = {
NO_LOCK, NO_LOCK, READ_LOCK, NO_LOCK };
sched_obj_list_t objlist;
objlist = (sched_obj_list_t )
xmalloc( sizeof( struct sched_obj_list ) );
objlist->destructor = sched_free_node_list;
objlist->cache = list_create( sched_obj_cache_entry_destructor );
lock_slurmctld( node_read_lock );
objlist->count = (int32_t) node_record_count;
if ( objlist->count == 0 ) {
objlist->data = NULL;
unlock_slurmctld( node_read_lock );
return objlist;
}
node_list_size = node_record_count * sizeof( struct node_record );
objlist->data = xmalloc( node_list_size );
memcpy( objlist->data, node_record_table_ptr, node_list_size );
unlock_slurmctld( node_read_lock );
return objlist;
}
/* ************************************************************************ */
/* TAG( sched_get_node_name ) */
/* ************************************************************************ */
static void *
sched_get_node_name( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
if ( type ) *type = 's';
return ( (struct node_record *) node_data->data )[ idx ].name;
}
/* ************************************************************************ */
/* TAG( sched_get_node_state ) */
/* ************************************************************************ */
static void *
sched_get_node_state( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
struct node_state_label_map_struct {
enum node_states state;
char * label;
};
/*
* This is so we don't have to maintain a coordinated enumeration
* across the plugin interface.
*
* It would seem best to map UNKNOWN to UNKNOWN, but some
* schedulers don't accept UNKNOWN as an unschedulable state and
* so they wait and see if it comes back up. UNKNOWN in our
* world typically means the slurmd has died, so no jobs can
* be scheduled there anyway.
*/
static struct node_state_label_map_struct
node_state_label_map[] = {
{ NODE_STATE_DOWN, NODE_STATE_LABEL_DOWN },
{ NODE_STATE_UNKNOWN, NODE_STATE_LABEL_DOWN },
{ NODE_STATE_IDLE, NODE_STATE_LABEL_IDLE },
{ NODE_STATE_ALLOCATED, NODE_STATE_LABEL_ALLOCATED },
{ NODE_STATE_DRAINED, NODE_STATE_LABEL_DRAINED },
{ NODE_STATE_DRAINING, NODE_STATE_LABEL_DRAINING },
{ NODE_STATE_COMPLETING, NODE_STATE_LABEL_COMPLETING },
{ NODE_STATE_END, NODE_STATE_LABEL_UNKNOWN }
};
struct node_state_label_map_struct *p;
enum node_states state = ( (struct node_record *) node_data->data )[ idx ].node_state;
if ( type ) *type = 'e';
if ( state & NODE_STATE_NO_RESPOND ) {
return NODE_STATE_LABEL_DOWN;
}
for ( p = node_state_label_map;
p->state != NODE_STATE_END;
++p ) {
if ( state == p->state ) {
return p->label;
}
}
return NODE_STATE_LABEL_UNKNOWN;
}
/* ************************************************************************ */
/* TAG( sched_get_node_num_cpus ) */
/* ************************************************************************ */
void *
sched_get_node_num_cpus( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
if ( type ) *type = 'U';
return (void *) &( (struct node_record *) node_data->data )[ idx ].cpus;
}
/* ************************************************************************ */
/* TAG( sched_get_node_real_mem ) */
/* ************************************************************************ */
void *
sched_get_node_real_mem( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
if ( type ) *type = 'U';
return (void *) &( (struct node_record *) node_data->data )[ idx ].real_memory;
}
/* ************************************************************************ */
/* TAG( sched_get_node_tmp_disk ) */
/* ************************************************************************ */
void *
sched_get_node_tmp_disk( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
if ( type ) *type = 'U';
return (void *) &( (struct node_record *) node_data->data )[ idx ].tmp_disk;
}
/* ************************************************************************ */
/* TAG( sched_get_node_partition ) */
/* ************************************************************************ */
void *
sched_get_node_partition( sched_obj_list_t node_data,
int32_t idx,
char *type )
{
if ( type ) *type = 's';
return ( (struct node_record *) node_data->data )[ idx ].partition_ptr->name;
}
/* ************************************************************************ */
/* TAG( sched_get_node_mod_time ) */
/* ************************************************************************ */
void *
sched_get_node_mod_time( sched_obj_list_t node_data,
int32_t idx,
char *type )
{

jwindley
committed
if ( type ) *type = 't';
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
return (void *) &( (struct node_record *) node_data->data )[ idx ].last_response;
}
static
char *_copy_nodelist_no_dup(char *node_list)
{
int new_size = 64;
char *new_str;
hostlist_t hl = hostlist_create( node_list );
if ( hl == NULL )
return NULL;
hostlist_uniq( hl );
new_str = xmalloc( new_size );
while ( hostlist_ranged_string( hl, new_size, new_str ) == -1 ) {
new_size *= 2;
xrealloc( new_str, new_size );
}
hostlist_destroy( hl );
return new_str;
}
/* ************************************************************************ */
/* TAG( sched_set_nodelist ) */
/* ************************************************************************ */
int
sched_set_nodelist( const uint32_t job_id, char *nodes )
{
ListIterator i;
struct job_record *job;
struct job_details *det;
int rc = SLURM_ERROR;
/* Write lock on job info, read lock on node info */
slurmctld_lock_t job_write_lock = {
NO_LOCK,
WRITE_LOCK,
READ_LOCK,
NO_LOCK
};
debug3( "Scheduler setting node list to %s for job %u", nodes, job_id );
lock_slurmctld( job_write_lock );
i = list_iterator_create( job_list );
while ( ( job = (struct job_record *) list_next( i ) ) != NULL ) {
if ( job->job_id != job_id ) continue;
/*
* Okay, the nice thing to do here would be to
* add a job details structure and put the node list
* in it.