MySQL  8.0.18
Source Code Documentation
mysql_file.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /**
24  @file include/mysql/psi/mysql_file.h
25  Instrumentation helpers for mysys file io.
26  This header file provides the necessary declarations
27  to use the mysys file API with the performance schema instrumentation.
28  In some compilers (SunStudio), 'static inline' functions, when declared
29  but not used, are not optimized away (because they are unused) by default,
30  so that including a static inline function from a header file does
31  create unwanted dependencies, causing unresolved symbols at link time.
32  Other compilers, like gcc, optimize these dependencies by default.
33 
34  Since the instrumented APIs declared here are wrapper on top
35  of mysys file io APIs, including mysql/psi/mysql_file.h assumes that
36  the dependency on my_sys already exists.
37 */
38 
39 #ifndef MYSQL_FILE_H
40 #define MYSQL_FILE_H
41 
42 /* For strlen() */
43 #include <string.h>
44 
45 #include "my_dbug.h"
46 /* For MY_STAT */
47 #include "my_dir.h"
48 /* For my_chsize */
49 #include "my_sys.h"
50 #include "mysql/psi/psi_file.h"
52 #include "pfs_file_provider.h"
53 
54 #ifndef PSI_FILE_CALL
55 #define PSI_FILE_CALL(M) psi_file_service->M
56 #endif
57 
58 /**
59  @defgroup psi_api_file File Instrumentation (API)
60  @ingroup psi_api
61  @{
62 */
63 
64 /**
65  @def mysql_file_register(P1, P2, P3)
66  File registration.
67 */
68 #define mysql_file_register(P1, P2, P3) inline_mysql_file_register(P1, P2, P3)
69 
70 /**
71  @def mysql_file_fgets(P1, P2, F)
72  Instrumented fgets.
73  @c mysql_file_fgets is a replacement for @c fgets.
74 */
75 #ifdef HAVE_PSI_FILE_INTERFACE
76 #define mysql_file_fgets(P1, P2, F) \
77  inline_mysql_file_fgets(__FILE__, __LINE__, P1, P2, F)
78 #else
79 #define mysql_file_fgets(P1, P2, F) inline_mysql_file_fgets(P1, P2, F)
80 #endif
81 
82 /**
83  @def mysql_file_fgetc(F)
84  Instrumented fgetc.
85  @c mysql_file_fgetc is a replacement for @c fgetc.
86 */
87 #ifdef HAVE_PSI_FILE_INTERFACE
88 #define mysql_file_fgetc(F) inline_mysql_file_fgetc(__FILE__, __LINE__, F)
89 #else
90 #define mysql_file_fgetc(F) inline_mysql_file_fgetc(F)
91 #endif
92 
93 /**
94  @def mysql_file_fputs(P1, F)
95  Instrumented fputs.
96  @c mysql_file_fputs is a replacement for @c fputs.
97 */
98 #ifdef HAVE_PSI_FILE_INTERFACE
99 #define mysql_file_fputs(P1, F) \
100  inline_mysql_file_fputs(__FILE__, __LINE__, P1, F)
101 #else
102 #define mysql_file_fputs(P1, F) inline_mysql_file_fputs(P1, F)
103 #endif
104 
105 /**
106  @def mysql_file_fputc(P1, F)
107  Instrumented fputc.
108  @c mysql_file_fputc is a replacement for @c fputc.
109 */
110 #ifdef HAVE_PSI_FILE_INTERFACE
111 #define mysql_file_fputc(P1, F) \
112  inline_mysql_file_fputc(__FILE__, __LINE__, P1, F)
113 #else
114 #define mysql_file_fputc(P1, F) inline_mysql_file_fputc(P1, F)
115 #endif
116 
117 /**
118  @def mysql_file_fprintf
119  Instrumented fprintf.
120  @c mysql_file_fprintf is a replacement for @c fprintf.
121 */
122 #define mysql_file_fprintf inline_mysql_file_fprintf
123 
124 /**
125  @def mysql_file_vfprintf(F, P1, P2)
126  Instrumented vfprintf.
127  @c mysql_file_vfprintf is a replacement for @c vfprintf.
128 */
129 #ifdef HAVE_PSI_FILE_INTERFACE
130 #define mysql_file_vfprintf(F, P1, P2) \
131  inline_mysql_file_vfprintf(__FILE__, __LINE__, F, P1, P2)
132 #else
133 #define mysql_file_vfprintf(F, P1, P2) inline_mysql_file_vfprintf(F, P1, P2)
134 #endif
135 
136 /**
137  @def mysql_file_fflush(F, P1, P2)
138  Instrumented fflush.
139  @c mysql_file_fflush is a replacement for @c fflush.
140 */
141 #ifdef HAVE_PSI_FILE_INTERFACE
142 #define mysql_file_fflush(F) inline_mysql_file_fflush(__FILE__, __LINE__, F)
143 #else
144 #define mysql_file_fflush(F) inline_mysql_file_fflush(F)
145 #endif
146 
147 /**
148  @def mysql_file_feof(F)
149  Instrumented feof.
150  @c mysql_file_feof is a replacement for @c feof.
151 */
152 #define mysql_file_feof(F) inline_mysql_file_feof(F)
153 
154 /**
155  @def mysql_file_fstat(FN, S)
156  Instrumented fstat.
157  @c mysql_file_fstat is a replacement for @c my_fstat.
158 */
159 #ifdef HAVE_PSI_FILE_INTERFACE
160 #define mysql_file_fstat(FN, S) \
161  inline_mysql_file_fstat(__FILE__, __LINE__, FN, S)
162 #else
163 #define mysql_file_fstat(FN, S) inline_mysql_file_fstat(FN, S)
164 #endif
165 
166 /**
167  @def mysql_file_stat(K, FN, S, FL)
168  Instrumented stat.
169  @c mysql_file_stat is a replacement for @c my_stat.
170 */
171 #ifdef HAVE_PSI_FILE_INTERFACE
172 #define mysql_file_stat(K, FN, S, FL) \
173  inline_mysql_file_stat(K, __FILE__, __LINE__, FN, S, FL)
174 #else
175 #define mysql_file_stat(K, FN, S, FL) inline_mysql_file_stat(FN, S, FL)
176 #endif
177 
178 /**
179  @def mysql_file_chsize(F, P1, P2, P3)
180  Instrumented chsize.
181  @c mysql_file_chsize is a replacement for @c my_chsize.
182 */
183 #ifdef HAVE_PSI_FILE_INTERFACE
184 #define mysql_file_chsize(F, P1, P2, P3) \
185  inline_mysql_file_chsize(__FILE__, __LINE__, F, P1, P2, P3)
186 #else
187 #define mysql_file_chsize(F, P1, P2, P3) inline_mysql_file_chsize(F, P1, P2, P3)
188 #endif
189 
190 /**
191  @def mysql_file_fopen(K, N, F1, F2)
192  Instrumented fopen.
193  @c mysql_file_fopen is a replacement for @c my_fopen.
194 */
195 #ifdef HAVE_PSI_FILE_INTERFACE
196 #define mysql_file_fopen(K, N, F1, F2) \
197  inline_mysql_file_fopen(K, __FILE__, __LINE__, N, F1, F2)
198 #else
199 #define mysql_file_fopen(K, N, F1, F2) inline_mysql_file_fopen(N, F1, F2)
200 #endif
201 
202 /**
203  @def mysql_file_fclose(FD, FL)
204  Instrumented fclose.
205  @c mysql_file_fclose is a replacement for @c my_fclose.
206  Without the instrumentation, this call will have the same behavior as the
207  undocumented and possibly platform specific my_fclose(NULL, ...) behavior.
208  With the instrumentation, mysql_fclose(NULL, ...) will safely return 0,
209  which is an extension compared to my_fclose and is therefore compliant.
210  mysql_fclose is on purpose *not* implementing
211  @code DBUG_ASSERT(file != NULL) @endcode,
212  since doing so could introduce regressions.
213 */
214 #ifdef HAVE_PSI_FILE_INTERFACE
215 #define mysql_file_fclose(FD, FL) \
216  inline_mysql_file_fclose(__FILE__, __LINE__, FD, FL)
217 #else
218 #define mysql_file_fclose(FD, FL) inline_mysql_file_fclose(FD, FL)
219 #endif
220 
221 /**
222  @def mysql_file_fread(FD, P1, P2, P3)
223  Instrumented fread.
224  @c mysql_file_fread is a replacement for @c my_fread.
225 */
226 #ifdef HAVE_PSI_FILE_INTERFACE
227 #define mysql_file_fread(FD, P1, P2, P3) \
228  inline_mysql_file_fread(__FILE__, __LINE__, FD, P1, P2, P3)
229 #else
230 #define mysql_file_fread(FD, P1, P2, P3) inline_mysql_file_fread(FD, P1, P2, P3)
231 #endif
232 
233 /**
234  @def mysql_file_fwrite(FD, P1, P2, P3)
235  Instrumented fwrite.
236  @c mysql_file_fwrite is a replacement for @c my_fwrite.
237 */
238 #ifdef HAVE_PSI_FILE_INTERFACE
239 #define mysql_file_fwrite(FD, P1, P2, P3) \
240  inline_mysql_file_fwrite(__FILE__, __LINE__, FD, P1, P2, P3)
241 #else
242 #define mysql_file_fwrite(FD, P1, P2, P3) \
243  inline_mysql_file_fwrite(FD, P1, P2, P3)
244 #endif
245 
246 /**
247  @def mysql_file_fseek(FD, P, W)
248  Instrumented fseek.
249  @c mysql_file_fseek is a replacement for @c my_fseek.
250 */
251 #ifdef HAVE_PSI_FILE_INTERFACE
252 #define mysql_file_fseek(FD, P, W) \
253  inline_mysql_file_fseek(__FILE__, __LINE__, FD, P, W)
254 #else
255 #define mysql_file_fseek(FD, P, W) inline_mysql_file_fseek(FD, P, W)
256 #endif
257 
258 /**
259  @def mysql_file_ftell(FD)
260  Instrumented ftell.
261  @c mysql_file_ftell is a replacement for @c my_ftell.
262 */
263 #ifdef HAVE_PSI_FILE_INTERFACE
264 #define mysql_file_ftell(FD) inline_mysql_file_ftell(__FILE__, __LINE__, FD)
265 #else
266 #define mysql_file_ftell(FD) inline_mysql_file_ftell(FD)
267 #endif
268 
269 /**
270  @def mysql_file_create(K, N, F1, F2, F3)
271  Instrumented create.
272  @c mysql_file_create is a replacement for @c my_create.
273 */
274 #ifdef HAVE_PSI_FILE_INTERFACE
275 #define mysql_file_create(K, N, F1, F2, F3) \
276  inline_mysql_file_create(K, __FILE__, __LINE__, N, F1, F2, F3)
277 #else
278 #define mysql_file_create(K, N, F1, F2, F3) \
279  inline_mysql_file_create(N, F1, F2, F3)
280 #endif
281 
282 /**
283  @def mysql_file_create_temp(K, T, D, P, M, U, F)
284  Instrumented create_temp_file.
285  @c mysql_file_create_temp is a replacement for @c create_temp_file.
286 */
287 #ifdef HAVE_PSI_FILE_INTERFACE
288 #define mysql_file_create_temp(K, T, D, P, M, U, F) \
289  inline_mysql_file_create_temp(K, __FILE__, __LINE__, T, D, P, M, U, F)
290 #else
291 #define mysql_file_create_temp(K, T, D, P, M, U, F) \
292  inline_mysql_file_create_temp(T, D, P, M, U, F)
293 #endif
294 
295 /**
296  @def mysql_file_open(K, N, F1, F2)
297  Instrumented open.
298  @c mysql_file_open is a replacement for @c my_open.
299 */
300 #ifdef HAVE_PSI_FILE_INTERFACE
301 #define mysql_file_open(K, N, F1, F2) \
302  inline_mysql_file_open(K, __FILE__, __LINE__, N, F1, F2)
303 #else
304 #define mysql_file_open(K, N, F1, F2) inline_mysql_file_open(N, F1, F2)
305 #endif
306 
307 /**
308  @def mysql_file_close(FD, F)
309  Instrumented close.
310  @c mysql_file_close is a replacement for @c my_close.
311 */
312 #ifdef HAVE_PSI_FILE_INTERFACE
313 #define mysql_file_close(FD, F) \
314  inline_mysql_file_close(__FILE__, __LINE__, FD, F)
315 #else
316 #define mysql_file_close(FD, F) inline_mysql_file_close(FD, F)
317 #endif
318 
319 /**
320  @def mysql_file_read(FD, B, S, F)
321  Instrumented read.
322  @c mysql_read is a replacement for @c my_read.
323 */
324 #ifdef HAVE_PSI_FILE_INTERFACE
325 #define mysql_file_read(FD, B, S, F) \
326  inline_mysql_file_read(__FILE__, __LINE__, FD, B, S, F)
327 #else
328 #define mysql_file_read(FD, B, S, F) inline_mysql_file_read(FD, B, S, F)
329 #endif
330 
331 /**
332  @def mysql_file_write(FD, B, S, F)
333  Instrumented write.
334  @c mysql_file_write is a replacement for @c my_write.
335 */
336 #ifdef HAVE_PSI_FILE_INTERFACE
337 #define mysql_file_write(FD, B, S, F) \
338  inline_mysql_file_write(__FILE__, __LINE__, FD, B, S, F)
339 #else
340 #define mysql_file_write(FD, B, S, F) inline_mysql_file_write(FD, B, S, F)
341 #endif
342 
343 /**
344  @def mysql_file_pread(FD, B, S, O, F)
345  Instrumented pread.
346  @c mysql_pread is a replacement for @c my_pread.
347 */
348 #ifdef HAVE_PSI_FILE_INTERFACE
349 #define mysql_file_pread(FD, B, S, O, F) \
350  inline_mysql_file_pread(__FILE__, __LINE__, FD, B, S, O, F)
351 #else
352 #define mysql_file_pread(FD, B, S, O, F) inline_mysql_file_pread(FD, B, S, O, F)
353 #endif
354 
355 /**
356  @def mysql_file_pwrite(FD, B, S, O, F)
357  Instrumented pwrite.
358  @c mysql_file_pwrite is a replacement for @c my_pwrite.
359 */
360 #ifdef HAVE_PSI_FILE_INTERFACE
361 #define mysql_file_pwrite(FD, B, S, O, F) \
362  inline_mysql_file_pwrite(__FILE__, __LINE__, FD, B, S, O, F)
363 #else
364 #define mysql_file_pwrite(FD, B, S, O, F) \
365  inline_mysql_file_pwrite(FD, B, S, O, F)
366 #endif
367 
368 /**
369  @def mysql_file_seek(FD, P, W, F)
370  Instrumented seek.
371  @c mysql_file_seek is a replacement for @c my_seek.
372 */
373 #ifdef HAVE_PSI_FILE_INTERFACE
374 #define mysql_file_seek(FD, P, W, F) \
375  inline_mysql_file_seek(__FILE__, __LINE__, FD, P, W, F)
376 #else
377 #define mysql_file_seek(FD, P, W, F) inline_mysql_file_seek(FD, P, W, F)
378 #endif
379 
380 /**
381  @def mysql_file_tell(FD, F)
382  Instrumented tell.
383  @c mysql_file_tell is a replacement for @c my_tell.
384 */
385 #ifdef HAVE_PSI_FILE_INTERFACE
386 #define mysql_file_tell(FD, F) inline_mysql_file_tell(__FILE__, __LINE__, FD, F)
387 #else
388 #define mysql_file_tell(FD, F) inline_mysql_file_tell(FD, F)
389 #endif
390 
391 /**
392  @def mysql_file_delete(K, P1, P2)
393  Instrumented delete.
394  @c mysql_file_delete is a replacement for @c my_delete.
395 */
396 #ifdef HAVE_PSI_FILE_INTERFACE
397 #define mysql_file_delete(K, P1, P2) \
398  inline_mysql_file_delete(K, __FILE__, __LINE__, P1, P2)
399 #else
400 #define mysql_file_delete(K, P1, P2) inline_mysql_file_delete(P1, P2)
401 #endif
402 
403 /**
404  @def mysql_file_rename(K, P1, P2, P3)
405  Instrumented rename.
406  @c mysql_file_rename is a replacement for @c my_rename.
407 */
408 #ifdef HAVE_PSI_FILE_INTERFACE
409 #define mysql_file_rename(K, P1, P2, P3) \
410  inline_mysql_file_rename(K, __FILE__, __LINE__, P1, P2, P3)
411 #else
412 #define mysql_file_rename(K, P1, P2, P3) inline_mysql_file_rename(P1, P2, P3)
413 #endif
414 
415 /**
416  @def mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5)
417  Instrumented create with symbolic link.
418  @c mysql_file_create_with_symlink is a replacement
419  for @c my_create_with_symlink.
420 */
421 #ifdef HAVE_PSI_FILE_INTERFACE
422 #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \
423  inline_mysql_file_create_with_symlink(K, __FILE__, __LINE__, P1, P2, P3, P4, \
424  P5)
425 #else
426 #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \
427  inline_mysql_file_create_with_symlink(P1, P2, P3, P4, P5)
428 #endif
429 
430 /**
431  @def mysql_file_delete_with_symlink(K, P1, P2)
432  Instrumented delete with symbolic link.
433  @c mysql_file_delete_with_symlink is a replacement
434  for @c my_delete_with_symlink.
435 */
436 #ifdef HAVE_PSI_FILE_INTERFACE
437 #define mysql_file_delete_with_symlink(K, P1, P2) \
438  inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2)
439 #else
440 #define mysql_file_delete_with_symlink(K, P1, P2) \
441  inline_mysql_file_delete_with_symlink(P1, P2)
442 #endif
443 
444 /**
445  @def mysql_file_rename_with_symlink(K, P1, P2, P3)
446  Instrumented rename with symbolic link.
447  @c mysql_file_rename_with_symlink is a replacement
448  for @c my_rename_with_symlink.
449 */
450 #ifdef HAVE_PSI_FILE_INTERFACE
451 #define mysql_file_rename_with_symlink(K, P1, P2, P3) \
452  inline_mysql_file_rename_with_symlink(K, __FILE__, __LINE__, P1, P2, P3)
453 #else
454 #define mysql_file_rename_with_symlink(K, P1, P2, P3) \
455  inline_mysql_file_rename_with_symlink(P1, P2, P3)
456 #endif
457 
458 /**
459  @def mysql_file_sync(P1, P2)
460  Instrumented file sync.
461  @c mysql_file_sync is a replacement for @c my_sync.
462 */
463 #ifdef HAVE_PSI_FILE_INTERFACE
464 #define mysql_file_sync(P1, P2) \
465  inline_mysql_file_sync(__FILE__, __LINE__, P1, P2)
466 #else
467 #define mysql_file_sync(P1, P2) inline_mysql_file_sync(P1, P2)
468 #endif
469 
470 /**
471  An instrumented FILE structure.
472  @c MYSQL_FILE is a drop-in replacement for @c FILE.
473  @sa mysql_file_open
474 */
475 struct MYSQL_FILE {
476  /** The real file. */
478  /**
479  The instrumentation hook.
480  Note that this hook is not conditionally defined,
481  for binary compatibility of the @c MYSQL_FILE interface.
482  */
483  struct PSI_file *m_psi;
484 };
485 
486 static inline void inline_mysql_file_register(
488  const char *category, PSI_file_info *info, int count
489 #else
490  const char *category MY_ATTRIBUTE((unused)),
491  void *info MY_ATTRIBUTE((unused)), int count MY_ATTRIBUTE((unused))
492 #endif
493 ) {
494 #ifdef HAVE_PSI_FILE_INTERFACE
495  PSI_FILE_CALL(register_file)(category, info, count);
496 #endif
497 }
498 
499 static inline char *inline_mysql_file_fgets(
501  const char *src_file, uint src_line,
502 #endif
503  char *str, int size, MYSQL_FILE *file) {
504  char *result;
505 #ifdef HAVE_PSI_FILE_INTERFACE
506  struct PSI_file_locker *locker;
507  PSI_file_locker_state state;
508  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
509  PSI_FILE_READ);
510  if (likely(locker != NULL)) {
511  PSI_FILE_CALL(start_file_wait)(locker, (size_t)size, src_file, src_line);
512  result = fgets(str, size, file->m_file);
513  PSI_FILE_CALL(end_file_wait)(locker, result ? strlen(result) : 0);
514  return result;
515  }
516 #endif
517 
518  result = fgets(str, size, file->m_file);
519  return result;
520 }
521 
522 static inline int inline_mysql_file_fgetc(
524  const char *src_file, uint src_line,
525 #endif
526  MYSQL_FILE *file) {
527  int result;
528 #ifdef HAVE_PSI_FILE_INTERFACE
529  struct PSI_file_locker *locker;
530  PSI_file_locker_state state;
531  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
532  PSI_FILE_READ);
533  if (likely(locker != NULL)) {
534  PSI_FILE_CALL(start_file_wait)(locker, (size_t)1, src_file, src_line);
535  result = fgetc(file->m_file);
536  PSI_FILE_CALL(end_file_wait)(locker, (size_t)1);
537  return result;
538  }
539 #endif
540 
541  result = fgetc(file->m_file);
542  return result;
543 }
544 
545 static inline int inline_mysql_file_fputs(
547  const char *src_file, uint src_line,
548 #endif
549  const char *str, MYSQL_FILE *file) {
550  int result;
551 #ifdef HAVE_PSI_FILE_INTERFACE
552  struct PSI_file_locker *locker;
553  PSI_file_locker_state state;
554  size_t bytes;
555  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
557  if (likely(locker != NULL)) {
558  bytes = str ? strlen(str) : 0;
559  PSI_FILE_CALL(start_file_wait)(locker, bytes, src_file, src_line);
560  result = fputs(str, file->m_file);
561  PSI_FILE_CALL(end_file_wait)(locker, bytes);
562  return result;
563  }
564 #endif
565 
566  result = fputs(str, file->m_file);
567  return result;
568 }
569 
570 static inline int inline_mysql_file_fputc(
572  const char *src_file, uint src_line,
573 #endif
574  char c, MYSQL_FILE *file) {
575  int result;
576 #ifdef HAVE_PSI_FILE_INTERFACE
577  struct PSI_file_locker *locker;
578  PSI_file_locker_state state;
579  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
581  if (likely(locker != NULL)) {
582  PSI_FILE_CALL(start_file_wait)(locker, (size_t)1, src_file, src_line);
583  result = fputc(c, file->m_file);
584  PSI_FILE_CALL(end_file_wait)(locker, (size_t)1);
585  return result;
586  }
587 #endif
588 
589  result = fputc(c, file->m_file);
590  return result;
591 }
592 
593 static inline int inline_mysql_file_fprintf(MYSQL_FILE *file,
594  const char *format, ...)
595  MY_ATTRIBUTE((format(printf, 2, 3)));
596 
597 static inline int inline_mysql_file_fprintf(MYSQL_FILE *file,
598  const char *format, ...) {
599  /*
600  TODO: figure out how to pass src_file and src_line from the caller.
601  */
602  int result;
603  va_list args;
604 #ifdef HAVE_PSI_FILE_INTERFACE
605  struct PSI_file_locker *locker;
606  PSI_file_locker_state state;
607  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
609  if (likely(locker != NULL)) {
610  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, __FILE__, __LINE__);
611  va_start(args, format);
612  result = vfprintf(file->m_file, format, args);
613  va_end(args);
614  PSI_FILE_CALL(end_file_wait)(locker, (size_t)result);
615  return result;
616  }
617 #endif
618 
619  va_start(args, format);
620  result = vfprintf(file->m_file, format, args);
621  va_end(args);
622  return result;
623 }
624 
625 static inline int inline_mysql_file_vfprintf(
627  const char *src_file, uint src_line,
628 #endif
629  MYSQL_FILE *file, const char *format, va_list args)
630 #ifdef HAVE_PSI_FILE_INTERFACE
631  MY_ATTRIBUTE((format(printf, 4, 0)));
632 #else
633  MY_ATTRIBUTE((format(printf, 2, 0)));
634 #endif
635 
636 static inline int inline_mysql_file_vfprintf(
638  const char *src_file, uint src_line,
639 #endif
640  MYSQL_FILE *file, const char *format, va_list args) {
641  int result;
642 #ifdef HAVE_PSI_FILE_INTERFACE
643  struct PSI_file_locker *locker;
644  PSI_file_locker_state state;
645  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
647  if (likely(locker != NULL)) {
648  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
649  result = vfprintf(file->m_file, format, args);
650  PSI_FILE_CALL(end_file_wait)(locker, (size_t)result);
651  return result;
652  }
653 #endif
654 
655  result = vfprintf(file->m_file, format, args);
656  return result;
657 }
658 
659 static inline int inline_mysql_file_fflush(
661  const char *src_file, uint src_line,
662 #endif
663  MYSQL_FILE *file) {
664  int result;
665 #ifdef HAVE_PSI_FILE_INTERFACE
666  struct PSI_file_locker *locker;
667  PSI_file_locker_state state;
668  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
670  if (likely(locker != NULL)) {
671  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
672  result = fflush(file->m_file);
673  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
674  return result;
675  }
676 #endif
677 
678  result = fflush(file->m_file);
679  return result;
680 }
681 
682 static inline int inline_mysql_file_feof(MYSQL_FILE *file) {
683  /* Not instrumented, there is no wait involved */
684  return feof(file->m_file);
685 }
686 
687 static inline int inline_mysql_file_fstat(
689  const char *src_file, uint src_line,
690 #endif
691  int filenr, MY_STAT *stat_area) {
692  int result;
693 #ifdef HAVE_PSI_FILE_INTERFACE
694  struct PSI_file_locker *locker;
695  PSI_file_locker_state state;
696  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, filenr,
698  if (likely(locker != NULL)) {
699  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
700  result = my_fstat(filenr, stat_area);
701  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
702  return result;
703  }
704 #endif
705 
706  result = my_fstat(filenr, stat_area);
707  return result;
708 }
709 
712  PSI_file_key key, const char *src_file, uint src_line,
713 #endif
714  const char *path, MY_STAT *stat_area, myf flags) {
715  MY_STAT *result;
716 #ifdef HAVE_PSI_FILE_INTERFACE
717  struct PSI_file_locker *locker;
718  PSI_file_locker_state state;
719  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
720  &state, key, PSI_FILE_STAT, path, &locker);
721  if (likely(locker != NULL)) {
722  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
723  result = my_stat(path, stat_area, flags);
724  PSI_FILE_CALL(end_file_open_wait)(locker, result);
725  return result;
726  }
727 #endif
728 
729  result = my_stat(path, stat_area, flags);
730  return result;
731 }
732 
733 static inline int inline_mysql_file_chsize(
735  const char *src_file, uint src_line,
736 #endif
737  File file, my_off_t newlength, int filler, myf flags) {
738  int result;
739 #ifdef HAVE_PSI_FILE_INTERFACE
740  struct PSI_file_locker *locker;
741  PSI_file_locker_state state;
742  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
744  if (likely(locker != NULL)) {
745  PSI_FILE_CALL(start_file_wait)
746  (locker, (size_t)newlength, src_file, src_line);
747  result = my_chsize(file, newlength, filler, flags);
748  PSI_FILE_CALL(end_file_wait)(locker, (size_t)newlength);
749  return result;
750  }
751 #endif
752 
753  result = my_chsize(file, newlength, filler, flags);
754  return result;
755 }
756 
759  PSI_file_key key, const char *src_file, uint src_line,
760 #endif
761  const char *filename, int flags, myf myFlags) {
762  MYSQL_FILE *that;
764  MYF(MY_WME));
765  if (likely(that != NULL)) {
766 #ifdef HAVE_PSI_FILE_INTERFACE
767  struct PSI_file_locker *locker;
768  PSI_file_locker_state state;
769  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
770  &state, key, PSI_FILE_STREAM_OPEN, filename, that);
771  if (likely(locker != NULL)) {
772  PSI_FILE_CALL(start_file_open_wait)
773  (locker, src_file, src_line);
774  that->m_file = my_fopen(filename, flags, myFlags);
775  that->m_psi = PSI_FILE_CALL(end_file_open_wait)(locker, that->m_file);
776  if (unlikely(that->m_file == NULL)) {
777  my_free(that);
778  return NULL;
779  }
780  return that;
781  }
782 #endif
783 
784  that->m_psi = NULL;
785  that->m_file = my_fopen(filename, flags, myFlags);
786  if (unlikely(that->m_file == NULL)) {
787  my_free(that);
788  return NULL;
789  }
790  }
791  return that;
792 }
793 
794 static inline int inline_mysql_file_fclose(
796  const char *src_file, uint src_line,
797 #endif
798  MYSQL_FILE *file, myf flags) {
799  int result = 0;
800  if (likely(file != NULL)) {
801 #ifdef HAVE_PSI_FILE_INTERFACE
802  struct PSI_file_locker *locker;
803  PSI_file_locker_state state;
804  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(
805  &state, file->m_psi, PSI_FILE_STREAM_CLOSE);
806  if (likely(locker != NULL)) {
807  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
808  result = my_fclose(file->m_file, flags);
809  PSI_FILE_CALL(end_file_close_wait)(locker, result);
810  my_free(file);
811  return result;
812  }
813 #endif
814 
815  result = my_fclose(file->m_file, flags);
816  my_free(file);
817  }
818  return result;
819 }
820 
821 static inline size_t inline_mysql_file_fread(
823  const char *src_file, uint src_line,
824 #endif
825  MYSQL_FILE *file, uchar *buffer, size_t count, myf flags) {
826  size_t result;
827 #ifdef HAVE_PSI_FILE_INTERFACE
828  struct PSI_file_locker *locker;
829  PSI_file_locker_state state;
830  size_t bytes_read;
831  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
832  PSI_FILE_READ);
833  if (likely(locker != NULL)) {
834  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
835  result = my_fread(file->m_file, buffer, count, flags);
836  if (flags & (MY_NABP | MY_FNABP)) {
837  bytes_read = (result == 0) ? count : 0;
838  } else {
839  bytes_read = (result != MY_FILE_ERROR) ? result : 0;
840  }
841  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
842  return result;
843  }
844 #endif
845 
846  result = my_fread(file->m_file, buffer, count, flags);
847  return result;
848 }
849 
850 static inline size_t inline_mysql_file_fwrite(
852  const char *src_file, uint src_line,
853 #endif
854  MYSQL_FILE *file, const uchar *buffer, size_t count, myf flags) {
855  size_t result;
856 #ifdef HAVE_PSI_FILE_INTERFACE
857  struct PSI_file_locker *locker;
858  PSI_file_locker_state state;
859  size_t bytes_written;
860  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
862  if (likely(locker != NULL)) {
863  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
864  result = my_fwrite(file->m_file, buffer, count, flags);
865  if (flags & (MY_NABP | MY_FNABP)) {
866  bytes_written = (result == 0) ? count : 0;
867  } else {
868  bytes_written = (result != MY_FILE_ERROR) ? result : 0;
869  }
870  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
871  return result;
872  }
873 #endif
874 
875  result = my_fwrite(file->m_file, buffer, count, flags);
876  return result;
877 }
878 
881  const char *src_file, uint src_line,
882 #endif
883  MYSQL_FILE *file, my_off_t pos, int whence) {
885 #ifdef HAVE_PSI_FILE_INTERFACE
886  struct PSI_file_locker *locker;
887  PSI_file_locker_state state;
888  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
889  PSI_FILE_SEEK);
890  if (likely(locker != NULL)) {
891  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
892  result = my_fseek(file->m_file, pos, whence);
893  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
894  return result;
895  }
896 #endif
897 
898  result = my_fseek(file->m_file, pos, whence);
899  return result;
900 }
901 
904  const char *src_file, uint src_line,
905 #endif
906  MYSQL_FILE *file) {
908 #ifdef HAVE_PSI_FILE_INTERFACE
909  struct PSI_file_locker *locker;
910  PSI_file_locker_state state;
911  locker = PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi,
912  PSI_FILE_TELL);
913  if (likely(locker != NULL)) {
914  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
915  result = my_ftell(file->m_file);
916  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
917  return result;
918  }
919 #endif
920 
921  result = my_ftell(file->m_file);
922  return result;
923 }
924 
927  PSI_file_key key, const char *src_file, uint src_line,
928 #endif
929  const char *filename, int create_flags, int access_flags, myf myFlags) {
930  File file;
931 #ifdef HAVE_PSI_FILE_INTERFACE
932  struct PSI_file_locker *locker;
933  PSI_file_locker_state state;
934  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
935  &state, key, PSI_FILE_CREATE, filename, &locker);
936  if (likely(locker != NULL)) {
937  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
938  file = my_create(filename, create_flags, access_flags, myFlags);
939  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
940  return file;
941  }
942 #endif
943 
944  file = my_create(filename, create_flags, access_flags, myFlags);
945  return file;
946 }
947 
950  PSI_file_key key, const char *src_file, uint src_line,
951 #endif
952  char *to, const char *dir, const char *pfx, int mode,
953  UnlinkOrKeepFile unlink_or_keep, myf myFlags) {
954  File file;
955 #ifdef HAVE_PSI_FILE_INTERFACE
956  struct PSI_file_locker *locker;
957  PSI_file_locker_state state;
958  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
959  &state, key, PSI_FILE_CREATE, NULL, &locker);
960  if (likely(locker != NULL)) {
961  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
962  /* The file name is generated by create_temp_file(). */
963  file = create_temp_file(to, dir, pfx, mode, unlink_or_keep, myFlags);
964  PSI_FILE_CALL(end_temp_file_open_wait_and_bind_to_descriptor)
965  (locker, file, (const char *)to);
966  return file;
967  }
968 #endif
969 
970  file = create_temp_file(to, dir, pfx, mode, unlink_or_keep, myFlags);
971  return file;
972 }
973 
976  PSI_file_key key, const char *src_file, uint src_line,
977 #endif
978  const char *filename, int flags, myf myFlags) {
979  File file;
980 #ifdef HAVE_PSI_FILE_INTERFACE
981  struct PSI_file_locker *locker;
982  PSI_file_locker_state state;
983  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
984  &state, key, PSI_FILE_OPEN, filename, &locker);
985  if (likely(locker != NULL)) {
986  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
987  file = my_open(filename, flags, myFlags);
988  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
989  return file;
990  }
991 #endif
992 
993  file = my_open(filename, flags, myFlags);
994  return file;
995 }
996 
997 static inline int inline_mysql_file_close(
999  const char *src_file, uint src_line,
1000 #endif
1001  File file, myf flags) {
1002  int result;
1003 #ifdef HAVE_PSI_FILE_INTERFACE
1004  struct PSI_file_locker *locker;
1005  PSI_file_locker_state state;
1006  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1007  PSI_FILE_CLOSE);
1008  if (likely(locker != NULL)) {
1009  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1010  result = my_close(file, flags);
1011  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1012  return result;
1013  }
1014 #endif
1015 
1016  result = my_close(file, flags);
1017  return result;
1018 }
1019 
1020 static inline size_t inline_mysql_file_read(
1022  const char *src_file, uint src_line,
1023 #endif
1024  File file, uchar *buffer, size_t count, myf flags) {
1025  size_t result;
1026 #ifdef HAVE_PSI_FILE_INTERFACE
1027  struct PSI_file_locker *locker;
1028  PSI_file_locker_state state;
1029  size_t bytes_read;
1030  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1031  PSI_FILE_READ);
1032  if (likely(locker != NULL)) {
1033  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1034  result = my_read(file, buffer, count, flags);
1035  if (flags & (MY_NABP | MY_FNABP)) {
1036  bytes_read = (result == 0) ? count : 0;
1037  } else {
1038  bytes_read = (result != MY_FILE_ERROR) ? result : 0;
1039  }
1040  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1041  return result;
1042  }
1043 #endif
1044 
1045  result = my_read(file, buffer, count, flags);
1046  return result;
1047 }
1048 
1049 static inline size_t inline_mysql_file_write(
1051  const char *src_file, uint src_line,
1052 #endif
1053  File file, const uchar *buffer, size_t count, myf flags) {
1054  size_t result;
1055 #ifdef HAVE_PSI_FILE_INTERFACE
1056  struct PSI_file_locker *locker;
1057  PSI_file_locker_state state;
1058  size_t bytes_written;
1059  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1060  PSI_FILE_WRITE);
1061  if (likely(locker != NULL)) {
1062  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1063  result = my_write(file, buffer, count, flags);
1064  if (flags & (MY_NABP | MY_FNABP)) {
1065  bytes_written = (result == 0) ? count : 0;
1066  } else {
1067  bytes_written = (result != MY_FILE_ERROR) ? result : 0;
1068  }
1069  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1070  return result;
1071  }
1072 #endif
1073 
1074  result = my_write(file, buffer, count, flags);
1075  return result;
1076 }
1077 
1078 static inline size_t inline_mysql_file_pread(
1080  const char *src_file, uint src_line,
1081 #endif
1082  File file, uchar *buffer, size_t count, my_off_t offset, myf flags) {
1083  size_t result;
1084 #ifdef HAVE_PSI_FILE_INTERFACE
1085  struct PSI_file_locker *locker;
1086  PSI_file_locker_state state;
1087  size_t bytes_read;
1088  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1089  PSI_FILE_READ);
1090  if (likely(locker != NULL)) {
1091  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1092  result = my_pread(file, buffer, count, offset, flags);
1093  if (flags & (MY_NABP | MY_FNABP)) {
1094  bytes_read = (result == 0) ? count : 0;
1095  } else {
1096  bytes_read = (result != MY_FILE_ERROR) ? result : 0;
1097  }
1098  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1099  return result;
1100  }
1101 #endif
1102 
1103  result = my_pread(file, buffer, count, offset, flags);
1104  return result;
1105 }
1106 
1107 static inline size_t inline_mysql_file_pwrite(
1109  const char *src_file, uint src_line,
1110 #endif
1111  File file, const uchar *buffer, size_t count, my_off_t offset, myf flags) {
1112  size_t result;
1113 #ifdef HAVE_PSI_FILE_INTERFACE
1114  struct PSI_file_locker *locker;
1115  PSI_file_locker_state state;
1116  size_t bytes_written;
1117  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1118  PSI_FILE_WRITE);
1119  if (likely(locker != NULL)) {
1120  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1121  result = my_pwrite(file, buffer, count, offset, flags);
1122  if (flags & (MY_NABP | MY_FNABP)) {
1123  bytes_written = (result == 0) ? count : 0;
1124  } else {
1125  bytes_written = (result != MY_FILE_ERROR) ? result : 0;
1126  }
1127  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1128  return result;
1129  }
1130 #endif
1131 
1132  result = my_pwrite(file, buffer, count, offset, flags);
1133  return result;
1134 }
1135 
1138  const char *src_file, uint src_line,
1139 #endif
1140  File file, my_off_t pos, int whence, myf flags) {
1141  my_off_t result;
1142 #ifdef HAVE_PSI_FILE_INTERFACE
1143  struct PSI_file_locker *locker;
1144  PSI_file_locker_state state;
1145  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1146  PSI_FILE_SEEK);
1147  if (likely(locker != NULL)) {
1148  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1149  result = my_seek(file, pos, whence, flags);
1150  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1151  return result;
1152  }
1153 #endif
1154 
1155  result = my_seek(file, pos, whence, flags);
1156  return result;
1157 }
1158 
1161  const char *src_file, uint src_line,
1162 #endif
1163  File file, myf flags) {
1164  my_off_t result;
1165 #ifdef HAVE_PSI_FILE_INTERFACE
1166  struct PSI_file_locker *locker;
1167  PSI_file_locker_state state;
1168  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1169  PSI_FILE_TELL);
1170  if (likely(locker != NULL)) {
1171  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1172  result = my_tell(file, flags);
1173  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1174  return result;
1175  }
1176 #endif
1177 
1178  result = my_tell(file, flags);
1179  return result;
1180 }
1181 
1182 static inline int inline_mysql_file_delete(
1184  PSI_file_key key, const char *src_file, uint src_line,
1185 #endif
1186  const char *name, myf flags) {
1187  int result;
1188 #ifdef HAVE_PSI_FILE_INTERFACE
1189  struct PSI_file_locker *locker;
1190  PSI_file_locker_state state;
1191  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1192  &state, key, PSI_FILE_DELETE, name, &locker);
1193  if (likely(locker != NULL)) {
1194  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1195  result = my_delete(name, flags);
1196  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1197  return result;
1198  }
1199 #endif
1200 
1201  result = my_delete(name, flags);
1202  return result;
1203 }
1204 
1205 static inline int inline_mysql_file_rename(
1207  PSI_file_key key, const char *src_file, uint src_line,
1208 #endif
1209  const char *from, const char *to, myf flags) {
1210  int result;
1211 #ifdef HAVE_PSI_FILE_INTERFACE
1212  struct PSI_file_locker *locker;
1213  PSI_file_locker_state state;
1214  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1215  &state, key, PSI_FILE_RENAME, from, &locker);
1216  if (likely(locker != NULL)) {
1217  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1218  result = my_rename(from, to, flags);
1219  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result);
1220  return result;
1221  }
1222 #endif
1223 
1224  result = my_rename(from, to, flags);
1225  return result;
1226 }
1227 
1230  PSI_file_key key, const char *src_file, uint src_line,
1231 #endif
1232  const char *linkname, const char *filename, int create_flags,
1233  int access_flags, myf flags) {
1234  File file;
1235 #ifdef HAVE_PSI_FILE_INTERFACE
1236  struct PSI_file_locker *locker;
1237  PSI_file_locker_state state;
1238  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1239  &state, key, PSI_FILE_CREATE, filename, &locker);
1240  if (likely(locker != NULL)) {
1241  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
1242  file = my_create_with_symlink(linkname, filename, create_flags,
1243  access_flags, flags);
1244  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
1245  return file;
1246  }
1247 #endif
1248 
1249  file = my_create_with_symlink(linkname, filename, create_flags, access_flags,
1250  flags);
1251  return file;
1252 }
1253 
1256  PSI_file_key key, const char *src_file, uint src_line,
1257 #endif
1258  const char *name, myf flags) {
1259  int result;
1260 #ifdef HAVE_PSI_FILE_INTERFACE
1261  struct PSI_file_locker *locker;
1262  PSI_file_locker_state state;
1263  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1264  &state, key, PSI_FILE_DELETE, name, &locker);
1265  if (likely(locker != NULL)) {
1266  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1268  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1269  return result;
1270  }
1271 #endif
1272 
1274  return result;
1275 }
1276 
1279  PSI_file_key key, const char *src_file, uint src_line,
1280 #endif
1281  const char *from, const char *to, myf flags) {
1282  int result;
1283 #ifdef HAVE_PSI_FILE_INTERFACE
1284  struct PSI_file_locker *locker;
1285  PSI_file_locker_state state;
1286  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1287  &state, key, PSI_FILE_RENAME, from, &locker);
1288  if (likely(locker != NULL)) {
1289  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1290  result = my_rename_with_symlink(from, to, flags);
1291  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result);
1292  return result;
1293  }
1294 #endif
1295 
1296  result = my_rename_with_symlink(from, to, flags);
1297  return result;
1298 }
1299 
1300 static inline int inline_mysql_file_sync(
1302  const char *src_file, uint src_line,
1303 #endif
1304  File fd, myf flags) {
1305  int result = 0;
1306 #ifdef HAVE_PSI_FILE_INTERFACE
1307  struct PSI_file_locker *locker;
1308  PSI_file_locker_state state;
1309  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, fd,
1310  PSI_FILE_SYNC);
1311  if (likely(locker != NULL)) {
1312  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1313  result = my_sync(fd, flags);
1314  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1315  return result;
1316  }
1317 #endif
1318 
1319  result = my_sync(fd, flags);
1320  return result;
1321 }
1322 
1323 /** @} (end of group psi_api_file) */
1324 
1325 #endif
my_off_t my_seek(File fd, my_off_t pos, int whence, myf MyFlags)
Definition: my_seek.cc:82
size_t my_pwrite(File Filedes, const uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags)
Write a chunk of bytes to a file at a given position.
Definition: my_pread.cc:160
Definition: result.h:33
int my_fstat(int filenr, MY_STAT *stat_area)
Definition: my_lib.cc:301
static int inline_mysql_file_sync(const char *src_file, uint src_line, File fd, myf flags)
Definition: mysql_file.h:1300
unsigned char uchar
Definition: my_inttypes.h:51
static int inline_mysql_file_delete_with_symlink(PSI_file_key key, const char *src_file, uint src_line, const char *name, myf flags)
Definition: mysql_file.h:1254
my_off_t my_ftell(FILE *stream)
Definition: my_fstream.cc:168
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:46
static my_off_t inline_mysql_file_tell(const char *src_file, uint src_line, File file, myf flags)
Definition: mysql_file.h:1159
File rename, such as my_rename() or my_rename_with_symlink().
Definition: psi_file_bits.h:101
static size_t inline_mysql_file_pread(const char *src_file, uint src_line, File file, uchar *buffer, size_t count, my_off_t offset, myf flags)
Definition: mysql_file.h:1078
#define MY_WME
Definition: my_sys.h:116
ssize_t count
Definition: memcached.c:386
static size_t inline_mysql_file_pwrite(const char *src_file, uint src_line, File file, const uchar *buffer, size_t count, my_off_t offset, myf flags)
Definition: mysql_file.h:1107
const string name("\ame\)
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
static int inline_mysql_file_close(const char *src_file, uint src_line, File file, myf flags)
Definition: mysql_file.h:997
struct result result
Definition: result.h:37
static my_off_t inline_mysql_file_ftell(const char *src_file, uint src_line, MYSQL_FILE *file)
Definition: mysql_file.h:902
File my_create_with_symlink(const char *linkname, const char *filename, int createflags, int access_flags, myf MyFlags)
Definition: my_symlink2.cc:53
int my_delete_with_symlink(const char *name, myf MyFlags)
Definition: my_symlink2.cc:132
int my_delete(const char *name, myf MyFlags)
Definition: my_delete.cc:45
UnlinkOrKeepFile
Definition: my_sys.h:782
static File inline_mysql_file_create_temp(PSI_file_key key, const char *src_file, uint src_line, char *to, const char *dir, const char *pfx, int mode, UnlinkOrKeepFile unlink_or_keep, myf myFlags)
Definition: mysql_file.h:948
static int inline_mysql_file_fputs(const char *src_file, uint src_line, const char *str, MYSQL_FILE *file)
Definition: mysql_file.h:545
static int inline_mysql_file_vfprintf(const char *src_file, uint src_line, MYSQL_FILE *file, const char *format, va_list args)
Definition: mysql_file.h:636
int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
Definition: my_chsize.cc:71
static int inline_mysql_file_fprintf(MYSQL_FILE *file, const char *format,...)
Definition: mysql_file.h:597
static int inline_mysql_file_fputc(const char *src_file, uint src_line, char c, MYSQL_FILE *file)
Definition: mysql_file.h:570
static size_t inline_mysql_file_fwrite(const char *src_file, uint src_line, MYSQL_FILE *file, const uchar *buffer, size_t count, myf flags)
Definition: mysql_file.h:850
Performance schema instrumentation (declarations).
static File inline_mysql_file_create(PSI_file_key key, const char *src_file, uint src_line, const char *filename, int create_flags, int access_flags, myf myFlags)
Definition: mysql_file.h:925
static int inline_mysql_file_fflush(const char *src_file, uint src_line, MYSQL_FILE *file)
Definition: mysql_file.h:659
static int inline_mysql_file_chsize(const char *src_file, uint src_line, File file, my_off_t newlength, int filler, myf flags)
Definition: mysql_file.h:733
File instrument information.
Definition: psi_file_bits.h:112
struct PSI_file_locker PSI_file_locker
Definition: psi_file_bits.h:60
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:38
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
File stat, as in stat().
Definition: psi_file_bits.h:93
#define MY_STAT
Definition: my_dir.h:70
Generic file seek, such as fseek() or seek().
Definition: psi_file_bits.h:87
const std::string FILE("FILE")
struct PSI_file PSI_file
Definition: psi_file_bits.h:53
FILE * my_fopen(const char *FileName, int Flags, myf MyFlags)
Definition: my_fopen.cc:63
File creation, as in create().
Definition: psi_file_bits.h:65
static File inline_mysql_file_create_with_symlink(PSI_file_key key, const char *src_file, uint src_line, const char *linkname, const char *filename, int create_flags, int access_flags, myf flags)
Definition: mysql_file.h:1228
static char * inline_mysql_file_fgets(const char *src_file, uint src_line, char *str, int size, MYSQL_FILE *file)
Definition: mysql_file.h:499
File open, as in open().
Definition: psi_file_bits.h:69
size_t my_write(File Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
Write a chunk of bytes to a file.
Definition: my_write.cc:78
int my_fclose(FILE *fd, myf MyFlags)
Definition: my_fopen.cc:186
static my_off_t inline_mysql_file_fseek(const char *src_file, uint src_line, MYSQL_FILE *file, my_off_t pos, int whence)
Definition: mysql_file.h:879
char * pos
Definition: do_ctype.cc:76
#define MY_FNABP
Definition: my_sys.h:113
File open, as in fopen().
Definition: psi_file_bits.h:71
#define PSI_FILE_CALL(M)
Definition: psi_file.h:31
bool unlikely(bool expr)
Definition: my_compiler.h:65
static void inline_mysql_file_register(const char *category, PSI_file_info *info, int count)
Definition: mysql_file.h:486
Generic file write, such as fputs(), fputc(), fprintf(), vfprintf(), fwrite(), write(), pwrite().
Definition: psi_file_bits.h:85
static char * path
Definition: mysqldump.cc:125
File close, as in close().
Definition: psi_file_bits.h:73
size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
Read a chunk of bytes from a file with retry&#39;s if needed If flag MY_FULL_IO is set then keep reading ...
Definition: my_read.cc:72
static int inline_mysql_file_rename(PSI_file_key key, const char *src_file, uint src_line, const char *from, const char *to, myf flags)
Definition: mysql_file.h:1205
unsigned int uint
Definition: uca-dump.cc:29
static MY_STAT * inline_mysql_file_stat(PSI_file_key key, const char *src_file, uint src_line, const char *path, MY_STAT *stat_area, myf flags)
Definition: mysql_file.h:710
#define MYF(v)
Definition: my_inttypes.h:114
File delete, such as my_delete() or my_delete_with_symlink().
Definition: psi_file_bits.h:99
static int inline_mysql_file_fclose(const char *src_file, uint src_line, MYSQL_FILE *file, myf flags)
Definition: mysql_file.h:794
FILE * m_file
The real file.
Definition: mysql_file.h:477
Performance schema instrumentation interface.
static int inline_mysql_file_rename_with_symlink(PSI_file_key key, const char *src_file, uint src_line, const char *from, const char *to, myf flags)
Definition: mysql_file.h:1277
static File inline_mysql_file_open(PSI_file_key key, const char *src_file, uint src_line, const char *filename, int flags, myf myFlags)
Definition: mysql_file.h:974
An instrumented FILE structure.
Definition: mysql_file.h:475
File my_open(const char *FileName, int Flags, myf MyFlags)
Definition: my_open.cc:65
int my_sync(File fd, myf my_flags)
Definition: my_sync.cc:84
static const char * whence(const Field *cached_field)
Get the name of the cached field of an Item_cache_json instance.
Definition: item.cc:8789
#define MY_FILE_ERROR
Definition: my_sys.h:109
static my_off_t inline_mysql_file_seek(const char *src_file, uint src_line, File file, my_off_t pos, int whence, myf flags)
Definition: mysql_file.h:1136
bool likely(bool expr)
Definition: my_compiler.h:64
Common header for many mysys elements.
File close, as in fclose().
Definition: psi_file_bits.h:75
File flush, as in fflush().
Definition: psi_file_bits.h:91
size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags)
Definition: my_fstream.cc:111
File sync, as in fsync() or my_sync().
Definition: psi_file_bits.h:103
static const char * key
Definition: suite_stubs.c:14
int File
Definition: my_io_bits.h:50
MY_STAT * my_stat(const char *path, MY_STAT *stat_area, myf my_flags)
Definition: my_lib.cc:311
static int inline_mysql_file_fstat(const char *src_file, uint src_line, int filenr, MY_STAT *stat_area)
Definition: mysql_file.h:687
unsigned long my_off_t
Definition: my_inttypes.h:77
static const char * category
Definition: sha2_password.cc:166
static int inline_mysql_file_delete(PSI_file_key key, const char *src_file, uint src_line, const char *name, myf flags)
Definition: mysql_file.h:1182
int my_rename_with_symlink(const char *from, const char *to, myf MyFlags)
Definition: my_symlink2.cc:159
File create_temp_file(char *to, const char *dir, const char *pfx, int mode, UnlinkOrKeepFile unlink_or_keep, myf MyFlags)
Definition: mf_tempfile.cc:87
const char * filename
Definition: pfs_example_component_population.cc:64
Generic file tell, such as ftell() or tell().
Definition: psi_file_bits.h:89
static int inline_mysql_file_feof(MYSQL_FILE *file)
Definition: mysql_file.h:682
int my_close(File Filedes, myf MyFlags)
Definition: my_open.cc:95
File my_create(const char *FileName, int CreateFlags, int AccessFlags, myf MyFlags)
Definition: my_create.cc:58
#define MY_NABP
Definition: my_sys.h:114
int myf
Definition: my_inttypes.h:111
Generic file read, such as fgets(), fgetc(), fread(), read(), pread().
Definition: psi_file_bits.h:80
static size_t inline_mysql_file_fread(const char *src_file, uint src_line, MYSQL_FILE *file, uchar *buffer, size_t count, myf flags)
Definition: mysql_file.h:821
size_t my_fread(FILE *stream, uchar *Buffer, size_t Count, myf MyFlags)
Definition: my_fstream.cc:70
my_off_t my_tell(File fd, myf MyFlags)
Definition: my_seek.cc:116
#define NULL
Definition: types.h:55
size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags)
Definition: my_pread.cc:82
my_off_t my_fseek(FILE *stream, my_off_t pos, int whence)
Definition: my_fstream.cc:158
struct PSI_file * m_psi
The instrumentation hook.
Definition: mysql_file.h:483
static size_t inline_mysql_file_read(const char *src_file, uint src_line, File file, uchar *buffer, size_t count, myf flags)
Definition: mysql_file.h:1020
static MYSQL_FILE * inline_mysql_file_fopen(PSI_file_key key, const char *src_file, uint src_line, const char *filename, int flags, myf myFlags)
Definition: mysql_file.h:757
State data storage for get_thread_file_name_locker_v1_t.
Definition: psi_file_bits.h:144
Log info(cout, "NOTE")
#define HAVE_PSI_FILE_INTERFACE
Definition: my_psi_config.h:101
int my_rename(const char *from, const char *to, myf MyFlags)
Definition: my_rename.cc:46
static int flags[50]
Definition: hp_test1.cc:39
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Below functions are used by the components.
Definition: my_memory.cc:57
File stat, as in fstat().
Definition: psi_file_bits.h:95
static size_t inline_mysql_file_write(const char *src_file, uint src_line, File file, const uchar *buffer, size_t count, myf flags)
Definition: mysql_file.h:1049
File chsize, as in my_chsize().
Definition: psi_file_bits.h:97
static int inline_mysql_file_fgetc(const char *src_file, uint src_line, MYSQL_FILE *file)
Definition: mysql_file.h:522