Skip to content

Commit 2a8eea9

Browse files
committed
slurm_plugin: Call slurm_init() once before any call to Slurm API
Since Slurm 20.11, slurm_init() needs to be called before any call to the Slurm API to make sure the config file is read in. We cannot call it in mod_slurm_init() or in mod_slurm_wcoll() directly as it requires slurm to be configured before use, thus pdsh would fail whenever the slurm plugin is found but Slurm is not configured correctly. Signed-off-by: Egbert Eich <eich@suse.com>
1 parent 3bc95a8 commit 2a8eea9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/modules/slurm.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,20 @@ static hostlist_t _hl_append (hostlist_t hl, char *nodes)
299299
return (hl);
300300
}
301301

302+
/*
303+
* Make sure, slurm_init() is called before any call to the Slurm API
304+
*/
305+
static void _slurm_init() {
306+
static bool _inited = false;
307+
308+
if (_inited)
309+
return;
310+
#if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(20,11,0)
311+
slurm_init(NULL);
312+
#endif
313+
_inited = true;
314+
}
315+
302316
static hostlist_t _slurm_wcoll (List joblist)
303317
{
304318
int i;
@@ -310,6 +324,7 @@ static hostlist_t _slurm_wcoll (List joblist)
310324
if ((joblist == NULL) && (envjobid = _slurm_jobid()) < 0)
311325
return (NULL);
312326

327+
_slurm_init();
313328
if (slurm_load_jobs((time_t) NULL, &msg, SHOW_ALL) < 0)
314329
errx ("Unable to contact slurm controller: %s\n",
315330
slurm_strerror (errno));
@@ -359,6 +374,7 @@ static hostlist_t _slurm_wcoll_partition (List partitionlist)
359374
partition_info_t * p;
360375
ListIterator li;
361376

377+
_slurm_init();
362378
if (slurm_load_partitions((time_t) NULL, &msg, SHOW_ALL) < 0)
363379
errx ("Unable to contact slurm controller: %s\n",
364380
slurm_strerror (errno));
@@ -402,6 +418,7 @@ static hostlist_t _slurm_wcoll_constraint (hostlist_t wl, List constraintlist)
402418
char *c;
403419
ListIterator li;
404420

421+
_slurm_init();
405422
if (slurm_load_node((time_t) NULL, &msg, SHOW_ALL) < 0)
406423
errx ("Unable to contact slurm controller: %s\n",
407424
slurm_strerror (errno));

0 commit comments

Comments
 (0)