1
/*****************************************************************************\
2
* topo_plugin.c - Topology plugin function stup.
3
*****************************************************************************
4
* Copyright (C) 2009 Lawrence Livermore National Security.
5
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6
* Written by Morris Jette <jette1@llnl.gov>
7
* CODE-OCEC-09-009. All rights reserved.
9
* This file is part of SLURM, a resource management program.
10
* For details, see <https://computing.llnl.gov/linux/slurm/>.
11
* Please also read the included file: DISCLAIMER.
13
* SLURM is free software; you can redistribute it and/or modify it under
14
* the terms of the GNU General Public License as published by the Free
15
* Software Foundation; either version 2 of the License, or (at your option)
18
* In addition, as a special exception, the copyright holders give permission
19
* to link the code of portions of this program with the OpenSSL library under
20
* certain conditions as described in each individual source file, and
21
* distribute linked combinations including the two. You must obey the GNU
22
* General Public License in all respects for all of the code used other than
23
* OpenSSL. If you modify file(s) with this exception, you may extend this
24
* exception to your version of the file(s), but you are not obligated to do
25
* so. If you do not wish to do so, delete this exception statement from your
26
* version. If you delete this exception statement from all source files in
27
* the program, then also delete it here.
29
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
30
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
34
* You should have received a copy of the GNU General Public License along
35
* with SLURM; if not, write to the Free Software Foundation, Inc.,
36
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37
\*****************************************************************************/
41
#include "src/common/log.h"
42
#include "src/common/plugrack.h"
43
#include "src/common/slurm_protocol_api.h"
44
#include "src/common/xmalloc.h"
45
#include "src/common/xstring.h"
47
#include "src/slurmctld/slurmctld.h"
51
/* ************************************************************************ */
52
/* TAG( slurm_topo_ops_t ) */
53
/* ************************************************************************ */
54
typedef struct slurm_topo_ops {
55
int (*build_config) ( void );
59
/* ************************************************************************ */
60
/* TAG( slurm_topo_contex_t ) */
61
/* ************************************************************************ */
62
typedef struct slurm_topo_context {
64
plugrack_t plugin_list;
65
plugin_handle_t cur_plugin;
68
} slurm_topo_context_t;
70
static slurm_topo_context_t *g_topo_context = NULL;
71
static pthread_mutex_t g_topo_context_lock = PTHREAD_MUTEX_INITIALIZER;
74
/* ************************************************************************ */
75
/* TAG( slurm_topo_get_ops ) */
76
/* ************************************************************************ */
77
static slurm_topo_ops_t *
78
slurm_topo_get_ops( slurm_topo_context_t *c )
81
* Must be synchronized with slurm_topo_ops_t above.
83
static const char *syms[] = {
86
int n_syms = sizeof( syms ) / sizeof( char * );
88
/* Find the correct plugin. */
89
c->cur_plugin = plugin_load_and_link(c->topo_type, n_syms, syms,
91
if ( c->cur_plugin != PLUGIN_INVALID_HANDLE )
94
error("Couldn't find the specified plugin name for %s "
95
"looking at all files",
98
/* Get plugin list. */
99
if ( c->plugin_list == NULL ) {
101
c->plugin_list = plugrack_create();
102
if ( c->plugin_list == NULL ) {
103
error( "cannot create plugin manager" );
106
plugrack_set_major_type( c->plugin_list, "topo" );
107
plugrack_set_paranoia( c->plugin_list,
108
PLUGRACK_PARANOIA_NONE,
110
plugin_dir = slurm_get_plugin_dir();
111
plugrack_read_dir( c->plugin_list, plugin_dir );
115
c->cur_plugin = plugrack_use_by_type( c->plugin_list, c->topo_type );
116
if ( c->cur_plugin == PLUGIN_INVALID_HANDLE ) {
117
error( "cannot find topology plugin for %s", c->topo_type );
121
/* Dereference the API. */
122
if ( plugin_get_syms( c->cur_plugin,
125
(void **) &c->ops ) < n_syms ) {
126
error( "incomplete topology plugin detected" );
134
/* ************************************************************************ */
135
/* TAG( slurm_topo_context_create ) */
136
/* ************************************************************************ */
137
static slurm_topo_context_t *
138
slurm_topo_context_create( const char *topo_type )
140
slurm_topo_context_t *c;
142
if ( topo_type == NULL ) {
143
debug3( "slurm_topo_context: no topology type" );
147
c = xmalloc( sizeof( slurm_topo_context_t ) );
148
c->topo_type = xstrdup( topo_type );
149
c->plugin_list = NULL;
150
c->cur_plugin = PLUGIN_INVALID_HANDLE;
151
c->topo_errno = SLURM_SUCCESS;
157
/* ************************************************************************ */
158
/* TAG( slurm_topo_context_destroy ) */
159
/* ************************************************************************ */
161
slurm_topo_context_destroy( slurm_topo_context_t *c )
164
* Must check return code here because plugins might still
165
* be loaded and active.
167
if ( c->plugin_list ) {
168
if ( plugrack_destroy( c->plugin_list ) != SLURM_SUCCESS ) {
172
plugin_unload(c->cur_plugin);
175
xfree( c->topo_type );
178
return SLURM_SUCCESS;
182
/* *********************************************************************** */
183
/* TAG( slurm_topo_init ) */
185
/* NOTE: The topology plugin can not be changed via reconfiguration */
186
/* due to background threads, job priorities, etc. Slurmctld must */
187
/* be restarted and job priority changes may be required to change */
188
/* the topology type. */
189
/* *********************************************************************** */
191
slurm_topo_init( void )
193
int retval = SLURM_SUCCESS;
194
char *topo_type = NULL;
196
slurm_mutex_lock( &g_topo_context_lock );
198
if ( g_topo_context )
201
topo_type = slurm_get_topology_plugin();
202
g_topo_context = slurm_topo_context_create( topo_type );
203
if ( g_topo_context == NULL ) {
204
error( "cannot create topology context for %s",
206
retval = SLURM_ERROR;
210
if ( slurm_topo_get_ops( g_topo_context ) == NULL ) {
211
error( "cannot resolve topology plugin operations" );
212
slurm_topo_context_destroy( g_topo_context );
213
g_topo_context = NULL;
214
retval = SLURM_ERROR;
218
slurm_mutex_unlock( &g_topo_context_lock );
223
/* *********************************************************************** */
224
/* TAG( slurm_topo_fini ) */
225
/* *********************************************************************** */
227
slurm_topo_fini( void )
232
return SLURM_SUCCESS;
234
rc = slurm_topo_context_destroy(g_topo_context);
235
g_topo_context = NULL;
240
/* *********************************************************************** */
241
/* TAG( slurm_topo_build_config ) */
242
/* *********************************************************************** */
244
slurm_topo_build_config( void )
246
if ( slurm_topo_init() < 0 )
249
return (*(g_topo_context->ops.build_config))();