1 /*****************************************************************************\
2 * sched_plugin.c - scheduler plugin stub.
3 *****************************************************************************
4 * Copyright (C) 2002-2007 The Regents of the University of California.
5 * Copyright (C) 2008-2009 Lawrence Livermore National Security.
6 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7 * Written by Jay Windley <jwindley@lnxi.com>.
8 * CODE-OCEC-09-009. All rights reserved.
9 *
10 * This file is part of Slurm, a resource management program.
11 * For details, see <https://slurm.schedmd.com/>.
12 * Please also read the included file: DISCLAIMER.
13 *
14 * Slurm is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
17 * any later version.
18 *
19 * In addition, as a special exception, the copyright holders give permission
20 * to link the code of portions of this program with the OpenSSL library under
21 * certain conditions as described in each individual source file, and
22 * distribute linked combinations including the two. You must obey the GNU
23 * General Public License in all respects for all of the code used other than
24 * OpenSSL. If you modify file(s) with this exception, you may extend this
25 * exception to your version of the file(s), but you are not obligated to do
26 * so. If you do not wish to do so, delete this exception statement from your
27 * version. If you delete this exception statement from all source files in
28 * the program, then also delete it here.
29 *
30 * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
31 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
33 * details.
34 *
35 * You should have received a copy of the GNU General Public License along
36 * with Slurm; if not, write to the Free Software Foundation, Inc.,
37 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 \*****************************************************************************/
39
40 #include <pthread.h>
41
42 #include "src/common/log.h"
43 #include "src/common/plugrack.h"
44 #include "src/common/slurm_protocol_api.h"
45 #include "src/common/xmalloc.h"
46 #include "src/common/xstring.h"
47
48 #include "src/slurmctld/gang.h"
49 #include "src/slurmctld/sched_plugin.h"
50 #include "src/slurmctld/slurmctld.h"
51
52 typedef struct slurm_sched_ops {
53 uint32_t (*initial_priority) ( uint32_t,
54 job_record_t * );
55 int (*reconfig) ( void );
56 } slurm_sched_ops_t;
57
58 /*
59 * Must be synchronized with slurm_sched_ops_t above.
60 */
61 static const char *syms[] = {
62 "slurm_sched_p_initial_priority",
63 "slurm_sched_p_reconfig",
64 };
65
66 static slurm_sched_ops_t ops;
67 static plugin_context_t *g_context = NULL;
68 static pthread_mutex_t g_context_lock = PTHREAD_MUTEX_INITIALIZER;
69 static bool init_run = false;
70
71 /*
72 * The scheduler plugin can not be changed via reconfiguration
73 * due to background threads, job priorities, etc.
74 * slurmctld must be restarted and job priority changes may be
75 * required to change the scheduler type.
76 */
slurm_sched_init(void)77 extern int slurm_sched_init(void)
78 {
79 int retval = SLURM_SUCCESS;
80 char *plugin_type = "sched";
81 char *type = NULL;
82
83 if ( init_run && g_context )
84 return retval;
85
86 slurm_mutex_lock( &g_context_lock );
87
88 if ( g_context )
89 goto done;
90
91 type = slurm_get_sched_type();
92 g_context = plugin_context_create(
93 plugin_type, type, (void **)&ops, syms, sizeof(syms));
94
95 if (!g_context) {
96 error("cannot create %s context for %s", plugin_type, type);
97 retval = SLURM_ERROR;
98 goto done;
99 }
100 init_run = true;
101
102 done:
103 slurm_mutex_unlock( &g_context_lock );
104 xfree(type);
105 return retval;
106 }
107
slurm_sched_fini(void)108 extern int slurm_sched_fini(void)
109 {
110 int rc;
111
112 if (!g_context)
113 return SLURM_SUCCESS;
114
115 init_run = false;
116 rc = plugin_context_destroy(g_context);
117 g_context = NULL;
118
119 gs_fini();
120
121 return rc;
122 }
123
slurm_sched_g_reconfig(void)124 extern int slurm_sched_g_reconfig(void)
125 {
126 if ( slurm_sched_init() < 0 )
127 return SLURM_ERROR;
128
129 gs_reconfig();
130
131 return (*(ops.reconfig))();
132 }
133
slurm_sched_g_initial_priority(uint32_t last_prio,job_record_t * job_ptr)134 extern uint32_t slurm_sched_g_initial_priority(uint32_t last_prio,
135 job_record_t *job_ptr)
136 {
137 if ( slurm_sched_init() < 0 )
138 return SLURM_ERROR;
139
140 return (*(ops.initial_priority))( last_prio, job_ptr );
141 }
142