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