MySQL  8.0.16
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, 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, F) \
289  inline_mysql_file_create_temp(K, __FILE__, __LINE__, T, D, P, M, F)
290 #else
291 #define mysql_file_create_temp(K, T, D, P, M, F) \
292  inline_mysql_file_create_temp(T, D, P, M, 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) {
884  my_off_t result;
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) {
907  my_off_t result;
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, myf myFlags) {
953  File file;
954 #ifdef HAVE_PSI_FILE_INTERFACE
955  struct PSI_file_locker *locker;
956  PSI_file_locker_state state;
957  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
958  &state, key, PSI_FILE_CREATE, NULL, &locker);
959  if (likely(locker != NULL)) {
960  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
961  /* The file name is generated by create_temp_file(). */
962  file = create_temp_file(to, dir, pfx, mode, myFlags);
963  PSI_FILE_CALL(end_temp_file_open_wait_and_bind_to_descriptor)
964  (locker, file, (const char *)to);
965  return file;
966  }
967 #endif
968 
969  file = create_temp_file(to, dir, pfx, mode, myFlags);
970  return file;
971 }
972 
975  PSI_file_key key, const char *src_file, uint src_line,
976 #endif
977  const char *filename, int flags, myf myFlags) {
978  File file;
979 #ifdef HAVE_PSI_FILE_INTERFACE
980  struct PSI_file_locker *locker;
981  PSI_file_locker_state state;
982  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
983  &state, key, PSI_FILE_OPEN, filename, &locker);
984  if (likely(locker != NULL)) {
985  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
986  file = my_open(filename, flags, myFlags);
987  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
988  return file;
989  }
990 #endif
991 
992  file = my_open(filename, flags, myFlags);
993  return file;
994 }
995 
996 static inline int inline_mysql_file_close(
998  const char *src_file, uint src_line,
999 #endif
1000  File file, myf flags) {
1001  int result;
1002 #ifdef HAVE_PSI_FILE_INTERFACE
1003  struct PSI_file_locker *locker;
1004  PSI_file_locker_state state;
1005  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1006  PSI_FILE_CLOSE);
1007  if (likely(locker != NULL)) {
1008  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1009  result = my_close(file, flags);
1010  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1011  return result;
1012  }
1013 #endif
1014 
1015  result = my_close(file, flags);
1016  return result;
1017 }
1018 
1019 static inline size_t inline_mysql_file_read(
1021  const char *src_file, uint src_line,
1022 #endif
1023  File file, uchar *buffer, size_t count, myf flags) {
1024  size_t result;
1025 #ifdef HAVE_PSI_FILE_INTERFACE
1026  struct PSI_file_locker *locker;
1027  PSI_file_locker_state state;
1028  size_t bytes_read;
1029  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1030  PSI_FILE_READ);
1031  if (likely(locker != NULL)) {
1032  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1033  result = my_read(file, buffer, count, flags);
1034  if (flags & (MY_NABP | MY_FNABP)) {
1035  bytes_read = (result == 0) ? count : 0;
1036  } else {
1037  bytes_read = (result != MY_FILE_ERROR) ? result : 0;
1038  }
1039  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1040  return result;
1041  }
1042 #endif
1043 
1044  result = my_read(file, buffer, count, flags);
1045  return result;
1046 }
1047 
1048 static inline size_t inline_mysql_file_write(
1050  const char *src_file, uint src_line,
1051 #endif
1052  File file, const uchar *buffer, size_t count, myf flags) {
1053  size_t result;
1054 #ifdef HAVE_PSI_FILE_INTERFACE
1055  struct PSI_file_locker *locker;
1056  PSI_file_locker_state state;
1057  size_t bytes_written;
1058  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1059  PSI_FILE_WRITE);
1060  if (likely(locker != NULL)) {
1061  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1062  result = my_write(file, buffer, count, flags);
1063  if (flags & (MY_NABP | MY_FNABP)) {
1064  bytes_written = (result == 0) ? count : 0;
1065  } else {
1066  bytes_written = (result != MY_FILE_ERROR) ? result : 0;
1067  }
1068  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1069  return result;
1070  }
1071 #endif
1072 
1073  result = my_write(file, buffer, count, flags);
1074  return result;
1075 }
1076 
1077 static inline size_t inline_mysql_file_pread(
1079  const char *src_file, uint src_line,
1080 #endif
1081  File file, uchar *buffer, size_t count, my_off_t offset, myf flags) {
1082  size_t result;
1083 #ifdef HAVE_PSI_FILE_INTERFACE
1084  struct PSI_file_locker *locker;
1085  PSI_file_locker_state state;
1086  size_t bytes_read;
1087  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1088  PSI_FILE_READ);
1089  if (likely(locker != NULL)) {
1090  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1091  result = my_pread(file, buffer, count, offset, flags);
1092  if (flags & (MY_NABP | MY_FNABP)) {
1093  bytes_read = (result == 0) ? count : 0;
1094  } else {
1095  bytes_read = (result != MY_FILE_ERROR) ? result : 0;
1096  }
1097  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1098  return result;
1099  }
1100 #endif
1101 
1102  result = my_pread(file, buffer, count, offset, flags);
1103  return result;
1104 }
1105 
1106 static inline size_t inline_mysql_file_pwrite(
1108  const char *src_file, uint src_line,
1109 #endif
1110  File file, const uchar *buffer, size_t count, my_off_t offset, myf flags) {
1111  size_t result;
1112 #ifdef HAVE_PSI_FILE_INTERFACE
1113  struct PSI_file_locker *locker;
1114  PSI_file_locker_state state;
1115  size_t bytes_written;
1116  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1117  PSI_FILE_WRITE);
1118  if (likely(locker != NULL)) {
1119  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1120  result = my_pwrite(file, buffer, count, offset, flags);
1121  if (flags & (MY_NABP | MY_FNABP)) {
1122  bytes_written = (result == 0) ? count : 0;
1123  } else {
1124  bytes_written = (result != MY_FILE_ERROR) ? result : 0;
1125  }
1126  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1127  return result;
1128  }
1129 #endif
1130 
1131  result = my_pwrite(file, buffer, count, offset, flags);
1132  return result;
1133 }
1134 
1137  const char *src_file, uint src_line,
1138 #endif
1139  File file, my_off_t pos, int whence, myf flags) {
1140  my_off_t result;
1141 #ifdef HAVE_PSI_FILE_INTERFACE
1142  struct PSI_file_locker *locker;
1143  PSI_file_locker_state state;
1144  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1145  PSI_FILE_SEEK);
1146  if (likely(locker != NULL)) {
1147  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1148  result = my_seek(file, pos, whence, flags);
1149  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1150  return result;
1151  }
1152 #endif
1153 
1154  result = my_seek(file, pos, whence, flags);
1155  return result;
1156 }
1157 
1160  const char *src_file, uint src_line,
1161 #endif
1162  File file, myf flags) {
1163  my_off_t result;
1164 #ifdef HAVE_PSI_FILE_INTERFACE
1165  struct PSI_file_locker *locker;
1166  PSI_file_locker_state state;
1167  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file,
1168  PSI_FILE_TELL);
1169  if (likely(locker != NULL)) {
1170  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1171  result = my_tell(file, flags);
1172  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1173  return result;
1174  }
1175 #endif
1176 
1177  result = my_tell(file, flags);
1178  return result;
1179 }
1180 
1181 static inline int inline_mysql_file_delete(
1183  PSI_file_key key, const char *src_file, uint src_line,
1184 #endif
1185  const char *name, myf flags) {
1186  int result;
1187 #ifdef HAVE_PSI_FILE_INTERFACE
1188  struct PSI_file_locker *locker;
1189  PSI_file_locker_state state;
1190  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1191  &state, key, PSI_FILE_DELETE, name, &locker);
1192  if (likely(locker != NULL)) {
1193  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1194  result = my_delete(name, flags);
1195  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1196  return result;
1197  }
1198 #endif
1199 
1200  result = my_delete(name, flags);
1201  return result;
1202 }
1203 
1204 static inline int inline_mysql_file_rename(
1206  PSI_file_key key, const char *src_file, uint src_line,
1207 #endif
1208  const char *from, const char *to, myf flags) {
1209  int result;
1210 #ifdef HAVE_PSI_FILE_INTERFACE
1211  struct PSI_file_locker *locker;
1212  PSI_file_locker_state state;
1213  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1214  &state, key, PSI_FILE_RENAME, from, &locker);
1215  if (likely(locker != NULL)) {
1216  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1217  result = my_rename(from, to, flags);
1218  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result);
1219  return result;
1220  }
1221 #endif
1222 
1223  result = my_rename(from, to, flags);
1224  return result;
1225 }
1226 
1229  PSI_file_key key, const char *src_file, uint src_line,
1230 #endif
1231  const char *linkname, const char *filename, int create_flags,
1232  int access_flags, myf flags) {
1233  File file;
1234 #ifdef HAVE_PSI_FILE_INTERFACE
1235  struct PSI_file_locker *locker;
1236  PSI_file_locker_state state;
1237  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1238  &state, key, PSI_FILE_CREATE, filename, &locker);
1239  if (likely(locker != NULL)) {
1240  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
1241  file = my_create_with_symlink(linkname, filename, create_flags,
1242  access_flags, flags);
1243  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
1244  return file;
1245  }
1246 #endif
1247 
1248  file = my_create_with_symlink(linkname, filename, create_flags, access_flags,
1249  flags);
1250  return file;
1251 }
1252 
1255  PSI_file_key key, const char *src_file, uint src_line,
1256 #endif
1257  const char *name, myf flags) {
1258  int result;
1259 #ifdef HAVE_PSI_FILE_INTERFACE
1260  struct PSI_file_locker *locker;
1261  PSI_file_locker_state state;
1262  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1263  &state, key, PSI_FILE_DELETE, name, &locker);
1264  if (likely(locker != NULL)) {
1265  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1266  result = my_delete_with_symlink(name, flags);
1267  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1268  return result;
1269  }
1270 #endif
1271 
1272  result = my_delete_with_symlink(name, flags);
1273  return result;
1274 }
1275 
1278  PSI_file_key key, const char *src_file, uint src_line,
1279 #endif
1280  const char *from, const char *to, myf flags) {
1281  int result;
1282 #ifdef HAVE_PSI_FILE_INTERFACE
1283  struct PSI_file_locker *locker;
1284  PSI_file_locker_state state;
1285  locker = PSI_FILE_CALL(get_thread_file_name_locker)(
1286  &state, key, PSI_FILE_RENAME, from, &locker);
1287  if (likely(locker != NULL)) {
1288  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1289  result = my_rename_with_symlink(from, to, flags);
1290  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result);
1291  return result;
1292  }
1293 #endif
1294 
1295  result = my_rename_with_symlink(from, to, flags);
1296  return result;
1297 }
1298 
1299 static inline int inline_mysql_file_sync(
1301  const char *src_file, uint src_line,
1302 #endif
1303  File fd, myf flags) {
1304  int result = 0;
1305 #ifdef HAVE_PSI_FILE_INTERFACE
1306  struct PSI_file_locker *locker;
1307  PSI_file_locker_state state;
1308  locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, fd,
1309  PSI_FILE_SYNC);
1310  if (likely(locker != NULL)) {
1311  PSI_FILE_CALL(start_file_wait)(locker, (size_t)0, src_file, src_line);
1312  result = my_sync(fd, flags);
1313  PSI_FILE_CALL(end_file_wait)(locker, (size_t)0);
1314  return result;
1315  }
1316 #endif
1317 
1318  result = my_sync(fd, flags);
1319  return result;
1320 }
1321 
1322  /** @} (end of group psi_api_file) */
1323 
1324 #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:161
int my_fstat(int filenr, MY_STAT *stat_area)
Definition: my_lib.cc:304
static int inline_mysql_file_sync(const char *src_file, uint src_line, File fd, myf flags)
Definition: mysql_file.h:1299
unsigned char uchar
Definition: my_inttypes.h:49
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:1253
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
t pos
Definition: dbug_analyze.cc:148
static my_off_t inline_mysql_file_tell(const char *src_file, uint src_line, File file, myf flags)
Definition: mysql_file.h:1158
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:1077
#define MY_WME
Definition: my_sys.h:114
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:1106
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:996
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
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 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, myf myFlags)
Definition: mysql_file.h:948
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
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
Performance schema instrumentation (declarations).
printf("== done ==\)
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:1227
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
#define MY_FNABP
Definition: my_sys.h:111
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:122
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:1204
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:131
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:1276
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:973
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:8736
#define MY_FILE_ERROR
Definition: my_sys.h:107
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:1135
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:314
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:88
static const char * category
Definition: sha2_password.cc:168
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:1181
int my_rename_with_symlink(const char *from, const char *to, myf MyFlags)
Definition: my_symlink2.cc:159
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:112
int myf
Definition: my_inttypes.h:128
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
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:1019
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
File create_temp_file(char *to, const char *dir, const char *pfx, int mode, myf MyFlags)
Definition: mf_tempfile.cc:84
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:1048
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