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