44
44
extern int initialize_schema_table(st_plugin_int *plugin);
45
45
extern int finalize_schema_table(st_plugin_int *plugin);
47
extern int initialize_udf(st_plugin_int *plugin);
48
extern int finalize_udf(st_plugin_int *plugin);
48
51
The number of elements in both plugin_type_initialize and
49
52
plugin_type_deinitialize should equal to the number of plugins
52
55
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
54
0,ha_initialize_handlerton,0,0,initialize_schema_table,
57
initialize_udf,ha_initialize_handlerton,0,0,initialize_schema_table,
58
61
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
60
0,ha_finalize_handlerton,0,0,finalize_schema_table,
63
finalize_udf,ha_finalize_handlerton,0,0,finalize_schema_table,
65
67
static const char *plugin_interface_version_sym=
66
68
"_mysql_plugin_interface_version_";
67
69
static const char *sizeof_st_plugin_sym=
68
70
"_mysql_sizeof_struct_st_plugin_";
69
71
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
70
72
static int min_plugin_interface_version= MYSQL_PLUGIN_INTERFACE_VERSION & ~0xFF;
73
74
/* Note that 'int version' must be the first field of every plugin
74
75
sub-structure (plugin->info).
76
77
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
79
MYSQL_UDF_INTERFACE_VERSION,
79
80
MYSQL_HANDLERTON_INTERFACE_VERSION,
80
81
MYSQL_FTPARSER_INTERFACE_VERSION,
81
82
MYSQL_DAEMON_INTERFACE_VERSION,
85
86
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
87
0x0000, /* UDF: not implemented */
88
MYSQL_UDF_INTERFACE_VERSION,
88
89
MYSQL_HANDLERTON_INTERFACE_VERSION,
89
90
MYSQL_FTPARSER_INTERFACE_VERSION,
90
91
MYSQL_DAEMON_INTERFACE_VERSION,
188
189
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
189
190
const char *list);
190
191
static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
191
int *, char **, my_bool);
192
193
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
193
194
struct st_plugin_int **);
194
195
static void unlock_variables(THD *thd, struct system_variables *vars);
307
305
sizeof(struct st_plugin_dl));
310
#endif /* HAVE_DLOPEN */
313
309
static inline void free_plugin_mem(struct st_plugin_dl *p)
317
312
dlclose(p->handle);
319
313
my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
320
314
if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
321
315
my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
707
701
tmp.name.length= name_len;
708
702
tmp.ref_count= 0;
709
703
tmp.state= PLUGIN_IS_UNINITIALIZED;
710
if (!test_plugin_options(tmp_root, &tmp, argc, argv, true))
704
if (!test_plugin_options(tmp_root, &tmp, argc, argv))
712
706
if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
803
static void plugin_del(const LEX_STRING *name)
805
struct st_plugin_int *plugin;
806
if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
813
795
static void reap_plugins(void)
1003
983
int plugin_init(int *argc, char **argv, int flags)
1006
bool def_enabled, is_myisam;
1007
986
struct st_mysql_plugin **builtins;
1008
987
struct st_mysql_plugin *plugin;
1009
988
struct st_plugin_int tmp, *plugin_ptr, **reap;
1043
1022
for (plugin= *builtins; plugin->info; plugin++)
1045
/* by default, only ndbcluster is disabled */
1047
my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0;
1048
1024
bzero(&tmp, sizeof(tmp));
1049
1025
tmp.plugin= plugin;
1050
1026
tmp.name.str= (char *)plugin->name;
1051
1027
tmp.name.length= strlen(plugin->name);
1053
1029
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
1054
if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled))
1030
if (test_plugin_options(&tmp_root, &tmp, argc, argv))
1057
1033
if (register_builtin(plugin, &tmp, &plugin_ptr))
1058
1034
goto err_unlock;
1060
/* only initialize MyISAM and CSV at this stage */
1062
!my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM")) &&
1063
my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
1066
1036
if (plugin_initialize(plugin_ptr))
1067
1037
goto err_unlock;
1070
1040
initialize the global default storage engine so that it may
1071
1041
not be null in any child thread.
1043
if (my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM") == 0)
1075
1045
assert(!global_system_variables.table_plugin);
1076
1046
global_system_variables.table_plugin=
1165
Register a plugin at run time. (note, this doesn't initialize a plugin)
1166
Will be useful for embedded applications.
1169
plugin_register_builtin()
1170
thd current thread (used to store scratch data in mem_root)
1171
plugin static plugin to install
1174
false - plugin registered successfully
1176
bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
1178
struct st_plugin_int tmp, *ptr;
1182
bzero(&tmp, sizeof(tmp));
1184
tmp.name.str= (char *)plugin->name;
1185
tmp.name.length= strlen(plugin->name);
1187
rw_wrlock(&LOCK_system_variables_hash);
1189
if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
1192
if ((result= register_builtin(plugin, &tmp, &ptr)))
1193
mysql_del_sys_var_chain(tmp.system_vars);
1196
rw_unlock(&LOCK_system_variables_hash);
1200
#endif /* NOT_USED_YET */
1204
1134
called only by plugin_init()
1549
1479
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
1550
1480
void *save, st_mysql_value *value)
1554
1484
struct my_option options;
1555
1485
value->val_int(value, &tmp);
1569
1499
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
1570
1500
void *save, st_mysql_value *value)
1574
1504
struct my_option options;
1575
1505
value->val_int(value, &tmp);
1589
1519
static int check_func_longlong(THD *thd, struct st_mysql_sys_var *var,
1590
1520
void *save, st_mysql_value *value)
1594
1524
struct my_option options;
1595
1525
value->val_int(value, &tmp);
1809
1739
Returns the 'bookmark' for the named variable.
1810
1740
LOCK_system_variables_hash should be at least read locked
1812
static st_bookmark *find_bookmark(const char *plugin, const char *name,
1742
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
1815
1744
st_bookmark *result= NULL;
1816
1745
uint namelen, length, pluginlen= 0;
2497
2424
options->arg_type= OPT_ARG;
2500
extern "C" my_bool get_one_plugin_option(int optid, const struct my_option *,
2427
extern "C" bool get_one_plugin_option(int optid, const struct my_option *,
2503
my_bool get_one_plugin_option(int optid __attribute__((unused)),
2430
bool get_one_plugin_option(int optid __attribute__((unused)),
2504
2431
const struct my_option *opt __attribute__((__unused__)),
2505
2432
char *argument __attribute__((__unused__)))
2511
2438
static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
2512
my_option *options, my_bool **enabled,
2439
my_option *options, bool can_disable)
2515
2441
const char *plugin_name= tmp->plugin->name;
2516
2442
uint namelen= strlen(plugin_name), optnamelen;
2543
2469
options[0].comment= name + namelen*2 + 10;
2547
NOTE: 'name' is one char above the allocated buffer!
2548
NOTE: This code assumes that 'my_bool' and 'char' are of same size.
2550
*((my_bool *)(name -1))= **enabled;
2551
*enabled= (my_bool *)(name - 1);
2554
2472
options[1].name= (options[0].name= name) + namelen + 1;
2555
2473
options[0].id= options[1].id= 256; /* must be >255. dup id ok */
2556
2474
options[0].var_type= options[1].var_type= GET_BOOL;
2557
2475
options[0].arg_type= options[1].arg_type= NO_ARG;
2558
options[0].def_value= options[1].def_value= **enabled;
2476
options[0].def_value= options[1].def_value= true;
2559
2477
options[0].value= options[0].u_max_value=
2560
2478
options[1].value= options[1].u_max_value= (char**) (name - 1);
2748
2665
bzero(opts, sizeof(my_option) * count);
2750
dummy= TRUE; /* plugin is enabled. */
2753
my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
2754
my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
2756
if (construct_options(mem_root, p, opts, &dummy2, can_disable))
2667
if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") == 0))
2669
else if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY") == 0))
2675
if (construct_options(mem_root, p, opts, can_disable))
2774
2693
Requires that a write-lock is held on LOCK_system_variables_hash
2776
2695
static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
2777
int *argc, char **argv, my_bool default_enabled)
2696
int *argc, char **argv)
2779
2698
struct sys_var_chain chain= { NULL, NULL };
2780
my_bool enabled_saved= default_enabled, can_disable;
2781
my_bool *enabled= &default_enabled;
2699
bool enabled_saved= true;
2782
2701
MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
2783
2702
&tmp->mem_root : &plugin_mem_root;
2784
2703
st_mysql_sys_var **opt;
2794
2713
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2795
2714
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
2798
my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
2799
my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
2716
if ((my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") == 0))
2718
else if ((my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY") == 0))
2801
2723
if (count > EXTRA_OPTIONS || (*argc > 1))
2808
2730
bzero(opts, sizeof(my_option) * count);
2810
if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
2732
if (construct_options(tmp_root, tmp, opts, can_disable))
2812
2734
sql_print_error("Bad options for plugin '%s'.", tmp->name.str);