MySQL 8.0.40
Source Code Documentation
os0file.h
Go to the documentation of this file.
1/***********************************************************************
2
3Copyright (c) 1995, 2024, 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;
231/** @} */
232
233/** Error codes from os_file_get_last_error @{ */
234static const ulint OS_FILE_NOT_FOUND = 71;
235static const ulint OS_FILE_DISK_FULL = 72;
237static const ulint OS_FILE_PATH_ERROR = 74;
238
239/** wait for OS aio resources to become available again */
241
248static const ulint OS_FILE_NAME_TOO_LONG = 82;
250
251static const ulint OS_FILE_ERROR_MAX = 100;
252/** @} */
253
254/** Types for AIO operations @{ */
255
256/** No transformations during read/write, write as is. */
257#define IORequestRead IORequest(IORequest::READ)
258#define IORequestWrite IORequest(IORequest::WRITE)
259
260/**
261The IO Context that is passed down to the low level IO code */
263 public:
264 /** Flags passed in the request, they can be ORred together. */
265 enum {
266 UNSET = 0,
267 READ = 1,
268 WRITE = 2,
269
270 /** Request for a doublewrite page IO */
271 DBLWR = 4,
272
273 /** Enumerations below can be ORed to READ/WRITE above*/
274
275 /** Data file */
277
278 /** Log file request*/
279 LOG = 16,
280
281 /** Disable partial read warnings */
283
284 /** Do not to wake i/o-handler threads, but the caller will do
285 the waking explicitly later, in this way the caller can post
286 several requests in a batch; NOTE that the batch must not be
287 so big that it exhausts the slots in AIO arrays! NOTE that
288 a simulated batch may introduce hidden chances of deadlocks,
289 because I/Os are not actually handled until all
290 have been posted: use with great caution! */
292
293 /** Ignore failed reads of non-existent pages */
295
296 /** Use punch hole if available, only makes sense if
297 compression algorithm != NONE. Ignored if not set */
299
300 /** Force raw read, do not try to compress/decompress.
301 This can be used to force a read and write without any
302 compression e.g., for redo log, merge sort temporary files
303 and the truncate redo log. */
305
306 /** Row log used in online DDL */
307 ROW_LOG = 1024,
308
309 /** We optimise cases where punch hole is not done if the compressed length
310 of the page is the same as the original size of the page. Ignore such
311 optimisations if this flag is set. */
313 };
314
315 /** Default constructor */
318 m_type(READ),
320 m_encryption(),
322 m_elen(0) {
323 /* No op */
324 }
325
326 /**
327 @param[in] type Request type, can be a value that is
328 ORed from the above enum */
329 explicit IORequest(int type)
331 m_type(type),
333 m_encryption(),
335 m_elen(0) {
336 if (is_log() || is_row_log()) {
338 }
339
342 }
343 }
344
345 /** @return true if ignore missing flag is set */
346 [[nodiscard]] static bool ignore_missing(int type) {
347 return ((type & IGNORE_MISSING) == IGNORE_MISSING);
348 }
349
350 /** @return true if it is a read request */
351 [[nodiscard]] bool is_read() const { return ((m_type & READ) == READ); }
352
353 /** @return true if it is a write request */
354 [[nodiscard]] bool is_write() const { return ((m_type & WRITE) == WRITE); }
355
356 /** @return true if it is a redo log write */
357 [[nodiscard]] bool is_log() const { return ((m_type & LOG) == LOG); }
358
359 /** @return true if it is a row log entry used in online DDL */
360 [[nodiscard]] bool is_row_log() const {
361 return ((m_type & ROW_LOG) == ROW_LOG);
362 }
363
364 /** @return true if the simulated AIO thread should be woken up */
365 [[nodiscard]] bool is_wake() const { return ((m_type & DO_NOT_WAKE) == 0); }
366
367 /** @return true if partial read warning disabled */
368 [[nodiscard]] bool is_partial_io_warning_disabled() const {
371 }
372
373 /** Disable partial read warnings */
375
376 /** @return true if missing files should be ignored */
377 [[nodiscard]] bool ignore_missing() const { return (ignore_missing(m_type)); }
378
379 /** @return true if punch hole should be used */
380 [[nodiscard]] bool punch_hole() const {
381 return ((m_type & PUNCH_HOLE) == PUNCH_HOLE);
382 }
383
384 /** @return true if punch hole needs to be done always if it's supported and
385 if the page is to be compressed. */
386 [[nodiscard]] bool is_punch_hole_optimisation_disabled() const {
388
391 }
392
393 /** @return true if the read should be validated */
394 [[nodiscard]] bool validate() const {
395 ut_ad(is_read() ^ is_write());
396
397 return (!is_read() || !punch_hole());
398 }
399
400 /** Set the punch hole flag */
404 }
405 }
406
407 /** Set the force punch hole flag */
411 }
412 }
413
414 /** Clear the do not wake flag */
415 void clear_do_not_wake() { m_type &= ~DO_NOT_WAKE; }
416
417 /** Clear the punch hole flag */
418 void clear_punch_hole() { m_type &= ~PUNCH_HOLE; }
419
420 /** @return the block size to use for IO */
421 [[nodiscard]] ulint block_size() const { return (m_block_size); }
422
423 /** Set the block size for IO
424 @param[in] block_size Block size to set */
426 m_block_size = static_cast<uint32_t>(block_size);
427 }
428
429 /** Returns original size of the IO to make. If one was not specified, then 0
430 is returned. */
431 uint32_t get_original_size() const { return m_original_size; }
432
433 void set_original_size(uint32_t original_size) {
434 m_original_size = original_size;
435 }
436
437 /** Clear all compression related flags */
440
442 }
443
444 /** Compare two requests
445 @return true if the are equal */
446 bool operator==(const IORequest &rhs) const { return (m_type == rhs.m_type); }
447
448 /** Set compression algorithm
449 @param[in] type The compression algorithm to use */
451 if (type == Compression::NONE) {
452 return;
453 }
454
456
458 }
459
460 /** Get the compression algorithm.
461 @return the compression algorithm */
462 [[nodiscard]] Compression compression_algorithm() const {
463 return (m_compression);
464 }
465
466 /** @return true if the page should be compressed */
467 [[nodiscard]] bool is_compressed() const {
469 }
470
471 /** @return true if the page read should not be transformed. */
472 [[nodiscard]] bool is_compression_enabled() const {
473 return ((m_type & NO_COMPRESSION) == 0);
474 }
475
476 /** Disable transformations. */
478
479 /** Get the encryption algorithm.
480 @return the encryption algorithm */
481 [[nodiscard]] Encryption encryption_algorithm() const {
482 return (m_encryption);
483 }
484
485 /** @return true if the page should be encrypted. */
486 [[nodiscard]] bool is_encrypted() const {
488 }
489
490 /** Clear all encryption related flags */
492 m_encryption.set_key(nullptr);
496 }
497
498 /** Note that the IO is for double write buffer page write. */
499 void dblwr() { m_type |= DBLWR; }
500
501 /** @return true if the request is for a dblwr page. */
502 [[nodiscard]] bool is_dblwr() const { return ((m_type & DBLWR) == DBLWR); }
503
504 /** @return true if punch hole is supported */
506 /* In this debugging mode, we act as if punch hole is supported,
507 and then skip any calls to actually punch a hole here.
508 In this way, Transparent Page Compression is still being tested. */
509 DBUG_EXECUTE_IF("ignore_punch_hole", return (true););
510
511#if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) || defined(_WIN32)
512 return (true);
513#else
514 return (false);
515#endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE || _WIN32 */
516 }
517
518 /** @return string representation. */
519 std::string to_string() const {
521
522 os << "bs: " << m_block_size << " flags:";
523
524 if (m_type & READ) {
525 os << " READ";
526 } else if (m_type & WRITE) {
527 os << " WRITE";
528 } else if (m_type & DBLWR) {
529 os << " DBLWR";
530 }
531
532 /** Enumerations below can be ORed to READ/WRITE above*/
533
534 /** Data file */
535 if (m_type & DATA_FILE) {
536 os << " | DATA_FILE";
537 }
538
539 if (m_type & LOG) {
540 os << " | LOG";
541 }
542
544 os << " | DISABLE_PARTIAL_IO_WARNINGS";
545 }
546
547 if (m_type & DO_NOT_WAKE) {
548 os << " | IGNORE_MISSING";
549 }
550
551 if (m_type & PUNCH_HOLE) {
552 os << " | PUNCH_HOLE";
553 }
554
555 if (m_type & NO_COMPRESSION) {
556 os << " | NO_COMPRESSION";
557 }
558
559 os << ", comp: " << m_compression.to_string();
560 os << ", enc: " << m_encryption.to_string(m_encryption.get_type());
561
562 return (os.str());
563 }
564
565 /** Get a reference to the underlying encryption information.
566 @return reference to the encryption information. */
567 [[nodiscard]] Encryption &get_encryption_info() noexcept {
568 return m_encryption;
569 }
570
571 /** Set the encrypted block to the given value.
572 @param[in] eblock the encrypted block. */
573 void set_encrypted_block(const file::Block *eblock) noexcept {
574 m_eblock = eblock;
575 }
576
577 /** Get the encrypted block.
578 @return the encrypted block. */
579 [[nodiscard]] const file::Block *get_encrypted_block() const noexcept {
580 return m_eblock;
581 }
582
583 private:
584 /* File system best block size */
585 uint32_t m_block_size{};
586
587 /** Request type bit flags */
588 int m_type{};
589
590 /** Compression algorithm */
592
593 /** Encryption algorithm */
595
596 /** The encrypted block. */
598
599 /** The length of data in encrypted block. */
600 uint32_t m_elen{};
601
602 /** Length of the original IO size.
603 For reads it is an expected uncompressed length.
604 For writes it is a length up to which the write is to be extended with a punch
605 hole, if supported. */
606 uint32_t m_original_size{};
607};
608
609/** @} */
610
611/** Sparse file size information. */
613 /** Total size of file in bytes */
615
616 /** If it is a sparse file then this is the number of bytes
617 actually allocated for the file. */
619};
620
621/** Win NT does not allow more than 64 */
623
624/** Modes for aio operations @{ */
625enum class AIO_mode : size_t {
626 /** Normal asynchronous i/o not for ibuf pages or ibuf bitmap pages */
627 NORMAL = 21,
628
629 /** Asynchronous i/o for ibuf pages or ibuf bitmap pages */
630 IBUF = 22,
631
632 /** Asynchronous i/o where the calling thread will itself wait for
633 the i/o to complete, doing also the job of the i/o-handler thread;
634 can be used for any pages, ibuf or non-ibuf. This is used to save
635 CPU time, as we can do with fewer thread switches. Plain synchronous
636 I/O is not as good, because it must serialize the file seek and read
637 or write, causing a bottleneck for parallelism. */
638 SYNC = 24
639};
640/** @} */
641
644extern ulint os_n_fsyncs;
645
646/* File types for directory entry data type */
647
649 /** Get status failed. */
651
652 /** stat() failed, with ENAMETOOLONG */
654
655 /** stat() failed with EACCESS */
657
658 /** File doesn't exist. */
660
661 /** File exists but type is unknown. */
663
664 /** Ordinary file. */
666
667 /** Directory. */
669
670 /** Symbolic link. */
672
673 /** Block device. */
676
677/* Maximum path string length in bytes when referring to tables with in the
678'./databasename/tablename.ibd' path format; we can allocate at least 2 buffers
679of this size from the thread stack; that is why this should not be made much
680bigger than 4000 bytes. The maximum path length used by any storage engine
681in the server must be at least this big. */
682constexpr uint32_t OS_FILE_MAX_PATH = 4000;
683static_assert(FN_REFLEN_SE >= OS_FILE_MAX_PATH,
684 "(FN_REFLEN_SE < OS_FILE_MAX_PATH)");
685
686/** Struct used in fetching information of a file in a directory */
688 char name[OS_FILE_MAX_PATH]; /*!< path to a file */
689 os_file_type_t type; /*!< file type */
690 os_offset_t size; /*!< file size in bytes */
691 os_offset_t alloc_size; /*!< Allocated size for
692 sparse files in bytes */
693 uint32_t block_size; /*!< Block size to use for IO
694 in bytes*/
695 time_t ctime; /*!< creation time */
696 time_t mtime; /*!< modification time */
697 time_t atime; /*!< access time */
698 bool rw_perm; /*!< true if can be opened
699 in read-write mode. Only valid
700 if type == OS_FILE_TYPE_FILE */
701};
702
703#ifndef UNIV_HOTBACKUP
704/** Create a temporary file. This function is like tmpfile(3). It will create
705the file in the MySQL server configuration parameter (--tmpdir).
706@return temporary file handle, or NULL on error */
708#endif /* !UNIV_HOTBACKUP */
709
710/** This function attempts to create a directory named pathname. The new
711directory gets default permissions. On Unix the permissions are
712(0770 & ~umask). If the directory exists already, nothing is done and
713the call succeeds, unless the fail_if_exists arguments is true.
714If another error occurs, such as a permission error, this does not crash,
715but reports the error and returns false.
716@param[in] pathname directory name as null-terminated string
717@param[in] fail_if_exists if true, pre-existing directory is treated as
718 an error.
719@return true if call succeeds, false on error */
720bool os_file_create_directory(const char *pathname, bool fail_if_exists);
721
722/** Callback function type to be implemented by caller. It is called for each
723entry in directory.
724@param[in] path path to the file
725@param[in] name name of the file */
726typedef std::function<void(const char *path, const char *name)> os_dir_cbk_t;
727
728/** This function scans the contents of a directory and invokes the callback
729for each entry.
730@param[in] path directory name as null-terminated string
731@param[in] scan_cbk use callback to be called for each entry
732@param[in] is_drop attempt to drop the directory after scan
733@return true if call succeeds, false on error */
734bool os_file_scan_directory(const char *path, os_dir_cbk_t scan_cbk,
735 bool is_drop);
736
737/** NOTE! Use the corresponding macro
738os_file_create_simple_no_error_handling(), not directly this function!
739A simple function to open or create a file.
740@param[in] name name of the file or path as a
741null-terminated string
742@param[in] create_mode create mode
743@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
744 OS_FILE_READ_ALLOW_DELETE; the last option
745 is used by a backup program reading the file
746@param[in] read_only if true read only mode checks are enforced
747@param[in] umask UNIX access permission to be set when creating a
748 file. Use os_umask_default to use global default
749 umask.
750@param[out] success true if succeeded
751@return own: handle to the file, not defined if error, error number
752 can be retrieved with os_file_get_last_error */
754 const char *name, ulint create_mode, ulint access_type, bool read_only,
755#ifndef _WIN32
756 mode_t umask,
757#endif
758 bool *success);
759
760/** Tries to disable OS caching on an opened file descriptor.
761@param[in] fd file descriptor to alter
762@param[in] file_name file name, used in the diagnostic message
763@param[in] operation_name "open" or "create"; used in the diagnostic
764 message */
765void os_file_set_nocache(int fd, const char *file_name,
766 const char *operation_name);
767
768/** NOTE! Use the corresponding macro os_file_create(), not directly
769this function!
770Opens an existing file or creates a new.
771@param[in] name name of the file or path as a null-terminated
772 string
773@param[in] create_mode create mode
774@param[in] purpose OS_DATA_FILE, OS_LOG_FILE etc.
775@param[in] read_only if true read only mode checks are enforced
776@param[out] success true if succeeded
777@return own: handle to the file, not defined if error, error number
778 can be retrieved with os_file_get_last_error */
779[[nodiscard]] pfs_os_file_t os_file_create_func(const char *name,
780 ulint create_mode,
781 ulint purpose, bool read_only,
782 bool *success);
783
784/** Deletes a file. The file has to be closed before calling this.
785@param[in] name file path as a null-terminated string
786@return true if success */
787bool os_file_delete_func(const char *name);
788
789/** Deletes a file if it exists. The file has to be closed before calling this.
790@param[in] name file path as a null-terminated string
791@param[out] exist indicate if file pre-exist
792@return true if success */
793bool os_file_delete_if_exists_func(const char *name, bool *exist);
794
795/** NOTE! Use the corresponding macro os_file_rename(), not directly
796this function!
797Renames a file (can also move it to another directory). It is safest that the
798file is closed before calling this function.
799@param[in] oldpath old file path as a null-terminated string
800@param[in] newpath new file path
801@return true if success */
802bool os_file_rename_func(const char *oldpath, const char *newpath);
803
804/** NOTE! Use the corresponding macro os_file_close(), not directly
805this function!
806Closes a file handle. In case of error, error number can be retrieved with
807os_file_get_last_error.
808@param[in] file Handle to a file
809@return true if success */
811
812#ifdef UNIV_PFS_IO
813
814/* Keys to register InnoDB I/O with performance schema */
822
823/* Following four macros are instumentations to register
824various file I/O operations with performance schema.
8251) register_pfs_file_open_begin() and register_pfs_file_open_end() are
826used to register file creation, opening and closing.
8272) register_pfs_file_rename_begin() and register_pfs_file_rename_end()
828are used to register file renaming.
8293) register_pfs_file_io_begin() and register_pfs_file_io_end() are
830used to register actual file read, write and flush
8314) register_pfs_file_close_begin() and register_pfs_file_close_end()
832are used to register file deletion operations*/
833#define register_pfs_file_open_begin(state, locker, key, op, name, \
834 src_location) \
835 do { \
836 locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
837 op, name, &locker); \
838 if (locker != nullptr) { \
839 PSI_FILE_CALL(start_file_open_wait) \
840 (locker, src_location.filename, static_cast<uint>(src_location.line)); \
841 } \
842 } while (0)
843
844#define register_pfs_file_open_end(locker, file, result) \
845 do { \
846 if (locker != nullptr) { \
847 file.m_psi = PSI_FILE_CALL(end_file_open_wait)(locker, result); \
848 } \
849 } while (0)
850
851#define register_pfs_file_rename_begin(state, locker, key, op, from, to, \
852 src_location) \
853 do { \
854 locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
855 op, from, &locker); \
856 if (locker != nullptr) { \
857 PSI_FILE_CALL(start_file_rename_wait) \
858 (locker, (size_t)0, from, to, src_location.filename, \
859 static_cast<uint>(src_location.line)); \
860 } \
861 } while (0)
862
863#define register_pfs_file_rename_end(locker, from, to, result) \
864 do { \
865 if (locker != nullptr) { \
866 PSI_FILE_CALL(end_file_rename_wait)(locker, from, to, result); \
867 } \
868 } while (0)
869
870#define register_pfs_file_close_begin(state, locker, key, op, name, \
871 src_location) \
872 do { \
873 locker = PSI_FILE_CALL(get_thread_file_name_locker)(state, key.m_value, \
874 op, name, &locker); \
875 if (locker != nullptr) { \
876 PSI_FILE_CALL(start_file_close_wait) \
877 (locker, src_location.filename, static_cast<uint>(src_location.line)); \
878 } \
879 } while (0)
880
881#define register_pfs_file_close_end(locker, result) \
882 do { \
883 if (locker != nullptr) { \
884 PSI_FILE_CALL(end_file_close_wait)(locker, result); \
885 } \
886 } while (0)
887
888#define register_pfs_file_io_begin(state, locker, file, count, op, \
889 src_location) \
890 do { \
891 locker = \
892 PSI_FILE_CALL(get_thread_file_stream_locker)(state, file.m_psi, op); \
893 if (locker != nullptr) { \
894 PSI_FILE_CALL(start_file_wait) \
895 (locker, count, src_location.filename, \
896 static_cast<uint>(src_location.line)); \
897 } \
898 } while (0)
899
900#define register_pfs_file_io_end(locker, count) \
901 do { \
902 if (locker != nullptr) { \
903 PSI_FILE_CALL(end_file_wait)(locker, count); \
904 } \
905 } while (0)
906
907/* Following macros/functions are file I/O APIs that would be performance
908schema instrumented if "UNIV_PFS_IO" is defined. They would point to
909wrapper functions with performance schema instrumentation in such case.
910
911os_file_create
912os_file_create_simple_no_error_handling
913os_file_close
914os_file_rename
915os_aio
916os_file_read
917os_file_read_no_error_handling
918os_file_read_no_error_handling_int_fd
919os_file_write
920
921The wrapper functions have the prefix of "innodb_". */
922
923#define os_file_create(key, name, create, purpose, read_only, success) \
924 pfs_os_file_create_func(key, name, create, purpose, read_only, success, \
925 UT_LOCATION_HERE)
926
927#ifndef _WIN32
928#define os_file_create_simple_no_error_handling(key, name, create_mode, \
929 access, read_only, success) \
930 pfs_os_file_create_simple_no_error_handling_func( \
931 key, name, create_mode, access, read_only, os_innodb_umask_default, \
932 success, UT_LOCATION_HERE)
933
934#define os_file_create_simple_no_error_handling_with_umask( \
935 key, name, create_mode, access, read_only, umask, success) \
936 pfs_os_file_create_simple_no_error_handling_func(key, name, create_mode, \
937 access, read_only, umask, \
938 success, UT_LOCATION_HERE)
939#else
940#define os_file_create_simple_no_error_handling(key, name, create_mode, \
941 access, read_only, success) \
942 pfs_os_file_create_simple_no_error_handling_func( \
943 key, name, create_mode, access, read_only, success, UT_LOCATION_HERE)
944#endif
945
946#define os_file_close_pfs(file) pfs_os_file_close_func(file, UT_LOCATION_HERE)
947
948#define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
949 message2) \
950 pfs_os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
951 message2, UT_LOCATION_HERE)
952
953#define os_file_read_pfs(type, file_name, file, buf, offset, n) \
954 pfs_os_file_read_func(type, file_name, file, buf, offset, n, UT_LOCATION_HERE)
955
956#define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
957 pfs_os_file_read_first_page_func(type, file_name, file, buf, n, \
958 UT_LOCATION_HERE)
959
960#define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
961 pfs_os_file_copy_func(src, src_offset, dest, dest_offset, size, \
962 UT_LOCATION_HERE)
963
964#define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
965 n, o) \
966 pfs_os_file_read_no_error_handling_func(type, file_name, file, buf, offset, \
967 n, o, UT_LOCATION_HERE)
968
969#define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
970 offset, n, o) \
971 pfs_os_file_read_no_error_handling_int_fd_func( \
972 type, file_name, file, buf, offset, n, o, UT_LOCATION_HERE)
973
974#define os_file_write_pfs(type, name, file, buf, offset, n) \
975 pfs_os_file_write_func(type, name, file, buf, offset, n, UT_LOCATION_HERE)
976
977#define os_file_write_int_fd(type, name, file, buf, offset, n) \
978 pfs_os_file_write_int_fd_func(type, name, file, buf, offset, n, \
979 UT_LOCATION_HERE)
980
981#define os_file_flush_pfs(file) pfs_os_file_flush_func(file, UT_LOCATION_HERE)
982
983#define os_file_rename(key, oldpath, newpath) \
984 pfs_os_file_rename_func(key, oldpath, newpath, UT_LOCATION_HERE)
985
986#define os_file_delete(key, name) \
987 pfs_os_file_delete_func(key, name, UT_LOCATION_HERE)
988
989#define os_file_delete_if_exists(key, name, exist) \
990 pfs_os_file_delete_if_exists_func(key, name, exist, UT_LOCATION_HERE)
991
992/** NOTE! Please use the corresponding macro
993os_file_create_simple_no_error_handling(), not directly this function!
994A performance schema instrumented wrapper function for
995os_file_create_simple_no_error_handling(). Add instrumentation to
996monitor file creation/open.
997@param[in] key Performance Schema Key
998@param[in] name name of the file or path as a null-terminated
999 string
1000@param[in] create_mode create mode
1001@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
1002 OS_FILE_READ_ALLOW_DELETE; the last option is
1003 used by a backup program reading the file
1004@param[in] read_only if true read only mode checks are enforced
1005@param[in] umask UNIX access permission to be set when creating a
1006 file. Use os_umask_default to use global default
1007 umask.
1008@param[out] success true if succeeded
1009@param[in] src_location location where func invoked
1010@return own: handle to the file, not defined if error, error number
1011 can be retrieved with os_file_get_last_error */
1012[[nodiscard]] static inline pfs_os_file_t
1014 mysql_pfs_key_t key, const char *name, ulint create_mode, ulint access_type,
1015 bool read_only,
1016#ifndef _WIN32
1017 mode_t umask,
1018#endif
1019 bool *success, ut::Location src_location);
1020
1021/** NOTE! Please use the corresponding macro os_file_create(), not directly
1022this function!
1023A performance schema wrapper function for os_file_create().
1024Add instrumentation to monitor file creation/open.
1025@param[in] key Performance Schema Key
1026@param[in] name name of the file or path as a null-terminated
1027 string
1028@param[in] create_mode create mode
1029@param[in] purpose OS_DATA_FILE, OS_LOG_FILE etc.
1030@param[in] read_only if true read only mode checks are enforced
1031@param[out] success true if succeeded
1032@param[in] src_location location where func invoked
1033@return own: handle to the file, not defined if error, error number
1034 can be retrieved with os_file_get_last_error */
1035[[nodiscard]] static inline pfs_os_file_t pfs_os_file_create_func(
1036 mysql_pfs_key_t key, const char *name, ulint create_mode, ulint purpose,
1037 bool read_only, bool *success, ut::Location src_location);
1038
1039/** NOTE! Please use the corresponding macro os_file_close(), not directly
1040this function!
1041A performance schema instrumented wrapper function for os_file_close().
1042@param[in] file handle to a file
1043@param[in] src_location location where func invoked
1044@return true if success */
1046 ut::Location src_location);
1047
1048/** NOTE! Please use the corresponding macro os_file_read(), not directly
1049this function!
1050This is the performance schema instrumented wrapper function for
1051os_file_read() which requests a synchronous read operation.
1052@param[in, out] type IO request context
1053@param[in] file_name file name
1054@param[in] file Open file handle
1055@param[out] buf buffer where to read
1056@param[in] offset file offset where to read
1057@param[in] n number of bytes to read
1058@param[in] src_location location where func invoked
1059@return DB_SUCCESS if request was successful */
1061 const char *file_name,
1062 pfs_os_file_t file, void *buf,
1063 os_offset_t offset, ulint n,
1064 ut::Location src_location);
1065
1066/** NOTE! Please use the corresponding macro os_file_read_first_page(),
1067not directly this function!
1068This is the performance schema instrumented wrapper function for
1069os_file_read_first_page() which requests a synchronous read operation
1070of page 0 of IBD file
1071@param[in, out] type IO request context
1072@param[in] file_name file name
1073@param[in] file Open file handle
1074@param[out] buf buffer where to read
1075@param[in] n number of bytes to read
1076@param[in] src_location location where func invoked
1077@return DB_SUCCESS if request was successful */
1079 IORequest &type, const char *file_name, pfs_os_file_t file, void *buf,
1080 ulint n, ut::Location src_location);
1081
1082/** copy data from one file to another file. Data is read/written
1083at current file offset.
1084@param[in] src file handle to copy from
1085@param[in] src_offset offset to copy from
1086@param[in] dest file handle to copy to
1087@param[in] dest_offset offset to copy to
1088@param[in] size number of bytes to copy
1089@param[in] src_location location where func invoked
1090@return DB_SUCCESS if successful */
1092 os_offset_t src_offset,
1093 pfs_os_file_t dest,
1094 os_offset_t dest_offset, uint size,
1095 ut::Location src_location);
1096
1097/** NOTE! Please use the corresponding macro os_file_read_no_error_handling(),
1098not directly this function!
1099This is the performance schema instrumented wrapper function for
1100os_file_read_no_error_handling_func() which requests a synchronous
1101read operation.
1102@param[in, out] type IO request context
1103@param[in] file_name file name
1104@param[in] file Open file handle
1105@param[out] buf buffer where to read
1106@param[in] offset file offset where to read
1107@param[in] n number of bytes to read
1108@param[out] o number of bytes actually read
1109@param[in] src_location location where func invoked
1110@return DB_SUCCESS if request was successful */
1112 IORequest &type, const char *file_name, pfs_os_file_t file, void *buf,
1113 os_offset_t offset, ulint n, ulint *o, ut::Location src_location);
1114
1115/** NOTE! Please use the corresponding macro
1116os_file_read_no_error_handling_int_fd(), not directly this function!
1117This is the performance schema instrumented wrapper function for
1118os_file_read_no_error_handling_int_fd_func() which requests a
1119synchronous read operation on files with int type descriptors.
1120@param[in, out] type IO request context
1121@param[in] file_name file name
1122@param[in] file Open file handle
1123@param[out] buf buffer where to read
1124@param[in] offset file offset where to read
1125@param[in] n number of bytes to read
1126@param[out] o number of bytes actually read
1127@param[in] src_location location where func invoked
1128@return DB_SUCCESS if request was successful */
1129
1131 IORequest &type, const char *file_name, int file, void *buf,
1132 os_offset_t offset, ulint n, ulint *o, ut::Location src_location);
1133
1134/** NOTE! Please use the corresponding macro os_aio(), not directly this
1135function!
1136Performance schema wrapper function of os_aio() which requests
1137an asynchronous I/O operation.
1138@param[in] type IO request context
1139@param[in] mode IO mode
1140@param[in] name Name of the file or path as NUL terminated
1141 string
1142@param[in] file Open file handle
1143@param[out] buf buffer where to read
1144@param[in] offset file offset where to read
1145@param[in] n how many bytes to read or write; this
1146must not cross a file boundary; in AIO this must be a block size multiple
1147@param[in] read_only if true read only mode checks are enforced
1148@param[in,out] m1 Message for the AIO handler, (can be used to
1149 identify a completed AIO operation); ignored
1150 if mode is OS_AIO_SYNC
1151@param[in,out] m2 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] location location where func invoked
1155@return DB_SUCCESS if request was queued successfully, false if fail */
1157 const char *name, pfs_os_file_t file,
1158 void *buf, os_offset_t offset, ulint n,
1159 bool read_only, fil_node_t *m1, void *m2,
1160 ut::Location location);
1161
1162/** NOTE! Please use the corresponding macro os_file_write(), not directly
1163this function!
1164This is the performance schema instrumented wrapper function for
1165os_file_write() which requests a synchronous write operation.
1166@param[in, out] type IO request context
1167@param[in] name Name of the file or path as NUL terminated
1168 string
1169@param[in] file Open file handle
1170@param[out] buf buffer where to read
1171@param[in] offset file offset where to read
1172@param[in] n number of bytes to read
1173@param[in] src_location location where func invoked
1174@return DB_SUCCESS if request was successful */
1177 const void *buf,
1178 os_offset_t offset, ulint n,
1179 ut::Location src_location);
1180
1181/** NOTE! Please use the corresponding macro os_file_write(), not
1182directly this function!
1183This is the performance schema instrumented wrapper function for
1184os_file_write() which requests a synchronous write operation
1185on files with int type descriptors.
1186@param[in, out] type IO request context
1187@param[in] name Name of the file or path as NUL terminated
1188 string
1189@param[in] file Open file handle
1190@param[out] buf buffer where to read
1191@param[in] offset file offset where to read
1192@param[in] n number of bytes to read
1193@param[in] src_location location where func invoked
1194@return DB_SUCCESS if request was successful */
1196 const char *name, int file,
1197 const void *buf,
1198 os_offset_t offset, ulint n,
1199 ut::Location src_location);
1200
1201/** NOTE! Please use the corresponding macro os_file_flush(), not directly
1202this function!
1203This is the performance schema instrumented wrapper function for
1204os_file_flush() which flushes the write buffers of a given file to the disk.
1205Flushes the write buffers of a given file to the disk.
1206@param[in] file Open file handle
1207@param[in] src_location location where func invoked
1208@return true if success */
1210 ut::Location src_location);
1211
1212/** NOTE! Please use the corresponding macro os_file_rename(), not directly
1213this function!
1214This is the performance schema instrumented wrapper function for
1215os_file_rename()
1216@param[in] key Performance Schema Key
1217@param[in] oldpath old file path as a null-terminated string
1218@param[in] newpath new file path
1219@param[in] src_location location where func invoked
1220@return true if success */
1222 const char *oldpath,
1223 const char *newpath,
1224 ut::Location src_location);
1225
1226/**
1227NOTE! Please use the corresponding macro os_file_delete(), not directly
1228this function!
1229This is the performance schema instrumented wrapper function for
1230os_file_delete()
1231@param[in] key Performance Schema Key
1232@param[in] name old file path as a null-terminated string
1233@param[in] src_location location where func invoked
1234@return true if success */
1236 const char *name,
1237 ut::Location src_location);
1238
1239/**
1240NOTE! Please use the corresponding macro os_file_delete_if_exists(), not
1241directly this function!
1242This is the performance schema instrumented wrapper function for
1243os_file_delete_if_exists()
1244@param[in] key Performance Schema Key
1245@param[in] name old file path as a null-terminated string
1246@param[in] exist indicate if file pre-exist
1247@param[in] src_location location where func invoked
1248@return true if success */
1250 const char *name,
1251 bool *exist,
1252 ut::Location src_location);
1253
1254#else /* UNIV_PFS_IO */
1255
1256/* If UNIV_PFS_IO is not defined, these I/O APIs point
1257to original un-instrumented file I/O APIs */
1258#define os_file_create(key, name, create, purpose, read_only, success) \
1259 os_file_create_func(name, create, purpose, read_only, success)
1260
1261#ifndef _WIN32
1262
1263#define os_file_create_simple_no_error_handling(key, name, create_mode, \
1264 access, read_only, success) \
1265 os_file_create_simple_no_error_handling_func( \
1266 name, create_mode, access, read_only, os_innodb_umask_default, success)
1267
1268#define os_file_create_simple_no_error_handling_with_umask( \
1269 key, name, create_mode, access, read_only, umask, success) \
1270 os_file_create_simple_no_error_handling_func(name, create_mode, access, \
1271 read_only, umask, success)
1272
1273#else
1274
1275#define os_file_create_simple_no_error_handling(key, name, create_mode, \
1276 access, read_only, success) \
1277 os_file_create_simple_no_error_handling_func(name, create_mode, access, \
1278 read_only, success)
1279
1280#endif
1281
1282#define os_file_close_pfs(file) os_file_close_func(file)
1283
1284#define os_aio(type, mode, name, file, buf, offset, n, read_only, message1, \
1285 message2) \
1286 os_aio_func(type, mode, name, file, buf, offset, n, read_only, message1, \
1287 message2)
1288
1289#define os_file_read_pfs(type, file_name, file, buf, offset, n) \
1290 os_file_read_func(type, file_name, file, buf, offset, n)
1291
1292#define os_file_read_first_page_pfs(type, file_name, file, buf, n) \
1293 os_file_read_first_page_func(type, file_name, file, buf, n)
1294
1295#define os_file_copy_pfs(src, src_offset, dest, dest_offset, size) \
1296 os_file_copy_func(src, src_offset, dest, dest_offset, size)
1297
1298#define os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, \
1299 n, o) \
1300 os_file_read_no_error_handling_func(type, file_name, file, buf, offset, n, o)
1301
1302#define os_file_read_no_error_handling_int_fd(type, file_name, file, buf, \
1303 offset, n, o) \
1304 os_file_read_no_error_handling_func(type, file_name, OS_FILE_FROM_FD(file), \
1305 buf, offset, n, o)
1306
1307#define os_file_write_pfs(type, name, file, buf, offset, n) \
1308 os_file_write_func(type, name, file, buf, offset, n)
1309
1310#define os_file_write_int_fd(type, name, file, buf, offset, n) \
1311 os_file_write_func(type, name, OS_FILE_FROM_FD(file), buf, offset, n)
1312
1313#define os_file_flush_pfs(file) os_file_flush_func(file)
1314
1315#define os_file_rename(key, oldpath, newpath) \
1316 os_file_rename_func(oldpath, newpath)
1317
1318#define os_file_delete(key, name) os_file_delete_func(name)
1319
1320#define os_file_delete_if_exists(key, name, exist) \
1321 os_file_delete_if_exists_func(name, exist)
1322
1323#endif /* UNIV_PFS_IO */
1324
1325#ifdef UNIV_PFS_IO
1326#define os_file_close(file) os_file_close_pfs(file)
1327#else
1328#define os_file_close(file) os_file_close_pfs((file).m_file)
1329#endif
1330
1331#ifdef UNIV_PFS_IO
1332#define os_file_read(type, file_name, file, buf, offset, n) \
1333 os_file_read_pfs(type, file_name, file, buf, offset, n)
1334#else
1335#define os_file_read(type, file_name, file, buf, offset, n) \
1336 os_file_read_pfs(type, file_name, file.m_file, buf, offset, n)
1337#endif
1338
1339#ifdef UNIV_PFS_IO
1340#define os_file_read_first_page(type, file_name, file, buf, n) \
1341 os_file_read_first_page_pfs(type, file_name, file, buf, n)
1342#else
1343#define os_file_read_first_page(type, file_name, file, buf, n) \
1344 os_file_read_first_page_pfs(type, file_name, file.m_file, buf, n)
1345#endif
1346
1347#ifdef UNIV_PFS_IO
1348#define os_file_flush(file) os_file_flush_pfs(file)
1349#else
1350#define os_file_flush(file) os_file_flush_pfs(file.m_file)
1351#endif
1352
1353#ifdef UNIV_PFS_IO
1354#define os_file_write(type, name, file, buf, offset, n) \
1355 os_file_write_pfs(type, name, file, buf, offset, n)
1356#else
1357#define os_file_write(type, name, file, buf, offset, n) \
1358 os_file_write_pfs(type, name, file.m_file, buf, offset, n)
1359#endif
1360
1361#ifdef UNIV_PFS_IO
1362#define os_file_copy(src, src_offset, dest, dest_offset, size) \
1363 os_file_copy_pfs(src, src_offset, dest, dest_offset, size)
1364#else
1365#define os_file_copy(src, src_offset, dest, dest_offset, size) \
1366 os_file_copy_pfs(src.m_file, src_offset, dest.m_file, dest_offset, size)
1367#endif
1368
1369#ifdef UNIV_PFS_IO
1370#define os_file_read_no_error_handling(type, file_name, file, buf, offset, n, \
1371 o) \
1372 os_file_read_no_error_handling_pfs(type, file_name, file, buf, offset, n, o)
1373#else
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.m_file, buf, \
1377 offset, n, o)
1378#endif
1379
1380#ifdef UNIV_HOTBACKUP
1381/** Closes a file handle.
1382@param[in] file handle to a file
1383@return true if success */
1384bool os_file_close_no_error_handling(os_file_t file);
1385#endif /* UNIV_HOTBACKUP */
1386
1387/** Gets a file size.
1388@param[in] filename Full path to the filename to check
1389@return file size if OK, else set m_total_size to ~0 and m_alloc_size to
1390 errno. */
1391[[nodiscard]] os_file_size_t os_file_get_size(const char *filename);
1392
1393/** Gets a file size.
1394@param[in] file Handle to a file
1395@return file size, or (os_offset_t) -1 on failure */
1397
1398/** Allocate a block to file using fallocate from the given offset if
1399fallocate is supported. Falls back to the old slower method of writing
1400zeros otherwise.
1401@param[in] name name of the file
1402@param[in] file handle to the file
1403@param[in] offset file offset
1404@param[in] size file size
1405@param[in] flush flush file content to disk
1406@return true if success */
1407[[nodiscard]] bool os_file_set_size_fast(const char *name, pfs_os_file_t file,
1408 os_offset_t offset, os_offset_t size,
1409 bool flush);
1410
1411/** Write the specified number of zeros to a file from specific offset.
1412@param[in] name name of the file or path as a null-terminated
1413 string
1414@param[in] file handle to a file
1415@param[in] offset file offset
1416@param[in] size file size
1417@param[in] flush flush file content to disk
1418@return true if success */
1419[[nodiscard]] bool os_file_set_size(const char *name, pfs_os_file_t file,
1420 os_offset_t offset, os_offset_t size,
1421 bool flush);
1422
1423/** Truncates a file at its current position.
1424@param[in,out] file file to be truncated
1425@return true if success */
1426bool os_file_set_eof(FILE *file); /*!< in: file to be truncated */
1427
1428/** Truncates a file to a specified size in bytes.
1429Do nothing if the size to preserve is greater or equal to the current
1430size of the file.
1431@param[in] pathname file path
1432@param[in] file file to be truncated
1433@param[in] size size to preserve in bytes
1434@return true if success */
1435bool os_file_truncate(const char *pathname, pfs_os_file_t file,
1436 os_offset_t size);
1437
1438/** Set read/write position of a file handle to specific offset.
1439@param[in] pathname file path
1440@param[in] file file handle
1441@param[in] offset read/write offset
1442@return true if success */
1443bool os_file_seek(const char *pathname, os_file_t file, os_offset_t offset);
1444
1445/** NOTE! Use the corresponding macro os_file_flush(), not directly this
1446function!
1447Flushes the write buffers of a given file to the disk.
1448@param[in] file handle to a file
1449@return true if success */
1451
1452/** Retrieves the last error number if an error occurs in a file io function.
1453The number should be retrieved before any other OS calls (because they may
1454overwrite the error number). If the number is not known to this program,
1455the OS error number + 100 is returned.
1456@param[in] report_all_errors true if we want an error message printed
1457 for all errors
1458@return error number, or OS error number + 100 */
1459ulint os_file_get_last_error(bool report_all_errors);
1460
1461/** NOTE! Use the corresponding macro os_file_read_first_page(), not directly
1462this function!
1463Requests a synchronous read operation of page 0 of IBD file.
1464@param[in] type IO request context
1465@param[in] file_name file name
1466@param[in] file Open file handle
1467@param[out] buf buffer where to read
1468@param[in] offset file offset where to read
1469@param[in] n number of bytes to read
1470@return DB_SUCCESS if request was successful, DB_IO_ERROR on failure */
1471[[nodiscard]] dberr_t os_file_read_func(IORequest &type, const char *file_name,
1472 os_file_t file, void *buf,
1473 os_offset_t offset, ulint n);
1474
1475/** NOTE! Use the corresponding macro os_file_read_first_page(),
1476not directly this function!
1477Requests a synchronous read operation of page 0 of IBD file
1478@param[in] type IO request context
1479@param[in] file_name file name
1480@param[in] file Open file handle
1481@param[out] buf buffer where to read
1482@param[in] n number of bytes to read
1483@return DB_SUCCESS if request was successful, DB_IO_ERROR on failure */
1485 const char *file_name,
1486 os_file_t file, void *buf,
1487 ulint n);
1488
1489/** Copy data from one file to another file. Data is read/written
1490at current file offset.
1491@param[in] src_file file handle to copy from
1492@param[in] src_offset offset to copy from
1493@param[in] dest_file file handle to copy to
1494@param[in] dest_offset offset to copy to
1495@param[in] size number of bytes to copy
1496@return DB_SUCCESS if successful */
1497[[nodiscard]] dberr_t os_file_copy_func(os_file_t src_file,
1498 os_offset_t src_offset,
1499 os_file_t dest_file,
1500 os_offset_t dest_offset, uint size);
1501
1502/** Rewind file to its start, read at most size - 1 bytes from it to str, and
1503NUL-terminate str. All errors are silently ignored. This function is
1504mostly meant to be used with temporary files.
1505@param[in,out] file File to read from
1506@param[in,out] str Buffer where to read
1507@param[in] size Size of buffer */
1508void os_file_read_string(FILE *file, char *str, ulint size);
1509
1510/** NOTE! Use the corresponding macro os_file_read_no_error_handling(),
1511not directly this function!
1512Requests a synchronous positioned read operation. This function does not do
1513any error handling. In case of error it returns false.
1514@param[in] type IO request context
1515@param[in] file_name file name
1516@param[in] file Open file handle
1517@param[out] buf buffer where to read
1518@param[in] offset file offset where to read
1519@param[in] n number of bytes to read
1520@param[out] o number of bytes actually read
1521@return DB_SUCCESS or error code */
1523 IORequest &type, const char *file_name, os_file_t file, void *buf,
1524 os_offset_t offset, ulint n, ulint *o);
1525
1526/** NOTE! Use the corresponding macro os_file_write(), not directly this
1527function!
1528Requests a synchronous write operation.
1529@param[in,out] type IO request context
1530@param[in] name name of the file or path as a null-terminated
1531 string
1532@param[in] file Open file handle
1533@param[out] buf buffer where to read
1534@param[in] offset file offset where to read
1535@param[in] n number of bytes to read
1536@return DB_SUCCESS if request was successful */
1537[[nodiscard]] dberr_t os_file_write_func(IORequest &type, const char *name,
1538 os_file_t file, const void *buf,
1539 os_offset_t offset, ulint n);
1540
1541/** Check the existence and type of a given path.
1542@param[in] path pathname of the file
1543@param[out] exists true if file exists
1544@param[out] type type of the file (if it exists)
1545@return true if call succeeded */
1546bool os_file_status(const char *path, bool *exists, os_file_type_t *type);
1547
1548/** Check the existence and usefulness of a given path.
1549@param[in] path path name
1550@retval true if the path exists and can be used
1551@retval false if the path does not exist or if the path is
1552unusable to get to a possibly existing file or directory. */
1553bool os_file_exists(const char *path);
1554
1555/** Create all missing subdirectories along the given path.
1556@return DB_SUCCESS if OK, otherwise error code. */
1558
1559#ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
1560/* Test the function os_file_get_parent_dir. */
1561void unit_test_os_file_get_parent_dir();
1562#endif /* UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR */
1563
1564#ifdef UNIV_HOTBACKUP
1565/** Deallocates the "Blocks" in block_cache */
1566void meb_free_block_cache();
1567#endif /* UNIV_HOTBACKUP */
1568
1569/** Creates and initializes block_cache. Creates array of MAX_BLOCKS
1570and allocates the memory in each block to hold BUFFER_BLOCK_SIZE
1571of data.
1572
1573This function is called by InnoDB during srv_start().
1574It is also called by MEB while applying the redo logs on TDE tablespaces,
1575the "Blocks" allocated in this block_cache are used to hold the decrypted
1576page data. */
1578
1579/** Initializes the asynchronous io system.
1580Creates an array for ibuf i/o (if not in read-only mode).
1581Also creates one array each for read and write where each
1582array is divided logically into n_readers and n_writers
1583respectively. The caller must create an i/o handler thread for each
1584segment in these arrays by calling os_aio_start_threads().
1585
1586@param[in] n_readers number of reader threads
1587@param[in] n_writers number of writer threads */
1588bool os_aio_init(ulint n_readers, ulint n_writers);
1589
1590/** Starts one thread for each segment created in os_aio_init */
1592
1593/**
1594Frees the asynchronous io system. */
1595void os_aio_free();
1596
1597/**
1598NOTE! Use the corresponding macro os_aio(), not directly this function!
1599Requests an asynchronous i/o operation.
1600@param[in] type IO request context
1601@param[in] aio_mode IO mode
1602@param[in] name Name of the file or path as NUL terminated
1603string
1604@param[in] file Open file handle
1605@param[out] buf buffer where to read
1606@param[in] offset file offset where to read
1607@param[in] n how many bytes to read or write; this
1608must not cross a file boundary; in AIO this must be a block size multiple
1609@param[in] read_only if true read only mode checks are enforced
1610@param[in,out] m1 Message for the AIO handler, (can be used to
1611identify a completed AIO operation); ignored if mode is OS_AIO_SYNC
1612@param[in,out] m2 message for the AIO handler (can be used to
1613identify a completed AIO operation); ignored if mode is OS_AIO_SYNC
1614@return DB_SUCCESS or error code */
1615dberr_t os_aio_func(IORequest &type, AIO_mode aio_mode, const char *name,
1616 pfs_os_file_t file, void *buf, os_offset_t offset, ulint n,
1617 bool read_only, fil_node_t *m1, void *m2);
1618
1619/** Wakes up all async i/o threads so that they know to exit themselves in
1620shutdown. */
1622
1623/** Waits until there are no pending writes in os_aio_write_array. There can
1624be other, synchronous, pending writes. */
1626
1627/** Wakes up simulated aio i/o-handler threads if they have something to do. */
1629
1630/** This function can be called if one wants to post a batch of reads and
1631prefers an i/o-handler thread to handle them all at once later. You must
1632call os_aio_simulated_wake_handler_threads later to ensure the threads
1633are not left sleeping! */
1635
1636/** Waits for an AIO operation to complete. This function is used to wait the
1637for completed requests. The AIO array of pending requests is divided
1638into segments. The thread specifies which segment or slot it wants to wait
1639for. NOTE: this function will also take care of freeing the AIO slot,
1640therefore no other thread is allowed to do the freeing!
1641@param[in] segment The number of the segment in the AIO arrays to
1642 wait for; segment 0 is the ibuf I/O thread,
1643 then follow the non-ibuf read threads,
1644 and as the last are the non-ibuf write threads
1645@param[out] m1 the messages passed with the AIO request; note
1646 that also in the case where the AIO operation
1647 failed, these output parameters are valid and
1648 can be used to restart the operation,
1649 for example
1650@param[out] m2 callback message
1651@param[out] request OS_FILE_WRITE or ..._READ
1652@return DB_SUCCESS or error code */
1653dberr_t os_aio_handler(ulint segment, fil_node_t **m1, void **m2,
1654 IORequest *request);
1655
1656/** Prints info of the aio arrays.
1657@param[in,out] file file where to print */
1658void os_aio_print(FILE *file);
1659
1660/** Refreshes the statistics used to print per-second averages. */
1662
1663/** Checks that all slots in the system have been freed, that is, there are
1664no pending io operations. */
1666
1667#ifdef UNIV_DEBUG
1668
1669/** Prints all pending IO
1670@param[in] file File where to print */
1672
1673#endif /* UNIV_DEBUG */
1674
1675/** Get available free space on disk
1676@param[in] path pathname of a directory or file in disk
1677@param[out] free_space free space available in bytes
1678@return DB_SUCCESS if all OK */
1679dberr_t os_get_free_space(const char *path, uint64_t &free_space);
1680
1681/** This function returns information about the specified file
1682@param[in] path pathname of the file
1683@param[out] stat_info information of a file in a directory
1684@param[in] check_rw_perm for testing whether the file can be opened
1685 in RW mode
1686@param[in] read_only true if file is opened in read-only mode
1687@return DB_SUCCESS if all OK */
1688dberr_t os_file_get_status(const char *path, os_file_stat_t *stat_info,
1689 bool check_rw_perm, bool read_only);
1690
1691/** Check if a file can be opened in read-write mode.
1692 @param[in] name filename to check
1693 @param[in] read_only true if check for read-only mode only
1694 @retval true if file can be opened in the specified mode (rw or ro);
1695 or file does not exist
1696 @retval false if file exists and can't be opened in the specified mode */
1697bool os_file_check_mode(const char *name, bool read_only);
1698
1699#ifndef UNIV_HOTBACKUP
1700
1701/** return any of the tmpdir path */
1702char *innobase_mysql_tmpdir();
1703
1704/** Creates a temporary file in the location specified by the parameter
1705path. If the path is NULL, then it will be created in --tmpdir.
1706@param[in] path location for creating temporary file
1707@return temporary file descriptor, or OS_FD_CLOSED on error */
1709
1710#endif /* !UNIV_HOTBACKUP */
1711
1712/** If it is a compressed page return the compressed page data + footer size
1713@param[in] buf Buffer to check, must include header + 10 bytes
1714@return ULINT_UNDEFINED if the page is not a compressed page or length
1715 of the compressed data (including footer) if it is a compressed page */
1717
1718/** If it is a compressed page return the original page data + footer size
1719@param[in] buf Buffer to check, must include header + 10 bytes
1720@return ULINT_UNDEFINED if the page is not a compressed page or length
1721 of the original data + footer if it is a compressed page */
1723
1724#ifndef _WIN32
1725/** Set the global file create umask. This value is to be set once, at startup
1726and never modified.
1727@param[in] umask The umask to use for all InnoDB file creation.
1728*/
1729void os_file_set_umask(mode_t umask);
1730
1731/** A magic constant for the umask parameter that indicates caller wants the
1732`os_innodb_umask` value to be used. The `os_innodb_umask` is a static value,
1733private to this module, and to the file creation methods, so it should not be
1734used directly. */
1735constexpr mode_t os_innodb_umask_default = std::numeric_limits<mode_t>::max();
1736
1737#endif
1738
1739/** Free storage space associated with a section of the file.
1740@param[in] fh Open file handle
1741@param[in] off Starting offset (SEEK_SET)
1742@param[in] len Size of the hole
1743@return DB_SUCCESS or error code */
1744[[nodiscard]] dberr_t os_file_punch_hole(os_file_t fh, os_offset_t off,
1745 os_offset_t len);
1746
1747/** Check if the file system supports sparse files.
1748
1749Warning: On POSIX systems we try and punch a hole from offset 0 to
1750the system configured page size. This should only be called on an empty
1751file.
1752
1753Note: On Windows we use the name and on Unices we use the file handle.
1754
1755@param[in] fh File handle for the file - if opened
1756@return true if the file system supports sparse files */
1757[[nodiscard]] bool os_is_sparse_file_supported(pfs_os_file_t fh);
1758
1759/** Decompress the page data contents. Page type must be FIL_PAGE_COMPRESSED, if
1760not then the source contents are left unchanged and DB_SUCCESS is returned.
1761@param[in] dblwr_read true of double write recovery in progress
1762@param[in,out] src Data read from disk, decompressed data will be
1763 copied to this page
1764@param[in,out] dst Scratch area to use for decompression or
1765 nullptr.
1766@param[in] dst_len If dst is valid, then size of the scratch area
1767 in bytes
1768@return DB_SUCCESS or error code */
1769[[nodiscard]] dberr_t os_file_decompress_page(bool dblwr_read, byte *src,
1770 byte *dst, ulint dst_len);
1771
1772/** Compress a data page
1773@param[in] compression Compression algorithm
1774@param[in] block_size File system block size
1775@param[in] src Source contents to compress
1776@param[in] src_len Length in bytes of the source
1777@param[out] dst Compressed page contents
1778@param[out] dst_len Length in bytes of dst contents
1779@return buffer data, dst_len will have the length of the data */
1780byte *os_file_compress_page(Compression compression, ulint block_size,
1781 byte *src, ulint src_len, byte *dst,
1782 ulint *dst_len);
1783
1784/** Determine if O_DIRECT is supported.
1785@retval true if O_DIRECT is supported.
1786@retval false if O_DIRECT is not supported. */
1787[[nodiscard]] bool os_is_o_direct_supported();
1788
1789/** Fill the pages with NULs
1790@param[in] file File handle
1791@param[in] name File name
1792@param[in] page_size physical page size
1793@param[in] start Offset from the start of the file in bytes
1794@param[in] len Length in bytes
1795@return DB_SUCCESS or error code */
1796[[nodiscard]] dberr_t os_file_write_zeros(pfs_os_file_t file, const char *name,
1797 ulint page_size, os_offset_t start,
1798 ulint len);
1799
1800#ifndef UNIV_NONINL
1801/** Class to scan the directory hierarchy using a depth first scan. */
1803 public:
1804 using Path = std::string;
1805
1806 /** Check if the path is a directory. The file/directory must exist.
1807 @param[in] path The path to check
1808 @return true if it is a directory */
1809 static bool is_directory(const Path &path);
1810
1811 /** Depth first traversal of the directory starting from basedir
1812 @param[in] basedir Start scanning from this directory
1813 @param[in] recursive `true` if scan should be recursive
1814 @param[in] f Function to call for each entry */
1815 template <typename F>
1816 static void walk(const Path &basedir, bool recursive, F &&f) {
1817#ifdef _WIN32
1818 walk_win32(basedir, recursive, [&](const Path &path, size_t) { f(path); });
1819#else
1820 walk_posix(basedir, recursive, [&](const Path &path, size_t) { f(path); });
1821#endif /* _WIN32 */
1822 }
1823
1824 private:
1825 /** Directory names for the depth first directory scan. */
1826 struct Entry {
1827 /** Constructor
1828 @param[in] path Directory to traverse
1829 @param[in] depth Relative depth to the base
1830 directory in walk() */
1831 Entry(const Path &path, size_t depth) : m_path(path), m_depth(depth) {}
1832
1833 /** Path to the directory */
1835
1836 /** Relative depth of m_path */
1837 size_t m_depth;
1838 };
1839
1840 using Function = std::function<void(const Path &, size_t)>;
1841
1842 /** Depth first traversal of the directory starting from basedir
1843 @param[in] basedir Start scanning from this directory
1844 @param[in] recursive `true` if scan should be recursive
1845 @param[in] f Function to call for each entry */
1846#ifdef _WIN32
1847 static void walk_win32(const Path &basedir, bool recursive, Function &&f);
1848#else
1849 static void walk_posix(const Path &basedir, bool recursive, Function &&f);
1850#endif /* _WIN32 */
1851};
1852
1853/** Allocate a page for sync IO
1854@return pointer to page */
1855[[nodiscard]] file::Block *os_alloc_block() noexcept;
1856
1857/** Get the sector aligned frame pointer.
1858@param[in] block the memory block containing the page frame.
1859@return the sector aligned frame pointer. */
1860[[nodiscard]] byte *os_block_get_frame(const file::Block *block) noexcept;
1861
1862/** Free a page after sync IO
1863@param[in,out] block The block to free/release */
1864void os_free_block(file::Block *block) noexcept;
1865
1866inline void file::Block::free(file::Block *obj) noexcept { os_free_block(obj); }
1867
1868/** Encrypt a page content when write it to disk.
1869@param[in] type IO flags
1870@param[out] buf buffer to read or write
1871@param[in] n number of bytes to read/write, starting from
1872 offset
1873@return pointer to the encrypted page */
1875
1876/** Allocate the buffer for IO on a transparently compressed table.
1877@param[in] type IO flags
1878@param[out] buf buffer to read or write
1879@param[in,out] n number of bytes to read/write, starting from
1880 offset
1881@return pointer to allocated page, compressed data is written to the offset
1882 that is aligned on the disk sector size */
1884
1885/** This is a wrapper function for the os_file_write() function call. The
1886purpose of this wrapper function is to retry on i/o error. On I/O error
1887(perhaps because of disk full situation) keep retrying the write operation
1888till it succeeds.
1889@param[in] type IO flags
1890@param[in] name name of the file or path as a null-terminated string
1891@param[in] file handle to an open file
1892@param[out] buf buffer from which to write
1893@param[in] offset file offset from the start where to read
1894@param[in] n number of bytes to read, starting from offset
1895@return DB_SUCCESS if request was successful, false if fail */
1897 pfs_os_file_t file, const void *buf,
1898 os_offset_t offset, ulint n);
1899
1900#include "os0file.ic"
1901#endif /* UNIV_NONINL */
1902
1903#endif /* os0file_h */
@ NORMAL
Get always.
Class to scan the directory hierarchy using a depth first scan.
Definition: os0file.h:1802
std::string Path
Definition: os0file.h:1804
static bool is_directory(const Path &path)
Check if the path is a directory.
Definition: os0file.cc:7736
static void walk_posix(const Path &basedir, bool recursive, Function &&f)
Depth first traversal of the directory starting from basedir.
Definition: os0file.cc:3579
std::function< void(const Path &, size_t)> Function
Definition: os0file.h:1840
static void walk(const Path &basedir, bool recursive, F &&f)
Depth first traversal of the directory starting from basedir.
Definition: os0file.h:1816
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:262
uint32_t m_original_size
Length of the original IO size.
Definition: os0file.h:606
bool is_punch_hole_optimisation_disabled() const
Definition: os0file.h:386
void compression_algorithm(Compression::Type type)
Set compression algorithm.
Definition: os0file.h:450
bool is_dblwr() const
Definition: os0file.h:502
Compression compression_algorithm() const
Get the compression algorithm.
Definition: os0file.h:462
bool is_partial_io_warning_disabled() const
Definition: os0file.h:368
void dblwr()
Note that the IO is for double write buffer page write.
Definition: os0file.h:499
void block_size(ulint block_size)
Set the block size for IO.
Definition: os0file.h:425
void clear_encrypted()
Clear all encryption related flags.
Definition: os0file.h:491
void clear_do_not_wake()
Clear the do not wake flag.
Definition: os0file.h:415
bool is_compression_enabled() const
Definition: os0file.h:472
bool is_encrypted() const
Definition: os0file.h:486
ulint block_size() const
Definition: os0file.h:421
void clear_punch_hole()
Clear the punch hole flag.
Definition: os0file.h:418
void disable_partial_io_warnings()
Disable partial read warnings.
Definition: os0file.h:374
const file::Block * get_encrypted_block() const noexcept
Get the encrypted block.
Definition: os0file.h:579
std::string to_string() const
Definition: os0file.h:519
uint32_t get_original_size() const
Returns original size of the IO to make.
Definition: os0file.h:431
bool operator==(const IORequest &rhs) const
Compare two requests.
Definition: os0file.h:446
void disable_compression()
Disable transformations.
Definition: os0file.h:477
bool punch_hole() const
Definition: os0file.h:380
IORequest()
Default constructor.
Definition: os0file.h:316
static bool is_punch_hole_supported()
Definition: os0file.h:505
static bool ignore_missing(int type)
Definition: os0file.h:346
void set_original_size(uint32_t original_size)
Definition: os0file.h:433
uint32_t m_block_size
Definition: os0file.h:585
bool ignore_missing() const
Definition: os0file.h:377
Compression m_compression
Compression algorithm.
Definition: os0file.h:591
void set_punch_hole()
Set the punch hole flag.
Definition: os0file.h:401
IORequest(int type)
Definition: os0file.h:329
Encryption & get_encryption_info() noexcept
Get a reference to the underlying encryption information.
Definition: os0file.h:567
uint32_t m_elen
The length of data in encrypted block.
Definition: os0file.h:600
bool is_write() const
Definition: os0file.h:354
bool validate() const
Definition: os0file.h:394
Encryption encryption_algorithm() const
Get the encryption algorithm.
Definition: os0file.h:481
bool is_row_log() const
Definition: os0file.h:360
void set_encrypted_block(const file::Block *eblock) noexcept
Set the encrypted block to the given value.
Definition: os0file.h:573
bool is_compressed() const
Definition: os0file.h:467
bool is_wake() const
Definition: os0file.h:365
void clear_compressed()
Clear all compression related flags.
Definition: os0file.h:438
void disable_punch_hole_optimisation()
Set the force punch hole flag.
Definition: os0file.h:408
const file::Block * m_eblock
The encrypted block.
Definition: os0file.h:597
int m_type
Request type bit flags.
Definition: os0file.h:588
@ UNSET
Definition: os0file.h:266
@ DBLWR
Request for a doublewrite page IO.
Definition: os0file.h:271
@ DISABLE_PARTIAL_IO_WARNINGS
Disable partial read warnings.
Definition: os0file.h:282
@ IGNORE_MISSING
Ignore failed reads of non-existent pages.
Definition: os0file.h:294
@ DO_NOT_WAKE
Do not to wake i/o-handler threads, but the caller will do the waking explicitly later,...
Definition: os0file.h:291
@ ROW_LOG
Row log used in online DDL.
Definition: os0file.h:307
@ LOG
Log file request.
Definition: os0file.h:279
@ 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:312
@ NO_COMPRESSION
Force raw read, do not try to compress/decompress.
Definition: os0file.h:304
@ WRITE
Definition: os0file.h:268
@ READ
Definition: os0file.h:267
@ DATA_FILE
Enumerations below can be ORed to READ/WRITE above.
Definition: os0file.h:276
@ PUNCH_HOLE
Use punch hole if available, only makes sense if compression algorithm != NONE.
Definition: os0file.h:298
bool is_read() const
Definition: os0file.h:351
bool is_log() const
Definition: os0file.h:357
Encryption m_encryption
Encryption algorithm.
Definition: os0file.h:594
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:1052
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:6720
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:5698
constexpr uint32_t OS_FILE_MAX_PATH
Definition: os0file.h:682
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:622
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:3062
ulint os_n_file_reads
Definition: os0file.cc:804
bool os_is_o_direct_supported()
Determine if O_DIRECT is supported.
Definition: os0file.cc:133
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:1008
dberr_t os_file_create_subdirs_if_needed(const char *path)
Create all missing subdirectories along the given path.
Definition: os0file.cc:1844
bool os_file_create_directory(const char *pathname, bool fail_if_exists)
This function attempts to create a directory named pathname.
Definition: os0file.cc:3039
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:6340
static const ulint OS_FILE_AIO_INTERRUPTED
Definition: os0file.h:245
os_file_type_t
Definition: os0file.h:648
@ OS_FILE_TYPE_BLOCK
Block device.
Definition: os0file.h:674
@ OS_FILE_PERMISSION_ERROR
stat() failed with EACCESS
Definition: os0file.h:656
@ OS_FILE_TYPE_MISSING
File doesn't exist.
Definition: os0file.h:659
@ OS_FILE_TYPE_NAME_TOO_LONG
stat() failed, with ENAMETOOLONG
Definition: os0file.h:653
@ OS_FILE_TYPE_UNKNOWN
File exists but type is unknown.
Definition: os0file.h:662
@ OS_FILE_TYPE_DIR
Directory.
Definition: os0file.h:668
@ OS_FILE_TYPE_FAILED
Get status failed.
Definition: os0file.h:650
@ OS_FILE_TYPE_LINK
Symbolic link.
Definition: os0file.h:671
@ OS_FILE_TYPE_FILE
Ordinary file.
Definition: os0file.h:665
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:5495
AIO_mode
Modes for aio operations.
Definition: os0file.h:625
@ 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:807
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:1333
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:3399
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:1634
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:6362
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:5344
static const ulint OS_FILE_ERROR_NOT_SPECIFIED
Definition: os0file.h:243
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:3096
std::function< void(const char *path, const char *name)> os_dir_cbk_t
Callback function type to be implemented by caller.
Definition: os0file.h:726
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:815
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:5732
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:5660
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:5719
int os_fd_t
Raw file handle.
Definition: os0file.h:112
void os_create_block_cache()
Creates and initializes block_cache.
Definition: os0file.cc:6300
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:5458
mysql_pfs_key_t innodb_arch_file_key
static const ulint OS_FILE_PATH_ERROR
Definition: os0file.h:237
void os_aio_wait_until_no_pending_writes()
Waits until there are no pending writes in os_aio_write_array.
Definition: os0file.cc:6416
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:5312
static const ulint OS_FILE_NOT_FOUND
Error codes from os_file_get_last_error.
Definition: os0file.h:234
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:7725
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:6895
static const ulint OS_FILE_SHARING_VIOLATION
Definition: os0file.h:242
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:813
static const ulint OS_FILE_READ_ALLOW_DELETE
Used by MySQLBackup.
Definition: os0file.h:216
unsigned long long os_fsync_threshold
Definition: os0file.cc:107
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:6386
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:1735
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:248
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:3245
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:7753
static const ulint OS_FILE_ERROR_MAX
Definition: os0file.h:251
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:3554
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:5706
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:3002
void os_file_set_nocache(int fd, const char *file_name, const char *operation_name)
Tries to disable OS caching on an opened file descriptor.
Definition: os0file.cc:5266
static const ulint OS_FILE_ALREADY_EXISTS
Definition: os0file.h:236
static const ulint OS_FILE_DISK_FULL
Definition: os0file.h:235
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:3368
void os_aio_print(FILE *file)
Prints info of the aio arrays.
Definition: os0file.cc:7585
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:818
byte * os_block_get_frame(const file::Block *block) noexcept
Get the sector aligned frame pointer.
Definition: os0file.cc:961
ulint os_n_file_writes
Definition: os0file.cc:806
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:5869
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:5513
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:5766
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:7677
bool os_file_delete_func(const char *name)
Deletes a file.
Definition: os0file.cc:3347
static const ulint OS_FILE_READ_WRITE
Definition: os0file.h:213
static const ulint OS_FILE_ACCESS_VIOLATION
Definition: os0file.h:247
dberr_t os_get_free_space(const char *path, uint64_t &free_space)
Get available free space on disk.
Definition: os0file.cc:5747
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:1957
void os_aio_refresh_stats()
Refreshes the statistics used to print per-second averages.
Definition: os0file.cc:7658
os_file_size_t os_file_get_size(const char *filename)
Gets a file size.
Definition: os0file.cc:3423
static const ulint OS_FILE_AIO_RESOURCES_RESERVED
wait for OS aio resources to become available again
Definition: os0file.h:240
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:5145
static const ulint OS_FILE_OPERATION_ABORTED
Definition: os0file.h:246
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:3572
file::Block * os_alloc_block() noexcept
Allocate a page for sync IO.
Definition: os0file.cc:965
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:5436
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:2482
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:5794
static const ulint OS_FILE_INSUFFICIENT_RESOURCE
Definition: os0file.h:244
static constexpr os_fd_t OS_FILE_CLOSED
Definition: os0file.h:148
FILE * os_file_create_tmpfile()
Create a temporary file.
Definition: os0file.cc:1607
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:5827
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:7719
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:5649
char * innobase_mysql_tmpdir()
return any of the tmpdir path
Definition: ha_innodb.cc:2480
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:84
static const ulint OS_FILE_TOO_MANY_OPENED
Definition: os0file.h:249
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:5681
void os_aio_start_threads()
Starts one thread for each segment created in os_aio_init.
Definition: os0file.cc:6359
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:1169
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:1153
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:3311
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:1826
Entry(const Path &path, size_t depth)
Constructor.
Definition: os0file.h:1831
Path m_path
Path to the directory.
Definition: os0file.h:1834
size_t m_depth
Relative depth of m_path.
Definition: os0file.h:1837
File node of a tablespace or the log data space.
Definition: fil0fil.h:155
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:1866
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:612
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:618
os_offset_t m_total_size
Total size of file in bytes.
Definition: os0file.h:614
Struct used in fetching information of a file in a directory.
Definition: os0file.h:687
uint32_t block_size
Block size to use for IO in bytes.
Definition: os0file.h:693
time_t ctime
creation time
Definition: os0file.h:695
char name[OS_FILE_MAX_PATH]
path to a file
Definition: os0file.h:688
time_t atime
access time
Definition: os0file.h:697
bool rw_perm
true if can be opened in read-write mode.
Definition: os0file.h:698
os_file_type_t type
file type
Definition: os0file.h:689
os_offset_t size
file size in bytes
Definition: os0file.h:690
os_offset_t alloc_size
Allocated size for sparse files in bytes.
Definition: os0file.h:691
time_t mtime
modification time
Definition: os0file.h:696
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