MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mysql_file.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2012, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #ifndef MYSQL_FILE_H
17 #define MYSQL_FILE_H
18 
19 #include <my_global.h>
20 
21 /* For strlen() */
22 #include <string.h>
23 /* For MY_STAT */
24 #include <my_dir.h>
25 /* For my_chsize */
26 #include <my_sys.h>
27 
44 #include "mysql/psi/psi.h"
45 
56 #define mysql_file_register(P1, P2, P3) \
57  inline_mysql_file_register(P1, P2, P3)
58 
64 #ifdef HAVE_PSI_FILE_INTERFACE
65  #define mysql_file_fgets(P1, P2, F) \
66  inline_mysql_file_fgets(__FILE__, __LINE__, P1, P2, F)
67 #else
68  #define mysql_file_fgets(P1, P2, F) \
69  inline_mysql_file_fgets(P1, P2, F)
70 #endif
71 
77 #ifdef HAVE_PSI_FILE_INTERFACE
78  #define mysql_file_fgetc(F) inline_mysql_file_fgetc(__FILE__, __LINE__, F)
79 #else
80  #define mysql_file_fgetc(F) inline_mysql_file_fgetc(F)
81 #endif
82 
88 #ifdef HAVE_PSI_FILE_INTERFACE
89  #define mysql_file_fputs(P1, F) \
90  inline_mysql_file_fputs(__FILE__, __LINE__, P1, F)
91 #else
92  #define mysql_file_fputs(P1, F)\
93  inline_mysql_file_fputs(P1, F)
94 #endif
95 
101 #ifdef HAVE_PSI_FILE_INTERFACE
102  #define mysql_file_fputc(P1, F) \
103  inline_mysql_file_fputc(__FILE__, __LINE__, P1, F)
104 #else
105  #define mysql_file_fputc(P1, F) \
106  inline_mysql_file_fputc(P1, F)
107 #endif
108 
114 #define mysql_file_fprintf inline_mysql_file_fprintf
115 
121 #ifdef HAVE_PSI_FILE_INTERFACE
122  #define mysql_file_vfprintf(F, P1, P2) \
123  inline_mysql_file_vfprintf(__FILE__, __LINE__, F, P1, P2)
124 #else
125  #define mysql_file_vfprintf(F, P1, P2) \
126  inline_mysql_file_vfprintf(F, P1, P2)
127 #endif
128 
134 #ifdef HAVE_PSI_FILE_INTERFACE
135  #define mysql_file_fflush(F) \
136  inline_mysql_file_fflush(__FILE__, __LINE__, F)
137 #else
138  #define mysql_file_fflush(F) \
139  inline_mysql_file_fflush(F)
140 #endif
141 
147 #define mysql_file_feof(F) inline_mysql_file_feof(F)
148 
154 #ifdef HAVE_PSI_FILE_INTERFACE
155  #define mysql_file_fstat(FN, S, FL) \
156  inline_mysql_file_fstat(__FILE__, __LINE__, FN, S, FL)
157 #else
158  #define mysql_file_fstat(FN, S, FL) \
159  inline_mysql_file_fstat(FN, S, FL)
160 #endif
161 
167 #ifdef HAVE_PSI_FILE_INTERFACE
168  #define mysql_file_stat(K, FN, S, FL) \
169  inline_mysql_file_stat(K, __FILE__, __LINE__, FN, S, FL)
170 #else
171  #define mysql_file_stat(K, FN, S, FL) \
172  inline_mysql_file_stat(FN, S, FL)
173 #endif
174 
180 #ifdef HAVE_PSI_FILE_INTERFACE
181  #define mysql_file_chsize(F, P1, P2, P3) \
182  inline_mysql_file_chsize(__FILE__, __LINE__, F, P1, P2, P3)
183 #else
184  #define mysql_file_chsize(F, P1, P2, P3) \
185  inline_mysql_file_chsize(F, P1, P2, P3)
186 #endif
187 
193 #ifdef HAVE_PSI_FILE_INTERFACE
194  #define mysql_file_fopen(K, N, F1, F2) \
195  inline_mysql_file_fopen(K, __FILE__, __LINE__, N, F1, F2)
196 #else
197  #define mysql_file_fopen(K, N, F1, F2) \
198  inline_mysql_file_fopen(N, F1, F2)
199 #endif
200 
213 #ifdef HAVE_PSI_FILE_INTERFACE
214  #define mysql_file_fclose(FD, FL) \
215  inline_mysql_file_fclose(__FILE__, __LINE__, FD, FL)
216 #else
217  #define mysql_file_fclose(FD, FL) \
218  inline_mysql_file_fclose(FD, FL)
219 #endif
220 
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) \
231  inline_mysql_file_fread(FD, P1, P2, P3)
232 #endif
233 
239 #ifdef HAVE_PSI_FILE_INTERFACE
240  #define mysql_file_fwrite(FD, P1, P2, P3) \
241  inline_mysql_file_fwrite(__FILE__, __LINE__, FD, P1, P2, P3)
242 #else
243  #define mysql_file_fwrite(FD, P1, P2, P3) \
244  inline_mysql_file_fwrite(FD, P1, P2, P3)
245 #endif
246 
252 #ifdef HAVE_PSI_FILE_INTERFACE
253  #define mysql_file_fseek(FD, P, W, F) \
254  inline_mysql_file_fseek(__FILE__, __LINE__, FD, P, W, F)
255 #else
256  #define mysql_file_fseek(FD, P, W, F) \
257  inline_mysql_file_fseek(FD, P, W, F)
258 #endif
259 
265 #ifdef HAVE_PSI_FILE_INTERFACE
266  #define mysql_file_ftell(FD, F) \
267  inline_mysql_file_ftell(__FILE__, __LINE__, FD, F)
268 #else
269  #define mysql_file_ftell(FD, F) \
270  inline_mysql_file_ftell(FD, F)
271 #endif
272 
278 #ifdef HAVE_PSI_FILE_INTERFACE
279  #define mysql_file_create(K, N, F1, F2, F3) \
280  inline_mysql_file_create(K, __FILE__, __LINE__, N, F1, F2, F3)
281 #else
282  #define mysql_file_create(K, N, F1, F2, F3) \
283  inline_mysql_file_create(N, F1, F2, F3)
284 #endif
285 
291 #ifdef HAVE_PSI_FILE_INTERFACE
292  #define mysql_file_create_temp(K, T, D, P, M, F) \
293  inline_mysql_file_create_temp(K, T, D, P, M, F)
294 #else
295  #define mysql_file_create_temp(K, T, D, P, M, F) \
296  inline_mysql_file_create_temp(T, D, P, M, F)
297 #endif
298 
304 #ifdef HAVE_PSI_FILE_INTERFACE
305  #define mysql_file_open(K, N, F1, F2) \
306  inline_mysql_file_open(K, __FILE__, __LINE__, N, F1, F2)
307 #else
308  #define mysql_file_open(K, N, F1, F2) \
309  inline_mysql_file_open(N, F1, F2)
310 #endif
311 
317 #ifdef HAVE_PSI_FILE_INTERFACE
318  #define mysql_file_close(FD, F) \
319  inline_mysql_file_close(__FILE__, __LINE__, FD, F)
320 #else
321  #define mysql_file_close(FD, F) \
322  inline_mysql_file_close(FD, F)
323 #endif
324 
330 #ifdef HAVE_PSI_FILE_INTERFACE
331  #define mysql_file_read(FD, B, S, F) \
332  inline_mysql_file_read(__FILE__, __LINE__, FD, B, S, F)
333 #else
334  #define mysql_file_read(FD, B, S, F) \
335  inline_mysql_file_read(FD, B, S, F)
336 #endif
337 
343 #ifdef HAVE_PSI_FILE_INTERFACE
344  #define mysql_file_write(FD, B, S, F) \
345  inline_mysql_file_write(__FILE__, __LINE__, FD, B, S, F)
346 #else
347  #define mysql_file_write(FD, B, S, F) \
348  inline_mysql_file_write(FD, B, S, F)
349 #endif
350 
356 #ifdef HAVE_PSI_FILE_INTERFACE
357  #define mysql_file_pread(FD, B, S, O, F) \
358  inline_mysql_file_pread(__FILE__, __LINE__, FD, B, S, O, F)
359 #else
360  #define mysql_file_pread(FD, B, S, O, F) \
361  inline_mysql_file_pread(FD, B, S, O, F)
362 #endif
363 
369 #ifdef HAVE_PSI_FILE_INTERFACE
370  #define mysql_file_pwrite(FD, B, S, O, F) \
371  inline_mysql_file_pwrite(__FILE__, __LINE__, FD, B, S, O, F)
372 #else
373  #define mysql_file_pwrite(FD, B, S, O, F) \
374  inline_mysql_file_pwrite(FD, B, S, O, F)
375 #endif
376 
382 #ifdef HAVE_PSI_FILE_INTERFACE
383  #define mysql_file_seek(FD, P, W, F) \
384  inline_mysql_file_seek(__FILE__, __LINE__, FD, P, W, F)
385 #else
386  #define mysql_file_seek(FD, P, W, F) \
387  inline_mysql_file_seek(FD, P, W, F)
388 #endif
389 
395 #ifdef HAVE_PSI_FILE_INTERFACE
396  #define mysql_file_tell(FD, F) \
397  inline_mysql_file_tell(__FILE__, __LINE__, FD, F)
398 #else
399  #define mysql_file_tell(FD, F) \
400  inline_mysql_file_tell(FD, F)
401 #endif
402 
408 #ifdef HAVE_PSI_FILE_INTERFACE
409  #define mysql_file_delete(K, P1, P2) \
410  inline_mysql_file_delete(K, __FILE__, __LINE__, P1, P2)
411 #else
412  #define mysql_file_delete(K, P1, P2) \
413  inline_mysql_file_delete(P1, P2)
414 #endif
415 
421 #ifdef HAVE_PSI_FILE_INTERFACE
422  #define mysql_file_rename(K, P1, P2, P3) \
423  inline_mysql_file_rename(K, __FILE__, __LINE__, P1, P2, P3)
424 #else
425  #define mysql_file_rename(K, P1, P2, P3) \
426  inline_mysql_file_rename(P1, P2, P3)
427 #endif
428 
435 #ifdef HAVE_PSI_FILE_INTERFACE
436  #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \
437  inline_mysql_file_create_with_symlink(K, __FILE__, __LINE__, \
438  P1, P2, P3, P4, P5)
439 #else
440  #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \
441  inline_mysql_file_create_with_symlink(P1, P2, P3, P4, P5)
442 #endif
443 
450 #ifdef HAVE_PSI_FILE_INTERFACE
451  #define mysql_file_delete_with_symlink(K, P1, P2) \
452  inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2)
453 #else
454  #define mysql_file_delete_with_symlink(K, P1, P2) \
455  inline_mysql_file_delete_with_symlink(P1, P2)
456 #endif
457 
464 #ifdef HAVE_PSI_FILE_INTERFACE
465  #define mysql_file_rename_with_symlink(K, P1, P2, P3) \
466  inline_mysql_file_rename_with_symlink(K, __FILE__, __LINE__, P1, P2, P3)
467 #else
468  #define mysql_file_rename_with_symlink(K, P1, P2, P3) \
469  inline_mysql_file_rename_with_symlink(P1, P2, P3)
470 #endif
471 
477 #ifdef HAVE_PSI_FILE_INTERFACE
478  #define mysql_file_sync(P1, P2) \
479  inline_mysql_file_sync(__FILE__, __LINE__, P1, P2)
480 #else
481  #define mysql_file_sync(P1, P2) \
482  inline_mysql_file_sync(P1, P2)
483 #endif
484 
490 {
492  FILE *m_file;
498  struct PSI_file *m_psi;
499 };
500 
506 typedef struct st_mysql_file MYSQL_FILE;
507 
508 static inline void inline_mysql_file_register(
509 #ifdef HAVE_PSI_FILE_INTERFACE
510  const char *category,
511  PSI_file_info *info,
512  int count
513 #else
514  const char *category __attribute__ ((unused)),
515  void *info __attribute__ ((unused)),
516  int count __attribute__ ((unused))
517 #endif
518 )
519 {
520 #ifdef HAVE_PSI_FILE_INTERFACE
521  PSI_FILE_CALL(register_file)(category, info, count);
522 #endif
523 }
524 
525 static inline char *
526 inline_mysql_file_fgets(
527 #ifdef HAVE_PSI_FILE_INTERFACE
528  const char *src_file, uint src_line,
529 #endif
530  char *str, int size, MYSQL_FILE *file)
531 {
532  char *result;
533 #ifdef HAVE_PSI_FILE_INTERFACE
534  struct PSI_file_locker *locker;
535  PSI_file_locker_state state;
536  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
537  (&state, file->m_psi, PSI_FILE_READ);
538  if (likely(locker != NULL))
539  {
540  PSI_FILE_CALL(start_file_wait)(locker, (size_t) size, src_file, src_line);
541  result= fgets(str, size, file->m_file);
542  PSI_FILE_CALL(end_file_wait)(locker, result ? strlen(result) : 0);
543  return result;
544  }
545 #endif
546 
547  result= fgets(str, size, file->m_file);
548  return result;
549 }
550 
551 static inline int
552 inline_mysql_file_fgetc(
553 #ifdef HAVE_PSI_FILE_INTERFACE
554  const char *src_file, uint src_line,
555 #endif
556  MYSQL_FILE *file)
557 {
558  int result;
559 #ifdef HAVE_PSI_FILE_INTERFACE
560  struct PSI_file_locker *locker;
561  PSI_file_locker_state state;
562  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
563  (&state, file->m_psi, PSI_FILE_READ);
564  if (likely(locker != NULL))
565  {
566  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line);
567  result= fgetc(file->m_file);
568  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1);
569  return result;
570  }
571 #endif
572 
573  result= fgetc(file->m_file);
574  return result;
575 }
576 
577 static inline int
578 inline_mysql_file_fputs(
579 #ifdef HAVE_PSI_FILE_INTERFACE
580  const char *src_file, uint src_line,
581 #endif
582  const char *str, MYSQL_FILE *file)
583 {
584  int result;
585 #ifdef HAVE_PSI_FILE_INTERFACE
586  struct PSI_file_locker *locker;
587  PSI_file_locker_state state;
588  size_t bytes;
589  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
590  (&state, file->m_psi, PSI_FILE_WRITE);
591  if (likely(locker != NULL))
592  {
593  bytes= str ? strlen(str) : 0;
594  PSI_FILE_CALL(start_file_wait)(locker, bytes, src_file, src_line);
595  result= fputs(str, file->m_file);
596  PSI_FILE_CALL(end_file_wait)(locker, bytes);
597  return result;
598  }
599 #endif
600 
601  result= fputs(str, file->m_file);
602  return result;
603 }
604 
605 static inline int
606 inline_mysql_file_fputc(
607 #ifdef HAVE_PSI_FILE_INTERFACE
608  const char *src_file, uint src_line,
609 #endif
610  char c, MYSQL_FILE *file)
611 {
612  int result;
613 #ifdef HAVE_PSI_FILE_INTERFACE
614  struct PSI_file_locker *locker;
615  PSI_file_locker_state state;
616  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
617  (&state, file->m_psi, PSI_FILE_WRITE);
618  if (likely(locker != NULL))
619  {
620  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line);
621  result= fputc(c, file->m_file);
622  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1);
623  return result;
624  }
625 #endif
626 
627  result= fputc(c, file->m_file);
628  return result;
629 }
630 
631 static inline int
632 inline_mysql_file_fprintf(MYSQL_FILE *file, const char *format, ...)
633 {
634  /*
635  TODO: figure out how to pass src_file and src_line from the caller.
636  */
637  int result;
638  va_list args;
639 #ifdef HAVE_PSI_FILE_INTERFACE
640  struct PSI_file_locker *locker;
641  PSI_file_locker_state state;
642  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
643  (&state, file->m_psi, PSI_FILE_WRITE);
644  if (likely(locker != NULL))
645  {
646  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, __FILE__, __LINE__);
647  va_start(args, format);
648  result= vfprintf(file->m_file, format, args);
649  va_end(args);
650  PSI_FILE_CALL(end_file_wait)(locker, (size_t) result);
651  return result;
652  }
653 #endif
654 
655  va_start(args, format);
656  result= vfprintf(file->m_file, format, args);
657  va_end(args);
658  return result;
659 }
660 
661 static inline int
662 inline_mysql_file_vfprintf(
663 #ifdef HAVE_PSI_FILE_INTERFACE
664  const char *src_file, uint src_line,
665 #endif
666  MYSQL_FILE *file, const char *format, va_list args)
667 {
668  int result;
669 #ifdef HAVE_PSI_FILE_INTERFACE
670  struct PSI_file_locker *locker;
671  PSI_file_locker_state state;
672  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
673  (&state, file->m_psi, PSI_FILE_WRITE);
674  if (likely(locker != NULL))
675  {
676  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
677  result= vfprintf(file->m_file, format, args);
678  PSI_FILE_CALL(end_file_wait)(locker, (size_t) result);
679  return result;
680  }
681 #endif
682 
683  result= vfprintf(file->m_file, format, args);
684  return result;
685 }
686 
687 static inline int
688 inline_mysql_file_fflush(
689 #ifdef HAVE_PSI_FILE_INTERFACE
690  const char *src_file, uint src_line,
691 #endif
692  MYSQL_FILE *file)
693 {
694  int result;
695 #ifdef HAVE_PSI_FILE_INTERFACE
696  struct PSI_file_locker *locker;
697  PSI_file_locker_state state;
698  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
699  (&state, file->m_psi, PSI_FILE_FLUSH);
700  if (likely(locker != NULL))
701  {
702  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
703  result= fflush(file->m_file);
704  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
705  return result;
706  }
707 #endif
708 
709  result= fflush(file->m_file);
710  return result;
711 }
712 
713 static inline int inline_mysql_file_feof(MYSQL_FILE *file)
714 {
715  /* Not instrumented, there is no wait involved */
716  return feof(file->m_file);
717 }
718 
719 static inline int
720 inline_mysql_file_fstat(
721 #ifdef HAVE_PSI_FILE_INTERFACE
722  const char *src_file, uint src_line,
723 #endif
724  int filenr, MY_STAT *stat_area, myf flags)
725 {
726  int result;
727 #ifdef HAVE_PSI_FILE_INTERFACE
728  struct PSI_file_locker *locker;
729  PSI_file_locker_state state;
730  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
731  (&state, filenr, PSI_FILE_FSTAT);
732  if (likely(locker != NULL))
733  {
734  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
735  result= my_fstat(filenr, stat_area, flags);
736  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
737  return result;
738  }
739 #endif
740 
741  result= my_fstat(filenr, stat_area, flags);
742  return result;
743 }
744 
745 static inline MY_STAT *
746 inline_mysql_file_stat(
747 #ifdef HAVE_PSI_FILE_INTERFACE
748  PSI_file_key key, const char *src_file, uint src_line,
749 #endif
750  const char *path, MY_STAT *stat_area, myf flags)
751 {
752  MY_STAT *result;
753 #ifdef HAVE_PSI_FILE_INTERFACE
754  struct PSI_file_locker *locker;
755  PSI_file_locker_state state;
756  locker= PSI_FILE_CALL(get_thread_file_name_locker)
757  (&state, key, PSI_FILE_STAT, path, &locker);
758  if (likely(locker != NULL))
759  {
760  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
761  result= my_stat(path, stat_area, flags);
762  PSI_FILE_CALL(end_file_open_wait)(locker, result);
763  return result;
764  }
765 #endif
766 
767  result= my_stat(path, stat_area, flags);
768  return result;
769 }
770 
771 static inline int
772 inline_mysql_file_chsize(
773 #ifdef HAVE_PSI_FILE_INTERFACE
774  const char *src_file, uint src_line,
775 #endif
776  File file, my_off_t newlength, int filler, myf flags)
777 {
778  int result;
779 #ifdef HAVE_PSI_FILE_INTERFACE
780  struct PSI_file_locker *locker;
781  PSI_file_locker_state state;
782  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
783  (&state, file, PSI_FILE_CHSIZE);
784  if (likely(locker != NULL))
785  {
786  PSI_FILE_CALL(start_file_wait)(locker, (size_t) newlength, src_file,
787  src_line);
788  result= my_chsize(file, newlength, filler, flags);
789  PSI_FILE_CALL(end_file_wait)(locker, (size_t) newlength);
790  return result;
791  }
792 #endif
793 
794  result= my_chsize(file, newlength, filler, flags);
795  return result;
796 }
797 
798 static inline MYSQL_FILE*
799 inline_mysql_file_fopen(
800 #ifdef HAVE_PSI_FILE_INTERFACE
801  PSI_file_key key, const char *src_file, uint src_line,
802 #endif
803  const char *filename, int flags, myf myFlags)
804 {
805  MYSQL_FILE *that;
806  that= (MYSQL_FILE*) my_malloc(sizeof(MYSQL_FILE), MYF(MY_WME));
807  if (likely(that != NULL))
808  {
809 #ifdef HAVE_PSI_FILE_INTERFACE
810  struct PSI_file_locker *locker;
811  PSI_file_locker_state state;
812  locker= PSI_FILE_CALL(get_thread_file_name_locker)
813  (&state, key, PSI_FILE_STREAM_OPEN, filename, that);
814  if (likely(locker != NULL))
815  {
816  PSI_FILE_CALL(start_file_open_wait)
817  (locker, src_file, src_line);
818  that->m_file= my_fopen(filename, flags, myFlags);
819  that->m_psi= PSI_FILE_CALL(end_file_open_wait)(locker, that->m_file);
820  if (unlikely(that->m_file == NULL))
821  {
822  my_free(that);
823  return NULL;
824  }
825  return that;
826  }
827 #endif
828 
829  that->m_psi= NULL;
830  that->m_file= my_fopen(filename, flags, myFlags);
831  if (unlikely(that->m_file == NULL))
832  {
833  my_free(that);
834  return NULL;
835  }
836  }
837  return that;
838 }
839 
840 static inline int
841 inline_mysql_file_fclose(
842 #ifdef HAVE_PSI_FILE_INTERFACE
843  const char *src_file, uint src_line,
844 #endif
845  MYSQL_FILE *file, myf flags)
846 {
847  int result= 0;
848  if (likely(file != NULL))
849  {
850 #ifdef HAVE_PSI_FILE_INTERFACE
851  struct PSI_file_locker *locker;
852  PSI_file_locker_state state;
853  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
854  (&state, file->m_psi, PSI_FILE_STREAM_CLOSE);
855  if (likely(locker != NULL))
856  {
857  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
858  result= my_fclose(file->m_file, flags);
859  PSI_FILE_CALL(end_file_close_wait)(locker, result);
860  my_free(file);
861  return result;
862  }
863 #endif
864 
865  result= my_fclose(file->m_file, flags);
866  my_free(file);
867  }
868  return result;
869 }
870 
871 static inline size_t
872 inline_mysql_file_fread(
873 #ifdef HAVE_PSI_FILE_INTERFACE
874  const char *src_file, uint src_line,
875 #endif
876  MYSQL_FILE *file, uchar *buffer, size_t count, myf flags)
877 {
878  size_t result;
879 #ifdef HAVE_PSI_FILE_INTERFACE
880  struct PSI_file_locker *locker;
881  PSI_file_locker_state state;
882  size_t bytes_read;
883  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
884  (&state, file->m_psi, PSI_FILE_READ);
885  if (likely(locker != NULL))
886  {
887  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
888  result= my_fread(file->m_file, buffer, count, flags);
889  if (flags & (MY_NABP | MY_FNABP))
890  bytes_read= (result == 0) ? count : 0;
891  else
892  bytes_read= (result != MY_FILE_ERROR) ? result : 0;
893  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
894  return result;
895  }
896 #endif
897 
898  result= my_fread(file->m_file, buffer, count, flags);
899  return result;
900 }
901 
902 static inline size_t
903 inline_mysql_file_fwrite(
904 #ifdef HAVE_PSI_FILE_INTERFACE
905  const char *src_file, uint src_line,
906 #endif
907  MYSQL_FILE *file, const uchar *buffer, size_t count, myf flags)
908 {
909  size_t result;
910 #ifdef HAVE_PSI_FILE_INTERFACE
911  struct PSI_file_locker *locker;
912  PSI_file_locker_state state;
913  size_t bytes_written;
914  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
915  (&state, file->m_psi, PSI_FILE_WRITE);
916  if (likely(locker != NULL))
917  {
918  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
919  result= my_fwrite(file->m_file, buffer, count, flags);
920  if (flags & (MY_NABP | MY_FNABP))
921  bytes_written= (result == 0) ? count : 0;
922  else
923  bytes_written= (result != MY_FILE_ERROR) ? result : 0;
924  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
925  return result;
926  }
927 #endif
928 
929  result= my_fwrite(file->m_file, buffer, count, flags);
930  return result;
931 }
932 
933 static inline my_off_t
934 inline_mysql_file_fseek(
935 #ifdef HAVE_PSI_FILE_INTERFACE
936  const char *src_file, uint src_line,
937 #endif
938  MYSQL_FILE *file, my_off_t pos, int whence, myf flags)
939 {
940  my_off_t result;
941 #ifdef HAVE_PSI_FILE_INTERFACE
942  struct PSI_file_locker *locker;
943  PSI_file_locker_state state;
944  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
945  (&state, file->m_psi, PSI_FILE_SEEK);
946  if (likely(locker != NULL))
947  {
948  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
949  result= my_fseek(file->m_file, pos, whence, flags);
950  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
951  return result;
952  }
953 #endif
954 
955  result= my_fseek(file->m_file, pos, whence, flags);
956  return result;
957 }
958 
959 static inline my_off_t
960 inline_mysql_file_ftell(
961 #ifdef HAVE_PSI_FILE_INTERFACE
962  const char *src_file, uint src_line,
963 #endif
964  MYSQL_FILE *file, myf flags)
965 {
966  my_off_t result;
967 #ifdef HAVE_PSI_FILE_INTERFACE
968  struct PSI_file_locker *locker;
969  PSI_file_locker_state state;
970  locker= PSI_FILE_CALL(get_thread_file_stream_locker)
971  (&state, file->m_psi, PSI_FILE_TELL);
972  if (likely(locker != NULL))
973  {
974  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
975  result= my_ftell(file->m_file, flags);
976  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
977  return result;
978  }
979 #endif
980 
981  result= my_ftell(file->m_file, flags);
982  return result;
983 }
984 
985 static inline File
986 inline_mysql_file_create(
987 #ifdef HAVE_PSI_FILE_INTERFACE
988  PSI_file_key key, const char *src_file, uint src_line,
989 #endif
990  const char *filename, int create_flags, int access_flags, myf myFlags)
991 {
992  File file;
993 #ifdef HAVE_PSI_FILE_INTERFACE
994  struct PSI_file_locker *locker;
995  PSI_file_locker_state state;
996  locker= PSI_FILE_CALL(get_thread_file_name_locker)
997  (&state, key, PSI_FILE_CREATE, filename, &locker);
998  if (likely(locker != NULL))
999  {
1000  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
1001  file= my_create(filename, create_flags, access_flags, myFlags);
1002  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
1003  return file;
1004  }
1005 #endif
1006 
1007  file= my_create(filename, create_flags, access_flags, myFlags);
1008  return file;
1009 }
1010 
1011 static inline File
1012 inline_mysql_file_create_temp(
1013 #ifdef HAVE_PSI_FILE_INTERFACE
1014  PSI_file_key key,
1015 #endif
1016  char *to, const char *dir, const char *pfx, int mode, myf myFlags)
1017 {
1018  File file;
1019  /*
1020  TODO: This event is instrumented, but not timed.
1021  The problem is that the file name is now known
1022  before the create_temp_file call.
1023  */
1024  file= create_temp_file(to, dir, pfx, mode, myFlags);
1025 #ifdef HAVE_PSI_FILE_INTERFACE
1026  PSI_FILE_CALL(create_file)(key, to, file);
1027 #endif
1028  return file;
1029 }
1030 
1031 static inline File
1032 inline_mysql_file_open(
1033 #ifdef HAVE_PSI_FILE_INTERFACE
1034  PSI_file_key key, const char *src_file, uint src_line,
1035 #endif
1036  const char *filename, int flags, myf myFlags)
1037 {
1038  File file;
1039 #ifdef HAVE_PSI_FILE_INTERFACE
1040  struct PSI_file_locker *locker;
1041  PSI_file_locker_state state;
1042  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1043  (&state, key, PSI_FILE_OPEN, filename, &locker);
1044  if (likely(locker != NULL))
1045  {
1046  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
1047  file= my_open(filename, flags, myFlags);
1048  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
1049  return file;
1050  }
1051 #endif
1052 
1053  file= my_open(filename, flags, myFlags);
1054  return file;
1055 }
1056 
1057 static inline int
1058 inline_mysql_file_close(
1059 #ifdef HAVE_PSI_FILE_INTERFACE
1060  const char *src_file, uint src_line,
1061 #endif
1062  File file, myf flags)
1063 {
1064  int result;
1065 #ifdef HAVE_PSI_FILE_INTERFACE
1066  struct PSI_file_locker *locker;
1067  PSI_file_locker_state state;
1068  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1069  (&state, file, PSI_FILE_CLOSE);
1070  if (likely(locker != NULL))
1071  {
1072  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1073  result= my_close(file, flags);
1074  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1075  return result;
1076  }
1077 #endif
1078 
1079  result= my_close(file, flags);
1080  return result;
1081 }
1082 
1083 static inline size_t
1084 inline_mysql_file_read(
1085 #ifdef HAVE_PSI_FILE_INTERFACE
1086  const char *src_file, uint src_line,
1087 #endif
1088  File file, uchar *buffer, size_t count, myf flags)
1089 {
1090  size_t result;
1091 #ifdef HAVE_PSI_FILE_INTERFACE
1092  struct PSI_file_locker *locker;
1093  PSI_file_locker_state state;
1094  size_t bytes_read;
1095  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1096  (&state, file, PSI_FILE_READ);
1097  if (likely(locker != NULL))
1098  {
1099  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1100  result= my_read(file, buffer, count, flags);
1101  if (flags & (MY_NABP | MY_FNABP))
1102  bytes_read= (result == 0) ? count : 0;
1103  else
1104  bytes_read= (result != MY_FILE_ERROR) ? result : 0;
1105  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1106  return result;
1107  }
1108 #endif
1109 
1110  result= my_read(file, buffer, count, flags);
1111  return result;
1112 }
1113 
1114 static inline size_t
1115 inline_mysql_file_write(
1116 #ifdef HAVE_PSI_FILE_INTERFACE
1117  const char *src_file, uint src_line,
1118 #endif
1119  File file, const uchar *buffer, size_t count, myf flags)
1120 {
1121  size_t result;
1122 #ifdef HAVE_PSI_FILE_INTERFACE
1123  struct PSI_file_locker *locker;
1124  PSI_file_locker_state state;
1125  size_t bytes_written;
1126  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1127  (&state, file, PSI_FILE_WRITE);
1128  if (likely(locker != NULL))
1129  {
1130  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1131  result= my_write(file, buffer, count, flags);
1132  if (flags & (MY_NABP | MY_FNABP))
1133  bytes_written= (result == 0) ? count : 0;
1134  else
1135  bytes_written= (result != MY_FILE_ERROR) ? result : 0;
1136  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1137  return result;
1138  }
1139 #endif
1140 
1141  result= my_write(file, buffer, count, flags);
1142  return result;
1143 }
1144 
1145 static inline size_t
1146 inline_mysql_file_pread(
1147 #ifdef HAVE_PSI_FILE_INTERFACE
1148  const char *src_file, uint src_line,
1149 #endif
1150  File file, uchar *buffer, size_t count, my_off_t offset, myf flags)
1151 {
1152  size_t result;
1153 #ifdef HAVE_PSI_FILE_INTERFACE
1154  struct PSI_file_locker *locker;
1155  PSI_file_locker_state state;
1156  size_t bytes_read;
1157  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1158  (&state, file, PSI_FILE_READ);
1159  if (likely(locker != NULL))
1160  {
1161  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1162  result= my_pread(file, buffer, count, offset, flags);
1163  if (flags & (MY_NABP | MY_FNABP))
1164  bytes_read= (result == 0) ? count : 0;
1165  else
1166  bytes_read= (result != MY_FILE_ERROR) ? result : 0;
1167  PSI_FILE_CALL(end_file_wait)(locker, bytes_read);
1168  return result;
1169  }
1170 #endif
1171 
1172  result= my_pread(file, buffer, count, offset, flags);
1173  return result;
1174 }
1175 
1176 static inline size_t
1177 inline_mysql_file_pwrite(
1178 #ifdef HAVE_PSI_FILE_INTERFACE
1179  const char *src_file, uint src_line,
1180 #endif
1181  File file, const uchar *buffer, size_t count, my_off_t offset, myf flags)
1182 {
1183  size_t result;
1184 #ifdef HAVE_PSI_FILE_INTERFACE
1185  struct PSI_file_locker *locker;
1186  PSI_file_locker_state state;
1187  size_t bytes_written;
1188  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1189  (&state, file, PSI_FILE_WRITE);
1190  if (likely(locker != NULL))
1191  {
1192  PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line);
1193  result= my_pwrite(file, buffer, count, offset, flags);
1194  if (flags & (MY_NABP | MY_FNABP))
1195  bytes_written= (result == 0) ? count : 0;
1196  else
1197  bytes_written= (result != MY_FILE_ERROR) ? result : 0;
1198  PSI_FILE_CALL(end_file_wait)(locker, bytes_written);
1199  return result;
1200  }
1201 #endif
1202 
1203  result= my_pwrite(file, buffer, count, offset, flags);
1204  return result;
1205 }
1206 
1207 static inline my_off_t
1208 inline_mysql_file_seek(
1209 #ifdef HAVE_PSI_FILE_INTERFACE
1210  const char *src_file, uint src_line,
1211 #endif
1212  File file, my_off_t pos, int whence, myf flags)
1213 {
1214  my_off_t result;
1215 #ifdef HAVE_PSI_FILE_INTERFACE
1216  struct PSI_file_locker *locker;
1217  PSI_file_locker_state state;
1218  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1219  (&state, file, PSI_FILE_SEEK);
1220  if (likely(locker != NULL))
1221  {
1222  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
1223  result= my_seek(file, pos, whence, flags);
1224  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
1225  return result;
1226  }
1227 #endif
1228 
1229  result= my_seek(file, pos, whence, flags);
1230  return result;
1231 }
1232 
1233 static inline my_off_t
1234 inline_mysql_file_tell(
1235 #ifdef HAVE_PSI_FILE_INTERFACE
1236  const char *src_file, uint src_line,
1237 #endif
1238  File file, myf flags)
1239 {
1240  my_off_t result;
1241 #ifdef HAVE_PSI_FILE_INTERFACE
1242  struct PSI_file_locker *locker;
1243  PSI_file_locker_state state;
1244  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1245  (&state, file, PSI_FILE_TELL);
1246  if (likely(locker != NULL))
1247  {
1248  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
1249  result= my_tell(file, flags);
1250  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
1251  return result;
1252  }
1253 #endif
1254 
1255  result= my_tell(file, flags);
1256  return result;
1257 }
1258 
1259 static inline int
1260 inline_mysql_file_delete(
1261 #ifdef HAVE_PSI_FILE_INTERFACE
1262  PSI_file_key key, const char *src_file, uint src_line,
1263 #endif
1264  const char *name, myf flags)
1265 {
1266  int result;
1267 #ifdef HAVE_PSI_FILE_INTERFACE
1268  struct PSI_file_locker *locker;
1269  PSI_file_locker_state state;
1270  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1271  (&state, key, PSI_FILE_DELETE, name, &locker);
1272  if (likely(locker != NULL))
1273  {
1274  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1275  result= my_delete(name, flags);
1276  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1277  return result;
1278  }
1279 #endif
1280 
1281  result= my_delete(name, flags);
1282  return result;
1283 }
1284 
1285 static inline int
1286 inline_mysql_file_rename(
1287 #ifdef HAVE_PSI_FILE_INTERFACE
1288  PSI_file_key key, const char *src_file, uint src_line,
1289 #endif
1290  const char *from, const char *to, myf flags)
1291 {
1292  int result;
1293 #ifdef HAVE_PSI_FILE_INTERFACE
1294  struct PSI_file_locker *locker;
1295  PSI_file_locker_state state;
1296  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1297  (&state, key, PSI_FILE_RENAME, to, &locker);
1298  if (likely(locker != NULL))
1299  {
1300  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
1301  result= my_rename(from, to, flags);
1302  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
1303  return result;
1304  }
1305 #endif
1306 
1307  result= my_rename(from, to, flags);
1308  return result;
1309 }
1310 
1311 static inline File
1312 inline_mysql_file_create_with_symlink(
1313 #ifdef HAVE_PSI_FILE_INTERFACE
1314  PSI_file_key key, const char *src_file, uint src_line,
1315 #endif
1316  const char *linkname, const char *filename, int create_flags,
1317  int access_flags, myf flags)
1318 {
1319  File file;
1320 #ifdef HAVE_PSI_FILE_INTERFACE
1321  struct PSI_file_locker *locker;
1322  PSI_file_locker_state state;
1323  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1324  (&state, key, PSI_FILE_CREATE, filename, &locker);
1325  if (likely(locker != NULL))
1326  {
1327  PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line);
1328  file= my_create_with_symlink(linkname, filename, create_flags, access_flags,
1329  flags);
1330  PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file);
1331  return file;
1332  }
1333 #endif
1334 
1335  file= my_create_with_symlink(linkname, filename, create_flags, access_flags,
1336  flags);
1337  return file;
1338 }
1339 
1340 static inline int
1341 inline_mysql_file_delete_with_symlink(
1342 #ifdef HAVE_PSI_FILE_INTERFACE
1343  PSI_file_key key, const char *src_file, uint src_line,
1344 #endif
1345  const char *name, myf flags)
1346 {
1347  int result;
1348 #ifdef HAVE_PSI_FILE_INTERFACE
1349  struct PSI_file_locker *locker;
1350  PSI_file_locker_state state;
1351  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1352  (&state, key, PSI_FILE_DELETE, name, &locker);
1353  if (likely(locker != NULL))
1354  {
1355  PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line);
1356  result= my_delete_with_symlink(name, flags);
1357  PSI_FILE_CALL(end_file_close_wait)(locker, result);
1358  return result;
1359  }
1360 #endif
1361 
1362  result= my_delete_with_symlink(name, flags);
1363  return result;
1364 }
1365 
1366 static inline int
1367 inline_mysql_file_rename_with_symlink(
1368 #ifdef HAVE_PSI_FILE_INTERFACE
1369  PSI_file_key key, const char *src_file, uint src_line,
1370 #endif
1371  const char *from, const char *to, myf flags)
1372 {
1373  int result;
1374 #ifdef HAVE_PSI_FILE_INTERFACE
1375  struct PSI_file_locker *locker;
1376  PSI_file_locker_state state;
1377  locker= PSI_FILE_CALL(get_thread_file_name_locker)
1378  (&state, key, PSI_FILE_RENAME, to, &locker);
1379  if (likely(locker != NULL))
1380  {
1381  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
1382  result= my_rename_with_symlink(from, to, flags);
1383  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
1384  return result;
1385  }
1386 #endif
1387 
1388  result= my_rename_with_symlink(from, to, flags);
1389  return result;
1390 }
1391 
1392 static inline int
1393 inline_mysql_file_sync(
1394 #ifdef HAVE_PSI_FILE_INTERFACE
1395  const char *src_file, uint src_line,
1396 #endif
1397  File fd, myf flags)
1398 {
1399  int result= 0;
1400 #ifdef HAVE_PSI_FILE_INTERFACE
1401  struct PSI_file_locker *locker;
1402  PSI_file_locker_state state;
1403  locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)
1404  (&state, fd, PSI_FILE_SYNC);
1405  if (likely(locker != NULL))
1406  {
1407  PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line);
1408  result= my_sync(fd, flags);
1409  PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0);
1410  return result;
1411  }
1412 #endif
1413 
1414  result= my_sync(fd, flags);
1415  return result;
1416 }
1417 
1420 #endif
1421