~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_plugin.cc

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
extern int initialize_schema_table(st_plugin_int *plugin);
45
45
extern int finalize_schema_table(st_plugin_int *plugin);
46
46
 
 
47
extern int initialize_udf(st_plugin_int *plugin);
 
48
extern int finalize_udf(st_plugin_int *plugin);
 
49
 
47
50
/*
48
51
  The number of elements in both plugin_type_initialize and
49
52
  plugin_type_deinitialize should equal to the number of plugins
51
54
*/
52
55
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
53
56
{
54
 
  0,ha_initialize_handlerton,0,0,initialize_schema_table,
 
57
  initialize_udf,ha_initialize_handlerton,0,0,initialize_schema_table,
55
58
  0
56
59
};
57
60
 
58
61
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
59
62
{
60
 
  0,ha_finalize_handlerton,0,0,finalize_schema_table,
 
63
  finalize_udf,ha_finalize_handlerton,0,0,finalize_schema_table,
61
64
  0
62
65
};
63
66
 
64
 
#ifdef HAVE_DLOPEN
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;
71
 
#endif
72
73
 
73
74
/* Note that 'int version' must be the first field of every plugin
74
75
   sub-structure (plugin->info).
75
76
*/
76
77
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
77
78
{
78
 
  0x0000,
 
79
  MYSQL_UDF_INTERFACE_VERSION,
79
80
  MYSQL_HANDLERTON_INTERFACE_VERSION,
80
81
  MYSQL_FTPARSER_INTERFACE_VERSION,
81
82
  MYSQL_DAEMON_INTERFACE_VERSION,
84
85
};
85
86
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
86
87
{
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
                               int *, char **);
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);
267
268
  Plugin support code
268
269
****************************************************************************/
269
270
 
270
 
#ifdef HAVE_DLOPEN
271
 
 
272
271
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
273
272
{
274
273
  uint i;
285
284
  return(0);
286
285
}
287
286
 
288
 
 
289
287
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
290
288
{
291
289
  uint i;
307
305
                                           sizeof(struct st_plugin_dl));
308
306
  return(tmp);
309
307
}
310
 
#endif /* HAVE_DLOPEN */
311
 
 
312
308
 
313
309
static inline void free_plugin_mem(struct st_plugin_dl *p)
314
310
{
315
 
#ifdef HAVE_DLOPEN
316
311
  if (p->handle)
317
312
    dlclose(p->handle);
318
 
#endif
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))
711
705
      {
712
706
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
713
707
        {
798
792
  return;
799
793
}
800
794
 
801
 
#ifdef NOT_USED
802
 
 
803
 
static void plugin_del(const LEX_STRING *name)
804
 
{
805
 
  struct st_plugin_int *plugin;
806
 
  if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
807
 
    plugin_del(plugin);
808
 
  return;
809
 
}
810
 
 
811
 
#endif
812
 
 
813
795
static void reap_plugins(void)
814
796
{
815
797
  uint count, idx;
888
870
  if (!plugin)
889
871
    return;
890
872
  intern_plugin_unlock(lex, plugin);
891
 
  reap_plugins();
892
873
  return;
893
874
}
894
875
 
899
880
  assert(list);
900
881
  while (count--)
901
882
    intern_plugin_unlock(lex, *list++);
902
 
  reap_plugins();
903
883
  return;
904
884
}
905
885
 
1003
983
int plugin_init(int *argc, char **argv, int flags)
1004
984
{
1005
985
  uint i;
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;
1042
1021
  {
1043
1022
    for (plugin= *builtins; plugin->info; plugin++)
1044
1023
    {
1045
 
      /* by default, only ndbcluster is disabled */
1046
 
      def_enabled=
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);
1052
1028
 
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))
1055
1031
        continue;
1056
1032
 
1057
1033
      if (register_builtin(plugin, &tmp, &plugin_ptr))
1058
1034
        goto err_unlock;
1059
1035
 
1060
 
      /* only initialize MyISAM and CSV at this stage */
