1 /* Copyright (c) 2005, 2012, Oracle and/or its affiliates. 2 Copyright (c) 2009, 2017, MariaDB Corporation. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 16 17 #ifndef _sql_plugin_h 18 #define _sql_plugin_h 19 20 /* 21 the following #define adds server-only members to enum_mysql_show_type, 22 that is defined in plugin.h 23 */ 24 #define SHOW_always_last SHOW_KEY_CACHE_LONG, \ 25 SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ 26 SHOW_LONG_NOFLUSH, SHOW_LEX_STRING, \ 27 /* SHOW_*_STATUS must be at the end, SHOW_LONG_STATUS being first */ \ 28 SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_LONGLONG_STATUS, \ 29 SHOW_UINT32_STATUS 30 #include <my_global.h> 31 #undef SHOW_always_last 32 33 #include "m_string.h" /* LEX_STRING */ 34 #include "my_alloc.h" /* MEM_ROOT */ 35 36 class sys_var; 37 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED}; 38 enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE, 39 PLUGIN_FORCE_PLUS_PERMANENT }; 40 extern const char *global_plugin_typelib_names[]; 41 42 extern volatile int global_plugin_version; 43 extern ulong dlopen_count; 44 45 #include <my_sys.h> 46 #include "sql_list.h" 47 48 #ifdef DBUG_OFF 49 #define plugin_ref_to_int(A) A 50 #define plugin_int_to_ref(A) A 51 #else 52 #define plugin_ref_to_int(A) (A ? A[0] : NULL) 53 #define plugin_int_to_ref(A) &(A) 54 #endif 55 56 /* 57 the following flags are valid for plugin_init() 58 */ 59 #define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1U 60 #define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2U 61 #define PLUGIN_INIT_SKIP_INITIALIZATION 4U 62 63 #define INITIAL_LEX_PLUGIN_LIST_SIZE 16 64 65 typedef enum enum_mysql_show_type SHOW_TYPE; 66 typedef struct st_mysql_show_var SHOW_VAR; 67 68 #define MYSQL_ANY_PLUGIN -1 69 70 /* 71 different values of st_plugin_int::state 72 though they look like a bitmap, plugin may only 73 be in one of those eigenstates, not in a superposition of them :) 74 It's a bitmap, because it makes it easier to test 75 "whether the state is one of those..." 76 */ 77 #define PLUGIN_IS_FREED 1U 78 #define PLUGIN_IS_DELETED 2U 79 #define PLUGIN_IS_UNINITIALIZED 4U 80 #define PLUGIN_IS_READY 8U 81 #define PLUGIN_IS_DYING 16U 82 #define PLUGIN_IS_DISABLED 32U 83 84 struct st_ptr_backup { 85 void **ptr; 86 void *value; savest_ptr_backup87 void save(void **p) { ptr= p; value= *p; } savest_ptr_backup88 void save(const char **p) { save((void**)p); } restorest_ptr_backup89 void restore() { *ptr= value; } 90 }; 91 92 /* A handle for the dynamic library containing a plugin or plugins. */ 93 94 struct st_plugin_dl 95 { 96 LEX_CSTRING dl; 97 void *handle; 98 struct st_maria_plugin *plugins; 99 st_ptr_backup *ptr_backup; 100 uint nbackups; 101 uint ref_count; /* number of plugins loaded from the library */ 102 int mysqlversion; 103 int mariaversion; 104 bool allocated; 105 }; 106 107 /* A handle of a plugin */ 108 109 struct st_plugin_int 110 { 111 LEX_CSTRING name; 112 struct st_maria_plugin *plugin; 113 struct st_plugin_dl *plugin_dl; 114 st_ptr_backup *ptr_backup; 115 uint nbackups; 116 uint state; 117 uint ref_count; /* number of threads using the plugin */ 118 uint locks_total; /* how many times the plugin was locked */ 119 void *data; /* plugin type specific, e.g. handlerton */ 120 MEM_ROOT mem_root; /* memory for dynamic plugin structures */ 121 sys_var *system_vars; /* server variables for this plugin */ 122 enum enum_plugin_load_option load_option; /* OFF, ON, FORCE, F+PERMANENT */ 123 }; 124 125 126 extern mysql_mutex_t LOCK_plugin; 127 128 /* 129 See intern_plugin_lock() for the explanation for the 130 conditionally defined plugin_ref type 131 */ 132 #ifdef DBUG_OFF 133 typedef struct st_plugin_int *plugin_ref; 134 #define plugin_ref_to_int(A) A 135 #define plugin_int_to_ref(A) A 136 #define plugin_decl(pi) ((pi)->plugin) 137 #define plugin_dlib(pi) ((pi)->plugin_dl) 138 #define plugin_data(pi,cast) ((cast)((pi)->data)) 139 #define plugin_name(pi) (&((pi)->name)) 140 #define plugin_state(pi) ((pi)->state) 141 #define plugin_load_option(pi) ((pi)->load_option) 142 #define plugin_equals(p1,p2) ((p1) == (p2)) 143 #else 144 typedef struct st_plugin_int **plugin_ref; 145 #define plugin_ref_to_int(A) (A ? A[0] : NULL) 146 #define plugin_int_to_ref(A) &(A) 147 #define plugin_decl(pi) ((pi)[0]->plugin) 148 #define plugin_dlib(pi) ((pi)[0]->plugin_dl) 149 #define plugin_data(pi,cast) ((cast)((pi)[0]->data)) 150 #define plugin_name(pi) (&((pi)[0]->name)) 151 #define plugin_state(pi) ((pi)[0]->state) 152 #define plugin_load_option(pi) ((pi)[0]->load_option) 153 #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0]) 154 #endif 155 156 typedef int (*plugin_type_init)(struct st_plugin_int *); 157 158 extern I_List<i_string> *opt_plugin_load_list_ptr; 159 extern char *opt_plugin_dir_ptr; 160 extern MYSQL_PLUGIN_IMPORT char opt_plugin_dir[FN_REFLEN]; 161 extern const LEX_CSTRING plugin_type_names[]; 162 extern ulong plugin_maturity; 163 extern TYPELIB plugin_maturity_values; 164 extern const char *plugin_maturity_names[]; 165 166 extern int plugin_init(int *argc, char **argv, int init_flags); 167 extern void plugin_shutdown(void); 168 void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root); 169 extern bool plugin_is_ready(const LEX_CSTRING *name, int type); 170 #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C) 171 #define my_plugin_lock(A,B) plugin_lock(A,B) 172 extern plugin_ref plugin_lock(THD *thd, plugin_ref ptr); 173 extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_CSTRING *name, 174 int type); 175 extern void plugin_unlock(THD *thd, plugin_ref plugin); 176 extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count); 177 extern bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name, 178 const LEX_CSTRING *dl); 179 extern bool mysql_uninstall_plugin(THD *thd, const LEX_CSTRING *name, 180 const LEX_CSTRING *dl); 181 extern bool plugin_register_builtin(struct st_mysql_plugin *plugin); 182 extern void plugin_thdvar_init(THD *thd); 183 extern void plugin_thdvar_cleanup(THD *thd); 184 sys_var *find_plugin_sysvar(st_plugin_int *plugin, st_mysql_sys_var *var); 185 void plugin_opt_set_limits(struct my_option *, const struct st_mysql_sys_var *); 186 extern SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type); 187 extern bool check_valid_path(const char *path, size_t length); 188 extern void plugin_mutex_init(); 189 190 typedef my_bool (plugin_foreach_func)(THD *thd, 191 plugin_ref plugin, 192 void *arg); 193 #define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D) 194 extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, 195 int type, uint state_mask, void *arg); 196 extern void sync_dynamic_session_variables(THD* thd, bool global_lock); 197 198 extern bool plugin_dl_foreach(THD *thd, const LEX_CSTRING *dl, 199 plugin_foreach_func *func, void *arg); 200 201 extern void sync_dynamic_session_variables(THD* thd, bool global_lock); 202 #endif 203 204 #ifdef WITH_WSREP 205 extern void wsrep_plugins_pre_init(); 206 extern void wsrep_plugins_post_init(); 207 #endif /* WITH_WSREP */ 208 209