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