1061
 
      if (!(is_myisam=
1062
 
            !my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM")) &&
1063
 
          my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
1064
 
        continue;
1065
 
 
1066
1036
      if (plugin_initialize(plugin_ptr))
1067
1037
        goto err_unlock;
1068
1038
 
1070
1040
        initialize the global default storage engine so that it may
1071
1041
        not be null in any child thread.
1072
1042
      */
1073
 
      if (is_myisam)
 
1043
      if (my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM") == 0)
1074
1044
      {
1075
1045
        assert(!global_system_variables.table_plugin);
1076
1046
        global_system_variables.table_plugin=
1160
1130
}
1161
1131
 
1162
1132
 
1163
 
#ifdef NOT_USED_YET
1164
 
/*
1165
 
  Register a plugin at run time. (note, this doesn't initialize a plugin)
1166
 
  Will be useful for embedded applications.
1167
 
 
1168
 
  SYNOPSIS
1169
 
    plugin_register_builtin()
1170
 
    thd         current thread (used to store scratch data in mem_root)
1171
 
    plugin      static plugin to install
1172
 
 
1173
 
  RETURN
1174
 
    false - plugin registered successfully
1175
 
*/
1176
 
bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
1177
 
{
1178
 
  struct st_plugin_int tmp, *ptr;
1179
 
  bool result= true;
1180
 
  int dummy_argc= 0;
1181
 
 
1182
 
  bzero(&tmp, sizeof(tmp));
1183
 
  tmp.plugin= plugin;
1184
 
  tmp.name.str= (char *)plugin->name;
1185
 
  tmp.name.length= strlen(plugin->name);
1186
 
 
1187
 
  rw_wrlock(&LOCK_system_variables_hash);
1188
 
 
1189
 
  if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
1190
 
    goto end;
1191
 
 
1192
 
  if ((result= register_builtin(plugin, &tmp, &ptr)))
1193
 
    mysql_del_sys_var_chain(tmp.system_vars);
1194
 
 
1195
 
end:
1196
 
  rw_unlock(&LOCK_system_variables_hash);
1197
 
 
1198
 
  return(result);;
1199
 
}
1200
 
#endif /* NOT_USED_YET */
1201
 
 
1202
 
 
1203
1133
/*
1204
1134
  called only by plugin_init()
1205
1135
*/
1549
1479
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
1550
1480
                          void *save, st_mysql_value *value)
1551
1481
{
1552
 
  my_bool fixed;
 
1482
  bool fixed;
1553
1483
  int64_t tmp;
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)
1571
1501
{
1572
 
  my_bool fixed;
 
1502
  bool fixed;
1573
1503
  int64_t tmp;
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)
1591
1521
{
1592
 
  my_bool fixed;
 
1522
  bool fixed;
1593
1523
  int64_t tmp;
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
1811
1741
*/
1812
 
static st_bookmark *find_bookmark(const char *plugin, const char *name,
1813
 
                                  int flags)
 
1742
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
1814
1743
{
1815
1744
  st_bookmark *result= NULL;
1816
1745
  uint namelen, length, pluginlen= 0;
2133
2062
      intern_plugin_unlock(NULL, *list--);
2134
2063
  }
2135
2064
 
2136
 
  reap_plugins();
2137
 
 
2138
2065
  reset_dynamic(&thd->lex->plugins);
2139
2066
 
2140
2067
  return;
2497
2424
    options->arg_type= OPT_ARG;
2498
2425
}
2499
2426
 
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 *,
2501
2428
                                         char *);
2502
2429
 
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__)))
2506
2433
{
2509
2436
 
2510
2437
 
2511
2438
static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
2512
 
                             my_option *options, my_bool **enabled,
2513
 
                             bool can_disable)
 
2439
                             my_option *options, bool can_disable)
2514
2440
{
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;
2544
2470
  }
2545
2471
 
2546
 
  /*
2547
 
    NOTE: 'name' is one char above the allocated buffer!
2548
 
    NOTE: This code assumes that 'my_bool' and 'char' are of same size.
2549
 
  */
2550
 
  *((my_bool *)(name -1))= **enabled;
2551
 
  *enabled= (my_bool *)(name - 1);
2552
 
 
2553
 
 
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);
2561
2479
  options+= 2;
2736
2654
{
2737
2655
  st_mysql_sys_var **opt;
2738
2656
  my_option *opts;
2739
 
  my_bool dummy, can_disable;
2740
 
  my_bool *dummy2= &dummy;
 
2657
  bool can_disable;
2741
2658
  uint count= EXTRA_OPTIONS;
2742
2659
 
2743
2660
  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2) {};
2747
2664
 
2748
2665
  bzero(opts, sizeof(my_option) * count);
2749
2666
 
2750
 
  dummy= TRUE; /* plugin is enabled. */
2751
 
 
2752
 
  can_disable=
2753
 
      my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
2754
 
      my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
2755
 
 
2756
 
  if (construct_options(mem_root, p, opts, &dummy2, can_disable))
 
2667
  if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") == 0))
 
2668
    can_disable= false;
 
2669
  else if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY") == 0))
 
2670
    can_disable= false;
 
2671
  else
 
2672
    can_disable= true;
 
2673
 
 
2674
 
 
2675
  if (construct_options(mem_root, p, opts, can_disable))
2757
2676
    return(NULL);
2758
2677
 
2759
2678
  return(opts);
2774
2693
    Requires that a write-lock is held on LOCK_system_variables_hash
2775
2694
*/
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)
2778
2697
{
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;
 
2700
  bool can_disable;
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} */
2796
2715
 
2797
 
  can_disable=
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))
 
2717
    can_disable= false;
 
2718
  else if ((my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY") == 0))
 
2719
    can_disable= false;
 
2720
  else
 
2721
    can_disable= true;
2800
2722
 
2801
2723
  if (count > EXTRA_OPTIONS || (*argc > 1))
2802
2724
  {
2807
2729
    }
2808
2730
    bzero(opts, sizeof(my_option) * count);
2809
2731
 
2810
 
    if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
 
2732
    if (construct_options(tmp_root, tmp, opts, can_disable))
2811
2733
    {
2812
2734
      sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
2813
2735
      return(-1);
2824
2746
    }
2825
2747
  }
2826
2748
 
2827
 
  if (!*enabled && !can_disable)
2828
 
  {
2829
 
    sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str);
2830
 
    *enabled= TRUE;
2831
 
  }
2832
 
 
2833
2749
  error= 1;
2834
2750
 
2835
 
  if (*enabled)
2836
2751
  {
2837
2752
    for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2838
2753
    {