1 /*********************************************************************** 2 3 Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved. 4 Copyright (c) 2009, Percona Inc. 5 6 Portions of this file contain modifications contributed and copyrighted 7 by Percona Inc.. Those modifications are 8 gratefully acknowledged and are described briefly in the InnoDB 9 documentation. The contributions by Percona Inc. are incorporated with 10 their permission, and subject to the conditions contained in the file 11 COPYING.Percona. 12 13 This program is free software; you can redistribute it and/or modify 14 it under the terms of the GNU General Public License, version 2.0, 15 as published by the Free Software Foundation. 16 17 This program is also distributed with certain software (including 18 but not limited to OpenSSL) that is licensed under separate terms, 19 as designated in a particular file or component or in included license 20 documentation. The authors of MySQL hereby grant you an additional 21 permission to link the program and your derivative works with the 22 separately licensed software that they have included with MySQL. 23 24 This program is distributed in the hope that it will be useful, 25 but WITHOUT ANY WARRANTY; without even the implied warranty of 26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 GNU General Public License, version 2.0, for more details. 28 29 You should have received a copy of the GNU General Public License along with 30 this program; if not, write to the Free Software Foundation, Inc., 31 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 32 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 "univ.i" 46 47 #ifndef __WIN__ 48 #include <dirent.h> 49 #include <sys/stat.h> 50 #include <time.h> 51 #endif 52 53 /** File node of a tablespace or the log data space */ 54 struct fil_node_t; 55 56 extern ibool os_has_said_disk_full; 57 /** Flag: enable debug printout for asynchronous i/o */ 58 extern ibool os_aio_print_debug; 59 60 /** Number of pending os_file_pread() operations */ 61 extern ulint os_file_n_pending_preads; 62 /** Number of pending os_file_pwrite() operations */ 63 extern ulint os_file_n_pending_pwrites; 64 65 /** Number of pending read operations */ 66 extern ulint os_n_pending_reads; 67 /** Number of pending write operations */ 68 extern ulint os_n_pending_writes; 69 70 #ifdef __WIN__ 71 72 /** We define always WIN_ASYNC_IO, and check at run-time whether 73 the OS actually supports it: Win 95 does not, NT does. */ 74 #define WIN_ASYNC_IO 75 76 /** Use unbuffered I/O */ 77 #define UNIV_NON_BUFFERED_IO 78 79 #endif 80 81 /** File offset in bytes */ 82 typedef ib_uint64_t os_offset_t; 83 #ifdef __WIN__ 84 /** File handle */ 85 # define os_file_t HANDLE 86 /** Convert a C file descriptor to a native file handle 87 @param fd file descriptor 88 @return native file handle */ 89 # define OS_FILE_FROM_FD(fd) (HANDLE) _get_osfhandle(fd) 90 #else 91 /** File handle */ 92 typedef int os_file_t; 93 /** Convert a C file descriptor to a native file handle 94 @param fd file descriptor 95 @return native file handle */ 96 # define OS_FILE_FROM_FD(fd) fd 97 #endif 98 99 /*Common file descriptor for file IO instrumentation with PFS 100 on windows and other platforms */ 101 struct pfs_os_file_t 102 { 103 os_file_t m_file; 104 #ifdef UNIV_PFS_IO 105 struct PSI_file *m_psi; 106 #endif 107 }; 108 109 /** Umask for creating files */ 110 extern ulint os_innodb_umask; 111 112 /** The next value should be smaller or equal to the smallest sector size used 113 on any disk. A log block is required to be a portion of disk which is written 114 so that if the start and the end of a block get written to disk, then the 115 whole block gets written. This should be true even in most cases of a crash: 116 if this fails for a log block, then it is equivalent to a media failure in the 117 log. */ 118 119 #define OS_FILE_LOG_BLOCK_SIZE 512 120 121 /** Options for os_file_create_func @{ */ 122 enum os_file_create_t { 123 OS_FILE_OPEN = 51, /*!< to open an existing file (if 124 doesn't exist, error) */ 125 OS_FILE_CREATE, /*!< to create new file (if 126 exists, error) */ 127 OS_FILE_OVERWRITE, /*!< to create a new file, if exists 128 the overwrite old file */ 129 OS_FILE_OPEN_RAW, /*!< to open a raw device or disk 130 partition */ 131 OS_FILE_CREATE_PATH, /*!< to create the directories */ 132 OS_FILE_OPEN_RETRY, /*!< open with retry */ 133 134 /** Flags that can be combined with the above values. Please ensure 135 that the above values stay below 128. */ 136 137 OS_FILE_ON_ERROR_NO_EXIT = 128, /*!< do not exit on unknown errors */ 138 OS_FILE_ON_ERROR_SILENT = 256 /*!< don't print diagnostic messages to 139 the log unless it is a fatal error, 140 this flag is only used if 141 ON_ERROR_NO_EXIT is set */ 142 }; 143 144 #define OS_FILE_READ_ONLY 333 145 #define OS_FILE_READ_WRITE 444 146 #define OS_FILE_READ_ALLOW_DELETE 555 /* for mysqlbackup */ 147 148 /* Options for file_create */ 149 #define OS_FILE_AIO 61 150 #define OS_FILE_NORMAL 62 151 /* @} */ 152 153 /** Types for file create @{ */ 154 #define OS_DATA_FILE 100 155 #define OS_LOG_FILE 101 156 /* @} */ 157 158 /** Error codes from os_file_get_last_error @{ */ 159 #define OS_FILE_NOT_FOUND 71 160 #define OS_FILE_DISK_FULL 72 161 #define OS_FILE_ALREADY_EXISTS 73 162 #define OS_FILE_PATH_ERROR 74 163 #define OS_FILE_AIO_RESOURCES_RESERVED 75 /* wait for OS aio resources 164 to become available again */ 165 #define OS_FILE_SHARING_VIOLATION 76 166 #define OS_FILE_ERROR_NOT_SPECIFIED 77 167 #define OS_FILE_INSUFFICIENT_RESOURCE 78 168 #define OS_FILE_AIO_INTERRUPTED 79 169 #define OS_FILE_OPERATION_ABORTED 80 170 171 #define OS_FILE_ACCESS_VIOLATION 81 172 173 #define OS_FILE_ERROR_MAX 100 174 /* @} */ 175 176 /** Types for aio operations @{ */ 177 #define OS_FILE_READ 10 178 #define OS_FILE_WRITE 11 179 180 #define OS_FILE_LOG 256 /* This can be ORed to type */ 181 /* @} */ 182 183 #define OS_AIO_N_PENDING_IOS_PER_THREAD 32 /*!< Win NT does not allow more 184 than 64 */ 185 186 /** Modes for aio operations @{ */ 187 #define OS_AIO_NORMAL 21 /*!< Normal asynchronous i/o not for ibuf 188 pages or ibuf bitmap pages */ 189 #define OS_AIO_IBUF 22 /*!< Asynchronous i/o for ibuf pages or ibuf 190 bitmap pages */ 191 #define OS_AIO_LOG 23 /*!< Asynchronous i/o for the log */ 192 #define OS_AIO_SYNC 24 /*!< Asynchronous i/o where the calling thread 193 will itself wait for the i/o to complete, 194 doing also the job of the i/o-handler thread; 195 can be used for any pages, ibuf or non-ibuf. 196 This is used to save CPU time, as we can do 197 with fewer thread switches. Plain synchronous 198 i/o is not as good, because it must serialize 199 the file seek and read or write, causing a 200 bottleneck for parallelism. */ 201 202 #define OS_AIO_SIMULATED_WAKE_LATER 512 /*!< This can be ORed to mode 203 in the call of os_aio(...), 204 if the caller wants to post several i/o 205 requests in a batch, and only after that 206 wake the i/o-handler thread; this has 207 effect only in simulated aio */ 208 /* @} */ 209 210 #define OS_WIN31 1 /*!< Microsoft Windows 3.x */ 211 #define OS_WIN95 2 /*!< Microsoft Windows 95 */ 212 #define OS_WINNT 3 /*!< Microsoft Windows NT 3.x */ 213 #define OS_WIN2000 4 /*!< Microsoft Windows 2000 */ 214 #define OS_WINXP 5 /*!< Microsoft Windows XP 215 or Windows Server 2003 */ 216 #define OS_WINVISTA 6 /*!< Microsoft Windows Vista 217 or Windows Server 2008 */ 218 #define OS_WIN7 7 /*!< Microsoft Windows 7 219 or Windows Server 2008 R2 */ 220 221 222 extern ulint os_n_file_reads; 223 extern ulint os_n_file_writes; 224 extern ulint os_n_fsyncs; 225 226 #ifdef UNIV_PFS_IO 227 /* Keys to register InnoDB I/O with performance schema */ 228 extern mysql_pfs_key_t innodb_file_data_key; 229 extern mysql_pfs_key_t innodb_file_log_key; 230 extern mysql_pfs_key_t innodb_file_temp_key; 231 232 /* Following four macros are instumentations to register 233 various file I/O operations with performance schema. 234 1) register_pfs_file_open_begin() and register_pfs_file_open_end() are 235 used to register file creation, opening, closing and renaming. 236 2) register_pfs_file_rename_begin() and register_pfs_file_rename_end() 237 are used to register file renaming 238 2) register_pfs_file_io_begin() and register_pfs_file_io_end() are 239 used to register actual file read, write and flush 240 3) register_pfs_file_close_begin() and register_pfs_file_close_end() 241 are used to register file deletion operations*/ 242 # define register_pfs_file_open_begin(state, locker, key, op, name, \ 243 src_file, src_line) \ 244 do { \ 245 locker = PSI_FILE_CALL(get_thread_file_name_locker)( \ 246 state, key, op, name, &locker); \ 247 if (locker != NULL) { \ 248 PSI_FILE_CALL(start_file_open_wait)( \ 249 locker, src_file, src_line); \ 250 } \ 251 } while (0) 252 253 # define register_pfs_file_open_end(locker, file, result) \ 254 do { \ 255 if (locker != NULL) { \ 256 file.m_psi = PSI_FILE_CALL( \ 257 end_file_open_wait)( \ 258 locker, result); \ 259 } \ 260 } while (0) 261 262 # define register_pfs_file_rename_begin(state, locker, key, op, name, \ 263 src_file, src_line) \ 264 register_pfs_file_open_begin(state, locker, key, op, name, \ 265 src_file, src_line) \ 266 267 # define register_pfs_file_rename_end(locker, result) \ 268 do { \ 269 if (locker != NULL) { \ 270 PSI_FILE_CALL(end_file_open_wait)(locker, result); \ 271 } \ 272 } while (0) 273 274 # define register_pfs_file_close_begin(state, locker, key, op, name, \ 275 src_file, src_line) \ 276 do { \ 277 locker = PSI_FILE_CALL(get_thread_file_name_locker)( \ 278 state, key, op, name, &locker); \ 279 if (UNIV_LIKELY(locker != NULL)) { \ 280 PSI_FILE_CALL(start_file_close_wait)( \ 281 locker, src_file, src_line); \ 282 } \ 283 } while (0) 284 285 # define register_pfs_file_close_end(locker, result) \ 286 do { \ 287 if (UNIV_LIKELY(locker != NULL)) { \ 288 PSI_FILE_CALL(end_file_close_wait)( \ 289 locker, result); \ 290 } \ 291 } while (0) 292 293 # define register_pfs_file_io_begin(state, locker, file, count, op, \ 294 src_file, src_line) \ 295 do { \ 296 locker = PSI_FILE_CALL(get_thread_file_stream_locker)( \ 297 state, file.m_psi, op); \ 298 if (locker != NULL) { \ 299 PSI_FILE_CALL(start_file_wait)( \ 300 locker, count, src_file, src_line); \ 301 } \ 302 } while (0) 303 304 # define register_pfs_file_io_end(locker, count) \ 305 do { \ 306 if (locker != NULL) { \ 307 PSI_FILE_CALL(end_file_wait)(locker, count); \ 308 } \ 309 } while (0) 310 #endif /* UNIV_PFS_IO */ 311 312 /* Following macros/functions are file I/O APIs that would be performance 313 schema instrumented if "UNIV_PFS_IO" is defined. They would point to 314 wrapper functions with performance schema instrumentation in such case. 315 316 os_file_create 317 os_file_create_simple 318 os_file_create_simple_no_error_handling 319 os_file_close 320 os_file_rename 321 os_aio 322 os_file_read 323 os_file_read_no_error_handling 324 os_file_read_no_error_handling_int_fd 325 os_file_write 326 os_file_write_int_fd 327 328 The wrapper functions have the prefix of "innodb_". */ 329 330 #ifdef UNIV_PFS_IO 331 # define os_file_create(key, name, create, purpose, type, success) \ 332 pfs_os_file_create_func(key, name, create, purpose, type, \ 333 success, __FILE__, __LINE__) 334 335 # define os_file_create_simple(key, name, create, access, success) \ 336 pfs_os_file_create_simple_func(key, name, create, access, \ 337 success, __FILE__, __LINE__) 338 339 # define os_file_create_simple_no_error_handling( \ 340 key, name, create_mode, access, success) \ 341 pfs_os_file_create_simple_no_error_handling_func( \ 342 key, name, create_mode, access, success, __FILE__, __LINE__) 343 344 # define os_file_close_pfs(file) \ 345 pfs_os_file_close_func(file, __FILE__, __LINE__) 346 347 # define os_aio(type, mode, name, file, buf, offset, \ 348 n, message1, message2) \ 349 pfs_os_aio_func(type, mode, name, file, buf, offset, \ 350 n, message1, message2, __FILE__, __LINE__) 351 352 # define os_file_read_pfs(file, buf, offset, n) \ 353 pfs_os_file_read_func(file, buf, offset, n, __FILE__, __LINE__) 354 355 # define os_file_read_no_error_handling(file, buf, offset, n) \ 356 pfs_os_file_read_no_error_handling_func(file, buf, offset, n, \ 357 __FILE__, __LINE__) 358 359 # define os_file_read_no_error_handling_int_fd( \ 360 file, buf, offset, n) \ 361 pfs_os_file_read_no_error_handling_int_fd_func( \ 362 file, buf, offset, n, __FILE__, __LINE__) 363 364 # define os_file_write_pfs(name, file, buf, offset, n) \ 365 pfs_os_file_write_func(name, file, buf, offset, \ 366 n, __FILE__, __LINE__) 367 368 # define os_file_write_int_fd(name, file, buf, offset, n) \ 369 pfs_os_file_write_int_fd_func(name, file, buf, offset, \ 370 n, __FILE__, __LINE__) 371 372 # define os_file_flush_pfs(file) \ 373 pfs_os_file_flush_func(file, __FILE__, __LINE__) 374 375 # define os_file_rename(key, oldpath, newpath) \ 376 pfs_os_file_rename_func(key, oldpath, newpath, __FILE__, __LINE__) 377 378 # define os_file_delete(key, name) \ 379 pfs_os_file_delete_func(key, name, __FILE__, __LINE__) 380 381 # define os_file_delete_if_exists(key, name) \ 382 pfs_os_file_delete_if_exists_func(key, name, __FILE__, __LINE__) 383 #else /* UNIV_PFS_IO */ 384 385 /* If UNIV_PFS_IO is not defined, these I/O APIs point 386 to original un-instrumented file I/O APIs */ 387 # define os_file_create(key, name, create, purpose, type, success) \ 388 os_file_create_func(name, create, purpose, type, success) 389 390 # define os_file_create_simple(key, name, create_mode, access, success) \ 391 os_file_create_simple_func(name, create_mode, access, success) 392 393 # define os_file_create_simple_no_error_handling( \ 394 key, name, create_mode, access, success) \ 395 os_file_create_simple_no_error_handling_func( \ 396 name, create_mode, access, success) 397 398 # define os_file_close_pfs(file) \ 399 os_file_close_func(file) 400 401 # define os_aio(type, mode, name, file, buf, offset, n, message1, message2) \ 402 os_aio_func(type, mode, name, file, buf, offset, n, \ 403 message1, message2) 404 405 # define os_file_read_pfs(file, buf, offset, n) \ 406 os_file_read_func(file, buf, offset, n) 407 408 # define os_file_read_no_error_handling(file, buf, offset, n) \ 409 os_file_read_no_error_handling_func(file, buf, offset, n) 410 # define os_file_read_no_error_handling_int_fd( \ 411 file, buf, offset, n) \ 412 os_file_read_no_error_handling_func(file, buf, offset, n) 413 414 # define os_file_write_int_fd(name, file, buf, offset, n) \ 415 os_file_write_func(name, file, buf, offset, n) 416 # define os_file_write_pfs(name, file, buf, offset, n) \ 417 os_file_write_func(name, file, buf, offset, n) 418 419 420 # define os_file_flush_pfs(file) os_file_flush_func(file) 421 422 # define os_file_rename(key, oldpath, newpath) \ 423 os_file_rename_func(oldpath, newpath) 424 425 # define os_file_delete(key, name) os_file_delete_func(name) 426 427 # define os_file_delete_if_exists(key, name) \ 428 os_file_delete_if_exists_func(name) 429 430 #endif /* UNIV_PFS_IO */ 431 432 #ifdef UNIV_PFS_IO 433 #define os_file_close(file) os_file_close_pfs(file) 434 #else 435 #define os_file_close(file) os_file_close_pfs((file).m_file) 436 #endif 437 438 #ifdef UNIV_PFS_IO 439 #define os_file_read(file, buf, offset, n) \ 440 os_file_read_pfs(file, buf, offset, n) 441 #else 442 #define os_file_read(file, buf, offset, n) \ 443 os_file_read_pfs(file.m_file, buf, offset, n) 444 #endif 445 446 #ifdef UNIV_PFS_IO 447 #define os_file_flush(file) os_file_flush_pfs(file) 448 #else 449 #define os_file_flush(file) os_file_flush_pfs(file.m_file) 450 #endif 451 452 #ifdef UNIV_PFS_IO 453 #define os_file_write(name, file, buf, offset, n) \ 454 os_file_write_pfs(name, file, buf, offset, n) 455 #else 456 #define os_file_write(name, file, buf, offset, n) \ 457 os_file_write_pfs(name, file.m_file, buf, offset, n) 458 #endif 459 /* File types for directory entry data type */ 460 461 enum os_file_type_t { 462 OS_FILE_TYPE_UNKNOWN = 0, 463 OS_FILE_TYPE_FILE, /* regular file 464 (or a character/block device) */ 465 OS_FILE_TYPE_DIR, /* directory */ 466 OS_FILE_TYPE_LINK /* symbolic link */ 467 }; 468 469 /* Maximum path string length in bytes when referring to tables with in the 470 './databasename/tablename.ibd' path format; we can allocate at least 2 buffers 471 of this size from the thread stack; that is why this should not be made much 472 bigger than 4000 bytes */ 473 #define OS_FILE_MAX_PATH 4000 474 475 /** Struct used in fetching information of a file in a directory */ 476 struct os_file_stat_t { 477 char name[OS_FILE_MAX_PATH]; /*!< path to a file */ 478 os_file_type_t type; /*!< file type */ 479 ib_int64_t size; /*!< file size */ 480 time_t ctime; /*!< creation time */ 481 time_t mtime; /*!< modification time */ 482 time_t atime; /*!< access time */ 483 bool rw_perm; /*!< true if can be opened 484 in read-write mode. Only valid 485 if type == OS_FILE_TYPE_FILE */ 486 }; 487 488 #ifdef __WIN__ 489 typedef HANDLE os_file_dir_t; /*!< directory stream */ 490 #else 491 typedef DIR* os_file_dir_t; /*!< directory stream */ 492 #endif 493 494 #ifdef __WIN__ 495 /***********************************************************************//** 496 Gets the operating system version. Currently works only on Windows. 497 @return OS_WIN95, OS_WIN31, OS_WINNT, OS_WIN2000, OS_WINXP, OS_WINVISTA, 498 OS_WIN7. */ 499 UNIV_INTERN 500 ulint 501 os_get_os_version(void); 502 /*===================*/ 503 #endif /* __WIN__ */ 504 #ifndef UNIV_HOTBACKUP 505 /****************************************************************//** 506 Creates the seek mutexes used in positioned reads and writes. */ 507 UNIV_INTERN 508 void 509 os_io_init_simple(void); 510 /*===================*/ 511 512 513 /** Create a temporary file. This function is like tmpfile(3), but 514 the temporary file is created in the given parameter path. If the path 515 is null then it will create the file in the mysql server configuration 516 parameter (--tmpdir). 517 @param[in] path location for creating temporary file 518 @return temporary file handle, or NULL on error */ 519 UNIV_INTERN 520 FILE* 521 os_file_create_tmpfile( 522 const char* path); 523 524 #endif /* !UNIV_HOTBACKUP */ 525 /***********************************************************************//** 526 The os_file_opendir() function opens a directory stream corresponding to the 527 directory named by the dirname argument. The directory stream is positioned 528 at the first entry. In both Unix and Windows we automatically skip the '.' 529 and '..' items at the start of the directory listing. 530 @return directory stream, NULL if error */ 531 UNIV_INTERN 532 os_file_dir_t 533 os_file_opendir( 534 /*============*/ 535 const char* dirname, /*!< in: directory name; it must not 536 contain a trailing '\' or '/' */ 537 ibool error_is_fatal);/*!< in: TRUE if we should treat an 538 error as a fatal error; if we try to 539 open symlinks then we do not wish a 540 fatal error if it happens not to be 541 a directory */ 542 /***********************************************************************//** 543 Closes a directory stream. 544 @return 0 if success, -1 if failure */ 545 UNIV_INTERN 546 int 547 os_file_closedir( 548 /*=============*/ 549 os_file_dir_t dir); /*!< in: directory stream */ 550 /***********************************************************************//** 551 This function returns information of the next file in the directory. We jump 552 over the '.' and '..' entries in the directory. 553 @return 0 if ok, -1 if error, 1 if at the end of the directory */ 554 UNIV_INTERN 555 int 556 os_file_readdir_next_file( 557 /*======================*/ 558 const char* dirname,/*!< in: directory name or path */ 559 os_file_dir_t dir, /*!< in: directory stream */ 560 os_file_stat_t* info); /*!< in/out: buffer where the info is returned */ 561 /*****************************************************************//** 562 This function attempts to create a directory named pathname. The new directory 563 gets default permissions. On Unix, the permissions are (0770 & ~umask). If the 564 directory exists already, nothing is done and the call succeeds, unless the 565 fail_if_exists arguments is true. 566 @return TRUE if call succeeds, FALSE on error */ 567 UNIV_INTERN 568 ibool 569 os_file_create_directory( 570 /*=====================*/ 571 const char* pathname, /*!< in: directory name as 572 null-terminated string */ 573 ibool fail_if_exists);/*!< in: if TRUE, pre-existing directory 574 is treated as an error. */ 575 /****************************************************************//** 576 NOTE! Use the corresponding macro os_file_create_simple(), not directly 577 this function! 578 A simple function to open or create a file. 579 @return own: handle to the file, not defined if error, error number 580 can be retrieved with os_file_get_last_error */ 581 UNIV_INTERN 582 os_file_t 583 os_file_create_simple_func( 584 /*=======================*/ 585 const char* name, /*!< in: name of the file or path as a 586 null-terminated string */ 587 ulint create_mode,/*!< in: create mode */ 588 ulint access_type,/*!< in: OS_FILE_READ_ONLY or 589 OS_FILE_READ_WRITE */ 590 ibool* success);/*!< out: TRUE if succeed, FALSE if error */ 591 /****************************************************************//** 592 NOTE! Use the corresponding macro 593 os_file_create_simple_no_error_handling(), not directly this function! 594 A simple function to open or create a file. 595 @return own: handle to the file, not defined if error, error number 596 can be retrieved with os_file_get_last_error */ 597 UNIV_INTERN 598 pfs_os_file_t 599 os_file_create_simple_no_error_handling_func( 600 /*=========================================*/ 601 const char* name, /*!< in: name of the file or path as a 602 null-terminated string */ 603 ulint create_mode,/*!< in: create mode */ 604 ulint access_type,/*!< in: OS_FILE_READ_ONLY, 605 OS_FILE_READ_WRITE, or 606 OS_FILE_READ_ALLOW_DELETE; the last option is 607 used by a backup program reading the file */ 608 ibool* success)/*!< out: TRUE if succeed, FALSE if error */ 609 MY_ATTRIBUTE((nonnull, warn_unused_result)); 610 /****************************************************************//** 611 Tries to disable OS caching on an opened file descriptor. */ 612 UNIV_INTERN 613 void 614 os_file_set_nocache( 615 /*================*/ 616 int fd, /*!< in: file descriptor to alter */ 617 const char* file_name, /*!< in: file name, used in the 618 diagnostic message */ 619 const char* operation_name);/*!< in: "open" or "create"; used in the 620 diagnostic message */ 621 /****************************************************************//** 622 NOTE! Use the corresponding macro os_file_create(), not directly 623 this function! 624 Opens an existing file or creates a new. 625 @return own: handle to the file, not defined if error, error number 626 can be retrieved with os_file_get_last_error */ 627 UNIV_INTERN 628 pfs_os_file_t 629 os_file_create_func( 630 /*================*/ 631 const char* name, /*!< in: name of the file or path as a 632 null-terminated string */ 633 ulint create_mode,/*!< in: create mode */ 634 ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous, 635 non-buffered i/o is desired, 636 OS_FILE_NORMAL, if any normal file; 637 NOTE that it also depends on type, os_aio_.. 638 and srv_.. variables whether we really use 639 async i/o or unbuffered i/o: look in the 640 function source code for the exact rules */ 641 ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */ 642 ibool* success)/*!< out: TRUE if succeed, FALSE if error */ 643 MY_ATTRIBUTE((nonnull, warn_unused_result)); 644 /***********************************************************************//** 645 Deletes a file. The file has to be closed before calling this. 646 @return TRUE if success */ 647 UNIV_INTERN 648 bool 649 os_file_delete_func( 650 /*================*/ 651 const char* name); /*!< in: file path as a null-terminated 652 string */ 653 654 /***********************************************************************//** 655 Deletes a file if it exists. The file has to be closed before calling this. 656 @return TRUE if success */ 657 UNIV_INTERN 658 bool 659 os_file_delete_if_exists_func( 660 /*==========================*/ 661 const char* name); /*!< in: file path as a null-terminated 662 string */ 663 /***********************************************************************//** 664 NOTE! Use the corresponding macro os_file_rename(), not directly 665 this function! 666 Renames a file (can also move it to another directory). It is safest that the 667 file is closed before calling this function. 668 @return TRUE if success */ 669 UNIV_INTERN 670 ibool 671 os_file_rename_func( 672 /*================*/ 673 const char* oldpath, /*!< in: old file path as a 674 null-terminated string */ 675 const char* newpath); /*!< in: new file path */ 676 /***********************************************************************//** 677 NOTE! Use the corresponding macro os_file_close(), not directly this 678 function! 679 Closes a file handle. In case of error, error number can be retrieved with 680 os_file_get_last_error. 681 @return TRUE if success */ 682 UNIV_INTERN 683 ibool 684 os_file_close_func( 685 /*===============*/ 686 os_file_t file); /*!< in, own: handle to a file */ 687 688 #ifdef UNIV_PFS_IO 689 /****************************************************************//** 690 NOTE! Please use the corresponding macro os_file_create_simple(), 691 not directly this function! 692 A performance schema instrumented wrapper function for 693 os_file_create_simple() which opens or creates a file. 694 @return own: handle to the file, not defined if error, error number 695 can be retrieved with os_file_get_last_error */ 696 UNIV_INLINE 697 pfs_os_file_t 698 pfs_os_file_create_simple_func( 699 /*===========================*/ 700 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 701 const char* name, /*!< in: name of the file or path as a 702 null-terminated string */ 703 ulint create_mode,/*!< in: create mode */ 704 ulint access_type,/*!< in: OS_FILE_READ_ONLY or 705 OS_FILE_READ_WRITE */ 706 ibool* success,/*!< out: TRUE if succeed, FALSE if error */ 707 const char* src_file,/*!< in: file name where func invoked */ 708 ulint src_line)/*!< in: line where the func invoked */ 709 MY_ATTRIBUTE((nonnull, warn_unused_result)); 710 711 /****************************************************************//** 712 NOTE! Please use the corresponding macro 713 os_file_create_simple_no_error_handling(), not directly this function! 714 A performance schema instrumented wrapper function for 715 os_file_create_simple_no_error_handling(). Add instrumentation to 716 monitor file creation/open. 717 @return own: handle to the file, not defined if error, error number 718 can be retrieved with os_file_get_last_error */ 719 UNIV_INLINE 720 pfs_os_file_t 721 pfs_os_file_create_simple_no_error_handling_func( 722 /*=============================================*/ 723 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 724 const char* name, /*!< in: name of the file or path as a 725 null-terminated string */ 726 ulint create_mode, /*!< in: file create mode */ 727 ulint access_type,/*!< in: OS_FILE_READ_ONLY, 728 OS_FILE_READ_WRITE, or 729 OS_FILE_READ_ALLOW_DELETE; the last option is 730 used by a backup program reading the file */ 731 ibool* success,/*!< out: TRUE if succeed, FALSE if error */ 732 const char* src_file,/*!< in: file name where func invoked */ 733 ulint src_line)/*!< in: line where the func invoked */ 734 MY_ATTRIBUTE((nonnull, warn_unused_result)); 735 736 /****************************************************************//** 737 NOTE! Please use the corresponding macro os_file_create(), not directly 738 this function! 739 A performance schema wrapper function for os_file_create(). 740 Add instrumentation to monitor file creation/open. 741 @return own: handle to the file, not defined if error, error number 742 can be retrieved with os_file_get_last_error */ 743 UNIV_INLINE 744 pfs_os_file_t 745 pfs_os_file_create_func( 746 /*====================*/ 747 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 748 const char* name, /*!< in: name of the file or path as a 749 null-terminated string */ 750 ulint create_mode,/*!< in: file create mode */ 751 ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous, 752 non-buffered i/o is desired, 753 OS_FILE_NORMAL, if any normal file; 754 NOTE that it also depends on type, os_aio_.. 755 and srv_.. variables whether we really use 756 async i/o or unbuffered i/o: look in the 757 function source code for the exact rules */ 758 ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */ 759 ibool* success,/*!< out: TRUE if succeed, FALSE if error */ 760 const char* src_file,/*!< in: file name where func invoked */ 761 ulint src_line)/*!< in: line where the func invoked */ 762 MY_ATTRIBUTE((nonnull, warn_unused_result)); 763 764 /***********************************************************************//** 765 NOTE! Please use the corresponding macro os_file_close(), not directly 766 this function! 767 A performance schema instrumented wrapper function for os_file_close(). 768 @return TRUE if success */ 769 UNIV_INLINE 770 ibool 771 pfs_os_file_close_func( 772 /*===================*/ 773 pfs_os_file_t file, /*!< in, own: handle to a file */ 774 const char* src_file,/*!< in: file name where func invoked */ 775 ulint src_line);/*!< in: line where the func invoked */ 776 /*******************************************************************//** 777 NOTE! Please use the corresponding macro os_file_read(), not directly 778 this function! 779 This is the performance schema instrumented wrapper function for 780 os_file_read() which requests a synchronous read operation. 781 @return TRUE if request was successful, FALSE if fail */ 782 UNIV_INLINE 783 ibool 784 pfs_os_file_read_func( 785 /*==================*/ 786 pfs_os_file_t file, /*!< in: handle to a file */ 787 void* buf, /*!< in: buffer where to read */ 788 os_offset_t offset, /*!< in: file offset where to read */ 789 ulint n, /*!< in: number of bytes to read */ 790 const char* src_file,/*!< in: file name where func invoked */ 791 ulint src_line);/*!< in: line where the func invoked */ 792 793 /*******************************************************************//** 794 NOTE! Please use the corresponding macro os_file_read_no_error_handling(), 795 not directly this function! 796 This is the performance schema instrumented wrapper function for 797 os_file_read_no_error_handling_func() which requests a synchronous 798 read operation. 799 @return TRUE if request was successful, FALSE if fail */ 800 UNIV_INLINE 801 ibool 802 pfs_os_file_read_no_error_handling_func( 803 /*====================================*/ 804 pfs_os_file_t file, /*!< in: handle to a file */ 805 void* buf, /*!< in: buffer where to read */ 806 os_offset_t offset, /*!< in: file offset where to read */ 807 ulint n, /*!< in: number of bytes to read */ 808 const char* src_file,/*!< in: file name where func invoked */ 809 ulint src_line);/*!< in: line where the func invoked */ 810 811 /*******************************************************************//** 812 NOTE! Please use the corresponding macro os_aio(), not directly this 813 function! 814 Performance schema wrapper function of os_aio() which requests 815 an asynchronous i/o operation. 816 @return TRUE if request was queued successfully, FALSE if fail */ 817 UNIV_INLINE 818 ibool 819 pfs_os_aio_func( 820 /*============*/ 821 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */ 822 ulint mode, /*!< in: OS_AIO_NORMAL etc. I/O mode */ 823 const char* name, /*!< in: name of the file or path as a 824 null-terminated string */ 825 pfs_os_file_t file, /*!< in: handle to a file */ 826 void* buf, /*!< in: buffer where to read or from which 827 to write */ 828 os_offset_t offset, /*!< in: file offset where to read or write */ 829 ulint n, /*!< in: number of bytes to read or write */ 830 fil_node_t* message1,/*!< in: message for the aio handler 831 (can be used to identify a completed 832 aio operation); ignored if mode is 833 OS_AIO_SYNC */ 834 void* message2,/*!< in: message for the aio handler 835 (can be used to identify a completed 836 aio operation); ignored if mode is 837 OS_AIO_SYNC */ 838 const char* src_file,/*!< in: file name where func invoked */ 839 ulint src_line);/*!< in: line where the func invoked */ 840 /*******************************************************************//** 841 NOTE! Please use the corresponding macro os_file_write(), not directly 842 this function! 843 This is the performance schema instrumented wrapper function for 844 os_file_write() which requests a synchronous write operation. 845 @return TRUE if request was successful, FALSE if fail */ 846 UNIV_INLINE 847 ibool 848 pfs_os_file_write_func( 849 /*===================*/ 850 const char* name, /*!< in: name of the file or path as a 851 null-terminated string */ 852 pfs_os_file_t file, /*!< in: handle to a file */ 853 const void* buf, /*!< in: buffer from which to write */ 854 os_offset_t offset, /*!< in: file offset where to write */ 855 ulint n, /*!< in: number of bytes to write */ 856 const char* src_file,/*!< in: file name where func invoked */ 857 ulint src_line);/*!< in: line where the func invoked */ 858 /***********************************************************************//** 859 NOTE! Please use the corresponding macro os_file_flush(), not directly 860 this function! 861 This is the performance schema instrumented wrapper function for 862 os_file_flush() which flushes the write buffers of a given file to the disk. 863 Flushes the write buffers of a given file to the disk. 864 @return TRUE if success */ 865 UNIV_INLINE 866 ibool 867 pfs_os_file_flush_func( 868 /*===================*/ 869 pfs_os_file_t file, /*!< in, own: handle to a file */ 870 const char* src_file,/*!< in: file name where func invoked */ 871 ulint src_line);/*!< in: line where the func invoked */ 872 873 /***********************************************************************//** 874 NOTE! Please use the corresponding macro os_file_rename(), not directly 875 this function! 876 This is the performance schema instrumented wrapper function for 877 os_file_rename() 878 @return TRUE if success */ 879 UNIV_INLINE 880 ibool 881 pfs_os_file_rename_func( 882 /*====================*/ 883 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 884 const char* oldpath,/*!< in: old file path as a null-terminated 885 string */ 886 const char* newpath,/*!< in: new file path */ 887 const char* src_file,/*!< in: file name where func invoked */ 888 ulint src_line);/*!< in: line where the func invoked */ 889 890 /***********************************************************************//** 891 NOTE! Please use the corresponding macro os_file_delete(), not directly 892 this function! 893 This is the performance schema instrumented wrapper function for 894 os_file_delete() 895 @return TRUE if success */ 896 UNIV_INLINE 897 bool 898 pfs_os_file_delete_func( 899 /*====================*/ 900 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 901 const char* name, /*!< in: old file path as a null-terminated 902 string */ 903 const char* src_file,/*!< in: file name where func invoked */ 904 ulint src_line);/*!< in: line where the func invoked */ 905 906 /***********************************************************************//** 907 NOTE! Please use the corresponding macro os_file_delete_if_exists(), not 908 directly this function! 909 This is the performance schema instrumented wrapper function for 910 os_file_delete_if_exists() 911 @return TRUE if success */ 912 UNIV_INLINE 913 bool 914 pfs_os_file_delete_if_exists_func( 915 /*==============================*/ 916 mysql_pfs_key_t key, /*!< in: Performance Schema Key */ 917 const char* name, /*!< in: old file path as a null-terminated 918 string */ 919 const char* src_file,/*!< in: file name where func invoked */ 920 ulint src_line);/*!< in: line where the func invoked */ 921 #endif /* UNIV_PFS_IO */ 922 923 #ifdef UNIV_HOTBACKUP 924 /***********************************************************************//** 925 Closes a file handle. 926 @return TRUE if success */ 927 UNIV_INTERN 928 ibool 929 os_file_close_no_error_handling( 930 /*============================*/ 931 os_file_t file); /*!< in, own: handle to a file */ 932 #endif /* UNIV_HOTBACKUP */ 933 /***********************************************************************//** 934 Gets a file size. 935 @return file size, or (os_offset_t) -1 on failure */ 936 UNIV_INTERN 937 os_offset_t 938 os_file_get_size( 939 /*=============*/ 940 pfs_os_file_t file) /*!< in: handle to a file */ 941 MY_ATTRIBUTE((warn_unused_result)); 942 /***********************************************************************//** 943 Write the specified number of zeros to a newly created file. 944 @return TRUE if success */ 945 UNIV_INTERN 946 ibool 947 os_file_set_size( 948 /*=============*/ 949 const char* name, /*!< in: name of the file or path as a 950 null-terminated string */ 951 pfs_os_file_t file, /*!< in: handle to a file */ 952 os_offset_t size) /*!< in: file size */ 953 MY_ATTRIBUTE((nonnull, warn_unused_result)); 954 /***********************************************************************//** 955 Truncates a file at its current position. 956 @return TRUE if success */ 957 UNIV_INTERN 958 ibool 959 os_file_set_eof( 960 /*============*/ 961 FILE* file); /*!< in: file to be truncated */ 962 /***********************************************************************//** 963 NOTE! Use the corresponding macro os_file_flush(), not directly this function! 964 Flushes the write buffers of a given file to the disk. 965 @return TRUE if success */ 966 UNIV_INTERN 967 ibool 968 os_file_flush_func( 969 /*===============*/ 970 os_file_t file); /*!< in, own: handle to a file */ 971 /***********************************************************************//** 972 Retrieves the last error number if an error occurs in a file io function. 973 The number should be retrieved before any other OS calls (because they may 974 overwrite the error number). If the number is not known to this program, 975 the OS error number + 100 is returned. 976 @return error number, or OS error number + 100 */ 977 UNIV_INTERN 978 ulint 979 os_file_get_last_error( 980 /*===================*/ 981 bool report_all_errors); /*!< in: TRUE if we want an error message 982 printed of all errors */ 983 /*******************************************************************//** 984 NOTE! Use the corresponding macro os_file_read(), not directly this function! 985 Requests a synchronous read operation. 986 @return TRUE if request was successful, FALSE if fail */ 987 UNIV_INTERN 988 ibool 989 os_file_read_func( 990 /*==============*/ 991 os_file_t file, /*!< in: handle to a file */ 992 void* buf, /*!< in: buffer where to read */ 993 os_offset_t offset, /*!< in: file offset where to read */ 994 ulint n); /*!< in: number of bytes to read */ 995 /*******************************************************************//** 996 Rewind file to its start, read at most size - 1 bytes from it to str, and 997 NUL-terminate str. All errors are silently ignored. This function is 998 mostly meant to be used with temporary files. */ 999 UNIV_INTERN 1000 void 1001 os_file_read_string( 1002 /*================*/ 1003 FILE* file, /*!< in: file to read from */ 1004 char* str, /*!< in: buffer where to read */ 1005 ulint size); /*!< in: size of buffer */ 1006 /*******************************************************************//** 1007 NOTE! Use the corresponding macro os_file_read_no_error_handling(), 1008 not directly this function! 1009 Requests a synchronous positioned read operation. This function does not do 1010 any error handling. In case of error it returns FALSE. 1011 @return TRUE if request was successful, FALSE if fail */ 1012 UNIV_INTERN 1013 ibool 1014 os_file_read_no_error_handling_func( 1015 /*================================*/ 1016 os_file_t file, /*!< in: handle to a file */ 1017 void* buf, /*!< in: buffer where to read */ 1018 os_offset_t offset, /*!< in: file offset where to read */ 1019 ulint n); /*!< in: number of bytes to read */ 1020 1021 /*******************************************************************//** 1022 NOTE! Use the corresponding macro os_file_write(), not directly this 1023 function! 1024 Requests a synchronous write operation. 1025 @return TRUE if request was successful, FALSE if fail */ 1026 UNIV_INTERN 1027 ibool 1028 os_file_write_func( 1029 /*===============*/ 1030 const char* name, /*!< in: name of the file or path as a 1031 null-terminated string */ 1032 os_file_t file, /*!< in: handle to a file */ 1033 const void* buf, /*!< in: buffer from which to write */ 1034 os_offset_t offset, /*!< in: file offset where to write */ 1035 ulint n); /*!< in: number of bytes to write */ 1036 /*******************************************************************//** 1037 Check the existence and type of the given file. 1038 @return TRUE if call succeeded */ 1039 UNIV_INTERN 1040 ibool 1041 os_file_status( 1042 /*===========*/ 1043 const char* path, /*!< in: pathname of the file */ 1044 ibool* exists, /*!< out: TRUE if file exists */ 1045 os_file_type_t* type); /*!< out: type of the file (if it exists) */ 1046 /****************************************************************//** 1047 The function os_file_dirname returns a directory component of a 1048 null-terminated pathname string. In the usual case, dirname returns 1049 the string up to, but not including, the final '/', and basename 1050 is the component following the final '/'. Trailing '/' characters 1051 are not counted as part of the pathname. 1052 1053 If path does not contain a slash, dirname returns the string ".". 1054 1055 Concatenating the string returned by dirname, a "/", and the basename 1056 yields a complete pathname. 1057 1058 The return value is a copy of the directory component of the pathname. 1059 The copy is allocated from heap. It is the caller responsibility 1060 to free it after it is no longer needed. 1061 1062 The following list of examples (taken from SUSv2) shows the strings 1063 returned by dirname and basename for different paths: 1064 1065 path dirname basename 1066 "/usr/lib" "/usr" "lib" 1067 "/usr/" "/" "usr" 1068 "usr" "." "usr" 1069 "/" "/" "/" 1070 "." "." "." 1071 ".." "." ".." 1072 1073 @return own: directory component of the pathname */ 1074 UNIV_INTERN 1075 char* 1076 os_file_dirname( 1077 /*============*/ 1078 const char* path); /*!< in: pathname */ 1079 /****************************************************************//** 1080 This function returns a new path name after replacing the basename 1081 in an old path with a new basename. The old_path is a full path 1082 name including the extension. The tablename is in the normal 1083 form "databasename/tablename". The new base name is found after 1084 the forward slash. Both input strings are null terminated. 1085 1086 This function allocates memory to be returned. It is the callers 1087 responsibility to free the return value after it is no longer needed. 1088 1089 @return own: new full pathname */ 1090 UNIV_INTERN 1091 char* 1092 os_file_make_new_pathname( 1093 /*======================*/ 1094 const char* old_path, /*!< in: pathname */ 1095 const char* new_name); /*!< in: new file name */ 1096 /****************************************************************//** 1097 This function returns a remote path name by combining a data directory 1098 path provided in a DATA DIRECTORY clause with the tablename which is 1099 in the form 'database/tablename'. It strips the file basename (which 1100 is the tablename) found after the last directory in the path provided. 1101 The full filepath created will include the database name as a directory 1102 under the path provided. The filename is the tablename with the '.ibd' 1103 extension. All input and output strings are null-terminated. 1104 1105 This function allocates memory to be returned. It is the callers 1106 responsibility to free the return value after it is no longer needed. 1107 1108 @return own: A full pathname; data_dir_path/databasename/tablename.ibd */ 1109 UNIV_INTERN 1110 char* 1111 os_file_make_remote_pathname( 1112 /*=========================*/ 1113 const char* data_dir_path, /*!< in: pathname */ 1114 const char* tablename, /*!< in: tablename */ 1115 const char* extention); /*!< in: file extention; ibd,cfg*/ 1116 /****************************************************************//** 1117 This function reduces a null-terminated full remote path name into 1118 the path that is sent by MySQL for DATA DIRECTORY clause. It replaces 1119 the 'databasename/tablename.ibd' found at the end of the path with just 1120 'tablename'. 1121 1122 Since the result is always smaller than the path sent in, no new memory 1123 is allocated. The caller should allocate memory for the path sent in. 1124 This function manipulates that path in place. 1125 1126 If the path format is not as expected, just return. The result is used 1127 to inform a SHOW CREATE TABLE command. */ 1128 UNIV_INTERN 1129 void 1130 os_file_make_data_dir_path( 1131 /*========================*/ 1132 char* data_dir_path); /*!< in/out: full path/data_dir_path */ 1133 /****************************************************************//** 1134 Creates all missing subdirectories along the given path. 1135 @return TRUE if call succeeded FALSE otherwise */ 1136 UNIV_INTERN 1137 ibool 1138 os_file_create_subdirs_if_needed( 1139 /*=============================*/ 1140 const char* path); /*!< in: path name */ 1141 /*********************************************************************** 1142 Initializes the asynchronous io system. Creates one array each for ibuf 1143 and log i/o. Also creates one array each for read and write where each 1144 array is divided logically into n_read_segs and n_write_segs 1145 respectively. The caller must create an i/o handler thread for each 1146 segment in these arrays. This function also creates the sync array. 1147 No i/o handler thread needs to be created for that */ 1148 UNIV_INTERN 1149 ibool 1150 os_aio_init( 1151 /*========*/ 1152 ulint n_per_seg, /*<! in: maximum number of pending aio 1153 operations allowed per segment */ 1154 ulint n_read_segs, /*<! in: number of reader threads */ 1155 ulint n_write_segs, /*<! in: number of writer threads */ 1156 ulint n_slots_sync); /*<! in: number of slots in the sync aio 1157 array */ 1158 /*********************************************************************** 1159 Frees the asynchronous io system. */ 1160 UNIV_INTERN 1161 void 1162 os_aio_free(void); 1163 /*=============*/ 1164 1165 /*******************************************************************//** 1166 NOTE! Use the corresponding macro os_aio(), not directly this function! 1167 Requests an asynchronous i/o operation. 1168 @return TRUE if request was queued successfully, FALSE if fail */ 1169 UNIV_INTERN 1170 ibool 1171 os_aio_func( 1172 /*========*/ 1173 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */ 1174 ulint mode, /*!< in: OS_AIO_NORMAL, ..., possibly ORed 1175 to OS_AIO_SIMULATED_WAKE_LATER: the 1176 last flag advises this function not to wake 1177 i/o-handler threads, but the caller will 1178 do the waking explicitly later, in this 1179 way the caller can post several requests in 1180 a batch; NOTE that the batch must not be 1181 so big that it exhausts the slots in aio 1182 arrays! NOTE that a simulated batch 1183 may introduce hidden chances of deadlocks, 1184 because i/os are not actually handled until 1185 all have been posted: use with great 1186 caution! */ 1187 const char* name, /*!< in: name of the file or path as a 1188 null-terminated string */ 1189 pfs_os_file_t file, /*!< in: handle to a file */ 1190 void* buf, /*!< in: buffer where to read or from which 1191 to write */ 1192 os_offset_t offset, /*!< in: file offset where to read or write */ 1193 ulint n, /*!< in: number of bytes to read or write */ 1194 fil_node_t* message1,/*!< in: message for the aio handler 1195 (can be used to identify a completed 1196 aio operation); ignored if mode is 1197 OS_AIO_SYNC */ 1198 void* message2);/*!< in: message for the aio handler 1199 (can be used to identify a completed 1200 aio operation); ignored if mode is 1201 OS_AIO_SYNC */ 1202 /************************************************************************//** 1203 Wakes up all async i/o threads so that they know to exit themselves in 1204 shutdown. */ 1205 UNIV_INTERN 1206 void 1207 os_aio_wake_all_threads_at_shutdown(void); 1208 /*=====================================*/ 1209 /************************************************************************//** 1210 Waits until there are no pending writes in os_aio_write_array. There can 1211 be other, synchronous, pending writes. */ 1212 UNIV_INTERN 1213 void 1214 os_aio_wait_until_no_pending_writes(void); 1215 /*=====================================*/ 1216 /**********************************************************************//** 1217 Wakes up simulated aio i/o-handler threads if they have something to do. */ 1218 UNIV_INTERN 1219 void 1220 os_aio_simulated_wake_handler_threads(void); 1221 /*=======================================*/ 1222 /**********************************************************************//** 1223 This function can be called if one wants to post a batch of reads and 1224 prefers an i/o-handler thread to handle them all at once later. You must 1225 call os_aio_simulated_wake_handler_threads later to ensure the threads 1226 are not left sleeping! */ 1227 UNIV_INTERN 1228 void 1229 os_aio_simulated_put_read_threads_to_sleep(void); 1230 /*============================================*/ 1231 1232 #ifdef WIN_ASYNC_IO 1233 /**********************************************************************//** 1234 This function is only used in Windows asynchronous i/o. 1235 Waits for an aio operation to complete. This function is used to wait the 1236 for completed requests. The aio array of pending requests is divided 1237 into segments. The thread specifies which segment or slot it wants to wait 1238 for. NOTE: this function will also take care of freeing the aio slot, 1239 therefore no other thread is allowed to do the freeing! 1240 @return TRUE if the aio operation succeeded */ 1241 UNIV_INTERN 1242 ibool 1243 os_aio_windows_handle( 1244 /*==================*/ 1245 ulint segment, /*!< in: the number of the segment in the aio 1246 arrays to wait for; segment 0 is the ibuf 1247 i/o thread, segment 1 the log i/o thread, 1248 then follow the non-ibuf read threads, and as 1249 the last are the non-ibuf write threads; if 1250 this is ULINT_UNDEFINED, then it means that 1251 sync aio is used, and this parameter is 1252 ignored */ 1253 ulint pos, /*!< this parameter is used only in sync aio: 1254 wait for the aio slot at this position */ 1255 fil_node_t**message1, /*!< out: the messages passed with the aio 1256 request; note that also in the case where 1257 the aio operation failed, these output 1258 parameters are valid and can be used to 1259 restart the operation, for example */ 1260 void** message2, 1261 ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */ 1262 #endif 1263 1264 /**********************************************************************//** 1265 Does simulated aio. This function should be called by an i/o-handler 1266 thread. 1267 @return TRUE if the aio operation succeeded */ 1268 UNIV_INTERN 1269 ibool 1270 os_aio_simulated_handle( 1271 /*====================*/ 1272 ulint segment, /*!< in: the number of the segment in the aio 1273 arrays to wait for; segment 0 is the ibuf 1274 i/o thread, segment 1 the log i/o thread, 1275 then follow the non-ibuf read threads, and as 1276 the last are the non-ibuf write threads */ 1277 fil_node_t**message1, /*!< out: the messages passed with the aio 1278 request; note that also in the case where 1279 the aio operation failed, these output 1280 parameters are valid and can be used to 1281 restart the operation, for example */ 1282 void** message2, 1283 ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */ 1284 /**********************************************************************//** 1285 Validates the consistency of the aio system. 1286 @return TRUE if ok */ 1287 UNIV_INTERN 1288 ibool 1289 os_aio_validate(void); 1290 /*=================*/ 1291 /**********************************************************************//** 1292 Prints info of the aio arrays. */ 1293 UNIV_INTERN 1294 void 1295 os_aio_print( 1296 /*=========*/ 1297 FILE* file); /*!< in: file where to print */ 1298 /**********************************************************************//** 1299 Refreshes the statistics used to print per-second averages. */ 1300 UNIV_INTERN 1301 void 1302 os_aio_refresh_stats(void); 1303 /*======================*/ 1304 1305 #ifdef UNIV_DEBUG 1306 /**********************************************************************//** 1307 Checks that all slots in the system have been freed, that is, there are 1308 no pending io operations. */ 1309 UNIV_INTERN 1310 ibool 1311 os_aio_all_slots_free(void); 1312 /*=======================*/ 1313 #endif /* UNIV_DEBUG */ 1314 1315 /*******************************************************************//** 1316 This function returns information about the specified file 1317 @return DB_SUCCESS if all OK */ 1318 UNIV_INTERN 1319 dberr_t 1320 os_file_get_status( 1321 /*===============*/ 1322 const char* path, /*!< in: pathname of the file */ 1323 os_file_stat_t* stat_info, /*!< information of a file in a 1324 directory */ 1325 bool check_rw_perm); /*!< in: for testing whether the 1326 file can be opened in RW mode */ 1327 1328 #if !defined(UNIV_HOTBACKUP) 1329 1330 /** return one of the tmpdir path 1331 @return tmpdir path*/ 1332 char *innobase_mysql_tmpdir(void); 1333 /** Create a temporary file in the location specified by the parameter 1334 path. If the path is null, then it will be created in tmpdir. 1335 @param[in] path location for creating temporary file 1336 @return temporary file descriptor, or < 0 on error */ 1337 UNIV_INTERN 1338 int 1339 innobase_mysql_tmpfile( 1340 const char* path); 1341 #endif /* !UNIV_HOTBACKUP */ 1342 1343 1344 #if defined(LINUX_NATIVE_AIO) 1345 /************************************************************************** 1346 This function is only used in Linux native asynchronous i/o. 1347 Waits for an aio operation to complete. This function is used to wait the 1348 for completed requests. The aio array of pending requests is divided 1349 into segments. The thread specifies which segment or slot it wants to wait 1350 for. NOTE: this function will also take care of freeing the aio slot, 1351 therefore no other thread is allowed to do the freeing! 1352 @return TRUE if the IO was successful */ 1353 UNIV_INTERN 1354 ibool 1355 os_aio_linux_handle( 1356 /*================*/ 1357 ulint global_seg, /*!< in: segment number in the aio array 1358 to wait for; segment 0 is the ibuf 1359 i/o thread, segment 1 is log i/o thread, 1360 then follow the non-ibuf read threads, 1361 and the last are the non-ibuf write 1362 threads. */ 1363 fil_node_t**message1, /*!< out: the messages passed with the */ 1364 void** message2, /*!< aio request; note that in case the 1365 aio operation failed, these output 1366 parameters are valid and can be used to 1367 restart the operation. */ 1368 ulint* type); /*!< out: OS_FILE_WRITE or ..._READ */ 1369 #endif /* LINUX_NATIVE_AIO */ 1370 1371 #ifndef UNIV_NONINL 1372 #include "os0file.ic" 1373 #endif 1374 1375 #endif 1376