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