33
31
When you ad a new plugin type, add both a string and make sure that the
34
32
init and deinit array are correctly updated.
36
const LEX_STRING plugin_type_names[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
34
const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
36
{ C_STRING_WITH_LEN("UDF") },
37
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
38
{ C_STRING_WITH_LEN("FTPARSER") },
38
39
{ C_STRING_WITH_LEN("DAEMON") },
39
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
40
40
{ C_STRING_WITH_LEN("INFORMATION SCHEMA") },
41
{ C_STRING_WITH_LEN("UDF") },
42
{ C_STRING_WITH_LEN("UDA") },
43
{ C_STRING_WITH_LEN("AUDIT") },
44
{ C_STRING_WITH_LEN("LOGGER") },
45
{ C_STRING_WITH_LEN("AUTH") }
41
{ C_STRING_WITH_LEN("AUDIT") }
48
44
extern int initialize_schema_table(st_plugin_int *plugin);
56
52
plugin_type_deinitialize should equal to the number of plugins
59
plugin_type_init plugin_type_initialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
62
ha_initialize_handlerton, /* Storage Engine */
63
initialize_schema_table, /* Information Schema */
64
initialize_udf, /* UDF */
67
logging_initializer, /* Logger */
68
authentication_initializer /* Auth */
71
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
74
ha_finalize_handlerton, /* Storage Engine */
75
finalize_schema_table, /* Information Schema */
76
finalize_udf, /* UDF */
79
logging_finalizer, /* Logger */
80
authentication_finalizer /* Auth */
55
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
57
initialize_udf,ha_initialize_handlerton,0,0,initialize_schema_table,
61
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
63
finalize_udf,ha_finalize_handlerton,0,0,finalize_schema_table,
67
static const char *plugin_interface_version_sym=
68
"_mysql_plugin_interface_version_";
69
static const char *sizeof_st_plugin_sym=
70
"_mysql_sizeof_struct_st_plugin_";
83
71
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
72
static int min_plugin_interface_version= MYSQL_PLUGIN_INTERFACE_VERSION & ~0xFF;
85
74
/* Note that 'int version' must be the first field of every plugin
86
75
sub-structure (plugin->info).
77
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
79
MYSQL_UDF_INTERFACE_VERSION,
80
MYSQL_HANDLERTON_INTERFACE_VERSION,
81
MYSQL_FTPARSER_INTERFACE_VERSION,
82
MYSQL_DAEMON_INTERFACE_VERSION,
83
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
84
MYSQL_AUDIT_INTERFACE_VERSION
86
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
88
MYSQL_UDF_INTERFACE_VERSION,
89
MYSQL_HANDLERTON_INTERFACE_VERSION,
90
MYSQL_FTPARSER_INTERFACE_VERSION,
91
MYSQL_DAEMON_INTERFACE_VERSION,
92
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
93
MYSQL_AUDIT_INTERFACE_VERSION
89
96
static bool initialized= 0;
91
98
static DYNAMIC_ARRAY plugin_dl_array;
92
99
static DYNAMIC_ARRAY plugin_array;
93
static HASH plugin_hash[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
100
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
94
101
static bool reap_needed= false;
95
102
static int plugin_array_version=0;
166
173
{ return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
167
174
bool check_update_type(Item_result type);
168
175
SHOW_TYPE show_type();
169
unsigned char* real_value_ptr(THD *thd, enum_var_type type);
176
uchar* real_value_ptr(THD *thd, enum_var_type type);
170
177
TYPELIB* plugin_var_typelib(void);
171
unsigned char* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
178
uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
172
179
bool check(THD *thd, set_var *var);
173
bool check_default(enum_var_type type __attribute__((unused)))
180
bool check_default(enum_var_type type __attribute__((__unused__)))
174
181
{ return is_readonly(); }
175
182
void set_default(THD *thd,
176
enum_var_type type __attribute__((unused)));
183
enum_var_type type __attribute__((__unused__)));
177
184
bool update(THD *thd, set_var *var);
336
346
tmp->ref_count++;
339
memset(&plugin_dl, 0, sizeof(plugin_dl));
349
bzero(&plugin_dl, sizeof(plugin_dl));
340
350
/* Compile dll path */
342
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
352
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
344
354
plugin_dl.ref_count= 1;
345
355
/* Open new dll handle */
346
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
356
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
348
358
const char *errmsg=dlerror();
349
359
if (!strncmp(dlpath, errmsg, dlpathlen))
358
368
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
371
/* Determine interface version */
372
if (!(sym= dlsym(plugin_dl.handle, plugin_interface_version_sym)))
374
free_plugin_mem(&plugin_dl);
375
if (report & REPORT_TO_USER)
376
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_interface_version_sym);
377
if (report & REPORT_TO_LOG)
378
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_interface_version_sym);
381
plugin_dl.version= *(int *)sym;
383
if (plugin_dl.version < min_plugin_interface_version ||
384
(plugin_dl.version >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8))
386
free_plugin_mem(&plugin_dl);
387
if (report & REPORT_TO_USER)
388
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, 0,
389
"plugin interface version mismatch");
390
if (report & REPORT_TO_LOG)
391
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, 0,
392
"plugin interface version mismatch");
362
395
/* Find plugin declarations */
363
396
if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
406
if (plugin_dl.version != MYSQL_PLUGIN_INTERFACE_VERSION)
409
uint sizeof_st_plugin;
410
struct st_mysql_plugin *old, *cur;
411
char *ptr= (char *)sym;
413
if ((sym= dlsym(plugin_dl.handle, sizeof_st_plugin_sym)))
414
sizeof_st_plugin= *(int *)sym;
417
#ifdef ERROR_ON_NO_SIZEOF_PLUGIN_SYMBOL
418
free_plugin_mem(&plugin_dl);
419
if (report & REPORT_TO_USER)
420
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), sizeof_st_plugin_sym);
421
if (report & REPORT_TO_LOG)
422
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), sizeof_st_plugin_sym);
426
When the following assert starts failing, we'll have to switch
427
to the upper branch of the #ifdef
429
assert(min_plugin_interface_version == 0);
430
sizeof_st_plugin= (int)offsetof(struct st_mysql_plugin, version);
435
((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
439
cur= (struct st_mysql_plugin*)
440
my_malloc(i*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
443
free_plugin_mem(&plugin_dl);
444
if (report & REPORT_TO_USER)
445
my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
446
if (report & REPORT_TO_LOG)
447
sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
451
All st_plugin fields not initialized in the plugin explicitly, are
452
set to 0. It matches C standard behaviour for struct initializers that
453
have less values than the struct definition.
456
(old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
458
memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
373
462
plugin_dl.plugins= (struct st_mysql_plugin *)sym;
375
464
/* Duplicate and convert dll name */
411
508
struct st_plugin_dl **);
412
509
if (tmp->ref_count &&
413
510
! my_strnncoll(files_charset_info,
414
(const unsigned char *)dl->str, dl->length,
415
(const unsigned char *)tmp->dl.str, tmp->dl.length))
511
(const uchar *)dl->str, dl->length,
512
(const uchar *)tmp->dl.str, tmp->dl.length))
417
514
/* Do not remove this element, unless no other plugin uses this dll. */
418
515
if (! --tmp->ref_count)
420
517
free_plugin_mem(tmp);
421
memset(tmp, 0, sizeof(struct st_plugin_dl));
518
bzero(tmp, sizeof(struct st_plugin_dl));
430
528
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
433
531
if (! initialized)
436
if (type == DRIZZLE_ANY_PLUGIN)
534
if (type == MYSQL_ANY_PLUGIN)
438
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
536
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
440
538
struct st_plugin_int *plugin= (st_plugin_int *)
441
hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
539
hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
447
545
return((st_plugin_int *)
448
hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
546
hash_search(&plugin_hash[type], (const uchar *)name->str, name->length));
561
659
struct st_plugin_int tmp;
562
660
struct st_mysql_plugin *plugin;
563
if (plugin_find_internal(name, DRIZZLE_ANY_PLUGIN))
661
if (plugin_find_internal(name, MYSQL_ANY_PLUGIN))
565
663
if (report & REPORT_TO_USER)
566
664
my_error(ER_UDF_EXISTS, MYF(0), name->str);
567
665
if (report & REPORT_TO_LOG)
568
666
sql_print_error(ER(ER_UDF_EXISTS), name->str);
571
669
/* Clear the whole struct to catch future extensions. */
572
memset(&tmp, 0, sizeof(tmp));
670
bzero((char*) &tmp, sizeof(tmp));
573
671
if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
575
673
/* Find plugin by name */
576
for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
674
for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
578
uint32_t name_len= strlen(plugin->name);
579
if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
676
uint name_len= strlen(plugin->name);
677
if (plugin->type >= 0 && plugin->type < MYSQL_MAX_PLUGIN_TYPE_NUM &&
580
678
! my_strnncoll(system_charset_info,
581
(const unsigned char *)name->str, name->length,
582
(const unsigned char *)plugin->name,
679
(const uchar *)name->str, name->length,
680
(const uchar *)plugin->name,
585
683
struct st_plugin_int *tmp_plugin_ptr;
684
if (*(int*)plugin->info <
685
min_plugin_info_interface_version[plugin->type] ||
686
((*(int*)plugin->info) >> 8) >
687
(cur_plugin_info_interface_version[plugin->type] >> 8))
690
strxnmov(buf, sizeof(buf) - 1, "API version for ",
691
plugin_type_names[plugin->type].str,
692
" plugin is too different", NullS);
693
if (report & REPORT_TO_USER)
694
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dl->str, 0, buf);
695
if (report & REPORT_TO_LOG)
696
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dl->str, 0, buf);
587
699
tmp.plugin= plugin;
588
700
tmp.name.str= (char *)plugin->name;
589
701
tmp.name.length= name_len;
590
702
tmp.ref_count= 0;
591
703
tmp.state= PLUGIN_IS_UNINITIALIZED;
592
if (!test_plugin_options(tmp_root, &tmp, argc, argv))
704
if (!test_plugin_options(tmp_root, &tmp, argc, argv, true))
594
706
if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
596
708
plugin_array_version++;
597
if (!my_hash_insert(&plugin_hash[plugin->type], (unsigned char*)tmp_plugin_ptr))
709
if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
599
711
init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
602
714
tmp_plugin_ptr->state= PLUGIN_IS_FREED;
842
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
843
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
846
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length,
847
bool not_used __attribute__((unused)))
968
extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, my_bool);
969
extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, my_bool);
972
uchar *get_plugin_hash_key(const uchar *buff, size_t *length,
973
my_bool not_used __attribute__((unused)))
849
975
struct st_plugin_int *plugin= (st_plugin_int *)buff;
850
976
*length= (uint)plugin->name.length;
851
return((unsigned char *)plugin->name.str);
977
return((uchar *)plugin->name.str);
855
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length,
856
bool not_used __attribute__((unused)))
981
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
982
my_bool not_used __attribute__((unused)))
858
984
struct st_bookmark *var= (st_bookmark *)buff;
859
985
*length= var->name_len + 1;
860
return (unsigned char*) var->key;
986
return (uchar*) var->key;
908
1035
for (builtins= mysqld_builtins; *builtins; builtins++)
910
for (plugin= *builtins; plugin->name; plugin++)
1037
for (plugin= *builtins; plugin->info; plugin++)
912
memset(&tmp, 0, sizeof(tmp));
1039
/* by default, only ndbcluster is disabled */
1041
my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0;
1042
bzero(&tmp, sizeof(tmp));
913
1043
tmp.plugin= plugin;
914
1044
tmp.name.str= (char *)plugin->name;
915
1045
tmp.name.length= strlen(plugin->name);
917
1047
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
918
if (test_plugin_options(&tmp_root, &tmp, argc, argv))
1048
if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled))
921
1051
if (register_builtin(plugin, &tmp, &plugin_ptr))
922
1052
goto err_unlock;
1054
/* only initialize MyISAM and CSV at this stage */
1056
!my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM")) &&
1057
my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
924
1060
if (plugin_initialize(plugin_ptr))
925
1061
goto err_unlock;
1003
1139
tmp->ref_count= 0;
1004
1140
tmp->plugin_dl= 0;
1006
if (insert_dynamic(&plugin_array, (unsigned char*)&tmp))
1142
if (insert_dynamic(&plugin_array, (uchar*)&tmp))
1009
1145
*ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
1010
1146
struct st_plugin_int **)=
1011
(struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)tmp,
1147
(struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)tmp,
1012
1148
sizeof(struct st_plugin_int));
1014
if (my_hash_insert(&plugin_hash[plugin->type],(unsigned char*) *ptr))
1150
if (my_hash_insert(&plugin_hash[plugin->type],(uchar*) *ptr))
1159
Register a plugin at run time. (note, this doesn't initialize a plugin)
1160
Will be useful for embedded applications.
1163
plugin_register_builtin()
1164
thd current thread (used to store scratch data in mem_root)
1165
plugin static plugin to install
1168
false - plugin registered successfully
1170
bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
1172
struct st_plugin_int tmp, *ptr;
1176
bzero(&tmp, sizeof(tmp));
1178
tmp.name.str= (char *)plugin->name;
1179
tmp.name.length= strlen(plugin->name);
1181
rw_wrlock(&LOCK_system_variables_hash);
1183
if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
1186
if ((result= register_builtin(plugin, &tmp, &ptr)))
1187
mysql_del_sys_var_chain(tmp.system_vars);
1190
rw_unlock(&LOCK_system_variables_hash);
1194
#endif /* NOT_USED_YET */
1022
1198
called only by plugin_init()
1227
1402
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
1228
int type, uint32_t state_mask, void *arg)
1403
int type, uint state_mask, void *arg)
1230
uint32_t idx, total;
1231
1406
struct st_plugin_int *plugin, **plugins;
1232
1407
int version=plugin_array_version;
1234
1409
if (!initialized)
1237
1412
state_mask= ~state_mask; // do it only once
1239
total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
1414
total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements
1240
1415
: plugin_hash[type].records;
1242
1417
Do the alloca out here in case we do have a working alloca:
1243
1418
leaving the nested stack frame invalidates alloca allocation.
1245
1420
plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
1246
if (type == DRIZZLE_ANY_PLUGIN)
1421
if (type == MYSQL_ANY_PLUGIN)
1248
1423
for (idx= 0; idx < total; idx++)
1286
1461
Internal type declarations for variables support
1287
1462
****************************************************************************/
1289
#undef DRIZZLE_SYSVAR_NAME
1290
#define DRIZZLE_SYSVAR_NAME(name) name
1464
#undef MYSQL_SYSVAR_NAME
1465
#define MYSQL_SYSVAR_NAME(name) name
1291
1466
#define PLUGIN_VAR_TYPEMASK 0x007f
1293
1468
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1295
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1296
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
1297
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1298
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
1300
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1301
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1302
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1303
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
1305
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1306
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1307
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
1308
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
1309
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1310
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1312
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1313
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1314
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1315
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1316
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1317
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1319
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
1470
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_bool_t, my_bool);
1471
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_bool_t, my_bool);
1472
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_str_t, char *);
1473
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_str_t, char *);
1475
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1476
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1477
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_set_t, ulonglong);
1478
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_set_t, ulonglong);
1480
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_int_t, int);
1481
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_long_t, long);
1482
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_longlong_t, longlong);
1483
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_uint_t, uint);
1484
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1485
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulonglong_t, ulonglong);
1487
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int);
1488
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_long_t, long);
1489
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_longlong_t, longlong);
1490
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_uint_t, uint);
1491
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1492
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulonglong_t, ulonglong);
1494
#define SET_PLUGIN_VAR_RESOLVE(opt)\
1495
*(mysql_sys_var_ptr_p*)&((opt)->resolve)= mysql_sys_var_ptr
1496
typedef uchar *(*mysql_sys_var_ptr_p)(void* a_thd, int offset);
1322
1499
/****************************************************************************
1323
1500
default variable data check and update functions
1324
1501
****************************************************************************/
1326
static int check_func_bool(THD *thd __attribute__((unused)),
1503
static int check_func_bool(THD *thd __attribute__((__unused__)),
1327
1504
struct st_mysql_sys_var *var,
1328
1505
void *save, st_mysql_value *value)
1366
1543
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
1367
1544
void *save, st_mysql_value *value)
1371
1548
struct my_option options;
1372
1549
value->val_int(value, &tmp);
1373
1550
plugin_opt_set_limits(&options, var);
1375
1552
if (var->flags & PLUGIN_VAR_UNSIGNED)
1376
*(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1553
*(uint *)save= (uint) getopt_ull_limit_value((ulonglong) tmp, &options,
1379
1556
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1381
1558
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1382
var->name, (int64_t) tmp);
1559
var->name, (longlong) tmp);
1386
1563
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
1387
1564
void *save, st_mysql_value *value)
1391
1568
struct my_option options;
1392
1569
value->val_int(value, &tmp);
1393
1570
plugin_opt_set_limits(&options, var);
1395
1572
if (var->flags & PLUGIN_VAR_UNSIGNED)
1396
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
1573
*(ulong *)save= (ulong) getopt_ull_limit_value((ulonglong) tmp, &options,
1399
1576
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
1401
1578
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1402
var->name, (int64_t) tmp);
1579
var->name, (longlong) tmp);
1406
static int check_func_int64_t(THD *thd, struct st_mysql_sys_var *var,
1583
static int check_func_longlong(THD *thd, struct st_mysql_sys_var *var,
1407
1584
void *save, st_mysql_value *value)
1411
1588
struct my_option options;
1412
1589
value->val_int(value, &tmp);
1413
1590
plugin_opt_set_limits(&options, var);
1415
1592
if (var->flags & PLUGIN_VAR_UNSIGNED)
1416
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
1593
*(ulonglong *)save= getopt_ull_limit_value((ulonglong) tmp, &options,
1419
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1596
*(longlong *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1421
1598
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1422
var->name, (int64_t) tmp);
1599
var->name, (longlong) tmp);
1425
1602
static int check_func_str(THD *thd,
1426
struct st_mysql_sys_var *var __attribute__((unused)),
1603
struct st_mysql_sys_var *var __attribute__((__unused__)),
1427
1604
void *save, st_mysql_value *value)
1429
1606
char buff[STRING_BUFFER_USUAL_SIZE];
1539
static void update_func_bool(THD *thd __attribute__((unused)),
1540
struct st_mysql_sys_var *var __attribute__((unused)),
1716
static void update_func_bool(THD *thd __attribute__((__unused__)),
1717
struct st_mysql_sys_var *var __attribute__((__unused__)),
1541
1718
void *tgt, const void *save)
1543
*(bool *) tgt= *(int *) save ? 1 : 0;
1720
*(my_bool *) tgt= *(int *) save ? 1 : 0;
1547
static void update_func_int(THD *thd __attribute__((unused)),
1548
struct st_mysql_sys_var *var __attribute__((unused)),
1724
static void update_func_int(THD *thd __attribute__((__unused__)),
1725
struct st_mysql_sys_var *var __attribute__((__unused__)),
1549
1726
void *tgt, const void *save)
1551
1728
*(int *)tgt= *(int *) save;
1555
static void update_func_long(THD *thd __attribute__((unused)),
1556
struct st_mysql_sys_var *var __attribute__((unused)),
1732
static void update_func_long(THD *thd __attribute__((__unused__)),
1733
struct st_mysql_sys_var *var __attribute__((__unused__)),
1557
1734
void *tgt, const void *save)
1559
1736
*(long *)tgt= *(long *) save;
1563
static void update_func_int64_t(THD *thd __attribute__((unused)),
1564
struct st_mysql_sys_var *var __attribute__((unused)),
1740
static void update_func_longlong(THD *thd __attribute__((__unused__)),
1741
struct st_mysql_sys_var *var __attribute__((__unused__)),
1565
1742
void *tgt, const void *save)
1567
*(int64_t *)tgt= *(uint64_t *) save;
1744
*(longlong *)tgt= *(ulonglong *) save;
1571
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
1748
static void update_func_str(THD *thd __attribute__((__unused__)), struct st_mysql_sys_var *var,
1572
1749
void *tgt, const void *save)
1574
1751
char *old= *(char **) tgt;
1735
1913
variables. If their value is non-NULL, it must point to a valid
1738
memset(global_system_variables.dynamic_variables_ptr +
1739
global_variables_dynamic_size, 0,
1740
new_size - global_variables_dynamic_size);
1741
memset(max_system_variables.dynamic_variables_ptr +
1742
global_variables_dynamic_size, 0,
1743
new_size - global_variables_dynamic_size);
1916
bzero(global_system_variables.dynamic_variables_ptr +
1917
global_variables_dynamic_size,
1918
new_size - global_variables_dynamic_size);
1919
bzero(max_system_variables.dynamic_variables_ptr +
1920
global_variables_dynamic_size,
1921
new_size - global_variables_dynamic_size);
1744
1922
global_variables_dynamic_size= new_size;
1848
2026
rw_unlock(&LOCK_system_variables_hash);
1850
return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1853
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1855
return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1858
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1860
return (int *)intern_sys_var_ptr(a_thd, offset, true);
1863
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1865
return (long *)intern_sys_var_ptr(a_thd, offset, true);
1868
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1870
return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1873
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1875
return (char **)intern_sys_var_ptr(a_thd, offset, true);
1878
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1880
return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1883
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1885
return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
2028
return (uchar*)thd->variables.dynamic_variables_ptr + offset;
2031
static uchar *mysql_sys_var_ptr(void* a_thd, int offset)
2033
return intern_sys_var_ptr((THD *)a_thd, offset, true);
2091
unsigned char* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2092
LEX_STRING *base __attribute__((unused)))
2241
uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2242
LEX_STRING *base __attribute__((__unused__)))
2094
unsigned char* result;
2096
2246
result= real_value_ptr(thd, type);
2098
2248
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2099
result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2249
result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
2100
2250
else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
2102
2252
char buffer[STRING_BUFFER_USUAL_SIZE];
2103
2253
String str(buffer, sizeof(buffer), system_charset_info);
2104
2254
TYPELIB *typelib= plugin_var_typelib();
2105
uint64_t mask= 1, value= *(uint64_t*) result;
2255
ulonglong mask= 1, value= *(ulonglong*) result;
2109
2259
for (i= 0; i < typelib->count; i++, mask<<=1)
2303
2453
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2305
2455
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2306
OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2456
OPTION_SET_LIMITS(GET_LL, options, (thdvar_longlong_t*) opt);
2308
2458
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2309
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2459
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_ulonglong_t*) opt);
2311
2461
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2312
2462
options->var_type= GET_ENUM;
2341
2491
options->arg_type= OPT_ARG;
2344
extern "C" bool get_one_plugin_option(int optid, const struct my_option *,
2494
extern "C" my_bool get_one_plugin_option(int optid, const struct my_option *,
2347
bool get_one_plugin_option(int optid __attribute__((unused)),
2348
const struct my_option *opt __attribute__((unused)),
2349
char *argument __attribute__((unused)))
2497
my_bool get_one_plugin_option(int optid __attribute__((unused)),
2498
const struct my_option *opt __attribute__((__unused__)),
2499
char *argument __attribute__((__unused__)))
2355
2505
static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
2356
my_option *options, bool can_disable)
2506
my_option *options, my_bool **enabled,
2358
2509
const char *plugin_name= tmp->plugin->name;
2359
uint32_t namelen= strlen(plugin_name), optnamelen;
2360
uint32_t buffer_length= namelen * 4 + (can_disable ? 75 : 10);
2510
uint namelen= strlen(plugin_name), optnamelen;
2511
uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
2361
2512
char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
2362
2513
char *optname, *p;
2363
2514
int index= 0, offset= 0;
2386
2537
options[0].comment= name + namelen*2 + 10;
2541
NOTE: 'name' is one char above the allocated buffer!
2542
NOTE: This code assumes that 'my_bool' and 'char' are of same size.
2544
*((my_bool *)(name -1))= **enabled;
2545
*enabled= (my_bool *)(name - 1);
2389
2548
options[1].name= (options[0].name= name) + namelen + 1;
2390
2549
options[0].id= options[1].id= 256; /* must be >255. dup id ok */
2391
2550
options[0].var_type= options[1].var_type= GET_BOOL;
2392
2551
options[0].arg_type= options[1].arg_type= NO_ARG;
2393
options[0].def_value= options[1].def_value= true;
2552
options[0].def_value= options[1].def_value= **enabled;
2394
2553
options[0].value= options[0].u_max_value=
2395
2554
options[1].value= options[1].u_max_value= (char**) (name - 1);
2411
2570
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2412
2571
case PLUGIN_VAR_BOOL:
2413
(((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2572
SET_PLUGIN_VAR_RESOLVE((thdvar_bool_t *) opt);
2415
2574
case PLUGIN_VAR_INT:
2416
(((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2575
SET_PLUGIN_VAR_RESOLVE((thdvar_int_t *) opt);
2418
2577
case PLUGIN_VAR_LONG:
2419
(((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2578
SET_PLUGIN_VAR_RESOLVE((thdvar_long_t *) opt);
2421
2580
case PLUGIN_VAR_LONGLONG:
2422
(((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2581
SET_PLUGIN_VAR_RESOLVE((thdvar_longlong_t *) opt);
2424
2583
case PLUGIN_VAR_STR:
2425
(((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2584
SET_PLUGIN_VAR_RESOLVE((thdvar_str_t *) opt);
2427
2586
case PLUGIN_VAR_ENUM:
2428
(((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2587
SET_PLUGIN_VAR_RESOLVE((thdvar_enum_t *) opt);
2430
2589
case PLUGIN_VAR_SET:
2431
(((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2590
SET_PLUGIN_VAR_RESOLVE((thdvar_set_t *) opt);
2434
sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2593
sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2435
2594
opt->flags, plugin_name);
2572
2731
st_mysql_sys_var **opt;
2573
2732
my_option *opts;
2575
uint32_t count= EXTRA_OPTIONS;
2733
my_bool dummy, can_disable;
2734
my_bool *dummy2= &dummy;
2735
uint count= EXTRA_OPTIONS;
2577
2737
for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2) {};
2579
2739
if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
2582
memset(opts, 0, sizeof(my_option) * count);
2584
if ((my_strcasecmp(&my_charset_utf8_general_ci, p->name.str, "MyISAM") == 0))
2586
else if ((my_strcasecmp(&my_charset_utf8_general_ci, p->name.str, "MEMORY") == 0))
2592
if (construct_options(mem_root, p, opts, can_disable))
2742
bzero(opts, sizeof(my_option) * count);
2744
dummy= TRUE; /* plugin is enabled. */
2747
my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
2748
my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
2750
if (construct_options(mem_root, p, opts, &dummy2, can_disable))
2624
2782
st_mysql_sys_var *o;
2626
2784
struct st_bookmark *var;
2627
uint32_t len, count= EXTRA_OPTIONS;
2785
uint len, count= EXTRA_OPTIONS;
2628
2786
assert(tmp->plugin && tmp->name.str);
2630
2788
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2631
2789
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
2633
if ((my_strcasecmp(&my_charset_utf8_general_ci, tmp->name.str, "MyISAM") == 0))
2635
else if ((my_strcasecmp(&my_charset_utf8_general_ci, tmp->name.str, "MEMORY") == 0))
2792
my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
2793
my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
2640
2795
if (count > EXTRA_OPTIONS || (*argc > 1))
2642
2797
if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
2644
sql_print_error(_("Out of memory for plugin '%s'."), tmp->name.str);
2799
sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
2647
memset(opts, 0, sizeof(my_option) * count);
2802
bzero(opts, sizeof(my_option) * count);
2649
if (construct_options(tmp_root, tmp, opts, can_disable))
2804
if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
2651
sql_print_error(_("Bad options for plugin '%s'."), tmp->name.str);
2806
sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
2751
2913
/* Only options with a non-NULL comment are displayed in help text */
2752
2914
for (;opt->id; opt++)
2753
2915
if (opt->comment)
2754
insert_dynamic(&all_options, (unsigned char*) opt);
2916
insert_dynamic(&all_options, (uchar*) opt);
2757
2919
for (;main_options->id; main_options++)
2758
insert_dynamic(&all_options, (unsigned char*) main_options);
2920
insert_dynamic(&all_options, (uchar*) main_options);
2760
2922
sort_dynamic(&all_options, (qsort_cmp) option_cmp);
2762
2924
/* main_options now points to the empty option terminator */
2763
insert_dynamic(&all_options, (unsigned char*) main_options);
2925
insert_dynamic(&all_options, (uchar*) main_options);
2765
2927
my_print_help((my_option*) all_options.buffer);
2766
2928
my_print_variables((my_option*) all_options.buffer);