MySQL  8.0.20
Source Code Documentation
os0file.h
Go to the documentation of this file.
1 /***********************************************************************
2 
3 Copyright (c) 1995, 2020, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2009, Percona Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted
7 by Percona Inc.. Those modifications are
8 gratefully acknowledged and are described briefly in the InnoDB
9 documentation. The contributions by Percona Inc. are incorporated with
10 their permission, and subject to the conditions contained in the file
11 COPYING.Percona.
12 
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License, version 2.0,
15 as published by the Free Software Foundation.
16 
17 This program is also distributed with certain software (including
18 but not limited to OpenSSL) that is licensed under separate terms,
19 as designated in a particular file or component or in included license
20 documentation. The authors of MySQL hereby grant you an additional
21 permission to link the program and your derivative works with the
22 separately licensed software that they have included with MySQL.
23 
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License, version 2.0, for more details.
28 
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 
33 ***********************************************************************/
34 
35 /** @file include/os0file.h
36  The interface to the operating system file io
37 
38  Created 10/21/1995 Heikki Tuuri
39  *******************************************************/
40 
41 #ifndef os0file_h
42 #define os0file_h
43 
44 #include "my_dbug.h"
45 #include "my_io.h"
46 
47 #include "os/file.h"
48 #include "os0atomic.h"
49 #include "os0enc.h"
50 
51 #ifndef _WIN32
52 #include <dirent.h>
53 #include <sys/stat.h>
54 #include <sys/statvfs.h>
55 #include <time.h>
56 #else
57 #include <Strsafe.h>
58 #include <locale>
59 #include <string>
60 #endif /* !_WIN32 */
61 
62 #include <functional>
63 #include <stack>
64 
65 /** Prefix all files and directory created under data directory with special
66 string so that it never conflicts with MySQL schema directory. */
67 #define OS_FILE_PREFIX "#"
68 
69 /** File node of a tablespace or the log data space */
70 struct fil_node_t;
71 
72 extern bool os_has_said_disk_full;
73 
74 /** Number of pending read operations */
75 extern ulint os_n_pending_reads;
76 /** Number of pending write operations */
77 extern ulint os_n_pending_writes;
78 
79 /* Flush after each os_fsync_threshold bytes */
80 extern unsigned long long os_fsync_threshold;
81 
82 /** File offset in bytes */
83 typedef ib_uint64_t os_offset_t;
84 
85 namespace file {
86 /** Blocks for doing IO, used in the transparent compression
87 and encryption code. */
88 struct Block {
89  /** Default constructor */
90  Block() : m_ptr(), m_in_use() {}
91 
93 
94  byte pad[INNOBASE_CACHE_LINE_SIZE - sizeof(ulint)];
96 };
97 } // namespace file
98 
99 #ifdef _WIN32
100 
101 typedef HANDLE os_file_dir_t; /*!< directory stream */
102 
103 /** We define always WIN_ASYNC_IO, and check at run-time whether
104 the OS actually supports it: Win 95 does not, NT does. */
105 #define WIN_ASYNC_IO
106 
107 /** Use unbuffered I/O */
108 #define UNIV_NON_BUFFERED_IO
109 
110 /** File handle */
111 #define os_file_t HANDLE
112 
113 /** Convert a C file descriptor to a native file handle
114 @param fd file descriptor
115 @return native file handle */
116 #define OS_FILE_FROM_FD(fd) (HANDLE) _get_osfhandle(fd)
117 
118 /** Associates a C file descriptor with an existing native file handle
119 @param[in] file native file handle
120 @return C file descriptor */
121 #define OS_FD_FROM_FILE(file) _open_osfhandle((intptr_t)file, _O_RDONLY)
122 
123 /** Closes the file associated with C file descriptor fd
124 @param[in] fd C file descriptor
125 @return 0 if success */
126 #define OS_FILE_CLOSE_FD(fd) _close(fd)
127 
128 #else /* _WIN32 */
129 
130 /** File handle */
131 typedef int os_file_t;
132 
133 /** Convert a C file descriptor to a native file handle
134 @param fd file descriptor
135 @return native file handle */
136 #define OS_FILE_FROM_FD(fd) fd
137 
138 /** C file descriptor from an existing native file handle
139 @param[in] file native file handle
140 @return C file descriptor */
141 #define OS_FD_FROM_FILE(file) file
142 
143 /** Closes the file associated with C file descriptor fd
144 @param[in] fd C file descriptor
145 @return 0 if success */
146 #define OS_FILE_CLOSE_FD(fd) (os_file_close(fd) ? 0 : -1)
147 
148 #endif /* _WIN32 */
149 
150 /** Common file descriptor for file IO instrumentation with PFS
151 on windows and other platforms */
153 #ifdef UNIV_PFS_IO
154  struct PSI_file *m_psi;
155 #else /* UNIV_PFS_IO */
156  pfs_os_file_t &operator=(os_file_t file) {
157  m_file = file;
158  return (*this);
159  }
160 #endif /* UNIV_PFS_IO */
161 
163 };
164 
165 static const os_file_t OS_FILE_CLOSED = os_file_t(~0);
166 
167 /** The next value should be smaller or equal to the smallest sector size used
168 on any disk. A log block is required to be a portion of disk which is written
169 so that if the start and the end of a block get written to disk, then the
170 whole block gets written. This should be true even in most cases of a crash:
171 if this fails for a log block, then it is equivalent to a media failure in the
172 log. */
173 
174 #define OS_FILE_LOG_BLOCK_SIZE 512
175 
176 /** Options for os_file_create_func @{ */
178  OS_FILE_OPEN = 51, /*!< to open an existing file (if
179  doesn't exist, error) */
180  OS_FILE_CREATE, /*!< to create new file (if
181  exists, error) */
182  OS_FILE_OPEN_RAW, /*!< to open a raw device or disk
183  partition */
184  OS_FILE_CREATE_PATH, /*!< to create the directories */
185  OS_FILE_OPEN_RETRY, /*!< open with retry */
186 
187  /** Flags that can be combined with the above values. Please ensure
188  that the above values stay below 128. */
189 
190  OS_FILE_ON_ERROR_NO_EXIT = 128, /*!< do not exit on unknown errors */
191  OS_FILE_ON_ERROR_SILENT = 256 /*!< don't print diagnostic messages to
192  the log unless it is a fatal error,
193  this flag is only used if
194  ON_ERROR_NO_EXIT is set */
195 };
196 
197 static const ulint OS_FILE_READ_ONLY = 333;
198 static const ulint OS_FILE_READ_WRITE = 444;
199 
200 /** Used by MySQLBackup */
201 static const ulint OS_FILE_READ_ALLOW_DELETE = 555;
202 
203 /* Options for file_create */
204 static const ulint OS_FILE_AIO = 61;
205 static const ulint OS_FILE_NORMAL = 62;
206 /* @} */
207 
208 /** Types for file create @{ */
209 static const ulint OS_DATA_FILE = 100;
210 static const ulint OS_LOG_FILE = 101;
211 /* Don't use this for Data files, Log files. Use it for smaller files
212 or if number of bytes to write are not multiple of sector size.
213 With this flag, writes to file will be always buffered and ignores the value
214 of innodb_flush_method. */
215 static const ulint OS_BUFFERED_FILE = 102;
216 
217 static const ulint OS_CLONE_DATA_FILE = 103;
218 static const ulint OS_CLONE_LOG_FILE = 104;
219 
220 /** Doublewrite files. */
221 static const ulint OS_DBLWR_FILE = 105;
222 
223 /** Redo log archive file. */
224 static const ulint OS_REDO_LOG_ARCHIVE_FILE = 105;
225 /* @} */
226 
227 /** Error codes from os_file_get_last_error @{ */
228 static const ulint OS_FILE_NOT_FOUND = 71;
229 static const ulint OS_FILE_DISK_FULL = 72;
230 static const ulint OS_FILE_ALREADY_EXISTS = 73;
231 static const ulint OS_FILE_PATH_ERROR = 74;
232 
233 /** wait for OS aio resources to become available again */
234 static const ulint OS_FILE_AIO_RESOURCES_RESERVED = 75;
235 
236 static const ulint OS_FILE_SHARING_VIOLATION = 76;
237 static const ulint OS_FILE_ERROR_NOT_SPECIFIED = 77;
238 static const ulint OS_FILE_INSUFFICIENT_RESOURCE = 78;
239 static const ulint OS_FILE_AIO_INTERRUPTED = 79;
240 static const ulint OS_FILE_OPERATION_ABORTED = 80;
241 static const ulint OS_FILE_ACCESS_VIOLATION = 81;
242 static const ulint OS_FILE_NAME_TOO_LONG = 82;
243 static const ulint OS_FILE_ERROR_MAX = 100;
244 /* @} */
245 
246 /** Types for AIO operations @{ */
247 
248 /** No transformations during read/write, write as is. */
249 #define IORequestRead IORequest(IORequest::READ)
250 #define IORequestWrite IORequest(IORequest::WRITE)
251 #define IORequestLogRead IORequest(IORequest::LOG | IORequest::READ)
252 #define IORequestLogWrite IORequest(IORequest::LOG | IORequest::WRITE)
253 
254 /**
255 The IO Context that is passed down to the low level IO code */
256 class IORequest {
257  public:
258  /** Flags passed in the request, they can be ORred together. */
259  enum {
260  UNSET = 0,
261  READ = 1,
262  WRITE = 2,
263 
264  /** Request for a doublewrite page IO */
265  DBLWR = 4,
266 
267  /** Enumerations below can be ORed to READ/WRITE above*/
268 
269  /** Data file */
270  DATA_FILE = 8,
271 
272  /** Log file request*/
273  LOG = 16,
274 
275  /** Disable partial read warnings */
276  DISABLE_PARTIAL_IO_WARNINGS = 32,
277 
278  /** Do not to wake i/o-handler threads, but the caller will do
279  the waking explicitly later, in this way the caller can post
280  several requests in a batch; NOTE that the batch must not be
281  so big that it exhausts the slots in AIO arrays! NOTE that
282  a simulated batch may introduce hidden chances of deadlocks,
283  because I/Os are not actually handled until all
284  have been posted: use with great caution! */
285  DO_NOT_WAKE = 64,
286 
287  /** Ignore failed reads of non-existent pages */
288  IGNORE_MISSING = 128,
289 
290  /** Use punch hole if available, only makes sense if
291  compression algorithm != NONE. Ignored if not set */
292  PUNCH_HOLE = 256,
293 
294  /** Force raw read, do not try to compress/decompress.
295  This can be used to force a read and write without any
296  compression e.g., for redo log, merge sort temporary files
297  and the truncate redo log. */
298  NO_COMPRESSION = 512
299  };
300 
301  /** Default constructor */
303  : m_block_size(UNIV_SECTOR_SIZE),
304  m_type(READ),
305  m_compression(),
306  m_encryption() {
307  /* No op */
308  }
309 
310  /**
311  @param[in] type Request type, can be a value that is
312  ORed from the above enum */
313  explicit IORequest(ulint type)
314  : m_block_size(UNIV_SECTOR_SIZE),
315  m_type(static_cast<uint16_t>(type)),
316  m_compression(),
317  m_encryption() {
318  if (is_log()) {
319  disable_compression();
320  }
321 
322  if (!is_punch_hole_supported()) {
323  clear_punch_hole();
324  }
325  }
326 
327  /** @return true if ignore missing flag is set */
328  static bool ignore_missing(ulint type) MY_ATTRIBUTE((warn_unused_result)) {
329  return ((type & IGNORE_MISSING) == IGNORE_MISSING);
330  }
331 
332  /** @return true if it is a read request */
333  bool is_read() const MY_ATTRIBUTE((warn_unused_result)) {
334  return ((m_type & READ) == READ);
335  }
336 
337  /** @return true if it is a write request */
338  bool is_write() const MY_ATTRIBUTE((warn_unused_result)) {
339  return ((m_type & WRITE) == WRITE);
340  }
341 
342  /** @return true if it is a redo log write */
343  bool is_log() const MY_ATTRIBUTE((warn_unused_result)) {
344  return ((m_type & LOG) == LOG);
345  }
346 
347  /** @return true if the simulated AIO thread should be woken up */
348  bool is_wake() const MY_ATTRIBUTE((warn_unused_result)) {
349  return ((m_type & DO_NOT_WAKE) == 0);
350  }
351 
352  /** @return true if partial read warning disabled */
354  MY_ATTRIBUTE((warn_unused_result)) {
355  return ((m_type & DISABLE_PARTIAL_IO_WARNINGS) ==
356  DISABLE_PARTIAL_IO_WARNINGS);
357  }
358 
359  /** Disable partial read warnings */
360  void disable_partial_io_warnings() { m_type |= DISABLE_PARTIAL_IO_WARNINGS; }
361 
362  /** @return true if missing files should be ignored */
363  bool ignore_missing() const MY_ATTRIBUTE((warn_unused_result)) {
364  return (ignore_missing(m_type));
365  }
366 
367  /** @return true if punch hole should be used */
368  bool punch_hole() const MY_ATTRIBUTE((warn_unused_result)) {
369  return ((m_type & PUNCH_HOLE) == PUNCH_HOLE);
370  }
371 
372  /** @return true if the read should be validated */
373  bool validate() const MY_ATTRIBUTE((warn_unused_result)) {
374  ut_a(is_read() ^ is_write());
375 
376  return (!is_read() || !punch_hole());
377  }
378 
379  /** Set the punch hole flag */
380  void set_punch_hole() {
381  if (is_punch_hole_supported()) {
382  m_type |= PUNCH_HOLE;
383  }
384  }
385 
386  /** Clear the do not wake flag */
387  void clear_do_not_wake() { m_type &= ~DO_NOT_WAKE; }
388 
389  /** Clear the punch hole flag */
390  void clear_punch_hole() { m_type &= ~PUNCH_HOLE; }
391 
392  /** @return the block size to use for IO */
393  ulint block_size() const MY_ATTRIBUTE((warn_unused_result)) {
394  return (m_block_size);
395  }
396 
397  /** Set the block size for IO
398  @param[in] block_size Block size to set */
399  void block_size(ulint block_size) {
400  m_block_size = static_cast<uint32_t>(block_size);
401  }
402 
403  /** Clear all compression related flags */
405  clear_punch_hole();
406 
407  m_compression.m_type = Compression::NONE;
408  }
409 
410  /** Compare two requests
411  @return true if the are equal */
412  bool operator==(const IORequest &rhs) const { return (m_type == rhs.m_type); }
413 
414  /** Set compression algorithm
415  @param[in] type The compression algorithm to use */
417  if (type == Compression::NONE) {
418  return;
419  }
420 
421  set_punch_hole();
422 
423  m_compression.m_type = type;
424  }
425 
426  /** Get the compression algorithm.
427  @return the compression algorithm */
428  Compression compression_algorithm() const MY_ATTRIBUTE((warn_unused_result)) {
429  return (m_compression);
430  }
431 
432  /** @return true if the page should be compressed */
433  bool is_compressed() const MY_ATTRIBUTE((warn_unused_result)) {
434  return (compression_algorithm().m_type != Compression::NONE);
435  }
436 
437  /** @return true if the page read should not be transformed. */
438  bool is_compression_enabled() const MY_ATTRIBUTE((warn_unused_result)) {
439  return ((m_type & NO_COMPRESSION) == 0);
440  }
441 
442  /** Disable transformations. */
443  void disable_compression() { m_type |= NO_COMPRESSION; }
444 
445  /** Set encryption algorithm
446  @param[in] type The encryption algorithm to use */
448  if (type == Encryption::NONE) {
449  return;
450  }
451 
452  m_encryption.set_type(type);
453  }
454 
455  /** Set encryption key and iv
456  @param[in] key The encryption key to use
457  @param[in] key_len length of the encryption key
458  @param[in] iv The encryption iv to use */
459  void encryption_key(byte *key, ulint key_len, byte *iv) {
460  m_encryption.set_key(key);
461  m_encryption.set_key_length(key_len);
462  m_encryption.set_initial_vector(iv);
463  }
464 
465  /** Get the encryption algorithm.
466  @return the encryption algorithm */
467  Encryption encryption_algorithm() const MY_ATTRIBUTE((warn_unused_result)) {
468  return (m_encryption);
469  }
470 
471  /** @return true if the page should be encrypted. */
472  bool is_encrypted() const MY_ATTRIBUTE((warn_unused_result)) {
473  return (m_encryption.get_type() != Encryption::NONE);
474  }
475 
476  /** Clear all encryption related flags */
478  m_encryption.set_key(nullptr);
479  m_encryption.set_key_length(0);
480  m_encryption.set_initial_vector(nullptr);
481  m_encryption.set_type(Encryption::NONE);
482  }
483 
484  /** Note that the IO is for double write buffer page write. */
485  void dblwr() { m_type |= DBLWR; }
486 
487  /** @return true if the request is for a dblwr page. */
488  bool is_dblwr() const MY_ATTRIBUTE((warn_unused_result)) {
489  return ((m_type & DBLWR) == DBLWR);
490  }
491 
492  /** @return true if punch hole is supported */
493  static bool is_punch_hole_supported() {
494  /* In this debugging mode, we act as if punch hole is supported,
495  and then skip any calls to actually punch a hole here.
496  In this way, Transparent Page Compression is still being tested. */
497  DBUG_EXECUTE_IF("ignore_punch_hole", return (true););
498 
499 #if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32)
500  return (true);
501 #else
502  return (false);
503 #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE || _WIN32 */
504  }
505 
506  /** @return string representation. */
507  std::string to_string() const {
509 
510  os << "bs: " << m_block_size << " flags:";
511 
512  if (m_type & READ) {
513  os << " READ";
514  } else if (m_type & WRITE) {
515  os << " WRITE";
516  } else if (m_type & DBLWR) {
517  os << " DBLWR";
518  }
519 
520  /** Enumerations below can be ORed to READ/WRITE above*/
521 
522  /** Data file */
523  if (m_type & DATA_FILE) {
524  os << " | DATA_FILE";
525  }
526 
527  if (m_type & LOG) {
528  os << " | LOG";
529  }
530 
531  if (m_type & DISABLE_PARTIAL_IO_WARNINGS) {
532  os << " | DISABLE_PARTIAL_IO_WARNINGS";
533  }
534 
535  if (m_type & DO_NOT_WAKE) {
536  os << " | IGNORE_MISSING";
537  }
538 
539  if (m_type & PUNCH_HOLE) {
540  os << " | PUNCH_HOLE";
541  }
542 
543  if (m_type & NO_COMPRESSION) {
544  os << " | NO_COMPRESSION";
545  }
546 
547  os << ", comp: " << m_compression.to_string();
548  os << ", enc: " << m_encryption.to_string(m_encryption.get_type());
549 
550  return (os.str());
551  }
552 
553  private:
554  /* File system best block size */
555  uint32_t m_block_size;
556 
557  /** Request type bit flags */
558  uint16_t m_type;
559 
560  /** Compression algorithm */
562 
563  /** Encryption algorithm */
565 };
566 
567 /* @} */
568 
569 /** Sparse file size information. */
571  /** Total size of file in bytes */
573 
574  /** If it is a sparse file then this is the number of bytes
575  actually allocated for the file. */
577 };
578 
579 /** Win NT does not allow more than 64 */
580 static const ulint OS_AIO_N_PENDING_IOS_PER_THREAD = 32;
581 
582 /** Modes for aio operations @{ */
583 enum class AIO_mode : size_t {
584  /** Normal asynchronous i/o not for ibuf pages or ibuf bitmap pages */
585  NORMAL = 21,
586 
587  /** Asynchronous i/o for ibuf pages or ibuf bitmap pages */
588  IBUF = 22,
589 
590  /** Asynchronous i/o for the log */
591  LOG = 23,
592 
593  /** Asynchronous i/o where the calling thread will itself wait for
594  the i/o to complete, doing also the job of the i/o-handler thread;
595  can be used for any pages, ibuf or non-ibuf. This is used to save
596  CPU time, as we can do with fewer thread switches. Plain synchronous
597  I/O is not as good, because it must serialize the file seek and read
598  or write, causing a bottleneck for parallelism. */
599  SYNC = 24
600 };
601 /* @} */
602 
603 extern ulint os_n_file_reads;
604 extern ulint os_n_file_writes;
605 extern ulint os_n_fsyncs;
606 
607 /* File types for directory entry data type */
608 
610  /** Get status failed. */
612 
613  /** stat() failed, with ENAMETOOLONG */
615 
616  /** stat() failed with EACCESS */
618 
619  /** File doesn't exist. */
621 
622  /** File exists but type is unknown. */
624 
625  /** Ordinary file. */
627 
628  /** Directory. */
630 
631  /** Symbolic link. */
633 
634  /** Block device. */
636 };
637 
638 /* Maximum path string length in bytes when referring to tables with in the
639 './databasename/tablename.ibd' path format; we can allocate at least 2 buffers
640 of this size from the thread stack; that is why this should not be made much
641 bigger than 4000 bytes. The maximum path length used by any storage engine
642 in the server must be at least this big. */
643 #define OS_FILE_MAX_PATH 4000
644 #if (FN_REFLEN_SE < OS_FILE_MAX_PATH)
645 #error "(FN_REFLEN_SE < OS_FILE_MAX_PATH)"
646 #endif
647 
648 /** Struct used in fetching information of a file in a directory */
650  char name[OS_FILE_MAX_PATH]; /*!< path to a file */
651  os_file_type_t type; /*!< file type */
652  os_offset_t size; /*!< file size in bytes */
653  os_offset_t alloc_size; /*!< Allocated size for
654  sparse files in bytes */
655  uint32_t block_size; /*!< Block size to use for IO
656  in bytes*/
657  time_t ctime; /*!< creation time */
658  time_t mtime; /*!< modification time */
659  time_t atime; /*!< access time */
660  bool rw_perm; /*!< true if can be opened
661  in read-write mode. Only valid
662  if type == OS_FILE_TYPE_FILE */
663 };
664 
665 #ifndef UNIV_HOTBACKUP
666 /** Create a temporary file. This function is like tmpfile(3), but
667 the temporary file is created in the given parameter path. If the path
668 is null then it will create the file in the mysql server configuration
669 parameter (--tmpdir).
670 @param[in] path location for creating temporary file
671 @return temporary file handle, or NULL on error */
672 FILE *os_file_create_tmpfile(const char *path);
673 #endif /* !UNIV_HOTBACKUP */
674 
675 /**
676 This function attempts to create a directory named pathname. The new directory
677 gets default permissions. On Unix, the permissions are (0770 & ~umask). If the
678 directory exists already, nothing is done and the call succeeds, unless the
679 fail_if_exists arguments is true.
680 
681 @param[in] pathname directory name as null-terminated string
682 @param[in] fail_if_exists if true, pre-existing directory is treated
683  as an error.
684 @return true if call succeeds, false on error */
685 bool os_file_create_directory(const char *pathname, bool fail_if_exists);
686 
687 /** Callback function type to be implemented by caller. It is called for each
688 entry in directory.
689 @param[in] path path to the file
690 @param[in] name name of the file */
691 typedef void (*os_dir_cbk_t)(const char *path, const char *name);
692 
693 /** This function scans the contents of a directory and invokes the callback
694 for each entry.
695 @param[in] path directory name as null-terminated string
696 @param[in] scan_cbk use callback to be called for each entry
697 @param[in] is_drop attempt to drop the directory after scan
698 @return true if call succeeds, false on error */
699 bool os_file_scan_directory(const char *path, os_dir_cbk_t scan_cbk,
700  bool is_drop);
701 
702 /** NOTE! Use the corresponding macro os_file_create_simple(), not directly
703 this function!
704 A simple function to open or create a file.
705 @param[in] name name of the file or path as a null-terminated
706  string
707 @param[in] create_mode create mode
708 @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE
709 @param[in] read_only if true read only mode checks are enforced
710 @param[out] success true if succeed, false if error
711 @return own: handle to the file, not defined if error, error number
712  can be retrieved with os_file_get_last_error */
713 os_file_t os_file_create_simple_func(const char *name, ulint create_mode,
714  ulint access_type, bool read_only,
715  bool *success);
716 
717 /** NOTE! Use the corresponding macro
718 os_file_create_simple_no_error_handling(), not directly this function!
719 A simple function to open or create a file.
720 @param[in] name name of the file or path as a
721 null-terminated string
722 @param[in] create_mode create mode
723 @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
724  OS_FILE_READ_ALLOW_DELETE; the last option
725  is used by a backup program reading the file
726 @param[in] read_only if true read only mode checks are enforced
727 @param[out] success true if succeeded
728 @return own: handle to the file, not defined if error, error number
729  can be retrieved with os_file_get_last_error */
731  const char *name, ulint create_mode, ulint access_type, bool read_only,
732  bool *success) MY_ATTRIBUTE((warn_unused_result));
733 
734 /** Tries to disable OS caching on an opened file descriptor.
735 @param[in] fd file descriptor to alter
736 @param[in] file_name file name, used in the diagnostic message
737 @param[in] operation_name "open" or "create"; used in the diagnostic
738  message */
739 void os_file_set_nocache(int fd, const char *file_name,
740  const char *operation_name);
741 
742 /** NOTE! Use the corresponding macro os_file_create(), not directly
743 this function!
744 Opens an existing file or creates a new.
745 @param[in] name name of the file or path as a null-terminated
746  string
747 @param[in] create_mode create mode
748 @param[in] purpose OS_FILE_AIO, if asynchronous, non-buffered I/O
749  is desired, OS_FILE_NORMAL, if any normal file;
750  NOTE that it also depends on type, os_aio_..
751  and srv_.. variables whether we really use
752  async I/O or unbuffered I/O: look in the
753  function source code for the exact rules
754 @param[in] type OS_DATA_FILE, OS_LOG_FILE etc.
755 @param[in] read_only if true read only mode checks are enforced
756 @param[in] success true if succeeded
757 @return own: handle to the file, not defined if error, error number
758  can be retrieved with os_file_get_last_error */
759 pfs_os_file_t os_file_create_func(const char *name, ulint create_mode,
760  ulint purpose, ulint type, bool read_only,
761  bool *success)
762  MY_ATTRIBUTE((warn_unused_result));
763 
764 /** Deletes a file. The file has to be closed before calling this.
765 @param[in] name file path as a null-terminated string
766 @return true if success */
767 bool os_file_delete_func(const char *name);
768 
769 /** Deletes a file if it exists. The file has to be closed before calling this.
770 @param[in] name file path as a null-terminated string
771 @param[out] exist indicate if file pre-exist
772 @return true if success */
773 bool os_file_delete_if_exists_func(const char *name, bool *exist);
774 
775 /** NOTE! Use the corresponding macro os_file_rename(), not directly
776 this function!
777 Renames a file (can also move it to another directory). It is safest that the
778 file is closed before calling this function.
779 @param[in] oldpath old file path as a null-terminated string
780 @param[in] newpath new file path
781 @return true if success */
782 bool os_file_rename_func(const char *oldpath, const char *newpath);
783 
784 /** NOTE! Use the corresponding macro os_file_close(), not directly this
785 function!
786 Closes a file handle. In case of error, error number can be retrieved with
787 os_file_get_last_error.
788 @param[in] file own: handle to a file
789 @return true if success */
791 
792 #ifdef UNIV_PFS_IO
793 
794 /* Keys to register InnoDB I/O with performance schema */
802 
803 /* Following four macros are instumentations to register
804 various file I/O operations with performance schema.
805 1) register_pfs_file_open_begin() and register_pfs_file_open_end() are
806 used to register file creation, opening and closing.
807 2) register_pfs_file_rename_begin() and register_pfs_file_rename_end()
808 are used to register file renaming.
809 3) register_pfs_file_io_begin() and register_pfs_file_io_end() are
810 used to register actual file read, write and flush
811 4) register_pfs_file_close_begin() and register_pfs_file_close_end()
812 are used to register file deletion operations*/
813 #define register_pfs_file_open_begin(state, locker, key, op, name, src_file, \
814  src_line) \
815  do { \
816  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
817  op, name, &locker); \
818  if (locker != nullptr) { \
819  PSI_FILE_CALL(start_file_open_wait) \
820  (locker, src_file, static_cast<uint>(src_line)); \
821  } \
822  } while (0)
823 
824 #define register_pfs_file_open_end(locker, file, result) \
825  do { \
826  if (locker != nullptr) { \
827  file.m_psi = PSI_FILE_CALL(end_file_open_wait)(locker, result); \
828  } \
829  } while (0)
830 
831 #define register_pfs_file_rename_begin(state, locker, key, op, from, to, \
832  src_file, src_line) \
833  do { \
834  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
835  op, from, &locker); \
836  if (locker != nullptr) { \
837  PSI_FILE_CALL(start_file_rename_wait) \
838  (locker, (size_t)0, from, to, src_file, static_cast<uint>(src_line)); \
839  } \
840  } while (0)
841 
842 #define register_pfs_file_rename_end(locker, from, to, result) \
843  do { \
844  if (locker != nullptr) { \
845  PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result); \
846  } \
847  } while (0)
848 
849 #define register_pfs_file_close_begin(state, locker, key, op, name, src_file, \
850  src_line) \
851  do { \
852  locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
853  op, name, &locker); \
854  if (locker != nullptr) { \
855  PSI_FILE_CALL(start_file_close_wait) \
856  (locker, src_file, static_cast<uint>(src_line)); \
857  } \
858  } while (0)
859 
860 #define register_pfs_file_close_end(locker, result) \
861  do { \
862  if (locker != nullptr) { \
863  PSI_FILE_CALL(end_file_close_wait)(locker, result); \
864  } \
865  } while (0)
866 
867 #define register_pfs_file_io_begin(state, locker, file, count, op, src_file, \
868  src_line) \
869  do { \
870  locker = \
871  PSI_FILE_CALL(get_thread_file_stream_locker)(state, file.m_psi, op); \
872  if (locker != nullptr) { \
873  PSI_FILE_CALL(start_file_wait) \
874  (locker, count, src_file, static_cast<uint>(src_line)); \
875  } \
876  } while (0)
877 
878 #define register_pfs_file_io_end(locker, count) \
879  do { \
880  if (locker != nullptr) { \
881  PSI_FILE_CALL(end_file_wait)(locker, count); \
882  } \
883  } while (0)
884 
885 /* Following macros/functions are file I/O APIs that would be performance
886 schema instrumented if "UNIV_PFS_IO" is defined. They would point to
887 wrapper functions with performance schema instrumentation in such case.
888 
889 os_file_create
890 os_file_create_simple
891 os_file_create_simple_no_error_handling
892 os_file_close
893 os_file_rename
894 os_aio
895 os_file_read
896 os_file_read_no_error_handling
897 os_file_read_no_error_handling_int_fd
898 os_file_write
899 
900 The wrapper functions have the prefix of "innodb_". */
901 
902 #define os_file_create(key, name, create, purpose, type, read_only, success) \
903  pfs_os_file_create_func(key, name, create, purpose, type, read_only, \
904  success, __FILE__, __LINE__)
905 
906 #define os_file_create_simple(key, name, create, access, read_only, success) \
907  pfs_os_file_create_simple_func(key, name, create, access, read_only, \
908  success, __FILE__, __LINE__)
909 
910 #define os_file_create_simple_no_error_handling(key, name, create_mode, \
911  access, read_only, success) \
912  pfs_os_file_create_simple_no_error_handling_func( \
913  key, name, create_mode, access, read_only, success, __FILE__, __LINE__)
914 
915 #define os_file_close_pfs(file) pfs_os_file_close_func(file, __FILE__, __LINE__)
916 
917 #define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
918  message2) \
919  pfs_os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
920  message2, __FILE__, __LINE__)
921 
922 #define os_file_read_pfs(type, file_name, file, buf, offset, n) \
923  pfs_os_file_read_func(type, file_name, file, buf, offset, n, __FILE__, \
924  __LINE__)
925 
926 #define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
927  pfs_os_file_read_first_page_func(type, file_name, file, buf, n, __FILE__, \
928  __LINE__)
929 
930 #define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
931  pfs_os_file_copy_func(src, src_offset, dest, dest_offset, size, __FILE__, \
932  __LINE__)
933 
934 #define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
935  n, o) \
936  pfs_os_file_read_no_error_handling_func(type, file_name, file, buf, offset, \
937  n, o, __FILE__, __LINE__)
938 
939 #define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
940  offset, n, o) \
941  pfs_os_file_read_no_error_handling_int_fd_func( \
942  type, file_name, file, buf, offset, n, o, __FILE__, __LINE__)
943 
944 #define os_file_write_pfs(type, name, file, buf, offset, n) \
945  pfs_os_file_write_func(type, name, file, buf, offset, n, __FILE__, __LINE__)
946 
947 #define os_file_write_int_fd(type, name, file, buf, offset, n) \
948  pfs_os_file_write_int_fd_func(type, name, file, buf, offset, n, __FILE__, \
949  __LINE__)
950 
951 #define os_file_flush_pfs(file) pfs_os_file_flush_func(file, __FILE__, __LINE__)
952 
953 #define os_file_rename(key, oldpath, newpath) \
954  pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__)
955 
956 #define os_file_delete(key, name) \
957  pfs_os_file_delete_func(key, name, __FILE__, __LINE__)
958 
959 #define os_file_delete_if_exists(key, name, exist) \
960  pfs_os_file_delete_if_exists_func(key, name, exist, __FILE__, __LINE__)
961 
962 /** NOTE! Please use the corresponding macro os_file_create_simple(),
963 not directly this function!
964 A performance schema instrumented wrapper function for
965 os_file_create_simple() which opens or creates a file.
966 @param[in] key Performance Schema Key
967 @param[in] name name of the file or path as a null-terminated
968  string
969 @param[in] create_mode create mode
970 @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE
971 @param[in] read_only if true read only mode checks are enforced
972 @param[out] success true if succeeded
973 @param[in] src_file file name where func invoked
974 @param[in] src_line line where the func invoked
975 @return own: handle to the file, not defined if error, error number
976  can be retrieved with os_file_get_last_error */
977 UNIV_INLINE
979  mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type,
980  bool read_only, bool *success, const char *src_file, uint src_line)
981  MY_ATTRIBUTE((warn_unused_result));
982 
983 /** NOTE! Please use the corresponding macro
984 os_file_create_simple_no_error_handling(), not directly this function!
985 A performance schema instrumented wrapper function for
986 os_file_create_simple_no_error_handling(). Add instrumentation to
987 monitor file creation/open.
988 @param[in] key Performance Schema Key
989 @param[in] name name of the file or path as a null-terminated
990  string
991 @param[in] create_mode create mode
992 @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
993  OS_FILE_READ_ALLOW_DELETE; the last option is
994  used by a backup program reading the file
995 @param[in] read_only if true read only mode checks are enforced
996 @param[out] success true if succeeded
997 @param[in] src_file file name where func invoked
998 @param[in] src_line line where the func invoked
999 @return own: handle to the file, not defined if error, error number
1000  can be retrieved with os_file_get_last_error */
1001 UNIV_INLINE
1003  mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type,
1004  bool read_only, bool *success, const char *src_file, uint src_line)
1005  MY_ATTRIBUTE((warn_unused_result));
1006 
1007 /** NOTE! Please use the corresponding macro os_file_create(), not directly
1008 this function!
1009 A performance schema wrapper function for os_file_create().
1010 Add instrumentation to monitor file creation/open.
1011 @param[in] key Performance Schema Key
1012 @param[in] name name of the file or path as a null-terminated
1013  string
1014 @param[in] create_mode create mode
1015 @param[in] purpose OS_FILE_AIO, if asynchronous, non-buffered I/O
1016  is desired, OS_FILE_NORMAL, if any normal file;
1017  NOTE that it also depends on type, os_aio_..
1018  and srv_.. variables whether we really use
1019  async I/O or unbuffered I/O: look in the
1020  function source code for the exact rules
1021 @param[in] type OS_DATA_FILE or OS_LOG_FILE
1022 @param[in] read_only if true read only mode checks are enforced
1023 @param[out] success true if succeeded
1024 @param[in] src_file file name where func invoked
1025 @param[in] src_line line where the func invoked
1026 @return own: handle to the file, not defined if error, error number
1027  can be retrieved with os_file_get_last_error */
1028 UNIV_INLINE
1030  ulint create_mode, ulint purpose,
1031  ulint type, bool read_only, bool *success,
1032  const char *src_file, uint src_line)
1033  MY_ATTRIBUTE((warn_unused_result));
1034 
1035 /** NOTE! Please use the corresponding macro os_file_close(), not directly
1036 this function!
1037 A performance schema instrumented wrapper function for os_file_close().
1038 @param[in] file handle to a file
1039 @param[in] src_file file name where func invoked
1040 @param[in] src_line line where the func invoked
1041 @return true if success */
1042 UNIV_INLINE
1043 bool pfs_os_file_close_func(pfs_os_file_t file, const char *src_file,
1044  uint src_line);
1045 
1046 /** NOTE! Please use the corresponding macro os_file_read(), not directly
1047 this function!
1048 This is the performance schema instrumented wrapper function for
1049 os_file_read() which requests a synchronous read operation.
1050 @param[in, out] type IO request context
1051 @param[in] file_name file name
1052 @param[in] file Open file handle
1053 @param[out] buf buffer where to read
1054 @param[in] offset file offset where to read
1055 @param[in] n number of bytes to read
1056 @param[in] src_file file name where func invoked
1057 @param[in] src_line line where the func invoked
1058 @return DB_SUCCESS if request was successful */
1059 UNIV_INLINE
1060 dberr_t pfs_os_file_read_func(IORequest &type, const char *file_name,
1061  pfs_os_file_t file, void *buf, os_offset_t offset,
1062  ulint n, const char *src_file, uint src_line);
1063 
1064 /** NOTE! Please use the corresponding macro os_file_read_first_page(),
1065 not directly this function!
1066 This is the performance schema instrumented wrapper function for
1067 os_file_read_first_page() which requests a synchronous read operation
1068 of page 0 of IBD file
1069 @param[in, out] type IO request context
1070 @param[in] file_name file name
1071 @param[in] file Open file handle
1072 @param[out] buf buffer where to read
1073 @param[in] n number of bytes to read
1074 @param[in] src_file file name where func invoked
1075 @param[in] src_line line where the func invoked
1076 @return DB_SUCCESS if request was successful */
1077 UNIV_INLINE
1078 dberr_t pfs_os_file_read_first_page_func(IORequest &type, const char *file_name,
1079  pfs_os_file_t file, void *buf, ulint n,
1080  const char *src_file, uint src_line);
1081 
1082 /** copy data from one file to another file. Data is read/written
1083 at current file offset.
1084 @param[in] src file handle to copy from
1085 @param[in] src_offset offset to copy from
1086 @param[in] dest file handle to copy to
1087 @param[in] dest_offset offset to copy to
1088 @param[in] size number of bytes to copy
1089 @param[in] src_file file name where func invoked
1090 @param[in] src_line line where the func invoked
1091 @return DB_SUCCESS if successful */
1092 UNIV_INLINE
1094  pfs_os_file_t dest, os_offset_t dest_offset,
1095  uint size, const char *src_file, uint src_line);
1096 
1097 /** NOTE! Please use the corresponding macro os_file_read_no_error_handling(),
1098 not directly this function!
1099 This is the performance schema instrumented wrapper function for
1100 os_file_read_no_error_handling_func() which requests a synchronous
1101 read operation.
1102 @param[in, out] type IO request context
1103 @param[in] file_name file name
1104 @param[in] file Open file handle
1105 @param[out] buf buffer where to read
1106 @param[in] offset file offset where to read
1107 @param[in] n number of bytes to read
1108 @param[out] o number of bytes actually read
1109 @param[in] src_file file name where func invoked
1110 @param[in] src_line line where the func invoked
1111 @return DB_SUCCESS if request was successful */
1112 UNIV_INLINE
1114  IORequest &type, const char *file_name, pfs_os_file_t file, void *buf,
1115  os_offset_t offset, ulint n, ulint *o, const char *src_file, uint src_line);
1116 
1117 /** NOTE! Please use the corresponding macro
1118 os_file_read_no_error_handling_int_fd(), not directly this function!
1119 This is the performance schema instrumented wrapper function for
1120 os_file_read_no_error_handling_int_fd_func() which requests a
1121 synchronous read operation on files with int type descriptors.
1122 @param[in, out] type IO request context
1123 @param[in] file_name file name
1124 @param[in] file Open file handle
1125 @param[out] buf buffer where to read
1126 @param[in] offset file offset where to read
1127 @param[in] n number of bytes to read
1128 @param[out] o number of bytes actually read
1129 @param[in] src_file file name where func invoked
1130 @param[in] src_line line where the func invoked
1131 @return DB_SUCCESS if request was successful */
1132 
1133 UNIV_INLINE
1135  IORequest &type, const char *file_name, int file, void *buf,
1136  os_offset_t offset, ulint n, ulint *o, const char *src_file,
1137  ulint src_line);
1138 
1139 /** NOTE! Please use the corresponding macro os_aio(), not directly this
1140 function!
1141 Performance schema wrapper function of os_aio() which requests
1142 an asynchronous I/O operation.
1143 @param[in] type IO request context
1144 @param[in] mode IO mode
1145 @param[in] name Name of the file or path as NUL terminated
1146  string
1147 @param[in] file Open file handle
1148 @param[out] buf buffer where to read
1149 @param[in] offset file offset where to read
1150 @param[in] n number of bytes to read
1151 @param[in] read_only if true read only mode checks are enforced
1152 @param[in,out] m1 Message for the AIO handler, (can be used to
1153  identify a completed AIO operation); ignored
1154  if mode is OS_AIO_SYNC
1155 @param[in,out] m2 message for the AIO handler (can be used to
1156  identify a completed AIO operation); ignored
1157  if mode is OS_AIO_SYNC
1158 @param[in] src_file file name where func invoked
1159 @param[in] src_line line where the func invoked
1160 @return DB_SUCCESS if request was queued successfully, false if fail */
1161 UNIV_INLINE
1162 dberr_t pfs_os_aio_func(IORequest &type, AIO_mode mode, const char *name,
1163  pfs_os_file_t file, void *buf, os_offset_t offset,
1164  ulint n, bool read_only, fil_node_t *m1, void *m2,
1165  const char *src_file, uint src_line);
1166 
1167 /** NOTE! Please use the corresponding macro os_file_write(), not directly
1168 this function!
1169 This is the performance schema instrumented wrapper function for
1170 os_file_write() which requests a synchronous write operation.
1171 @param[in, out] type IO request context
1172 @param[in] name Name of the file or path as NUL terminated
1173  string
1174 @param[in] file Open file handle
1175 @param[out] buf buffer where to read
1176 @param[in] offset file offset where to read
1177 @param[in] n number of bytes to read
1178 @param[in] src_file file name where func invoked
1179 @param[in] src_line line where the func invoked
1180 @return DB_SUCCESS if request was successful */
1181 UNIV_INLINE
1183  pfs_os_file_t file, const void *buf,
1184  os_offset_t offset, ulint n,
1185  const char *src_file, uint src_line);
1186 
1187 /** NOTE! Please use the corresponding macro os_file_write(), not
1188 directly this function!
1189 This is the performance schema instrumented wrapper function for
1190 os_file_write() which requests a synchronous write operation
1191 on files with int type descriptors.
1192 @param[in, out] type IO request context
1193 @param[in] name Name of the file or path as NUL terminated
1194  string
1195 @param[in] file Open file handle
1196 @param[out] buf buffer where to read
1197 @param[in] offset file offset where to read
1198 @param[in] n number of bytes to read
1199 @param[in] src_file file name where func invoked
1200 @param[in] src_line line where the func invoked
1201 @return DB_SUCCESS if request was successful */
1202 UNIV_INLINE
1204  int file, const void *buf,
1205  os_offset_t offset, ulint n,
1206  const char *src_file, ulint src_line);
1207 
1208 /** NOTE! Please use the corresponding macro os_file_flush(), not directly
1209 this function!
1210 This is the performance schema instrumented wrapper function for
1211 os_file_flush() which flushes the write buffers of a given file to the disk.
1212 Flushes the write buffers of a given file to the disk.
1213 @param[in] file Open file handle
1214 @param[in] src_file file name where func invoked
1215 @param[in] src_line line where the func invoked
1216 @return true if success */
1217 UNIV_INLINE
1218 bool pfs_os_file_flush_func(pfs_os_file_t file, const char *src_file,
1219  uint src_line);
1220 
1221 /** NOTE! Please use the corresponding macro os_file_rename(), not directly
1222 this function!
1223 This is the performance schema instrumented wrapper function for
1224 os_file_rename()
1225 @param[in] key Performance Schema Key
1226 @param[in] oldpath old file path as a null-terminated string
1227 @param[in] newpath new file path
1228 @param[in] src_file file name where func invoked
1229 @param[in] src_line line where the func invoked
1230 @return true if success */
1231 UNIV_INLINE
1232 bool pfs_os_file_rename_func(mysql_pfs_key_t key, const char *oldpath,
1233  const char *newpath, const char *src_file,
1234  uint src_line);
1235 
1236 /**
1237 NOTE! Please use the corresponding macro os_file_delete(), not directly
1238 this function!
1239 This is the performance schema instrumented wrapper function for
1240 os_file_delete()
1241 @param[in] key Performance Schema Key
1242 @param[in] name old file path as a null-terminated string
1243 @param[in] src_file file name where func invoked
1244 @param[in] src_line line where the func invoked
1245 @return true if success */
1246 UNIV_INLINE
1248  const char *src_file, uint src_line);
1249 
1250 /**
1251 NOTE! Please use the corresponding macro os_file_delete_if_exists(), not
1252 directly this function!
1253 This is the performance schema instrumented wrapper function for
1254 os_file_delete_if_exists()
1255 @param[in] key Performance Schema Key
1256 @param[in] name old file path as a null-terminated string
1257 @param[in] exist indicate if file pre-exist
1258 @param[in] src_file file name where func invoked
1259 @param[in] src_line line where the func invoked
1260 @return true if success */
1261 UNIV_INLINE
1263  bool *exist, const char *src_file,
1264  uint src_line);
1265 
1266 #else /* UNIV_PFS_IO */
1267 
1268 /* If UNIV_PFS_IO is not defined, these I/O APIs point
1269 to original un-instrumented file I/O APIs */
1270 #define os_file_create(key, name, create, purpose, type, read_only, success) \
1271  os_file_create_func(name, create, purpose, type, read_only, success)
1272 
1273 #define os_file_create_simple(key, name, create_mode, access, read_only, \
1274  success) \
1275  os_file_create_simple_func(name, create_mode, access, read_only, success)
1276 
1277 #define os_file_create_simple_no_error_handling(key, name, create_mode, \
1278  access, read_only, success) \
1279  os_file_create_simple_no_error_handling_func(name, create_mode, access, \
1280  read_only, success)
1281 
1282 #define os_file_close_pfs(file) os_file_close_func(file)
1283 
1284 #define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
1285  message2) \
1286  os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
1287  message2)
1288 
1289 #define os_file_read_pfs(type, file_name, file, buf, offset, n) \
1290  os_file_read_func(type, file_name, file, buf, offset, n)
1291 
1292 #define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
1293  os_file_read_first_page_func(type, file_name, file, buf, n)
1294 
1295 #define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
1296  os_file_copy_func(src, src_offset, dest, dest_offset, size)
1297 
1298 #define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
1299  n, o) \
1300  os_file_read_no_error_handling_func(type, file_name, file, buf, offset, n, o)
1301 
1302 #define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
1303  offset, n, o) \
1304  os_file_read_no_error_handling_func(type, file_name, file, buf, offset, n, o)
1305 
1306 #define os_file_write_pfs(type, name, file, buf, offset, n) \
1307  os_file_write_func(type, name, file, buf, offset, n)
1308 
1309 #define os_file_write_int_fd(type, name, file, buf, offset, n) \
1310  os_file_write_func(type, name, file, buf, offset, n)
1311 
1312 #define os_file_flush_pfs(file) os_file_flush_func(file)
1313 
1314 #define os_file_rename(key, oldpath, newpath) \
1315  os_file_rename_func(oldpath, newpath)
1316 
1317 #define os_file_delete(key, name) os_file_delete_func(name)
1318 
1319 #define os_file_delete_if_exists(key, name, exist) \
1320  os_file_delete_if_exists_func(name, exist)
1321 
1322 #endif /* UNIV_PFS_IO */
1323 
1324 #ifdef UNIV_PFS_IO
1325 #define os_file_close(file) os_file_close_pfs(file)
1326 #else
1327 #define os_file_close(file) os_file_close_pfs((file).m_file)
1328 #endif
1329 
1330 #ifdef UNIV_PFS_IO
1331 #define os_file_read(type, file_name, file, buf, offset, n) \
1332  os_file_read_pfs(type, file_name, file, buf, offset, n)
1333 #else
1334 #define os_file_read(type, file_name, file, buf, offset, n) \
1335  os_file_read_pfs(type, file_name, file.m_file, buf, offset, n)
1336 #endif
1337 
1338 #ifdef UNIV_PFS_IO
1339 #define os_file_read_first_page(type, file_name, file, buf, n) \
1340  os_file_read_first_page_pfs(type, file_name, file, buf, n)
1341 #else
1342 #define os_file_read_first_page(type, file_name, file, buf, n) \
1343  os_file_read_first_page_pfs(type, file_name, file.m_file, buf, n)
1344 #endif
1345 
1346 #ifdef UNIV_PFS_IO
1347 #define os_file_flush(file) os_file_flush_pfs(file)
1348 #else
1349 #define os_file_flush(file) os_file_flush_pfs(file.m_file)
1350 #endif
1351 
1352 #ifdef UNIV_PFS_IO
1353 #define os_file_write(type, name, file, buf, offset, n) \
1354  os_file_write_pfs(type, name, file, buf, offset, n)
1355 #else
1356 #define os_file_write(type, name, file, buf, offset, n) \
1357  os_file_write_pfs(type, name, file.m_file, buf, offset, n)
1358 #endif
1359 
1360 #ifdef UNIV_PFS_IO
1361 #define os_file_copy(src, src_offset, dest, dest_offset, size) \
1362  os_file_copy_pfs(src, src_offset, dest, dest_offset, size)
1363 #else
1364 #define os_file_copy(src, src_offset, dest, dest_offset, size) \
1365  os_file_copy_pfs(src.m_file, src_offset, dest.m_file, dest_offset, size)
1366 #endif
1367 
1368 #ifdef UNIV_PFS_IO
1369 #define os_file_read_no_error_handling(type, file_name, file, buf, offset, n, \
1370  o) \
1371  os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, n, o)
1372 #else
1373 #define os_file_read_no_error_handling(type, file_name, file, buf, offset, n, \
1374  o) \
1375  os_file_read_no_error_handling_pfs(type, file_name, file.m_file, buf, \
1376  offset, n, o)
1377 #endif
1378 
1379 #ifdef UNIV_HOTBACKUP
1380 /** Closes a file handle.
1381 @param[in] file handle to a file
1382 @return true if success */
1383 bool os_file_close_no_error_handling(os_file_t file);
1384 #endif /* UNIV_HOTBACKUP */
1385 
1386 /** Gets a file size.
1387 @param[in] filename handle to a file
1388 @return file size if OK, else set m_total_size to ~0 and m_alloc_size
1389  to errno */
1391  MY_ATTRIBUTE((warn_unused_result));
1392 
1393 /** Gets a file size.
1394 @param[in] file handle to a file
1395 @return file size, or (os_offset_t) -1 on failure */
1397  MY_ATTRIBUTE((warn_unused_result));
1398 
1399 /** Allocate a block to file using fallocate from the given offset if
1400 fallocate is supported. Falls back to the old slower method of writing
1401 zeros otherwise.
1402 @param[in] name name of the file
1403 @param[in] file handle to the file
1404 @param[in] offset file offset
1405 @param[in] size file size
1406 @param[in] read_only enable read-only checks if true
1407 @param[in] flush flush file content to disk
1408 @return true if success */
1409 bool os_file_set_size_fast(const char *name, pfs_os_file_t file,
1410  os_offset_t offset, os_offset_t size, bool read_only,
1411  bool flush) MY_ATTRIBUTE((warn_unused_result));
1412 
1413 /** Write the specified number of zeros to a file from specific offset.
1414 @param[in] name name of the file or path as a null-terminated
1415  string
1416 @param[in] file handle to a file
1417 @param[in] offset file offset
1418 @param[in] size file size
1419 @param[in] read_only enable read-only checks if true
1420 @param[in] flush flush file content to disk
1421 @return true if success */
1422 bool os_file_set_size(const char *name, pfs_os_file_t file, os_offset_t offset,
1423  os_offset_t size, bool read_only, bool flush)
1424  MY_ATTRIBUTE((warn_unused_result));
1425 
1426 /** Truncates a file at its current position.
1427 @param[in,out] file file to be truncated
1428 @return true if success */
1429 bool os_file_set_eof(FILE *file); /*!< in: file to be truncated */
1430 
1431 /** Truncates a file to a specified size in bytes. Do nothing if the size
1432 preserved is smaller or equal than current size of file.
1433 @param[in] pathname file path
1434 @param[in] file file to be truncated
1435 @param[in] size size preserved in bytes
1436 @return true if success */
1437 bool os_file_truncate(const char *pathname, pfs_os_file_t file,
1438  os_offset_t size);
1439 
1440 /** Set read/write position of a file handle to specific offset.
1441 @param[in] pathname file path
1442 @param[in] file file handle
1443 @param[in] offset read/write offset
1444 @return true if success */
1445 bool os_file_seek(const char *pathname, os_file_t file, os_offset_t offset);
1446 
1447 /** NOTE! Use the corresponding macro os_file_flush(), not directly this
1448 function!
1449 Flushes the write buffers of a given file to the disk.
1450 @param[in] file handle to a file
1451 @return true if success */
1453 
1454 /** Retrieves the last error number if an error occurs in a file io function.
1455 The number should be retrieved before any other OS calls (because they may
1456 overwrite the error number). If the number is not known to this program,
1457 the OS error number + 100 is returned.
1458 @param[in] report_all_errors true if we want an error message printed
1459  for all errors
1460 @return error number, or OS error number + 100 */
1461 ulint os_file_get_last_error(bool report_all_errors);
1462 
1463 /** NOTE! Use the corresponding macro os_file_read(), not directly this
1464 function!
1465 Requests a synchronous read operation.
1466 @param[in] type IO request context
1467 @param[in] file_name file name
1468 @param[in] file Open file handle
1469 @param[out] buf buffer where to read
1470 @param[in] offset file offset where to read
1471 @param[in] n number of bytes to read
1472 @return DB_SUCCESS if request was successful */
1473 dberr_t os_file_read_func(IORequest &type, const char *file_name,
1474  os_file_t file, void *buf, os_offset_t offset,
1475  ulint n) MY_ATTRIBUTE((warn_unused_result));
1476 
1477 /** NOTE! Use the corresponding macro os_file_read_first_page(),
1478 not directly this function!
1479 Requests a synchronous read operation of page 0 of IBD file
1480 @param[in] type IO request context
1481 @param[in] file_name file name
1482 @param[in] file Open file handle
1483 @param[out] buf buffer where to read
1484 @param[in] n number of bytes to read
1485 @return DB_SUCCESS if request was successful */
1486 dberr_t os_file_read_first_page_func(IORequest &type, const char *file_name,
1487  os_file_t file, void *buf, ulint n)
1488  MY_ATTRIBUTE((warn_unused_result));
1489 
1490 /** copy data from one file to another file. Data is read/written
1491 at current file offset.
1492 @param[in] src_file file handle to copy from
1493 @param[in] src_offset offset to copy from
1494 @param[in] dest_file file handle to copy to
1495 @param[in] dest_offset offset to copy to
1496 @param[in] size number of bytes to copy
1497 @return DB_SUCCESS if successful */
1498 dberr_t os_file_copy_func(os_file_t src_file, os_offset_t src_offset,
1499  os_file_t dest_file, os_offset_t dest_offset,
1500  uint size) MY_ATTRIBUTE((warn_unused_result));
1501 
1502 /** Rewind file to its start, read at most size - 1 bytes from it to str, and
1503 NUL-terminate str. All errors are silently ignored. This function is
1504 mostly meant to be used with temporary files.
1505 @param[in,out] file file to read from
1506 @param[in,out] str buffer where to read
1507 @param[in] size size of buffer */
1508 void os_file_read_string(FILE *file, char *str, ulint size);
1509 
1510 /** NOTE! Use the corresponding macro os_file_read_no_error_handling(),
1511 not directly this function!
1512 Requests a synchronous positioned read operation. This function does not do
1513 any error handling. In case of error it returns FALSE.
1514 @param[in] type IO request context
1515 @param[in] file_name file name
1516 @param[in] file Open file handle
1517 @param[out] buf buffer where to read
1518 @param[in] offset file offset where to read
1519 @param[in] n number of bytes to read
1520 @param[out] o number of bytes actually read
1521 @return DB_SUCCESS or error code */
1523  IORequest &type, const char *file_name, os_file_t file, void *buf,
1524  os_offset_t offset, ulint n, ulint *o) MY_ATTRIBUTE((warn_unused_result));
1525 
1526 /** NOTE! Use the corresponding macro os_file_write(), not directly this
1527 function!
1528 Requests a synchronous write operation.
1529 @param[in,out] type IO request context
1530 @param[in] name name of the file or path as a null-terminated
1531  string
1532 @param[in] file Open file handle
1533 @param[out] buf buffer where to read
1534 @param[in] offset file offset where to read
1535 @param[in] n number of bytes to read
1536 @return DB_SUCCESS if request was successful */
1538  const void *buf, os_offset_t offset, ulint n)
1539  MY_ATTRIBUTE((warn_unused_result));
1540 
1541 /** Check the existence and type of the given file.
1542 @param[in] path pathname of the file
1543 @param[out] exists true if file exists
1544 @param[out] type type of the file (if it exists)
1545 @return true if call succeeded */
1546 bool os_file_status(const char *path, bool *exists, os_file_type_t *type);
1547 
1548 /** Create all missing subdirectories along the given path.
1549 @return DB_SUCCESS if OK, otherwise error code. */
1550 dberr_t os_file_create_subdirs_if_needed(const char *path);
1551 
1552 #ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
1553 /* Test the function os_file_get_parent_dir. */
1554 void unit_test_os_file_get_parent_dir();
1555 #endif /* UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR */
1556 
1557 #ifdef UNIV_HOTBACKUP
1558 /** Deallocates the "Blocks" in block_cache */
1559 void meb_free_block_cache();
1560 #endif /* UNIV_HOTBACKUP */
1561 
1562 /** Creates and initializes block_cache. Creates array of MAX_BLOCKS
1563 and allocates the memory in each block to hold BUFFER_BLOCK_SIZE
1564 of data.
1565 
1566 This function is called by InnoDB during srv_start().
1567 It is also called by MEB while applying the redo logs on TDE tablespaces,
1568 the "Blocks" allocated in this block_cache are used to hold the decrypted
1569 page data. */
1570 void os_create_block_cache();
1571 
1572 /** Initializes the asynchronous io system. Creates one array each for ibuf
1573 and log i/o. Also creates one array each for read and write where each
1574 array is divided logically into n_read_segs and n_write_segs
1575 respectively. The caller must create an i/o handler thread for each
1576 segment in these arrays. This function also creates the sync array.
1577 No i/o handler thread needs to be created for that
1578 @param[in] n_readers number of reader threads
1579 @param[in] n_writers number of writer threads
1580 @param[in] n_slots_sync number of slots in the dblwr aio array */
1581 
1582 bool os_aio_init(ulint n_readers, ulint n_writers, ulint n_slots_sync);
1583 
1584 /**
1585 Frees the asynchronous io system. */
1586 void os_aio_free();
1587 
1588 /**
1589 NOTE! Use the corresponding macro os_aio(), not directly this function!
1590 Requests an asynchronous i/o operation.
1591 @param[in] type IO request context
1592 @param[in] aio_mode IO mode
1593 @param[in] name Name of the file or path as NUL terminated
1594  string
1595 @param[in] file Open file handle
1596 @param[out] buf buffer where to read
1597 @param[in] offset file offset where to read
1598 @param[in] n number of bytes to read
1599 @param[in] read_only if true read only mode checks are enforced
1600 @param[in,out] m1 Message for the AIO handler, (can be used to
1601  identify a completed AIO operation); ignored
1602  if mode is OS_AIO_SYNC
1603 @param[in,out] m2 message for the AIO handler (can be used to
1604  identify a completed AIO operation); ignored
1605  if mode is OS_AIO_SYNC
1606 @return DB_SUCCESS or error code */
1607 dberr_t os_aio_func(IORequest &type, AIO_mode aio_mode, const char *name,
1608  pfs_os_file_t file, void *buf, os_offset_t offset, ulint n,
1609  bool read_only, fil_node_t *m1, void *m2);
1610 
1611 /** Wakes up all async i/o threads so that they know to exit themselves in
1612 shutdown. */
1614 
1615 /** Waits until there are no pending writes in os_aio_write_array. There can
1616 be other, synchronous, pending writes. */
1618 
1619 /** Wakes up simulated aio i/o-handler threads if they have something to do. */
1621 
1622 /** This function can be called if one wants to post a batch of reads and
1623 prefers an i/o-handler thread to handle them all at once later. You must
1624 call os_aio_simulated_wake_handler_threads later to ensure the threads
1625 are not left sleeping! */
1627 
1628 /** This is the generic AIO handler interface function.
1629 Waits for an aio operation to complete. This function is used to wait the
1630 for completed requests. The AIO array of pending requests is divided
1631 into segments. The thread specifies which segment or slot it wants to wait
1632 for. NOTE: this function will also take care of freeing the aio slot,
1633 therefore no other thread is allowed to do the freeing!
1634 @param[in] segment the number of the segment in the aio arrays to
1635  wait for; segment 0 is the ibuf I/O thread,
1636  segment 1 the log I/O thread, then follow the
1637  non-ibuf read threads, and as the last are the
1638  non-ibuf write threads; if this is
1639  ULINT_UNDEFINED, then it means that sync AIO
1640  is used, and this parameter is ignored
1641 @param[out] m1 the messages passed with the AIO request;
1642  note that also in the case where the AIO
1643  operation failed, these output parameters
1644  are valid and can be used to restart the
1645  operation, for example
1646 @param[out] m2 callback message
1647 @param[out] request OS_FILE_WRITE or ..._READ
1648 @return DB_SUCCESS or error code */
1649 dberr_t os_aio_handler(ulint segment, fil_node_t **m1, void **m2,
1650  IORequest *request);
1651 
1652 /** Prints info of the aio arrays.
1653 @param[in,out] file file where to print */
1654 void os_aio_print(FILE *file);
1655 
1656 /** Refreshes the statistics used to print per-second averages. */
1657 void os_aio_refresh_stats();
1658 
1659 /** Checks that all slots in the system have been freed, that is, there are
1660 no pending io operations. */
1661 bool os_aio_all_slots_free();
1662 
1663 #ifdef UNIV_DEBUG
1664 
1665 /** Prints all pending IO
1666 @param[in] file file where to print */
1668 
1669 #endif /* UNIV_DEBUG */
1670 
1671 /** Get available free space on disk
1672 @param[in] path pathname of a directory or file in disk
1673 @param[out] free_space free space available in bytes
1674 @return DB_SUCCESS if all OK */
1675 dberr_t os_get_free_space(const char *path, uint64_t &free_space);
1676 
1677 /** This function returns information about the specified file
1678 @param[in] path pathname of the file
1679 @param[in] stat_info information of a file in a directory
1680 @param[in] check_rw_perm for testing whether the file can be opened
1681  in RW mode
1682 @param[in] read_only if true read only mode checks are enforced
1683 @return DB_SUCCESS if all OK */
1684 dberr_t os_file_get_status(const char *path, os_file_stat_t *stat_info,
1685  bool check_rw_perm, bool read_only);
1686 
1687 #ifndef UNIV_HOTBACKUP
1688 
1689 /** return any of the tmpdir path */
1690 char *innobase_mysql_tmpdir();
1691 /** Creates a temporary file in the location specified by the parameter
1692 path. If the path is NULL then it will be created on --tmpdir location.
1693 This function is defined in ha_innodb.cc.
1694 @param[in] path location for creating temporary file
1695 @return temporary file descriptor, or < 0 on error */
1696 int innobase_mysql_tmpfile(const char *path);
1697 #endif /* !UNIV_HOTBACKUP */
1698 
1699 /** If it is a compressed page return the compressed page data + footer size
1700 @param[in] buf Buffer to check, must include header + 10 bytes
1701 @return ULINT_UNDEFINED if the page is not a compressed page or length
1702  of the compressed data (including footer) if it is a compressed page */
1703 ulint os_file_compressed_page_size(const byte *buf);
1704 
1705 /** If it is a compressed page return the original page data + footer size
1706 @param[in] buf Buffer to check, must include header + 10 bytes
1707 @return ULINT_UNDEFINED if the page is not a compressed page or length
1708  of the original data + footer if it is a compressed page */
1709 ulint os_file_original_page_size(const byte *buf);
1710 
1711 /** Set the file create umask
1712 @param[in] umask The umask to use for file creation. */
1713 void os_file_set_umask(ulint umask);
1714 
1715 /** Get the file create umask
1716 @return the umask to use for file creation. */
1717 ulint os_file_get_umask();
1718 
1719 /** Free storage space associated with a section of the file.
1720 @param[in] fh Open file handle
1721 @param[in] off Starting offset (SEEK_SET)
1722 @param[in] len Size of the hole
1723 @return DB_SUCCESS or error code */
1725  MY_ATTRIBUTE((warn_unused_result));
1726 
1727 /** Check if the file system supports sparse files.
1728 
1729 Warning: On POSIX systems we try and punch a hole from offset 0 to
1730 the system configured page size. This should only be called on an empty
1731 file.
1732 
1733 Note: On Windows we use the name and on Unices we use the file handle.
1734 
1735 @param[in] path File name
1736 @param[in] fh File handle for the file - if opened
1737 @return true if the file system supports sparse files */
1738 bool os_is_sparse_file_supported(const char *path, pfs_os_file_t fh)
1739  MY_ATTRIBUTE((warn_unused_result));
1740 
1741 /** Decompress the page data contents. Page type must be FIL_PAGE_COMPRESSED, if
1742 not then the source contents are left unchanged and DB_SUCCESS is returned.
1743 @param[in] dblwr_read true of double write recovery in progress
1744 @param[in,out] src Data read from disk, decompressed data will be
1745  copied to this page
1746 @param[in,out] dst Scratch area to use for decompression
1747 @param[in] dst_len Size of the scratch area in bytes
1748 @return DB_SUCCESS or error code */
1749 dberr_t os_file_decompress_page(bool dblwr_read, byte *src, byte *dst,
1750  ulint dst_len)
1751  MY_ATTRIBUTE((warn_unused_result));
1752 
1753 /** Compress a data page
1754 @param[in] compression Compression algorithm
1755 @param[in] block_size File system block size
1756 @param[in] src Source contents to compress
1757 @param[in] src_len Length in bytes of the source
1758 @param[out] dst Compressed page contents
1759 @param[out] dst_len Length in bytes of dst contents
1760 @return buffer data, dst_len will have the length of the data */
1761 byte *os_file_compress_page(Compression compression, ulint block_size,
1762  byte *src, ulint src_len, byte *dst,
1763  ulint *dst_len);
1764 
1765 /** Determine if O_DIRECT is supported.
1766 @retval true if O_DIRECT is supported.
1767 @retval false if O_DIRECT is not supported. */
1768 bool os_is_o_direct_supported() MY_ATTRIBUTE((warn_unused_result));
1769 
1770 /** Fill the pages with NULs
1771 @param[in] file File handle
1772 @param[in] name File name
1773 @param[in] page_size physical page size
1774 @param[in] start Offset from the start of the file in bytes
1775 @param[in] len Length in bytes
1776 @param[in] read_only_mode
1777  if true, then read only mode checks are enforced.
1778 @return DB_SUCCESS or error code */
1780  ulint page_size, os_offset_t start, ulint len,
1781  bool read_only_mode)
1782  MY_ATTRIBUTE((warn_unused_result));
1783 
1784 #ifndef UNIV_NONINL
1785 /** Class to scan the directory heirarchy using a depth first scan. */
1786 class Dir_Walker {
1787  public:
1788  using Path = std::string;
1789 
1790  /** Check if the path is a directory. The file/directory must exist.
1791  @param[in] path The path to check
1792  @return true if it is a directory */
1793  static bool is_directory(const Path &path);
1794 
1795  /** Depth first traversal of the directory starting from basedir
1796  @param[in] basedir Start scanning from this directory
1797  @param[in] recursive `true` if scan should be recursive
1798  @param[in] f Function to call for each entry */
1799  template <typename F>
1800  static void walk(const Path &basedir, bool recursive, F &&f) {
1801 #ifdef _WIN32
1802  walk_win32(basedir, recursive,
1803  [&](const Path &path, size_t depth) { f(path); });
1804 #else
1805  walk_posix(basedir, recursive,
1806  [&](const Path &path, size_t depth) { f(path); });
1807 #endif /* _WIN32 */
1808  }
1809 
1810  private:
1811  /** Directory names for the depth first directory scan. */
1812  struct Entry {
1813  /** Constructor
1814  @param[in] path Directory to traverse
1815  @param[in] depth Relative depth to the base
1816  directory in walk() */
1817  Entry(const Path &path, size_t depth) : m_path(path), m_depth(depth) {}
1818 
1819  /** Path to the directory */
1821 
1822  /** Relative depth of m_path */
1823  size_t m_depth;
1824  };
1825 
1826  using Function = std::function<void(const Path &, size_t)>;
1827 
1828  /** Depth first traversal of the directory starting from basedir
1829  @param[in] basedir Start scanning from this directory
1830  @param[in] recursive `true` if scan should be recursive
1831  @param[in] f Callback for each entry found */
1832 #ifdef _WIN32
1833  static void walk_win32(const Path &basedir, bool recursive, Function &&f);
1834 #else
1835  static void walk_posix(const Path &basedir, bool recursive, Function &&f);
1836 #endif /* _WIN32 */
1837 };
1838 
1839 /** Allocate a page for sync IO
1840 @return pointer to page */
1841 file::Block *os_alloc_block() noexcept;
1842 
1843 /** Free a page after sync IO
1844 @param[in,out] block The block to free/release */
1845 void os_free_block(file::Block *block) noexcept;
1846 
1847 #include "os0file.ic"
1848 #endif /* UNIV_NONINL */
1849 
1850 #endif /* os0file_h */
Path m_path
Path to the directory.
Definition: os0file.h:1820
Encryption algorithm.
Definition: os0enc.h:39
bool validate() const
Definition: os0file.h:373
bool is_log() const
Definition: os0file.h:343
static const ulint OS_REDO_LOG_ARCHIVE_FILE
Redo log archive file.
Definition: os0file.h:224
static const ulint OS_DATA_FILE
Types for file create.
Definition: os0file.h:209
int os_file_t
File handle.
Definition: os0file.h:131
AIO_mode
Modes for aio operations.
Definition: os0file.h:583
UNIV_INLINE dberr_t pfs_os_file_read_no_error_handling_int_fd_func(IORequest &type, const char *file_name, int file, void *buf, os_offset_t offset, ulint n, ulint *o, const char *src_file, ulint src_line)
NOTE! Please use the corresponding macro os_file_read_no_error_handling_int_fd(), not directly this f...
mysql_pfs_key_t innodb_temp_file_key
UNIV_INLINE dberr_t pfs_os_file_read_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read(), not directly this function! This is the perf...
File node of a tablespace or the log data space.
Definition: fil0fil.h:144
stat() failed with EACCESS
Definition: os0file.h:617
UNIV_INLINE pfs_os_file_t pfs_os_file_create_simple_no_error_handling_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create_simple_no_error_handling(), not directly this function! A performance schema instrumented wrapper function for os_file_create_simple_no_error_handling().
to create new file (if exists, error)
Definition: os0file.h:180
static const ulint OS_FILE_AIO_RESOURCES_RESERVED
wait for OS aio resources to become available again
Definition: os0file.h:234
IORequest()
Default constructor.
Definition: os0file.h:302
void encryption_key(byte *key, ulint key_len, byte *iv)
Set encryption key and iv.
Definition: os0file.h:459
mysql_pfs_key_t innodb_log_file_key
Compression algorithm.
Definition: file.h:50
dberr_t os_file_read_first_page_func(IORequest &type, const char *file_name, os_file_t file, void *buf, ulint n)
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function! Requests a s...
Definition: os0file.cc:5621
bool os_aio_all_slots_free()
Checks that all slots in the system have been freed, that is, there are no pending io operations...
Definition: os0file.cc:7902
dberr_t os_aio_handler(ulint segment, fil_node_t **m1, void **m2, IORequest *request)
This is the generic AIO handler interface function.
Definition: os0file.cc:5990
void set_punch_hole()
Set the punch hole flag.
Definition: os0file.h:380
void clear_compressed()
Clear all compression related flags.
Definition: os0file.h:404
mysql_pfs_key_t innodb_arch_file_key
void disable_compression()
Disable transformations.
Definition: os0file.h:443
Page encryption infrastructure.
Macros for using atomics.
byte pad[INNOBASE_CACHE_LINE_SIZE - sizeof(ulint)]
Definition: os0file.h:94
Sparse file size information.
Definition: os0file.h:570
Include file for Sun RPC to compile out of the box.
to open a raw device or disk partition
Definition: os0file.h:182
void os_aio_wait_until_no_pending_writes()
Waits until there are no pending writes in os_aio_write_array.
Definition: os0file.cc:6550
bool os_file_flush_func(os_file_t file)
NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushes the write buff...
Definition: os0file.cc:2936
ulint os_file_get_umask()
Get the file create umask.
Definition: os0file.cc:7965
bool is_wake() const
Definition: os0file.h:348
Compression compression_algorithm() const
Get the compression algorithm.
Definition: os0file.h:428
dberr_t os_file_write_func(IORequest &type, const char *name, os_file_t file, const void *buf, os_offset_t offset, ulint n)
NOTE! Use the corresponding macro os_file_write(), not directly this function! Requests a synchronous...
Definition: os0file.cc:5796
os_offset_t size
file size in bytes
Definition: os0file.h:652
bool is_encrypted() const
Definition: os0file.h:472
bool os_is_sparse_file_supported(const char *path, pfs_os_file_t fh)
Check if the file system supports sparse files.
Definition: os0file.cc:5854
static bool ignore_missing(ulint type)
Definition: os0file.h:328
bool operator==(const IORequest &rhs) const
Compare two requests.
Definition: os0file.h:412
Ordinary file.
Definition: os0file.h:626
Asynchronous i/o where the calling thread will itself wait for the i/o to complete, doing also the job of the i/o-handler thread; can be used for any pages, ibuf or non-ibuf.
static const ulint OS_CLONE_DATA_FILE
Definition: os0file.h:217
bool os_file_set_size(const char *name, pfs_os_file_t file, os_offset_t offset, os_offset_t size, bool read_only, bool flush)
Write the specified number of zeros to a file from specific offset.
Definition: os0file.cc:5434
File exists but type is unknown.
Definition: os0file.h:623
bool os_file_delete_if_exists_func(const char *name, bool *exist)
Deletes a file if it exists.
Definition: os0file.cc:3336
Flags that can be combined with the above values.
Definition: os0file.h:190
dberr_t os_file_punch_hole(os_file_t fh, os_offset_t off, os_offset_t len)
Free storage space associated with a section of the file.
Definition: os0file.cc:5830
void os_aio_print(FILE *file)
Prints info of the aio arrays.
Definition: os0file.cc:7820
mysql_pfs_key_t innodb_tablespace_open_file_key
void os_aio_refresh_stats()
Refreshes the statistics used to print per-second averages.
Definition: os0file.cc:7883
unsigned long long os_fsync_threshold
Definition: os0file.cc:103
uint32_t block_size
Block size to use for IO in bytes.
Definition: os0file.h:655
time_t mtime
modification time
Definition: os0file.h:658
static const ulint OS_BUFFERED_FILE
Definition: os0file.h:215
byte * os_file_compress_page(Compression compression, ulint block_size, byte *src, ulint src_len, byte *dst, ulint *dst_len)
Compress a data page.
Definition: os0file.cc:1323
bool is_dblwr() const
Definition: os0file.h:488
mysql_pfs_key_t innodb_clone_file_key
static const ulint OS_FILE_NOT_FOUND
Error codes from os_file_get_last_error.
Definition: os0file.h:228
static void walk(const Path &basedir, bool recursive, F &&f)
Depth first traversal of the directory starting from basedir.
Definition: os0file.h:1800
Asynchronous i/o for ibuf pages or ibuf bitmap pages.
uint16_t m_type
Request type bit flags.
Definition: os0file.h:558
bool os_file_set_eof(FILE *file)
Truncates a file at its current position.
Definition: os0file.cc:3573
open with retry
Definition: os0file.h:185
bool os_file_seek(const char *pathname, os_file_t file, os_offset_t offset)
Set read/write position of a file handle to specific offset.
Definition: os0file.cc:5564
Type
Algorithm types supported.
Definition: file.h:52
Struct used in fetching information of a file in a directory.
Definition: os0file.h:649
UNIV_INLINE bool pfs_os_file_close_func(pfs_os_file_t file, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_close(), not directly this function! A performance s...
const std::string FILE("FILE")
NOTE: The functions in this file should only use functions from other files in library.
time_t atime
access time
Definition: os0file.h:659
struct PSI_file PSI_file
Definition: psi_file_bits.h:53
No encryption.
Definition: os0enc.h:45
void os_free_block(file::Block *block) noexcept
Free a page after sync IO.
Definition: os0file.cc:984
Parsing sql code.
Definition: sql_bootstrap.h:69
Symbolic link.
Definition: os0file.h:632
dberr_t os_file_write_zeros(pfs_os_file_t file, const char *name, ulint page_size, os_offset_t start, ulint len, bool read_only_mode)
Fill the pages with NULs.
Definition: os0file.cc:5929
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
size_t m_depth
Relative depth of m_path.
Definition: os0file.h:1823
static const ulint OS_CLONE_LOG_FILE
Definition: os0file.h:218
void os_aio_simulated_put_read_threads_to_sleep()
This function can be called if one wants to post a batch of reads and prefers an i/o-handler thread t...
Definition: os0file.cc:3591
don&#39;t print diagnostic messages to the log unless it is a fatal error, this flag is only used if ON_E...
Definition: os0file.h:191
static const ulint OS_FILE_ACCESS_VIOLATION
Definition: os0file.h:241
bool os_file_create_directory(const char *pathname, bool fail_if_exists)
This function attempts to create a directory named pathname.
Definition: os0file.cc:3065
Class to scan the directory heirarchy using a depth first scan.
Definition: os0file.h:1786
The IO Context that is passed down to the low level IO code.
Definition: os0file.h:256
Get status failed.
Definition: os0file.h:611
ulint os_file_compressed_page_size(const byte *buf)
If it is a compressed page return the compressed page data + footer size.
Definition: os0file.cc:1134
Encryption m_encryption
Encryption algorithm.
Definition: os0file.h:564
static const os_file_t OS_FILE_CLOSED
Definition: os0file.h:165
bool read_only
Definition: mysqld.cc:1062
static const ulint OS_AIO_N_PENDING_IOS_PER_THREAD
Win NT does not allow more than 64.
Definition: os0file.h:580
void clear_encrypted()
Clear all encryption related flags.
Definition: os0file.h:477
#define READ(DECODE, BYTES)
Auxiliary macro used to define READ_INT and READ_STRING.
Definition: rpl_master.cc:882
static const ulint OS_FILE_INSUFFICIENT_RESOURCE
Definition: os0file.h:238
dberr_t os_aio_func(IORequest &type, AIO_mode aio_mode, const char *name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, bool read_only, fil_node_t *m1, void *m2)
NOTE! Use the corresponding macro os_aio(), not directly this function! Requests an asynchronous i/o ...
Definition: os0file.cc:7078
UNIV_INLINE bool pfs_os_file_flush_func(pfs_os_file_t file, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_flush(), not directly this function! This is the per...
Directory.
Definition: os0file.h:629
void os_aio_print_pending_io(FILE *file)
Prints all pending IO.
Definition: os0file.cc:7954
to open an existing file (if doesn&#39;t exist, error)
Definition: os0file.h:178
int innobase_mysql_tmpfile(const char *path)
Creates a temporary file in the location specified by the parameter path.
Definition: ha_innodb.cc:2201
UNIV_INLINE bool pfs_os_file_delete_func(mysql_pfs_key_t key, const char *name, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_delete(), not directly this function! This is the pe...
UNIV_INLINE bool pfs_os_file_delete_if_exists_func(mysql_pfs_key_t key, const char *name, bool *exist, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_delete_if_exists(), not directly this function! This...
uint32_t m_block_size
Definition: os0file.h:555
static const ulint OS_FILE_SHARING_VIOLATION
Definition: os0file.h:236
A helper class for handling file paths.
Definition: path.h:37
os_file_type_t type
file type
Definition: os0file.h:651
bool os_file_delete_func(const char *name)
Deletes a file.
Definition: os0file.cc:3364
bool os_is_o_direct_supported()
Determine if O_DIRECT is supported.
Definition: os0file.cc:132
ulint lock_word_t
Definition: os0atomic.h:55
os_offset_t m_total_size
Total size of file in bytes.
Definition: os0file.h:572
#define INNOBASE_CACHE_LINE_SIZE
CPU cache line size.
Definition: ut0counter.h:52
static const ulint OS_FILE_ALREADY_EXISTS
Definition: os0file.h:230
Entry(const Path &path, size_t depth)
Constructor.
Definition: os0file.h:1817
UNIV_INLINE bool pfs_os_file_rename_func(mysql_pfs_key_t key, const char *oldpath, const char *newpath, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_rename(), not directly this function! This is the pe...
#define HANDLE
Definition: violite.h:158
dberr_t
Definition: db0err.h:38
IORequest(ulint type)
Definition: os0file.h:313
void os_aio_wake_all_threads_at_shutdown()
Wakes up all async i/o threads so that they know to exit themselves in shutdown.
Definition: os0file.cc:6520
void os_aio_simulated_wake_handler_threads()
Wakes up simulated aio i/o-handler threads if they have something to do.
Definition: os0file.cc:6856
os_offset_t m_alloc_size
If it is a sparse file then this is the number of bytes actually allocated for the file...
Definition: os0file.h:576
static char * path
Definition: mysqldump.cc:131
bool os_file_truncate(const char *pathname, pfs_os_file_t file, os_offset_t size)
Truncates a file to a specified size in bytes.
Definition: os0file.cc:5542
static const ulint OS_FILE_READ_WRITE
Definition: os0file.h:198
UNIV_INLINE dberr_t pfs_os_file_read_first_page_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read_first_page(), not directly this function! This ...
UNIV_INLINE pfs_os_file_t pfs_os_file_create_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint purpose, ulint type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create(), not directly this function! A performance ...
dberr_t os_file_decompress_page(bool dblwr_read, byte *src, byte *dst, ulint dst_len)
Decompress the page data contents.
Definition: file.cc:259
dberr_t os_file_copy_func(os_file_t src_file, os_offset_t src_offset, os_file_t dest_file, os_offset_t dest_offset, uint size)
copy data from one file to another file.
Definition: os0file.cc:5753
unsigned int uint
Definition: uca-dump.cc:29
case opt name
Definition: sslopt-case.h:32
static const ulint OS_FILE_PATH_ERROR
Definition: os0file.h:231
dberr_t os_get_free_space(const char *path, uint64_t &free_space)
Get available free space on disk.
Definition: os0file.cc:5873
UNIV_INLINE dberr_t pfs_os_file_write_int_fd_func(IORequest &type, const char *name, int file, const void *buf, os_offset_t offset, ulint n, const char *src_file, ulint src_line)
NOTE! Please use the corresponding macro os_file_write(), not directly this function! This is the per...
Type
Algorithm types supported.
Definition: os0enc.h:42
bool punch_hole() const
Definition: os0file.h:368
std::function< void(const Path &, size_t)> Function
Definition: os0file.h:1826
os_file_type_t
Definition: os0file.h:609
bool is_write() const
Definition: os0file.h:338
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
void clear_punch_hole()
Clear the punch hole flag.
Definition: os0file.h:390
lock_word_t m_in_use
Definition: os0file.h:95
void(* os_dir_cbk_t)(const char *path, const char *name)
Callback function type to be implemented by caller.
Definition: os0file.h:691
os_file_t os_file_create_simple_func(const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create_simple(), not directly this function! A simple funct...
Definition: os0file.cc:2974
dberr_t os_file_create_subdirs_if_needed(const char *path)
Create all missing subdirectories along the given path.
Definition: os0file.cc:1853
bool os_file_close_func(os_file_t file)
NOTE! Use the corresponding macro os_file_close(), not directly this function! Closes a file handle...
Definition: os0file.cc:3414
UNIV_INLINE dberr_t pfs_os_aio_func(IORequest &type, AIO_mode mode, const char *name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, bool read_only, fil_node_t *m1, void *m2, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_aio(), not directly this function! Performance schema wra...
bool os_has_said_disk_full
Definition: os0file.cc:795
static const ulint OS_FILE_READ_ALLOW_DELETE
Used by MySQLBackup.
Definition: os0file.h:201
stat() failed, with ENAMETOOLONG
Definition: os0file.h:614
bool os_file_set_size_fast(const char *name, pfs_os_file_t file, os_offset_t offset, os_offset_t size, bool read_only, bool flush)
Allocate a block to file using fallocate from the given offset if fallocate is supported.
Definition: os0file.cc:5401
ulint block_size() const
Definition: os0file.h:393
ulint os_file_get_last_error(bool report_all_errors)
Retrieves the last error number if an error occurs in a file io function.
Definition: os0file.cc:5231
static const char * key
Definition: suite_stubs.c:14
bool os_aio_init(ulint n_readers, ulint n_writers, ulint n_slots_sync)
Initializes the asynchronous io system.
Definition: os0file.cc:6476
ulint os_n_file_reads
Definition: os0file.cc:782
int n
Definition: xcom_base.c:425
mysql_pfs_key_t innodb_dblwr_file_key
bool ignore_missing() const
Definition: os0file.h:363
void dblwr()
Note that the IO is for double write buffer page write.
Definition: os0file.h:485
time_t ctime
creation time
Definition: os0file.h:657
Block device.
Definition: os0file.h:635
ulint os_n_fsyncs
Definition: os0file.cc:785
void encryption_algorithm(Encryption::Type type)
Set encryption algorithm.
Definition: os0file.h:447
ib_uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:83
#define OS_FILE_MAX_PATH
Definition: os0file.h:643
bool rw_perm
true if can be opened in read-write mode.
Definition: os0file.h:660
bool is_partial_io_warning_disabled() const
Definition: os0file.h:353
static const ulint OS_FILE_NORMAL
Definition: os0file.h:205
ulint os_n_file_writes
Definition: os0file.cc:784
os_file_t m_file
Definition: os0file.h:162
ulint os_file_original_page_size(const byte *buf)
If it is a compressed page return the original page data + footer size.
Definition: os0file.cc:1150
static bool is_punch_hole_supported()
Definition: os0file.h:493
static const ulint OS_FILE_NAME_TOO_LONG
Definition: os0file.h:242
static const ulint OS_LOG_FILE
Definition: os0file.h:210
const char * filename
Definition: pfs_example_component_population.cc:64
void compression_algorithm(Compression::Type type)
Set compression algorithm.
Definition: os0file.h:416
#define LOG(ARGS)
Definition: test_trace_plugin.cc:160
bool os_file_rename_func(const char *oldpath, const char *newpath)
NOTE! Use the corresponding macro os_file_rename(), not directly this function! Renames a file (can a...
Definition: os0file.cc:3383
static const ulint OS_FILE_READ_ONLY
Definition: os0file.h:197
void os_aio_free()
Frees the asynchronous io system.
Definition: os0file.cc:6496
pfs_os_file_t os_file_create_simple_no_error_handling_func(const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), not directly this functi...
Definition: os0file.cc:3276
bool is_read() const
Definition: os0file.h:333
void flush(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:97
Directory names for the depth first directory scan.
Definition: os0file.h:1812
void clear_do_not_wake()
Clear the do not wake flag.
Definition: os0file.h:387
Encryption encryption_algorithm() const
Get the encryption algorithm.
Definition: os0file.h:467
Block()
Default constructor.
Definition: os0file.h:90
void os_file_set_umask(ulint umask)
Set the file create umask.
Definition: os0file.cc:7961
dberr_t os_file_get_status(const char *path, os_file_stat_t *stat_info, bool check_rw_perm, bool read_only)
This function returns information about the specified file.
Definition: os0file.cc:5892
file::Block * os_alloc_block() noexcept
Allocate a page for sync IO.
Definition: os0file.cc:941
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:152
UNIV_INLINE dberr_t pfs_os_file_write_func(IORequest &type, const char *name, pfs_os_file_t file, const void *buf, os_offset_t offset, ulint n, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_write(), not directly this function! This is the per...
bool os_file_scan_directory(const char *path, os_dir_cbk_t scan_cbk, bool is_drop)
This function scans the contents of a directory and invokes the callback for each entry...
Definition: os0file.cc:3084
Common #defines and includes for file and socket I/O.
void os_create_block_cache()
Creates and initializes block_cache.
Definition: os0file.cc:6429
Blocks for doing IO, used in the transparent compression and encryption code.
Definition: os0file.h:88
void block_size(ulint block_size)
Set the block size for IO.
Definition: os0file.h:399
No compression.
Definition: file.h:58
UNIV_INLINE pfs_os_file_t pfs_os_file_create_simple_func(mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type, bool read_only, bool *success, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_create_simple(), not directly this function! A perfo...
static const ulint OS_FILE_AIO
Definition: os0file.h:204
byte * m_ptr
Definition: os0file.h:92
std::basic_ostringstream< char, std::char_traits< char >, ut_allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut_allocator.
Definition: ut0new.h:1303
Definition: os0file.h:85
static const ulint OS_FILE_OPERATION_ABORTED
Definition: os0file.h:240
void disable_partial_io_warnings()
Disable partial read warnings.
Definition: os0file.h:360
os_offset_t alloc_size
Allocated size for sparse files in bytes.
Definition: os0file.h:653
static const ulint OS_FILE_ERROR_NOT_SPECIFIED
Definition: os0file.h:237
to create the directories
Definition: os0file.h:184
dberr_t os_file_read_func(IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n)
NOTE! Use the corresponding macro os_file_read(), not directly this function! Requests a synchronous ...
Definition: os0file.cc:5602
static const ulint OS_FILE_AIO_INTERRUPTED
Definition: os0file.h:239
bool is_compressed() const
Definition: os0file.h:433
os_file_size_t os_file_get_size(const char *filename)
Gets a file size.
Definition: os0file.cc:3442
ulint os_n_pending_reads
Number of pending read operations.
Definition: os0file.cc:792
bool is_compression_enabled() const
Definition: os0file.h:438
Compression m_compression
Compression algorithm.
Definition: os0file.h:561
Define for performance schema registration key.
Definition: sync0sync.h:50
unsigned char byte
Blob class.
Definition: common.h:159
void os_file_set_nocache(int fd, const char *file_name, const char *operation_name)
Tries to disable OS caching on an opened file descriptor.
Definition: os0file.cc:5355
dberr_t os_file_read_no_error_handling_func(IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o)
NOTE! Use the corresponding macro os_file_read_no_error_handling(), not directly this function! Reque...
Definition: os0file.cc:5776
struct PSI_file * m_psi
Definition: os0file.h:154
ulint os_n_pending_writes
Number of pending write operations.
Definition: os0file.cc:790
pfs_os_file_t os_file_create_func(const char *name, ulint create_mode, ulint purpose, ulint type, bool read_only, bool *success)
NOTE! Use the corresponding macro os_file_create(), not directly this function! Opens an existing fil...
Definition: os0file.cc:3118
static const ulint OS_DBLWR_FILE
Doublewrite files.
Definition: os0file.h:221
bool os_file_status(const char *path, bool *exists, os_file_type_t *type)
Check the existence and type of the given file.
Definition: os0file.cc:5817
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.c:108
UNIV_INLINE dberr_t pfs_os_file_copy_func(pfs_os_file_t src, os_offset_t src_offset, pfs_os_file_t dest, os_offset_t dest_offset, uint size, const char *src_file, uint src_line)
copy data from one file to another file.
File doesn&#39;t exist.
Definition: os0file.h:620
static const ulint OS_FILE_ERROR_MAX
Definition: os0file.h:243
static const ulint OS_FILE_DISK_FULL
Definition: os0file.h:229
std::string to_string() const
Definition: os0file.h:507
mysql_pfs_key_t innodb_data_file_key
FILE * os_file_create_tmpfile(const char *path)
Create a temporary file.
Definition: os0file.cc:1604
UNIV_INLINE dberr_t pfs_os_file_read_no_error_handling_func(IORequest &type, const char *file_name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o, const char *src_file, uint src_line)
NOTE! Please use the corresponding macro os_file_read_no_error_handling(), not directly this function...
static void start(PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:165
char * innobase_mysql_tmpdir()
return any of the tmpdir path
Definition: ha_innodb.cc:2195
os_file_create_t
Options for os_file_create_func.
Definition: os0file.h:177
void os_file_read_string(FILE *file, char *str, ulint size)
Rewind file to its start, read at most size - 1 bytes from it to str, and NUL-terminate str...
Definition: os0file.cc:1631