1
1
/*****************************************************************************\
2
* plugin.h - plugin architecture implementation.
2
* plugin.h - plugin architecture implementation.
3
3
*****************************************************************************
4
4
* Copyright (C) 2002-2007 The Regents of the University of California.
5
* Copyright (C) 2008 Lawrence Livermore National Security.
5
* Copyright (C) 2008-2009 Lawrence Livermore National Security.
6
6
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7
7
* Written by Jay Windley <jwindley@lnxi.com>.
8
* CODE-OCEC-09-009. All rights reserved.
10
10
* This file is part of SLURM, a resource management program.
11
* For details, see <http://www.llnl.gov/linux/slurm/>.
11
* For details, see <https://computing.llnl.gov/linux/slurm/>.
12
* Please also read the included file: DISCLAIMER.
13
14
* SLURM is free software; you can redistribute it and/or modify it under
14
15
* the terms of the GNU General Public License as published by the Free
83
const char * plugin_strerror(plugin_err_t e)
88
case EPLUGIN_NOTFOUND:
89
return ("Plugin file not found");
90
case EPLUGIN_ACCESS_ERROR:
91
return ("Plugin access denied");
92
case EPLUGIN_DLOPEN_FAILED:
93
return ("Dlopen of plugin file failed");
94
case EPLUGIN_INIT_FAILED:
95
return ("Plugin init() callback failed");
96
case EPLUGIN_MISSING_SYMBOL:
97
return ("Plugin name/type/version symbol missing");
99
return ("Unknown error");
83
103
plugin_peek( const char *fq_path,
84
104
char *plugin_type,
120
140
return SLURM_SUCCESS;
124
plugin_load_from_file( const char *fq_path )
144
plugin_load_from_file(plugin_handle_t *p, const char *fq_path)
126
plugin_handle_t plug;
130
* Try to open the shared object.
146
plugin_handle_t plug;
149
*p = PLUGIN_INVALID_HANDLE;
152
* Check for file existence and access permissions
154
if (access(fq_path, R_OK) < 0) {
156
return EPLUGIN_NOTFOUND;
158
return EPLUGIN_ACCESS_ERROR;
162
* Try to open the shared object.
132
164
* Use RTLD_LAZY to allow plugins to use symbols that may be
133
165
* defined in only one slurm entity (e.g. srun and not slurmd),
135
167
* entity from which it is available. (i.e. srun symbols are only
136
168
* used in the context of srun, not slurmd.)
139
plug = dlopen( fq_path, RTLD_LAZY );
140
if ( plug == NULL ) {
141
error( "plugin_load_from_file: dlopen(%s): %s",
144
return PLUGIN_INVALID_HANDLE;
147
/* Now see if our required symbols are defined. */
148
if ( ( dlsym( plug, PLUGIN_NAME ) == NULL ) ||
149
( dlsym( plug, PLUGIN_TYPE ) == NULL ) ||
150
( dlsym( plug, PLUGIN_VERSION ) == NULL ) ) {
151
debug( "plugin_load_from_file: invalid symbol");
152
/* slurm_seterrno( SLURM_PLUGIN_SYMBOLS ); */
153
return PLUGIN_INVALID_HANDLE;
157
* Now call its init() function, if present. If the function
158
* returns nonzero, unload the plugin and signal an error.
160
if ( ( init = dlsym( plug, "init" ) ) != NULL ) {
161
if ( (*init)() != 0 ) {
162
error( "plugin_load_from_file(%s): init() returned SLURM_ERROR",
164
(void) dlclose( plug );
165
return PLUGIN_INVALID_HANDLE;
171
plug = dlopen(fq_path, RTLD_LAZY);
173
error("plugin_load_from_file: dlopen(%s): %s",
176
return EPLUGIN_DLOPEN_FAILED;
179
/* Now see if our required symbols are defined. */
180
if ((dlsym(plug, PLUGIN_NAME) == NULL) ||
181
(dlsym(plug, PLUGIN_TYPE) == NULL) ||
182
(dlsym(plug, PLUGIN_VERSION) == NULL)) {
184
return EPLUGIN_MISSING_SYMBOL;
188
* Now call its init() function, if present. If the function
189
* returns nonzero, unload the plugin and signal an error.
191
if ((init = dlsym(plug, "init")) != NULL) {
192
if ((*init)() != 0) {
194
return EPLUGIN_INIT_FAILED;
199
return EPLUGIN_SUCCESS;
173
203
plugin_load_and_link(const char *type_name, int n_syms,
174
204
const char *names[], void *ptrs[])
176
plugin_handle_t plug = PLUGIN_INVALID_HANDLE;
206
plugin_handle_t plug = PLUGIN_INVALID_HANDLE;
178
208
char *head=NULL, *dir_array=NULL, *so_name = NULL,
240
270
plugin_unload( plugin_handle_t plug )
244
if ( plug != PLUGIN_INVALID_HANDLE ) {
245
if ( ( fini = dlsym( plug, "fini" ) ) != NULL ) {
248
(void) dlclose( plug );
274
if ( plug != PLUGIN_INVALID_HANDLE ) {
275
if ( ( fini = dlsym( plug, "fini" ) ) != NULL ) {
278
(void) dlclose( plug );
254
284
plugin_get_sym( plugin_handle_t plug, const char *name )
256
if ( plug != PLUGIN_INVALID_HANDLE )
257
return dlsym( plug, name );
286
if ( plug != PLUGIN_INVALID_HANDLE )
287
return dlsym( plug, name );
263
293
plugin_get_name( plugin_handle_t plug )
265
if ( plug != PLUGIN_INVALID_HANDLE )
266
return (const char *) dlsym( plug, PLUGIN_NAME );
295
if ( plug != PLUGIN_INVALID_HANDLE )
296
return (const char *) dlsym( plug, PLUGIN_NAME );
272
302
plugin_get_type( plugin_handle_t plug )
274
if ( plug != PLUGIN_INVALID_HANDLE )
275
return (const char *) dlsym( plug, PLUGIN_TYPE );
304
if ( plug != PLUGIN_INVALID_HANDLE )
305
return (const char *) dlsym( plug, PLUGIN_TYPE );
281
311
plugin_get_version( plugin_handle_t plug )
285
if ( plug == PLUGIN_INVALID_HANDLE ) return 0;
286
ptr = (uint32_t *) dlsym( plug, PLUGIN_VERSION );
287
return ptr ? *ptr : 0;
315
if ( plug == PLUGIN_INVALID_HANDLE ) return 0;
316
ptr = (uint32_t *) dlsym( plug, PLUGIN_VERSION );
317
return ptr ? *ptr : 0;
291
321
plugin_get_syms( plugin_handle_t plug,
299
for ( i = 0; i < n_syms; ++i ) {
300
ptrs[ i ] = dlsym( plug, names[ i ] );
329
for ( i = 0; i < n_syms; ++i ) {
330
ptrs[ i ] = dlsym( plug, names[ i ] );
304
334
debug3("Couldn't find sym '%s' in the plugin",