|
| 1 | +// Copyright 2023 The LMP Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | + |
| 16 | +// |
| 17 | +// net_watcher libbpf 内核<->用户 传递信息相关结构体 |
| 18 | + |
| 19 | +#ifndef __MYSQL_HELPER_BPF_H |
| 20 | +#define __MYSQL_HELPER_BPF_H |
| 21 | + |
| 22 | +#include "net_watcher.h" |
| 23 | +#include "vmlinux.h" |
| 24 | +#include <asm-generic/errno.h> |
| 25 | +#include <bpf/bpf_core_read.h> |
| 26 | +#include <bpf/bpf_endian.h> |
| 27 | +#include <bpf/bpf_helpers.h> |
| 28 | +#include <bpf/bpf_tracing.h> |
| 29 | +#include <string.h> |
| 30 | + |
| 31 | +enum enum_server_command { |
| 32 | + COM_SLEEP, |
| 33 | + COM_QUIT, |
| 34 | + COM_INIT_DB, |
| 35 | + COM_QUERY, |
| 36 | + COM_FIELD_LIST, |
| 37 | + COM_CREATE_DB, |
| 38 | + COM_DROP_DB, |
| 39 | + COM_REFRESH, |
| 40 | + COM_SHUTDOWN, |
| 41 | + COM_STATISTICS, |
| 42 | + COM_PROCESS_INFO, |
| 43 | + COM_CONNECT, |
| 44 | + COM_PROCESS_KILL, |
| 45 | + COM_DEBUG, |
| 46 | + COM_PING, |
| 47 | + COM_TIME, |
| 48 | + COM_DELAYED_INSERT, |
| 49 | + COM_CHANGE_USER, |
| 50 | + COM_BINLOG_DUMP, |
| 51 | + COM_TABLE_DUMP, |
| 52 | + COM_CONNECT_OUT, |
| 53 | + COM_REGISTER_SLAVE, |
| 54 | + COM_STMT_PREPARE, |
| 55 | + COM_STMT_EXECUTE, |
| 56 | + COM_STMT_SEND_LONG_DATA, |
| 57 | + COM_STMT_CLOSE, |
| 58 | + COM_STMT_RESET, |
| 59 | + COM_SET_OPTION, |
| 60 | + COM_STMT_FETCH, |
| 61 | + COM_DAEMON, |
| 62 | + COM_BINLOG_DUMP_GTID, |
| 63 | + COM_RESET_CONNECTION, |
| 64 | + /* don't forget to update const char *command_name[] in sql_parse.cc */ |
| 65 | + /* Must be last */ |
| 66 | + COM_END |
| 67 | +}; |
| 68 | + |
| 69 | +typedef struct st_com_init_db_data { |
| 70 | + const char *db_name; |
| 71 | + unsigned long length; |
| 72 | +} COM_INIT_DB_DATA; |
| 73 | + |
| 74 | +#define MYSQL_SHUTDOWN_KILLABLE_CONNECT (unsigned char)(1 << 0) |
| 75 | +#define MYSQL_SHUTDOWN_KILLABLE_TRANS (unsigned char)(1 << 1) |
| 76 | +#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2) |
| 77 | +#define MYSQL_SHUTDOWN_KILLABLE_UPDATE (unsigned char)(1 << 3) |
| 78 | + |
| 79 | +#define LOCK_MODE_MASK 0xFUL |
| 80 | +#define LOCK_TYPE_MASK 0xF0UL |
| 81 | + |
| 82 | +enum mysql_enum_shutdown_level { |
| 83 | + SHUTDOWN_DEFAULT = 0, |
| 84 | + SHUTDOWN_WAIT_CONNECTIONS = MYSQL_SHUTDOWN_KILLABLE_CONNECT, |
| 85 | + SHUTDOWN_WAIT_TRANSACTIONS = MYSQL_SHUTDOWN_KILLABLE_TRANS, |
| 86 | + SHUTDOWN_WAIT_UPDATES = MYSQL_SHUTDOWN_KILLABLE_UPDATE, |
| 87 | + SHUTDOWN_WAIT_ALL_BUFFERS = (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1), |
| 88 | + SHUTDOWN_WAIT_CRITICAL_BUFFERS = (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1, |
| 89 | + KILL_QUERY = 254, |
| 90 | + KILL_CONNECTION = 255 |
| 91 | +}; |
| 92 | + |
| 93 | +typedef struct st_com_refresh_data { |
| 94 | + unsigned char options; |
| 95 | +} COM_REFRESH_DATA; |
| 96 | + |
| 97 | +typedef struct st_com_shutdown_data { |
| 98 | + enum mysql_enum_shutdown_level level; |
| 99 | +} COM_SHUTDOWN_DATA; |
| 100 | + |
| 101 | +typedef struct st_com_kill_data { |
| 102 | + unsigned long id; |
| 103 | +} COM_KILL_DATA; |
| 104 | + |
| 105 | +typedef struct st_com_set_option_data { |
| 106 | + unsigned int opt_command; |
| 107 | +} COM_SET_OPTION_DATA; |
| 108 | + |
| 109 | +typedef struct st_com_stmt_execute_data { |
| 110 | + unsigned long stmt_id; |
| 111 | + unsigned long flags; |
| 112 | + unsigned char *params; |
| 113 | + unsigned long params_length; |
| 114 | +} COM_STMT_EXECUTE_DATA; |
| 115 | + |
| 116 | +typedef struct st_com_stmt_fetch_data { |
| 117 | + unsigned long stmt_id; |
| 118 | + unsigned long num_rows; |
| 119 | +} COM_STMT_FETCH_DATA; |
| 120 | + |
| 121 | +typedef struct st_com_stmt_send_long_data_data { |
| 122 | + unsigned long stmt_id; |
| 123 | + unsigned int param_number; |
| 124 | + unsigned char *longdata; |
| 125 | + unsigned long length; |
| 126 | +} COM_STMT_SEND_LONG_DATA_DATA; |
| 127 | + |
| 128 | +typedef struct st_com_stmt_prepare_data { |
| 129 | + const char *query; |
| 130 | + unsigned int length; |
| 131 | +} COM_STMT_PREPARE_DATA; |
| 132 | + |
| 133 | +typedef struct st_stmt_close_data { |
| 134 | + unsigned int stmt_id; |
| 135 | +} COM_STMT_CLOSE_DATA; |
| 136 | + |
| 137 | +typedef struct st_com_stmt_reset_data { |
| 138 | + unsigned int stmt_id; |
| 139 | +} COM_STMT_RESET_DATA; |
| 140 | + |
| 141 | +typedef struct st_com_query_data { |
| 142 | + const char *query; |
| 143 | + unsigned int length; |
| 144 | +} COM_QUERY_DATA; |
| 145 | + |
| 146 | +typedef struct st_com_field_list_data { |
| 147 | + unsigned char *table_name; |
| 148 | + unsigned int table_name_length; |
| 149 | + const unsigned char *query; |
| 150 | + unsigned int query_length; |
| 151 | +} COM_FIELD_LIST_DATA; |
| 152 | + |
| 153 | +union COM_DATA { |
| 154 | + COM_INIT_DB_DATA com_init_db; |
| 155 | + COM_REFRESH_DATA com_refresh; |
| 156 | + COM_SHUTDOWN_DATA com_shutdown; |
| 157 | + COM_KILL_DATA com_kill; |
| 158 | + COM_SET_OPTION_DATA com_set_option; |
| 159 | + COM_STMT_EXECUTE_DATA com_stmt_execute; |
| 160 | + COM_STMT_FETCH_DATA com_stmt_fetch; |
| 161 | + COM_STMT_SEND_LONG_DATA_DATA com_stmt_send_long_data; |
| 162 | + COM_STMT_PREPARE_DATA com_stmt_prepare; |
| 163 | + COM_STMT_CLOSE_DATA com_stmt_close; |
| 164 | + COM_STMT_RESET_DATA com_stmt_reset; |
| 165 | + COM_QUERY_DATA com_query; |
| 166 | + COM_FIELD_LIST_DATA com_field_list; |
| 167 | +}; |
| 168 | + |
| 169 | +/* help functions end */ |
| 170 | + |
| 171 | +#endif |
0 commit comments