Debian Codegraph @

storage/innobase/fil/fil0crypt.cc

raw symbols SCIP
1 /*****************************************************************************
2 Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
3 Copyright (c) 2014, 2022, MariaDB Corporation.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
16
17 *****************************************************************************/
18 /**************************************************//**
19 @file fil0crypt.cc
20 Innodb file space encrypt/decrypt
21
22 Created Jonas Oreland Google
23 Modified Jan Lindström [email protected]
24 *******************************************************/
25
26 #include "fil0crypt.h"cxx . . $ `<file>/storage/innobase/include/fil0crypt.h`/
27 #include "mach0data.h"cxx . . $ `<file>/storage/innobase/include/mach0data.h`/
28 #include "page0zip.h"cxx . . $ `<file>/storage/innobase/include/page0zip.h`/
29 #include "buf0checksum.h"cxx . . $ `<file>/storage/innobase/include/buf0checksum.h`/
30 #ifdef UNIV_INNOCHECKSUMcxx . . $ `<built-in>:481:9`!
31 # include "buf0buf.h"cxx . . $ `<file>/storage/innobase/include/buf0buf.h`/
32 #else
33 #include "buf0flu.h"cxx . . $ `<file>/storage/innobase/include/buf0flu.h`/
34 #include "buf0dblwr.h"cxx . . $ `<file>/storage/innobase/include/buf0dblwr.h`/
35 #include "btr0sea.h"cxx . . $ `<file>/storage/innobase/include/btr0sea.h`/
36 #include "srv0srv.h"cxx . . $ `<file>/storage/innobase/include/srv0srv.h`/
37 #include "srv0start.h"cxx . . $ `<file>/storage/innobase/include/srv0start.h`/
38 #include "mtr0mtr.h"cxx . . $ `<file>/storage/innobase/include/mtr0mtr.h`/
39 #include "mtr0log.h"cxx . . $ `<file>/storage/innobase/include/mtr0log.h`/
40 #include "ut0ut.h"cxx . . $ `<file>/storage/innobase/include/ut0ut.h`/
41 #include "fsp0fsp.h"cxx . . $ `<file>/storage/innobase/include/fsp0fsp.h`/
42 #include "fil0pagecompress.h"cxx . . $ `<file>/storage/innobase/include/fil0pagecompress.h`/
43 #include <my_crypt.h>cxx . . $ `<file>/include/my_crypt.h`/
44
45 static bool fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited. = false;
46
47 /** Is encryption enabled/disabled */
48 ulong srv_encrypt_tablescxx . . $ srv_encrypt_tables.;
49
50 /** No of key rotation threads requested */
51 uint srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.;
52
53 /** No of key rotation threads started */
54 uint srv_n_fil_crypt_threads_startedcxx . . $ srv_n_fil_crypt_threads_started.;
55
56 /** At this age or older a space/page will be rotated */
57 uint srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.;
58
59 /** Whether the encryption plugin does key rotation */
60 Atomic_relaxedcxx . . $ Atomic_relaxed#<bool> srv_encrypt_rotatecxx . . $ Atomic_relaxed#Atomic_relaxed(49f6e7a06ebc5aa8).;
61
62 /** Condition variable for srv_n_fil_crypt_threads_started */
63 static pthread_cond_tcxx . . $ pthread_cond_t# fil_crypt_condcxx . . $ fil_crypt_cond.;
64
65 /** Condition variable to to signal the key rotation threads */
66 static pthread_cond_tcxx . . $ pthread_cond_t# fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.;
67
68 /** Condition variable for interrupting sleeptime_ms sleep at the end
69 of fil_crypt_rotate_page() */
70 static pthread_cond_tcxx . . $ pthread_cond_t# fil_crypt_throttle_sleep_condcxx . . $ fil_crypt_throttle_sleep_cond.;
71
72 /** Mutex for key rotation threads. Acquired before fil_system.mutex! */
73 static mysql_mutex_t fil_crypt_threads_mutexcxx . . $ fil_crypt_threads_mutex.;
74
75 /** Variable ensuring only 1 thread at time does initial conversion */
76 static bool fil_crypt_start_convertingcxx . . $ fil_crypt_start_converting.;
77
78 /** Variables for throttling */
79 uint srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops.; // 10ms per iop
80 static constexpr uint srv_alloc_timecxx . . $ srv_alloc_time. = 3; // allocate iops for 3s at a time
81 static uint n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated.;
82
83 #define DEBUG_KEYROTATION_THROTTLINGcxx . . $ `storage/innobase/fil/fil0crypt.cc:83:9`! 0
84
85 /** Statistics variables */
86 static fil_crypt_stat_tcxx . . $ fil_crypt_stat_t# crypt_statcxx . . $ crypt_stat.;
87 static mysql_mutex_t crypt_stat_mutexcxx . . $ crypt_stat_mutex.;
88
89 /** Wake up the encryption threads */
90 void fil_crypt_threads_signalcxx . . $ fil_crypt_threads_signal(b45ddcbc8423892c).(bool broadcast)
91 {
92 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
93 if (broadcast)
94 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
95 else
96 pthread_cond_signal(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
97 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
98 }
99
100 /***********************************************************************
101 Check if a key needs rotation given a key_state
102 @param[in] crypt_data Encryption information
103 @param[in] key_version Current key version
104 @param[in] latest_key_version Latest key version
105 @param[in] rotate_key_age when to rotate
106 @return true if key needs rotation, false if not */
107 static bool
108 fil_crypt_needs_rotationcxx . . $ fil_crypt_needs_rotation(8d74958e750faaf9).(
109 const fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
110 uint key_version,
111 uint latest_key_version,
112 uint rotate_key_age)
113 MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result));
114
115 /*********************************************************************
116 Init space crypt */
117 void fil_space_crypt_initcxx . . $ fil_space_crypt_init(49f6e7a06ebc5aa8).()
118 {
119 pthread_cond_init(&fil_crypt_throttle_sleep_condcxx . . $ fil_crypt_throttle_sleep_cond., nullptr);
120 mysql_mutex_initcxx . . $ crypt_stat_mutex.(0, &crypt_stat_mutex, nullptr);
121 }
122
123 /*********************************************************************
124 Cleanup space crypt */
125 void fil_space_crypt_cleanupcxx . . $ fil_space_crypt_cleanup(49f6e7a06ebc5aa8).()
126 {
127 pthread_cond_destroy(&fil_crypt_throttle_sleep_condcxx . . $ fil_crypt_throttle_sleep_cond.);
128 mysql_mutex_destroycxx . . $ `include/mysql/psi/mysql_thread.h:348:11`!(&crypt_stat_mutex);
129 }
130
131 /**
132 Get latest key version from encryption plugin.
133 @return key version or ENCRYPTION_KEY_VERSION_INVALID */
134 uint
135 fil_space_crypt_tcxx . . $ fil_space_crypt_t#::key_get_latest_versioncxx . . $ fil_space_crypt_t#key_get_latest_version(db52760e79bf9054).(void)
136 {
137 uint key_version = key_foundcxx . . $ fil_space_crypt_t#key_found.;
138
139 if (is_key_foundcxx . . $ fil_space_crypt_t#is_key_found(50ce9a9e25b4a850).()) {
140 key_version = encryption_key_get_latest_versioncxx . . $ `include/mysql/service_encryption.h:87:9`!(key_id);
141 /* InnoDB does dirty read of srv_fil_crypt_rotate_key_age.
142 It doesn't matter because srv_encrypt_rotate
143 can be set to true only once */
144 if (!srv_encrypt_rotatecxx . . $ srv_encrypt_rotate.
145 && key_version > srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.) {
146 srv_encrypt_rotatecxx . . $ srv_encrypt_rotate. =cxx . . $ Atomic_relaxed#`operator=`(ada6a8422704cf8a). true;
147 }
148
149 srv_statscxx . . $ srv_stats..n_key_requestscxx . . $ srv_stats_t#n_key_requests..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).();
150 key_foundcxx . . $ fil_space_crypt_t#key_found. = key_version;
151 }
152
153 return key_version;
154 }
155
156 /******************************************************************
157 Get the latest(key-version), waking the encrypt thread, if needed
158 @param[in,out] crypt_data Crypt data */
159 static inline
160 uint
161 fil_crypt_get_latest_key_versioncxx . . $ fil_crypt_get_latest_key_version(346702181f99c4a3).(
162 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data)
163 {
164 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(crypt_data != NULL);
165
166 uint key_version = crypt_data->key_get_latest_versioncxx . . $ fil_space_crypt_t#key_get_latest_version(db52760e79bf9054).();
167
168 if (crypt_data->is_key_foundcxx . . $ fil_space_crypt_t#is_key_found(50ce9a9e25b4a850).()) {
169
170 if (fil_crypt_needs_rotationcxx . . $ fil_crypt_needs_rotation(8d74958e750faaf9).(
171 crypt_data,
172 crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.,
173 key_version,
174 srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.)) {
175 if (fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.) {
176 fil_crypt_threads_signalcxx . . $ fil_crypt_threads_signal(b45ddcbc8423892c).();
177 }
178 }
179 }
180
181 return key_version;
182 }
183
184 /******************************************************************
185 Mutex helper for crypt_data->scheme */
186 void
187 crypt_data_scheme_lockercxx . . $ crypt_data_scheme_locker(1040889517b87df6).(
188 /*=====================*/
189 st_encryption_scheme* scheme,
190 int exit)
191 {
192 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data =
193 static_cast<fil_space_crypt_tcxx . . $ fil_space_crypt_t#*>(scheme);
194
195 if (exit) {
196 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
197 } else {
198 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
199 }
200 }
201
202 /******************************************************************
203 Create a fil_space_crypt_t object
204 @param[in] type CRYPT_SCHEME_UNENCRYPTE or
205 CRYPT_SCHEME_1
206 @param[in] encrypt_mode FIL_ENCRYPTION_DEFAULT or
207 FIL_ENCRYPTION_ON or
208 FIL_ENCRYPTION_OFF
209 @param[in] min_key_version key_version or 0
210 @param[in] key_id Used key id
211 @return crypt object */
212 static
213 fil_space_crypt_tcxx . . $ fil_space_crypt_t#*
214 fil_space_create_crypt_datacxx . . $ fil_space_create_crypt_data(53bf17fecf5c58c5).(
215 uint type,
216 fil_encryption_tcxx . . $ fil_encryption_t# encrypt_mode,
217 uint min_key_version,
218 uint key_id)
219 {
220 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
221 if (void* buf = ut_zalloc_nokeycxx . . $ byte#(sizeof(fil_space_crypt_t))) {
222 crypt_data = new(buf)
223 fil_space_crypt_tcxx . . $ fil_space_crypt_t#fil_space_crypt_t(36e28a2f5374ae1b).(
224 type,
225 min_key_version,
226 key_id,
227 encrypt_mode);
228 }
229
230 return crypt_data;
231 }
232
233 /******************************************************************
234 Create a fil_space_crypt_t object
235 @param[in] encrypt_mode FIL_ENCRYPTION_DEFAULT or
236 FIL_ENCRYPTION_ON or
237 FIL_ENCRYPTION_OFF
238
239 @param[in] key_id Encryption key id
240 @return crypt object */
241 fil_space_crypt_tcxx . . $ fil_space_crypt_t#*
242 fil_space_create_crypt_datacxx . . $ fil_space_create_crypt_data(21ed37a4e50748ce).(
243 fil_encryption_tcxx . . $ fil_encryption_t# encrypt_mode,
244 uint key_id)
245 {
246 return (fil_space_create_crypt_datacxx . . $ fil_space_create_crypt_data(53bf17fecf5c58c5).(0, encrypt_mode, 0, key_id));
247 }
248
249 /******************************************************************
250 Merge fil_space_crypt_t object
251 @param[in,out] dst Destination cryp data
252 @param[in] src Source crypt data */
253 static
254 void
255 fil_space_merge_crypt_datacxx . . $ fil_space_merge_crypt_data(95ef56306fbeccf3).(
256 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* dst,
257 const fil_space_crypt_tcxx . . $ fil_space_crypt_t#* src)
258 {
259 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&dst->mutex);
260
261 /* validate that they are mergeable */
262 ut_acxx . . $ ulint#(src->type == CRYPT_SCHEME_UNENCRYPTEDcxx . . $ `storage/innobase/include/fil0crypt.h:62:9`! ||
263 src->type == CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!);
264
265 ut_acxx . . $ ulint#(dst->type == CRYPT_SCHEME_UNENCRYPTEDcxx . . $ `storage/innobase/include/fil0crypt.h:62:9`! ||
266 dst->type == CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!);
267
268 dst->encryptioncxx . . $ fil_space_crypt_t#encryption. = src->encryptioncxx . . $ fil_space_crypt_t#encryption.;
269 dst->type = src->type;
270 dst->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. = src->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.;
271 dst->keyserver_requests += src->keyserver_requests;
272
273 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&dst->mutex);
274 }
275
276 /** Initialize encryption parameters from a tablespace header page.
277 @param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
278 @param[in] page first page of the tablespace
279 @return crypt data from page 0
280 @retval NULL if not present or not valid */
281 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* fil_space_read_crypt_datacxx . . $ fil_space_read_crypt_data(1109c76aac6a686).(ulintcxx . . $ ulint# zip_size, const bytecxx . . $ byte#* page)
282 {
283 const ulintcxx . . $ ulint# offset = FSP_HEADER_OFFSETcxx . . $ `storage/innobase/include/fsp0fsp.h:102:9`!
284 + fsp_header_get_encryption_offsetcxx . . $ fsp_header_get_encryption_offset(ecdaa1632f49f591).(zip_size);
285
286 if (memcmp(page + offset, CRYPT_MAGICcxx . . $ CRYPT_MAGIC., MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`!) != 0) {
287 /* Crypt data is not stored. */
288 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
289 }
290
291 uint8_tcxx . . $ uint8_t# type = mach_read_from_1cxx . . $ mach_read_from_1(f3688bc2ee54ea05).(page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 0);
292 uint8_tcxx . . $ uint8_t# iv_length = mach_read_from_1cxx . . $ mach_read_from_1(f3688bc2ee54ea05).(page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 1);
293 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data;
294
295 if (!(type == CRYPT_SCHEME_UNENCRYPTEDcxx . . $ `storage/innobase/include/fil0crypt.h:62:9`! ||
296 type == CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!)
297 || iv_length != sizeof crypt_data->iv) {
298 ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Found non sensible crypt scheme: "
299 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). type <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "," <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). iv_length
300 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " for space: "
301 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). page_get_space_idcxx . . $ page_get_space_id(ca1608e2c87725e2).(page);
302 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
303 }
304
305 uint min_key_version = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).
306 (page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 2 + iv_length);
307
308 uint key_id = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).
309 (page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 2 + iv_length + 4);
310
311 fil_encryption_tcxx . . $ fil_encryption_t# encryption = (fil_encryption_tcxx . . $ fil_encryption_t#)mach_read_from_1cxx . . $ mach_read_from_1(f3688bc2ee54ea05).(
312 page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 2 + iv_length + 8);
313
314 crypt_data = fil_space_create_crypt_datacxx . . $ fil_space_create_crypt_data(21ed37a4e50748ce).(encryption, key_id);
315 /* We need to overwrite these as above function will initialize
316 members */
317 crypt_data->type = type;
318 crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. = min_key_version;
319 memcpy(crypt_data->iv, page + offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`! + 2, iv_length);
320
321 return crypt_data;
322 }
323
324 /******************************************************************
325 Free a crypt data object
326 @param[in,out] crypt_data crypt data to be freed */
327 void fil_space_destroy_crypt_datacxx . . $ fil_space_destroy_crypt_data(c548bc37e2e8ad2e).(fil_space_crypt_tcxx . . $ fil_space_crypt_t# **crypt_data)
328 {
329 if (crypt_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! && (*crypt_data) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
330 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* c;
331 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(fil_crypt_threads_inited)) {
332 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
333 c = *crypt_data;
334 *crypt_data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
335 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
336 } else {
337 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(srv_read_only_mode || !srv_was_started);
338 c = *crypt_data;
339 *crypt_data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
340 }
341 if (c) {
342 c->~fil_space_crypt_tcxx . . $ fil_space_crypt_t#();
343 ut_freecxx . . $ `storage/innobase/include/ut0new.h:1044:9`!(c);
344 }
345 }
346 }
347
348 /** Amend encryption information from redo log.
349 @param[in] space tablespace
350 @param[in] data encryption metadata */
351 void fil_crypt_parsecxx . . $ fil_crypt_parse(fb64f0e1226595f5).(fil_space_tcxx . . $ fil_space_t#* space, const bytecxx . . $ byte#* data)
352 {
353 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(data[1] == MY_AES_BLOCK_SIZE);
354 if (void* buf = ut_zalloc_nokeycxx . . $ ut_allocator#ut_allocator(cb2f890c2fdad230).(sizeof(fil_space_crypt_t))) {
355 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data = new(buf)
356 fil_space_crypt_tcxx . . $ fil_space_crypt_t#fil_space_crypt_t(36e28a2f5374ae1b).(
357 data[0],
358 mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(&data[2 + MY_AES_BLOCK_SIZEcxx . . $ `include/mysql/service_my_crypt.h:43:9`!]),
359 mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(&data[6 + MY_AES_BLOCK_SIZEcxx . . $ `include/mysql/service_my_crypt.h:43:9`!]),
360 static_cast<fil_encryption_tcxx . . $ fil_encryption_t#>
361 (data[10 + MY_AES_BLOCK_SIZEcxx . . $ `include/mysql/service_my_crypt.h:43:9`!]));
362 memcpy(crypt_data->iv, data + 2, MY_AES_BLOCK_SIZEcxx . . $ `include/mysql/service_my_crypt.h:43:9`!);
363 mysql_mutex_lockcxx . . $ fil_system_t#mutex.(&fil_system.mutex);
364 if (space->crypt_datacxx . . $ fil_space_t#crypt_data.) {
365 fil_space_merge_crypt_datacxx . . $ fil_space_merge_crypt_data(95ef56306fbeccf3).(space->crypt_datacxx . . $ fil_space_t#crypt_data.,
366 crypt_data);
367 fil_space_destroy_crypt_datacxx . . $ fil_space_destroy_crypt_data(c548bc37e2e8ad2e).(&crypt_data);
368 crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
369 } else {
370 space->crypt_datacxx . . $ fil_space_t#crypt_data. = crypt_data;
371 }
372 mysql_mutex_unlockcxx . . $ fil_system_t#mutex.(&fil_system.mutex);
373 }
374 }
375
376 /** Write encryption metadata to the first page.
377 @param[in,out] block first page of the tablespace
378 @param[in,out] mtr mini-transaction */
379 void fil_space_crypt_tcxx . . $ fil_space_crypt_t#::write_page0cxx . . $ fil_space_crypt_t#write_page0(c4796673375b2726).(buf_block_tcxx . . $ buf_block_t#* block, mtr_tcxx . . $ mtr_t#* mtr)
380 {
381 const ulintcxx . . $ ulint# offset = FSP_HEADER_OFFSETcxx . . $ `storage/innobase/include/fsp0fsp.h:102:9`!
382 + fsp_header_get_encryption_offsetcxx . . $ fsp_header_get_encryption_offset(ecdaa1632f49f591).(block->zip_sizecxx . . $ buf_block_t#zip_size(c9b1e749b64d5edc).());
383 bytecxx . . $ byte#* b = block->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame. + offset;
384
385 mtr->memcpycxx . . $ mtr_t#memcpy(cacdda589782ca45).<mtr_tcxx . . $ mtr_t#::MAYBE_NOPcxx . . $ mtr_t#MAYBE_NOP.>(*block, b, CRYPT_MAGICcxx . . $ CRYPT_MAGIC., MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`!);
386
387 b += MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`!;
388 bytecxx . . $ byte#* const start = b;
389 *b++ = static_cast<bytecxx . . $ byte#>(type);
390 compile_time_assertcxx . . $ `include/my_global.h:377:9`!(sizeof iv == MY_AES_BLOCK_SIZEcxx . . $ `include/mysql/service_my_crypt.h:43:9`!);
391 compile_time_assertcxx . . $ `include/my_global.h:377:9`!(sizeof iv == CRYPT_SCHEME_1_IV_LENcxx . . $ `storage/innobase/include/fil0crypt.h:61:9`!);
392 *b++ = sizeof iv;
393 memcpy(b, iv, sizeof iv);
394 b += sizeof iv;
395 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(b, min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.);
396 b += 4;
397 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(b, key_id);
398 b += 4;
399 *b++ = bytecxx . . $ byte#(encryptioncxx . . $ fil_space_crypt_t#encryption.);
400 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(b - start == 11 + MY_AES_BLOCK_SIZE);
401 /* We must log also any unchanged bytes, because recovery will
402 invoke fil_crypt_parse() based on this log record. */
403 mtr->memcpycxx . . $ mtr_t#memcpy(9fdef666e3f18c6c).(*block, offset + MAGIC_SZcxx . . $ `storage/innobase/include/fil0crypt.h:35:9`!, b - start);
404 }
405
406 /** Encrypt a buffer for non full checksum.
407 @param[in,out] crypt_data Crypt data
408 @param[in] space space_id
409 @param[in] offset Page offset
410 @param[in] lsn Log sequence number
411 @param[in] src_frame Page to encrypt
412 @param[in] zip_size ROW_FORMAT=COMPRESSED
413 page size, or 0
414 @param[in,out] dst_frame Output buffer
415 @return encrypted buffer or NULL */
416 static bytecxx . . $ byte#* fil_encrypt_buf_for_non_full_checksumcxx . . $ fil_encrypt_buf_for_non_full_checksum(54be1c3e1ae68cb6).(
417 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
418 ulintcxx . . $ ulint# space,
419 ulintcxx . . $ ulint# offset,
420 lsn_tcxx . . $ lsn_t# lsn,
421 const bytecxx . . $ byte#* src_frame,
422 ulintcxx . . $ ulint# zip_size,
423 bytecxx . . $ byte#* dst_frame)
424 {
425 uint size = uint(zip_size ? zip_size : srv_page_sizecxx . . $ srv_page_size.);
426 uint key_version = fil_crypt_get_latest_key_versioncxx . . $ fil_crypt_get_latest_key_version(346702181f99c4a3).(crypt_data);
427 ut_acxx . . $ ulint#(key_version != ENCRYPTION_KEY_VERSION_INVALIDcxx . . $ `include/mysql/service_encryption.h:44:9`!);
428 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!ut_align_offset(src_frame, 8));
429 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!ut_align_offset(dst_frame, 8));
430
431 const bool page_compressed = fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(src_frame)
432 == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTEDcxx . . $ FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED.;
433 uint header_len = FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`!;
434
435 if (page_compressed) {
436 header_len += FIL_PAGE_ENCRYPT_COMP_METADATA_LENcxx . . $ `storage/innobase/include/fil0fil.h:1269:9`!;
437 }
438
439 /* FIL page header is not encrypted */
440 memcpy(dst_frame, src_frame, header_len);
441 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!,
442 key_version);
443
444 /* Calculate the start offset in a page */
445 uint unencrypted_bytes = header_len + FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!;
446 uint srclen = size - unencrypted_bytes;
447 const bytecxx . . $ byte#* src = src_frame + header_len;
448 bytecxx . . $ byte#* dst = dst_frame + header_len;
449
450 if (page_compressed) {
451 srclen = mach_read_from_2cxx . . $ mach_read_from_2(469dcb4e54b221a8).(src_frame + FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`!);
452 }
453 uint dstlen = srclen;
454
455 int rc = encryption_scheme_encrypt(src, srclen, dst, &dstlen,
456 crypt_data, key_version,
457 (uint32cxx . . $ uint32#)space, (uint32cxx . . $ uint32#)offset, lsn);
458 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(rc == MY_AES_OKcxx . . $ `include/mysql/service_my_crypt.h:37:9`!);
459 ut_acxx . . $ ulint#(dstlen == srclen);
460
461 /* For compressed tables we do not store the FIL header because
462 the whole page is not stored to the disk. In compressed tables only
463 the FIL header + compressed (and now encrypted) payload alligned
464 to sector boundary is written. */
465 if (!page_compressed) {
466 /* FIL page trailer is also not encrypted */
467 static_assert(FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`! == 8, "alignment");
468 memcpy_alignedcxx . . $ memcpy_aligned(cc817cb175f282d).<8>(dst_frame + size - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!,
469 src_frame + size - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!, 8);
470 } else {
471 /* Clean up rest of buffer */
472 memset(dst_frame+header_len+srclen, 0,
473 size - (header_len + srclen));
474 }
475
476 /* store the post-encryption checksum after the key-version */
477 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`! + 4,
478 zip_size
479 ? page_zip_calc_checksumcxx . . $ page_zip_calc_checksum(9a0403da8c830ea4).(dst_frame, zip_size,
480 SRV_CHECKSUM_ALGORITHM_CRC32cxx . . $ SRV_CHECKSUM_ALGORITHM_CRC32.)
481 : buf_calc_page_crc32cxx . . $ buf_calc_page_crc32(92865eb9586733e9).(dst_frame));
482
483 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(fil_space_verify_crypt_checksum(dst_frame, zip_size));
484
485 srv_statscxx . . $ srv_stats..pages_encryptedcxx . . $ srv_stats_t#pages_encrypted..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).();
486
487 return dst_frame;
488 }
489
490 /** Encrypt a buffer for full checksum format.
491 @param[in,out] crypt_data Crypt data
492 @param[in] space space_id
493 @param[in] offset Page offset
494 @param[in] lsn Log sequence number
495 @param[in] src_frame Page to encrypt
496 @param[in,out] dst_frame Output buffer
497 @return encrypted buffer or NULL */
498 static bytecxx . . $ byte#* fil_encrypt_buf_for_full_crc32cxx . . $ fil_encrypt_buf_for_full_crc32(29009676bdf40f4c).(
499 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
500 ulintcxx . . $ ulint# space,
501 ulintcxx . . $ ulint# offset,
502 lsn_tcxx . . $ lsn_t# lsn,
503 const bytecxx . . $ byte#* src_frame,
504 bytecxx . . $ byte#* dst_frame)
505 {
506 uint key_version = fil_crypt_get_latest_key_versioncxx . . $ fil_crypt_get_latest_key_version(346702181f99c4a3).(crypt_data);
507 ut_dcxx . . $ `storage/innobase/include/ut0dbg.h:68:9`!(bool corrupted = false);
508 const uint size = buf_page_full_crc32_sizecxx . . $ buf_page_full_crc32_size(17aa04929161d1fd).(src_frame, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
509 #ifdef UNIV_DEBUG
510 &corrupted
511 #else
512 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!
513 #endif
514 );
515 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!corrupted);
516 uint srclen = size - (FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!
517 + FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!);
518 const bytecxx . . $ byte#* src = src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!;
519 bytecxx . . $ byte#* dst = dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!;
520 uint dstlen = srclen;
521
522 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(key_version != ENCRYPTION_KEY_VERSION_INVALIDcxx . . $ `include/mysql/service_encryption.h:44:9`!);
523
524 /* Till FIL_PAGE_LSN, page is not encrypted */
525 memcpy(dst_frame, src_frame, FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!);
526
527 /* Write key version to the page. */
528 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(dst_frame + FIL_PAGE_FCRC32_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1253:9`!, key_version);
529
530 int rc = encryption_scheme_encrypt(src, srclen, dst, &dstlen,
531 crypt_data, key_version,
532 uint(space), uint(offset), lsn);
533 ut_acxx . . $ ulint#(rc == MY_AES_OKcxx . . $ `include/mysql/service_my_crypt.h:37:9`!);
534 ut_acxx . . $ ulint#(dstlen == srclen);
535
536 const ulintcxx . . $ ulint# payload = size - FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!;
537 mach_write_to_4cxx . . $ mach_write_to_4(6165b45f45ef689c).(dst_frame + payload, my_crc32c(0, dst_frame, payload));
538 /* Clean the rest of the buffer. FIXME: Punch holes when writing! */
539 memset(dst_frame + (payload + 4), 0, srv_page_sizecxx . . $ srv_page_size. - (payload + 4));
540
541 srv_statscxx . . $ srv_stats..pages_encryptedcxx . . $ srv_stats_t#pages_encrypted..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).();
542
543 return dst_frame;
544 }
545
546 /** Encrypt a buffer.
547 @param[in,out] crypt_data Crypt data
548 @param[in] space space_id
549 @param[in] offset Page offset
550 @param[in] src_frame Page to encrypt
551 @param[in] zip_size ROW_FORMAT=COMPRESSED
552 page size, or 0
553 @param[in,out] dst_frame Output buffer
554 @param[in] use_full_checksum full crc32 algo is used
555 @return encrypted buffer or NULL */
556 bytecxx . . $ byte#* fil_encrypt_bufcxx . . $ fil_encrypt_buf(f003be6960c9aee0).(
557 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
558 ulintcxx . . $ ulint# space,
559 ulintcxx . . $ ulint# offset,
560 const bytecxx . . $ byte#* src_frame,
561 ulintcxx . . $ ulint# zip_size,
562 bytecxx . . $ byte#* dst_frame,
563 bool use_full_checksum)
564 {
565 const lsn_tcxx . . $ lsn_t# lsn = mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(src_frame + FIL_PAGE_LSNcxx . . $ `storage/innobase/include/fil0fil.h:1213:9`!);
566
567 if (use_full_checksum) {
568 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!zip_size);
569 return fil_encrypt_buf_for_full_crc32cxx . . $ fil_encrypt_buf_for_full_crc32(29009676bdf40f4c).(
570 crypt_data, space, offset,
571 lsn, src_frame, dst_frame);
572 }
573
574 return fil_encrypt_buf_for_non_full_checksumcxx . . $ fil_encrypt_buf_for_non_full_checksum(54be1c3e1ae68cb6).(
575 crypt_data, space, offset, lsn,
576 src_frame, zip_size, dst_frame);
577 }
578
579 /** Check whether these page types are allowed to encrypt.
580 @param[in] space tablespace object
581 @param[in] src_frame source page
582 @return true if it is valid page type */
583 static bool fil_space_encrypt_valid_page_typecxx . . $ fil_space_encrypt_valid_page_type(93d04109de622682).(
584 const fil_space_tcxx . . $ fil_space_t#* space,
585 const bytecxx . . $ byte#* src_frame)
586 {
587 switch (fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(src_frame)) {
588 case FIL_PAGE_RTREEcxx . . $ FIL_PAGE_RTREE.:
589 return space->full_crc32cxx . . $ fil_space_t#full_crc32(3482b152b9333168).();
590 case FIL_PAGE_TYPE_FSP_HDRcxx . . $ FIL_PAGE_TYPE_FSP_HDR.:
591 case FIL_PAGE_TYPE_XDEScxx . . $ FIL_PAGE_TYPE_XDES.:
592 return false;
593 }
594
595 return true;
596 }
597
598 /******************************************************************
599 Encrypt a page
600
601 @param[in] space Tablespace
602 @param[in] offset Page offset
603 @param[in] src_frame Page to encrypt
604 @param[in,out] dst_frame Output buffer
605 @return encrypted buffer or NULL */
606 bytecxx . . $ byte#* fil_space_encryptcxx . . $ fil_space_encrypt(25e56ab47a9e07b6).(
607 const fil_space_tcxx . . $ fil_space_t#* space,
608 ulintcxx . . $ ulint# offset,
609 bytecxx . . $ byte#* src_frame,
610 bytecxx . . $ byte#* dst_frame)
611 {
612 if (!fil_space_encrypt_valid_page_typecxx . . $ fil_space_encrypt_valid_page_type(93d04109de622682).(space, src_frame)) {
613 return src_frame;
614 }
615
616 if (!space->crypt_datacxx . . $ fil_space_t#crypt_data. || !space->crypt_datacxx . . $ fil_space_t#crypt_data.->is_encryptedcxx . . $ fil_space_crypt_t#is_encrypted(50ce9a9e25b4a850).()) {
617 return (src_frame);
618 }
619
620 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
621
622 return fil_encrypt_bufcxx . . $ fil_encrypt_buf(f003be6960c9aee0).(space->crypt_datacxx . . $ fil_space_t#crypt_data., space->idcxx . . $ fil_space_t#id., offset,
623 src_frame, space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(),
624 dst_frame, space->full_crc32cxx . . $ fil_space_t#full_crc32(3482b152b9333168).());
625 }
626
627 /** Decrypt a page for full checksum format.
628 @param[in] space space id
629 @param[in] crypt_data crypt_data
630 @param[in] tmp_frame Temporary buffer
631 @param[in,out] src_frame Page to decrypt
632 @return DB_SUCCESS or error */
633 static dberr_tcxx . . $ dberr_t# fil_space_decrypt_full_crc32cxx . . $ fil_space_decrypt_full_crc32(93d953a1af07859b).(
634 ulintcxx . . $ ulint# space,
635 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
636 bytecxx . . $ byte#* tmp_frame,
637 bytecxx . . $ byte#* src_frame)
638 {
639 uint key_version = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
640 src_frame + FIL_PAGE_FCRC32_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1253:9`!);
641 lsn_tcxx . . $ lsn_t# lsn = mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(src_frame + FIL_PAGE_LSNcxx . . $ `storage/innobase/include/fil0fil.h:1213:9`!);
642 uint offset = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(src_frame + FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`!);
643
644 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
645
646 memcpy(tmp_frame, src_frame, FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!);
647
648 /* Calculate the offset where decryption starts */
649 const bytecxx . . $ byte#* src = src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!;
650 bytecxx . . $ byte#* dst = tmp_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!;
651 bool corrupted = false;
652 uint size = buf_page_full_crc32_sizecxx . . $ buf_page_full_crc32_size(17aa04929161d1fd).(src_frame, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &corrupted);
653 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(corrupted)) {
654 return DB_DECRYPTION_FAILEDcxx . . $ DB_DECRYPTION_FAILED.;
655 }
656
657 uint srclen = size - (FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!
658 + FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!);
659 uint dstlen = srclen;
660
661 int rc = encryption_scheme_decrypt(src, srclen, dst, &dstlen,
662 crypt_data, key_version,
663 (uint) space, offset, lsn);
664
665 if (rc != MY_AES_OKcxx . . $ `include/mysql/service_my_crypt.h:37:9`! || dstlen != srclen) {
666 return DB_DECRYPTION_FAILEDcxx . . $ DB_DECRYPTION_FAILED.;
667 }
668
669 /* Copy only checksum part in the trailer */
670 memcpy(tmp_frame + srv_page_sizecxx . . $ srv_page_size. - FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!,
671 src_frame + srv_page_sizecxx . . $ srv_page_size. - FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!,
672 FIL_PAGE_FCRC32_CHECKSUMcxx . . $ `storage/innobase/include/fil0fil.h:1283:9`!);
673
674 srv_statscxx . . $ srv_stats..pages_decryptedcxx . . $ srv_stats_t#pages_decrypted..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).();
675
676 return DB_SUCCESScxx . . $ DB_SUCCESS.; /* page was decrypted */
677 }
678
679 /** Decrypt a page for non full checksum format.
680 @param[in] crypt_data crypt_data
681 @param[in] tmp_frame Temporary buffer
682 @param[in] physical_size page size
683 @param[in,out] src_frame Page to decrypt
684 @return DB_SUCCESS or error */
685 static dberr_tcxx . . $ dberr_t# fil_space_decrypt_for_non_full_checksumcxx . . $ fil_space_decrypt_for_non_full_checksum(74a76d317fef622e).(
686 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
687 bytecxx . . $ byte#* tmp_frame,
688 ulintcxx . . $ ulint# physical_size,
689 bytecxx . . $ byte#* src_frame)
690 {
691 uint key_version = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
692 src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!);
693 bool page_compressed = (fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(src_frame)
694 == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTEDcxx . . $ FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED.);
695 uint offset = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(src_frame + FIL_PAGE_OFFSETcxx . . $ `storage/innobase/include/fil0fil.h:1195:9`!);
696 uint space = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
697 src_frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_IDcxx . . $ `storage/innobase/include/fil0fil.h:1245:9`!);
698 ib_uint64_tcxx . . $ ib_uint64_t# lsn = mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(src_frame + FIL_PAGE_LSNcxx . . $ `storage/innobase/include/fil0fil.h:1213:9`!);
699
700 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
701
702 /* read space & lsn */
703 uint header_len = FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`!;
704
705 if (page_compressed) {
706 header_len += FIL_PAGE_ENCRYPT_COMP_METADATA_LENcxx . . $ `storage/innobase/include/fil0fil.h:1269:9`!;
707 }
708
709 /* Copy FIL page header, it is not encrypted */
710 memcpy(tmp_frame, src_frame, header_len);
711
712 /* Calculate the offset where decryption starts */
713 const bytecxx . . $ byte#* src = src_frame + header_len;
714 bytecxx . . $ byte#* dst = tmp_frame + header_len;
715 uint srclen = uint(physical_size) - header_len - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!;
716 uint dstlen = srclen;
717
718 if (page_compressed) {
719 srclen = mach_read_from_2cxx . . $ mach_read_from_2(469dcb4e54b221a8).(src_frame + FIL_PAGE_DATAcxx . . $ `storage/innobase/include/fil0fil.h:1249:9`!);
720 }
721
722 int rc = encryption_scheme_decrypt(src, srclen, dst, &dstlen,
723 crypt_data, key_version,
724 space, offset, lsn);
725
726 if (! ((rc == MY_AES_OKcxx . . $ `include/mysql/service_my_crypt.h:37:9`!) && ((ulintcxx . . $ ulint#) dstlen == srclen))) {
727 return DB_DECRYPTION_FAILEDcxx . . $ DB_DECRYPTION_FAILED.;
728 }
729
730 /* For compressed tables we do not store the FIL header because
731 the whole page is not stored to the disk. In compressed tables only
732 the FIL header + compressed (and now encrypted) payload alligned
733 to sector boundary is written. */
734 if (!page_compressed) {
735 /* Copy FIL trailer */
736 memcpy(tmp_frame + physical_size - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!,
737 src_frame + physical_size - FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!,
738 FIL_PAGE_DATA_ENDcxx . . $ `storage/innobase/include/fil0fil.h:1277:9`!);
739 }
740
741 srv_statscxx . . $ srv_stats..pages_decryptedcxx . . $ srv_stats_t#pages_decrypted..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).();
742
743 return DB_SUCCESScxx . . $ DB_SUCCESS.; /* page was decrypted */
744 }
745
746 /** Decrypt a page.
747 @param[in] space_id tablespace id
748 @param[in] fsp_flags Tablespace flags
749 @param[in] crypt_data crypt_data
750 @param[in] tmp_frame Temporary buffer
751 @param[in] physical_size page size
752 @param[in,out] src_frame Page to decrypt
753 @retval DB_SUCCESS on success
754 @retval DB_DECRYPTION_FAILED on error */
755 dberr_tcxx . . $ dberr_t#
756 fil_space_decryptcxx . . $ fil_space_decrypt(97ea329debe48c4).(
757 uint32_tcxx . . $ uint32_t# space_id,
758 uint32_tcxx . . $ uint32_t# fsp_flags,
759 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
760 bytecxx . . $ byte#* tmp_frame,
761 ulintcxx . . $ ulint# physical_size,
762 bytecxx . . $ byte#* src_frame)
763 {
764 if (!crypt_data || !crypt_data->is_encryptedcxx . . $ fil_space_crypt_t#is_encrypted(50ce9a9e25b4a850).()) {
765 return DB_DECRYPTION_FAILEDcxx . . $ DB_DECRYPTION_FAILED.;
766 }
767
768 if (fil_space_tcxx . . $ fil_space_t#::full_crc32cxx . . $ fil_space_t#full_crc32(ad254478a19226f0).(fsp_flags)) {
769 return fil_space_decrypt_full_crc32cxx . . $ fil_space_decrypt_full_crc32(93d953a1af07859b).(
770 space_id, crypt_data, tmp_frame, src_frame);
771 }
772
773 return fil_space_decrypt_for_non_full_checksumcxx . . $ fil_space_decrypt_for_non_full_checksum(74a76d317fef622e).(crypt_data, tmp_frame,
774 physical_size,
775 src_frame);
776 }
777
778 /**
779 Decrypt a page.
780 @param[in] space Tablespace
781 @param[in] tmp_frame Temporary buffer used for decrypting
782 @param[in,out] src_frame Page to decrypt
783 @return decrypted page, or original not encrypted page if decryption is
784 not needed.
785 @retval nullptr on failure */
786 bytecxx . . $ byte#*
787 fil_space_decryptcxx . . $ fil_space_decrypt(1064dddfcae33dd0).(
788 const fil_space_tcxx . . $ fil_space_t#* space,
789 bytecxx . . $ byte#* tmp_frame,
790 bytecxx . . $ byte#* src_frame)
791 {
792 const ulintcxx . . $ ulint# physical_size = space->physical_sizecxx . . $ fil_space_t#physical_size(d22c8608b6eae7b5).();
793
794 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
795
796 if (DB_SUCCESScxx . . $ DB_SUCCESS. != fil_space_decryptcxx . . $ fil_space_decrypt(97ea329debe48c4).(space->idcxx . . $ fil_space_t#id., space->flagscxx . . $ fil_space_t#flags.,
797 space->crypt_datacxx . . $ fil_space_t#crypt_data.,
798 tmp_frame, physical_size,
799 src_frame)) {
800 return nullptr;
801 }
802
803 /* Copy the decrypted page back to page buffer, not
804 really any other options. */
805 return static_cast<bytecxx . . $ byte#*>(memcpy(src_frame, tmp_frame, physical_size));
806 }
807
808 /***********************************************************************/
809
810 /** A copy of global key state */
811 struct key_state_tcxx . . $ key_state_t# {
812 key_state_tcxx . . $ key_state_t#key_state_t(49f6e7a06ebc5aa8).() : key_idcxx . . $ key_state_t#key_id.(0), key_versioncxx . . $ key_state_t#key_version.(0),
813 rotate_key_agecxx . . $ key_state_t#rotate_key_age.(srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.) {}
814 bool operatorcxx . . $ key_state_t#`operator==`(95e32c3e03e4dec6).==(const key_state_tcxx . . $ key_state_t#& other) const {
815 return key_versioncxx . . $ key_state_t#key_version. == other.key_versioncxx . . $ key_state_t#key_version. &&
816 rotate_key_agecxx . . $ key_state_t#rotate_key_age. == other.rotate_key_agecxx . . $ key_state_t#rotate_key_age.;
817 }
818 uint key_idcxx . . $ key_state_t#key_id.;
819 uint key_versioncxx . . $ key_state_t#key_version.;
820 uint rotate_key_agecxx . . $ key_state_t#rotate_key_age.;
821 };
822
823 /***********************************************************************
824 Copy global key state
825 @param[in,out] new_state key state
826 @param[in] crypt_data crypt data */
827 static void
828 fil_crypt_get_key_statecxx . . $ fil_crypt_get_key_state(971be311117efd13).(
829 key_state_tcxx . . $ key_state_t#* new_state,
830 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data)
831 {
832 if (srv_encrypt_tablescxx . . $ srv_encrypt_tables.) {
833 new_state->key_versioncxx . . $ key_state_t#key_version. = crypt_data->key_get_latest_versioncxx . . $ fil_space_crypt_t#key_get_latest_version(db52760e79bf9054).();
834 new_state->rotate_key_agecxx . . $ key_state_t#rotate_key_age. = srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.;
835
836 ut_acxx . . $ ulint#(new_state->key_version != ENCRYPTION_KEY_NOT_ENCRYPTEDcxx . . $ `include/mysql/service_encryption.h:45:9`!);
837 } else {
838 new_state->key_versioncxx . . $ key_state_t#key_version. = 0;
839 new_state->rotate_key_agecxx . . $ key_state_t#rotate_key_age. = 0;
840 }
841 }
842
843 /***********************************************************************
844 Check if a key needs rotation given a key_state
845 @param[in] crypt_data Encryption information
846 @param[in] key_version Current key version
847 @param[in] latest_key_version Latest key version
848 @param[in] rotate_key_age when to rotate
849 @return true if key needs rotation, false if not */
850 static bool
851 fil_crypt_needs_rotationcxx . . $ fil_crypt_needs_rotation(8d74958e750faaf9).(
852 const fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data,
853 uint key_version,
854 uint latest_key_version,
855 uint rotate_key_age)
856 {
857 if (key_version == ENCRYPTION_KEY_VERSION_INVALIDcxx . . $ `include/mysql/service_encryption.h:44:9`!) {
858 return false;
859 }
860
861 if (key_version == 0 && latest_key_version != 0) {
862 /* this is rotation unencrypted => encrypted
863 * ignore rotate_key_age */
864 return true;
865 }
866
867 if (latest_key_version == 0 && key_version != 0) {
868 if (crypt_data->encryptioncxx . . $ fil_space_crypt_t#encryption. == FIL_ENCRYPTION_DEFAULTcxx . . $ FIL_ENCRYPTION_DEFAULT.) {
869 /* this is rotation encrypted => unencrypted */
870 return true;
871 }
872 return false;
873 }
874
875 if (crypt_data->encryptioncxx . . $ fil_space_crypt_t#encryption. == FIL_ENCRYPTION_DEFAULTcxx . . $ FIL_ENCRYPTION_DEFAULT.
876 && crypt_data->type == CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!
877 && !srv_encrypt_tablescxx . . $ srv_encrypt_tables.) {
878 /* This is rotation encrypted => unencrypted */
879 return true;
880 }
881
882 if (rotate_key_age == 0) {
883 return false;
884 }
885
886 /* this is rotation encrypted => encrypted,
887 * only reencrypt if key is sufficiently old */
888 if (key_version + rotate_key_age < latest_key_version) {
889 return true;
890 }
891
892 return false;
893 }
894
895 /** Read page 0 and possible crypt data from there.
896 @param[in,out] space Tablespace */
897 static inline void fil_crypt_read_crypt_datacxx . . $ fil_crypt_read_crypt_data(932cf7f430860204).(fil_space_tcxx . . $ fil_space_t# *space)
898 {
899 if (space->crypt_datacxx . . $ fil_space_t#crypt_data. || space->sizecxx . . $ fil_space_t#size. || !space->get_sizecxx . . $ fil_space_t#get_size(2658d6455debfaef).())
900 /* The encryption metadata has already been read, or the
901 tablespace is not encrypted and the file has been opened already,
902 or the file cannot be accessed, likely due to a concurrent DROP
903 (possibly as part of TRUNCATE or ALTER TABLE).
904
905 FIXME: The file can become unaccessible any time after this check!
906 We should really remove this function and instead make crypt_data
907 an integral part of fil_space_t. */
908 return;
909
910 const ulintcxx . . $ ulint# zip_size= space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).();
911 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
912 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
913 if (buf_block_tcxx . . $ buf_block_t#* b= buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(page_id_tcxx . . $ page_id_t#{space->idcxx . . $ fil_space_t#id., 0}, zip_size,
914 RW_S_LATCHcxx . . $ RW_S_LATCH., nullptr,
915 BUF_GET_POSSIBLY_FREEDcxx . . $ `storage/innobase/include/buf0buf.h:58:9`!, &mtr))
916 {
917 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
918 if (!space->crypt_datacxx . . $ fil_space_t#crypt_data. && !space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).())
919 space->crypt_datacxx . . $ fil_space_t#crypt_data.= fil_space_read_crypt_datacxx . . $ fil_space_read_crypt_data(1109c76aac6a686).(zip_size, b->pagecxx . . $ buf_block_t#page..framecxx . . $ buf_page_t#frame.);
920 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
921 }
922 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
923 }
924
925 /** Start encrypting a space
926 @param[in,out] space Tablespace
927 @return true if a recheck of tablespace is needed by encryption thread. */
928 static bool fil_crypt_start_encrypting_spacecxx . . $ fil_crypt_start_encrypting_space(92bb835b6a5cb160).(fil_space_tcxx . . $ fil_space_t#* space)
929 {
930 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
931
932 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
933
934 /* If space is not encrypted and encryption is not enabled, then
935 do not continue encrypting the space. */
936 if (!crypt_data && !srv_encrypt_tablescxx . . $ srv_encrypt_tables.) {
937 func_exit:
938 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
939 return false;
940 }
941
942 const bool recheck = fil_crypt_start_convertingcxx . . $ fil_crypt_start_converting.;
943
944 if (recheck || crypt_data || space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
945 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
946 return recheck;
947 }
948
949 /* NOTE: we need to write and flush page 0 before publishing
950 * the crypt data. This so that after restart there is no
951 * risk of finding encrypted pages without having
952 * crypt data in page 0 */
953
954 /* 1 - create crypt data */
955 crypt_data = fil_space_create_crypt_datacxx . . $ fil_space_create_crypt_data(21ed37a4e50748ce).(
956 FIL_ENCRYPTION_DEFAULTcxx . . $ FIL_ENCRYPTION_DEFAULT., FIL_DEFAULT_ENCRYPTION_KEYcxx . . $ `storage/innobase/include/fil0crypt.h:41:9`!);
957
958 if (!crypt_data) {
959 goto func_exit;
960 }
961
962 fil_crypt_start_convertingcxx . . $ fil_crypt_start_converting. = true;
963 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
964
965 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
966 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
967
968 /* 2 - get page 0 */
969 if (buf_block_tcxx . . $ buf_block_t#* block = buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(
970 page_id_tcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).(space->idcxx . . $ fil_space_t#id., 0), space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(),
971 RW_X_LATCHcxx . . $ RW_X_LATCH., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, BUF_GET_POSSIBLY_FREEDcxx . . $ `storage/innobase/include/buf0buf.h:58:9`!, &mtr)) {
972 crypt_data->type = CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!;
973 crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. = 0; // all pages are unencrypted
974 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..start_timecxx . . $ fil_space_rotate_state_t#start_time. = time(0);
975 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..startingcxx . . $ fil_space_rotate_state_t#starting. = true;
976 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads. = 1;
977
978 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
979 const bool stopping = space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).();
980 if (!stopping) {
981 space->crypt_datacxx . . $ fil_space_t#crypt_data. = crypt_data;
982 }
983 mysql_mutex_unlockcxx . . $ fil_system_t#mutex.(&fil_system.mutex);
984
985 if (stopping) {
986 goto abort;
987 }
988
989 /* 3 - write crypt data to page 0 */
990 mtr.set_named_spacecxx . . $ mtr_t#set_named_space(932cf7f430860204).(space);
991 crypt_data->write_page0cxx . . $ fil_space_crypt_t#write_page0(c4796673375b2726).(block, &mtr);
992
993 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
994
995 /* 4 - sync tablespace before publishing crypt data */
996 while (buf_flush_list_spacecxx . . $ buf_flush_list_space(11a03951b981ba78).(space));
997
998 /* 5 - publish crypt data */
999 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
1000 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
1001 crypt_data->type = CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!;
1002 ut_acxx . . $ ulint#(crypt_data->rotate_state.active_threads == 1);
1003 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads. = 0;
1004 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..startingcxx . . $ fil_space_rotate_state_t#starting. = false;
1005
1006 fil_crypt_start_convertingcxx . . $ fil_crypt_start_converting. = false;
1007 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
1008 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_data->mutex);
1009
1010 return false;
1011 }
1012
1013 abort:
1014 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1015 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
1016 fil_crypt_start_convertingcxx . . $ fil_crypt_start_converting. = false;
1017 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
1018
1019 crypt_data->~fil_space_crypt_tcxx . . $ fil_space_crypt_t#();
1020 ut_freecxx . . $ byte#(crypt_data);
1021 return false;
1022 }
1023
1024 /** State of a rotation thread */
1025 struct rotate_thread_tcxx . . $ rotate_thread_t# {
1026 explicit rotate_thread_tcxx . . $ rotate_thread_t#rotate_thread_t(cb2f890c2fdad230).(uint no) : thread_nocxx . . $ rotate_thread_t#thread_no.(no) {}
1027
1028 uint thread_nocxx . . $ rotate_thread_t#thread_no.;
1029 bool firstcxx . . $ rotate_thread_t#first. = true; /*!< is position before first space */
1030 space_list_tcxx . . $ space_list_t#::iteratorcxx . . $ ilist#iterator# spacecxx . . $ rotate_thread_t#space.
1031 = fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();/*!< current space or .end() */
1032 uint32_tcxx . . $ uint32_t# offsetcxx . . $ rotate_thread_t#offset. = 0; /*!< current page number */
1033 ulintcxx . . $ ulint# batchcxx . . $ rotate_thread_t#batch. = 0; /*!< #pages to rotate */
1034 uint min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found. = 0; /*!< min key version found but not rotated */
1035 lsn_tcxx . . $ lsn_t# end_lsncxx . . $ rotate_thread_t#end_lsn. = 0; /*!< max lsn when rotating this space */
1036
1037 uint estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops. = 20;/*!< estimation of max iops */
1038 uint allocated_iopscxx . . $ rotate_thread_t#allocated_iops. = 0; /*!< allocated iops */
1039 ulintcxx . . $ ulint# cnt_waitedcxx . . $ rotate_thread_t#cnt_waited. = 0; /*!< #times waited during this slot */
1040 uintmax_tcxx . . $ uintmax_t# sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. = 0; /*!< wait time during this slot */
1041
1042 fil_crypt_stat_tcxx . . $ fil_crypt_stat_t# crypt_statcxx . . $ rotate_thread_t#crypt_stat.; // statistics
1043
1044 /** @return whether this thread should terminate */
1045 bool should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).() const {
1046 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_crypt_threads_mutex);
1047 switch (srv_shutdown_statecxx . . $ srv_shutdown_state.) {
1048 case SRV_SHUTDOWN_NONEcxx . . $ SRV_SHUTDOWN_NONE.:
1049 return thread_nocxx . . $ rotate_thread_t#thread_no. >= srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.;
1050 case SRV_SHUTDOWN_EXIT_THREADScxx . . $ SRV_SHUTDOWN_EXIT_THREADS.:
1051 /* srv_init_abort() must have been invoked */
1052 case SRV_SHUTDOWN_CLEANUPcxx . . $ SRV_SHUTDOWN_CLEANUP.:
1053 case SRV_SHUTDOWN_INITIATEDcxx . . $ SRV_SHUTDOWN_INITIATED.:
1054 return true;
1055 case SRV_SHUTDOWN_LAST_PHASEcxx . . $ SRV_SHUTDOWN_LAST_PHASE.:
1056 break;
1057 }
1058 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(0);
1059 return true;
1060 }
1061 };
1062
1063 /** Avoid the removal of the tablespace from
1064 default_encrypt_list only when
1065 1) Another active encryption thread working on tablespace
1066 2) Eligible for tablespace key rotation
1067 3) Tablespace is in flushing phase
1068 @return true if tablespace should be removed from
1069 default encrypt */
1070 static bool fil_crypt_must_removecxx . . $ fil_crypt_must_remove(4430f81875d4418b).(const fil_space_tcxx . . $ fil_space_t# &space)
1071 {
1072 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!space.is_temporary());
1073 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!space.is_being_imported());
1074 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = space.crypt_datacxx . . $ fil_space_t#crypt_data.;
1075 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_system.mutex);
1076 const ulong encrypt_tables= srv_encrypt_tablescxx . . $ srv_encrypt_tables.;
1077 if (!crypt_data)
1078 return !encrypt_tables;
1079 if (!crypt_data->is_key_foundcxx . . $ fil_space_crypt_t#is_key_found(50ce9a9e25b4a850).())
1080 return true;
1081
1082 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
1083 const bool remove= (space.is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).() || crypt_data->not_encryptedcxx . . $ fil_space_crypt_t#not_encrypted(50ce9a9e25b4a850).()) &&
1084 (!crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing. &&
1085 !encrypt_tables == !!crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. &&
1086 !crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.);
1087 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
1088 return remove;
1089 }
1090
1091 /***********************************************************************
1092 Check if space needs rotation given a key_state
1093 @param[in,out] state Key rotation state
1094 @param[in,out] key_state Key state
1095 @param[in,out] recheck needs recheck ?
1096 @return true if space needs key rotation */
1097 static
1098 bool
1099 fil_crypt_space_needs_rotationcxx . . $ fil_crypt_space_needs_rotation(86307a039b316995).(
1100 rotate_thread_tcxx . . $ rotate_thread_t#* state,
1101 key_state_tcxx . . $ key_state_t#* key_state,
1102 bool* recheck)
1103 {
1104 mysql_mutex_assert_not_ownercxx . . $ `include/mysql/psi/mysql_thread.h:282:9`!(&fil_crypt_threads_mutex);
1105
1106 fil_space_tcxx . . $ fil_space_t#* space = &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).state->spacecxx . . $ rotate_thread_t#space.;
1107
1108 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
1109 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!space->is_temporary());
1110 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!space->is_being_imported());
1111
1112 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
1113
1114 if (crypt_data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
1115 /**
1116 * space has no crypt data
1117 * start encrypting it...
1118 */
1119 *recheck = fil_crypt_start_encrypting_spacecxx . . $ fil_crypt_start_encrypting_space(92bb835b6a5cb160).(space);
1120 crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
1121
1122 if (crypt_data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
1123 return false;
1124 }
1125
1126 crypt_data->key_get_latest_versioncxx . . $ fil_space_crypt_t#key_get_latest_version(db52760e79bf9054).();
1127 }
1128
1129 /* If used key_id is not found from encryption plugin we can't
1130 continue to rotate the tablespace */
1131 if (!crypt_data->is_key_foundcxx . . $ fil_space_crypt_t#is_key_found(50ce9a9e25b4a850).()) {
1132 return false;
1133 }
1134
1135 bool need_key_rotation = false;
1136
1137 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
1138
1139 do {
1140 /* prevent threads from starting to rotate space */
1141 if (crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..startingcxx . . $ fil_space_rotate_state_t#starting.) {
1142 /* recheck this space later */
1143 *recheck = true;
1144 break;
1145 }
1146
1147 /* prevent threads from starting to rotate space */
1148 if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1149 break;
1150 }
1151
1152 if (crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing.) {
1153 break;
1154 }
1155
1156 /* No need to rotate space if encryption is disabled */
1157 if (crypt_data->not_encryptedcxx . . $ fil_space_crypt_t#not_encrypted(50ce9a9e25b4a850).()) {
1158 break;
1159 }
1160
1161 if (crypt_data->key_id != key_state->key_idcxx . . $ key_state_t#key_id.) {
1162 key_state->key_idcxx . . $ key_state_t#key_id.= crypt_data->key_id;
1163 fil_crypt_get_key_statecxx . . $ fil_crypt_get_key_state(971be311117efd13).(key_state, crypt_data);
1164 }
1165
1166 need_key_rotation = fil_crypt_needs_rotationcxx . . $ fil_crypt_needs_rotation(8d74958e750faaf9).(
1167 crypt_data,
1168 crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.,
1169 key_state->key_versioncxx . . $ key_state_t#key_version.,
1170 key_state->rotate_key_agecxx . . $ key_state_t#rotate_key_age.);
1171 } while (0);
1172
1173 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_data->mutex);
1174 return need_key_rotation;
1175 }
1176
1177 /***********************************************************************
1178 Update global statistics with thread statistics
1179 @param[in,out] state key rotation statistics */
1180 static void
1181 fil_crypt_update_total_statcxx . . $ fil_crypt_update_total_stat(a7822dfb21d2c8f4).(
1182 rotate_thread_tcxx . . $ rotate_thread_t# *state)
1183 {
1184 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_stat_mutex);
1185 crypt_statcxx . . $ crypt_stat..pages_read_from_cachecxx . . $ fil_crypt_stat_t#pages_read_from_cache. +=
1186 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_cachecxx . . $ fil_crypt_stat_t#pages_read_from_cache.;
1187 crypt_statcxx . . $ crypt_stat..pages_read_from_diskcxx . . $ fil_crypt_stat_t#pages_read_from_disk. +=
1188 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_diskcxx . . $ fil_crypt_stat_t#pages_read_from_disk.;
1189 crypt_statcxx . . $ crypt_stat..pages_modifiedcxx . . $ fil_crypt_stat_t#pages_modified. += state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_modifiedcxx . . $ fil_crypt_stat_t#pages_modified.;
1190 crypt_statcxx . . $ crypt_stat..pages_flushedcxx . . $ fil_crypt_stat_t#pages_flushed. += state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_flushedcxx . . $ fil_crypt_stat_t#pages_flushed.;
1191 // remote old estimate
1192 crypt_statcxx . . $ crypt_stat..estimated_iopscxx . . $ fil_crypt_stat_t#estimated_iops. -= state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..estimated_iopscxx . . $ fil_crypt_stat_t#estimated_iops.;
1193 // add new estimate
1194 crypt_statcxx . . $ crypt_stat..estimated_iopscxx . . $ fil_crypt_stat_t#estimated_iops. += state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.;
1195 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_stat_mutex);
1196
1197 // make new estimate "current" estimate
1198 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_cachecxx . . $ fil_crypt_stat_t#pages_read_from_cache. = 0;
1199 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_diskcxx . . $ fil_crypt_stat_t#pages_read_from_disk. = 0;
1200 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_modifiedcxx . . $ fil_crypt_stat_t#pages_modified. = 0;
1201 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_flushedcxx . . $ fil_crypt_stat_t#pages_flushed. = 0;
1202 // record our old (current) estimate
1203 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..estimated_iopscxx . . $ fil_crypt_stat_t#estimated_iops. = state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.;
1204 }
1205
1206 /***********************************************************************
1207 Allocate iops to thread from global setting,
1208 used before starting to rotate a space.
1209 @param[in,out] state Rotation state
1210 @return true if allocation succeeded, false if failed */
1211 static bool fil_crypt_alloc_iopscxx . . $ fil_crypt_alloc_iops(c894e907616a3f9a).(rotate_thread_tcxx . . $ rotate_thread_t# *state)
1212 {
1213 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_crypt_threads_mutex);
1214 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(state->allocated_iops == 0);
1215
1216 /* We have not yet selected the space to rotate, thus
1217 state might not contain space and we can't check
1218 its status yet. */
1219
1220 uint max_iops = state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.;
1221
1222 if (n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated. >= srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops.) {
1223 wait:
1224 my_cond_waitcxx . . $ fil_crypt_threads_cond.(&fil_crypt_threads_cond,
1225 &fil_crypt_threads_mutex.m_mutex);
1226 return false;
1227 }
1228
1229 uint alloc = srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops. - n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated.;
1230
1231 if (alloc > max_iops) {
1232 alloc = max_iops;
1233 }
1234
1235 if (!alloc) {
1236 goto wait;
1237 }
1238
1239 n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated. += alloc;
1240
1241 state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. = alloc;
1242 return true;
1243 }
1244
1245 /**
1246 Reallocate iops to thread when processing a tablespace
1247 @param[in,out] state Rotation state
1248 @return whether the thread should continue running */
1249 static bool fil_crypt_realloc_iopscxx . . $ fil_crypt_realloc_iops(c894e907616a3f9a).(rotate_thread_tcxx . . $ rotate_thread_t# *state)
1250 {
1251 ut_acxx . . $ rotate_thread_t#allocated_iops.(state->allocated_iops > 0);
1252
1253 if (10 * state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited. > state->batchcxx . . $ rotate_thread_t#batch.) {
1254 /* if we waited more than 10% re-estimate max_iops */
1255 ulintcxx . . $ ulint# avg_wait_time_us =
1256 ulintcxx . . $ ulint#(state->sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. / state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited.);
1257
1258 if (avg_wait_time_us == 0) {
1259 avg_wait_time_us = 1; // prevent division by zero
1260 }
1261
1262 DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("ib_crypt",
1263 ("thr_no: %u - update estimated_max_iops from %u to "
1264 ULINTPF ".",
1265 state->thread_no,
1266 state->estimated_max_iops,
1267 1000000 / avg_wait_time_us));
1268
1269 state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(
1270 1U, uint(1000000 / avg_wait_time_us));
1271 state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited. = 0;
1272 state->sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. = 0;
1273 } else {
1274 DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("ib_crypt",
1275 ("thr_no: %u only waited " ULINTPF
1276 "%% skip re-estimate.",
1277 state->thread_no,
1278 (100 * state->cnt_waited)
1279 / (state->batch ? state->batch : 1)));
1280 }
1281
1282 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(state->estimated_max_iops);
1283
1284 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
1285
1286 if (state->should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).()) {
1287 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
1288 return false;
1289 }
1290
1291 if (state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. > state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.) {
1292 /* release iops */
1293 uint extra = state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. - state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.;
1294 state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. = state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.;
1295 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n_fil_crypt_iops_allocated >= extra);
1296 n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated. -= extra;
1297 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
1298 } else if (srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops. > n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated.) {
1299 /* there are extra iops free */
1300 uint add = srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops. - n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated.;
1301 if (state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. + add > state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops.) {
1302 /* but don't alloc more than our max */
1303 add= state->estimated_max_iopscxx . . $ rotate_thread_t#estimated_max_iops. - state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops.;
1304 }
1305 n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated. += add;
1306 state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops. += add;
1307
1308 DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("ib_crypt",
1309 ("thr_no: %u increased iops from %u to %u.",
1310 state->thread_no,
1311 state->allocated_iops - add,
1312 state->allocated_iops));
1313 }
1314
1315 fil_crypt_update_total_statcxx . . $ fil_crypt_update_total_stat(a7822dfb21d2c8f4).(state);
1316 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
1317 return true;
1318 }
1319
1320 /** Release excess allocated iops
1321 @param state rotation state
1322 @param wake whether to wake up other threads */
1323 static void fil_crypt_return_iopscxx . . $ fil_crypt_return_iops(df68cb7315230dcc).(rotate_thread_tcxx . . $ rotate_thread_t# *state, bool wake= true)
1324 {
1325 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_crypt_threads_mutex);
1326
1327 if (uint iops= state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops.)
1328 {
1329 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n_fil_crypt_iops_allocated >= iops);
1330 n_fil_crypt_iops_allocatedcxx . . $ n_fil_crypt_iops_allocated.-= iops;
1331 state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops.= 0;
1332 if (wake)
1333 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
1334 }
1335
1336 fil_crypt_update_total_statcxx . . $ fil_crypt_update_total_stat(a7822dfb21d2c8f4).(state);
1337 }
1338
1339 /** Acquire a tablespace reference.
1340 @return whether a tablespace reference was successfully acquired */
1341 inline bool fil_space_tcxx . . $ fil_space_t#::acquire_if_not_stoppedcxx . . $ fil_space_t#acquire_if_not_stopped(c9857a73d68e59ba).()
1342 {
1343 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_system.mutex);
1344 const uint32_tcxx . . $ uint32_t# n= acquire_lowcxx . . $ fil_space_t#acquire_low(2141b656ce2cc063).();
1345 if (UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(!(n & (STOPPING | CLOSING))))
1346 return true;
1347 if (UNIV_UNLIKELYcxx . . $ fil_space_t#STOPPING.(n & STOPPING))
1348 return false;
1349 return UNIV_LIKELYcxx . . $ `storage/innobase/include/univ.i:437:9`!(!(n & CLOSING)) || prepare_acquiredcxx . . $ fil_space_t#prepare_acquired(77ce49a7840d23c7).();
1350 }
1351
1352 bool fil_crypt_must_default_encryptcxx . . $ fil_crypt_must_default_encrypt(c9857a73d68e59ba).()
1353 {
1354 /* prevents a race condition with fil_crypt_set_rotate_key_age() */
1355 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_system.mutex);
1356 return !srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age. || !srv_encrypt_rotatecxx . . $ srv_encrypt_rotate.;
1357 }
1358
1359 /** Return the next tablespace from default_encrypt_tables list.
1360 @param space previous tablespace (nullptr to start from the start)
1361 @param recheck whether the removal condition needs to be rechecked after
1362 the encryption parameters were changed
1363 @param encrypt expected state of innodb_encrypt_tables
1364 @return the next tablespace to process (n_pending_ops incremented)
1365 @retval fil_system.temp_space if there is no work to do
1366 @retval nullptr upon reaching the end of the iteration */
1367 inline fil_space_tcxx . . $ fil_space_t# *fil_system_tcxx . . $ fil_system_t#::default_encrypt_nextcxx . . $ fil_system_t#default_encrypt_next(b017f7afa5547651).(fil_space_tcxx . . $ fil_space_t# *space,
1368 bool recheck,
1369 bool encrypt) noexcept
1370 {
1371 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&mutex);
1372
1373 auto it= space && space->is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt.
1374 ? sized_ilistcxx . . $ sized_ilist#<fil_space_t, default_encrypt_tag_t>::iteratorcxx . . $ sized_ilist#iterator#(space)
1375 : default_encrypt_tablescxx . . $ fil_system_t#default_encrypt_tables..begincxx . . $ ilist#begin(ad7448b2af519333).();
1376 const auto end= default_encrypt_tablescxx . . $ fil_system_t#default_encrypt_tables..endcxx . . $ ilist#end(ad7448b2af519333).();
1377
1378 if (space)
1379 {
1380 const bool released= !space->releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
1381
1382 if (space->is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt.)
1383 {
1384 while (++cxx . . $ ilist#Iterator#operator++(fc97392e836d6e10).it !=cxx . . $ `operator!=`(15200bf62d6bc6bb). end &&
1385 (!UT_LIST_GET_LENcxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).(it->chain) || it->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()));
1386
1387 /* If one of the encryption threads already started
1388 the encryption of the table then don't remove the
1389 unencrypted spaces from default encrypt list.
1390
1391 If there is a change in innodb_encrypt_tables variables
1392 value then don't remove the last processed tablespace
1393 from the default encrypt list. */
1394 if (released && !recheck && fil_crypt_must_removecxx . . $ fil_crypt_must_remove(4430f81875d4418b).(*space))
1395 {
1396 ut_acxx . . $ fil_system_t#default_encrypt_tables.(!default_encrypt_tables.empty());
1397 default_encrypt_tablescxx . . $ fil_system_t#default_encrypt_tables..removecxx . . $ ilist#remove(926f85bfe424ae64).(*space);
1398 space->is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt.= false;
1399 }
1400 }
1401 }
1402 else while (it !=cxx . . $ `operator!=`(15200bf62d6bc6bb). end &&
1403 (!UT_LIST_GET_LENcxx . . $ `storage/innobase/include/ut0lst.h:415:9`!(it->chain) || it->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()))
1404 {
1405 /* Find the next suitable default encrypt table if
1406 beginning of default_encrypt_tables list has been scheduled
1407 to be deleted */
1408 it++cxx . . $ ilist#Iterator#operator++(6188afb7a25126a2).;
1409 }
1410
1411 if (it ==cxx . . $ `operator==`(15200bf62d6bc6bb). end)
1412 return temp_spacecxx . . $ fil_system_t#temp_space.;
1413
1414 do
1415 {
1416 space= &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).it;
1417 if (space->acquire_if_not_stoppedcxx . . $ fil_space_t#acquire_if_not_stopped(c9857a73d68e59ba).())
1418 return space;
1419 if (++cxx . . $ ilist#Iterator#operator++(fc97392e836d6e10).it ==cxx . . $ `operator==`(15200bf62d6bc6bb). end)
1420 return nullptr;
1421 }
1422 while (!UT_LIST_GET_LENcxx . . $ ut_list_base#count.(it->chain) || it->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).());
1423
1424 return nullptr;
1425 }
1426
1427 /** Determine the next tablespace for encryption key rotation.
1428 @param space current tablespace (nullptr to start from the beginning)
1429 @param recheck whether the removal condition needs to be rechecked after
1430 encryption parameters were changed
1431 @param encrypt expected state of innodb_encrypt_tables
1432 @return the next tablespace
1433 @retval fil_system.temp_space if there is no work to do
1434 @retval end() upon reaching the end of the iteration */
1435 space_list_tcxx . . $ space_list_t#::iteratorcxx . . $ ilist#iterator# fil_space_tcxx . . $ fil_space_t#::nextcxx . . $ fil_space_t#next(cdec6cbe7335d640).(space_list_tcxx . . $ space_list_t#::iteratorcxx . . $ ilist#iterator# space,
1436 bool recheck, bool encrypt) noexcept
1437 {
1438 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
1439
1440 if (fil_crypt_must_default_encryptcxx . . $ fil_crypt_must_default_encrypt(c9857a73d68e59ba).())
1441 {
1442 fil_space_tcxx . . $ fil_space_t# *next_space=
1443 fil_systemcxx . . $ fil_system..default_encrypt_nextcxx . . $ fil_system_t#default_encrypt_next(b017f7afa5547651).(space ==cxx . . $ `operator==`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()
1444 ? nullptr : &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).space, recheck, encrypt);
1445 space=cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). next_space
1446 ? space_list_tcxx . . $ space_list_t#::iteratorcxx . . $ ilist#iterator#(next_space)
1447 : fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
1448 }
1449 else
1450 {
1451 if (space ==cxx . . $ `operator==`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).())
1452 space=cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..begincxx . . $ ilist#begin(ad7448b2af519333).();
1453 else
1454 {
1455 /* Move on to the next fil_space_t */
1456 space->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
1457 ++cxx . . $ ilist#Iterator#operator++(fc97392e836d6e10).space;
1458 }
1459
1460 for (; space !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).(); ++cxx . . $ ilist#Iterator#operator++(fc97392e836d6e10).space)
1461 {
1462 if (space->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_temporarycxx . . $ fil_space_t#is_temporary(3482b152b9333168).() || space->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_being_importedcxx . . $ fil_space_t#is_being_imported(3482b152b9333168).())
1463 continue;
1464 const uint32_tcxx . . $ uint32_t# n= space->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).acquire_lowcxx . . $ fil_space_t#acquire_low(2141b656ce2cc063).();
1465 if (UNIV_LIKELYcxx . . $ fil_space_t#CLOSING.(!(n & (STOPPING | CLOSING))))
1466 break;
1467 if (!(n & STOPPINGcxx . . $ fil_space_t#STOPPING.) && space->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).prepare_acquiredcxx . . $ fil_space_t#prepare_acquired(77ce49a7840d23c7).())
1468 break;
1469 }
1470 }
1471
1472 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
1473 return space;
1474 }
1475
1476 /** Search for a space needing rotation
1477 @param[in,out] key_state Key state
1478 @param[in,out] state Rotation state
1479 @param[in,out] recheck recheck of the tablespace is needed or
1480 still encryption thread does write page 0
1481 @return whether the thread should keep running */
1482 static bool fil_crypt_find_space_to_rotatecxx . . $ fil_crypt_find_space_to_rotate(5fbb71c4b314a772).(
1483 key_state_tcxx . . $ key_state_t#* key_state,
1484 rotate_thread_tcxx . . $ rotate_thread_t#* state,
1485 bool* recheck) noexcept
1486 {
1487 /* we need iops to start rotating */
1488 do {
1489 if (state->should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).()) {
1490 if (state->spacecxx . . $ rotate_thread_t#space. !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
1491 state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
1492 state->spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
1493 }
1494 return false;
1495 }
1496 } while (!fil_crypt_alloc_iopscxx . . $ fil_crypt_alloc_iops(c894e907616a3f9a).(state));
1497
1498 if (state->firstcxx . . $ rotate_thread_t#first.) {
1499 state->firstcxx . . $ rotate_thread_t#first. = false;
1500 if (state->spacecxx . . $ rotate_thread_t#space. !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
1501 state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
1502 }
1503 state->spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
1504 }
1505
1506 state->spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_space_tcxx . . $ fil_space_t#::nextcxx . . $ fil_space_t#next(cdec6cbe7335d640).(state->spacecxx . . $ rotate_thread_t#space., *recheck,
1507 key_state->key_versioncxx . . $ key_state_t#key_version. != 0);
1508
1509 bool wake = true;
1510 while (state->spacecxx . . $ rotate_thread_t#space. !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
1511 if (state->spacecxx . . $ rotate_thread_t#space.
1512 ==cxx . . $ `operator==`(15200bf62d6bc6bb). space_list_tcxx . . $ ilist#Iterator#Iterator(b878f813500fc8c).::iteratorcxx . . $ ilist#iterator#(fil_systemcxx . . $ fil_system..temp_spacecxx . . $ fil_system_t#temp_space.)) {
1513 wake = false;
1514 goto done;
1515 }
1516
1517 if (state->should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).()) {
1518 state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
1519 done:
1520 state->spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
1521 break;
1522 }
1523
1524 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
1525 /* If there is no crypt data and we have not yet read
1526 page 0 for this tablespace, we need to read it before
1527 we can continue. */
1528 if (!state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).crypt_datacxx . . $ fil_space_t#crypt_data.) {
1529 fil_crypt_read_crypt_datacxx . . $ fil_crypt_read_crypt_data(932cf7f430860204).(&*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).state->spacecxx . . $ rotate_thread_t#space.);
1530 }
1531
1532 if (fil_crypt_space_needs_rotationcxx . . $ fil_crypt_space_needs_rotation(86307a039b316995).(state, key_state, recheck)) {
1533 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(key_state->key_id);
1534 /* init state->min_key_version_found before
1535 * starting on a space */
1536 state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found. = key_state->key_versioncxx . . $ key_state_t#key_version.;
1537 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
1538 return true;
1539 }
1540
1541 state->spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_space_tcxx . . $ fil_space_t#::nextcxx . . $ fil_space_t#next(cdec6cbe7335d640).(state->spacecxx . . $ rotate_thread_t#space., *recheck,
1542 key_state->key_versioncxx . . $ key_state_t#key_version. != 0);
1543 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
1544 }
1545
1546 /* no work to do; release our allocation of I/O capacity */
1547 fil_crypt_return_iopscxx . . $ fil_crypt_return_iops(df68cb7315230dcc).(state, wake);
1548 return true;
1549 }
1550
1551 /***********************************************************************
1552 Start rotating a space
1553 @param[in] key_state Key state
1554 @param[in,out] state Rotation state */
1555 static
1556 void
1557 fil_crypt_start_rotate_spacecxx . . $ fil_crypt_start_rotate_space(2037374cd1403d7a).(
1558 const key_state_tcxx . . $ key_state_t#* key_state,
1559 rotate_thread_tcxx . . $ rotate_thread_t#* state)
1560 {
1561 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).crypt_datacxx . . $ fil_space_t#crypt_data.;
1562
1563 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(crypt_data);
1564 mysql_mutex_lockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
1565 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(key_state->key_id == crypt_data->key_id);
1566
1567 if (crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads. == 0) {
1568 /* only first thread needs to init */
1569 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset. = 1; // skip page 0
1570 /* no need to rotate beyond current max
1571 * if space extends, it will be encrypted with newer version */
1572 /* FIXME: max_offset could be removed and instead
1573 space->size consulted.*/
1574 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..max_offsetcxx . . $ fil_space_rotate_state_t#max_offset. = state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).sizecxx . . $ fil_space_t#size.;
1575 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..end_lsncxx . . $ fil_space_rotate_state_t#end_lsn. = 0;
1576 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..min_key_version_foundcxx . . $ fil_space_rotate_state_t#min_key_version_found. =
1577 key_state->key_versioncxx . . $ key_state_t#key_version.;
1578
1579 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..start_timecxx . . $ fil_space_rotate_state_t#start_time. = time(0);
1580
1581 if (crypt_data->type == CRYPT_SCHEME_UNENCRYPTEDcxx . . $ `storage/innobase/include/fil0crypt.h:62:9`! &&
1582 crypt_data->is_encryptedcxx . . $ fil_space_crypt_t#is_encrypted(50ce9a9e25b4a850).() &&
1583 key_state->key_versioncxx . . $ key_state_t#key_version. != 0) {
1584 /* this is rotation unencrypted => encrypted */
1585 crypt_data->type = CRYPT_SCHEME_1cxx . . $ `storage/innobase/include/fil0crypt.h:60:9`!;
1586 }
1587 }
1588
1589 /* count active threads in space */
1590 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.++;
1591
1592 /* Initialize thread local state */
1593 state->end_lsncxx . . $ rotate_thread_t#end_lsn. = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..end_lsncxx . . $ fil_space_rotate_state_t#end_lsn.;
1594 state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found. =
1595 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..min_key_version_foundcxx . . $ fil_space_rotate_state_t#min_key_version_found.;
1596
1597 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_data->mutex);
1598 }
1599
1600 /***********************************************************************
1601 Search for batch of pages needing rotation
1602 @param[in] key_state Key state
1603 @param[in,out] state Rotation state
1604 @return true if page needing key rotation found, false if not found */
1605 static
1606 bool
1607 fil_crypt_find_page_to_rotatecxx . . $ fil_crypt_find_page_to_rotate(51819f7f8d52bd67).(
1608 const key_state_tcxx . . $ key_state_t#* key_state,
1609 rotate_thread_tcxx . . $ rotate_thread_t#* state)
1610 {
1611 ulintcxx . . $ ulint# batch = srv_alloc_timecxx . . $ srv_alloc_time. * state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops.;
1612
1613 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(state->space == fil_system.space_list.end()
1614 || state->space->referenced());
1615
1616 /* If space is marked to be dropped stop rotation. */
1617 if (state->spacecxx . . $ rotate_thread_t#space. ==cxx . . $ `operator==`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()
1618 || state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1619 return false;
1620 }
1621
1622 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).crypt_datacxx . . $ fil_space_t#crypt_data.;
1623
1624 mysql_mutex_lockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
1625 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(key_state->key_id == crypt_data->key_id);
1626
1627 bool found = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..max_offsetcxx . . $ fil_space_rotate_state_t#max_offset. >=
1628 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset.;
1629
1630 if (found) {
1631 state->offsetcxx . . $ rotate_thread_t#offset. = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset.;
1632 ulintcxx . . $ ulint# remaining = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..max_offsetcxx . . $ fil_space_rotate_state_t#max_offset. -
1633 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset.;
1634
1635 if (batch <= remaining) {
1636 state->batchcxx . . $ rotate_thread_t#batch. = batch;
1637 } else {
1638 state->batchcxx . . $ rotate_thread_t#batch. = remaining;
1639 }
1640 }
1641
1642 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset. += uint32_tcxx . . $ uint32_t#(batch);
1643 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
1644 return found;
1645 }
1646
1647 /***********************************************************************
1648 Get a page and compute sleep time
1649 @param[in,out] state Rotation state
1650 @param[in] offset Page offset
1651 @param[in,out] mtr Minitransaction
1652 @param[out] sleeptime_ms Sleep time
1653 @return page or NULL*/
1654 static
1655 buf_block_tcxx . . $ buf_block_t#*
1656 fil_crypt_get_page_throttlecxx . . $ fil_crypt_get_page_throttle(87053b988ed431da).(
1657 rotate_thread_tcxx . . $ rotate_thread_t#* state,
1658 uint32_tcxx . . $ uint32_t# offset,
1659 mtr_tcxx . . $ mtr_t#* mtr,
1660 ulintcxx . . $ ulint#* sleeptime_ms)
1661 {
1662 fil_space_tcxx . . $ fil_space_t#* space = &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).state->spacecxx . . $ rotate_thread_t#space.;
1663 const ulintcxx . . $ ulint# zip_size = space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).();
1664 const page_id_tcxx . . $ page_id_t# page_idcxx . . $ page_id_t#page_id_t(b4d55b1286ff73e8).(space->idcxx . . $ fil_space_t#id., offset);
1665 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
1666
1667 /* Before reading from tablespace we need to make sure that
1668 the tablespace is not about to be dropped. */
1669 if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1670 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1671 }
1672
1673 buf_block_tcxx . . $ buf_block_t#* block = buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(page_id, zip_size, RW_X_LATCHcxx . . $ RW_X_LATCH.,
1674 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
1675 BUF_PEEK_IF_IN_POOLcxx . . $ `storage/innobase/include/buf0buf.h:56:9`!, mtr);
1676 if (block != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
1677 /* page was in buffer pool */
1678 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(
1679 block, reinterpret_cast<dict_index_tcxx . . $ dict_index_t#*>(-1));
1680 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_cachecxx . . $ fil_crypt_stat_t#pages_read_from_cache.++;
1681 return block;
1682 }
1683
1684 if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1685 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1686 }
1687
1688 if (offset % (zip_size ? zip_size : srv_page_sizecxx . . $ srv_page_size.)
1689 && DB_SUCCESS_LOCKED_RECcxx . . $ DB_SUCCESS_LOCKED_REC.
1690 != fseg_page_is_allocatedcxx . . $ fseg_page_is_allocated(6d2f533a32123586).(mtr, space, offset)) {
1691 /* page is already freed */
1692 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1693 }
1694
1695 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_read_from_diskcxx . . $ fil_crypt_stat_t#pages_read_from_disk.++;
1696
1697 const ulonglongcxx . . $ ulonglong# start = my_interval_timer();
1698 block = buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(page_id, zip_size,
1699 RW_X_LATCHcxx . . $ RW_X_LATCH.,
1700 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, BUF_GET_POSSIBLY_FREEDcxx . . $ `storage/innobase/include/buf0buf.h:58:9`!, mtr);
1701 const ulonglongcxx . . $ ulonglong# end = my_interval_timer();
1702
1703 state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited.++;
1704
1705 if (end > start) {
1706 state->sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. += (end - start) / 1000;
1707 }
1708
1709 /* average page load */
1710 ulintcxx . . $ ulint# add_sleeptime_ms = 0;
1711 ulintcxx . . $ ulint# avg_wait_time_us =ulintcxx . . $ ulint#(state->sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. / state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited.);
1712 ulintcxx . . $ ulint# alloc_wait_us = 1000000 / state->allocated_iopscxx . . $ rotate_thread_t#allocated_iops.;
1713
1714 if (avg_wait_time_us < alloc_wait_us) {
1715 /* we reading faster than we allocated */
1716 add_sleeptime_ms = (alloc_wait_us - avg_wait_time_us) / 1000;
1717 } else {
1718 /* if page load time is longer than we want, skip sleeping */
1719 }
1720
1721 *sleeptime_ms += add_sleeptime_ms;
1722
1723 return block;
1724 }
1725
1726 /***********************************************************************
1727 Rotate one page
1728 @param[in,out] key_state Key state
1729 @param[in,out] state Rotation state */
1730 static
1731 void
1732 fil_crypt_rotate_pagecxx . . $ fil_crypt_rotate_page(2037374cd1403d7a).(
1733 const key_state_tcxx . . $ key_state_t#* key_state,
1734 rotate_thread_tcxx . . $ rotate_thread_t#* state)
1735 {
1736 fil_space_tcxx . . $ fil_space_t# *space = &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).state->spacecxx . . $ rotate_thread_t#space.;
1737 ulintcxx . . $ ulint# space_id = space->idcxx . . $ fil_space_t#id.;
1738 uint32_tcxx . . $ uint32_t# offset = state->offsetcxx . . $ rotate_thread_t#offset.;
1739 ulintcxx . . $ ulint# sleeptime_ms = 0;
1740 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
1741
1742 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
1743 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(offset > 0);
1744
1745 /* In fil_crypt_thread where key rotation is done we have
1746 acquired space and checked that this space is not yet
1747 marked to be dropped. Similarly, in fil_crypt_find_page_to_rotate().
1748 Check here also to give DROP TABLE or similar a change. */
1749 if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1750 return;
1751 }
1752
1753 if (space_id == TRX_SYS_SPACEcxx . . $ TRX_SYS_SPACE. && offset == TRX_SYS_PAGE_NOcxx . . $ `storage/innobase/include/trx0types.h:44:9`!) {
1754 /* don't encrypt this as it contains address to dblwr buffer */
1755 return;
1756 }
1757
1758 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
1759 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1760 if (buf_block_tcxx . . $ buf_block_t#* block = fil_crypt_get_page_throttlecxx . . $ fil_crypt_get_page_throttle(87053b988ed431da).(state,
1761 offset, &mtr,
1762 &sleeptime_ms)) {
1763 btr_search_drop_page_hash_indexcxx . . $ btr_search_drop_page_hash_index(33307f3566ecc1a8).(
1764 block, reinterpret_cast<dict_index_tcxx . . $ dict_index_t#*>(-1));
1765 bool modified = false;
1766 bytecxx . . $ byte#* frame = buf_block_get_framecxx . . $ `storage/innobase/include/buf0buf.h:385:9`!(block);
1767 const lsn_tcxx . . $ lsn_t# block_lsn = mach_read_from_8cxx . . $ mach_read_from_8(b191ace3c5bffbd9).(FIL_PAGE_LSNcxx . . $ `storage/innobase/include/fil0fil.h:1213:9`! + frame);
1768 uint kv = buf_page_get_key_versioncxx . . $ buf_page_get_key_version(e74f0a0c57ad6687).(frame, space->flagscxx . . $ fil_space_t#flags.);
1769
1770 if (block->pagecxx . . $ buf_block_t#page..oldest_modificationcxx . . $ buf_page_t#oldest_modification(c9b1e749b64d5edc).() > 1) {
1771 /* Do not unnecessarily touch pages that are
1772 already dirty. */
1773 } else if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1774 /* The tablespace is closing (in DROP TABLE or
1775 TRUNCATE TABLE or similar): avoid further access */
1776 } else if (!kv && !*reinterpret_cast<uint16_tcxx . . $ uint16_t#*>
1777 (&frame[FIL_PAGE_TYPEcxx . . $ `storage/innobase/include/fil0fil.h:1215:9`!])) {
1778 /* It looks like this page is not
1779 allocated. Because key rotation is accessing
1780 pages in a pattern that is unlike the normal
1781 B-tree and undo log access pattern, we cannot
1782 invoke fseg_page_is_allocated() here, because that
1783 could result in a deadlock. If we invoked
1784 fseg_page_is_allocated() and released the
1785 tablespace latch before acquiring block->lock,
1786 then the fseg_page_is_allocated() information
1787 could be stale already. */
1788
1789 /* If the data file was originally created
1790 before MariaDB 10.0 or MySQL 5.6, some
1791 allocated data pages could carry 0 in
1792 FIL_PAGE_TYPE. The FIL_PAGE_TYPE on those
1793 pages will be updated in
1794 buf_flush_init_for_writing() when the page
1795 is modified the next time.
1796
1797 Also, when the doublewrite buffer pages are
1798 allocated on bootstrap in a non-debug build,
1799 some dummy pages will be allocated, with 0 in
1800 the FIL_PAGE_TYPE. Those pages should be
1801 skipped from key rotation forever. */
1802 } else if (fil_crypt_needs_rotationcxx . . $ fil_crypt_needs_rotation(8d74958e750faaf9).(
1803 crypt_data,
1804 kv,
1805 key_state->key_versioncxx . . $ key_state_t#key_version.,
1806 key_state->rotate_key_agecxx . . $ key_state_t#rotate_key_age.)) {
1807
1808 mtr.set_named_spacecxx . . $ mtr_t#set_named_space(932cf7f430860204).(space);
1809 modified = true;
1810
1811 /* force rotation by dummy updating page */
1812 mtr.writecxx . . $ mtr_t#write(4888ddbfa94c5eeb).<1,mtr_tcxx . . $ mtr_t#::FORCEDcxx . . $ mtr_t#FORCED.>(*block,
1813 &frame[FIL_PAGE_SPACE_IDcxx . . $ `storage/innobase/include/fil0fil.h:1247:9`!],
1814 frame[FIL_PAGE_SPACE_IDcxx . . $ `storage/innobase/include/fil0fil.h:1247:9`!]);
1815
1816 /* statistics */
1817 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_modifiedcxx . . $ fil_crypt_stat_t#pages_modified.++;
1818 } else {
1819 if (crypt_data->is_encryptedcxx . . $ fil_space_crypt_t#is_encrypted(50ce9a9e25b4a850).()) {
1820 if (kv < state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found.) {
1821 state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found. = kv;
1822 }
1823 }
1824 }
1825
1826 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1827 lsn_tcxx . . $ lsn_t# end_lsn = mtr.commit_lsncxx . . $ mtr_t#commit_lsn(fe4d2d262d4164a8).();
1828
1829
1830 if (modified) {
1831 /* if we modified page, we take lsn from mtr */
1832 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(end_lsn > state->end_lsn);
1833 ut_acxx . . $ ulint#(end_lsn > block_lsn);
1834 state->end_lsncxx . . $ rotate_thread_t#end_lsn. = end_lsn;
1835 } else {
1836 /* if we did not modify page, check for max lsn */
1837 if (block_lsn > state->end_lsncxx . . $ rotate_thread_t#end_lsn.) {
1838 state->end_lsncxx . . $ rotate_thread_t#end_lsn. = block_lsn;
1839 }
1840 }
1841 } else {
1842 /* If block read failed mtr memo and log should be empty. */
1843 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!mtr.has_modifications());
1844 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr.is_empty());
1845 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1846 }
1847
1848 if (sleeptime_ms) {
1849 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
1850 timespeccxx . . $ timespec# abstime;
1851 set_timespec_nseccxx . . $ time_t#(abstime, 1000000ULL * sleeptime_ms);
1852 my_cond_timedwaitcxx . . $ `include/my_pthread.h:417:9`!(&fil_crypt_throttle_sleep_cond,
1853 &fil_crypt_threads_mutex.m_mutex, &abstime);
1854 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
1855 }
1856 }
1857
1858 /***********************************************************************
1859 Rotate a batch of pages
1860 @param[in,out] key_state Key state
1861 @param[in,out] state Rotation state */
1862 static
1863 void
1864 fil_crypt_rotate_pagescxx . . $ fil_crypt_rotate_pages(2037374cd1403d7a).(
1865 const key_state_tcxx . . $ key_state_t#* key_state,
1866 rotate_thread_tcxx . . $ rotate_thread_t#* state)
1867 {
1868 const uint32_tcxx . . $ uint32_t# space_id = state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).idcxx . . $ fil_space_t#id.;
1869 uint32_tcxx . . $ uint32_t# end = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(state->offsetcxx . . $ rotate_thread_t#offset. + uint32_tcxx . . $ uint32_t#(state->batchcxx . . $ rotate_thread_t#batch.),
1870 state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).free_limitcxx . . $ fil_space_t#free_limit.);
1871
1872 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(state->space->referenced());
1873
1874 for (; state->offsetcxx . . $ rotate_thread_t#offset. < end; state->offsetcxx . . $ rotate_thread_t#offset.++) {
1875
1876 /* we can't rotate pages in dblwr buffer as
1877 * it's not possible to read those due to lots of asserts
1878 * in buffer pool.
1879 *
1880 * However since these are only (short-lived) copies of
1881 * real pages, they will be updated anyway when the
1882 * real page is updated
1883 */
1884 if (buf_dblwrcxx . . $ buf_dblwr..is_insidecxx . . $ buf_dblwr_t#is_inside(deacbfd80cf1a7bf).(page_id_tcxx . . $ page_id_t#(space_id, state->offsetcxx . . $ rotate_thread_t#offset.))) {
1885 continue;
1886 }
1887
1888 /* If space is marked as stopping, stop rotating
1889 pages. */
1890 if (state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1891 break;
1892 }
1893
1894 fil_crypt_rotate_pagecxx . . $ fil_crypt_rotate_page(2037374cd1403d7a).(key_state, state);
1895 }
1896 }
1897
1898 /***********************************************************************
1899 Flush rotated pages and then update page 0
1900
1901 @param[in,out] state rotation state */
1902 static
1903 void
1904 fil_crypt_flush_spacecxx . . $ fil_crypt_flush_space(a7822dfb21d2c8f4).(
1905 rotate_thread_tcxx . . $ rotate_thread_t#* state)
1906 {
1907 fil_space_tcxx . . $ fil_space_t#* space = &*cxx . . $ ilist#Iterator#`operator*`(80ef4fb0f39170b5).state->spacecxx . . $ rotate_thread_t#space.;
1908 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
1909
1910 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
1911
1912 /* flush tablespace pages so that there are no pages left with old key */
1913 lsn_tcxx . . $ lsn_t# end_lsn = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..end_lsncxx . . $ fil_space_rotate_state_t#end_lsn.;
1914
1915 if (end_lsn > 0 && !space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1916 ulintcxx . . $ ulint# sum_pages = 0;
1917 const ulonglongcxx . . $ ulonglong# start = my_interval_timer();
1918 while (buf_flush_list_spacecxx . . $ buf_flush_list_space(11a03951b981ba78).(space, &sum_pages));
1919 if (sum_pages) {
1920 const ulonglongcxx . . $ ulonglong# end = my_interval_timer();
1921
1922 state->cnt_waitedcxx . . $ rotate_thread_t#cnt_waited. += sum_pages;
1923 state->sum_waited_uscxx . . $ rotate_thread_t#sum_waited_us. += (end - start) / 1000;
1924
1925 /* statistics */
1926 state->crypt_statcxx . . $ rotate_thread_t#crypt_stat..pages_flushedcxx . . $ fil_crypt_stat_t#pages_flushed. += sum_pages;
1927 }
1928 }
1929
1930 if (crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. == 0) {
1931 crypt_data->type = CRYPT_SCHEME_UNENCRYPTEDcxx . . $ `storage/innobase/include/fil0crypt.h:62:9`!;
1932 }
1933
1934 if (space->is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1935 return;
1936 }
1937
1938 /* update page 0 */
1939 mtr_tcxx . . $ mtr_t# mtrcxx . . $ mtr_t#mtr_t(a6968fd0d8f26912).{nullptr};
1940 mtr.startcxx . . $ mtr_t#start(49f6e7a06ebc5aa8).();
1941
1942 if (buf_block_tcxx . . $ buf_block_t#* block = buf_page_get_gencxx . . $ buf_page_get_gen(4cc82125c68d4d05).(
1943 page_id_tcxx . . $ page_id_t#(space->idcxx . . $ fil_space_t#id., 0), space->zip_sizecxx . . $ fil_space_t#zip_size(d22c8608b6eae7b5).(),
1944 RW_X_LATCHcxx . . $ RW_X_LATCH., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, BUF_GET_POSSIBLY_FREEDcxx . . $ `storage/innobase/include/buf0buf.h:58:9`!, &mtr)) {
1945 mtr.set_named_spacecxx . . $ mtr_t#set_named_space(932cf7f430860204).(space);
1946 crypt_data->write_page0cxx . . $ fil_space_crypt_t#write_page0(c4796673375b2726).(block, &mtr);
1947 }
1948
1949 mtr.commitcxx . . $ mtr_t#commit(49f6e7a06ebc5aa8).();
1950 }
1951
1952 /***********************************************************************
1953 Complete rotating a space
1954 @param[in,out] state Rotation state */
1955 static void fil_crypt_complete_rotate_spacecxx . . $ fil_crypt_complete_rotate_space(a7822dfb21d2c8f4).(rotate_thread_tcxx . . $ rotate_thread_t#* state)
1956 {
1957 fil_space_crypt_tcxx . . $ fil_space_crypt_t# *crypt_data = state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).crypt_datacxx . . $ fil_space_t#crypt_data.;
1958
1959 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(crypt_data);
1960 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(state->space->referenced());
1961
1962 mysql_mutex_lockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
1963
1964 /* Space might already be dropped */
1965 if (!state->spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
1966 /**
1967 * Update crypt data state with state from thread
1968 */
1969 if (state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found. <
1970 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..min_key_version_foundcxx . . $ fil_space_rotate_state_t#min_key_version_found.) {
1971 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..min_key_version_foundcxx . . $ fil_space_rotate_state_t#min_key_version_found. =
1972 state->min_key_version_foundcxx . . $ rotate_thread_t#min_key_version_found.;
1973 }
1974
1975 if (state->end_lsncxx . . $ rotate_thread_t#end_lsn. > crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..end_lsncxx . . $ fil_space_rotate_state_t#end_lsn.) {
1976 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..end_lsncxx . . $ fil_space_rotate_state_t#end_lsn. = state->end_lsncxx . . $ rotate_thread_t#end_lsn.;
1977 }
1978
1979 ut_acxx . . $ ulint#(crypt_data->rotate_state.active_threads > 0);
1980 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.--;
1981 bool last = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads. == 0;
1982
1983 /**
1984 * check if space is fully done
1985 * this as when threads shutdown, it could be that we "complete"
1986 * iterating before we have scanned the full space.
1987 */
1988 bool done = crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset. >=
1989 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..max_offsetcxx . . $ fil_space_rotate_state_t#max_offset.;
1990
1991 /**
1992 * we should flush space if we're last thread AND
1993 * the iteration is done
1994 */
1995 bool should_flush = last && done;
1996
1997 if (should_flush) {
1998 /* we're the last active thread */
1999 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing. = true;
2000 crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version. =
2001 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..min_key_version_foundcxx . . $ fil_space_rotate_state_t#min_key_version_found.;
2002 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
2003 fil_crypt_flush_spacecxx . . $ fil_crypt_flush_space(a7822dfb21d2c8f4).(state);
2004
2005 mysql_mutex_lockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
2006 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing. = false;
2007 }
2008 } else {
2009 ut_acxx . . $ ulint#(crypt_data->rotate_state.active_threads > 0);
2010 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.--;
2011 }
2012
2013 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
2014 }
2015
2016 #ifdef UNIV_PFS_THREADcxx . . $ `storage/innobase/include/univ.i:71:10`!
2017 mysql_pfs_key_tcxx . . $ mysql_pfs_key_t# page_encrypt_thread_keycxx . . $ page_encrypt_thread_key.;
2018 #endif /* UNIV_PFS_THREAD */
2019
2020 /** A thread which monitors global key state and rotates tablespaces
2021 accordingly */
2022 static void fil_crypt_threadcxx . . $ fil_crypt_thread(49f6e7a06ebc5aa8).()
2023 {
2024 my_thread_init();
2025 #ifdef UNIV_PFS_THREADcxx . . $ `storage/innobase/include/univ.i:71:10`!
2026 pfs_register_threadcxx . . $ `storage/innobase/include/srv0srv.h:398:11`!(page_encrypt_thread_key);
2027 #endif /* UNIV_PFS_THREAD */
2028 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2029 rotate_thread_tcxx . . $ rotate_thread_t# thrcxx . . $ rotate_thread_t#rotate_thread_t(cb2f890c2fdad230).(srv_n_fil_crypt_threads_startedcxx . . $ srv_n_fil_crypt_threads_started.++);
2030 pthread_cond_broadcast(&fil_crypt_condcxx . . $ fil_crypt_cond.);
2031
2032 if (!thr.should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).()) {
2033 /* if we find a tablespace that is starting, skip over it
2034 and recheck it later */
2035 bool recheck = false;
2036
2037 wait_for_work:
2038 if (!recheck && !thr.should_shutdowncxx . . $ rotate_thread_t#should_shutdown(50ce9a9e25b4a850).()) {
2039 /* wait for key state changes
2040 * i.e either new key version of change or
2041 * new rotate_key_age */
2042 my_cond_waitcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_cond,
2043 &fil_crypt_threads_mutex.m_mutex);
2044 }
2045
2046 recheck = false;
2047 thr.firstcxx . . $ rotate_thread_t#first. = true; // restart from first tablespace
2048
2049 key_state_tcxx . . $ key_state_t# new_statecxx . . $ key_state_t#key_state_t(49f6e7a06ebc5aa8).;
2050
2051 /* iterate all spaces searching for those needing rotation */
2052 while (fil_crypt_find_space_to_rotatecxx . . $ fil_crypt_find_space_to_rotate(5fbb71c4b314a772).(&new_state, &thr,
2053 &recheck)) {
2054 if (thr.spacecxx . . $ rotate_thread_t#space. ==cxx . . $ `operator==`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
2055 goto wait_for_work;
2056 }
2057
2058 /* we found a space to rotate */
2059 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
2060 fil_crypt_start_rotate_spacecxx . . $ fil_crypt_start_rotate_space(2037374cd1403d7a).(&new_state, &thr);
2061
2062 /* iterate all pages (cooperativly with other threads) */
2063 while (fil_crypt_find_page_to_rotatecxx . . $ fil_crypt_find_page_to_rotate(51819f7f8d52bd67).(&new_state, &thr)) {
2064
2065 /* If space is marked as stopping, release
2066 space and stop rotation. */
2067 if (thr.spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).is_stoppingcxx . . $ fil_space_t#is_stopping(3482b152b9333168).()) {
2068 fil_crypt_complete_rotate_spacecxx . . $ fil_crypt_complete_rotate_space(a7822dfb21d2c8f4).(&thr);
2069 thr.spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
2070 thr.spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
2071 break;
2072 }
2073
2074 fil_crypt_rotate_pagescxx . . $ fil_crypt_rotate_pages(2037374cd1403d7a).(&new_state, &thr);
2075 /* realloc iops */
2076 if (!fil_crypt_realloc_iopscxx . . $ fil_crypt_realloc_iops(c894e907616a3f9a).(&thr)) {
2077 break;
2078 }
2079 }
2080
2081 /* complete rotation */
2082 if (thr.spacecxx . . $ rotate_thread_t#space. !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
2083 fil_crypt_complete_rotate_spacecxx . . $ fil_crypt_complete_rotate_space(a7822dfb21d2c8f4).(&thr);
2084 }
2085
2086 /* force key state refresh */
2087 new_state.key_idcxx . . $ key_state_t#key_id. = 0;
2088
2089 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
2090 /* release iops */
2091 fil_crypt_return_iopscxx . . $ fil_crypt_return_iops(df68cb7315230dcc).(&thr);
2092 }
2093
2094 if (thr.spacecxx . . $ rotate_thread_t#space. !=cxx . . $ `operator!=`(15200bf62d6bc6bb). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).()) {
2095 thr.spacecxx . . $ rotate_thread_t#space.->cxx . . $ ilist#Iterator#`operator->`(258ee1c9e0a18a5c).releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
2096 thr.spacecxx . . $ rotate_thread_t#space. =cxx . . $ ilist#Iterator#`operator=`(206d77260714dfcd). fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list..endcxx . . $ ilist#end(ad7448b2af519333).();
2097 }
2098 }
2099
2100 fil_crypt_return_iopscxx . . $ fil_crypt_return_iops(df68cb7315230dcc).(&thr);
2101 srv_n_fil_crypt_threads_startedcxx . . $ srv_n_fil_crypt_threads_started.--;
2102 pthread_cond_broadcast(&fil_crypt_condcxx . . $ fil_crypt_cond.);
2103 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
2104
2105 my_thread_end();
2106 #ifdef UNIV_PFS_THREADcxx . . $ `storage/innobase/include/univ.i:71:10`!
2107 pfs_delete_threadcxx . . $ `storage/innobase/include/srv0srv.h:407:11`!();
2108 #endif
2109 }
2110
2111 /*********************************************************************
2112 Adjust thread count for key rotation
2113 @param[in] enw_cnt Number of threads to be used */
2114 void fil_crypt_set_thread_cntcxx . . $ fil_crypt_set_thread_cnt(cb2f890c2fdad230).(const uint new_cnt)
2115 {
2116 if (srv_read_only_modecxx . . $ srv_read_only_mode.)
2117 return;
2118
2119 if (!fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.) {
2120 if (srv_shutdown_statecxx . . $ srv_shutdown_state. != SRV_SHUTDOWN_NONEcxx . . $ SRV_SHUTDOWN_NONE.)
2121 return;
2122 fil_crypt_threads_initcxx . . $ fil_crypt_threads_init(49f6e7a06ebc5aa8).();
2123 }
2124
2125 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2126
2127 if (new_cnt > srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.) {
2128 uint add = new_cnt - srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.;
2129 srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads. = new_cnt;
2130 for (uint i = 0; i < add; i++) {
2131 stdcxx . . $ std/::threadcxx . . $ std/thread# thdcxx . . $ std/thread#thread(33bc091c26643b13).(fil_crypt_threadcxx . . $ fil_crypt_thread(49f6e7a06ebc5aa8).);
2132 ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Creating #"
2133 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). i+1 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " encryption thread id "
2134 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). thd.get_idcxx . . $ std/thread#get_id(9fbd4289b045ee20).()
2135 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " total threads " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). new_cnt <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ".";
2136 thd.detachcxx . . $ std/thread#detach(49f6e7a06ebc5aa8).();
2137 }
2138 } else if (new_cnt < srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.) {
2139 srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads. = new_cnt;
2140 }
2141
2142 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2143
2144 while (srv_n_fil_crypt_threads_startedcxx . . $ srv_n_fil_crypt_threads_started. != srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.) {
2145 my_cond_waitcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_cond,
2146 &fil_crypt_threads_mutex.m_mutex);
2147 }
2148
2149 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2150 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
2151 }
2152
2153 /** Initialize the tablespace default_encrypt_tables
2154 if innodb_encryption_rotate_key_age=0. */
2155 static void fil_crypt_default_encrypt_tables_fillcxx . . $ fil_crypt_default_encrypt_tables_fill(49f6e7a06ebc5aa8).()
2156 {
2157 mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_system.mutex);
2158
2159 for (fil_space_tcxx . . $ fil_space_t#& space : fil_systemcxx . . $ fil_system..space_listcxx . . $ fil_system_t#space_list.) {
2160 if (space.is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt.
2161 || UT_LIST_GET_LENcxx . . $ ut_list_base#count.(space.chain) == 0
2162 || space.is_temporarycxx . . $ fil_space_t#is_temporary(3482b152b9333168).() || space.is_being_importedcxx . . $ fil_space_t#is_being_imported(3482b152b9333168).()
2163 || !space.acquire_if_not_stoppedcxx . . $ fil_space_t#acquire_if_not_stopped(c9857a73d68e59ba).()) {
2164 continue;
2165 }
2166
2167 /* Ensure that crypt_data has been initialized. */
2168 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space.size);
2169
2170 /* Skip ENCRYPTION!=DEFAULT tablespaces. */
2171 if (space.crypt_datacxx . . $ fil_space_t#crypt_data.
2172 && !space.crypt_datacxx . . $ fil_space_t#crypt_data.->is_default_encryptioncxx . . $ fil_space_crypt_t#is_default_encryption(50ce9a9e25b4a850).()) {
2173 goto next;
2174 }
2175
2176 if (srv_encrypt_tablescxx . . $ srv_encrypt_tables.) {
2177 /* Skip encrypted tablespaces if
2178 innodb_encrypt_tables!=OFF */
2179 if (space.crypt_datacxx . . $ fil_space_t#crypt_data.
2180 && space.crypt_datacxx . . $ fil_space_t#crypt_data.->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.) {
2181 goto next;
2182 }
2183 } else {
2184 /* Skip unencrypted tablespaces if
2185 innodb_encrypt_tables=OFF */
2186 if (!space.crypt_datacxx . . $ fil_space_t#crypt_data.
2187 || !space.crypt_datacxx . . $ fil_space_t#crypt_data.->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.) {
2188 goto next;
2189 }
2190 }
2191
2192 fil_systemcxx . . $ fil_system..default_encrypt_tablescxx . . $ fil_system_t#default_encrypt_tables..push_backcxx . . $ ilist#push_back(926f85bfe424ae64).(space);
2193 space.is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt. = true;
2194 next:
2195 space.releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).();
2196 }
2197 }
2198
2199 /*********************************************************************
2200 Adjust max key age
2201 @param[in] val New max key age */
2202 void fil_crypt_set_rotate_key_agecxx . . $ fil_crypt_set_rotate_key_age(cb2f890c2fdad230).(uint val)
2203 {
2204 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
2205 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
2206 srv_fil_crypt_rotate_key_agecxx . . $ srv_fil_crypt_rotate_key_age.= val;
2207 if (val == 0)
2208 fil_crypt_default_encrypt_tables_fillcxx . . $ fil_crypt_default_encrypt_tables_fill(49f6e7a06ebc5aa8).();
2209 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
2210 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2211 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2212 }
2213
2214 /*********************************************************************
2215 Adjust rotation iops
2216 @param[in] val New max roation iops */
2217 void fil_crypt_set_rotation_iopscxx . . $ fil_crypt_set_rotation_iops(cb2f890c2fdad230).(uint val)
2218 {
2219 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2220 srv_n_fil_crypt_iopscxx . . $ srv_n_fil_crypt_iops.= val;
2221 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2222 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
2223 }
2224
2225 /** Add the import tablespace to default_encrypt list
2226 if necessary and signal fil_crypt_threads
2227 @param space imported tablespace */
2228 void fil_crypt_add_imported_spacecxx . . $ fil_crypt_add_imported_space(932cf7f430860204).(fil_space_tcxx . . $ fil_space_t# *space)
2229 {
2230 mysql_mutex_lockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2231
2232 mysql_mutex_lockcxx . . $ fil_system_t#mutex.(&fil_system.mutex);
2233
2234 if (fil_crypt_must_default_encryptcxx . . $ fil_crypt_must_default_encrypt(c9857a73d68e59ba).())
2235 {
2236 fil_systemcxx . . $ fil_system..default_encrypt_tablescxx . . $ fil_system_t#default_encrypt_tables..push_backcxx . . $ ilist#push_back(926f85bfe424ae64).(*space);
2237 space->is_in_default_encryptcxx . . $ fil_space_t#is_in_default_encrypt.= true;
2238 }
2239
2240 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
2241
2242 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2243 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2244 }
2245
2246 /*********************************************************************
2247 Adjust encrypt tables
2248 @param[in] val New setting for innodb-encrypt-tables */
2249 void fil_crypt_set_encrypt_tablescxx . . $ fil_crypt_set_encrypt_tables(2c44cd906ae4e829).(ulong val)
2250 {
2251 if (!fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.)
2252 return;
2253
2254 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
2255
2256 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_system.mutex);
2257 srv_encrypt_tablescxx . . $ srv_encrypt_tables.= val;
2258
2259 if (fil_crypt_must_default_encryptcxx . . $ fil_crypt_must_default_encrypt(c9857a73d68e59ba).())
2260 fil_crypt_default_encrypt_tables_fillcxx . . $ fil_crypt_default_encrypt_tables_fill(49f6e7a06ebc5aa8).();
2261
2262 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_system.mutex);
2263
2264 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2265 mysql_mutex_unlockcxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2266 }
2267
2268 /*********************************************************************
2269 Init threads for key rotation */
2270 void fil_crypt_threads_initcxx . . $ fil_crypt_threads_init(49f6e7a06ebc5aa8).()
2271 {
2272 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!srv_read_only_mode);
2273
2274 if (!fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.) {
2275 pthread_cond_init(&fil_crypt_condcxx . . $ fil_crypt_cond., nullptr);
2276 pthread_cond_init(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond., nullptr);
2277 mysql_mutex_initcxx . . $ fil_crypt_threads_mutex.(0, &fil_crypt_threads_mutex, nullptr);
2278 uint cnt = srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads.;
2279 srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads. = 0;
2280 fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited. = true;
2281 fil_crypt_set_thread_cntcxx . . $ fil_crypt_set_thread_cnt(cb2f890c2fdad230).(cnt);
2282 }
2283 }
2284
2285 /*********************************************************************
2286 Clean up key rotation threads resources */
2287 void fil_crypt_threads_cleanupcxx . . $ fil_crypt_threads_cleanup(49f6e7a06ebc5aa8).()
2288 {
2289 if (!fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.) {
2290 return;
2291 }
2292 ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(!srv_n_fil_crypt_threads_started);
2293 pthread_cond_destroy(&fil_crypt_condcxx . . $ fil_crypt_cond.);
2294 pthread_cond_destroy(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2295 mysql_mutex_destroycxx . . $ fil_crypt_threads_mutex.(&fil_crypt_threads_mutex);
2296 fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited. = false;
2297 }
2298
2299 /*********************************************************************
2300 Wait for crypt threads to stop accessing space
2301 @param[in] space Tablespace */
2302 void fil_space_crypt_close_tablespacecxx . . $ fil_space_crypt_close_tablespace(29fb68a7869e2f7c).(const fil_space_tcxx . . $ fil_space_t# *space)
2303 {
2304 fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.;
2305
2306 if (!crypt_data || srv_n_fil_crypt_threadscxx . . $ srv_n_fil_crypt_threads. == 0
2307 || !fil_crypt_threads_initedcxx . . $ fil_crypt_threads_inited.) {
2308 return;
2309 }
2310
2311 time_tcxx . . $ time_t# start = time(0);
2312 time_tcxx . . $ time_t# last = start;
2313
2314 mysql_mutex_lockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
2315
2316 while (crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.
2317 || crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing.) {
2318 mysql_mutex_unlockcxx . . $ fil_space_crypt_t#mutex.(&crypt_data->mutex);
2319
2320 /* wakeup throttle (all) sleepers */
2321 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&fil_crypt_threads_mutex);
2322 pthread_cond_broadcast(&fil_crypt_throttle_sleep_condcxx . . $ fil_crypt_throttle_sleep_cond.);
2323 pthread_cond_broadcast(&fil_crypt_threads_condcxx . . $ fil_crypt_threads_cond.);
2324 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&fil_crypt_threads_mutex);
2325
2326 stdcxx . . $ std/::this_threadcxx . . $ std/this_thread/::sleep_forcxx . . $ std/this_thread/sleep_for(fb2140da9187dddf).(stdcxx . . $ std/chrono/duration#duration(edcd8b2679e9bd1a).::chronocxx . . $ std/chrono/::millisecondscxx . . $ std/chrono/milliseconds#(20));
2327
2328 time_tcxx . . $ time_t# now = time(0);
2329
2330 if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(now >= last + 30)) {
2331 ibcxx . . $ ib/::warncxx . . $ ib/warn#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Waited "
2332 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). now - start
2333 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " seconds to drop space: "
2334 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). space->chaincxx . . $ fil_space_t#chain..startcxx . . $ ut_list_base#start.->namecxx . . $ fil_node_t#name. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " ("
2335 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). space->idcxx . . $ fil_space_t#id. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ") active threads "
2336 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads.
2337 <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " flushing="
2338 <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ".";
2339 last = now;
2340 }
2341
2342 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
2343 }
2344
2345 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_data->mutex);
2346 }
2347
2348 /*********************************************************************
2349 Get crypt status for a space (used by information_schema)
2350 @param[in] space Tablespace
2351 @param[out] status Crypt status */
2352 void
2353 fil_space_crypt_get_statuscxx . . $ fil_space_crypt_get_status(987eed585136e001).(
2354 const fil_space_tcxx . . $ fil_space_t#* space,
2355 struct fil_space_crypt_status_tcxx . . $ fil_space_crypt_status_t#* status)
2356 {
2357 memset(status, 0, sizeof(*status));
2358
2359 ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->referenced());
2360
2361 /* If there is no crypt data and we have not yet read
2362 page 0 for this tablespace, we need to read it before
2363 we can continue. */
2364 if (!space->crypt_datacxx . . $ fil_space_t#crypt_data.) {
2365 fil_crypt_read_crypt_datacxx . . $ fil_crypt_read_crypt_data(932cf7f430860204).(const_cast<fil_space_tcxx . . $ fil_space_t#*>(space));
2366 }
2367
2368 status->spacecxx . . $ fil_space_crypt_status_t#space. = ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`!;
2369
2370 if (fil_space_crypt_tcxx . . $ fil_space_crypt_t#* crypt_data = space->crypt_datacxx . . $ fil_space_t#crypt_data.) {
2371 status->spacecxx . . $ fil_space_crypt_status_t#space. = space->idcxx . . $ fil_space_t#id.;
2372 mysql_mutex_lockcxx . . $ `include/mysql/psi/mysql_thread.h:360:11`!(&crypt_data->mutex);
2373 status->schemecxx . . $ fil_space_crypt_status_t#scheme. = crypt_data->type;
2374 status->keyserver_requestscxx . . $ fil_space_crypt_status_t#keyserver_requests. = crypt_data->keyserver_requests;
2375 status->min_key_versioncxx . . $ fil_space_crypt_status_t#min_key_version. = crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.;
2376 status->key_idcxx . . $ fil_space_crypt_status_t#key_id. = crypt_data->key_id;
2377
2378 if (crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..active_threadscxx . . $ fil_space_rotate_state_t#active_threads. > 0 ||
2379 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing.) {
2380 status->rotatingcxx . . $ fil_space_crypt_status_t#rotating. = true;
2381 status->flushingcxx . . $ fil_space_crypt_status_t#flushing. =
2382 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..flushingcxx . . $ fil_space_rotate_state_t#flushing.;
2383 status->rotate_next_page_numbercxx . . $ fil_space_crypt_status_t#rotate_next_page_number. =
2384 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..next_offsetcxx . . $ fil_space_rotate_state_t#next_offset.;
2385 status->rotate_max_page_numbercxx . . $ fil_space_crypt_status_t#rotate_max_page_number. =
2386 crypt_data->rotate_statecxx . . $ fil_space_crypt_t#rotate_state..max_offsetcxx . . $ fil_space_rotate_state_t#max_offset.;
2387 }
2388
2389 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_data->mutex);
2390
2391 if (srv_encrypt_tablescxx . . $ srv_encrypt_tables. || crypt_data->min_key_versioncxx . . $ fil_space_crypt_t#min_key_version.) {
2392 status->current_key_versioncxx . . $ fil_space_crypt_status_t#current_key_version. =
2393 fil_crypt_get_latest_key_versioncxx . . $ fil_crypt_get_latest_key_version(346702181f99c4a3).(crypt_data);
2394 }
2395 }
2396 }
2397
2398 /*********************************************************************
2399 Return crypt statistics
2400 @param[out] stat Crypt statistics */
2401 void fil_crypt_total_statcxx . . $ fil_crypt_total_stat(691ac56fea2ba466).(fil_crypt_stat_tcxx . . $ fil_crypt_stat_t# *stat)
2402 {
2403 mysql_mutex_lockcxx . . $ crypt_stat_mutex.(&crypt_stat_mutex);
2404 *stat =cxx . . $ fil_crypt_stat_t#`operator=`(c26c47966808f81a). crypt_statcxx . . $ crypt_stat.;
2405 mysql_mutex_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:391:11`!(&crypt_stat_mutex);
2406 }
2407
2408 #endif /* UNIV_INNOCHECKSUM */
2409
2410 /**
2411 Verify that post encryption checksum match calculated checksum.
2412 This function should be called only if tablespace contains crypt_data
2413 metadata (this is strong indication that tablespace is encrypted).
2414 Function also verifies that traditional checksum does not match
2415 calculated checksum as if it does page could be valid unencrypted,
2416 encrypted, or corrupted.
2417
2418 @param[in,out] page page frame (checksum is temporarily modified)
2419 @param[in] zip_size ROW_FORMAT=COMPRESSED page size, or 0
2420 @return true if page is encrypted AND OK, false otherwise */
2421 bool fil_space_verify_crypt_checksumcxx . . $ fil_space_verify_crypt_checksum(3a706fe4966174d9).(const bytecxx . . $ byte#* page, ulintcxx . . $ ulint# zip_size)
2422 {
2423 if (ENCRYPTION_KEY_NOT_ENCRYPTEDcxx . . $ `include/mysql/service_encryption.h:45:9`! == mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
2424 page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`!)) {
2425 return false;
2426 }
2427
2428 /* Compressed and encrypted pages do not have checksum. Assume not
2429 corrupted. Page verification happens after decompression in
2430 buf_page_t::read_complete() using buf_page_is_corrupted(). */
2431 if (fil_page_get_typecxx . . $ fil_page_get_type(422f7ec86fa2a2fb).(page) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTEDcxx . . $ FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED.) {
2432 return true;
2433 }
2434
2435 /* Read stored post encryption checksum. */
2436 const ib_uint32_tcxx . . $ ib_uint32_t# checksum = mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(
2437 page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSIONcxx . . $ `storage/innobase/include/fil0fil.h:1236:9`! + 4);
2438
2439 /* If stored checksum matches one of the calculated checksums
2440 page is not corrupted. */
2441
2442 #ifndef UNIV_INNOCHECKSUMcxx . . $ `<built-in>:481:9`!
2443 switch (srv_checksum_algorithmcxx . . $ srv_checksum_algorithm.) {
2444 case SRV_CHECKSUM_ALGORITHM_STRICT_FULL_CRC32cxx . . $ SRV_CHECKSUM_ALGORITHM_STRICT_FULL_CRC32.:
2445 case SRV_CHECKSUM_ALGORITHM_STRICT_CRC32cxx . . $ SRV_CHECKSUM_ALGORITHM_STRICT_CRC32.:
2446 #endif /* !UNIV_INNOCHECKSUM */
2447 if (zip_size) {
2448 return checksum == page_zip_calc_checksumcxx . . $ page_zip_calc_checksum(9a0403da8c830ea4).(
2449 page, zip_size, false);
2450 }
2451
2452 return checksum == buf_calc_page_crc32cxx . . $ buf_calc_page_crc32(92865eb9586733e9).(page);
2453 #ifndef UNIV_INNOCHECKSUMcxx . . $ `<built-in>:481:9`!
2454 default:
2455 if (checksum == BUF_NO_CHECKSUM_MAGICcxx . . $ `storage/innobase/include/buf0buf.h:30:9`!) {
2456 return true;
2457 }
2458 if (zip_size) {
2459 return checksum == page_zip_calc_checksumcxx . . $ page_zip_calc_checksum(9a0403da8c830ea4).(
2460 page, zip_size, false)
2461 || checksum == page_zip_calc_checksumcxx . . $ page_zip_calc_checksum(9a0403da8c830ea4).(
2462 page, zip_size, true);
2463 }
2464
2465 return checksum == buf_calc_page_crc32cxx . . $ buf_calc_page_crc32(92865eb9586733e9).(page)
2466 || checksum == buf_calc_page_new_checksumcxx . . $ buf_calc_page_new_checksum(92865eb9586733e9).(page);
2467 }
2468 #endif /* !UNIV_INNOCHECKSUM */
2469 }