~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/slurmctld/topo_plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
8
 *  
 
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.
 
12
 *  
 
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)
 
16
 *  any later version.
 
17
 *
 
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.
 
28
 *  
 
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
 
32
 *  details.
 
33
 *  
 
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
\*****************************************************************************/
 
38
 
 
39
#include <pthread.h>
 
40
 
 
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"
 
46
#if 0
 
47
#include "src/slurmctld/slurmctld.h"
 
48
#endif
 
49
 
 
50
 
 
51
/* ************************************************************************ */
 
52
/*  TAG(                        slurm_topo_ops_t                         )  */
 
53
/* ************************************************************************ */
 
54
typedef struct slurm_topo_ops {
 
55
        int             (*build_config)         ( void );
 
56
} slurm_topo_ops_t;
 
57
 
 
58
 
 
59
/* ************************************************************************ */
 
60
/*  TAG(                        slurm_topo_contex_t                      )  */
 
61
/* ************************************************************************ */
 
62
typedef struct slurm_topo_context {
 
63
        char            *topo_type;
 
64
        plugrack_t      plugin_list;
 
65
        plugin_handle_t cur_plugin;
 
66
        int             topo_errno;
 
67
        slurm_topo_ops_t ops;
 
68
} slurm_topo_context_t;
 
69
 
 
70
static slurm_topo_context_t     *g_topo_context = NULL;
 
71
static pthread_mutex_t          g_topo_context_lock = PTHREAD_MUTEX_INITIALIZER;
 
72
 
 
73
 
 
74
/* ************************************************************************ */
 
75
/*  TAG(                       slurm_topo_get_ops                        )  */
 
76
/* ************************************************************************ */
 
77
static slurm_topo_ops_t *
 
78
slurm_topo_get_ops( slurm_topo_context_t *c )
 
79
{
 
80
        /*
 
81
         * Must be synchronized with slurm_topo_ops_t above.
 
82
         */
 
83
        static const char *syms[] = {
 
84
                "topo_build_config",
 
85
        };
 
86
        int n_syms = sizeof( syms ) / sizeof( char * );
 
87
 
 
88
        /* Find the correct plugin. */
 
89
        c->cur_plugin = plugin_load_and_link(c->topo_type, n_syms, syms,
 
90
                                             (void **) &c->ops);
 
91
        if ( c->cur_plugin != PLUGIN_INVALID_HANDLE ) 
 
92
                return &c->ops;
 
93
 
 
94
        error("Couldn't find the specified plugin name for %s "
 
95
              "looking at all files",
 
96
              c->topo_type);
 
97
        
 
98
        /* Get plugin list. */
 
99
        if ( c->plugin_list == NULL ) {
 
100
                char *plugin_dir;
 
101
                c->plugin_list = plugrack_create();
 
102
                if ( c->plugin_list == NULL ) {
 
103
                        error( "cannot create plugin manager" );
 
104
                        return NULL;
 
105
                }
 
106
                plugrack_set_major_type( c->plugin_list, "topo" );
 
107
                plugrack_set_paranoia( c->plugin_list,
 
108
                                       PLUGRACK_PARANOIA_NONE,
 
109
                                       0 );
 
110
                plugin_dir = slurm_get_plugin_dir();
 
111
                plugrack_read_dir( c->plugin_list, plugin_dir );
 
112
                xfree(plugin_dir);
 
113
        }
 
114
 
 
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 );
 
118
                return NULL;
 
119
        }
 
120
 
 
121
        /* Dereference the API. */
 
122
        if ( plugin_get_syms( c->cur_plugin,
 
123
                              n_syms,
 
124
                              syms,
 
125
                              (void **) &c->ops ) < n_syms ) {
 
126
                error( "incomplete topology plugin detected" );
 
127
                return NULL;
 
128
        }
 
129
 
 
130
        return &c->ops;
 
131
}
 
132
 
 
133
 
 
134
/* ************************************************************************ */
 
135
/*  TAG(                  slurm_topo_context_create                      )  */
 
136
/* ************************************************************************ */
 
137
static slurm_topo_context_t *
 
138
slurm_topo_context_create( const char *topo_type )
 
139
{
 
140
        slurm_topo_context_t *c;
 
141
 
 
142
        if ( topo_type == NULL ) {
 
143
                debug3( "slurm_topo_context:  no topology type" );
 
144
                return NULL;
 
145
        }
 
146
 
 
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;
 
152
 
 
153
        return c;
 
154
}
 
155
 
 
156
 
 
157
/* ************************************************************************ */
 
158
/*  TAG(                  slurm_topo_context_destroy                     )  */
 
159
/* ************************************************************************ */
 
160
static int
 
161
slurm_topo_context_destroy( slurm_topo_context_t *c )
 
162
{
 
163
        /*
 
164
         * Must check return code here because plugins might still
 
165
         * be loaded and active.
 
166
         */
 
167
        if ( c->plugin_list ) {
 
168
                if ( plugrack_destroy( c->plugin_list ) != SLURM_SUCCESS ) {
 
169
                        return SLURM_ERROR;
 
170
                }
 
171
        } else {
 
172
                plugin_unload(c->cur_plugin);
 
173
        }
 
174
 
 
175
        xfree( c->topo_type );
 
176
        xfree( c );
 
177
 
 
178
        return SLURM_SUCCESS;
 
179
}
 
180
 
 
181
 
 
182
/* *********************************************************************** */
 
183
/*  TAG(                        slurm_topo_init                         )  */
 
184
/*                                                                         */
 
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
/* *********************************************************************** */
 
190
extern int
 
191
slurm_topo_init( void )
 
192
{
 
193
        int retval = SLURM_SUCCESS;
 
194
        char *topo_type = NULL;
 
195
        
 
196
        slurm_mutex_lock( &g_topo_context_lock );
 
197
 
 
198
        if ( g_topo_context )
 
199
                goto done;
 
200
 
 
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",
 
205
                         topo_type );
 
206
                retval = SLURM_ERROR;
 
207
                goto done;
 
208
        }
 
209
 
 
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;
 
215
        }
 
216
 
 
217
 done:
 
218
        slurm_mutex_unlock( &g_topo_context_lock );
 
219
        xfree(topo_type);
 
220
        return retval;
 
221
}
 
222
 
 
223
/* *********************************************************************** */
 
224
/*  TAG(                        slurm_topo_fini                         )  */
 
225
/* *********************************************************************** */
 
226
extern int
 
227
slurm_topo_fini( void )
 
228
{
 
229
        int rc;
 
230
 
 
231
        if (!g_topo_context)
 
232
                return SLURM_SUCCESS;
 
233
 
 
234
        rc = slurm_topo_context_destroy(g_topo_context);
 
235
        g_topo_context = NULL;
 
236
        return rc;
 
237
}
 
238
 
 
239
 
 
240
/* *********************************************************************** */
 
241
/*  TAG(                      slurm_topo_build_config                   )  */
 
242
/* *********************************************************************** */
 
243
extern int
 
244
slurm_topo_build_config( void )
 
245
{
 
246
        if ( slurm_topo_init() < 0 )
 
247
                return SLURM_ERROR;
 
248
 
 
249
        return (*(g_topo_context->ops.build_config))();
 
250
}
 
251